Your Location is: Home > Linux-kernel

What is the in-line assembly code for kernel preemption and disable interrupts?

From: Zagreb View: 3008 user45698746 


I know that in kernel I can call get_cpu() to disable kernel preemption and local_irq_save(flags) to disable interrupt. I'm curious how can I still achieve the same goal without calling these functions. I have three questions,

  1. I found that cli instruction is the one responsible for disabling interrupts. Therefore, I was wondering if the following in-line assembly,

    asm volatile("cli": : :"memory");

is enough to disable interrupts. If It works, how can I check if it actually disables interrupts?

  1. Is there any inline assembly instruction that I can use to disable kernel preemption?

  2. I know it is not possible to disable interrupts from the userspace. I just wondering if somehow someone manages to run that cli instruction from the userspace. Will it still be able to disable the interrupts? If the answer is no then why?

Best answer