Skip to content
Snippets Groups Projects
Commit f715c49b authored by iliya.saroukha's avatar iliya.saroukha :first_quarter_moon:
Browse files

semi-feat: sometimes vmxon executes successfully, most of the time the CF...

semi-feat: sometimes vmxon executes successfully, most of the time the CF (Carry Flag) is set to 1..
parent c4cd2c0c
Branches
No related tags found
No related merge requests found
......@@ -12,7 +12,6 @@
/*============== my includes ==============*/
#include "debug/debug.h"
#include "linux/cleanup.h"
#include "msr/msr.h"
#include "region/vxmon_reg.h"
......@@ -24,7 +23,7 @@
/* : clobbered registers list (optional)*/
/* );*/
static struct vmxon_reg_t vmxon_region;
static struct vmxon_region_t vmxon_region;
static void cr4_enable_vmx(void) {
unsigned long cr4;
......@@ -50,10 +49,16 @@ static bool vmx_support_cpuid(void) {
static unsigned char vmxon(void *pa) {
unsigned char ret;
__asm__ __volatile__("vmxon %[pa]; setna %[ret]"
: [ret] "=rm"(ret)
: [pa] "m"(vmxon_region.pa)
: "cc", "memory");
__asm__ volatile("vmxon %[pa]; setna %[ret]"
: [ret] "=rm"(ret)
: [pa] "m"(pa)
: "cc", "memory");
unsigned long long rflags;
__asm__ volatile("pushfq; popq %0" : "=r"(rflags));
DEBUG_FMT("RFLAGS: 0x%llx\n", rflags);
return ret;
}
......@@ -86,8 +91,6 @@ static int my_init(void) {
cr4_enable_vmx();
pr_info("Checking the necessary flags of the IA32_FEATURE_CONTROL_MSR\n");
DEBUG_FMT("IA32_FEATURE_CONTROL = %llu\n",
__rdmsr(IA32_FEATURE_CONTROL_MSR));
if (!ia32_feature_control_flags()) {
pr_err("The flags of the IA32_FEATURE_CONTROL MSR do not permit "
"virtualization\n");
......@@ -97,30 +100,27 @@ static int my_init(void) {
pr_info("Executing VMXON with address = 0x%px as its operand\n",
vmxon_region.pa);
/*__asm__ volatile("vmxon %0" ::"m"(vmxon_region.pa) : "memory");*/
unsigned char vmxon_ret;
unsigned char vmxon_ret = 0;
if ((vmxon_ret = vmxon(vmxon_region.pa) != 0)) {
pr_err("vmxon failed with return code %d\n", vmxon_ret);
kfree(vmxon_region.va);
pr_err("`vmxon` failed with return code %d\n", vmxon_ret);
return -1;
}
DEBUG_FMT("vmxon ret = %d\n", vmxon_ret);
pr_info("`vmxon` was successfully executed!\n");
return 0;
}
static void my_exit(void) {
printk(KERN_INFO "Executing VMXOFF\n");
pr_info("Executing VMXOFF\n");
__asm__ volatile("vmxoff");
printk(KERN_INFO "Freeing memory of the VMXON region\n");
pr_info("Freeing memory of the VMXON region\n");
kfree(vmxon_region.va);
printk(KERN_INFO "Hypervisor has exited\n");
pr_info("vmbr.ko has exited\n");
}
module_init(my_init);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment