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

wip: reading the values of cr0 and cr4 and their respective VMX MSRs

parent f486b6b1
No related branches found
No related tags found
No related merge requests found
#include "asm/cpuid.h"
#include "asm/msr.h" #include "asm/msr.h"
#include "asm/paravirt.h"
#include "linux/kern_levels.h" #include "linux/kern_levels.h"
#include "linux/printk.h" #include "linux/printk.h"
#include <linux/init.h> /* Needed for the macros */ #include <linux/init.h> /* Needed for the macros */
#include <linux/module.h> /* Needed by all modules */ #include <linux/module.h> /* Needed by all modules */
#define IA32_FEATURE_CONTROL_LOCK_BIT (1 << 0) #define IA32_FEATURE_CONTROL_LOCK_BIT (1UL << 0)
#define IA32_FEATURE_CONTROL_VMXON_IN_SMX (1 << 1) #define IA32_FEATURE_CONTROL_VMXON_IN_SMX (1UL << 1)
#define IA32_FEATURE_CONTROL_VMXON_OUTSIDE_SMX (1 << 2) #define IA32_FEATURE_CONTROL_VMXON_OUTSIDE_SMX (1UL << 2)
#define IA32_FEATURE_CONTROL_MSR (0x3a) #define IA32_FEATURE_CONTROL_MSR (0x3a)
// Appendix 8 p. 4'592 of Intel SDM
#define IA32_VMX_CR0_FIXED0 (0x486)
#define IA32_VMX_CR0_FIXED1 (0x487)
#define IA32_VMX_CR4_FIXED0 (0x488)
#define IA32_VMX_CR4_FIXED1 (0x489)
#define CR0_PE (1UL << 0)
#define CR0_NE (1UL << 5)
#define CR0_PG (1UL << 31)
/*asm ( assembler template*/ /*asm ( assembler template*/
/* : output operands (optional)*/ /* : output operands (optional)*/
/* : input operands (optional)*/ /* : input operands (optional)*/
...@@ -24,11 +36,10 @@ static void cr4_enable_vmx(void) { ...@@ -24,11 +36,10 @@ static void cr4_enable_vmx(void) {
} }
static bool vmx_supported(void) { static bool vmx_supported(void) {
int ecx; unsigned int ecx = cpuid_ecx(1);
/*__asm__ volatile("mov $1, %rax");*/
__asm__ volatile("mov $1, %rax"); /*__asm__ volatile("cpuid");*/
__asm__ volatile("cpuid"); /*__asm__ volatile("mov %%ecx , %0\n\t" : "=r"(ecx));*/
__asm__ volatile("mov %%ecx , %0\n\t" : "=r"(ecx));
return (ecx >> 5) & 1; return (ecx >> 5) & 1;
} }
...@@ -52,6 +63,24 @@ static bool ia32_feature_control_flags(void) { ...@@ -52,6 +63,24 @@ static bool ia32_feature_control_flags(void) {
return true; return true;
} }
static void reading_cr_msr(void) {
unsigned long long cr0, cr4;
__asm__ volatile("mov %%cr0, %0" : "=r"(cr0));
__asm__ volatile("mov %%cr4, %0" : "=r"(cr4));
pr_debug("CR0 = 0x%llx\n", cr0);
pr_debug("CR4 = 0x%llx\n\n", cr4);
/*unsigned long cr0_fixed0 = __rdmsr(IA32_VMX_CR0_FIXED0);*/
/*unsigned long cr0_fixed1 = __rdmsr(IA32_VMX_CR0_FIXED1);*/
pr_debug(KERN_INFO "CR0_FIXED0 = 0x%llx\n", __rdmsr(IA32_VMX_CR0_FIXED0));
pr_debug(KERN_INFO "CR0_FIXED1 = 0x%llx\n\n", __rdmsr(IA32_VMX_CR0_FIXED1));
pr_debug(KERN_INFO "CR4_FIXED0 = 0x%llx\n", __rdmsr(IA32_VMX_CR4_FIXED0));
pr_debug(KERN_INFO "CR4_FIXED1 = 0x%llx\n", __rdmsr(IA32_VMX_CR4_FIXED1));
}
static int my_init(void) { static int my_init(void) {
if (!vmx_supported()) { if (!vmx_supported()) {
printk(KERN_INFO "VMX isn't supported\n"); printk(KERN_INFO "VMX isn't supported\n");
...@@ -73,6 +102,8 @@ static int my_init(void) { ...@@ -73,6 +102,8 @@ static int my_init(void) {
printk(KERN_INFO "IA32_FEATURE_CONTROL MSR flags allow virtualization\n"); printk(KERN_INFO "IA32_FEATURE_CONTROL MSR flags allow virtualization\n");
reading_cr_msr();
return 0; return 0;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment