Message ID | 20230524155339.415820-4-john.allen@amd.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp32800vqr; Wed, 24 May 2023 09:29:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5zdARmmhI/N66W35WfHBcZxOJ8Ltdd8PWyksWjKRfZwQHa6dNQGhBUyN1RyLjtQ/NuchrR X-Received: by 2002:a05:6a20:748e:b0:10c:9e35:857a with SMTP id p14-20020a056a20748e00b0010c9e35857amr6873885pzd.49.1684945742762; Wed, 24 May 2023 09:29:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1684945742; cv=pass; d=google.com; s=arc-20160816; b=mr1VgOoqmURPfgiDndAFH8yGoRj9b9d5SlpDgyKQHr6JqFV6TOOsL8XySmDJRpmWwU Mlw6r7J9rjutzwvDdXdNMuC5eWPwtqw62QCBzmHmp8/K49D2BBq2/Vxcwyw8v9w0d/ED rCeyGqgWQAwSsZjbSz4QVpoq2ypTBgla5j7DWW8OqVM4+l/5xBmakN6goSysRCYexrDR oGeO4QWA2akQ/JWDZrVNXJKeCzAbRok2aUFr9cHH5R7S+YleBGiblcg9XrLOBND5oTSt Wu2W5Mj9OTcoWBA02Yhv1iUgihxkHRNuDkkRCizqtbGATbOsYNA2ky8ai7G1h+xhmzTY G6hw== ARC-Message-Signature: i=2; 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=bhJQrei0cPAAxb+GVVGUWNvRMGgni/3k1a10NVoTUFU=; b=VWyeTsmfXJ/RBMV2GXG3QAOddDhpsd8ZKgPX0DREoEEHjRrsfKAsUTgcUj92tFyJOJ aiy2P4lbfele5or18jPgPbIMqkrOQFOUWcbEYtT02ynyWFMpTyCqS7WOVD68qaKNYz+Q h/6TRwANyhc/dsEuGjndT5qG7449xWGeUPcv9E3xoqxMKzaTQ8+Sh8ePnWGaOsuJpmPi MO4likNtFHReo7rTjHgvSsALFIxH0As2qiWt3Iw2ryGLwkQccCLeTQQU/VhOrv3f86sh jVmuKDf9L0Wy3Zee/HuRb63tiqsSTV7QJ15Gx3E6wVrriNXXFS9Dvq/o/XSQmG+VNq5j EpBw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="H0T7jq/l"; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i186-20020a626dc3000000b0064d2b6d84a6si8650680pfc.159.2023.05.24.09.28.47; Wed, 24 May 2023 09:29:02 -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=@amd.com header.s=selector1 header.b="H0T7jq/l"; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237560AbjEXPyp (ORCPT <rfc822;ahmedalshaiji.dev@gmail.com> + 99 others); Wed, 24 May 2023 11:54:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237544AbjEXPyi (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 24 May 2023 11:54:38 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2047.outbound.protection.outlook.com [40.107.96.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63FEF97; Wed, 24 May 2023 08:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dbj3zm02rUnSz5WLkhYcdja40favZ7mEG0pOMmesQcwqC6cz1FT6YAgb2wzy9VFOuv7yOesEp7WlM9b3F/6NeVsAobA8MfPpo2sdyYwKZushXvjQRDmL4ta9gRZDf2eCTgb8MbEq83bLhdYeOSXx0a+siJ3c78Evlx1hQqLP2n2rkREh8XjCbut9bY61E6YXFtLfVAMV5JThrbUXXx6P95ptSZ4miw/gcpBX9mzdL6NApguKZLUlScC9EPLHfxj7hP8y2uBFWX9XUf8NlfC4b2E4pWy4INpun8SXg7tJAHfZNTIqhregZFQqcG/9ZpRRnMgllvu3yXYP0trZYJScAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bhJQrei0cPAAxb+GVVGUWNvRMGgni/3k1a10NVoTUFU=; b=Yi8j7K/3818fnxZ51G+MbYHH4S0XD1UQT1P12dkMhvE2C0WADZIHdriqLsmgtaZunXBfTClsK1f4zexQkC4NdcT30dGcI469bP6WHSzctvJT3vT5p231viJgNmoi98bdOEYBrf16xgjF83MOymckljYQzzFAfjfM5WJaueYgBp5BkFygv9pCG3EwndsXf4L0ANm5XLwFdx7N/F1dPPoN3PkPKpvn4dOFkaYHz43AE6TlrmB++xgwJ4debpq9Sl58DoslZAKDWHoPS2HNlf8aJy2TM/YEU0oEwhRcOlxUwjxMNzzKK4ufEGmCE+Ff/kKPf9DfJ4CzoSdQwVISxJ0kfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bhJQrei0cPAAxb+GVVGUWNvRMGgni/3k1a10NVoTUFU=; b=H0T7jq/lg1XGAk/ehplL6oeqY+OnTV68UKp7p9Ormp0H1ilbw8fyh7j36jJGbQRPQS0PtrukLmBKBgqQGwULSc3GwsNgh5NG4cPxIYWyl7PZQM8PwWUf/w7Gijr3YGSLPUCmw2sgSoUN+BSa9rxb1ha74IWLe3/Ays5gdFMFk78= Received: from BN9PR03CA0647.namprd03.prod.outlook.com (2603:10b6:408:13b::22) by DS7PR12MB6045.namprd12.prod.outlook.com (2603:10b6:8:86::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.16; Wed, 24 May 2023 15:54:33 +0000 Received: from BN8NAM11FT062.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13b:cafe::30) by BN9PR03CA0647.outlook.office365.com (2603:10b6:408:13b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.28 via Frontend Transport; Wed, 24 May 2023 15:54:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT062.mail.protection.outlook.com (10.13.177.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6433.16 via Frontend Transport; Wed, 24 May 2023 15:54:33 +0000 Received: from jallen-jump-host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 24 May 2023 10:54:32 -0500 From: John Allen <john.allen@amd.com> To: <kvm@vger.kernel.org> CC: <linux-kernel@vger.kernel.org>, <pbonzini@redhat.com>, <weijiang.yang@intel.com>, <rick.p.edgecombe@intel.com>, <seanjc@google.com>, <x86@kernel.org>, <thomas.lendacky@amd.com>, <bp@alien8.de>, John Allen <john.allen@amd.com> Subject: [RFC PATCH v2 3/6] KVM: x86: SVM: Pass through shadow stack MSRs Date: Wed, 24 May 2023 15:53:36 +0000 Message-ID: <20230524155339.415820-4-john.allen@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230524155339.415820-1-john.allen@amd.com> References: <20230524155339.415820-1-john.allen@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT062:EE_|DS7PR12MB6045:EE_ X-MS-Office365-Filtering-Correlation-Id: fe640d0f-8462-4d4a-7fee-08db5c6f2aec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WW5V9zmQu3XAjBLBhlc8V8znETcjtuZvauVlTw70yJXr3ycJIS6c4/SCr4seDT2KIytVS40AAaTYoJUldtxpQyRCs9Pou9kZZG8/2zbAVfEDFm74HMk7o9sgCsXisDRJ8wrmNWTrgA7/vguQ00fyKFzzCGQxgkKhUBvQLTobJGcrNAwC6lTrHE8RFjr3sfY3llHsQOie/GyXZ6CKSQi1F9VYB/svxa+8+xJcAhZC85CN84WspYFSGP5egA/YnM/2I+ELAQNpel2BxpmlRaD96S4BLO1k9nNk3DmvOSERqEE21DDxAaurdbnASFPI9ueT4rpFJgkRT7rBh5hdV2v2/Fs6ZCPAoemLecfwcQX42dHcwbdC1lSCiMalZ2lyRaxPK3cqMlgNV3mRWqWWU/0TOU+3s/4igmFYxSWC/YpoPWNlqpNyCBisRpFCvm92iVjHehOBVKoAxHigiozktVN1MKOZR0HJekX5NEJFR1yduDV7ir5l0WcIYfb6AdDOlht5dUJGo41EZM70AoGT81pOWU02213BGfyQpY//kNTdWPrQbVJMHldMjueARaihAgpTn14HuFf8gOEu61Tr0w4rR9twQ8lmhRvFFOU4ziU4/oHAY0CBAyMjS4ghd2QE93kEVc5juIxfutU+HoSs0v8zdFFf5DZX17lG3FUT/+03WUfBnjeZ88tRmZ8sKI+s413iQCnP3/HCX9P3MNe15cC3kGDN6e3BpVBtbewxR+uFbIhDIs5S6VvwvGzZrOZjuz1o9yuD+2DQXhn6tAKFkukIFg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(136003)(396003)(39860400002)(451199021)(46966006)(40470700004)(36840700001)(40460700003)(41300700001)(7696005)(83380400001)(47076005)(426003)(336012)(36860700001)(16526019)(186003)(2906002)(26005)(82310400005)(86362001)(2616005)(1076003)(82740400003)(356005)(81166007)(40480700001)(44832011)(5660300002)(36756003)(8676002)(8936002)(6916009)(70586007)(70206006)(4326008)(54906003)(478600001)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2023 15:54:33.3699 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe640d0f-8462-4d4a-7fee-08db5c6f2aec X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT062.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6045 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766793667067091660?= X-GMAIL-MSGID: =?utf-8?q?1766793667067091660?= |
Series |
[RFC,v2,1/6] KVM: x86: SVM: Emulate reads and writes to shadow stack MSRs
|
|
Commit Message
John Allen
May 24, 2023, 3:53 p.m. UTC
If kvm supports shadow stack, pass through shadow stack MSRs to improve
guest performance.
Signed-off-by: John Allen <john.allen@amd.com>
---
arch/x86/kvm/svm/svm.c | 17 +++++++++++++++++
arch/x86/kvm/svm/svm.h | 2 +-
2 files changed, 18 insertions(+), 1 deletion(-)
Comments
On Wed, May 24, 2023, John Allen wrote: > If kvm supports shadow stack, pass through shadow stack MSRs to improve > guest performance. > > Signed-off-by: John Allen <john.allen@amd.com> > --- > arch/x86/kvm/svm/svm.c | 17 +++++++++++++++++ > arch/x86/kvm/svm/svm.h | 2 +- > 2 files changed, 18 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 6df486bb1ac4..cdbce20989b8 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -136,6 +136,13 @@ static const struct svm_direct_access_msrs { > { .index = X2APIC_MSR(APIC_TMICT), .always = false }, > { .index = X2APIC_MSR(APIC_TMCCT), .always = false }, > { .index = X2APIC_MSR(APIC_TDCR), .always = false }, > + { .index = MSR_IA32_U_CET, .always = false }, > + { .index = MSR_IA32_S_CET, .always = false }, > + { .index = MSR_IA32_INT_SSP_TAB, .always = false }, > + { .index = MSR_IA32_PL0_SSP, .always = false }, > + { .index = MSR_IA32_PL1_SSP, .always = false }, > + { .index = MSR_IA32_PL2_SSP, .always = false }, > + { .index = MSR_IA32_PL3_SSP, .always = false }, > { .index = MSR_INVALID, .always = false }, > }; > > @@ -1181,6 +1188,16 @@ static inline void init_vmcb_after_set_cpuid(struct kvm_vcpu *vcpu) > set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_EIP, 1, 1); > set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_ESP, 1, 1); > } > + > + if (kvm_cet_user_supported() && guest_cpuid_has(vcpu, X86_FEATURE_SHSTK)) { > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_U_CET, 1, 1); > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_S_CET, 1, 1); > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_INT_SSP_TAB, 1, 1); > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL0_SSP, 1, 1); > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL1_SSP, 1, 1); > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL2_SSP, 1, 1); > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL3_SSP, 1, 1); > + } This is wrong, KVM needs to set/clear interception based on SHSKT, i.e. it can't be a one-way street. Userspace *probably* won't toggle SHSTK in guest CPUID, but weirder things have happened.
On Fri, Jun 23, 2023 at 05:05:18PM -0700, Sean Christopherson wrote: > On Wed, May 24, 2023, John Allen wrote: > > If kvm supports shadow stack, pass through shadow stack MSRs to improve > > guest performance. > > > > Signed-off-by: John Allen <john.allen@amd.com> > > --- > > arch/x86/kvm/svm/svm.c | 17 +++++++++++++++++ > > arch/x86/kvm/svm/svm.h | 2 +- > > 2 files changed, 18 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > > index 6df486bb1ac4..cdbce20989b8 100644 > > --- a/arch/x86/kvm/svm/svm.c > > +++ b/arch/x86/kvm/svm/svm.c > > @@ -136,6 +136,13 @@ static const struct svm_direct_access_msrs { > > { .index = X2APIC_MSR(APIC_TMICT), .always = false }, > > { .index = X2APIC_MSR(APIC_TMCCT), .always = false }, > > { .index = X2APIC_MSR(APIC_TDCR), .always = false }, > > + { .index = MSR_IA32_U_CET, .always = false }, > > + { .index = MSR_IA32_S_CET, .always = false }, > > + { .index = MSR_IA32_INT_SSP_TAB, .always = false }, > > + { .index = MSR_IA32_PL0_SSP, .always = false }, > > + { .index = MSR_IA32_PL1_SSP, .always = false }, > > + { .index = MSR_IA32_PL2_SSP, .always = false }, > > + { .index = MSR_IA32_PL3_SSP, .always = false }, > > { .index = MSR_INVALID, .always = false }, > > }; > > > > @@ -1181,6 +1188,16 @@ static inline void init_vmcb_after_set_cpuid(struct kvm_vcpu *vcpu) > > set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_EIP, 1, 1); > > set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_ESP, 1, 1); > > } > > + > > + if (kvm_cet_user_supported() && guest_cpuid_has(vcpu, X86_FEATURE_SHSTK)) { > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_U_CET, 1, 1); > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_S_CET, 1, 1); > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_INT_SSP_TAB, 1, 1); > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL0_SSP, 1, 1); > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL1_SSP, 1, 1); > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL2_SSP, 1, 1); > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL3_SSP, 1, 1); > > + } > > This is wrong, KVM needs to set/clear interception based on SHSKT, i.e. it can't > be a one-way street. Userspace *probably* won't toggle SHSTK in guest CPUID, but > weirder things have happened. Can you clarify what you mean by that? Do you mean that we need to check both guest_cpuid_has and kvm_cpu_cap_has like the guest_can_use function that is used in Weijiang Yang's series? Or is there something else I'm omitting here? static __always_inline bool guest_can_use(struct kvm_vcpu *vcpu, unsigned int feature) { return kvm_cpu_cap_has(feature) && guest_cpuid_has(vcpu, feature); }
On Tue, Aug 01, 2023, John Allen wrote: > On Fri, Jun 23, 2023 at 05:05:18PM -0700, Sean Christopherson wrote: > > On Wed, May 24, 2023, John Allen wrote: > > > If kvm supports shadow stack, pass through shadow stack MSRs to improve > > > guest performance. > > > > > > Signed-off-by: John Allen <john.allen@amd.com> > > > --- > > > arch/x86/kvm/svm/svm.c | 17 +++++++++++++++++ > > > arch/x86/kvm/svm/svm.h | 2 +- > > > 2 files changed, 18 insertions(+), 1 deletion(-) > > > > > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > > > index 6df486bb1ac4..cdbce20989b8 100644 > > > --- a/arch/x86/kvm/svm/svm.c > > > +++ b/arch/x86/kvm/svm/svm.c > > > @@ -136,6 +136,13 @@ static const struct svm_direct_access_msrs { > > > { .index = X2APIC_MSR(APIC_TMICT), .always = false }, > > > { .index = X2APIC_MSR(APIC_TMCCT), .always = false }, > > > { .index = X2APIC_MSR(APIC_TDCR), .always = false }, > > > + { .index = MSR_IA32_U_CET, .always = false }, > > > + { .index = MSR_IA32_S_CET, .always = false }, > > > + { .index = MSR_IA32_INT_SSP_TAB, .always = false }, > > > + { .index = MSR_IA32_PL0_SSP, .always = false }, > > > + { .index = MSR_IA32_PL1_SSP, .always = false }, > > > + { .index = MSR_IA32_PL2_SSP, .always = false }, > > > + { .index = MSR_IA32_PL3_SSP, .always = false }, > > > { .index = MSR_INVALID, .always = false }, > > > }; > > > > > > @@ -1181,6 +1188,16 @@ static inline void init_vmcb_after_set_cpuid(struct kvm_vcpu *vcpu) > > > set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_EIP, 1, 1); > > > set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_ESP, 1, 1); > > > } > > > + > > > + if (kvm_cet_user_supported() && guest_cpuid_has(vcpu, X86_FEATURE_SHSTK)) { > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_U_CET, 1, 1); > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_S_CET, 1, 1); > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_INT_SSP_TAB, 1, 1); > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL0_SSP, 1, 1); > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL1_SSP, 1, 1); > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL2_SSP, 1, 1); > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL3_SSP, 1, 1); > > > + } > > > > This is wrong, KVM needs to set/clear interception based on SHSKT, i.e. it can't > > be a one-way street. Userspace *probably* won't toggle SHSTK in guest CPUID, but > > weirder things have happened. > > Can you clarify what you mean by that? Do you mean that we need to check > both guest_cpuid_has and kvm_cpu_cap_has like the guest_can_use function > that is used in Weijiang Yang's series? Or is there something else I'm > omitting here? When init_vmcb_after_set_cpuid() is called, KVM must not assume that the MSRs are currently intercepted, i.e. KVM can't just handle the case where userspace enables SHSTK, KVM must also handle the case where userspace disables SHSTK. Using guest_can_use() is also a good idea, but it would likely lead to extra work on CPUs that don't support CET/SHSTK. This isn't a fastpath, but toggling interception for MSRs that don't exist would be odd. It's probably better to effectively open code guest_can_use(), which the KVM check gating the MSR toggling. E.g. something like if (kvm_cpu_cap_has(X86_FEATURE_SHSTK)) { bool shstk_enabled = guest_cpuid_has(vcpu, X86_FEATURE_SHSTK); set_msr_inteception(vcpu, svm->msrpm, MSR_IA32_BLAH, shstk_enabled, shstk_enabled); }
On Tue, Aug 01, 2023 at 09:42:09AM -0700, Sean Christopherson wrote: > On Tue, Aug 01, 2023, John Allen wrote: > > On Fri, Jun 23, 2023 at 05:05:18PM -0700, Sean Christopherson wrote: > > > On Wed, May 24, 2023, John Allen wrote: > > > > If kvm supports shadow stack, pass through shadow stack MSRs to improve > > > > guest performance. > > > > > > > > Signed-off-by: John Allen <john.allen@amd.com> > > > > --- > > > > arch/x86/kvm/svm/svm.c | 17 +++++++++++++++++ > > > > arch/x86/kvm/svm/svm.h | 2 +- > > > > 2 files changed, 18 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > > > > index 6df486bb1ac4..cdbce20989b8 100644 > > > > --- a/arch/x86/kvm/svm/svm.c > > > > +++ b/arch/x86/kvm/svm/svm.c > > > > @@ -136,6 +136,13 @@ static const struct svm_direct_access_msrs { > > > > { .index = X2APIC_MSR(APIC_TMICT), .always = false }, > > > > { .index = X2APIC_MSR(APIC_TMCCT), .always = false }, > > > > { .index = X2APIC_MSR(APIC_TDCR), .always = false }, > > > > + { .index = MSR_IA32_U_CET, .always = false }, > > > > + { .index = MSR_IA32_S_CET, .always = false }, > > > > + { .index = MSR_IA32_INT_SSP_TAB, .always = false }, > > > > + { .index = MSR_IA32_PL0_SSP, .always = false }, > > > > + { .index = MSR_IA32_PL1_SSP, .always = false }, > > > > + { .index = MSR_IA32_PL2_SSP, .always = false }, > > > > + { .index = MSR_IA32_PL3_SSP, .always = false }, > > > > { .index = MSR_INVALID, .always = false }, > > > > }; > > > > > > > > @@ -1181,6 +1188,16 @@ static inline void init_vmcb_after_set_cpuid(struct kvm_vcpu *vcpu) > > > > set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_EIP, 1, 1); > > > > set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_ESP, 1, 1); > > > > } > > > > + > > > > + if (kvm_cet_user_supported() && guest_cpuid_has(vcpu, X86_FEATURE_SHSTK)) { > > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_U_CET, 1, 1); > > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_S_CET, 1, 1); > > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_INT_SSP_TAB, 1, 1); > > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL0_SSP, 1, 1); > > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL1_SSP, 1, 1); > > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL2_SSP, 1, 1); > > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL3_SSP, 1, 1); > > > > + } > > > > > > This is wrong, KVM needs to set/clear interception based on SHSKT, i.e. it can't > > > be a one-way street. Userspace *probably* won't toggle SHSTK in guest CPUID, but > > > weirder things have happened. > > > > Can you clarify what you mean by that? Do you mean that we need to check > > both guest_cpuid_has and kvm_cpu_cap_has like the guest_can_use function > > that is used in Weijiang Yang's series? Or is there something else I'm > > omitting here? > > When init_vmcb_after_set_cpuid() is called, KVM must not assume that the MSRs are > currently intercepted, i.e. KVM can't just handle the case where userspace enables > SHSTK, KVM must also handle the case where userspace disables SHSTK. > > Using guest_can_use() is also a good idea, but it would likely lead to extra work > on CPUs that don't support CET/SHSTK. This isn't a fastpath, but toggling > interception for MSRs that don't exist would be odd. It's probably better to > effectively open code guest_can_use(), which the KVM check gating the MSR toggling. > > E.g. something like > > if (kvm_cpu_cap_has(X86_FEATURE_SHSTK)) { > bool shstk_enabled = guest_cpuid_has(vcpu, X86_FEATURE_SHSTK); > > set_msr_inteception(vcpu, svm->msrpm, MSR_IA32_BLAH, > shstk_enabled, shstk_enabled); > } Thanks for the clarification. I will use the above method in the next version of the series.
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 6df486bb1ac4..cdbce20989b8 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -136,6 +136,13 @@ static const struct svm_direct_access_msrs { { .index = X2APIC_MSR(APIC_TMICT), .always = false }, { .index = X2APIC_MSR(APIC_TMCCT), .always = false }, { .index = X2APIC_MSR(APIC_TDCR), .always = false }, + { .index = MSR_IA32_U_CET, .always = false }, + { .index = MSR_IA32_S_CET, .always = false }, + { .index = MSR_IA32_INT_SSP_TAB, .always = false }, + { .index = MSR_IA32_PL0_SSP, .always = false }, + { .index = MSR_IA32_PL1_SSP, .always = false }, + { .index = MSR_IA32_PL2_SSP, .always = false }, + { .index = MSR_IA32_PL3_SSP, .always = false }, { .index = MSR_INVALID, .always = false }, }; @@ -1181,6 +1188,16 @@ static inline void init_vmcb_after_set_cpuid(struct kvm_vcpu *vcpu) set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_EIP, 1, 1); set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_ESP, 1, 1); } + + if (kvm_cet_user_supported() && guest_cpuid_has(vcpu, X86_FEATURE_SHSTK)) { + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_U_CET, 1, 1); + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_S_CET, 1, 1); + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_INT_SSP_TAB, 1, 1); + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL0_SSP, 1, 1); + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL1_SSP, 1, 1); + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL2_SSP, 1, 1); + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL3_SSP, 1, 1); + } } static void init_vmcb(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index f44751dd8d5d..dad977747a15 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -29,7 +29,7 @@ #define IOPM_SIZE PAGE_SIZE * 3 #define MSRPM_SIZE PAGE_SIZE * 2 -#define MAX_DIRECT_ACCESS_MSRS 46 +#define MAX_DIRECT_ACCESS_MSRS 53 #define MSRPM_OFFSETS 32 extern u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly; extern bool npt_enabled;