From cb8a5cba9b3796e090c3d7a7eb1b67d38c9d7e0d Mon Sep 17 00:00:00 2001
From: "iliya.saroukha" <iliya.saroukhanian@etu.hesge.ch>
Date: Wed, 4 Dec 2024 16:07:36 +0100
Subject: [PATCH] feat: added macros for reading values from IA32_VMX_BASIC,
 lots of thing to debug i suppose

---
 proto/hypervisor.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/proto/hypervisor.c b/proto/hypervisor.c
index 5061d48..4f630e5 100755
--- a/proto/hypervisor.c
+++ b/proto/hypervisor.c
@@ -22,6 +22,9 @@
 // regions
 #define IA32_VMX_BASIC (0x480)
 
+#define VMCS_REVISION_ID (__rdmsr(IA32_VMX_BASIC) & 0x7fffffff)
+#define REGION_SIZE ((__rdmsr(IA32_VMX_BASIC) >> 32) & 0x1fff)
+
 // Appendix 8 p. 4'592 of Intel SDM
 #define IA32_VMX_CR0_FIXED0 (0x486)
 #define IA32_VMX_CR0_FIXED1 (0x487)
@@ -158,7 +161,7 @@ static int my_init(void) {
 
     printk(KERN_INFO "Allocating memory for VMXON region\n");
 
-    if (!vmxon_region_alloc()) {
+    if (vmxon_region_alloc() != 0) {
         pr_err("Failed to allocated memory for the VMXON region\n");
         return -1;
     }
@@ -174,7 +177,10 @@ static int my_init(void) {
     unsigned long long vmx_basic_msr = __rdmsr(IA32_VMX_BASIC);
     pr_debug("IA32_VMX_BASIC_MSR = 0x%llx\n", vmx_basic_msr);
 
-    unsigned long vmcs_revision_id = vmx_basic_msr & 0x7fffffff;
+    unsigned long size_to_alloc = REGION_SIZE;
+    pr_debug("Region size to allocate = 0x%lx\n", size_to_alloc);
+
+    unsigned long vmcs_revision_id = VMCS_REVISION_ID;
     pr_debug("VMCS revision identifier = 0x%lx\n", vmcs_revision_id);
 
     return 0;
-- 
GitLab