Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp202678pxb; Wed, 3 Feb 2021 03:30:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjdfP30ACpNI0tUhRyHEleGP7xhmGdruT8oJtNwF3n3Pa/0giJF8j9Xu0RhSUS6B1AWdzb X-Received: by 2002:a17:906:447:: with SMTP id e7mr2748026eja.172.1612351838867; Wed, 03 Feb 2021 03:30:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612351838; cv=none; d=google.com; s=arc-20160816; b=iQAxju1JsayA9OgtlW07or/IymQEwkf5xepcyT7ExphEySoCeY3YhVxAqqRqrNWAQ3 N5tqF4lXrSz5Ny5EEjrtxN8Y1zR43107QoDjd63cdXTdPYIuKHvy0VKOirl4EpiHh0Y7 BJEqikO/ZSOw3Tc5HJBmRPMQC/13xZrbltAvWw8m4mpsIh+zyaZz56pQWIfIQpHmICjA aACuLrKf+cf1HDZsoTd9nwomuHeBCVf6SJhlP+VlGT7ntL4ZeXdkvrbKN+Pvfp0E7EQT PUgpqHlO8W1+Wsg4hwE6YesyHxuxaT2yQJyJuciUGPpEySDVTYBi0Q13JHGkEy00W39K Ysfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=ED5GfyDwp8BLVLaJajVm1Fs6pxb67+rFkBhXjP73XJ4=; b=XAMAIH9avLIF2PsiMBWbKi23asnjiJkU8yYPvp25UcOo/orCXGO0t7/+p8ZDSq1gLX QBeVyZgvR52nfygMe7BoE8B+2eY/06MnqZG+oM9hS4ZStQ+dOBKfKr2wYXzW1CFKbTvS oodX4+nNIE8Yz8fYPYJhiU+j6RS1J69/GVnHGwnBXwjuZlpLdUPS1dvnC+/Pln6i+kXG 86wXMMkDrF5od/tPa3whY4XN23/dbkG/DoTW8P27/EmCDHL8bLt+iprRinVZ6sf0BTPh WYhhRUymPxk6bZx20W6LPfaE+QxwD1knucRJxCU7yxGFnY44EAdPimPMPAs8KCuGS1sR JajQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id y16si464234edi.542.2021.02.03.03.30.14; Wed, 03 Feb 2021 03:30:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S234120AbhBCL0w (ORCPT + 99 others); Wed, 3 Feb 2021 06:26:52 -0500 Received: from mga01.intel.com ([192.55.52.88]:28346 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234221AbhBCLYK (ORCPT ); Wed, 3 Feb 2021 06:24:10 -0500 IronPort-SDR: y3ZxE26+OHuBD5jHiRo1eJ9cvdkZtSYVAMl9+2DBmTBQDEaNLUyGIZPRi8qNPWiPm9cWuN8Gyk 6VGd8RVFdKnQ== X-IronPort-AV: E=McAfee;i="6000,8403,9883"; a="199981316" X-IronPort-AV: E=Sophos;i="5.79,398,1602572400"; d="scan'208";a="199981316" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2021 03:22:27 -0800 IronPort-SDR: kvMKIEOXyxTV7KTYiLGyzsTEjvlcVqfmUlDnDBRwdrTCILho+RSMt99tRgrErnicc6j9JgFDZ4 ozn06tUOpk8Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,398,1602572400"; d="scan'208";a="480311207" Received: from unknown (HELO local-michael-cet-test.sh.intel.com) ([10.239.159.166]) by fmsmga001.fm.intel.com with ESMTP; 03 Feb 2021 03:22:25 -0800 From: Yang Weijiang To: pbonzini@redhat.com, seanjc@google.com, jmattson@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yu.c.zhang@linux.intel.com, Yang Weijiang Subject: [PATCH v15 11/14] KVM: VMX: Pass through CET MSRs to the guest when supported Date: Wed, 3 Feb 2021 19:34:18 +0800 Message-Id: <20210203113421.5759-12-weijiang.yang@intel.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20210203113421.5759-1-weijiang.yang@intel.com> References: <20210203113421.5759-1-weijiang.yang@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pass through all CET MSRs when the associated CET component (kernel vs. user) is enabled to improve guest performance. All CET MSRs are context switched, either via dedicated VMCS fields or XSAVES. Co-developed-by: Zhang Yi Z Signed-off-by: Zhang Yi Z Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Yang Weijiang --- arch/x86/kvm/vmx/vmx.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index c2242fc1f71a..b6657117191b 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -659,6 +659,10 @@ static bool is_valid_passthrough_msr(u32 msr) case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B: /* PT MSRs. These are handled in pt_update_intercept_for_msr() */ return true; + case MSR_IA32_U_CET: + case MSR_IA32_S_CET: + case MSR_IA32_PL0_SSP ... MSR_IA32_INT_SSP_TAB: + return true; } r = possible_passthrough_msr_slot(msr) != -ENOENT; @@ -7343,6 +7347,32 @@ static void update_intel_pt_cfg(struct kvm_vcpu *vcpu) vmx->pt_desc.ctl_bitmask &= ~(0xfULL << (32 + i * 4)); } +static bool is_cet_state_supported(struct kvm_vcpu *vcpu, u32 xss_state) +{ + return (vcpu->arch.guest_supported_xss & xss_state) && + (guest_cpuid_has(vcpu, X86_FEATURE_SHSTK) || + guest_cpuid_has(vcpu, X86_FEATURE_IBT)); +} + +static void vmx_update_intercept_for_cet_msr(struct kvm_vcpu *vcpu) +{ + bool incpt = !is_cet_state_supported(vcpu, XFEATURE_MASK_CET_USER); + + vmx_set_intercept_for_msr(vcpu, MSR_IA32_U_CET, MSR_TYPE_RW, incpt); + + incpt |= !guest_cpuid_has(vcpu, X86_FEATURE_SHSTK); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_PL3_SSP, MSR_TYPE_RW, incpt); + + incpt = !is_cet_state_supported(vcpu, XFEATURE_MASK_CET_KERNEL); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_S_CET, MSR_TYPE_RW, incpt); + + incpt |= !guest_cpuid_has(vcpu, X86_FEATURE_SHSTK); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_INT_SSP_TAB, MSR_TYPE_RW, incpt); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_PL0_SSP, MSR_TYPE_RW, incpt); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_PL1_SSP, MSR_TYPE_RW, incpt); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_PL2_SSP, MSR_TYPE_RW, incpt); +} + static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); @@ -7386,6 +7416,9 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) /* Refresh #PF interception to account for MAXPHYADDR changes. */ update_exception_bitmap(vcpu); + + if (kvm_cet_supported()) + vmx_update_intercept_for_cet_msr(vcpu); } static __init void vmx_set_cpu_caps(void) -- 2.26.2