C - Write to physical memory from kernel module
c, interrupt, kernel, memory, module
Solution
directly from 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.
This strikly asks to avoid `ioremap` call within an interrupt service routine.
Problem
In the kernel module, I need to handle the interrupt by writing a "zero" to address of physical memory. First of all, I should allocate a memory by some function like "mmap", but for kernel module; for example, 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; } ``` However, the kernel crashes when interrupt comes and interrupt handler starts handling it (kernel BUG at mm/vmalloc.c:numberofline) It seems that something wrong with my usage of ioremap, or I should use another "kernel substitute of mmap" Please tell me, how to workaround this problem?