Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp985332imu; Fri, 25 Jan 2019 14:56:44 -0800 (PST) X-Google-Smtp-Source: ALg8bN6mSIDwznJljkocD4L20AK/P2hSfmwxV0UUvfmkTonmUKFso/OvMyUfjQqVTOn+aTM1+4Ud X-Received: by 2002:a62:2606:: with SMTP id m6mr12461764pfm.133.1548457004585; Fri, 25 Jan 2019 14:56:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548457004; cv=none; d=google.com; s=arc-20160816; b=TwumvfLDcLaU1UWslXveOt/SrIf4hFjefs9/llWN5eNES2Fse/eRNZOxNBvRRs4a7r drELqIJdzAuAjFp18k3xmBIb6/3XzhnRKiaHY/+IUOOxVx4Ob9ai2VuHCU4J48o0PMbx YOpospHTUFbOQkj6zpoLaLUw5Y6pXJ4mVWlT6X8MytnXqZ0ToAcBCxLnY3GK6E618XDT 0pcmIrWu+wIO6VlyBXGAFlKWK8MlNal8sK8WzUWAeWsMotwegVZOeaFLkfQmMoPA7b5e BVpfsgAE4j1QFncYsFRbOv55tuwNPG11vhni3dQ5mqjNz4zYeEZV0LLcPc/6LcX00TiX 6IZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=dcshyWUgaDBLr/+7cMQvOIIJOdfb9F0usqSEK492wds=; b=m9DGGCRtoYNXwAecPSaNPohHOqnCBpyVDkH/ZowMNgybUrKLPHbY0+05QG/wY8opRp B2XQSzjExN2I25xKeF55lC4uoekJJBNAapzwxJ+cl6KgJ0jTDVqgny4C9mJDuAXYqhp6 uaCoqdsB7ec5kbd/+TzM2EltlKr8TGCuX+tJJn4TGVkp6IDGrVzKuJwEli22rNxzN2eZ Ccl3dmDyU9Gs7zLbQojkXOcJQdmdV7kEkiX0ueeLnY2/59HFJMTKzqCgOjXg77Iu5v6k 4XRi7y5eSR1eP45eS+OPLl7AuQKYU8OAbW1sSiuwvEN+KiQmhvWoz9KTw7TtjG31e3Ek BGPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s24si740660plq.41.2019.01.25.14.56.29; Fri, 25 Jan 2019 14:56:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729129AbfAYW40 (ORCPT + 99 others); Fri, 25 Jan 2019 17:56:26 -0500 Received: from mga18.intel.com ([134.134.136.126]:19240 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726179AbfAYW4Z (ORCPT ); Fri, 25 Jan 2019 17:56:25 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jan 2019 14:56:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,523,1539673200"; d="scan'208";a="111149118" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.14]) by orsmga006.jf.intel.com with ESMTP; 25 Jan 2019 14:56:25 -0800 Date: Fri, 25 Jan 2019 14:56:25 -0800 From: Sean Christopherson To: Yang Weijiang Cc: pbonzini@redhat.com, rkrcmar@redhat.com, jmattson@google.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, mst@redhat.com, yu-cheng.yu@intel.com, yi.z.zhang@intel.com, hjl.tools@gmail.com, Zhang Yi Z Subject: Re: [PATCH v2 6/7] KVM:VMX: Load Guest CET via VMCS when CET is enabled in Guest Message-ID: <20190125225625.GF21849@linux.intel.com> References: <20190122205909.24165-1-weijiang.yang@intel.com> <20190122205909.24165-7-weijiang.yang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190122205909.24165-7-weijiang.yang@intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 23, 2019 at 04:59:08AM +0800, Yang Weijiang wrote: > "Load Guest CET state" bit controls whether guest CET states > will be loaded on Guest entry. Before doing that, KVM needs > to check if CET feature is exposed to Guest. > > Signed-off-by: Zhang Yi Z > Signed-off-by: Yang Weijiang > --- > arch/x86/kvm/vmx.c | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 68c0e5e41cb1..9c8cecac80ea 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -55,6 +55,7 @@ > #include > #include > #include > +#include > > #include "trace.h" > #include "pmu.h" > @@ -4065,6 +4066,18 @@ static inline bool vmx_feature_control_msr_valid(struct kvm_vcpu *vcpu, > return !(val & ~valid_bits); > } > > +static int vmx_guest_cet_cap(struct kvm_vcpu *vcpu) > +{ > + struct kvm_cpuid_entry2 *best; > + int r = 0; > + > + best = kvm_find_cpuid_entry(vcpu, 7, 0); > + if (best && best->function == 0x7) > + r = (best->ecx & bit(X86_FEATURE_SHSTK)) | > + (best->edx & bit(X86_FEATURE_IBT)) ? 1 : 0; > + return r; > +} > + > static int vmx_get_msr_feature(struct kvm_msr_entry *msr) > { > switch (msr->index) { > @@ -5409,6 +5422,26 @@ static int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) > return 1; > } > > + /* > + * To enable Guest CET, first check if Guest CET feature is > + * available, if it's not available but its CR4.CET is being set, > + * return a fault to Guest; then check if Host CET is enabled and > + * CR4.CET is toggled, if they are, then enable loading CET state Comment doesn't match the code. Comment says "toggled", code is just looking at "enabled". > + * bit in entry control, otherwise, clear the bit to > + * disable guest CET state loading. What happens to CET state if the control is clear? Is host state retained but inaccessible? > + */ > + if (vmx_guest_cet_cap(vcpu)) { Why not? if (guest_cpuid_has(vcpu, X86_FEATURE_SHSTK) || guest_cpuid_has(vcpu, X86_FEATURE_IBT)) { > + if (hw_cr4 & cr4 & X86_CR4_CET) { > + vmcs_set_bits(VM_ENTRY_CONTROLS, > + VM_ENTRY_LOAD_GUEST_CET_STATE); > + } else { > + vmcs_clear_bits(VM_ENTRY_CONTROLS, > + VM_ENTRY_LOAD_GUEST_CET_STATE); > + } > + } else if (cr4 & X86_CR4_CET) { > + return 1; > + } > + > if (to_vmx(vcpu)->nested.vmxon && !nested_cr4_valid(vcpu, cr4)) > return 1; > > -- > 2.17.1 >