Message ID | 20190522234545.5930-2-krish.sadhukhan@oracle.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | kvm-unit-test: nVMX: Test "Load IA32_EFER" VM-exit control on vmentry of nested guests | expand |
On Wed, May 22, 2019 at 5:12 PM Krish Sadhukhan <krish.sadhukhan@oracle.com> wrote: > > Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com> > Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> There will likely be a lot of these over time. Why not implement something more generic, like static_cpu_has() in the kernel?
On Wed, May 22, 2019 at 07:45:44PM -0400, Krish Sadhukhan wrote: > Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com> > Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> > --- > lib/x86/processor.h | 8 ++++++++ > x86/vmexit.c | 2 +- > 2 files changed, 9 insertions(+), 1 deletion(-) > > diff --git a/lib/x86/processor.h b/lib/x86/processor.h > index 15237a5..2ca988e 100644 > --- a/lib/x86/processor.h > +++ b/lib/x86/processor.h > @@ -476,4 +476,12 @@ static inline void set_bit(int bit, u8 *addr) > : "+m" (*addr) : "Ir" (bit) : "cc", "memory"); > } > > +static inline int efer_nx_enabled(void) cpu_has_efer_nx() would be more appropriate. Most readers would expect "enabled" to mean we're checking MSR_EFER.NX==1. This can have a boolean return value. > +{ > + if (cpuid(0x80000001).d & (1 << 20)) > + return 1; > + else > + return 0; > +} This can simply be: return cpuid(0x80000001).d & (1 << 20); or if gcc complains about boolean stuff: return !!(cpuid(0x80000001).d & (1 << 20)); > + > #endif > diff --git a/x86/vmexit.c b/x86/vmexit.c > index c12dd24..7053a46 100644 > --- a/x86/vmexit.c > +++ b/x86/vmexit.c > @@ -526,7 +526,7 @@ static bool do_test(struct test *test) > > static void enable_nx(void *junk) > { > - if (cpuid(0x80000001).d & (1 << 20)) > + if (efer_nx_enabled()) > wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_NX_MASK); > } > > -- > 2.20.1 >
diff --git a/lib/x86/processor.h b/lib/x86/processor.h index 15237a5..2ca988e 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -476,4 +476,12 @@ static inline void set_bit(int bit, u8 *addr) : "+m" (*addr) : "Ir" (bit) : "cc", "memory"); } +static inline int efer_nx_enabled(void) +{ + if (cpuid(0x80000001).d & (1 << 20)) + return 1; + else + return 0; +} + #endif diff --git a/x86/vmexit.c b/x86/vmexit.c index c12dd24..7053a46 100644 --- a/x86/vmexit.c +++ b/x86/vmexit.c @@ -526,7 +526,7 @@ static bool do_test(struct test *test) static void enable_nx(void *junk) { - if (cpuid(0x80000001).d & (1 << 20)) + if (efer_nx_enabled()) wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_NX_MASK); }