Why does linux disable kernel boot after the kernel code contains a spinlock?

I am new to Linux and reading a book of Linux device drivers from Rubini and Corbet. I am confused by one post related to spinlocks ; the book says:

If an opaque uniprocessor system ever rotates on a lock, it will spin forever; no other thread can ever get to release the lock. For this reason, spin-lock operations on single-processor systems without the use of privileges are optimized to do nothing, except for those that change the IRQ masking status.

Further in the book is indicated

The case of kernel continuity is handled by the spinlock code itself. At any time in the kernel, the code contains a spin lock; interrupt is disabled on the corresponding processor. Even uniprocessor systems must disable prevention in such a way as to avoid race conditions.

Question. On a single processor system, if kernel prohibition is turned off whenever the kernel code (executed on behalf of the user process) contains a spin lock, while another process ever gets a chance to start, and therefore try to set a direct lock? Why does Linux Kernel disable kernel pre-use when the kernel code contains a spin lock?

+4
source share
1 answer

The answer to your first question is the arguments for the second.

Spinlocks obtained by the kernel can be implemented by disabling preemption, as this ensures that the kernel completes its critical section without the intervention of another process. The whole point is that another process will not be able to work until the kernel releases the lock.

There is no reason for this to be implemented in this way; this is just an easy way to implement it and does not allow any process to spin on the lock held by the kernel. But this trick only works if the kernel has acquired a lock: user processes cannot turn off the continuity, and if the kernel rotates (i.e., it tries to get a spin lock, but another process already holds it), itโ€™s better to leave guess on! Otherwise, the system will hang, because the kernel is waiting for a lock that will not be released, because the process holding it cannot release it.

A kernel acquiring a spin lock is a special case. If a user-level program acquires a spin lock, then prevention will not be disabled.

+6
source

Source: https://habr.com/ru/post/1497256/


All Articles