diff --git a/proto/hypervisor.c b/proto/hypervisor.c index 11b49ac33f43bceca66d205157a4c6b0a938a6ec..f0ed19ebc44c08fe121bb0b1ca81b3d60ff55f4b 100644 --- a/proto/hypervisor.c +++ b/proto/hypervisor.c @@ -16,8 +16,10 @@ #include "asm/special_insns.h" #include "asm/tlbflush.h" #include "debug/debug.h" +#include "linux/threads.h" #include "msr/msr.h" -#include "region/vxmon_reg.h" +#include "region/vxmon.h" +#include "vcpu/vcpu.h" #define NULL ((void *)0) @@ -27,7 +29,7 @@ /* : clobbered registers list (optional)*/ /* );*/ -static struct vmxon_region_t vmxon_region; +static struct vcpu_t vcpus[1]; static int cr4_enable_vmx(void) { unsigned long cr4; @@ -177,18 +179,22 @@ static int my_init(void) { DEBUG_FMT("IA32_VMX_BASIC_MSR = 0x%llx\n", __rdmsr(IA32_VMX_BASIC)); - pr_info("Initializing VMXON region\n"); - int ret_init_vmxon; - if ((ret_init_vmxon = init_vmxon_reg(&vmxon_region)) != 0) { - pr_err("Failed to initialized the VMXON region\n"); - return -ret_init_vmxon; + pr_info("Allocating VMXON region\n"); + + struct vmxon_t *vmxon_reg = alloc_vmxon(); + + if (!vmxon_reg) { + pr_err("VMXON region allocation failed\n"); + return -ENOMEM; } - pr_info("VA of the allocated region = 0x%px\n", vmxon_region.va); - pr_info("PA of the allocated region = 0x%llx\n", vmxon_region.pa); + vmxon_regions[0] = vmxon_reg; + + pr_info("VA of the allocated region = 0x%px\n", vmxon_reg); + pr_info("PA of the allocated region = 0x%lx\n", __pa(vmxon_reg)); - pr_info("Reading VMXON region for VMCS ID: 0x%lx\n", - (*(unsigned long *)vmxon_region.va)); + pr_info("Reading VMXON region for VMCS ID: 0x%x\n", + vmxon_reg->header.vmcs_rev_id); pr_info("Patching CR0 and CR4 depending on the value of their respective " "MSRs\n"); @@ -209,18 +215,18 @@ static int my_init(void) { return -EPERM; } - pr_info("Executing VMXON with address = 0x%llx as its operand\n", - vmxon_region.pa); + pr_info("Executing VMXON with address = 0x%lx as its operand\n", + __pa(vmxon_reg)); unsigned char vmxon_ret = 0; /*if ((vmxon_ret = vmxon(vmxon_region.pa) != 0)) {*/ - if ((vmxon_ret = kvm_cpu_vmxon(vmxon_region.pa) != 0)) { + if ((vmxon_ret = kvm_cpu_vmxon(__pa(vmxon_reg)) != 0)) { /*unsigned long vm_err = __rdmsr(0x4400);*/ /*pr_err("VM_ERR val = 0x%lx\n", vm_err);*/ cr4_clear_bits(13); - kfree(vmxon_region.va); + kfree(vmxon_reg); /*__asm__ volatile("vmxoff");*/ pr_err("`vmxon` failed with return code %d\n", vmxon_ret); return -1; @@ -242,7 +248,7 @@ static void my_exit(void) { } pr_info("Freeing memory of the VMXON region\n"); - kfree(vmxon_region.va); + kfree(vmxon_regions[0]); pr_info("vmbr.ko has exited\n"); }