0

I am trying to code some IRQ handler for a shared IRQ line.

Essentially I only need to read some memory words from the device memory.

To do so I use mem = ioremap_nocache(addr, 8); (8 Bytes is only what I need). And then calling from the handlers.

irqreturn_t do_sample_irq() {
    int val;
    val = ioread32(mem); // I know this is only 4 Bytes, but it is ok.
    printk(KERN_INFO, "%x.\n", val);
    return (irqreturn_t) IRQ_HANDLED;
}
irqreturn_t sample_irq_handler() {
    irqreturn_t ret;
    spin_lock_irq(&lock);
    ret = do_sample_irq();
    spin_unlock_irq(&lock);
    return ret;
}

Then, whenever I insert the module, instantly gives a kernel panic: kernel not sync: Fatal exception interrupt context.

My guess is that I am not using the proper synchronising techniques, but I cannot devise what (new in the developing kernel modules task).

What is happening?

as43z
  • 25
  • 7
  • 1
    `printk` from ISR? See: https://stackoverflow.com/questions/8738951/printk-inside-an-interrupt-handler-is-it-really-that-bad – Craig Estey Apr 16 '23 at 21:01
  • I guess the printk was adding so much overhead, now the `do_sample_irq()` produces a warning. – as43z Apr 16 '23 at 21:09
  • 2
    Didn't I imply do _not_ put `printk` in an ISR [ever]? ;-) Slowdowns and _lockups_. I did it in a driver ISR [accidentally] and it wreaked havoc. If you want debug in an ISR, consider an "event trace buffer" See my answer: [Need test to determine if asynchronous I/O is actually happening in C code](https://stackoverflow.com/a/65099395/5382650) That answer is actually a watered down version of one I actually put into my production kernel drivers. – Craig Estey Apr 16 '23 at 21:20
  • Isn't this warning you got? https://elixir.bootlin.com/linux/latest/source/lib/vsprintf.c#L2652 Because what does the heck `%k` mean? – 0andriy Apr 17 '23 at 06:43
  • @CraigEstey, I see no issues with that. (Answering to your first comment) – 0andriy Apr 17 '23 at 06:49
  • Also `\n` seems misplaced. – 0andriy Apr 17 '23 at 06:49
  • @0andriy I wanted to put %x. Will edit it now. – as43z Apr 17 '23 at 07:40
  • And did it help after these changes made? – 0andriy Apr 17 '23 at 09:12
  • @0andriy well it worked when I deleted the printk statement, Craig Estey was right. The %k was a typo I made when adapting the code to this post. – as43z Apr 17 '23 at 14:06

0 Answers0