OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:44 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: [Solved] PIC and spurious IRQs
PostPosted: Wed May 18, 2022 2:06 am 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
Hi all,
The PIC page on the wiki says:
Quote:
For a spurious IRQ, there is no real IRQ and the PIC chip's ISR (In Service Register) flag for the corresponding IRQ will not be set. This means that the interrupt handler must not send an EOI back to the PIC to reset the ISR flag.

The correct way to handle an IRQ 7 is to first check the master PIC chip's ISR to see if the IRQ is a spurious IRQ or a real IRQ. If it is a real IRQ then it is treated the same as any other real IRQ. If it is a spurious IRQ then you ignore it (and do not send the EOI).

I understand that the PIC itself can generate spurious interrupts using the IRQ 7 vector, but I think that it's important to check if any interrupt is spurious (since userspace can easily execute INT xx instruction for any interrupt anyway, and you certainly don't want to send EOI to the PIC in that case). Am I misunderstanding something?

Edit: oh wait, I was missing something. You can set privilege level in the IDT to prevent user space raising interrupts.


Top
 Profile  
 
 Post subject: Re: [Solved] PIC and spurious IRQs
PostPosted: Wed May 18, 2022 12:24 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
davmac314 wrote:
I understand that the PIC itself can generate spurious interrupts using the IRQ 7 vector, but I think that it's important to check if any interrupt is spurious (since userspace can easily execute INT xx instruction for any interrupt anyway, and you certainly don't want to send EOI to the PIC in that case). Am I misunderstanding something?

Edit: oh wait, I was missing something. You can set privilege level in the IDT to prevent user space raising interrupts.
Well, you caught it yourself. Yes, you can just prevent userspace from executing software interrupts on IRQ vectors. Moreover, interrupt handlers should be written in a way to ensure safe operation even if the interrupt was spurious (i.e. not actually caused by the device attached). For the PIC driver itself, I would borrow a page from Linux's book and mask out interrupts that are being served. If you also keep a copy of the PIC mask in software, it is pretty fast to notice if a masked IRQ happened anyway. Such an IRQ must be spurious. It won't find all spurious IRQs, but it will find most of them, and spurious IRQs are rare enough that slowing down every IRQ is probably not worth it.

Not that any of this matters one jot or tittle these days, since APIC exists and is faster and typically preferable.

_________________
Carpe diem!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 79 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group