Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp25480rdb; Thu, 21 Dec 2023 01:30:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8KOp3M8gnxCRbxQN6VH+m87kj8KKXxUb6N4UK5H86XCmSM0+zPznoMAMHdru5KPU+gbkz X-Received: by 2002:a9d:744b:0:b0:6d9:d132:ef24 with SMTP id p11-20020a9d744b000000b006d9d132ef24mr21919424otk.25.1703151029921; Thu, 21 Dec 2023 01:30:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703151029; cv=none; d=google.com; s=arc-20160816; b=RtmekOoC+dcUsJXtEomXTa7ehPtKjSZ//kMRRZAU8AzSjswXiWJ9d7Lncprk429imo 3rUjFGzV/HHTWdJvFGXgDoQft55R2WH/5ei2fqkmITk2y+H86cdRfThMwv9kN8ZpqziW HVIR8D9+YqOfAX6Me+C48pddpiK9zTd+0x0ULgLytrBpePv9Y2SEme+V5h46xpI4fhTZ d/jQlHppUL5+8zdcS/BtIOsDE0WB05xDo/xaAHQFTEgNP+9tBQANYACQYYnbe65RsqtW Qb/KTDpNXxQYckHzdV2voR6Z2zrl3vkgzv8eUyxdXzLmnuQ9FD+6BaaTFh1u7SALKzjg qzeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zCNuBv9tCcjwxH7L7ypsk7gHZFBXGHab5SiPL32Xa40=; fh=uy0EBGgYIm8+MgsxUvKHUXUo3s9z4H9hdLwRv8YoeJU=; b=ntM1Zo+ghjw5rZwJOu1rGTHBN3Vliu30mGX4VwdZZ7yGC8PIM7xuVXY7nwlhJaJgcs GSlYr34d0M33LmkBbg42qp5C+vLeqVtfuKsR1Fke55B2nuGdQR4Izo8NQGwcceqJtH+j 000TLjtrTMj6m7pp+HctHkpLCH6UXVAdRgVbkOG8ygMc02l8Tw44sQov8r0LVyKJVTi5 bM1fbE4huNdJ8Cb18D+zOzTo2XkBYBeg/zSoRcg8b5nwhoKgnBGy5JtGMTAifmo04wo+ Tb0XikIgMhxvZF9x3UowOjBY8ELscVAHzsW040IAB2lx+k/Kt2tIz31lTkO0kxLEKi+S hXPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P0cXIsCh; spf=pass (google.com: domain of linux-kernel+bounces-8083-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id w11-20020a65410b000000b005c67bb15866si1292733pgp.52.2023.12.21.01.30.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:30:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8083-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P0cXIsCh; spf=pass (google.com: domain of linux-kernel+bounces-8083-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 517E4B2136E for ; Thu, 21 Dec 2023 09:19:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3744F59B68; Thu, 21 Dec 2023 09:03:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="P0cXIsCh" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9EBD584CC; Thu, 21 Dec 2023 09:03:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703149436; x=1734685436; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rp976lNmbwXGmFC0F/2oL/XVVTd66ULVFJacpxwzuyg=; b=P0cXIsChvZzWgYX0e6KNfXN3mo4sp6d8SkLQF7zDDeS0wzwddxUEJNn/ 1U1skIZdBL/lkmvYDqXZbyKgS9zOYHpuP7dNYDTzBGWn7uit3rVXWmRfJ TKaX7+912sdQg7VkHWnwDgJKJ+yxaMg8abn291fZLnd6jHXd8l2EyhTfY ZyzEYbOI7WvXwwetYoQSXtxgAK6g8fmjti1+yqK9H6AioCGetmMSc35iP N8Byan286q+UiOpJ9zZHA4uUI3eVFW7sQCLspDBxfWDeMh+bVfCVLMLxn zRTTZP0CXPok+Pbr6bEzqCEBMESRWNpiTfCwBZQVlKON+A3JQ+CbO3LbA g==; X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="398729713" X-IronPort-AV: E=Sophos;i="6.04,293,1695711600"; d="scan'208";a="398729713" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2023 01:03:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="900028638" X-IronPort-AV: E=Sophos;i="6.04,293,1695711600"; d="scan'208";a="900028638" Received: from 984fee00a5ca.jf.intel.com (HELO embargo.jf.intel.com) ([10.165.9.183]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2023 01:03:11 -0800 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, mlevitsk@redhat.com, john.allen@amd.com, weijiang.yang@intel.com Subject: [PATCH v8 22/26] KVM: VMX: Set up interception for CET MSRs Date: Thu, 21 Dec 2023 09:02:35 -0500 Message-Id: <20231221140239.4349-23-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231221140239.4349-1-weijiang.yang@intel.com> References: <20231221140239.4349-1-weijiang.yang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Enable/disable CET MSRs interception per associated feature configuration. Shadow Stack feature requires all CET MSRs passed through to guest to make it supported in user and supervisor mode while IBT feature only depends on MSR_IA32_{U,S}_CETS_CET to enable user and supervisor IBT. Note, this MSR design introduced an architectural limitation of SHSTK and IBT control for guest, i.e., when SHSTK is exposed, IBT is also available to guest from architectual perspective since IBT relies on subset of SHSTK relevant MSRs. Signed-off-by: Yang Weijiang --- arch/x86/kvm/vmx/vmx.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 064a5fe87948..08058b182893 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -692,6 +692,10 @@ static bool is_valid_passthrough_msr(u32 msr) case MSR_LBR_CORE_TO ... MSR_LBR_CORE_TO + 8: /* LBR MSRs. These are handled in vmx_update_intercept_for_lbr_msrs() */ 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; @@ -7767,6 +7771,42 @@ static void update_intel_pt_cfg(struct kvm_vcpu *vcpu) vmx->pt_desc.ctl_bitmask &= ~(0xfULL << (32 + i * 4)); } +static void vmx_update_intercept_for_cet_msr(struct kvm_vcpu *vcpu) +{ + bool incpt; + + if (kvm_cpu_cap_has(X86_FEATURE_SHSTK)) { + incpt = !guest_cpuid_has(vcpu, X86_FEATURE_SHSTK); + + vmx_set_intercept_for_msr(vcpu, MSR_IA32_U_CET, + MSR_TYPE_RW, incpt); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_S_CET, + 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); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_PL3_SSP, + MSR_TYPE_RW, incpt); + if (guest_cpuid_has(vcpu, X86_FEATURE_LM)) + vmx_set_intercept_for_msr(vcpu, MSR_IA32_INT_SSP_TAB, + MSR_TYPE_RW, incpt); + if (!incpt) + return; + } + + if (kvm_cpu_cap_has(X86_FEATURE_IBT)) { + incpt = !guest_cpuid_has(vcpu, X86_FEATURE_IBT); + + vmx_set_intercept_for_msr(vcpu, MSR_IA32_U_CET, + MSR_TYPE_RW, incpt); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_S_CET, + MSR_TYPE_RW, incpt); + } +} + static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); @@ -7845,6 +7885,8 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) /* Refresh #PF interception to account for MAXPHYADDR changes. */ vmx_update_exception_bitmap(vcpu); + + vmx_update_intercept_for_cet_msr(vcpu); } static u64 vmx_get_perf_capabilities(void) -- 2.39.3