From patchwork Wed May 1 07:10:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13650284 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D5F3C4345F for ; Wed, 1 May 2024 07:48:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6B6B6B0095; Wed, 1 May 2024 03:48:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D1AA86B0096; Wed, 1 May 2024 03:48:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE1DF6B0098; Wed, 1 May 2024 03:48:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9EA3A6B0095 for ; Wed, 1 May 2024 03:48:21 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 24AEA80741 for ; Wed, 1 May 2024 07:48:21 +0000 (UTC) X-FDA: 82069049202.01.A0C6AEE Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2080.outbound.protection.outlook.com [40.107.93.80]) by imf28.hostedemail.com (Postfix) with ESMTP id 413DBC0029 for ; Wed, 1 May 2024 07:48:18 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="wem35fG/"; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf28.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.80 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714549698; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=55BsZiyOriOSg+pL30Cck6KPdOkZNWZZJ/n3ehKgAlU=; b=l0l+0O2b18M4mW+cROnkllg9g3Y3ToM0W0Bd6k+w5WIw/p774NoBYcM+e55Ekab3jNoZDg V/WDgq6gDkcia5joqaZY1qU4ebDeZMf1qGzWxqvl+EtDBGmK9k7fJGxfJP+6TQgOftF1Hq x44jesFZPVs4i99Z9rcBjNESoqRRAag= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1714549698; a=rsa-sha256; cv=pass; b=Z4hz0RJnh/ZvssMmE72t8EqglMf5AzNgofuM94XvXeINn3Bngwt6GM0VOrlIySDDmBdgpY PzXh3UsA4jd2rWLBUjt368H3UNRVeKTdLqsuvBIwfYBSwARzlk481ZEfcxDI8lGlZ7mmHG WmcNYdkrmfRU6qDLMa8JKO+SfGQ3PpI= ARC-Authentication-Results: i=2; imf28.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="wem35fG/"; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf28.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.80 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fyYR5InUTA98zfsbk6hjFATbGzr2pJoRAP+9w7Y/ppoimVcOKv7xFVspSbbFswZlkpXF+L9imdRyfrMOQzF9Z6QYXukxJ2i57qWp3Z2CMJqRhByo1Yn3vn32N0liSrI1FvoaGo4uhMKQzCynHcIQBy8Sj7I9xqTXx9K9E+GHrFv85r9PLKkIkBwS/hNh5aOaQJpRcLP6YhUqveL/rsMtQ7zqx7g4GKN4cOaTzgXieI7KSl6f3MviQqxaUACY4QEZpEEEuvomSO2T9nVllX7PH6JdaePZ2HxQ+BFbg4hUDjW0arjQD1tOZpNk576QqJJjyysrca8BtUo0ZgI71cj0UQ== 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=55BsZiyOriOSg+pL30Cck6KPdOkZNWZZJ/n3ehKgAlU=; b=m1AZMJsTlqgviorug54XD2mK10OyE5KPjz8h4/602vy8T4TVFlLO84falg72v/Oj2rhslVxVGQQwlPCHhLv1EmoLUaUP7p4+NHSxufjemnMCdatPfN3Yf/P2ukw3z0CkRGt8sd+Wwn1BizTFXYX+rMwLG7mANGUq9wZqxwo510Jvp8cYJapZ9k9ouHuED0EG6Wsy21QEcCGDnIPpREAcqD+inQRduR8dnuklBN/8ec5hCckkJZJqKa/I/Uciu+dvw4zDo1zoUQYBR2Q1WFXiE8p4bblsYhwWLQGdrstn2Nb1Hz+G3sMouxznLtYAud7YEsEybwArAWc7/nt3mS+mWQ== 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 (0) 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=55BsZiyOriOSg+pL30Cck6KPdOkZNWZZJ/n3ehKgAlU=; b=wem35fG/9nfcXUsfSsv5Tp75mCX/u8hZE+Gp1wdnTKR6pJhy3xI/p0zqyf/coOpBPkvORmzB3aFYrM0aWEMD3NrBdSvO4/XWAaZ2yqM78Q35TdalM9Xk461WJwu92LTJK+KLZq9gDK3Q5LhsPn2v6VntqFN6NMJkt+IOJ28KTqA= Received: from PH8PR22CA0014.namprd22.prod.outlook.com (2603:10b6:510:2d1::29) by SJ0PR12MB8140.namprd12.prod.outlook.com (2603:10b6:a03:4e3::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.24; Wed, 1 May 2024 07:48:15 +0000 Received: from CY4PEPF0000EE33.namprd05.prod.outlook.com (2603:10b6:510:2d1:cafe::cb) by PH8PR22CA0014.outlook.office365.com (2603:10b6:510:2d1::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.36 via Frontend Transport; Wed, 1 May 2024 07:48:15 +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 CY4PEPF0000EE33.mail.protection.outlook.com (10.167.242.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7544.18 via Frontend Transport; Wed, 1 May 2024 07:48:15 +0000 Received: from localhost (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.2507.35; Wed, 1 May 2024 02:48:14 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , Subject: [PATCH 4/4] KVM: SEV: Allow per-guest configuration of GHCB protocol version Date: Wed, 1 May 2024 02:10:48 -0500 Message-ID: <20240501071048.2208265-5-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240501071048.2208265-1-michael.roth@amd.com> References: <20240501071048.2208265-1-michael.roth@amd.com> MIME-Version: 1.0 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: CY4PEPF0000EE33:EE_|SJ0PR12MB8140:EE_ X-MS-Office365-Filtering-Correlation-Id: 023a83b1-0973-441b-3f7b-08dc69b30f0c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|82310400014|7416005|1800799015|376005; X-Microsoft-Antispam-Message-Info: pzZ1EN6QItJAEJcltyx1edNlp74kPRg5fEC6R5QlMziJ/lAELVDtDl3bFjPluPQpHVlBVPBWyeb5Lo4jxeJcM+DoDyA1F9dt10O2DkHXWih0jnkQY76IhRcflDCC9F7YHLO9FZmE6EX1O256mCHh0TvzqpefwtUsiejrMXn1RysSUpNjdrpjpXUkWzm8xoXHXPYR/bAFgla1VNxb/nz/c0Cot/EfWEsTfZh3+Ak5vW3NjrF2pPnH4SyNpqNeDdDDbhCrYWIFm2tH2ekKNs5D37VhCJO2TbA8XhR8nmz7qddbqeZcK6L+fFO2hzjTX8q5Y+EIW4v+4OQagIbuEB/SoTdSKH4McYH46WaB7Hn137GlTGX3S46Uj6kaH014ioCan0LLqesJoHxahSAa6xr7CHFkPjIzUG6ps6ogWHvyjh0nX8CqLpwEZWdB/E3oYUBqyFsBge5u7oOQc88CGJ8XT7FWVt+Yms+udb98+2LmMvWqdv9C8P5ndf9kz7hfP2Q0LsTal20eDuczOVfi4FcjDzT7datPSRlAgb+8hwHiHLXuntG7cLc9i9eW5mZ+/LOPF46QWMy0TpRQx7oFVtkcq1QDWeU5fSuxcWRtWaqTZdf1VJgxVnCfRH9pVcw+XLV4o8EBUXwlNbJB+ppnmvqkEo8ZCRMjT7fEVDDj7H5NvXo98Uj4SGsaTx4G7HM5LnuC9abqHwJs0h3q5pSyHnfuP+j+sRARee+JBGdTUluvwUVmvfbEY4lH++mT5oVyhvRYdSeAQPywL+DjoW9hTnWcBcuvhNdU+vAq4ZNCJr2x5wn+m16ZcgYmLF0DI50nQXMTHs7j3BHPY3KCwtyXanXwtSoKfecBMhHjHI7p8NaWR/Vv9BBotOfDJl1vgfPb8ltC7BxLb2MM4uhqt+/nR1uVZTbxNBqEbSK7LPmj6/BpJoLTpU9YwryEVLXaN0LIUrsEqOB6mdOpCYIp1XuWrBNkM6M0tW+fNI2+wqaRTC2bIb60qa5zKKIdifUWdINDAKqVGAd4nqtHK0o57g06X8uQD/fseyucuXxQC7duc/Cur8rxPuSL9n8kaEdSXu2v4ntC0g8Xll1x86VjrTKCcrS8E4ohbigK6i2OZegPongy9O0wN9FyZNebVQp+yFFfvcMp+aalyReDPF3w675pRK+nWuOEnruTq8Wofi+C9h5z1ZbkByEMFiA6HnErD0stnELav51l+l9Zc2UvRNCMZhxmeTSLKoLykdzS+YKguVXuGlQ7J6iGdNmvAULk0ZlvJeB1imgiEbUEWSunNVmBYoBQ4Y6yTV+LAWC5fbEE56WPyEq7LdBTqqvxhTEF1JKJBaY6sgcYZKc0EZSDBUXPIPkFZoAq2Cqx3RJurS+Eu1Mcpg3XFDG8skEhyQOLOHO/BmUw 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:(13230031)(36860700004)(82310400014)(7416005)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 07:48:15.1213 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 023a83b1-0973-441b-3f7b-08dc69b30f0c 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: CY4PEPF0000EE33.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB8140 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 413DBC0029 X-Stat-Signature: jhym98w5myu9py9eaj1mzaoznri8a4fu X-Rspam-User: X-HE-Tag: 1714549698-709760 X-HE-Meta: U2FsdGVkX1/ZFIN92QGpXJWRY54ERSKhG9WWcYgWl4lHrCH3QMsVwAs32sDGmnbulkbcpzDrq/SvBGW0CMa5xuJvcaN4UxY5Pu8ih4a+r1dH6jVCawXeb2Ph8RaXN3RAWBxrL8Z8ZTuN0dvaY+eh+KgWzj3XOl2+oB9HffAzP0HFYDtY1xzCydUYjzugNx/5QIN6aStHENsJQpPJAIEiygqGNFGiMxVHVDR+XP28DYCFU4MN6TOM0TIOIYXOVAFsEZlAa7eP2BGRVh07dqi0wx6J9Dht/xYFHPNIbtNzUyOVEdcSppr5239Z96G1nLzwVVjB4XMtptxxD5E8WZkdcMCYS5hUMLQiJ1lAtBaug13hEMVtmdRxVVF8tpp0QG/RguXGZTlSiNFz394HE4hDUBOwJdkE6++HnodxuNntuKsaotnT0sjxzWjckl07YHWhaUMpeX+EBNiQom6lqp5wRJkEbTl/JZvifS3MKxoyeAZf2tWzjhJmZ5gJjFRzQHRKccqFK+4tKOWcgFKfmbqw40IqrgRAQHSbSwNI4IHtyR85AyohQ6BW+HJCYHAjVblD+ahIGIpXKUYuLWcPsi/vQb97qF0AgaPhZzLqQngz3+eOUAB0KudyGAa6hOJLX58JlAPQiAIJ+TuIG+EGWT8fFVMC5RLbXOL/24KJwCz1kV+Uy+nZ0dfkyDU5rmNzWwGvRIhIStYpjseAjx0Osz3SWx8dG2sKsStj+sD4MlE68g7QFgsWkEXLQAtWAMhioO2gMnIUXTo0PpWeXXQClrjp22r4JuwhUC0q9UOhd5+3xOq06z/uWxuzWh/pFKtz+57VKBMUpwLO0EUI8nzxAlRq3Bi0KtUXW7W8Twj4481QWFzfCqHmFS3hq2gH4zBWR1Qm7Ao1hDKUc0finumyDJMpf5DL4CCnCBYIgUk0UbOBxD6hI7GcfHZEoGbe4XJwLzYDgo4HpBjKzLn4UFY27hH l0ytXAYk KeOKQt51aT1fGxh0r+2x2rOXTrSRPSHIrk9uP8Fbj08RyttdS8L1KExofASqFKmBSRu6jTYc/CDsrML67/bRHM44AerYUK3e708YnLZcqHe6bS/UXlLLrd+T28t04nBbtgeXrUswZYjOynZKpY67phh2eRmNqj5G6yYpt03spb3bE/Sblw45ERGSjUTs2wAmGwU2xA14GTPyjkrMGHhYI7ABtHaSbi03lKxCk5qyF0cYnwBHfiRwdtLH8eLv1ftH1fCUo2qCFjog0vr7fZEP4fA5N9SI7qSIhHadSznNfASAkwJPqMO6olzD1BmyLRLz3PKCIegS1aoWBq3IpbNJSFVBvy3yhOa8HO41K+smLrqdtJtY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The GHCB protocol version may be different from one guest to the next. Add a field to track it for each KVM instance and extend KVM_SEV_INIT2 to allow it to be configured by userspace. Now that all SEV-ES support for GHCB protocol version 2 is in place, go ahead and default to it when creating SEV-ES guests through the new KVM_SEV_INIT2 interface. Keep the older KVM_SEV_ES_INIT interface restricted to GHCB protocol version 1. Suggested-by: Sean Christopherson Signed-off-by: Michael Roth --- .../virt/kvm/x86/amd-memory-encryption.rst | 11 +++++-- arch/x86/include/uapi/asm/kvm.h | 4 ++- arch/x86/kvm/svm/sev.c | 32 +++++++++++++++++-- arch/x86/kvm/svm/svm.h | 1 + 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Documentation/virt/kvm/x86/amd-memory-encryption.rst b/Documentation/virt/kvm/x86/amd-memory-encryption.rst index 3381556d596d..9677a0714a39 100644 --- a/Documentation/virt/kvm/x86/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/x86/amd-memory-encryption.rst @@ -95,13 +95,19 @@ Returns: 0 on success, -negative on error struct kvm_sev_init { __u64 vmsa_features; /* initial value of features field in VMSA */ __u32 flags; /* must be 0 */ - __u32 pad[9]; + __u16 ghcb_version; /* maximum guest GHCB version allowed */ + __u16 pad1; + __u32 pad2[8]; }; It is an error if the hypervisor does not support any of the bits that are set in ``flags`` or ``vmsa_features``. ``vmsa_features`` must be 0 for SEV virtual machines, as they do not have a VMSA. +``ghcb_version`` must be 0 for SEV virtual machines, as they do not issue GHCB +requests. If ``ghcb_version`` is 0 for any other guest type, then the maximum +allowed guest GHCB protocol will default to version 2. + This command replaces the deprecated KVM_SEV_INIT and KVM_SEV_ES_INIT commands. The commands did not have any parameters (the ```data``` field was unused) and only work for the KVM_X86_DEFAULT_VM machine type (0). @@ -112,7 +118,8 @@ They behave as if: KVM_SEV_ES_INIT * the ``flags`` and ``vmsa_features`` fields of ``struct kvm_sev_init`` are - set to zero + set to zero, and ``ghcb_version`` is set to 0 for KVM_SEV_INIT and 1 for + KVM_SEV_ES_INIT. If the ``KVM_X86_SEV_VMSA_FEATURES`` attribute does not exist, the hypervisor only supports KVM_SEV_INIT and KVM_SEV_ES_INIT. In that case, note that KVM_SEV_ES_INIT diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h index 72ad5ace118d..9fae1b73b529 100644 --- a/arch/x86/include/uapi/asm/kvm.h +++ b/arch/x86/include/uapi/asm/kvm.h @@ -711,7 +711,9 @@ struct kvm_sev_cmd { struct kvm_sev_init { __u64 vmsa_features; __u32 flags; - __u32 pad[9]; + __u16 ghcb_version; + __u16 pad1; + __u32 pad2[8]; }; struct kvm_sev_launch_start { diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 01baa8aa7e12..a4bde1193b92 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -33,7 +33,8 @@ #include "cpuid.h" #include "trace.h" -#define GHCB_VERSION_MAX 1ULL +#define GHCB_VERSION_MAX 2ULL +#define GHCB_VERSION_DEFAULT 2ULL #define GHCB_VERSION_MIN 1ULL #define GHCB_HV_FT_SUPPORTED GHCB_HV_FT_SNP @@ -268,12 +269,24 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp, if (data->vmsa_features & ~valid_vmsa_features) return -EINVAL; + if (data->ghcb_version > GHCB_VERSION_MAX || (!es_active && data->ghcb_version)) + return -EINVAL; + if (unlikely(sev->active)) return -EINVAL; sev->active = true; sev->es_active = es_active; sev->vmsa_features = data->vmsa_features; + sev->ghcb_version = data->ghcb_version; + + /* + * Currently KVM supports the full range of mandatory features defined + * by version 2 of the GHCB protocol, so default to that for SEV-ES + * guests created via KVM_SEV_INIT2. + */ + if (sev->es_active && !sev->ghcb_version) + sev->ghcb_version = GHCB_VERSION_DEFAULT; ret = sev_asid_new(sev); if (ret) @@ -307,6 +320,7 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) { struct kvm_sev_init data = { .vmsa_features = 0, + .ghcb_version = 0, }; unsigned long vm_type; @@ -314,6 +328,14 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) return -EINVAL; vm_type = (argp->id == KVM_SEV_INIT ? KVM_X86_SEV_VM : KVM_X86_SEV_ES_VM); + + /* + * KVM_SEV_ES_INIT has been deprecated by KVM_SEV_INIT2, so it will + * continue to only ever support the minimal GHCB protocol version. + */ + if (vm_type == KVM_X86_SEV_ES_VM) + data.ghcb_version = GHCB_VERSION_MIN; + return __sev_guest_init(kvm, argp, &data, vm_type); } @@ -2897,6 +2919,7 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm) { struct vmcb_control_area *control = &svm->vmcb->control; struct kvm_vcpu *vcpu = &svm->vcpu; + struct kvm_sev_info *sev = &to_kvm_svm(vcpu->kvm)->sev_info; u64 ghcb_info; int ret = 1; @@ -2907,7 +2930,7 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm) switch (ghcb_info) { case GHCB_MSR_SEV_INFO_REQ: - set_ghcb_msr(svm, GHCB_MSR_SEV_INFO(GHCB_VERSION_MAX, + set_ghcb_msr(svm, GHCB_MSR_SEV_INFO((__u64)sev->ghcb_version, GHCB_VERSION_MIN, sev_enc_bit)); break; @@ -3268,11 +3291,14 @@ void sev_init_vmcb(struct vcpu_svm *svm) void sev_es_vcpu_reset(struct vcpu_svm *svm) { + struct kvm_vcpu *vcpu = &svm->vcpu; + struct kvm_sev_info *sev = &to_kvm_svm(vcpu->kvm)->sev_info; + /* * Set the GHCB MSR value as per the GHCB specification when emulating * vCPU RESET for an SEV-ES guest. */ - set_ghcb_msr(svm, GHCB_MSR_SEV_INFO(GHCB_VERSION_MAX, + set_ghcb_msr(svm, GHCB_MSR_SEV_INFO((__u64)sev->ghcb_version, GHCB_VERSION_MIN, sev_enc_bit)); } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 6fd0f5862681..9ae0c57c7d20 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -87,6 +87,7 @@ struct kvm_sev_info { struct list_head regions_list; /* List of registered regions */ u64 ap_jump_table; /* SEV-ES AP Jump Table address */ u64 vmsa_features; + u16 ghcb_version; /* Highest guest GHCB protocol version allowed */ struct kvm *enc_context_owner; /* Owner of copied encryption context */ struct list_head mirror_vms; /* List of VMs mirroring */ struct list_head mirror_entry; /* Use as a list entry of mirrors */