gpt4 book ai didi

C - 从内核模块写入物理内存

转载 作者:IT王子 更新时间:2023-10-28 23:36:06 26 4
gpt4 key购买 nike

在内核模块中,我需要通过向物理内存地址写入“零”来处理中断。

首先,我应该通过诸如“mmap”之类的函数来分配内存,但是对于内核模块;例如,ioremap。

static irqreturn_t int068_interrupt(int irq, void *dev_id)
{
unsigned int *p;
unsigned int address;
unsigned int memsize;

address = 0x12345678;
memsize = 1024;

p = ioremap(address, memsize);
p[0]=0;

printk("Interrupt was handled\n");

return IRQ_HANDLED;
}

但是,当中断到来并且中断处理程序开始处理它时,内核会崩溃(mm/vmalloc.c:nu​​mberofline 处的内核BUG)

我对 ioremap 的使用似乎有问题,或者我应该使用另一个“内核替代 mmap”

请告诉我,如何解决这个问题?

最佳答案

直接来自Linux ioremap.c:

If you iounmap and ioremap a region, the other CPUs will not see this change until their next context switch. Meanwhile, (eg) if an interrupt comes in on one of those other CPUs which requires the new ioremap'd region to be referenced, the CPU will reference the old region.

这明显要求避免在中断服务例程中调用 ioremap

关于C - 从内核模块写入物理内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15248191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com