Enable and register vcpu_state information to the host Signed-off-by: Nikunj A. Dadhania diff --git a/x86/vmexit.c b/x86/vmexit.c index ad8ab55..a9823c9 100644 --- a/x86/vmexit.c +++ b/x86/vmexit.c @@ -3,6 +3,7 @@ #include "smp.h" #include "processor.h" #include "atomic.h" +#include "vm.h" static unsigned int inl(unsigned short port) { @@ -173,10 +174,45 @@ static void enable_nx(void *junk) wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_NX_MASK); } +#define KVM_MSR_ENABLED 1 +#define KVM_FEATURE_VCPU_STATE 7 +#define MSR_KVM_VCPU_STATE 0x4b564d04 + +struct kvm_vcpu_state { + int state; + int flush_on_enter; + int pad[14]; +}; + +struct kvm_vcpu_state test[4]; + +static inline void my_wrmsr(unsigned int msr, + unsigned low, unsigned high) +{ + asm volatile("wrmsr" : : "c" (msr), "a"(low), "d" (high) : "memory"); +} +#define wrmsrl(msr, val) my_wrmsr(msr, (u32)((u64)(val)), ((u64)(val))>>32) + +static void enable_vcpu_state(void *junk) +{ + struct kvm_vcpu_state *vs; + int me = smp_id(); + + if (cpuid(0x80000001).d & (1 << KVM_FEATURE_VCPU_STATE)) { + vs = &test[me]; + memset(vs, 0, sizeof(struct kvm_vcpu_state)); + + wrmsrl(MSR_KVM_VCPU_STATE, ((unsigned long)(vs) | KVM_MSR_ENABLED)); + printf("%d: Done vcpu state %p\n", me, virt_to_phys((void*)vs)); + } +} + bool test_wanted(struct test *test, char *wanted[], int nwanted) { int i; + return true; + if (!nwanted) return true; @@ -192,11 +228,16 @@ int main(int ac, char **av) int i; smp_init(); + setup_vm(); + nr_cpus = cpu_count(); for (i = cpu_count(); i > 0; i--) on_cpu(i-1, enable_nx, 0); + for (i = cpu_count(); i > 0; i--) + on_cpu(i-1, enable_vcpu_state, 0); + for (i = 0; i < ARRAY_SIZE(tests); ++i) if (test_wanted(&tests[i], av + 1, ac - 1)) do_test(&tests[i]);