From: "Jan Beulich" Subject: Re: [PATCH v6 09/10] x86/hvm: Add SMAP support to HVM guest Date: Wed, 07 May 2014 12:47:30 +0100 Message-ID: <536A3972020000780000FE4B@mail.emea.novell.com> References: <1399450782-14735-1-git-send-email-feng.wu@intel.com> <1399450782-14735-10-git-send-email-feng.wu@intel.com> <536A0F19.7010704@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <536A0F19.7010704@citrix.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper , Feng Wu Cc: kevin.tian@intel.com, eddie.dong@intel.com, ian.campbell@citrix.com, jun.nakajima@intel.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org >>> On 07.05.14 at 12:46, wrote: > On 07/05/14 09:19, Feng Wu wrote: >> @@ -360,13 +362,26 @@ static inline bool_t hvm_vcpu_has_smep(void) >> >> hvm_cpuid(0, &eax, NULL, NULL, NULL); >> >> - if (eax < 7) >> + if ( eax < 7 ) >> return 0; >> >> hvm_cpuid(7, NULL, &ebx, NULL, NULL); >> return !!(ebx & cpufeat_mask(X86_FEATURE_SMEP)); >> } >> >> +static inline bool_t hvm_vcpu_has_smap(void) >> +{ >> + unsigned int eax, ebx; >> + >> + hvm_cpuid(0, &eax, NULL, NULL, NULL); >> + >> + if ( eax < 7 ) >> + return 0; >> + >> + hvm_cpuid(0x7, NULL, &ebx, NULL, NULL); > > I have just noticed a bug here and in hvm_vcpu_have_smep(). CPUID.0x7 > takes a count of 0 for the feature leaf. You should not rely on the > default value of dummy inside hvm_cpuid() for this call to work > correctly, so need to explicitly pass ecx. While I'm fine with this being made more explicit, I don't think it's a bug (not even a latent one) to rely on the default sub-leaf being zero. Jan