Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Must IRET be used when returning from an interrupt?

IRET can restore the registers from the stack,including EFLAGS, ESP, EIP and so on, but we can also restore the registers all by ourselves. For example, "movl" can be used to restore the %esp register, "jmp" can jump the address pointed to EIP which is stored on the stack.

The linux kernel returns from all interrupts by IRET, which is a weight instruction.

Some kernel operations (like context switches) happen frequently.

Isn't IRET a waste?

like image 313
venus.w Avatar asked Jan 17 '23 18:01

venus.w


1 Answers

Besides all the heavy stuff IRET can and often should do in addition to a mere blend of POPF+RETF, there's one more thing that it does. It has a special function related to non-maskable interrupts (NMIs).

Concurrent NMIs are delivered to the CPU one by one. IRET signals to the NMI circuitry that another NMI can now be delivered. No other instruction can do this signalling. If NMIs could preempt execution of other NMI ISRs, they would be able to cause a stack overflow, which rarely is a good thing. Unless we're talking about this wonderful website. :)

So, all in all, IRET is not a waste.

like image 90
Alexey Frunze Avatar answered Jan 25 '23 00:01

Alexey Frunze