From 2978e6b75fb7f6fc4576a19495eaee277acdd74d Mon Sep 17 00:00:00 2001 From: "iliya.saroukha" <iliya.saroukhanian@etu.hesge.ch> Date: Tue, 10 Dec 2024 15:20:30 +0100 Subject: [PATCH] debug: trying to print out the CPL value, probably doesn't work though --- proto/hypervisor.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/proto/hypervisor.c b/proto/hypervisor.c index 2f262fa..3984043 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); -- GitLab