diff --git a/proto/hypervisor.c b/proto/hypervisor.c index 2f262fad3185ac07299d07298b999d24a04934b9..3984043ca7b6ce13eda48405de6b01042ce6468a 100644 --- a/proto/hypervisor.c +++ b/proto/hypervisor.c @@ -79,6 +79,20 @@ static unsigned char vmxon(unsigned long long pa) { } static int my_init(void) { + /* + * https://www.sciencedirect.com/topics/computer-science/current-privilege-level + */ + DEBUG_FMT("Querying CS (lowest 2 bits) for CPL\n"); + unsigned long cs, cpl; + + __asm__ volatile("mov %%cs, %0" : "=r"(cs)); + cpl = cs & 0x3; + + DEBUG_FMT("CPL level = %lu\n", cpl); + if (cpl > 0) { + return -1; + } + pr_info("Checking VMX support using CPUID\n"); if (!vmx_support_cpuid()) { pr_err("VMX isn't supported\n"); @@ -119,6 +133,9 @@ static int my_init(void) { unsigned char vmxon_ret = 0; if ((vmxon_ret = vmxon(vmxon_region.pa) != 0)) { + /*unsigned long vm_err = __rdmsr(0x4400);*/ + /*pr_err("VM_ERR val = 0x%lx\n", vm_err);*/ + kfree(vmxon_region.va); __asm__ volatile("vmxoff"); pr_err("`vmxon` failed with return code %d\n", vmxon_ret);