From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH] x86/vmx: correct the SMEP logic for HVM_CR0_GUEST_RESERVED_BITS Date: Wed, 23 Apr 2014 10:43:16 +0100 Message-ID: <53578B34.5010707@citrix.com> References: <1398263547-31877-1-git-send-email-feng.wu@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1398263547-31877-1-git-send-email-feng.wu@intel.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Feng Wu Cc: kevin.tian@intel.com, ian.campbell@citrix.com, eddie.dong@intel.com, xen-devel@lists.xen.org, JBeulich@suse.com, jun.nakajima@intel.com List-Id: xen-devel@lists.xenproject.org On 23/04/14 15:32, Feng Wu wrote: > When checking the SMEP feature for HVM guests, we should check the > VCPU instead of the host CPU. > > Signed-off-by: Feng Wu > --- > xen/include/asm-x86/hvm/hvm.h | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h > index dcc3483..74a09ef 100644 > --- a/xen/include/asm-x86/hvm/hvm.h > +++ b/xen/include/asm-x86/hvm/hvm.h > @@ -351,6 +351,15 @@ static inline int hvm_event_pending(struct vcpu *v) > return hvm_funcs.event_pending(v); > } > > +static inline bool_t hvm_vcpu_has_smep(void) > +{ > + unsigned int ebx = 0, leaf = 0x7; You need to check hvm_cpuid.0.eax for max leaf. ~Andrew > + > + hvm_cpuid(leaf, NULL, &ebx, NULL, NULL); > + > + return !!(ebx & cpufeat_mask(X86_FEATURE_SMEP)); > +} > + > /* These reserved bits in lower 32 remain 0 after any load of CR0 */ > #define HVM_CR0_GUEST_RESERVED_BITS \ > (~((unsigned long) \ > @@ -370,7 +379,7 @@ static inline int hvm_event_pending(struct vcpu *v) > X86_CR4_DE | X86_CR4_PSE | X86_CR4_PAE | \ > X86_CR4_MCE | X86_CR4_PGE | X86_CR4_PCE | \ > X86_CR4_OSFXSR | X86_CR4_OSXMMEXCPT | \ > - (cpu_has_smep ? X86_CR4_SMEP : 0) | \ > + (hvm_vcpu_has_smep() ? X86_CR4_SMEP : 0) | \ > (cpu_has_fsgsbase ? X86_CR4_FSGSBASE : 0) | \ > ((nestedhvm_enabled((_v)->domain) && cpu_has_vmx)\ > ? X86_CR4_VMXE : 0) | \