From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752585AbdHGIgy (ORCPT ); Mon, 7 Aug 2017 04:36:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35570 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752505AbdHGIgw (ORCPT ); Mon, 7 Aug 2017 04:36:52 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8CA5DC047B70 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=david@redhat.com Subject: Re: [PATCH v2 3/3] KVM: x86: use general helpers for some cpuid manipulation To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini References: <20170804221250.27674-1-rkrcmar@redhat.com> <20170804221250.27674-4-rkrcmar@redhat.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: Date: Mon, 7 Aug 2017 10:36:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170804221250.27674-4-rkrcmar@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 07 Aug 2017 08:36:52 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05.08.2017 00:12, Radim Krčmář wrote: > Add guest_cpuid_clear() and use it instead of kvm_find_cpuid_entry(). > Also replace some uses of kvm_find_cpuid_entry() with guest_cpuid_has(). > > Signed-off-by: Radim Krčmář > --- > v2: added __always_inline (Paolo) > --- > arch/x86/kvm/cpuid.h | 9 +++++++++ > arch/x86/kvm/svm.c | 5 +---- > arch/x86/kvm/vmx.c | 6 ++---- > arch/x86/kvm/x86.c | 14 ++------------ > 4 files changed, 14 insertions(+), 20 deletions(-) > > diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h > index 4e9ac93b4f3a..ac15193e5e52 100644 > --- a/arch/x86/kvm/cpuid.h > +++ b/arch/x86/kvm/cpuid.h > @@ -104,6 +104,15 @@ static __always_inline bool guest_cpuid_has(struct kvm_vcpu *vcpu, unsigned x86_ > return *reg & bit(x86_feature); > } > > +static __always_inline void guest_cpuid_clear(struct kvm_vcpu *vcpu, unsigned x86_feature) > +{ > + int *reg; you could instantiate it directly. > + > + reg = guest_cpuid_get_register(vcpu, x86_feature); > + if (reg) > + *reg &= ~bit(x86_feature); > +} > + > static inline bool guest_cpuid_is_amd(struct kvm_vcpu *vcpu) > { > struct kvm_cpuid_entry2 *best; > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > index b8196aecbdcc..2432bb952a30 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -5075,7 +5075,6 @@ static u64 svm_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) > static void svm_cpuid_update(struct kvm_vcpu *vcpu) > { > struct vcpu_svm *svm = to_svm(vcpu); > - struct kvm_cpuid_entry2 *entry; > > /* Update nrips enabled cache */ > svm->nrips_enabled = !!guest_cpuid_has(&svm->vcpu, X86_FEATURE_NRIPS); > @@ -5083,9 +5082,7 @@ static void svm_cpuid_update(struct kvm_vcpu *vcpu) > if (!kvm_vcpu_apicv_active(vcpu)) > return; > > - entry = kvm_find_cpuid_entry(vcpu, 1, 0); > - if (entry) > - entry->ecx &= ~bit(X86_FEATURE_X2APIC); > + guest_cpuid_clear(vcpu, X86_FEATURE_X2APIC); > } > > static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry) > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 85b73c1f963a..1731c7aca464 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -9472,15 +9472,13 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu) > > if (vmx_invpcid_supported()) { > /* Exposing INVPCID only when PCID is exposed */ > - struct kvm_cpuid_entry2 *best = kvm_find_cpuid_entry(vcpu, 0x7, 0); > bool invpcid_enabled = > - best && best->ebx & bit(X86_FEATURE_INVPCID) && > + guest_cpuid_has(vcpu, X86_FEATURE_INVPCID) && > guest_cpuid_has(vcpu, X86_FEATURE_PCID); > > if (!invpcid_enabled) { > secondary_exec_ctl &= ~SECONDARY_EXEC_ENABLE_INVPCID; > - if (best) > - best->ebx &= ~bit(X86_FEATURE_INVPCID); > + guest_cpuid_clear(vcpu, X86_FEATURE_INVPCID); just how I wanted it :) > } > > if (nested) { > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index ee4e251c82fc..33fd6b6419ef 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -1022,21 +1022,11 @@ bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer) > if (efer & efer_reserved_bits) > return false; > > - if (efer & EFER_FFXSR) { > - struct kvm_cpuid_entry2 *feat; > - > - feat = kvm_find_cpuid_entry(vcpu, 0x80000001, 0); > - if (!feat || !(feat->edx & bit(X86_FEATURE_FXSR_OPT))) > + if (efer & EFER_FFXSR && !guest_cpuid_has(vcpu, X86_FEATURE_FXSR_OPT)) > return false; > - } > > - if (efer & EFER_SVME) { > - struct kvm_cpuid_entry2 *feat; > - > - feat = kvm_find_cpuid_entry(vcpu, 0x80000001, 0); > - if (!feat || !(feat->ecx & bit(X86_FEATURE_SVM))) > + if (efer & EFER_SVME && !guest_cpuid_has(vcpu, X86_FEATURE_SVM)) > return false; > - } > > return true; > } > Very nice cleanup. Reviewed-by: David Hildenbrand -- Thanks, David