System Calls in x86_32
Hi All,
I need help understanding how the direct system calls work on the x86_32 architecture.
What I understand is that when a guest is initialized, it uses the hypercall do_set_trap_table to initialize the trap table which calls init_int80_direct_trap for system call interrupts. The later updates the int80_desc structure in the VCPU of the guest so that the new address gets the callback directly.
What I do not understand is where does the call back occur. Int80 is not handles in the x86_32's entry.S?!!!! So, where is the code that issues the callback?
Why is architecture is different on x86_64. The entry.S contains an entry for int80. Does this affect the performance of the guests?
Ahmed
Quoted 6 lines
I need help understanding how the direct system calls work on the
x86_32
architecture.What I understand is that when a guest is initialized, it uses the
hypercalldo_set_trap_tableto initialize the trap table which callsinit_int80_direct_trapfor system call interrupts.
Correct.
Quoted 3 lines
The later updates the
int80_descstructure in the VCPU of the guest so that the new address gets the callback directly.
Yes, on 32 bit arch (arch/x86/x86_32/traps.c). The definition is different on 64 bit arch (arch/x86/x86_64/traps.c), int80_desc is not used.
Quoted 3 lines
What I do not understand is where does the call back occur. Int80 is not
handles in the x86_32'sentry.S?!!!! So, where is the code that issues the callback?
Here is an explanation how things work on 32 bit arch:
During boot Interrupt Descriptor Table (IDT) is constructed and loaded onto the CPU(s) (construct_percpu_idt() in arch/x86/smpboot.c). This table contains description of various interrupt vectors.
When do_set_trap_table() hypercall is issued, vector 0x80 is reset to point to the guest provided interrupt handler (by init_int80_direct_trap() in include/asm-x86/processor.h).
Thanks to that, whenever INT 0x80 instruction is executed, the guest provided handler will be invoked directly, without involving Xen. That's how the callback happens: CPU encounters INT 0x80 intruction, looks up the relevant, guest provided, interrupt handler in the IDT and invokes it.
Quoted 3 lines
Why is architecture is different on
x86_64. Theentry.Scontains an entry
for int80. Does this affect the performance of the guests?
64 bit architecture is more complicated, because Xen will intercept interrupt 0x80 (it therefore loads it's own interrupt handler into IDT, specifically int80_direct_trap defined in arch/x86/x86_64/entry.S). The reason why Xen wants to intercept the interrupts is that we could be executing 32bit guest, or an HVM guest etc (look through the definition of int80_direct_trap for details).
Hope this helps
Gr(z)egor(z)
Quoted 3 lines
The reason why Xen wants to intercept the
interrupts is that we could be executing 32bit guest, or an HVM guest etc (look through the definition ofint80_direct_trapfor details).
Not exactly. First of all, HVM guests are don't-care here - they handle int 0x80 with their own IDT. 64-bit guests must go through Xen because guest and kernel run in ring 3, and the kernel mode flag must be set correctly, which can only be donein Xen. 32-bit guest must go through Xen because x84-64 doesn't know 32-bit gates (i.e. the target code selector of any gate must be a 64-bit code segment).
Jan