C - Write to physical memory from a kernel module

In the kernel module, I need to handle the interrupt by writing "zero" to the address of the physical memory.

First of all, I have to allocate memory with some function, for example "mmap", but for the kernel module; e.g. 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, when a kernel crashes, a crash occurs, and the interrupt handler starts to process it (BUG kernel on mm / vmalloc.c: numberofline)

Something seems to be wrong with my use of ioremap, or should I use another "mmap kernel substitute"

Please tell me how to solve this problem?

+7
source share
1 answer

directly from Linux ioremap.c :

If you are an iounmap and ioremap region, other processors will not see this change them until the next context switch. Meanwhile (for example), if an interrupt occurs on one of these other processors, which requires a new ioremap'd for reference, the CPU will refer to the old area.

It is very important to avoid calling ioremap as part of the interrupt service routine.

+3
source

All Articles