I have been playing around with VMX and KVM and have a few more general and some more precise questions.
- I created a VM with the virtual manager because I assumed (from what I have read online) it to be the easiest way to have a guest running Ubuntu 18.04 (in my case) or, in general, an entire operating system. Does this add/change anything from the KVM/qemu implementation, or is it just an interface?
- As far as I understood in KVM (when the kernel modules (kvm and kvm_intel) are inserted), the kernel does take the role of a hypervisor. Is this correct? Under this assumption, I assumed that a new kernel module would then be part of the hypervisor. In a basic kernel module, I used VMREAD to read out a few values from the VMCS. One of the values was the GUEST_IDTR_BASE (defined in vmx.h ) to read out the IDTR of the guest. For some reason, the HOST_IDTR and the GUEST_IDTR have the same value? Is this correct? If yes, what is the reason behind it, and if not, what am I not understanding?
- I tried to change the handle_monitor_trap in vmx.c adding just some print statement to understand if something happens and when it is called and recompiled the kvm_intel module. When I then, in a separate module, change the MTF bit (following the intel manual, it should be the 27th bit in the CPU_BASED_VM_EXEC_CONTROL) with
__asm__ __volatile__ ("vmwrite %[value], %[encoding]; setna %[ret]"
: [ret]"=rm"(ret)
: [value]"rm"(value), [encoding]"r"(encoding) : "cc", "memory");
where value is the old value I read from CPU_BASED_VM_EXEC_CONTROL OR 0x8000000 and encoding is just the CPU_BASED_VM_EXEC_CONTROL. when I insert the module into the kernel (and of course only when the VM is running) the handler I modified is called. Problems:
- After a very brief amount of time, it just stops (and the bit is again 0). Does something reset the bit? How does this happen? Is qemu also somehow involved?
- When printing out the Rip, for example, while executing a loop in the guest, the Rip that is being printed increases every step and never goes back. What is vm executing? Am I even exiting the correct VM or is there some other structure I am not aware of in KVM or in qemu?
I disabled all but one cpu to be sure that I would change the "correct" VMCS since, if I understood it correctly from the manual, there could be different VMCS on different cores.
In general, I would be very grateful for any help you can give me. If you also have any tips on navigating the source code better, I would be very thankful since my experience is minimal.