Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10504690rwp; Thu, 20 Jul 2023 23:34:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlFskgLpj2mcUzOIgjNPlQK/ww9T0H2f62ZxTUSEKZ86Ndsvzzxuia9F0cFGJLeohmJAhODz X-Received: by 2002:aa7:c2c4:0:b0:51d:9dd1:29d0 with SMTP id m4-20020aa7c2c4000000b0051d9dd129d0mr806690edp.23.1689921288721; Thu, 20 Jul 2023 23:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689921288; cv=none; d=google.com; s=arc-20160816; b=Sw96VFm4GFTAteAZEAuUb1rs+pM+e9IMR/YTqa3/CiXyOaUsqSsrxxJD1PPvWnO0mH Pv5DTkhy1f6ic3ZTawWKao+wYCBxfS526QfQBVTPuvD7zuAr5TkoX2Gdo2oo/MT0+3Hy /daDjhQDN06Fi5n7lPCK9kExyGlZrEiBCcL0kNHnz96+4AZEcoFh/eDP4+ctaGCxgfiN CwG6PfE3j9GzpObJ2eqnf9WLwduK5hbJTdu2eV/ydAw9JeA3Fw35/jhROseJt4Q99pbW MkI4YYkUwCEXeRNmSDdAXdW75LkY8C/w2uIVKxv2WZK/iRWxARUTIS8GJh2YDh9OF8Fz LyGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mMP675WzkoJDrLn74OGhWK5kBjoJUo2mQTlJXswLTNI=; fh=Opje+PjCQx5n1tZXLBqSYGCQ4Th9+H4dl5HcyP+qSnE=; b=wS6bwa5XkE/bDTJI4OU0xvqaZPa990SJyY6o7ShME8wxhrYl8EKKqK0p6qMKldkGFk n+xCPr7qo9kQq4cc11ngn4vRCa2cjjQWcTwe6PULNSlMeCRuJrJDzSC75Vb7L9GTEPJS 9fZxX8mr7Oq7/oZUtVhpT0IQ7zeiyEGBubh9FGHFsL79KOodDlkLdhL9LVZpuRUWguDj Gc8bFvaKrBnIIl1ipdOoKJq1gDQ3S7EuAJuqJUeERemiJd2el/AyrhbFhMFXaIa5hQCM +GAl2zNs3RU8/tIVXcZnWbI0xyF54MUgj+97HNjInTMjO30T/HPVubFFOZdC3jpgVlVG jFtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XdeoyaG7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o6-20020aa7c506000000b0051df215a297si1992475edq.641.2023.07.20.23.34.24; Thu, 20 Jul 2023 23:34:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XdeoyaG7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230382AbjGUGJn (ORCPT + 99 others); Fri, 21 Jul 2023 02:09:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230022AbjGUGI5 (ORCPT ); Fri, 21 Jul 2023 02:08:57 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3B5E92; Thu, 20 Jul 2023 23:08:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689919736; x=1721455736; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=szDn5JNOEksWSPekEwByzDTDJlcIsFrl8fPjFl+HRyw=; b=XdeoyaG7Eqr2Do1djMaqHqadVtgSscQ+MuSjjNA9pKrJ15F/NgMeJjFX OrkVneXxNSjn6zg0jlpCQyekWIbDgmcGwJfeZGuMTQQIdbudVIikPZCMk CHM26XqpUWoSuHQ91iWiLzFYa6hmuhD1LZ2DZ0bzGUDRhZdVH+96B1Myu mL5tEyy0kF25hCBIZFOzJF0rgO4mAfk5wiPQbuvBRsYyDI2Z9Fr1pyFaC pq2WbRtojjZYwp7ZahuYBmLinaJF+Bpj94Lwz1L1+fsfZa28/N0IVjkXN Bsh0CzgsjjCPqBb3z75YkADCUFc6ba39C3ffairFg4DYJVltvVroqDba/ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="370547556" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="370547556" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 23:08:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="848721981" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="848721981" Received: from embargo.jf.intel.com ([10.165.9.183]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 23:08:41 -0700 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, john.allen@amd.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: rick.p.edgecombe@intel.com, chao.gao@intel.com, binbin.wu@linux.intel.com, weijiang.yang@intel.com Subject: [PATCH v4 14/20] KVM:VMX: Set up interception for CET MSRs Date: Thu, 20 Jul 2023 23:03:46 -0400 Message-Id: <20230721030352.72414-15-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230721030352.72414-1-weijiang.yang@intel.com> References: <20230721030352.72414-1-weijiang.yang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DATE_IN_PAST_03_06, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pass through CET MSRs when the associated feature is enabled. Shadow Stack feature requires all the CET MSRs to make it architectural support in guest. IBT feature only depends on MSR_IA32_U_CET and MSR_IA32_S_CET to enable both user and supervisor IBT. Signed-off-by: Yang Weijiang --- arch/x86/kvm/vmx/vmx.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b29817ec6f2e..85cb7e748a89 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -709,6 +709,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; @@ -7758,6 +7762,34 @@ 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) +{ + if (guest_can_use(vcpu, X86_FEATURE_SHSTK)) { + vmx_set_intercept_for_msr(vcpu, MSR_IA32_U_CET, + MSR_TYPE_RW, false); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_S_CET, + MSR_TYPE_RW, false); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_PL0_SSP, + MSR_TYPE_RW, false); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_PL1_SSP, + MSR_TYPE_RW, false); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_PL2_SSP, + MSR_TYPE_RW, false); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_PL3_SSP, + MSR_TYPE_RW, false); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_INT_SSP_TAB, + MSR_TYPE_RW, false); + return; + } + + if (guest_can_use(vcpu, X86_FEATURE_IBT)) { + vmx_set_intercept_for_msr(vcpu, MSR_IA32_U_CET, + MSR_TYPE_RW, false); + vmx_set_intercept_for_msr(vcpu, MSR_IA32_S_CET, + MSR_TYPE_RW, false); + } +} + static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); @@ -7825,6 +7857,9 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) /* Refresh #PF interception to account for MAXPHYADDR changes. */ vmx_update_exception_bitmap(vcpu); + + if (kvm_is_cet_supported()) + vmx_update_intercept_for_cet_msr(vcpu); } static u64 vmx_get_perf_capabilities(void) -- 2.27.0