Confused about virtual memory during interrupts
Posted: Mon Feb 25, 2019 11:49 am
Ok so I have a bit of a problem I'm trying to figure out. In my x86 OS, I have multitasking working, with one kernel stack per process and every process in its own virtual address space but I'm having some trouble now that I'm rewriting the keyboard driver to accommodate this. Basically I figure that the active user process (in my os this means the one the user switched to with ALT+TAB), should be the only one allowed to read keystrokes. So I figure I'll allocate a ring buffer inside the active process and the keyboard driver will write to it when a key is pressed, great. However when a key is pressed, that's happening from inside an IRQ, so that means it could be fired while inside the address space of ANY process, so it has no idea where the ring buffer it's supposed to write to is!
So I thought of a couple solutions to this problem but none of them seem good:
- Have an address space just for IRQ's and make sure the ring buffer is mapped into this address space and the address space of the active process, this unfortunately means a TLB flush will occur for every IRQ.
- Make sure the ring buffer is mapped into the kernel space of every process, this seems like a hell of alot of overhead for allocating a ring buffer, meaning I have to find all the running processes and allocate inside them
- Temporarily change address spaces while writing to the ring buffer, but once again this is gonna cause a TLB flush
So this seems more fundamental then just rewriting a keyboard driver, but how do you guys make sure you can always access certain dynamically allocated resources from any process?
So I thought of a couple solutions to this problem but none of them seem good:
- Have an address space just for IRQ's and make sure the ring buffer is mapped into this address space and the address space of the active process, this unfortunately means a TLB flush will occur for every IRQ.
- Make sure the ring buffer is mapped into the kernel space of every process, this seems like a hell of alot of overhead for allocating a ring buffer, meaning I have to find all the running processes and allocate inside them
- Temporarily change address spaces while writing to the ring buffer, but once again this is gonna cause a TLB flush
So this seems more fundamental then just rewriting a keyboard driver, but how do you guys make sure you can always access certain dynamically allocated resources from any process?