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

todo: need to understand thoroughly the code added

parent 9cea4db9
No related branches found
No related tags found
No related merge requests found
......@@ -2,12 +2,54 @@
#include <linux/init.h> /* Needed for the macros */
#include <linux/module.h> /* Needed by all modules */
#define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX (1 << 2)
#define FEATURE_CONTROL_LOCKED (1 << 0)
#define MSR_IA32_FEATURE_CONTROL 0x0000003a
/*asm ( assembler template*/
/* : output operands (optional)*/
/* : input operands (optional)*/
/* : clobbered registers list (optional)*/
/* );*/
static bool getVmxOperation(void) {
/*
* Configure IA32_FEATURE_CONTROL MSR to allow VMXON:
* Bit 0: Lock bit. If clear, VMXON causes a #GP.
* Bit 2: Enables VMXON outside of SMX operation. If clear, VMXON
* outside of SMX causes a #GP.
*/
unsigned long cr0, cr4;
unsigned long long required, feature_control;
unsigned long low1 = 0;
required = FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX;
required |= FEATURE_CONTROL_LOCKED;
feature_control = __rdmsr(MSR_IA32_FEATURE_CONTROL);
printk(KERN_INFO "RDMS output is %ld\n", (long)feature_control);
if ((feature_control & required) != required) {
wrmsr(MSR_IA32_FEATURE_CONTROL, feature_control | required, low1);
}
/*
* Ensure bits in CR0 and CR4 are valid in VMX operation:
* - Bit X is 1 in _FIXED0: bit X is fixed to 1 in CRx.
* - Bit X is 0 in _FIXED1: bit X is fixed to 0 in CRx.
*/
__asm__ volatile("mov %%cr0, %0" : "=r"(cr0) : : "memory");
cr0 &= __rdmsr(MSR_IA32_VMX_CR0_FIXED1);
cr0 |= __rdmsr(MSR_IA32_VMX_CR0_FIXED0);
__asm__ volatile("mov %0, %%cr0" : : "r"(cr0) : "memory");
__asm__ volatile("mov %%cr4, %0" : "=r"(cr4) : : "memory");
cr4 &= __rdmsr(MSR_IA32_VMX_CR4_FIXED1);
cr4 |= __rdmsr(MSR_IA32_VMX_CR4_FIXED0);
__asm__ volatile("mov %0, %%cr4" : : "r"(cr4) : "memory");
return true;
}
static void enable_vmx(void) {
unsigned long cr4;
......@@ -38,6 +80,11 @@ static int my_init(void) {
printk(KERN_INFO "VMX has been successfully enabled!\n");
if (!getVmxOperation()) {
printk(KERN_INFO "VMX operation couldn't correctly setup\n");
return -1;
}
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment