From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BEFDC282C0 for ; Fri, 25 Jan 2019 22:56:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7405F21855 for ; Fri, 25 Jan 2019 22:56:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729401AbfAYW40 (ORCPT ); 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 >