I need to ensure in a code portion (in kernel mode) that no one else can modify/check the CR0 register. On a one-processor system I think disabling interrupts is the best. But on multi-processor systems :
Is there a way to disable ALL interrupts from ALL processors during a code section (with the spinlock mechanism for example)?
Is this necessary? When modifying the cr0
register on a multi-processor system, I guess the register is only modified for the current CPU?
--> so disabling interrupts only for the current CPU would be sufficient?
--> is there a way to check/modify from other CPUs (on a same system) the register from another CPU?
Many thanks in forward for your answers (and sorry for my approximative English)
Jérôme.
Jérôme,
Have you looked into using spin_lock_irqsave()
and spin_unlock_irqrestore()
? This disables local interrupts.
I believe a more all-encompassing version is spin_lock_irq()
and spin_unlock_irq()
which stops all interrupts unconditionally (like cli()/sti()
).
There are many conditions to take into account when using these locking mechanisms. One of the primary examples is losing the ability to call kernel functions that may sleep
while inside your spin_lock
. You may need to do a bit of research before you can determine which is best in your particular case. But from the brief explanation you provided it seems one of the two schemes above should work for you.
Good luck!