Recently, I am doing homework about Virtualization. My question is, how VMM transfer control to the guest kernel and run that code in Ring 1?
Type-1 VMM: This is the classical trap-and-emulate VMM. The VMM runs directly on hardware, acts as a "host operating system" in Ring 0. Guest kernel and guest applications run upon VMM, in Ring 1 and Ring 3 respectively.
When Guest applications make a syscall, it will trap to Ring 0 VMM, (CPU is designed to do this).
VMM will then detect that this is a syscall, and then transfer control to the guest kernel syscal handler and execute it in Ring 1.
When it is done, the guest kernel performs syscall-return, this is a privileged call, which will trap again into VMM.
VMM then do a real return to the guest user space in ring 3. (CPU is also designed to do this.)
My question is about step 2. How does the VMM transfer control to guest kernel and force the CPU to ring 1? It couldn't be a simple "call" since then the guest kernel code will run in ring 0. It must be some kind of "syscall-return" or some special context switch instructions.
Do you have some idea? Thank you!