From patchwork Fri May 31 04:30:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681109 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2070.outbound.protection.outlook.com [40.107.94.70]) (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 B08397BB0C; Fri, 31 May 2024 04:31:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129890; cv=fail; b=BPYhl++Q3cHMlKwktC9/PrNPioVP1/RRB7CdNdGGNzjhpgpth8gSpmj7JJsQJnfZKpTr1ZdmmjYYP4nYQjdGdgvZb4fL2E+yOThjjPQJ/Rn8Pln5ak73rzyjODIOwH09eV/xpAbo6ZqRfLIRKWBsmme/xo/9q5ofRCoINOV5M7Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129890; c=relaxed/simple; bh=sgzW8Mc18zB8Z7oryreValO4nHvWpNjQwC0ieFMSd84=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lr2uNeIVDEEM5QY4lrE+QXt7FxLB2hrNvRLHUtRm/W5l/tPvKt3nE3MeFZ7UmJ9evDEUnD8U8j53fpXB+goAJ4af2jWGqQFcYHXb5jIEdVedYmL8g3Zcc9DmYPazh/izhcNasIdO+kDDG/yB6DOeVn9GiAetWLzM8UYS764gUas= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=2N5KgMeA; arc=fail smtp.client-ip=40.107.94.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="2N5KgMeA" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B1nPH6H7mXixoNXk+1IE2BRscCy+kWL45DXv/e5f/nG7AeCDaSXsVzIQUNne44BuwrRG97w+z5XPNCU7EHphCai0CjfniqyIiWaCRuTGePeH/jRrBH6904RtAF99P2CJSie0LUc0XqilhXzpYAc2vw1T1SmFNzkVXcsHzdLXUdqOcSYTAQ5yzuV2Pb+xryz4k49cqTkjFfbJigMC+Fs34CU3dvBhVPmXAXuSR0u2jbULvjc62EAS4o4f5KwaovFQMoPNMflBG0wEIF/d/hoS6h4f0sABJTRQu5ezZs0eHrnLb3Ka6/4fATMkGRr4He7EIpsQu8uYqZnxhmH/0ZO9hA== 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=My/46emAAveMnlDZZLz52UnrMsuXP5H6Gb8aOQdZTQk=; b=LBBCW/+Lk+vRU7oKor3gh02GZfYYTAjCrTe7LTdDZpgrY58f6WFJiqeg0E/CmjTHPALxKF0al1M0MpRhwBgDnqBT4K2f2ns2MorluT5ft4YF2zKveqD5rXQhfJCUZOD2A6JgrFS8PfYbTebwQ1hYwVtNBJtiJQ7daMyR9yzeCbVFfpzEtk9ZCeSZZmMOLbYl9ZgLpP4OAKrmiPWRVP1W7MPPX1lHrTn+RfrbrqHUVQ/Ow29l1r2f8lIYndC0BncoJadpXm2mAV9dpcPxZ57/CyLn+Bq+9t5b5S/f8eSS5h5us3OxH40F9msuYAfwsi6FJeGfDFOwXAq/4FClTjRq6g== 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=My/46emAAveMnlDZZLz52UnrMsuXP5H6Gb8aOQdZTQk=; b=2N5KgMeAv8mW7C5e5dK+f3rh7LweaF74JP3VhsQbPH4IuNGOl1PQdhIrP+/EZIl1BpNxPJfVeEF9sKnY84uyDHBG38Ck6A0COTCw69laf4bw2Pm/7xTBizw+9kN1B/UOSDAj5Zi2eqH/cZfzAqpTF6FbMpNPcnxc0Ao+bWQaCpQ= Received: from BY3PR05CA0028.namprd05.prod.outlook.com (2603:10b6:a03:254::33) by BL3PR12MB6593.namprd12.prod.outlook.com (2603:10b6:208:38c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Fri, 31 May 2024 04:31:25 +0000 Received: from SJ1PEPF00002320.namprd03.prod.outlook.com (2603:10b6:a03:254:cafe::ad) by BY3PR05CA0028.outlook.office365.com (2603:10b6:a03:254::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.8 via Frontend Transport; Fri, 31 May 2024 04:31:24 +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 SJ1PEPF00002320.mail.protection.outlook.com (10.167.242.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:31:24 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:31:20 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 01/24] virt: sev-guest: Use AES GCM crypto library Date: Fri, 31 May 2024 10:00:15 +0530 Message-ID: <20240531043038.3370793-2-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: SJ1PEPF00002320:EE_|BL3PR12MB6593:EE_ X-MS-Office365-Filtering-Correlation-Id: 581aebe3-a2a8-4d9a-6ced-08dc812a87ed X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|7416005|1800799015|376005|36860700004; X-Microsoft-Antispam-Message-Info: lx1vakVT7QAfWCfO0S04m/2Eg6VjAtrCk/3hcxX3LqXgi/NxP8NgffuoDnYSu+aSGx/Lre1gT2IlavVkv53pOQXZrMg9w2ZI3El1Ntij7/DLq/Za2LqLBCC2GTjckyz/JP/V9xdHxiJkNt412pJyyPFfQoA2vwgt0u5CR1h0DcyDomJDkM97CG6nMiMvAKfqQ2tvyagt/RS5sTRlSO+WfuGMaUH/k+vX7AVuGAFjODD/OSv2uG9d8pwBoydrqm8MUQYx/gO84YnNZC6k2O1cG0cKcr9T3Libn23+Nm8a36ArbZ7SlYm8nJh233BXnJDmnq2dm/SD5Oa7AWl3aIFnmferluLPphZaGQ/5qI6ZhBc5xFFXuKrwKND9X7A/RkmdjEYmJYMaPUui0WGYZQu/N7oAAWdvyhfE0ikKEeBv41N3QZb19n2kgeUnUU4J1ITSk89rXrmb6HGsBKI8bvDC+fdo7/2ZnP3idEUC9nCvdv9FbnR+BF145XL95jtjcbAQqfA8NB+u6mncdbDaJPqYTn9BAF+IbjyuKbk8h6siqVgxf9yuCJikVdcSbB1v8sd8JpnTJVncTFhJrA1JOcwrNOMYjxfGYivE34zj64cXLJM94gcalA2bVLYjMyOSbVypV2u6OIiLpNO6WSHN5yrU2QzhOdzze1FL1MFlcvBFARf2yhK8+cDWE0pqHrpBM6ZwyjriUsKXdwWCHRrGrytPKUV5LLDni7IndlgCv82pT61XcgAWR0eX9xDMhC4edQIqq3/c4yIa8rge3Ybah+nx9VHtyxjnIEN3aQ2/8zd7TYBpz9E9EX8Kt0oezfiAQDpb/xod16JojLHybrab6Bt2tbP9R1mjmoePCYmlDh/lw+/JapbfXC1LvmhySdok84mxsDflMjfmJ8/q+E9xs4hSBNfaQBhGXl+lfs/NsMQhdCLW1Ay1X4+mm0lCo9qLkYW5Kg8hmzqozo7TmHGYnKGlMN36iP4y8vPvsIlrzKeccZmTnehpkXReruO9Br8rgPHP5FyK9iS3YBHXQVAh/HHRHoSQDiG7JJsgq4SZs0qbdI1qb98/vuUi8JekuBY8aGNFX3ZBS+3MjpaNNN2x1n4R1vRTgz6HF9VKeQr6kQs4ZWQi4bSwt5KQ2fF5Z+TuGruGDVJWm2eNIKCLsEUQX4dZj4vBd2NFGf06qIWE6tPklHqTFqi71jP2mf9R3xCGJnwZ05/aT7h+DbV1X7SUXgZEFB5nsehjaL+977JlOxQ0+6ywsMbtVgzsy56ezgcz8jaHlGGV+j6Tm8UbELg0LGgDf/hIs7CcgTgeLrPEycN0kLIMo3kncwJ80jIRq7gRTv4TxPNFoD9ThqYyMn5TbiUU8LYD0IWu1Wiqea/3xNr+J2C8Q82yEA1D2H4qA25TCSFj 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)(82310400017)(7416005)(1800799015)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:31:24.7611 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 581aebe3-a2a8-4d9a-6ced-08dc812a87ed 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: SJ1PEPF00002320.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6593 The sev-guest driver encryption code uses Crypto API for SNP guest messaging to interact with AMD Security processor. For enabling SecureTSC, SEV-SNP guests need to send a TSC_INFO request guest message before the smpboot phase starts. Details from the TSC_INFO response will be used to program the VMSA before the secondary CPUs are brought up. The Crypto API is not available this early in the boot phase. In preparation of moving the encryption code out of sev-guest driver to support SecureTSC and make reviewing the diff easier, start using AES GCM library implementation instead of Crypto API. Drop __enc_payload() and dec_payload() helpers as both are pretty small and can be moved to the respective callers. CC: Ard Biesheuvel Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky Tested-by: Peter Gonda Acked-by: Borislav Petkov (AMD) --- drivers/virt/coco/sev-guest/sev-guest.h | 3 + drivers/virt/coco/sev-guest/sev-guest.c | 175 ++++++------------------ drivers/virt/coco/sev-guest/Kconfig | 4 +- 3 files changed, 43 insertions(+), 139 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.h b/drivers/virt/coco/sev-guest/sev-guest.h index 21bda26fdb95..ceb798a404d6 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.h +++ b/drivers/virt/coco/sev-guest/sev-guest.h @@ -13,6 +13,9 @@ #include #define MAX_AUTHTAG_LEN 32 +#define AUTHTAG_LEN 16 +#define AAD_LEN 48 +#define MSG_HDR_VER 1 /* See SNP spec SNP_GUEST_REQUEST section for the structure */ enum msg_type { diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 654290a8e1ba..0768c6692483 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -17,8 +17,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -32,24 +31,16 @@ #include "sev-guest.h" #define DEVICE_NAME "sev-guest" -#define AAD_LEN 48 -#define MSG_HDR_VER 1 #define SNP_REQ_MAX_RETRY_DURATION (60*HZ) #define SNP_REQ_RETRY_DELAY (2*HZ) -struct snp_guest_crypto { - struct crypto_aead *tfm; - u8 *iv, *authtag; - int iv_len, a_len; -}; - struct snp_guest_dev { struct device *dev; struct miscdevice misc; void *certs_data; - struct snp_guest_crypto *crypto; + struct aesgcm_ctx *ctx; /* request and response are in unencrypted memory */ struct snp_guest_msg *request, *response; @@ -161,132 +152,31 @@ static inline struct snp_guest_dev *to_snp_dev(struct file *file) return container_of(dev, struct snp_guest_dev, misc); } -static struct snp_guest_crypto *init_crypto(struct snp_guest_dev *snp_dev, u8 *key, size_t keylen) +static struct aesgcm_ctx *snp_init_crypto(u8 *key, size_t keylen) { - struct snp_guest_crypto *crypto; + struct aesgcm_ctx *ctx; - crypto = kzalloc(sizeof(*crypto), GFP_KERNEL_ACCOUNT); - if (!crypto) + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL_ACCOUNT); + if (!ctx) return NULL; - crypto->tfm = crypto_alloc_aead("gcm(aes)", 0, 0); - if (IS_ERR(crypto->tfm)) - goto e_free; - - if (crypto_aead_setkey(crypto->tfm, key, keylen)) - goto e_free_crypto; - - crypto->iv_len = crypto_aead_ivsize(crypto->tfm); - crypto->iv = kmalloc(crypto->iv_len, GFP_KERNEL_ACCOUNT); - if (!crypto->iv) - goto e_free_crypto; - - if (crypto_aead_authsize(crypto->tfm) > MAX_AUTHTAG_LEN) { - if (crypto_aead_setauthsize(crypto->tfm, MAX_AUTHTAG_LEN)) { - dev_err(snp_dev->dev, "failed to set authsize to %d\n", MAX_AUTHTAG_LEN); - goto e_free_iv; - } + if (aesgcm_expandkey(ctx, key, keylen, AUTHTAG_LEN)) { + pr_err("Crypto context initialization failed\n"); + kfree(ctx); + return NULL; } - crypto->a_len = crypto_aead_authsize(crypto->tfm); - crypto->authtag = kmalloc(crypto->a_len, GFP_KERNEL_ACCOUNT); - if (!crypto->authtag) - goto e_free_iv; - - return crypto; - -e_free_iv: - kfree(crypto->iv); -e_free_crypto: - crypto_free_aead(crypto->tfm); -e_free: - kfree(crypto); - - return NULL; -} - -static void deinit_crypto(struct snp_guest_crypto *crypto) -{ - crypto_free_aead(crypto->tfm); - kfree(crypto->iv); - kfree(crypto->authtag); - kfree(crypto); -} - -static int enc_dec_message(struct snp_guest_crypto *crypto, struct snp_guest_msg *msg, - u8 *src_buf, u8 *dst_buf, size_t len, bool enc) -{ - struct snp_guest_msg_hdr *hdr = &msg->hdr; - struct scatterlist src[3], dst[3]; - DECLARE_CRYPTO_WAIT(wait); - struct aead_request *req; - int ret; - - req = aead_request_alloc(crypto->tfm, GFP_KERNEL); - if (!req) - return -ENOMEM; - - /* - * AEAD memory operations: - * +------ AAD -------+------- DATA -----+---- AUTHTAG----+ - * | msg header | plaintext | hdr->authtag | - * | bytes 30h - 5Fh | or | | - * | | cipher | | - * +------------------+------------------+----------------+ - */ - sg_init_table(src, 3); - sg_set_buf(&src[0], &hdr->algo, AAD_LEN); - sg_set_buf(&src[1], src_buf, hdr->msg_sz); - sg_set_buf(&src[2], hdr->authtag, crypto->a_len); - - sg_init_table(dst, 3); - sg_set_buf(&dst[0], &hdr->algo, AAD_LEN); - sg_set_buf(&dst[1], dst_buf, hdr->msg_sz); - sg_set_buf(&dst[2], hdr->authtag, crypto->a_len); - - aead_request_set_ad(req, AAD_LEN); - aead_request_set_tfm(req, crypto->tfm); - aead_request_set_callback(req, 0, crypto_req_done, &wait); - - aead_request_set_crypt(req, src, dst, len, crypto->iv); - ret = crypto_wait_req(enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req), &wait); - - aead_request_free(req); - return ret; -} - -static int __enc_payload(struct snp_guest_dev *snp_dev, struct snp_guest_msg *msg, - void *plaintext, size_t len) -{ - struct snp_guest_crypto *crypto = snp_dev->crypto; - struct snp_guest_msg_hdr *hdr = &msg->hdr; - - memset(crypto->iv, 0, crypto->iv_len); - memcpy(crypto->iv, &hdr->msg_seqno, sizeof(hdr->msg_seqno)); - - return enc_dec_message(crypto, msg, plaintext, msg->payload, len, true); -} - -static int dec_payload(struct snp_guest_dev *snp_dev, struct snp_guest_msg *msg, - void *plaintext, size_t len) -{ - struct snp_guest_crypto *crypto = snp_dev->crypto; - struct snp_guest_msg_hdr *hdr = &msg->hdr; - - /* Build IV with response buffer sequence number */ - memset(crypto->iv, 0, crypto->iv_len); - memcpy(crypto->iv, &hdr->msg_seqno, sizeof(hdr->msg_seqno)); - - return enc_dec_message(crypto, msg, msg->payload, plaintext, len, false); + return ctx; } static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, u32 sz) { - struct snp_guest_crypto *crypto = snp_dev->crypto; struct snp_guest_msg *resp = &snp_dev->secret_response; struct snp_guest_msg *req = &snp_dev->secret_request; struct snp_guest_msg_hdr *req_hdr = &req->hdr; struct snp_guest_msg_hdr *resp_hdr = &resp->hdr; + struct aesgcm_ctx *ctx = snp_dev->ctx; + u8 iv[GCM_AES_IV_SIZE] = {}; dev_dbg(snp_dev->dev, "response [seqno %lld type %d version %d sz %d]\n", resp_hdr->msg_seqno, resp_hdr->msg_type, resp_hdr->msg_version, resp_hdr->msg_sz); @@ -307,11 +197,16 @@ static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, * If the message size is greater than our buffer length then return * an error. */ - if (unlikely((resp_hdr->msg_sz + crypto->a_len) > sz)) + if (unlikely((resp_hdr->msg_sz + ctx->authsize) > sz)) return -EBADMSG; /* Decrypt the payload */ - return dec_payload(snp_dev, resp, payload, resp_hdr->msg_sz + crypto->a_len); + memcpy(iv, &resp_hdr->msg_seqno, min(sizeof(iv), sizeof(resp_hdr->msg_seqno))); + if (!aesgcm_decrypt(ctx, payload, resp->payload, resp_hdr->msg_sz, + &resp_hdr->algo, AAD_LEN, iv, resp_hdr->authtag)) + return -EBADMSG; + + return 0; } static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 type, @@ -319,6 +214,8 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 { struct snp_guest_msg *req = &snp_dev->secret_request; struct snp_guest_msg_hdr *hdr = &req->hdr; + struct aesgcm_ctx *ctx = snp_dev->ctx; + u8 iv[GCM_AES_IV_SIZE] = {}; memset(req, 0, sizeof(*req)); @@ -338,7 +235,14 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 dev_dbg(snp_dev->dev, "request [seqno %lld type %d version %d sz %d]\n", hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); - return __enc_payload(snp_dev, req, payload, sz); + if (WARN_ON((sz + ctx->authsize) > sizeof(req->payload))) + return -EBADMSG; + + memcpy(iv, &hdr->msg_seqno, min(sizeof(iv), sizeof(hdr->msg_seqno))); + aesgcm_encrypt(ctx, req->payload, payload, sz, &hdr->algo, AAD_LEN, + iv, hdr->authtag); + + return 0; } static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, @@ -486,7 +390,6 @@ struct snp_req_resp { static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg) { - struct snp_guest_crypto *crypto = snp_dev->crypto; struct snp_report_req *req = &snp_dev->req.report; struct snp_report_resp *resp; int rc, resp_len; @@ -504,7 +407,7 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(resp->data) + crypto->a_len; + resp_len = sizeof(resp->data) + snp_dev->ctx->authsize; resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); if (!resp) return -ENOMEM; @@ -526,7 +429,6 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg) { struct snp_derived_key_req *req = &snp_dev->req.derived_key; - struct snp_guest_crypto *crypto = snp_dev->crypto; struct snp_derived_key_resp resp = {0}; int rc, resp_len; /* Response data is 64 bytes and max authsize for GCM is 16 bytes. */ @@ -542,7 +444,7 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(resp.data) + crypto->a_len; + resp_len = sizeof(resp.data) + snp_dev->ctx->authsize; if (sizeof(buf) < resp_len) return -ENOMEM; @@ -569,7 +471,6 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques { struct snp_ext_report_req *req = &snp_dev->req.ext_report; - struct snp_guest_crypto *crypto = snp_dev->crypto; struct snp_report_resp *resp; int ret, npages = 0, resp_len; sockptr_t certs_address; @@ -612,7 +513,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(resp->data) + crypto->a_len; + resp_len = sizeof(resp->data) + snp_dev->ctx->authsize; resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); if (!resp) return -ENOMEM; @@ -954,8 +855,8 @@ static int __init sev_guest_probe(struct platform_device *pdev) goto e_free_response; ret = -EIO; - snp_dev->crypto = init_crypto(snp_dev, snp_dev->vmpck, VMPCK_KEY_LEN); - if (!snp_dev->crypto) + snp_dev->ctx = snp_init_crypto(snp_dev->vmpck, VMPCK_KEY_LEN); + if (!snp_dev->ctx) goto e_free_cert_data; misc = &snp_dev->misc; @@ -978,11 +879,13 @@ static int __init sev_guest_probe(struct platform_device *pdev) ret = misc_register(misc); if (ret) - goto e_free_cert_data; + goto e_free_ctx; dev_info(dev, "Initialized SEV guest driver (using vmpck_id %d)\n", vmpck_id); return 0; +e_free_ctx: + kfree(snp_dev->ctx); e_free_cert_data: free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE); e_free_response: @@ -1001,7 +904,7 @@ static void __exit sev_guest_remove(struct platform_device *pdev) free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE); free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg)); free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg)); - deinit_crypto(snp_dev->crypto); + kfree(snp_dev->ctx); misc_deregister(&snp_dev->misc); } diff --git a/drivers/virt/coco/sev-guest/Kconfig b/drivers/virt/coco/sev-guest/Kconfig index 1cffc72c41cb..0b772bd921d8 100644 --- a/drivers/virt/coco/sev-guest/Kconfig +++ b/drivers/virt/coco/sev-guest/Kconfig @@ -2,9 +2,7 @@ config SEV_GUEST tristate "AMD SEV Guest driver" default m depends on AMD_MEM_ENCRYPT - select CRYPTO - select CRYPTO_AEAD2 - select CRYPTO_GCM + select CRYPTO_LIB_AESGCM select TSM_REPORTS help SEV-SNP firmware provides the guest a mechanism to communicate with From patchwork Fri May 31 04:30:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681110 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2088.outbound.protection.outlook.com [40.107.101.88]) (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 A6F132135B; Fri, 31 May 2024 04:31:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129894; cv=fail; b=X/JWnMtGVt22WRa4rv+QKiIQ+73LSPZCuindtdUO8qoOZBx/T6C1VmeOSYY8dQ7WUSKxLv3A8+NNHO9/8myNMZJIKCfQpOI2JqAGZcry1ZrZjMJG8vDC5YKYCCIwp9ZDgI44bRg8KIU+cWNKulN4iFi/K1SFPEK0aF6XsssIAw4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129894; c=relaxed/simple; bh=SNLYlOC5DNyzJwqEwdYfz5p/eK7UMeIhQt4EQDMoiIk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Dg5S42xLKitzAd48/OaGxmtIkveWrEomxm7MGUMnjpywJgf/ITiL5sLdOCJe36xakgnMISoeTtGYiOULY213mSQqDcW2vmhxtpfEbdkSxTy/fODsun8gSkHnMWyyKSYbuWXveSiP+nqcBC0EBFJv+d6faih4z+Pq3xWThmaM0kE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=HxPmpN49; arc=fail smtp.client-ip=40.107.101.88 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="HxPmpN49" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i1Dwsmm6w0W7Ax5D1YrGdA7QH3UXDzrb941jgjdbjoyQVxIzy3F9Aghi0fd/pw9uSSE/GYtdYdWLlNlrdKOIW6gisS1Lhp7DRMQBoWPRpeUXAfNbP3fo/Mo2Two2cI8dYDcjE/0u29AnHr1nShw73nKQ2x1IKbYO2AWNVeIuPoE8MiLo4t1aOCSDk2XhLxDUiLGbKX2isTTJpQtSYNKdUVrGzxnH6w8pG/HnDbW1dmHVpfwWQZfUeUOm1PQZclqpdq3r7hEVSg+VX+AtX2GTDxNu6KVZsjXs7+zoKXuvP8eHXcn+tiFrHHbjthcLSWBDMLxe7ugqB5UL8HvT3JV0Yw== 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=zFn4XLYAV1hqTrSmZJytKYJYyzmtJMlpElBMk/DoxG0=; b=JsobFe60JiCHs9GjD+vgbfU+xZRJImM/5dI1UBhMz/A/esWxsmUzvYpKXICe1J9VxZubxVtViTzALSzRSu05/eOWqvGDLCYR3k9pmaq3lAb//hm8MX0w1mP03MsTkhl4IEHAQIHdj1aows1CMQoIfItdXw3c4jFlXS3Cm5GiFpcbBu5CKgNSQVY9YSAUlfDBp2+z6hmheD5OPydjo8wj9Da8ldB+AsByqYVH16bIOmP+qzeuqOBucBbbhA0rdXN1vsAdbP+KbWQqo0rQ7hMNpjRvajGQsj9YZgV4ZlGL6FyUYT2/mDjC4P6xk7z4meAQT0oIE30o56OGK3F/cu5hFw== 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=zFn4XLYAV1hqTrSmZJytKYJYyzmtJMlpElBMk/DoxG0=; b=HxPmpN49fnQM49HPKciY6coM9iGUT23npoVv9bntYrVPjl3jKLZLZIj2+P1V4+ufA7g6dPAmSaF2WT7FR0e5FgrLz22ADkkAOmqitEj9KVmxnWQi1jb7n6TV77Vx9OcE/QdPGtxtJ3c9L7dUAgqBwV28IZjg85RbVnB+8udRTvo= Received: from SJ0PR03CA0138.namprd03.prod.outlook.com (2603:10b6:a03:33c::23) by DM6PR12MB4313.namprd12.prod.outlook.com (2603:10b6:5:21e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.22; Fri, 31 May 2024 04:31:28 +0000 Received: from SJ1PEPF00002327.namprd03.prod.outlook.com (2603:10b6:a03:33c:cafe::79) by SJ0PR03CA0138.outlook.office365.com (2603:10b6:a03:33c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.30 via Frontend Transport; Fri, 31 May 2024 04:31:28 +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 SJ1PEPF00002327.mail.protection.outlook.com (10.167.242.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:31:28 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:31:24 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 02/24] virt: sev-guest: Replace dev_dbg with pr_debug Date: Fri, 31 May 2024 10:00:16 +0530 Message-ID: <20240531043038.3370793-3-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: SJ1PEPF00002327:EE_|DM6PR12MB4313:EE_ X-MS-Office365-Filtering-Correlation-Id: cdc11012-60a5-4ffd-d82a-08dc812a8a0e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|82310400017|376005|36860700004; X-Microsoft-Antispam-Message-Info: 52UTv/rrcE4KkVeKDYZqxfTGgd+6LXrgrvExjEDbnbDDc2Y1NcmZCqUT5rSB7gFn/AJwPLooZRXC/zB679TYGo37pl37lQeXKe/IjQCPwbFdVkN6kRq/YdEBckCnczlKIzKd9Lo4d4jgIO+hPEk99asihxT7fMTIcRFp2MoVpt3izXnEYnXEyYqMLh2zasAtMugrJ2VUAMiDihbQig7NWt/VkiLL5/l0ox2qDOiKJpyxPwrBW4Qx+4oSW7UstiwNZ15NnlLMhiA9u545LynaCxPB1fmeTefqpl4lj3VkUZ6PmZZi4ESD7k5soSJBy64TZiOmlby0A3usGj/wbqW21VUs4usyoLnVgHUHNnlkOIve9VzZ3xZzr0tncQRTKW+i7qlElsvd0OvEZ4vjwp4In9IWro+o85slBrJ/mQTU0gV9FvHM/NR0txP7LqZpZh2KPXor3WTmmr7lGmloJRBiWT6ggWURsCgjFdJa1DPb2rTYcs0jvtXEyqCzHpjUgdy85qGKWBcOANYQ2432f3TOzqlWYXAXvaSpvNmJimP/WsILJ+Qb40O+8Est9N9y7iwhLwiiHY9t2ZdrSCAXslruU//GO4BaxBJsHgH1//LjQtYjBZ7GIXX1lLTM7QiXfYlHzJzcVUR/IRZzPo7i7q6pjKxHgSmGgkIJpMu3JsGJBP7we668/I/eNAIvRSUuOmzNa1rbQFLi13Js8AC6F1Ym7dZ6mWqZtALzI6U5z5F+7texFlZPKR53jpFxnMlygpcRQTclPqLGa+ovbFshcgN8gieYcunUca6teNVS8eWS6mTCWqBZbgCEju4gc4l4eHa4HpanywYNlCBbgmKkmXarvJkgoz5SQX5TZUv8shfV+s9iHSqgpE++/ZqRMFIcqN6O1w93dpQl3Uo9lS08v5eVx4sTLv/A1z2YvZBnS6j6SAHl3HH2pmHqKnLU1uNTSL2/OMnCSn9qK965PS/NO75GQgwOd8/dVNl+Cx3q/o/wEKxn+PBxTe8CuWjLILhwTJ+rpWefFlsSdLTE+4+yzOMYV10KZtfykTf0eSNj51prxvDkW30IGT7PxNUlVCo9OEeIWbzK/A/s7NeJRVwiKggusv6rgdg2uendMBFxHV5VG/e0bWZxzHoq9/YeORaPzz3RbFha6xwzoZLgdeg+YFh6r5TAVBckAyrHl0w41Czy1q8O++sTgA8+l7fXoTWhMbmFoCbKgVMQxB2PTCfjWxsCS4N7uPMqMVN2bUegD/2o8/nAQlls76XZj3fL3pQ8TN/y7Jsz7wsmIO4S8bfVkH4bmZG/dRETCoC/QReYVMU39ZGs0YCwxksykH/Bf177l/pHcpVtmsaDAR2CaY/qqwyX2xrutP4EI85SQQjWTp7c8oI= 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)(7416005)(1800799015)(82310400017)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:31:28.3355 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cdc11012-60a5-4ffd-d82a-08dc812a8a0e 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: SJ1PEPF00002327.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4313 In preparation of moving code to arch/x86/kernel/sev.c, replace dev_dbg with pr_debug. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky Tested-by: Peter Gonda Reviewed-by: Borislav Petkov (AMD) --- drivers/virt/coco/sev-guest/sev-guest.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 0768c6692483..7e1bf2056b47 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -178,8 +178,9 @@ static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, struct aesgcm_ctx *ctx = snp_dev->ctx; u8 iv[GCM_AES_IV_SIZE] = {}; - dev_dbg(snp_dev->dev, "response [seqno %lld type %d version %d sz %d]\n", - resp_hdr->msg_seqno, resp_hdr->msg_type, resp_hdr->msg_version, resp_hdr->msg_sz); + pr_debug("response [seqno %lld type %d version %d sz %d]\n", + resp_hdr->msg_seqno, resp_hdr->msg_type, resp_hdr->msg_version, + resp_hdr->msg_sz); /* Copy response from shared memory to encrypted memory. */ memcpy(resp, snp_dev->response, sizeof(*resp)); @@ -232,8 +233,8 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 if (!hdr->msg_seqno) return -ENOSR; - dev_dbg(snp_dev->dev, "request [seqno %lld type %d version %d sz %d]\n", - hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); + pr_debug("request [seqno %lld type %d version %d sz %d]\n", + hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); if (WARN_ON((sz + ctx->authsize) > sizeof(req->payload))) return -EBADMSG; From patchwork Fri May 31 04:30:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681111 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2053.outbound.protection.outlook.com [40.107.244.53]) (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 1FE397E567; Fri, 31 May 2024 04:31:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129898; cv=fail; b=oiwWg1WTki9tTD/7ChMDcqxDVDk7PW54salZc6WFlmZ3DC7tabu2x5uc5bCqQy7GYv6RQEnnGPHjvgIFyPcd4pM1VzM2E0fGl7Yonvkj4Erk6FmDsKYbb51dq9zg3V62DraqTXT5pwD1XyT5Qjh6Dl7nwlF2g6y+B92dgcHbJ0w= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129898; c=relaxed/simple; bh=q2kWjEzjA+DFFztsKOcNuZwc737C3ZFSHARsEA35SQU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Tc3qN9Lv/mRWftPxvbkDa4Rm73bHaLlfEnudoH4eDKRLPzRVlW/0f4Z1ZRJ+HTvQrPBmh5WZ8YQZ+G4JRRikWhFdL5YMA0p5AaPiffaX40WJHI9LXAYxQdzjxhJPZ0KJweH28aczSqnyhm4GdW5jcBRONNGoRf5RzFDLGiFn1mI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=YdtV2+ic; arc=fail smtp.client-ip=40.107.244.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="YdtV2+ic" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N0Rg2u78Qs+Pdu9xHrDaM11wbY3APrwUy8iGYhTOlaTJS1seWyeEkr7Yju5rPc7zatyPwcurb9QZXB+RDrrdqvw8PMOZlmjITRUxgZDzDIWXZZIPhSsl51A5eFc0VanipYiBh7KUUkpyA2rC+gSQzaMGzLaY6vOlRl/0M2NLBD6URb3t7fnkUJyAYdkreu/AZCll0PdPjMDPiWDbGwS6VsaHX6k9PKE/vY71zV4XdBUKxUoCCbM7PA/AD4w2NRRQL7xz1VvgmgYzyfIc8wuQvniZ/gQcpOpvfkMeDfZZvM9dAC/NXIp+BiOyi+FwG+cA6vwVKkN5WnfWZ/F/tvOdYA== 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=nI/Y21S2btVbZW0tEO8bOp8UBMffd+nyqWoSmXb8jPA=; b=PvntYHBYb/djQKpg948EbTgbGSvp8up/fU6aAi4/qiAh/BwkQirmzV3VL6ECEnXock4RUMVuZaIV4Jp3LpbpTBXsU/26OptApJY0VjVDZkrQosn8gCtEcWfBMbFUxfYcqtCtt4EnfdXRGHrWCB5R9YOMC9bt7QiC+O5NQEaUP89rCzdwC8lki+v9PVXe1d5YeBwu2aIpaBvM4JU3JPOADuGGbGeJHbpmWdp4YNw78b1NXnqpcILhRvIFC2yeKxHrM26J/wsNemEXsw6gwXkAOi6JbRXDayIVVEnoHc7WhD2Vmg4ZDukMQ87lj49F3X+jxU7Of89DuA267+40VMLqdg== 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=nI/Y21S2btVbZW0tEO8bOp8UBMffd+nyqWoSmXb8jPA=; b=YdtV2+icvcb8NWOUdBojYVpzLhXcl7rSzwNTDkqW86whYGvzqpSoZzgnsHiDK5017OZuIYJCrAdjx1jY+9EcCDQZOTZuwjAuOi55fC3AwTI8Bd9dXKxnvbcmBHWL/Spjkcn9cvXY0PAi/qoPRIC8Pto4PNHxPhqpD1c5ZIR68LI= Received: from SJ0PR03CA0129.namprd03.prod.outlook.com (2603:10b6:a03:33c::14) by IA1PR12MB9030.namprd12.prod.outlook.com (2603:10b6:208:3f2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22; Fri, 31 May 2024 04:31:32 +0000 Received: from SJ1PEPF00002327.namprd03.prod.outlook.com (2603:10b6:a03:33c:cafe::cb) by SJ0PR03CA0129.outlook.office365.com (2603:10b6:a03:33c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24 via Frontend Transport; Fri, 31 May 2024 04:31:32 +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 SJ1PEPF00002327.mail.protection.outlook.com (10.167.242.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:31:32 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:31:27 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 03/24] virt: sev-guest: Make payload a variable length array Date: Fri, 31 May 2024 10:00:17 +0530 Message-ID: <20240531043038.3370793-4-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: SJ1PEPF00002327:EE_|IA1PR12MB9030:EE_ X-MS-Office365-Filtering-Correlation-Id: a9e83b7f-3fd3-4598-492b-08dc812a8c46 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|376005|1800799015|36860700004|7416005; X-Microsoft-Antispam-Message-Info: ZEgA+AcN+OYaBeivLlD6CQ4Vo4j1eEpJhAecgM8XTmLCcwBVkn1nEXreP+wDskVem+xGYZ3IkVlTT+jT4mPSBfNKTXmM5mbgyLtCbJ2M4y3ejhTtpDA7GxwLaIdsh6gHo8UGd84op0/v2H5NF5jOQiBsSKQMzY4lXgzjmjJlV9ypMtmU7hMn6XG1kNgYrMMiuy1+qFyy29jneFcnng7367c/WJ3pF/vhNSXtLmNOjVIjBZa/InwXkg11tgdYFAMfoeXGSuKCjZvlZ8tSKKmwsS6YKwwy5fZxL/ZCPDuCmgHDcUVVW+U1nu0anHFrckjVr8v9SCKjscMc/bgo/RPnVnIDJcNVVynl7wUpjGNcAxQdWGoGz+snSKu0oazAgNELdYR7lfWWBzZiwAni0A3xFfY0Q1JbzqpPESYV6qSvJNOem/AdegWrTbNAwcR1TjjTktP6f7lSx1FMHsPgjT2qzWlM+zsz2/H7AfvRnhHWNprHXPQfa/nIxHajDCLe1PWVGaHrHS480nR+UFFwFGl1yHjxoc4+2aTESyW5Y7+x7b0gMrKvYzUeX536BxC3L9ydQ0RJLQHmNpEJ3WJ0hOFGU/W0kPjpqXSfwN+cb/FbeoTHseyi9z5ozDNZzk5nLO28AmhGaIfUjlkD257WJ+K1tOmG9Ny+57AAhjd6AcDGI3P4yyDQE5AsotX5qiS4J2kRuqT2w6qrIyZdyrR+CjgKRAJ4ss+E01WVKJOnSBHhhfYRfyrNzkgJtEZXPb6OIIvtDRNgqe4zGSiyyrwLAVS0Q/hXdVbJ4BVqAbRGKbsx9g5zQYncggKPIIDKF/NFxP1kXtPj5ka7T0zxgbc8APsdp3Ivvd/JikpN3Lctjk5v5LN0Ijxs/aYDQFsPn/R3j/u/jVXZfIT0o4IDbcuSlMobVUqYmUMh7PPtg8GxBfAMjI5tEZWKAUSL1QU7G4oKPGnir1p1sVtJH0V7kANo8lPGU8qb0OWhPS7SZiHVBB67txXnC9gGljF+OuyC5tICtvn1JV5SWXRP78SgjM/3V2yQDCxWUbakLGu2Cpi49GuWHKxOAV+308IaiAQWaUYNxo6nDC+O+cRcuc0hQLg9Ufob6xL3m1Dly5rSevx7iv7DIOByBMlDlBFnF9Jc6c48vqOmBOUxIHIbmcL3VBUXGjUMZRjH+yX/3cWJdcjszqmMxlj8IIdfjOkQ2E+9CkMPlFEB20MEoD70gW2yU9iwOg1e0jECbZ/kcIG1bzUjC+PbSJdi/tIAoDopbfV9GlY56CRhfKqSxMb8OwdOUsFD8fGDNDR84r5gNdawv45gsAMxnT6jkwgHGm2TJhJ9dK3To2g9Wl5ex4LCv4N2LP8NNLSxto8asSEO+NvfmmI1Orzy8Zu7VvXlkJSMfRp9CIy+Ce8u 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)(82310400017)(376005)(1800799015)(36860700004)(7416005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:31:32.0544 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a9e83b7f-3fd3-4598-492b-08dc812a8c46 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: SJ1PEPF00002327.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB9030 Currently, guest message is PAGE_SIZE bytes and payload is hard-coded to 4000 bytes, assuming snp_guest_msg_hdr structure as 96 bytes. Remove the structure size assumption and hard-coding of payload size and instead use variable length array. While at it, rename the local guest message variables for clarity. Signed-off-by: Nikunj A Dadhania Suggested-by: Tom Lendacky Reviewed-by: Tom Lendacky Signed-off-by: Nikunj A Dadhania Acked-by: Borislav Petkov (AMD) --- drivers/virt/coco/sev-guest/sev-guest.h | 5 +- drivers/virt/coco/sev-guest/sev-guest.c | 74 +++++++++++++++---------- 2 files changed, 48 insertions(+), 31 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.h b/drivers/virt/coco/sev-guest/sev-guest.h index ceb798a404d6..97796f658fd3 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.h +++ b/drivers/virt/coco/sev-guest/sev-guest.h @@ -60,7 +60,10 @@ struct snp_guest_msg_hdr { struct snp_guest_msg { struct snp_guest_msg_hdr hdr; - u8 payload[4000]; + u8 payload[]; } __packed; +#define SNP_GUEST_MSG_SIZE 4096 +#define SNP_GUEST_MSG_PAYLOAD_SIZE (SNP_GUEST_MSG_SIZE - sizeof(struct snp_guest_msg)) + #endif /* __VIRT_SEVGUEST_H__ */ diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 7e1bf2056b47..69bd817239d8 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -48,7 +48,7 @@ struct snp_guest_dev { * Avoid information leakage by double-buffering shared messages * in fields that are in regular encrypted memory. */ - struct snp_guest_msg secret_request, secret_response; + struct snp_guest_msg *secret_request, *secret_response; struct snp_secrets_page *secrets; struct snp_req_data input; @@ -171,40 +171,40 @@ static struct aesgcm_ctx *snp_init_crypto(u8 *key, size_t keylen) static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, u32 sz) { - struct snp_guest_msg *resp = &snp_dev->secret_response; - struct snp_guest_msg *req = &snp_dev->secret_request; - struct snp_guest_msg_hdr *req_hdr = &req->hdr; - struct snp_guest_msg_hdr *resp_hdr = &resp->hdr; + struct snp_guest_msg *resp_msg = snp_dev->secret_response; + struct snp_guest_msg *req_msg = snp_dev->secret_request; + struct snp_guest_msg_hdr *req_msg_hdr = &req_msg->hdr; + struct snp_guest_msg_hdr *resp_msg_hdr = &resp_msg->hdr; struct aesgcm_ctx *ctx = snp_dev->ctx; u8 iv[GCM_AES_IV_SIZE] = {}; pr_debug("response [seqno %lld type %d version %d sz %d]\n", - resp_hdr->msg_seqno, resp_hdr->msg_type, resp_hdr->msg_version, - resp_hdr->msg_sz); + resp_msg_hdr->msg_seqno, resp_msg_hdr->msg_type, resp_msg_hdr->msg_version, + resp_msg_hdr->msg_sz); /* Copy response from shared memory to encrypted memory. */ - memcpy(resp, snp_dev->response, sizeof(*resp)); + memcpy(resp_msg, snp_dev->response, SNP_GUEST_MSG_SIZE); /* Verify that the sequence counter is incremented by 1 */ - if (unlikely(resp_hdr->msg_seqno != (req_hdr->msg_seqno + 1))) + if (unlikely(resp_msg_hdr->msg_seqno != (req_msg_hdr->msg_seqno + 1))) return -EBADMSG; /* Verify response message type and version number. */ - if (resp_hdr->msg_type != (req_hdr->msg_type + 1) || - resp_hdr->msg_version != req_hdr->msg_version) + if (resp_msg_hdr->msg_type != (req_msg_hdr->msg_type + 1) || + resp_msg_hdr->msg_version != req_msg_hdr->msg_version) return -EBADMSG; /* * If the message size is greater than our buffer length then return * an error. */ - if (unlikely((resp_hdr->msg_sz + ctx->authsize) > sz)) + if (unlikely((resp_msg_hdr->msg_sz + ctx->authsize) > sz)) return -EBADMSG; /* Decrypt the payload */ - memcpy(iv, &resp_hdr->msg_seqno, min(sizeof(iv), sizeof(resp_hdr->msg_seqno))); - if (!aesgcm_decrypt(ctx, payload, resp->payload, resp_hdr->msg_sz, - &resp_hdr->algo, AAD_LEN, iv, resp_hdr->authtag)) + memcpy(iv, &resp_msg_hdr->msg_seqno, min(sizeof(iv), sizeof(resp_msg_hdr->msg_seqno))); + if (!aesgcm_decrypt(ctx, payload, resp_msg->payload, resp_msg_hdr->msg_sz, + &resp_msg_hdr->algo, AAD_LEN, iv, resp_msg_hdr->authtag)) return -EBADMSG; return 0; @@ -213,12 +213,12 @@ static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 type, void *payload, size_t sz) { - struct snp_guest_msg *req = &snp_dev->secret_request; - struct snp_guest_msg_hdr *hdr = &req->hdr; + struct snp_guest_msg *msg = snp_dev->secret_request; + struct snp_guest_msg_hdr *hdr = &msg->hdr; struct aesgcm_ctx *ctx = snp_dev->ctx; u8 iv[GCM_AES_IV_SIZE] = {}; - memset(req, 0, sizeof(*req)); + memset(msg, 0, SNP_GUEST_MSG_SIZE); hdr->algo = SNP_AEAD_AES_256_GCM; hdr->hdr_version = MSG_HDR_VER; @@ -236,11 +236,11 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 pr_debug("request [seqno %lld type %d version %d sz %d]\n", hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); - if (WARN_ON((sz + ctx->authsize) > sizeof(req->payload))) + if (WARN_ON((sz + ctx->authsize) > SNP_GUEST_MSG_PAYLOAD_SIZE)) return -EBADMSG; memcpy(iv, &hdr->msg_seqno, min(sizeof(iv), sizeof(hdr->msg_seqno))); - aesgcm_encrypt(ctx, req->payload, payload, sz, &hdr->algo, AAD_LEN, + aesgcm_encrypt(ctx, msg->payload, payload, sz, &hdr->algo, AAD_LEN, iv, hdr->authtag); return 0; @@ -346,7 +346,7 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, return -EIO; /* Clear shared memory's response for the host to populate. */ - memset(snp_dev->response, 0, sizeof(struct snp_guest_msg)); + memset(snp_dev->response, 0, SNP_GUEST_MSG_SIZE); /* Encrypt the userspace provided payload in snp_dev->secret_request. */ rc = enc_payload(snp_dev, seqno, rio->msg_version, type, req_buf, req_sz); @@ -357,8 +357,7 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, * Write the fully encrypted request to the shared unencrypted * request page. */ - memcpy(snp_dev->request, &snp_dev->secret_request, - sizeof(snp_dev->secret_request)); + memcpy(snp_dev->request, &snp_dev->secret_request, SNP_GUEST_MSG_SIZE); rc = __handle_guest_request(snp_dev, exit_code, rio); if (rc) { @@ -842,12 +841,21 @@ static int __init sev_guest_probe(struct platform_device *pdev) snp_dev->dev = dev; snp_dev->secrets = secrets; + /* Allocate secret request and response message for double buffering */ + snp_dev->secret_request = kzalloc(SNP_GUEST_MSG_SIZE, GFP_KERNEL); + if (!snp_dev->secret_request) + goto e_unmap; + + snp_dev->secret_response = kzalloc(SNP_GUEST_MSG_SIZE, GFP_KERNEL); + if (!snp_dev->secret_response) + goto e_free_secret_req; + /* Allocate the shared page used for the request and response message. */ - snp_dev->request = alloc_shared_pages(dev, sizeof(struct snp_guest_msg)); + snp_dev->request = alloc_shared_pages(dev, SNP_GUEST_MSG_SIZE); if (!snp_dev->request) - goto e_unmap; + goto e_free_secret_resp; - snp_dev->response = alloc_shared_pages(dev, sizeof(struct snp_guest_msg)); + snp_dev->response = alloc_shared_pages(dev, SNP_GUEST_MSG_SIZE); if (!snp_dev->response) goto e_free_request; @@ -890,9 +898,13 @@ static int __init sev_guest_probe(struct platform_device *pdev) e_free_cert_data: free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE); e_free_response: - free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg)); + free_shared_pages(snp_dev->response, SNP_GUEST_MSG_SIZE); e_free_request: - free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg)); + free_shared_pages(snp_dev->request, SNP_GUEST_MSG_SIZE); +e_free_secret_resp: + kfree(snp_dev->secret_response); +e_free_secret_req: + kfree(snp_dev->secret_request); e_unmap: iounmap(mapping); return ret; @@ -903,8 +915,10 @@ static void __exit sev_guest_remove(struct platform_device *pdev) struct snp_guest_dev *snp_dev = platform_get_drvdata(pdev); free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE); - free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg)); - free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg)); + free_shared_pages(snp_dev->response, SNP_GUEST_MSG_SIZE); + free_shared_pages(snp_dev->request, SNP_GUEST_MSG_SIZE); + kfree(snp_dev->secret_response); + kfree(snp_dev->secret_request); kfree(snp_dev->ctx); misc_deregister(&snp_dev->misc); } From patchwork Fri May 31 04:30:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681112 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2057.outbound.protection.outlook.com [40.107.95.57]) (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 6F0D1208A9; Fri, 31 May 2024 04:32:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129942; cv=fail; b=a/s9HEuaQvb6Xvo82QHwhEMaZCaRdyQq6mOwYKktsQ1GspJNdH5MqYtaSMo1RYZQ/1y+vkYmmwXuCbjQhbuM+ryp0W9c2+iM4CPCuSWloSv7PWrq1inkgAOzBWHhbDL+32rBm9oRhVfzw9VGS9u3Xv5ne5/dMrNivLPD2PKiGsA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129942; c=relaxed/simple; bh=d1rWMx1QPn6jbcFd+n4eU5UAH+QltNpHO2hgC3Q/Afg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=suOWRXRvzlvpBTU15C0vS8O1M9apucgh2z4auyLXKeNkL/H/oXjoc7ng/TNrsUfvj0pQnFKr/KiPdAacXwjZ+DSFha1nd7bP2VYFgGheQHjsc5YS0B31rAXbDrITrCWcYbrrtxGuNC0uvuC6zs5gIMU4pls91nj6F4edjPWACAY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=YcFQT9uM; arc=fail smtp.client-ip=40.107.95.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="YcFQT9uM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IscfX+pAXd4fpVum2jhp/sja3OuHCxo4HsFHb91RR8JhySvo7w1CTFO0gG5OBoNFSvoZRWqidRFPX4uMBBGQ2XfdQi6IqYHPO2l0Z+RKWTp72jtAJbnoK9JZOVNvU77xGEhNKoe+94TVbnVy3+rk3yI+viS6epRJJTnGhBIAHIYaZHe8Jp514GsSpMnrDmsUhRzc4sWx/gh3WfyU9+yPy6//gHyeEPYTrMyTcoZh4l4pxi5te7bSQxXuzuZ9xJCccLmK91qiHSwhD2PWv1w3yhpVUzaEekh9uI5f2/3JuBT9WVsgbxni7rLhg03673r5Bzpx/Sboz0qS2XlwmDkPXg== 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=TvKSxTjKqXCcxa90DTuEl+Z5I8inQRhapQV6hmDUr6g=; b=XLs+vCLIk6azCj50IfuhyQQZ1gG3RR23EfB7FDfjxKiErtHQ89ftMUVy8nWK+cNr/x7IhuTB5vYvWgNJvRbuGvBzyDRAFwZt1jIdv71N3uWSYhrnkZpCZdqCh6Ur6rgeXe9/HOc6MmOEAkAta4AIpuor7RNJZnO0eIaeeq4tE2yiAZlyqok/mx4goCQw41CMslgAj7YSg3rGidK2kk2u6GK7tNl7SvVplPuSZWZLdhufJGJ+f825RzrkQUXbFyEPDe+Hbw/yMDN8+1KUcrpjcAF3Uj8xK07qBdHZa527NJgh8dYSir9shqLJqurQfnmle/v/AxdEWA1ZHKWl86mSOw== 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=TvKSxTjKqXCcxa90DTuEl+Z5I8inQRhapQV6hmDUr6g=; b=YcFQT9uMVQYqRi8GJfJdQNxQoZfomplu3R6L8doMboutZZfESCCclAq/54ryM5UUnfIIcZKmmjNl9M0dOjKyVW69kXqQXsJvzOavoYDhI3IByOnHO2zu8tNr7SO7DcBs2QUM/258Zp3lDV4YNB6m3huSXk7NG4gAZ9voMXqR9uY= Received: from BYAPR05CA0013.namprd05.prod.outlook.com (2603:10b6:a03:c0::26) by IA1PR12MB8309.namprd12.prod.outlook.com (2603:10b6:208:3fe::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.22; Fri, 31 May 2024 04:32:17 +0000 Received: from SJ1PEPF00002321.namprd03.prod.outlook.com (2603:10b6:a03:c0:cafe::35) by BYAPR05CA0013.outlook.office365.com (2603:10b6:a03:c0::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.9 via Frontend Transport; Fri, 31 May 2024 04:32:17 +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 SJ1PEPF00002321.mail.protection.outlook.com (10.167.242.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:32:17 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:31:31 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 04/24] virt: sev-guest: Add SNP guest request structure Date: Fri, 31 May 2024 10:00:18 +0530 Message-ID: <20240531043038.3370793-5-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: SJ1PEPF00002321:EE_|IA1PR12MB8309:EE_ X-MS-Office365-Filtering-Correlation-Id: deb1486a-ed39-493d-9149-08dc812aa74c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|82310400017|7416005|1800799015|36860700004; X-Microsoft-Antispam-Message-Info: EC4VOaSFjgpTgGnkcPzNI+HPddMCF3PKqeo0QEgdrRDqqhV62Cje7O7ivmo/f1N4aAIp0XJkkLGhtAih1eMAtITKXXI4ksixiDyT++mAOjEI1QFZdsnw6T9h33zAtDikkyxRfstAAdNsV7j1H8fu7ol5OZisvHz60rzV/mGm4qipty7JKNvfE0k37kNHTiEhOzedvPgGHH8x24vIfTxIZRMSLFlkEMXnALonqCxbdUH0kUapb9KE+/+4MYW40fzcaBkAmIbmEC/mkrnSgjcJpkUUpBWugcJMJhF0h1XUjsvFKKxmgCxp8bU8dvI86gdX14etAgSWAgE7mirh9IiTVIF55fZ8eHGP4Ha2So4yl7+7qlPDEQKV8kJ+lntDQmCL6+f26BAbbqCF6gdrr6OiG1tczSpVjx9n/RdUMH0IP+Yea4V3t5nsb1Yrza0p1JodNY51G0uTuJ0BX7e0LVGslyogNL1ruueh1wUnz+uTqFXMPRvAR7U8hWR6Zof1+u5XtLcg7h6BnITn5+pd/72ZA0EJDzuxKuUBwu5I4iiFOiu3OZt1cRmnuKSnWq43rU08Zh9Ttv/Ee3Qt56EZF3WLJu2DowPARqaZJhxgy35kAXo0r7bijdi0QXK1H46Iv7wk3SAY8NJSikTbdnkqto0aBXwJviS3ltVxOciZG6WFXPF3ELeALf4Q4rvYPQL/KxhP4uRBPlo8qnRYvb21fMl4Oj9BB5GUu+eRmn+g1pQidxay4X7uplIJ2ZLPde4oSB+XnisFb289sOX9+XMH6aZQsjklSaQXHQAbYNY5pqiIfjPw8MjD/7SUEmX6IOLhFiQt10CL5wrymgqgo8y2dpgFm8zXf0gqtLcz5gJdHH1OY/vqrGaOzYXNMnds3KRYJ8DUhOkIWUi2/vVgiA5/OBXZ4TUodOs89khEjcE2NwF510CjT+iiCUy/uYzZjozNgplIW3OuV38HjzJrMleQNk/tvdHAAsIV+TOZUbH11icLgdGZVgmbfVXKg+ZbA7PeF7Cwag30r3Fm/7OAEBmzt5wfYS8wcVyjGVKfHbGUAAT57GTwO3qV86H+E8TiLXUvnahuxbij03BEnPO2F/g/BZnEwXsiYYhOvatv/H4UtG7I9dOPi+n5Hma8J8ZOJGut9etiFcacBhrsy5V4mRkyBbd1SQ+i2n2ePucHjVwWf2ACrAKXS3SEnxm3FLEVxz534WOwKVIjXYgzhYut4l/9XBuKgGwcuqFC4yzxHatTypiDQWKu8uu8l5WDYMnhi4L1pCVhvf9QEzrznNw4hmmZuxDnHArQSNiKwhmKLvHZwhazWL8yumbHVpw1hrYh5NAAuv21 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)(376005)(82310400017)(7416005)(1800799015)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:32:17.3940 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: deb1486a-ed39-493d-9149-08dc812aa74c 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: SJ1PEPF00002321.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8309 Add a snp_guest_req structure to simplify the function arguments. This structure will be used to call the SNP Guest message request API instead of passing a long list of parameters. Update the snp_issue_guest_request() prototype to include the new guest request structure and move all the sev-guest.h header content to sev.h. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky --- arch/x86/include/asm/sev.h | 78 ++++++++++- drivers/virt/coco/sev-guest/sev-guest.h | 69 ---------- arch/x86/kernel/sev.c | 15 ++- drivers/virt/coco/sev-guest/sev-guest.c | 169 +++++++++++++----------- 4 files changed, 177 insertions(+), 154 deletions(-) delete mode 100644 drivers/virt/coco/sev-guest/sev-guest.h diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index ca20cc4e5826..dbf17e66d52a 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -112,8 +112,6 @@ struct rmp_state { struct snp_req_data { unsigned long req_gpa; unsigned long resp_gpa; - unsigned long data_gpa; - unsigned int data_npages; }; struct sev_guest_platform_data { @@ -155,6 +153,76 @@ struct snp_secrets_page { u8 rsvd3[3840]; } __packed; +#define MAX_AUTHTAG_LEN 32 +#define AUTHTAG_LEN 16 +#define AAD_LEN 48 +#define MSG_HDR_VER 1 + +/* See SNP spec SNP_GUEST_REQUEST section for the structure */ +enum msg_type { + SNP_MSG_TYPE_INVALID = 0, + SNP_MSG_CPUID_REQ, + SNP_MSG_CPUID_RSP, + SNP_MSG_KEY_REQ, + SNP_MSG_KEY_RSP, + SNP_MSG_REPORT_REQ, + SNP_MSG_REPORT_RSP, + SNP_MSG_EXPORT_REQ, + SNP_MSG_EXPORT_RSP, + SNP_MSG_IMPORT_REQ, + SNP_MSG_IMPORT_RSP, + SNP_MSG_ABSORB_REQ, + SNP_MSG_ABSORB_RSP, + SNP_MSG_VMRK_REQ, + SNP_MSG_VMRK_RSP, + + SNP_MSG_TYPE_MAX +}; + +enum aead_algo { + SNP_AEAD_INVALID, + SNP_AEAD_AES_256_GCM, +}; + +struct snp_guest_msg_hdr { + u8 authtag[MAX_AUTHTAG_LEN]; + u64 msg_seqno; + u8 rsvd1[8]; + u8 algo; + u8 hdr_version; + u16 hdr_sz; + u8 msg_type; + u8 msg_version; + u16 msg_sz; + u32 rsvd2; + u8 msg_vmpck; + u8 rsvd3[35]; +} __packed; + +struct snp_guest_msg { + struct snp_guest_msg_hdr hdr; + u8 payload[]; +} __packed; + +#define SNP_GUEST_MSG_SIZE 4096 +#define SNP_GUEST_MSG_PAYLOAD_SIZE (SNP_GUEST_MSG_SIZE - sizeof(struct snp_guest_msg)) + +struct snp_guest_req { + void *req_buf; + size_t req_sz; + + void *resp_buf; + size_t resp_sz; + + void *data; + size_t data_npages; + + u64 exit_code; + unsigned int vmpck_id; + u8 msg_version; + u8 msg_type; +}; + #ifdef CONFIG_AMD_MEM_ENCRYPT extern void __sev_es_ist_enter(struct pt_regs *regs); extern void __sev_es_ist_exit(void); @@ -224,7 +292,8 @@ void snp_set_wakeup_secondary_cpu(void); bool snp_init(struct boot_params *bp); void __noreturn snp_abort(void); void snp_dmi_setup(void); -int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, struct snp_guest_request_ioctl *rio); +int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data *input, + struct snp_guest_request_ioctl *rio); void snp_accept_memory(phys_addr_t start, phys_addr_t end); u64 snp_get_unsupported_features(u64 status); u64 sev_get_status(void); @@ -249,7 +318,8 @@ static inline void snp_set_wakeup_secondary_cpu(void) { } static inline bool snp_init(struct boot_params *bp) { return false; } static inline void snp_abort(void) { } static inline void snp_dmi_setup(void) { } -static inline int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, struct snp_guest_request_ioctl *rio) +static inline int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data *input, + struct snp_guest_request_ioctl *rio) { return -ENOTTY; } diff --git a/drivers/virt/coco/sev-guest/sev-guest.h b/drivers/virt/coco/sev-guest/sev-guest.h deleted file mode 100644 index 97796f658fd3..000000000000 --- a/drivers/virt/coco/sev-guest/sev-guest.h +++ /dev/null @@ -1,69 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2021 Advanced Micro Devices, Inc. - * - * Author: Brijesh Singh - * - * SEV-SNP API spec is available at https://developer.amd.com/sev - */ - -#ifndef __VIRT_SEVGUEST_H__ -#define __VIRT_SEVGUEST_H__ - -#include - -#define MAX_AUTHTAG_LEN 32 -#define AUTHTAG_LEN 16 -#define AAD_LEN 48 -#define MSG_HDR_VER 1 - -/* See SNP spec SNP_GUEST_REQUEST section for the structure */ -enum msg_type { - SNP_MSG_TYPE_INVALID = 0, - SNP_MSG_CPUID_REQ, - SNP_MSG_CPUID_RSP, - SNP_MSG_KEY_REQ, - SNP_MSG_KEY_RSP, - SNP_MSG_REPORT_REQ, - SNP_MSG_REPORT_RSP, - SNP_MSG_EXPORT_REQ, - SNP_MSG_EXPORT_RSP, - SNP_MSG_IMPORT_REQ, - SNP_MSG_IMPORT_RSP, - SNP_MSG_ABSORB_REQ, - SNP_MSG_ABSORB_RSP, - SNP_MSG_VMRK_REQ, - SNP_MSG_VMRK_RSP, - - SNP_MSG_TYPE_MAX -}; - -enum aead_algo { - SNP_AEAD_INVALID, - SNP_AEAD_AES_256_GCM, -}; - -struct snp_guest_msg_hdr { - u8 authtag[MAX_AUTHTAG_LEN]; - u64 msg_seqno; - u8 rsvd1[8]; - u8 algo; - u8 hdr_version; - u16 hdr_sz; - u8 msg_type; - u8 msg_version; - u16 msg_sz; - u32 rsvd2; - u8 msg_vmpck; - u8 rsvd3[35]; -} __packed; - -struct snp_guest_msg { - struct snp_guest_msg_hdr hdr; - u8 payload[]; -} __packed; - -#define SNP_GUEST_MSG_SIZE 4096 -#define SNP_GUEST_MSG_PAYLOAD_SIZE (SNP_GUEST_MSG_SIZE - sizeof(struct snp_guest_msg)) - -#endif /* __VIRT_SEVGUEST_H__ */ diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 3342ed58e168..8145bf123ac9 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2191,7 +2191,8 @@ static int __init init_sev_config(char *str) } __setup("sev=", init_sev_config); -int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, struct snp_guest_request_ioctl *rio) +int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data *input, + struct snp_guest_request_ioctl *rio) { struct ghcb_state state; struct es_em_ctxt ctxt; @@ -2215,12 +2216,12 @@ int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, struct sn vc_ghcb_invalidate(ghcb); - if (exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST) { - ghcb_set_rax(ghcb, input->data_gpa); - ghcb_set_rbx(ghcb, input->data_npages); + if (req->exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST) { + ghcb_set_rax(ghcb, __pa(req->data)); + ghcb_set_rbx(ghcb, req->data_npages); } - ret = sev_es_ghcb_hv_call(ghcb, &ctxt, exit_code, input->req_gpa, input->resp_gpa); + ret = sev_es_ghcb_hv_call(ghcb, &ctxt, req->exit_code, input->req_gpa, input->resp_gpa); if (ret) goto e_put; @@ -2235,8 +2236,8 @@ int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, struct sn case SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN): /* Number of expected pages are returned in RBX */ - if (exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST) { - input->data_npages = ghcb_get_rbx(ghcb); + if (req->exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST) { + req->data_npages = ghcb_get_rbx(ghcb); ret = -ENOSPC; break; } diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 69bd817239d8..b6be676f82be 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -28,8 +28,6 @@ #include #include -#include "sev-guest.h" - #define DEVICE_NAME "sev-guest" #define SNP_REQ_MAX_RETRY_DURATION (60*HZ) @@ -169,7 +167,7 @@ static struct aesgcm_ctx *snp_init_crypto(u8 *key, size_t keylen) return ctx; } -static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, u32 sz) +static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, struct snp_guest_req *req) { struct snp_guest_msg *resp_msg = snp_dev->secret_response; struct snp_guest_msg *req_msg = snp_dev->secret_request; @@ -198,20 +196,19 @@ static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, * If the message size is greater than our buffer length then return * an error. */ - if (unlikely((resp_msg_hdr->msg_sz + ctx->authsize) > sz)) + if (unlikely((resp_msg_hdr->msg_sz + ctx->authsize) > req->resp_sz)) return -EBADMSG; /* Decrypt the payload */ memcpy(iv, &resp_msg_hdr->msg_seqno, min(sizeof(iv), sizeof(resp_msg_hdr->msg_seqno))); - if (!aesgcm_decrypt(ctx, payload, resp_msg->payload, resp_msg_hdr->msg_sz, + if (!aesgcm_decrypt(ctx, req->resp_buf, resp_msg->payload, resp_msg_hdr->msg_sz, &resp_msg_hdr->algo, AAD_LEN, iv, resp_msg_hdr->authtag)) return -EBADMSG; return 0; } -static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 type, - void *payload, size_t sz) +static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, struct snp_guest_req *req) { struct snp_guest_msg *msg = snp_dev->secret_request; struct snp_guest_msg_hdr *hdr = &msg->hdr; @@ -223,11 +220,11 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 hdr->algo = SNP_AEAD_AES_256_GCM; hdr->hdr_version = MSG_HDR_VER; hdr->hdr_sz = sizeof(*hdr); - hdr->msg_type = type; - hdr->msg_version = version; + hdr->msg_type = req->msg_type; + hdr->msg_version = req->msg_version; hdr->msg_seqno = seqno; - hdr->msg_vmpck = vmpck_id; - hdr->msg_sz = sz; + hdr->msg_vmpck = req->vmpck_id; + hdr->msg_sz = req->req_sz; /* Verify the sequence number is non-zero */ if (!hdr->msg_seqno) @@ -236,17 +233,17 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 pr_debug("request [seqno %lld type %d version %d sz %d]\n", hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); - if (WARN_ON((sz + ctx->authsize) > SNP_GUEST_MSG_PAYLOAD_SIZE)) + if (WARN_ON((req->req_sz + ctx->authsize) > SNP_GUEST_MSG_PAYLOAD_SIZE)) return -EBADMSG; memcpy(iv, &hdr->msg_seqno, min(sizeof(iv), sizeof(hdr->msg_seqno))); - aesgcm_encrypt(ctx, msg->payload, payload, sz, &hdr->algo, AAD_LEN, - iv, hdr->authtag); + aesgcm_encrypt(ctx, msg->payload, req->req_buf, req->req_sz, &hdr->algo, + AAD_LEN, iv, hdr->authtag); return 0; } -static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, +static int __handle_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, struct snp_guest_request_ioctl *rio) { unsigned long req_start = jiffies; @@ -261,7 +258,7 @@ static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, * sequence number must be incremented or the VMPCK must be deleted to * prevent reuse of the IV. */ - rc = snp_issue_guest_request(exit_code, &snp_dev->input, rio); + rc = snp_issue_guest_request(req, &snp_dev->input, rio); switch (rc) { case -ENOSPC: /* @@ -271,8 +268,8 @@ static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, * order to increment the sequence number and thus avoid * IV reuse. */ - override_npages = snp_dev->input.data_npages; - exit_code = SVM_VMGEXIT_GUEST_REQUEST; + override_npages = req->data_npages; + req->exit_code = SVM_VMGEXIT_GUEST_REQUEST; /* * Override the error to inform callers the given extended @@ -327,15 +324,13 @@ static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, } if (override_npages) - snp_dev->input.data_npages = override_npages; + req->data_npages = override_npages; return rc; } -static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, - struct snp_guest_request_ioctl *rio, u8 type, - void *req_buf, size_t req_sz, void *resp_buf, - u32 resp_sz) +static int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, + struct snp_guest_request_ioctl *rio) { u64 seqno; int rc; @@ -349,7 +344,7 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, memset(snp_dev->response, 0, SNP_GUEST_MSG_SIZE); /* Encrypt the userspace provided payload in snp_dev->secret_request. */ - rc = enc_payload(snp_dev, seqno, rio->msg_version, type, req_buf, req_sz); + rc = enc_payload(snp_dev, seqno, req); if (rc) return rc; @@ -357,9 +352,9 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, * Write the fully encrypted request to the shared unencrypted * request page. */ - memcpy(snp_dev->request, &snp_dev->secret_request, SNP_GUEST_MSG_SIZE); + memcpy(snp_dev->request, snp_dev->secret_request, SNP_GUEST_MSG_SIZE); - rc = __handle_guest_request(snp_dev, exit_code, rio); + rc = __handle_guest_request(snp_dev, req, rio); if (rc) { if (rc == -EIO && rio->exitinfo2 == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN)) @@ -368,12 +363,11 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, dev_alert(snp_dev->dev, "Detected error from ASP request. rc: %d, exitinfo2: 0x%llx\n", rc, rio->exitinfo2); - snp_disable_vmpck(snp_dev); return rc; } - rc = verify_and_dec_payload(snp_dev, resp_buf, resp_sz); + rc = verify_and_dec_payload(snp_dev, req); if (rc) { dev_alert(snp_dev->dev, "Detected unexpected decode failure from ASP. rc: %d\n", rc); snp_disable_vmpck(snp_dev); @@ -390,8 +384,9 @@ struct snp_req_resp { static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg) { - struct snp_report_req *req = &snp_dev->req.report; - struct snp_report_resp *resp; + struct snp_report_req *report_req = &snp_dev->req.report; + struct snp_guest_req req = {0}; + struct snp_report_resp *report_resp; int rc, resp_len; lockdep_assert_held(&snp_cmd_mutex); @@ -399,7 +394,7 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io if (!arg->req_data || !arg->resp_data) return -EINVAL; - if (copy_from_user(req, (void __user *)arg->req_data, sizeof(*req))) + if (copy_from_user(report_req, (void __user *)arg->req_data, sizeof(*report_req))) return -EFAULT; /* @@ -407,29 +402,37 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(resp->data) + snp_dev->ctx->authsize; - resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); - if (!resp) + resp_len = sizeof(report_resp->data) + snp_dev->ctx->authsize; + report_resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); + if (!report_resp) return -ENOMEM; - rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg, - SNP_MSG_REPORT_REQ, req, sizeof(*req), resp->data, - resp_len); + req.msg_version = arg->msg_version; + req.msg_type = SNP_MSG_REPORT_REQ; + req.vmpck_id = vmpck_id; + req.req_buf = report_req; + req.req_sz = sizeof(*report_req); + req.resp_buf = report_resp->data; + req.resp_sz = resp_len; + req.exit_code = SVM_VMGEXIT_GUEST_REQUEST; + + rc = snp_send_guest_request(snp_dev, &req, arg); if (rc) goto e_free; - if (copy_to_user((void __user *)arg->resp_data, resp, sizeof(*resp))) + if (copy_to_user((void __user *)arg->resp_data, report_resp, sizeof(*report_resp))) rc = -EFAULT; e_free: - kfree(resp); + kfree(report_resp); return rc; } static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg) { - struct snp_derived_key_req *req = &snp_dev->req.derived_key; - struct snp_derived_key_resp resp = {0}; + struct snp_derived_key_req *derived_key_req = &snp_dev->req.derived_key; + struct snp_derived_key_resp derived_key_resp = {0}; + struct snp_guest_req req = {0}; int rc, resp_len; /* Response data is 64 bytes and max authsize for GCM is 16 bytes. */ u8 buf[64 + 16]; @@ -444,25 +447,35 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(resp.data) + snp_dev->ctx->authsize; + resp_len = sizeof(derived_key_resp.data) + snp_dev->ctx->authsize; if (sizeof(buf) < resp_len) return -ENOMEM; - if (copy_from_user(req, (void __user *)arg->req_data, sizeof(*req))) + if (copy_from_user(derived_key_req, (void __user *)arg->req_data, + sizeof(*derived_key_req))) return -EFAULT; - rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg, - SNP_MSG_KEY_REQ, req, sizeof(*req), buf, resp_len); + req.msg_version = arg->msg_version; + req.msg_type = SNP_MSG_KEY_REQ; + req.vmpck_id = vmpck_id; + req.req_buf = derived_key_req; + req.req_sz = sizeof(*derived_key_req); + req.resp_buf = buf; + req.resp_sz = resp_len; + req.exit_code = SVM_VMGEXIT_GUEST_REQUEST; + + rc = snp_send_guest_request(snp_dev, &req, arg); if (rc) return rc; - memcpy(resp.data, buf, sizeof(resp.data)); - if (copy_to_user((void __user *)arg->resp_data, &resp, sizeof(resp))) + memcpy(derived_key_resp.data, buf, sizeof(derived_key_resp.data)); + if (copy_to_user((void __user *)arg->resp_data, &derived_key_resp, + sizeof(derived_key_resp))) rc = -EFAULT; /* The response buffer contains the sensitive data, explicitly clear it. */ memzero_explicit(buf, sizeof(buf)); - memzero_explicit(&resp, sizeof(resp)); + memzero_explicit(&derived_key_resp, sizeof(derived_key_resp)); return rc; } @@ -470,32 +483,33 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques struct snp_req_resp *io) { - struct snp_ext_report_req *req = &snp_dev->req.ext_report; - struct snp_report_resp *resp; - int ret, npages = 0, resp_len; + struct snp_ext_report_req *report_req = &snp_dev->req.ext_report; + struct snp_guest_req req = {0}; + struct snp_report_resp *report_resp; sockptr_t certs_address; + int ret, resp_len; lockdep_assert_held(&snp_cmd_mutex); if (sockptr_is_null(io->req_data) || sockptr_is_null(io->resp_data)) return -EINVAL; - if (copy_from_sockptr(req, io->req_data, sizeof(*req))) + if (copy_from_sockptr(report_req, io->req_data, sizeof(*report_req))) return -EFAULT; /* caller does not want certificate data */ - if (!req->certs_len || !req->certs_address) + if (!report_req->certs_len || !report_req->certs_address) goto cmd; - if (req->certs_len > SEV_FW_BLOB_MAX_SIZE || - !IS_ALIGNED(req->certs_len, PAGE_SIZE)) + if (report_req->certs_len > SEV_FW_BLOB_MAX_SIZE || + !IS_ALIGNED(report_req->certs_len, PAGE_SIZE)) return -EINVAL; if (sockptr_is_kernel(io->resp_data)) { - certs_address = KERNEL_SOCKPTR((void *)req->certs_address); + certs_address = KERNEL_SOCKPTR((void *)report_req->certs_address); } else { - certs_address = USER_SOCKPTR((void __user *)req->certs_address); - if (!access_ok(certs_address.user, req->certs_len)) + certs_address = USER_SOCKPTR((void __user *)report_req->certs_address); + if (!access_ok(certs_address.user, report_req->certs_len)) return -EFAULT; } @@ -505,45 +519,53 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques * the host. If host does not supply any certs in it, then copy * zeros to indicate that certificate data was not provided. */ - memset(snp_dev->certs_data, 0, req->certs_len); - npages = req->certs_len >> PAGE_SHIFT; + memset(snp_dev->certs_data, 0, report_req->certs_len); + req.data_npages = report_req->certs_len >> PAGE_SHIFT; cmd: /* * The intermediate response buffer is used while decrypting the * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(resp->data) + snp_dev->ctx->authsize; - resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); - if (!resp) + resp_len = sizeof(report_resp->data) + snp_dev->ctx->authsize; + report_resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); + if (!report_resp) return -ENOMEM; - snp_dev->input.data_npages = npages; - ret = handle_guest_request(snp_dev, SVM_VMGEXIT_EXT_GUEST_REQUEST, arg, - SNP_MSG_REPORT_REQ, &req->data, - sizeof(req->data), resp->data, resp_len); + req.msg_version = arg->msg_version; + req.msg_type = SNP_MSG_REPORT_REQ; + req.vmpck_id = vmpck_id; + req.req_buf = &report_req->data; + req.req_sz = sizeof(report_req->data); + req.resp_buf = report_resp->data; + req.resp_sz = resp_len; + req.exit_code = SVM_VMGEXIT_EXT_GUEST_REQUEST; + req.data = snp_dev->certs_data; + + ret = snp_send_guest_request(snp_dev, &req, arg); /* If certs length is invalid then copy the returned length */ if (arg->vmm_error == SNP_GUEST_VMM_ERR_INVALID_LEN) { - req->certs_len = snp_dev->input.data_npages << PAGE_SHIFT; + report_req->certs_len = req.data_npages << PAGE_SHIFT; - if (copy_to_sockptr(io->req_data, req, sizeof(*req))) + if (copy_to_sockptr(io->req_data, report_req, sizeof(*report_req))) ret = -EFAULT; } if (ret) goto e_free; - if (npages && copy_to_sockptr(certs_address, snp_dev->certs_data, req->certs_len)) { + if (req.data_npages && report_req->certs_len && + copy_to_sockptr(certs_address, snp_dev->certs_data, report_req->certs_len)) { ret = -EFAULT; goto e_free; } - if (copy_to_sockptr(io->resp_data, resp, sizeof(*resp))) + if (copy_to_sockptr(io->resp_data, report_resp, sizeof(*report_resp))) ret = -EFAULT; e_free: - kfree(resp); + kfree(report_resp); return ret; } @@ -873,10 +895,9 @@ static int __init sev_guest_probe(struct platform_device *pdev) misc->name = DEVICE_NAME; misc->fops = &snp_guest_fops; - /* initial the input address for guest request */ + /* Initialize the input addresses for guest request */ snp_dev->input.req_gpa = __pa(snp_dev->request); snp_dev->input.resp_gpa = __pa(snp_dev->response); - snp_dev->input.data_gpa = __pa(snp_dev->certs_data); ret = tsm_register(&sev_tsm_ops, snp_dev, &tsm_report_extra_type); if (ret) From patchwork Fri May 31 04:30:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681113 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2048.outbound.protection.outlook.com [40.107.244.48]) (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 DF3137C6DF; Fri, 31 May 2024 04:32:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129947; cv=fail; b=U87kEg+JP/+hNsROvyqRYUgykMMuaQMfPAm+s0Qtb2hUZSQ5m4sTRlqh/mF5g6H9C2SvuIgRL78jlp4JvDpmdvK2m5ls34FopWeRC/JylEe4Yp/jYy7ifm+4WWvOrO4c9R72y2YFR19Nnbs7oUMQoMP4KvvCkKF5L3UEfBATbBU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129947; c=relaxed/simple; bh=1zhiSjGSs7jsDZI4Psh4cnFP+IZk2ta1QszzXwa977U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V47NSRCCejzV5fkJ9hYtfu1NfnDTCXT9LWk5GoHsy8VKMFuHuEPAWrL3quUqKmlNhkv8aP3HrHmegmV58VBEl6+wvrJGIvwoksrWTOl5MkK/wegW0qE5l0u8STTuwndT811b8V7McQQ8Tk57UGypHCGkAFc9qfhdxaYreEDvjVU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=fw62SfCM; arc=fail smtp.client-ip=40.107.244.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="fw62SfCM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NvIOBrYwryOUkwhfDs1EDdYES4tS6gthIMnKCXxVb3xENcnbatFZft2DVlbfBzrbqT8fYABO5BExVV+zW0TZfiIdel73B6fBl2ZA3uXdqkvKaPpgnRAi9MPL7o/SnYrXK8k6VLS6NuNZofK+tQdljs/Tc9ZGx3NV+3WfhWl+Q6ZR+57pi2nJ4mIfqrn9n8TMSBeNMWoYc4ekAVBnM/BAquzuOQpPlJ14NQbPn6suArOGd6LoB1mrzqMNp9Q51ZXj5nwkP+g6YDY/SVRxXfRUAmEsXOBdh9GNNSc0kZTNy2/hd2g36p4pW98nNq1Hf70HwqUKRjzq06uODMdWiugSEA== 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=8HnSZtY2O9qHXtbbZoTLYC+uZpaV6FkJ1XiyN1FPbFc=; b=UmVy6BQDpEYjKInElzoU8dWe70BxS6qYOIs9oy5oOp3hqwm+H7/6fkCOHyu26HzBtHVGIRkhB/SYvMbcWWq7bgly6MA3FwLrFXqdx+qFzfBoRWKnW4CDoLYB/eq5iBZ1snIkhKVrUO4sfEOmJDM+MEy0vBC97Qa9yK5IbPuKMnqA44dGEZVRhniQIEPhq4bvB5R95BPNbzN6XtXqQLhmF75Pv4hkJm9XTg7n6vCtkWhU+bB6ypOd8ahwdF40U8pIwLpDD5K8/Z5DLoV8XlXvMlrk8EWN8W1uEqkHkPx6mAm3Yu2q02NQj+9hbbzOI1xGQgfNNkiIpQjmwe7IHg8caA== 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=8HnSZtY2O9qHXtbbZoTLYC+uZpaV6FkJ1XiyN1FPbFc=; b=fw62SfCMLgWQrgFefc7rozrqk/YNW74fx1cgHURr6dxHXCIUrxqSWeAyd1P4V/rLZ62wPKzU/1aEV/4TBBSBbvc5aUqCjKDE8hAWJaE6GbjmIiDsk6vJzwA8wtcgqJC36YDkaohYCYzg5c6lm5Kl4LOLDmkLCyB5dS7ONRcT4uw= Received: from BYAPR05CA0026.namprd05.prod.outlook.com (2603:10b6:a03:c0::39) by CYYPR12MB8749.namprd12.prod.outlook.com (2603:10b6:930:c6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Fri, 31 May 2024 04:32:22 +0000 Received: from SJ1PEPF00002321.namprd03.prod.outlook.com (2603:10b6:a03:c0:cafe::f9) by BYAPR05CA0026.outlook.office365.com (2603:10b6:a03:c0::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.9 via Frontend Transport; Fri, 31 May 2024 04:32:22 +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 SJ1PEPF00002321.mail.protection.outlook.com (10.167.242.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:32:22 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:32:16 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 05/24] virt: sev-guest: Fix user-visible strings Date: Fri, 31 May 2024 10:00:19 +0530 Message-ID: <20240531043038.3370793-6-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: SJ1PEPF00002321:EE_|CYYPR12MB8749:EE_ X-MS-Office365-Filtering-Correlation-Id: 18ed6612-80b6-456b-0b6a-08dc812aaa51 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|36860700004|376005|7416005|1800799015; X-Microsoft-Antispam-Message-Info: 3of65TlsTTS7fHt92R0FJ8OuZlFJ8o1zhFPPmHvGoAi7VfPwGkEeysFzQlr1vNsoY0u5yezX18hU9+8W/3G7RW2GAXch+WEkGx7/PwzlK5xR0iaD5EyRKb1MJVb9X9Dw3n81i8L2uHfRprBPB9DrRvAiWysewmr65DEGguYtNMVqfzfetskJ14Ar4urrJAHRT6c8PDlDhpnOSp8unmuGW0XfKDRVUfQNI+GDwe0zW78YGYuJy576wVJAT3JOJe3e+8CH8SGNuuus2d/zFhBUE7m0IIF5XezRh/X7i8SeNn3/DHlzLJoS+tAVL/f4F7xmN7gkn5tp+6lpDYpZ3yZHwdwRLfc/XRzuXQ0wZuZljzgiVvkdcJFGEMHUY4yokH/whPqkcuxOX8Lg3rScbXzQroHWtlcezXqpERXRDQrhHMfYtZQUO1ORjGeUL6qCDyg3hbZDwXsrYyIbgVvWqHyLWrBxcWU64wIOBS+eGCIKSMgvtAYXpt5yYjJqXnkxdbvz+E13uGCiX3xBSFhjShgZNO1fS+1VczCg0UCXPaDMKAncx9xAGUlb1jxCEDbqvN/E+/jMqyRc3hk7JQiOCTWskujyFkm2eYkYpeHJB58A/lr8xZtPl59D35hj8qttF8SQgsOfEj9pojKFpxQzCtkJm3FEE5t90hBBFd8LLEi94fAWJ2tUQefbSXQOqfJKC1yRtqHmgq3zC8JbZw2FlJ9dMD0LKr4EncRgGTtu5UMktf/kmt/ygYDfuClVk42CAQoaEKWjN8v0ZyYAuA3R0aFs6TVgmf6esCIByTQpohu1PUrxiXR3tsjTopmq1uXKY58lLUvg3F5FpaXbfUrZbwDbUE56J763/q9v+pEwil5pYbKPG9sjuQllN+VTEVtcn/u+k/475+oex2vV2jpomo1NeBRg+MuM6d6Iy5vCOUybRYVP4b2InBlSpu2rFHXj407ROyf8CeRz324klGuVk9A5s57Wv8BCuJOky6KjwHPkrlLiFwra9jG+/A30Sn8uayu8xfcoTsk+vFdp4FvRetcH3VrBgZZImQVl0D3sdykdfZPTWa3/NCoZE0DOm7Ie0JEJ6i5hBMYqwnUx5p9y3LAJklMZ5g4SXlYfjLXWzJSa2mIXkmtXPtiTt7sPD674Z0ZwMJeaGi4FlbucdydhqlFAIUIjDEg2RDUHeTkm7v0ovZo2PxcYx7ECQ5DMKo1xCtUoygTFFvX4kjSS3g9ARYf3DNyKUopviua/2TTX1YHfywdoaDGoMtWPYp8QuWh/0DCAeQRchpuasfnxV+jDgbP//Zyeu+dDMnuHHpx24P6HYvDsToc1K88+S0v31ebpGxcOdUf7RZ2fx0r8IigV7jCLzf5Rmy2W9jWS+6jCgCkKXEQDWzr1TawxC90uj4d6Dc0/ 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)(82310400017)(36860700004)(376005)(7416005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:32:22.4565 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 18ed6612-80b6-456b-0b6a-08dc812aaa51 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: SJ1PEPF00002321.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8749 User-visible abbreviations should be in capitals, ensure messages are readable and clear. No functional change. Signed-off-by: Nikunj A Dadhania --- drivers/virt/coco/sev-guest/sev-guest.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index b6be676f82be..5c0cbdad9fa2 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -95,7 +95,7 @@ static bool is_vmpck_empty(struct snp_guest_dev *snp_dev) */ static void snp_disable_vmpck(struct snp_guest_dev *snp_dev) { - dev_alert(snp_dev->dev, "Disabling vmpck_id %d to prevent IV reuse.\n", + dev_alert(snp_dev->dev, "Disabling VMPCK%d to prevent IV reuse.\n", vmpck_id); memzero_explicit(snp_dev->vmpck, VMPCK_KEY_LEN); snp_dev->vmpck = NULL; @@ -849,13 +849,13 @@ static int __init sev_guest_probe(struct platform_device *pdev) ret = -EINVAL; snp_dev->vmpck = get_vmpck(vmpck_id, secrets, &snp_dev->os_area_msg_seqno); if (!snp_dev->vmpck) { - dev_err(dev, "invalid vmpck id %d\n", vmpck_id); + dev_err(dev, "Invalid VMPCK%d communication key\n", vmpck_id); goto e_unmap; } /* Verify that VMPCK is not zero. */ if (is_vmpck_empty(snp_dev)) { - dev_err(dev, "vmpck id %d is null\n", vmpck_id); + dev_err(dev, "Empty VMPCK%d communication key\n", vmpck_id); goto e_unmap; } @@ -911,7 +911,7 @@ static int __init sev_guest_probe(struct platform_device *pdev) if (ret) goto e_free_ctx; - dev_info(dev, "Initialized SEV guest driver (using vmpck_id %d)\n", vmpck_id); + dev_info(dev, "Initialized SEV guest driver (using VMPCK%d communication key)\n", vmpck_id); return 0; e_free_ctx: From patchwork Fri May 31 04:30:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681116 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2050.outbound.protection.outlook.com [40.107.93.50]) (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 E9FE37D096; Fri, 31 May 2024 04:33:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129990; cv=fail; b=nA0hL6ozOOpVjiwqqGUT0/jYewU269PWbyKi3NjwWzECZA40GAXgICbuoBKtkWsLQ2uCsMfBhVTjJwx5TTUDXMejcwq1tIj6BGzPThzyTBh27MBoJ3eb9mkI98uTIe5vP41Q1fAX5mJ5CeIMz0Cz5ss19CE+YosYXafhza4PnUI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129990; c=relaxed/simple; bh=JhzeNpCXiZt+ZCmy09NVMPrWAFQsr8TlaBbEBA4NAQ0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fo8FmNJpHDmWFGRg1cqwuPraTzU0SCL8BTzw2PspDulVvkr35YH4S+LE8uywnyTwaiJI3WcQeMXVMwyUTBhNexJdLfbOwYFCa1HUjcUOolH5hKGXfNdZxAB0O4tyW30rdjg3887R1x6LPXuYzB+bygQ7lF/pZdr9WZaZlXcyeBE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=OpkoHNYU; arc=fail smtp.client-ip=40.107.93.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="OpkoHNYU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QnB5C3L8VbRq5gP9m8Q4ANldP9HILMfCpYhMes7UfCAAObdexnFnkATRC80dcRWvRLUxCSeo1c4AjABXveOqgSnITEhpFya6+mPzv/iAclhAjqtoxj3ScWRwg2PQoNQCKUnZpUkWL+FrhMyCEWI0+quMAIibrQRMhM6t1y/3AbEeYbN8ZIDTC0GOObya0w67QWmqyI3iQmnTFdgWoPwX6OmHDqvbKID0ea11im44YdrpT5ActNLN+cEliPPdd0a2Rmql62N8KMrXwy5jYxbMcBNW72pNy8ZmAbF+XL1GJuauuNxZnubHspIyZEr2CEvYSp5lSN6y4AXl7/DOGk40gQ== 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=xRBQlAHS9rNdGZeioNgGfyyZkvzGqblc/uPtEahNQDw=; b=g55vsHw6Sd+zaYfu7Tw7R7ITx6arfCvS70p1w5sPDi/4O9FJWEZjWhhLNhPwqtO5HKuOlFkGJEtEynk1nnOHeBsGG588RKBZhIHeAzR3QC6pdaSKmEfoEtoplURUUqQLUI1dwQwqMAYzEB+JD6Mt47zKrDw+qndhj8x1Ur0oMznIVwXmDGURlOvSIYU2kT9Iq5Q4GwlGSMFxjMmH0JBhqJcJjh4rbNPmlAVZk4b4zr6La6+j8m2ALOmfAAC2+Yff0/kMtcTqBS/OA401v9gM3yTx+z4gjBGMlU6qK1LJ3hY6y1Ytj4+YLLlZZI1Tn2IUPhkiFBZYWlUub1B5dEGJcQ== 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=xRBQlAHS9rNdGZeioNgGfyyZkvzGqblc/uPtEahNQDw=; b=OpkoHNYUhLv9c0ebM3MnNRJfjyjvf36vYOb+Xkm0aeXuiPBBJ0eso89iZwtqfTQe7IPgN0G8xHMsaUsAKuLh2aMuR0QOBSVf3jUR2PM3EivSHpm2arJL15fgMYytbCzPmcNGYGZVoRWnN7iuRnUPc+QrgEpYocNss5HoLV0tWqQ= Received: from DM6PR08CA0063.namprd08.prod.outlook.com (2603:10b6:5:1e0::37) by CYYPR12MB8991.namprd12.prod.outlook.com (2603:10b6:930:b9::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Fri, 31 May 2024 04:33:06 +0000 Received: from DS3PEPF000099D9.namprd04.prod.outlook.com (2603:10b6:5:1e0:cafe::4a) by DM6PR08CA0063.outlook.office365.com (2603:10b6:5:1e0::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24 via Frontend Transport; Fri, 31 May 2024 04:33:00 +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 DS3PEPF000099D9.mail.protection.outlook.com (10.167.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:33:00 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:32:19 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 06/24] virt: sev-guest: Simplify VMPCK and sequence number assignments Date: Fri, 31 May 2024 10:00:20 +0530 Message-ID: <20240531043038.3370793-7-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D9:EE_|CYYPR12MB8991:EE_ X-MS-Office365-Filtering-Correlation-Id: c110c2ce-c623-404c-0974-08dc812ac0df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|376005|1800799015|82310400017|7416005; X-Microsoft-Antispam-Message-Info: DIKGTTkux+JqAHNBuqoXmsFHS8aiE8YnjngImfL0Pq9yj/0BPKFFwtMWPgtdqqyoWqnP21Cja2nRXXfO4GsTwbhYjfhkSZyoGKJf1mblECYlzfiOC813apxqcpq7oiiL3L08AnL6u4tQlYwmgwqMRAMxwr6qpBZ4/yb7hvpq6Rl8qX333dBuhqjoaPuhlQ74wMoinVAKHsiLDN0MK9mhZPWvTYBzv4VDGf0wmo20KvEEyvpdjvYwGW8NBBKsRMdKQJtDtHQWSGA6ib3mdqjYc2xFyGAwuJuxosclETH4UXvwTXWvCybKo7oRkbmqh2BnNk8PSLEUw/HbfHK/ydIMBWbbabu/d/mugYsXSzf0BvPO/iIuRJ5YmmGsvOgd1BPWR2mmG7vfft0tVhAUeQPvz/CdFIH/MNaIGl5mdz/0pp+P8k9791pemD4gkJQZRBBzH/GDBltAUPgjYH5iEbAMLIPfZHiBhzE7ZzkZMhE3po6yabJZQ8j6ZmBnCndZ0UTC7fY0UP9uzBJRA+g/hqe4HlwTPyc6GZuKx7+gn7FB9ZJEcESxrJ+ER8+9h6OTsrRQQgVragtFIaugdodMrIFoQsYqXXQKAnU4htk+AHN774sq1dpGEL7ZK+kSqH1Ll7IcVv7RAYL2I2nvPhmyR5zMDcY6H/nElhm9qM2rEp9RnPj95br8IWP78if/5BlmtdcfPF0SXLInj60cn2dbKwc87lb5ZZNtUVvb38Jmh9tQInZFWqj1QReCgFzc/UUz3RWxgNMqGS6fLzNF0H1MJzC680Ol7OJFfJF+L3a3eMryo/RIZWPJc60GrVhX1pt0VOc0e9y5IPWrtzYPMTdwvrRCFnwt4pp6K4HZbIMig12jQGTIspiWCq/bh8rmAtppLPdMS92owFeFphHAbYWljFd1fRTnbrXFr6V/tHWyudRLOnjNbXT5QQOtKKnGq6K72x5O7Yjk3n0bThj7F+lRYzMWgsoT42ELhxxQDnE9PmbdpnXXWW09dtbCPMo6iJLp96Lrz0DCsALhezAvzSDKxW5nppLPFf9HdQS9hyRaqrBtGOcdkSwahzeuIWQtVAhy1DU2HtWhRX1jd/PNlFoM2glMRP73lG6fZ3WIFmW13q9T4uX+p6rvgeFMV5UC2QPRgjfyvVe1Y+XE5FwQ1QVHUXBU4E0CVDSIJz6MZCMoNLsInMmRb+G6BuPKQLc/e9T/4Gia9t1ACz+65pHTH/+U8RURy0W3bodU4GVPk+q3PjQZ6xyvoHeZc+GOBtlAviAXGPgjAfIk9KZqv8COlDdlCLb8tGDSf46tMvomq6XCGDIoij9s1pdRajirHf6NM1rOyIqzAkqz969sMwJ4rfm6XrR6LfJxH7YCffzcXkIozkavhSlPnquR+aByoBD3RYOjhhDr 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)(376005)(1800799015)(82310400017)(7416005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:33:00.3282 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c110c2ce-c623-404c-0974-08dc812ac0df 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: DS3PEPF000099D9.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8991 Preparatory patch to remove direct usage of VMPCK and message sequence number in the SEV guest driver. Use arrays for the VM platform communication key and message sequence number to simplify the function and usage. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky --- arch/x86/include/asm/sev.h | 12 ++++------- drivers/virt/coco/sev-guest/sev-guest.c | 27 ++++--------------------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index dbf17e66d52a..d06b08f7043c 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -118,6 +118,8 @@ struct sev_guest_platform_data { u64 secrets_gpa; }; +#define VMPCK_MAX_NUM 4 + /* * The secrets page contains 96-bytes of reserved field that can be used by * the guest OS. The guest OS uses the area to save the message sequence @@ -126,10 +128,7 @@ struct sev_guest_platform_data { * See the GHCB spec section Secret page layout for the format for this area. */ struct secrets_os_area { - u32 msg_seqno_0; - u32 msg_seqno_1; - u32 msg_seqno_2; - u32 msg_seqno_3; + u32 msg_seqno[VMPCK_MAX_NUM]; u64 ap_jump_table_pa; u8 rsvd[40]; u8 guest_usage[32]; @@ -145,10 +144,7 @@ struct snp_secrets_page { u32 fms; u32 rsvd2; u8 gosvw[16]; - u8 vmpck0[VMPCK_KEY_LEN]; - u8 vmpck1[VMPCK_KEY_LEN]; - u8 vmpck2[VMPCK_KEY_LEN]; - u8 vmpck3[VMPCK_KEY_LEN]; + u8 vmpck[VMPCK_MAX_NUM][VMPCK_KEY_LEN]; struct secrets_os_area os_area; u8 rsvd3[3840]; } __packed; diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 5c0cbdad9fa2..a3c0b22d2e14 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -668,30 +668,11 @@ static const struct file_operations snp_guest_fops = { static u8 *get_vmpck(int id, struct snp_secrets_page *secrets, u32 **seqno) { - u8 *key = NULL; - - switch (id) { - case 0: - *seqno = &secrets->os_area.msg_seqno_0; - key = secrets->vmpck0; - break; - case 1: - *seqno = &secrets->os_area.msg_seqno_1; - key = secrets->vmpck1; - break; - case 2: - *seqno = &secrets->os_area.msg_seqno_2; - key = secrets->vmpck2; - break; - case 3: - *seqno = &secrets->os_area.msg_seqno_3; - key = secrets->vmpck3; - break; - default: - break; - } + if ((id + 1) > VMPCK_MAX_NUM) + return NULL; - return key; + *seqno = &secrets->os_area.msg_seqno[id]; + return secrets->vmpck[id]; } struct snp_msg_report_resp_hdr { From patchwork Fri May 31 04:30:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681114 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2067.outbound.protection.outlook.com [40.107.92.67]) (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 C08D6208A9; Fri, 31 May 2024 04:33:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129986; cv=fail; b=LkogPRt7s3HBvau/N9EuYsXHqbXlMJM9Fvptt8GwVXWJuJQ7lMOIPsDAbhWjhPm/fsAYYJtuXyRfubuQ9j4PR7SZqDion9OXjTcG3yvDbCT/TvJL1FJBd7T430COzJySrcD1+8AnTy9jpq+/7MRYxGL/NwTE4QRTWEvU2f6uF/w= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129986; c=relaxed/simple; bh=N0jmctl1Y5kfWALQdfPDmVNGaPqj8pTAjcDr4R2kApc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pPDksOtP7phCDzT2yqjvtmaDXB9iDruT2jruCwF6RkOBXxwNjbZG4KOTWASDPuM4ILJ0RcEYskpMNwvZSr8jOCwSahEhtAx0/kXC+1GD4frIRtTKCgUnjPz0pKno66lKU9zXSs53wPwQ7DseWJ9NcG8GN3muuUCphsGQBNNTfpc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=kO0uEPg4; arc=fail smtp.client-ip=40.107.92.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="kO0uEPg4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q6zlPd6d7n3GrSVaObjTs/ywu36S6Wwq17p8i/4G0VFoChd6kwFh88deETCIKbkyxxsiqopgqG3tMgCHfUtpa9p/7qYH0DA74ERLwzRxlC9xPUFVHqcRFpKcCfTNIWJlHJ1OXR1UGE8LznGR/S/z7LV8YExuQyz2O0QwGxCRvwTM42riHWHcQjahkg6Sn+bxCA/o3EKbJJ7fHhUxuVgI/i2zWseZXy5mHArIEycrkQLAYz3S9jqsZEHpHC4sx1K95J1xZZVaDUTboamTO1N4rywpAl4pONbMygbr0tWuwjBtoLZFXXY7CIKvgCtCy1bwmnXeKpk/zcepBBaKCrnDfw== 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=f5ZXXzrDtAq57WfO5Hy/z2mbdi69I8PVwNWrEhm1oOA=; b=XQ82A53NW9++5KOpsqK2yV5zjYBEYRngJWZSP5B830bFwRAzCcap/nRL34TtCA4WHWYBvYyBTpaVZ9LkLgUHYfOSdD2DoLgkT+B9aFqv2pfowSSEQgH6D54DgM8tluWBFWcg2J/YyQJYgk45p/zk2vCIjspQbj1rTCcmeKqwfwQmhSiq8uiydq0bwssF/4lhtDWKL8aokPlGv6ldvh++OYtwHaoS26LSs3tWKG8CpsXuuZjACpnEuJ0msPYqqwYws1Wvn/1nBoDg43JT/hDsUhy4XBqGwMTz2fyLmQ8iE8/lcIXg5D+ZRmW8VQ5Knrk6470zF7TygetIpngEsHwBLA== 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=f5ZXXzrDtAq57WfO5Hy/z2mbdi69I8PVwNWrEhm1oOA=; b=kO0uEPg42EdpQEtkiLDQGksW3Pk15UzdNZcv5IV9VLUED2Z/cCgPN9pZQ0U/hoonQHzcGBLzi+MZnVuuD9DXWHVeR4+raJ/lXN2Fh0Yzaaahj696YohqiO0oM5xoku981JrLK5h0JY6jeRDh3pgVrUZm7y6VXqo75KOHFA7vbIU= Received: from DM6PR08CA0039.namprd08.prod.outlook.com (2603:10b6:5:1e0::13) by DS7PR12MB8084.namprd12.prod.outlook.com (2603:10b6:8:ef::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24; Fri, 31 May 2024 04:33:01 +0000 Received: from DS3PEPF000099D9.namprd04.prod.outlook.com (2603:10b6:5:1e0:cafe::28) by DM6PR08CA0039.outlook.office365.com (2603:10b6:5:1e0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21 via Frontend Transport; Fri, 31 May 2024 04:33:01 +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 DS3PEPF000099D9.mail.protection.outlook.com (10.167.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:33:01 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:32:55 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 07/24] virt: sev-guest: Store VMPCK index to SNP guest device structure Date: Fri, 31 May 2024 10:00:21 +0530 Message-ID: <20240531043038.3370793-8-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D9:EE_|DS7PR12MB8084:EE_ X-MS-Office365-Filtering-Correlation-Id: b3ba2f27-628a-4113-75c2-08dc812ac1ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|82310400017|36860700004|7416005|376005; X-Microsoft-Antispam-Message-Info: msFVR1PLRovHjW48jNxxzv8NmpcPAbS39/tVAImxMrnkMO5Dh/BngvEJ2OLgQkstTt2zAlTpTaeh9pr3RxL99aPGqh0V86cQ+nSci7iOabvwt/lBml7kyAFqBpyTAJT2OkVJ8AGDqBCb79agLqrVK36lHlM5IhjlexVmB1MZnOWsB1JoTtf/IXNgyLatbHLIXowjdw7FwdIOhnX3n+8QXNmlDplkGFrMdfZ9cIvNCTduLPffBte0a3yVsDe80tTZ+Qic/KzGJEn4mU4MeOZ3wZgSpo9c9M7JfcMMnTwUb0CR3p3dvkaN0oE4fOwQpnalBRm+suk1cj+Sw18xGx8mLgMfQKwNtY1CdZ5izEZDoPNEK+5wNqKhBGg233Bw+dxvqykQeLdeL7FCYhFRJdsFH37KuN29SgdCuzINyH7ZjBPrfXis4D+XRGP/Em+3Awfsubederu6yJRMc7ikN1lRCQde7fief271u1cotEf6M89bz1+uyJSieQlh5dk/mpGTxt/KNrOyBIgC0+FDTVXR6wf055YxULzOvBuvGyvtHMK0Lo8xuE0lCWtl1aVNNy7FoQDZR2xaM+JEcumS7p4EjKJCzjdNR6BUC2IRakNzxhAXdfxogr0zsQVNT3eFFHK5elNjR46tHUbm4CYME54gCF+DjHu6Uzm1dthMpTajllaC5cnLx8BBb3nqFmjHB7LuP/IB0F+OWCsbAploteeOUQUoUsvR373/+9841eyxVvelwWNZ84uR+BVZodaXRA74DD/bywRdqaZHGF+SHADIVMSLVmKf1+Kv5UgyrBXCeSk1DYdDQgsa/8Q3zGD291TN4L0Sd0Rj0dTN77GbX2eLHs3/TAsr5iUc5tlX81DenKf6jD/u8amzq419gcC2HKAcaAak2905hb64KE3MYLY1vcz1/OqKKAP6pKua7rt2H4Q1uZOO1n8+8YwMfXIMz+paLgZf9rY/QUiLthXND4wJssUuHc+kMIs86B9zhUJr33j+JTACLbfpq52sGJ0okdilsD59DIzCgXcG16mz706FgIw1nmLEnB5tuc971GjvQwnAhXwNBJniZHGrf1lyZDCZvwOu8cQld9InbSAQtJpnoElp0J0IGc7RPS8rpIOt796PxJhT8CGktqP/zZqA1pg8SkRMz9He+geP2A3X+XnmV0+4PLTqjbvvWMF661XyhmW/Je9U2qr34zQGYwyRxoIJOkrr3ckgu3fpbBYz3Z8CHOGsUr/swhwlnPMIffel2+L+VpYs5r3rTQ8OElnauZNYYj2qeG2IqFryCPTSG407YlqnUGcOjdkd1CTANQbR47l4+k6L0vKhBmIvtrJHwBHNmPKbTl3dG5Y1DxNr5vEOp8iCRkjHBWoa7QUUvkcJBOSoJPBJybpuDPVAyLpfubiA 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)(1800799015)(82310400017)(36860700004)(7416005)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:33:01.7032 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b3ba2f27-628a-4113-75c2-08dc812ac1ae 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: DS3PEPF000099D9.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8084 Currently, SEV guest driver retrieves the pointers to VMPCK and os_area_msg_seqno from the secrets page. In order to get rid of this dependency, use vmpck_id to index the appropriate key and the corresponding message sequence number. Signed-off-by: Nikunj A Dadhania --- drivers/virt/coco/sev-guest/sev-guest.c | 67 ++++++++++++------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index a3c0b22d2e14..0729d0b73495 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -55,8 +55,7 @@ struct snp_guest_dev { struct snp_derived_key_req derived_key; struct snp_ext_report_req ext_report; } req; - u32 *os_area_msg_seqno; - u8 *vmpck; + unsigned int vmpck_id; }; static u32 vmpck_id; @@ -66,14 +65,17 @@ MODULE_PARM_DESC(vmpck_id, "The VMPCK ID to use when communicating with the PSP. /* Mutex to serialize the shared buffer access and command handling. */ static DEFINE_MUTEX(snp_cmd_mutex); +static inline u8 *get_vmpck(struct snp_guest_dev *snp_dev) +{ + return snp_dev->secrets->vmpck[snp_dev->vmpck_id]; +} + static bool is_vmpck_empty(struct snp_guest_dev *snp_dev) { char zero_key[VMPCK_KEY_LEN] = {0}; + u8 *key = get_vmpck(snp_dev); - if (snp_dev->vmpck) - return !memcmp(snp_dev->vmpck, zero_key, VMPCK_KEY_LEN); - - return true; + return !memcmp(key, zero_key, VMPCK_KEY_LEN); } /* @@ -95,28 +97,23 @@ static bool is_vmpck_empty(struct snp_guest_dev *snp_dev) */ static void snp_disable_vmpck(struct snp_guest_dev *snp_dev) { - dev_alert(snp_dev->dev, "Disabling VMPCK%d to prevent IV reuse.\n", - vmpck_id); - memzero_explicit(snp_dev->vmpck, VMPCK_KEY_LEN); - snp_dev->vmpck = NULL; -} - -static inline u64 __snp_get_msg_seqno(struct snp_guest_dev *snp_dev) -{ - u64 count; - - lockdep_assert_held(&snp_cmd_mutex); + u8 *key = get_vmpck(snp_dev); - /* Read the current message sequence counter from secrets pages */ - count = *snp_dev->os_area_msg_seqno; + if (is_vmpck_empty(snp_dev)) + return; - return count + 1; + dev_alert(snp_dev->dev, "Disabling VMPCK%u to prevent IV reuse.\n", snp_dev->vmpck_id); + memzero_explicit(key, VMPCK_KEY_LEN); } /* Return a non-zero on success */ static u64 snp_get_msg_seqno(struct snp_guest_dev *snp_dev) { - u64 count = __snp_get_msg_seqno(snp_dev); + u64 count; + + lockdep_assert_held(&snp_cmd_mutex); + + count = snp_dev->secrets->os_area.msg_seqno[snp_dev->vmpck_id] + 1; /* * The message sequence counter for the SNP guest request is a 64-bit @@ -140,7 +137,7 @@ static void snp_inc_msg_seqno(struct snp_guest_dev *snp_dev) * The counter is also incremented by the PSP, so increment it by 2 * and save in secrets page. */ - *snp_dev->os_area_msg_seqno += 2; + snp_dev->secrets->os_area.msg_seqno[snp_dev->vmpck_id] += 2; } static inline struct snp_guest_dev *to_snp_dev(struct file *file) @@ -150,15 +147,17 @@ static inline struct snp_guest_dev *to_snp_dev(struct file *file) return container_of(dev, struct snp_guest_dev, misc); } -static struct aesgcm_ctx *snp_init_crypto(u8 *key, size_t keylen) +static struct aesgcm_ctx *snp_init_crypto(struct snp_guest_dev *snp_dev) { struct aesgcm_ctx *ctx; + u8 *key; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL_ACCOUNT); if (!ctx) return NULL; - if (aesgcm_expandkey(ctx, key, keylen, AUTHTAG_LEN)) { + key = get_vmpck(snp_dev); + if (aesgcm_expandkey(ctx, key, VMPCK_KEY_LEN, AUTHTAG_LEN)) { pr_err("Crypto context initialization failed\n"); kfree(ctx); return NULL; @@ -666,13 +665,14 @@ static const struct file_operations snp_guest_fops = { .unlocked_ioctl = snp_guest_ioctl, }; -static u8 *get_vmpck(int id, struct snp_secrets_page *secrets, u32 **seqno) +static bool assign_vmpck(struct snp_guest_dev *dev, unsigned int vmpck_id) { - if ((id + 1) > VMPCK_MAX_NUM) - return NULL; + if ((vmpck_id + 1) > VMPCK_MAX_NUM) + return false; + + dev->vmpck_id = vmpck_id; - *seqno = &secrets->os_area.msg_seqno[id]; - return secrets->vmpck[id]; + return true; } struct snp_msg_report_resp_hdr { @@ -828,21 +828,20 @@ static int __init sev_guest_probe(struct platform_device *pdev) goto e_unmap; ret = -EINVAL; - snp_dev->vmpck = get_vmpck(vmpck_id, secrets, &snp_dev->os_area_msg_seqno); - if (!snp_dev->vmpck) { + snp_dev->secrets = secrets; + if (!assign_vmpck(snp_dev, vmpck_id)) { dev_err(dev, "Invalid VMPCK%d communication key\n", vmpck_id); goto e_unmap; } /* Verify that VMPCK is not zero. */ if (is_vmpck_empty(snp_dev)) { - dev_err(dev, "Empty VMPCK%d communication key\n", vmpck_id); + dev_err(dev, "Empty VMPCK%d communication key\n", snp_dev->vmpck_id); goto e_unmap; } platform_set_drvdata(pdev, snp_dev); snp_dev->dev = dev; - snp_dev->secrets = secrets; /* Allocate secret request and response message for double buffering */ snp_dev->secret_request = kzalloc(SNP_GUEST_MSG_SIZE, GFP_KERNEL); @@ -867,7 +866,7 @@ static int __init sev_guest_probe(struct platform_device *pdev) goto e_free_response; ret = -EIO; - snp_dev->ctx = snp_init_crypto(snp_dev->vmpck, VMPCK_KEY_LEN); + snp_dev->ctx = snp_init_crypto(snp_dev); if (!snp_dev->ctx) goto e_free_cert_data; From patchwork Fri May 31 04:30:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681115 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2073.outbound.protection.outlook.com [40.107.237.73]) (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 B397720B33; Fri, 31 May 2024 04:33:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129987; cv=fail; b=Cnu2gbQKGaUM+XYhzTy9xmrqDI5ArBTVmD8qnUWVFULASwDt0XT+ivdMHJZ3cwi1doj+cEYy3HEetgLRWB+2ObNJSRGl6G5sHD3nsQeFYTEWmRExNbrPGe8ZFAXVjHAEc4ouTvG/AP3Nv4GjYa4gFAGHu5r7Ryn7ttDQUFZ1OuI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129987; c=relaxed/simple; bh=7ZDn46ulUtwzRbJyDl53G4ujNNySYMc14dJ+ykT7hFA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gNi3ugrzVQh2AKoytZ61zWRekzyyWFh2N3MbI+uZqaAe92Iv6vCIUNRncwnAEb+syVJGSYkTk8K4c942SvhDnyYDO6p+W24zbQjsmvY8YzEMc2THw49k3oRKqivGgGqE6TeMSZ0Qu0n6c50H7nLtkmhm/KDyjaCt029AZIm3LZM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=XD4IdLBY; arc=fail smtp.client-ip=40.107.237.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="XD4IdLBY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=juRJwq5GmKz0opQ/Lq1iVRZXPrI/KarOiQSDw5C43hjPC66hAlYlxkA/2BoKnYdTixsMreCdOV2FiZcGAghpoXw5Qi9VaunxyjWpflKqYdsjcsOKyzRfpSYxvbb0579+pIgIuuXSQJeDdVjvPflDOiZo2oVt7f0QQGEMgpN2efTsPCXNFQttbm/kD4aW7DI4Z7Iwyw6B8Fi8S0OIyCbCwFcE/uOa0UJkDscNANBVc3X6w2xTJS8mBwURSE7g8ez2AUDGjgmkCjiLAeTvQcJ6zZxKwpouhzP9iJ1qeh+SldhAIMjYiO/7f0mDi03mOhp2OmGYCpNiXl6ZRBQUX5BUJg== 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=i9GkarFZgKGH1f0qGp274+NA5OexXI/DQxI6BAriPHU=; b=JnMzO/Oaigzx3MDHhUTcx+x6S4H+9gv5BXfr/Xm+0w+OTWIKwN+gbedqvmxUllMg0dyCuZYxOQH5Ks3AWrAdQRNUGRfFvTk2CWgIRVKjZU+oFkxJbjy/EQxKDUeD8MmhJnJBf6i0BvBlM9v1DkBmn0ybaQGEATS5n1xY76a5290xZqIfyXIU2tcWYBKtzvnYqTNQzlObdUSrZsItFeComeZGW5PC+FUmtu6BSzXCdK6Aw5Tlxn3MrWLeiY2fqYE6QOe4qS2XEoD4YAebm0gCI9+lLp75+sHldEc5unrLncX9UrwvS8IKCMWoNdu7P19KSTs0Tb5HIVkRAC5vwad5Xw== 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=i9GkarFZgKGH1f0qGp274+NA5OexXI/DQxI6BAriPHU=; b=XD4IdLBYnBsArk3ZFclJ70oJAGs2SFzfQPN5f/DCn9MT4zbhat3l4gzlyChHANg2Keyj+weuGHziHcDTO/JIIFusUuzZFfe/zO63ThtFhiGfP8nz8hFrB9l4RmhKuL3r2gkp9GqddYwPVE/TMiSkDDnAwSz6Dc9CIG/3woMsliM= Received: from DM6PR08CA0057.namprd08.prod.outlook.com (2603:10b6:5:1e0::31) by DS0PR12MB7874.namprd12.prod.outlook.com (2603:10b6:8:141::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24; Fri, 31 May 2024 04:33:03 +0000 Received: from DS3PEPF000099D9.namprd04.prod.outlook.com (2603:10b6:5:1e0:cafe::ad) by DM6PR08CA0057.outlook.office365.com (2603:10b6:5:1e0::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.23 via Frontend Transport; Fri, 31 May 2024 04:33:03 +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 DS3PEPF000099D9.mail.protection.outlook.com (10.167.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:33:02 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:32:58 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 08/24] virt: sev-guest: Take mutex in snp_send_guest_request() Date: Fri, 31 May 2024 10:00:22 +0530 Message-ID: <20240531043038.3370793-9-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D9:EE_|DS0PR12MB7874:EE_ X-MS-Office365-Filtering-Correlation-Id: 16c183ef-92ab-47be-93dc-08dc812ac26f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|36860700004|376005|7416005|1800799015; X-Microsoft-Antispam-Message-Info: m3KPB/7VCTLMMzpAbEhgT8cbRlciN8AaXry6PFlWUziOdx2UA9+sEGHRp5/DBYWfx5r4g9lm58WoeKX26m67YaCAZ4xSDjJNv13MvCPadvpL6RwFVmAgI2/ZjvYr1ET5R+OaRtW4Tzkm7/hvTKecflX6QpeZED8/BG8v/TGsrv/0PqJKJUU1ST/g+LkK7a87urmW6xgMngI+7oPv5o03AsZk1n9L93fwfLDVGb7MlfuTH+C5NlNMej6fC20Oy6GYEKPq4Y3f36gj1XLzXlNCLqFwBtA7xUvndAyr/EWlnvdicqUR8IeIwk3XH67kbbhvV9Y7sloVhHJKU7GLd0q7qtvxj20NmCMDRWIPFdf0BOGXf4hS5Obaw0NVslGtUiK6i8qpmpGkECkbDug+xlEXHeHTD4nxTJLeSmwBEmp3GcPW/Va2nZdMS23pOP9UX4c+lRjum7rMM+ptwUWEjufB64esJJi39U9p043t7F4iBO8StqFV9zCY6aZElU7qUEalfHxkM6Uz3Wkk3+zZwVV81qr4VOlZDiEs8CdDG5jx9h73G0QitKV0rCDU9AGfYJLBrAv/lAWCLmZxBRW2bD4pkwEE2S8wi9A91ZC8Pn2MIsyGmPU4B1Y7XQZmra5T95iOiWIYNxOvV7shAGB2ZGdyXO09tgB+Ur2OCjTOxHBsnCzYTmI8/zsdInAPXaqBeoiNrq35VkaGjd3+LD2qoETerDBvDU9yBIEU/OpdazOlPhmsA9sFoHeEGMKSlIXY5zB+OnjiwC/40NPUnJTTz4CYCdzPN8htYezXUbPphMXTaxx07345/p/6IHo1q6Yxb0lz+RU2j2FlNqbfa2VtNy6cSHrygrEULjUI1cKOeuJsJY+Os4Q82fegCd6pJ2WlmdhJrZ/7apYJ4OCkIKRzJvTTbFXdnfD66Jx67LJRay2ZtBVy9iPJGs3+jZLTibbGRd2zZysg4enWJB2g7B/+4FO0h9zw6+h1vRlcIkuy/52Y9GST2qtdYjGshEKdVtISTZX90+o4PmLMoQOsJ5yFVHPHW3fKupICvzqxKm+Dh0Ln50XodEwAOZyT8pfMmG0KRGRCEW40pr9KMA7PxrC+LYhJCViHSWkzRnLeUNX6O8xa3ngir4MTJYtdPISusalZcbA29aDVb1tAWlbg7B82ZdVsWqKKwWSTjBP/RbQH3KptpgHGSvbf9sJmnHE/l0//lawvw2qPhgYTR4UXWm/z16FRR774i3ZRBx15dcU6tud3cWn0Hqci/QaRnxQCXgquiWCmAPU8Gc4pVEsU8CBBaWxzwI8Bsten5o1ye/yXprm1WHlpLJRsOhAEPBteSx9NYDuZuAnqWMqlftXFJfyIrKqHIdgFtxLQg/mpNDBeUaXST1A= 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)(82310400017)(36860700004)(376005)(7416005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:33:02.9688 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 16c183ef-92ab-47be-93dc-08dc812ac26f 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: DS3PEPF000099D9.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7874 SNP command mutex is used to serialize access to the shared buffer, command handling and message sequence number races. As part of the preparation for moving SEV guest driver common code and making mutex private, take the mutex in snp_send_guest_request() instead of snp_guest_ioctl(). This will result in locking behavior change as detailed below: Current locking behaviour: snp_guest_ioctl() mutex_lock(&snp_cmd_mutex) get_report()/get_derived_key()/get_ext_report() snp_send_guest_request() ... mutex_unlock(&snp_cmd_mutex) New locking behaviour: snp_guest_ioctl() get_report()/get_derived_key()/get_ext_report() snp_send_guest_request() guard(mutex)(&snp_cmd_mutex) ... Remove multiple lockdep check in the sev-guest driver as they are redundant now. Signed-off-by: Nikunj A Dadhania --- drivers/virt/coco/sev-guest/sev-guest.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 0729d0b73495..19ee85fcfd08 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -111,8 +111,6 @@ static u64 snp_get_msg_seqno(struct snp_guest_dev *snp_dev) { u64 count; - lockdep_assert_held(&snp_cmd_mutex); - count = snp_dev->secrets->os_area.msg_seqno[snp_dev->vmpck_id] + 1; /* @@ -334,6 +332,8 @@ static int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_gues u64 seqno; int rc; + guard(mutex)(&snp_cmd_mutex); + /* Get message sequence and verify that its a non-zero */ seqno = snp_get_msg_seqno(snp_dev); if (!seqno) @@ -388,8 +388,6 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io struct snp_report_resp *report_resp; int rc, resp_len; - lockdep_assert_held(&snp_cmd_mutex); - if (!arg->req_data || !arg->resp_data) return -EINVAL; @@ -436,8 +434,6 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque /* Response data is 64 bytes and max authsize for GCM is 16 bytes. */ u8 buf[64 + 16]; - lockdep_assert_held(&snp_cmd_mutex); - if (!arg->req_data || !arg->resp_data) return -EINVAL; @@ -488,8 +484,6 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques sockptr_t certs_address; int ret, resp_len; - lockdep_assert_held(&snp_cmd_mutex); - if (sockptr_is_null(io->req_data) || sockptr_is_null(io->resp_data)) return -EINVAL; @@ -585,12 +579,9 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long if (!input.msg_version) return -EINVAL; - mutex_lock(&snp_cmd_mutex); - /* Check if the VMPCK is not empty */ if (is_vmpck_empty(snp_dev)) { dev_err_ratelimited(snp_dev->dev, "VMPCK is disabled\n"); - mutex_unlock(&snp_cmd_mutex); return -ENOTTY; } @@ -615,8 +606,6 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long break; } - mutex_unlock(&snp_cmd_mutex); - if (input.exitinfo2 && copy_to_user(argp, &input, sizeof(input))) return -EFAULT; @@ -705,8 +694,6 @@ static int sev_report_new(struct tsm_report *report, void *data) if (!buf) return -ENOMEM; - guard(mutex)(&snp_cmd_mutex); - /* Check if the VMPCK is not empty */ if (is_vmpck_empty(snp_dev)) { dev_err_ratelimited(snp_dev->dev, "VMPCK is disabled\n"); From patchwork Fri May 31 04:30:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681117 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2044.outbound.protection.outlook.com [40.107.223.44]) (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 0025D7F7F6; Fri, 31 May 2024 04:33:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129996; cv=fail; b=H0UiqN1aYPMhKSGeiqbzlSIbklczow5cUUXXa/zMr3n9H324SwIXmLqmqCGzYGl7N9bAsdSadfzb2fY/xVhEd+nz6/rwIF3FlhBXuKgFZ++HKSw+TE9f1Q4xVn3pxTvCwhrTpu1O3artYc89IGZA/i3d5Rp1Ke89MSLOcnsbmks= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129996; c=relaxed/simple; bh=NhjoRkKbsqbDncxFAPYBLTSpqNw6ya6nNTQd2/IhpNo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hXcvO0GFHacTDkQ0ZwWiKw7scCBU5fOL7dOzZKP3jaOh5eaEfemPY0aaCXsoM0JM0/pcpKit9494c+iljMSn2UsRr/AQ5LOjSQq8zRu9eQZBLwgLZb/PITzbSd913wgINB3Li4pDrp1LMWbo6THmUTFcJ0K0IBhS364iRey9rZI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=DQSMmF6S; arc=fail smtp.client-ip=40.107.223.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="DQSMmF6S" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FCa15YAY4slRIyiFyazVvjDisLjX+0YsglfgQSGRYARJog0wofJeWYSI5EV0NU3CegL1ZMEBUZuFsExCYdsNzwtXK8Tw6hipV3jmPNznEUsTEoQNpV3iJPZJM7Hx28W4n4mtQjEMsFbl8fAXyLlB06BnHgyzhZO4GnRGX2GsMOKhIlVcBuRC2cM7q6II6Ztf/LYzV13Q/LJLnXuuyweslFKHsLGqCokl4l2P4TTb804YOzYPWerXoG8hjHMRLQnapBkhUsWoPjDk7YBBNQZmXmLSGgyh5MK+FxJmqBSNVgFu2QZgbNwWuWjsG9Q7Ryxv5Db/mGm3Cy6IGCHsH0zljA== 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=o/I6itsDr0fon0lLuHBDsAu/5e/dtkW4j3PsfC78/2A=; b=Pt6jViBivIknx0XuwLI8ZsACZ0Q33MmmdFTkguMFqhmt2Xwi9i4T4ynOW0MIQ5TBEFql/waCclfJjJOoyn/7f5VZcUETsa3rXdPzA7RZ76FgD+rGGAwbyQcyl8pE3MFjInkaAqPv5vBUEOG1Q9VZC7K5e8cZh3tVutuD6v+SXe/BFn65Ij6rwx+LFFN2WP8WPFBWq/AYS0cxvW20ncOQuFRCCt/dbs/NGXa7PFULJkiaiMgWDnV3zPgtgFULRxCyq0zuYEuTaFRJKo+PrpEzu/X6BOY+rWqj8ZkQUdfo/prwYyBlpuFT024r98lV4LocZ661ZeH2SpiaRtXsdZhwmg== 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=o/I6itsDr0fon0lLuHBDsAu/5e/dtkW4j3PsfC78/2A=; b=DQSMmF6S4XBqpt626NDtyX1bm3R55+uC6yJ5cCcU2wH9hYOAZULVe1PRtzDkf6nXH+axyI/SikxQjFcKnKAGMdQkVPLeeydBcDxRq0pq9/W5GwS3B88GRO197qhHqPUX+NY1hHJCSCCLGLHMnQ6ypG3ne1gLERGtRf5l6H1vCFk= Received: from DM6PR08CA0049.namprd08.prod.outlook.com (2603:10b6:5:1e0::23) by LV8PR12MB9154.namprd12.prod.outlook.com (2603:10b6:408:190::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Fri, 31 May 2024 04:33:08 +0000 Received: from DS3PEPF000099D9.namprd04.prod.outlook.com (2603:10b6:5:1e0:cafe::12) by DM6PR08CA0049.outlook.office365.com (2603:10b6:5:1e0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24 via Frontend Transport; Fri, 31 May 2024 04:33:07 +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 DS3PEPF000099D9.mail.protection.outlook.com (10.167.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:33:07 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:33:02 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 09/24] virt: sev-guest: Carve out SNP guest messaging init/exit Date: Fri, 31 May 2024 10:00:23 +0530 Message-ID: <20240531043038.3370793-10-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D9:EE_|LV8PR12MB9154:EE_ X-MS-Office365-Filtering-Correlation-Id: cd766aa1-6e33-409a-0dfe-08dc812ac555 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|36860700004|376005|7416005|1800799015; X-Microsoft-Antispam-Message-Info: 2oxwwPMsrq1FgRa6d1l0jenwps4WxUcyYw16jXIj9+CmPHN2FSTnoroO7tJ9oI4GdHXS5cImDHnglAuk9ZycteCe5uihwOQEdfC7Rh2EZMdT9+ccfUh79oUIyApJTEDIUYzdwReaKCmjB3bjqfIi3bxm1URWw9tO6HpjsP2VdDHeiG3Ay2n7Thj9vAGqzmCrZpI5pnbsQDtSl2GCkdzYSJSi5OWk7QposHV1kQ0oJgjfpKBsi47Sh9hbBdaef9rnbdfxajsuhEF77HgbiitllcMtePjBoDBUn0FDJ8NJR68Z2DiYyHtc7VBnh8u9RM7wL8+x6/rJbj6B0hj471HdqX8TXxjrRA1qXeezipD2eb224VQ6Rs31bzRFGlD85NvAmDJeb0L9x6p0xyd5KUX2N3dHABKp+Lr8Frh/TlEiteL3sP/nwQy48eRiTLx3tQhnxfz7mkIik22j8iZSdjOkX4OEr54NlfMdjSIv0JjNbKPcOl3/gIgTtbdyuiCDWoAOGxLxPyAOhEw5mOrSHho5Dp8+d/qpX5oYlQgSEJbGEUYYn2W+73JpoKMEFrBAOl+Fl6H9opwmWH6WDVFFayAdrN2/QV0ThU9J2UevmS+ss4XoXMNXoJPzqaxjAWmWpXvmJa2QgBbBn8aG984ig/jiZMzhGSrUrt4M6hMqiABvK2Z0mOiNYDYMKuEHBaGui+D/rNTe3+BNizjHdyMX0bK5eiIpv5XAZxMvF3g8ivYAYJF8h6lzJBK43cWuCufQeeVimmerL2d8grLgFMk+yxVlXUvGG5BW4h+S/ci2uxgzzu8zu0ri2iv/LXBu1dwRotTFUIqm35W9I9AwOSPgyqM48iAzTXwkjSYO9w2rCPgSqszKk7wO5ZiWh2BKoyytoEJXGBvyPLkEi6of3K4uN6dRq87SEpj355hLuwYJ58/7Rs4Cl76ZKSfc4sKqTgRXzfVbpW6aUkLj1uo4Z8Mb3EwEz4EqvjgIUeolt+Ta8/6oGXKjFLtKusmnTddP55Fyb37KLcjFiQ7IAXoAL0Xi4nxEfgHxPbcC1WOfC1+u+ITauFd0dEb02xWFPyhoqo2c+arvPUaHHW/PSMdW8f9Q1LM+dmcnfs0EQFcIOig0kp0P3usH0K3CprnBLqSRALWqgdPRBNlnEUY6IboCajPcF7nwU5kcmYx4DdqnuGpkPM31WVul7S3vynXTbdmvykyc4Ano03VT5vwPE2OviY0thqjg5HTMtTxcQv03t8pqAPwEZGQO6yT8K+r/4PLz1IBZCwzQkI4AIiR5xDSjHMza3yXhdbThIdPfDeVIUNB9AsRE6oGOV2v0kaKTT/EaHhxF+2Hwi7V07hB9JiqrEjIvwnUTgu+4j/Lbihjx6U/M/tWFffwZmldv5bPR9BBB0LP8xXFo 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)(82310400017)(36860700004)(376005)(7416005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:33:07.8281 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cd766aa1-6e33-409a-0dfe-08dc812ac555 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: DS3PEPF000099D9.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9154 In preparation for the movement of common code required for both SEV guest driver and Secure TSC, carve out initializaton and cleanup routines. While at it, the device pointer in alloc_shared_pages() is used only in the print routines, replace dev_err() with pr_err() and drop the device pointer from the function prototype. Signed-off-by: Nikunj A Dadhania --- drivers/virt/coco/sev-guest/sev-guest.c | 152 ++++++++++++++---------- 1 file changed, 88 insertions(+), 64 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 19ee85fcfd08..0ec376f7edec 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -150,6 +150,11 @@ static struct aesgcm_ctx *snp_init_crypto(struct snp_guest_dev *snp_dev) struct aesgcm_ctx *ctx; u8 *key; + if (is_vmpck_empty(snp_dev)) { + pr_err("VM communication key VMPCK%u is invalid\n", snp_dev->vmpck_id); + return NULL; + } + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL_ACCOUNT); if (!ctx) return NULL; @@ -629,7 +634,7 @@ static void free_shared_pages(void *buf, size_t sz) __free_pages(virt_to_page(buf), get_order(sz)); } -static void *alloc_shared_pages(struct device *dev, size_t sz) +static void *alloc_shared_pages(size_t sz) { unsigned int npages = PAGE_ALIGN(sz) >> PAGE_SHIFT; struct page *page; @@ -641,7 +646,7 @@ static void *alloc_shared_pages(struct device *dev, size_t sz) ret = set_memory_decrypted((unsigned long)page_address(page), npages); if (ret) { - dev_err(dev, "failed to mark page shared, ret=%d\n", ret); + pr_err("failed to mark page shared, ret=%d\n", ret); __free_pages(page, get_order(sz)); return NULL; } @@ -786,14 +791,80 @@ static void unregister_sev_tsm(void *data) tsm_unregister(&sev_tsm_ops); } +static int snp_guest_messaging_init(struct snp_guest_dev *snp_dev, u64 secrets_gpa) +{ + int ret = -ENOMEM; + + snp_dev->secrets = (__force void *)ioremap_encrypted(secrets_gpa, PAGE_SIZE); + if (!snp_dev->secrets) { + pr_err("Failed to map SNP secrets page.\n"); + return ret; + } + + /* Allocate secret request and response message for double buffering */ + snp_dev->secret_request = kzalloc(SNP_GUEST_MSG_SIZE, GFP_KERNEL); + if (!snp_dev->secret_request) + goto e_unmap; + + snp_dev->secret_response = kzalloc(SNP_GUEST_MSG_SIZE, GFP_KERNEL); + if (!snp_dev->secret_response) + goto e_free_secret_req; + + /* Allocate the shared page used for the request and response message. */ + snp_dev->request = alloc_shared_pages(SNP_GUEST_MSG_SIZE); + if (!snp_dev->request) + goto e_free_secret_resp; + + snp_dev->response = alloc_shared_pages(SNP_GUEST_MSG_SIZE); + if (!snp_dev->response) + goto e_free_request; + + /* Initialize the input addresses for guest request */ + snp_dev->input.req_gpa = __pa(snp_dev->request); + snp_dev->input.resp_gpa = __pa(snp_dev->response); + + ret = -EIO; + snp_dev->ctx = snp_init_crypto(snp_dev); + if (!snp_dev->ctx) { + pr_err("SNP crypto context initialization failed\n"); + goto e_free_response; + } + + return 0; + +e_free_response: + free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg)); +e_free_request: + free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg)); +e_free_secret_resp: + kfree(snp_dev->secret_response); +e_free_secret_req: + kfree(snp_dev->secret_request); +e_unmap: + iounmap(snp_dev->secrets); + + return ret; +} + +static void snp_guest_messaging_exit(struct snp_guest_dev *snp_dev) +{ + if (!snp_dev) + return; + + kfree(snp_dev->ctx); + free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg)); + free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg)); + kfree(snp_dev->secret_response); + kfree(snp_dev->secret_request); + iounmap(snp_dev->secrets); +} + static int __init sev_guest_probe(struct platform_device *pdev) { struct sev_guest_platform_data *data; - struct snp_secrets_page *secrets; struct device *dev = &pdev->dev; struct snp_guest_dev *snp_dev; struct miscdevice *misc; - void __iomem *mapping; int ret; if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) @@ -803,69 +874,36 @@ static int __init sev_guest_probe(struct platform_device *pdev) return -ENODEV; data = (struct sev_guest_platform_data *)dev->platform_data; - mapping = ioremap_encrypted(data->secrets_gpa, PAGE_SIZE); - if (!mapping) - return -ENODEV; - - secrets = (__force void *)mapping; - ret = -ENOMEM; snp_dev = devm_kzalloc(&pdev->dev, sizeof(struct snp_guest_dev), GFP_KERNEL); if (!snp_dev) - goto e_unmap; + return -ENOMEM; ret = -EINVAL; - snp_dev->secrets = secrets; if (!assign_vmpck(snp_dev, vmpck_id)) { dev_err(dev, "Invalid VMPCK%d communication key\n", vmpck_id); - goto e_unmap; + return ret; } - /* Verify that VMPCK is not zero. */ - if (is_vmpck_empty(snp_dev)) { - dev_err(dev, "Empty VMPCK%d communication key\n", snp_dev->vmpck_id); - goto e_unmap; + if (snp_guest_messaging_init(snp_dev, data->secrets_gpa)) { + dev_err(dev, "Unable to setup SNP Guest messaging using VMPCK%u\n", + snp_dev->vmpck_id); + return ret; } platform_set_drvdata(pdev, snp_dev); snp_dev->dev = dev; - /* Allocate secret request and response message for double buffering */ - snp_dev->secret_request = kzalloc(SNP_GUEST_MSG_SIZE, GFP_KERNEL); - if (!snp_dev->secret_request) - goto e_unmap; - - snp_dev->secret_response = kzalloc(SNP_GUEST_MSG_SIZE, GFP_KERNEL); - if (!snp_dev->secret_response) - goto e_free_secret_req; - - /* Allocate the shared page used for the request and response message. */ - snp_dev->request = alloc_shared_pages(dev, SNP_GUEST_MSG_SIZE); - if (!snp_dev->request) - goto e_free_secret_resp; - - snp_dev->response = alloc_shared_pages(dev, SNP_GUEST_MSG_SIZE); - if (!snp_dev->response) - goto e_free_request; - - snp_dev->certs_data = alloc_shared_pages(dev, SEV_FW_BLOB_MAX_SIZE); + ret = -ENOMEM; + snp_dev->certs_data = alloc_shared_pages(SEV_FW_BLOB_MAX_SIZE); if (!snp_dev->certs_data) - goto e_free_response; - - ret = -EIO; - snp_dev->ctx = snp_init_crypto(snp_dev); - if (!snp_dev->ctx) - goto e_free_cert_data; + goto e_cleanup_msg_init; misc = &snp_dev->misc; misc->minor = MISC_DYNAMIC_MINOR; misc->name = DEVICE_NAME; misc->fops = &snp_guest_fops; - /* Initialize the input addresses for guest request */ - snp_dev->input.req_gpa = __pa(snp_dev->request); - snp_dev->input.resp_gpa = __pa(snp_dev->response); - ret = tsm_register(&sev_tsm_ops, snp_dev, &tsm_report_extra_type); if (ret) goto e_free_cert_data; @@ -876,25 +914,15 @@ static int __init sev_guest_probe(struct platform_device *pdev) ret = misc_register(misc); if (ret) - goto e_free_ctx; + goto e_free_cert_data; dev_info(dev, "Initialized SEV guest driver (using VMPCK%d communication key)\n", vmpck_id); return 0; -e_free_ctx: - kfree(snp_dev->ctx); e_free_cert_data: free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE); -e_free_response: - free_shared_pages(snp_dev->response, SNP_GUEST_MSG_SIZE); -e_free_request: - free_shared_pages(snp_dev->request, SNP_GUEST_MSG_SIZE); -e_free_secret_resp: - kfree(snp_dev->secret_response); -e_free_secret_req: - kfree(snp_dev->secret_request); -e_unmap: - iounmap(mapping); +e_cleanup_msg_init: + snp_guest_messaging_exit(snp_dev); return ret; } @@ -903,11 +931,7 @@ static void __exit sev_guest_remove(struct platform_device *pdev) struct snp_guest_dev *snp_dev = platform_get_drvdata(pdev); free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE); - free_shared_pages(snp_dev->response, SNP_GUEST_MSG_SIZE); - free_shared_pages(snp_dev->request, SNP_GUEST_MSG_SIZE); - kfree(snp_dev->secret_response); - kfree(snp_dev->secret_request); - kfree(snp_dev->ctx); + snp_guest_messaging_exit(snp_dev); misc_deregister(&snp_dev->misc); } From patchwork Fri May 31 04:30:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681118 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2081.outbound.protection.outlook.com [40.107.220.81]) (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 266B57F7D5; Fri, 31 May 2024 04:33:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129997; cv=fail; b=IKiGalondzKOVHBnSjxQ6BK0lM1PybjlKO4vwd8kKaFv7i3BR6469LbjsUJWUPLS28azH6YhgxvITtbftKswaNyaXva5jI0bCJoZr5hixnDns9TaVvOlPoEkzvByq83Vz9X7EaQDrRa4OesMnzECb/gB4ZkfXjZ3C6CMy4kcrYY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129997; c=relaxed/simple; bh=BC7xgHNpGjcqmRYLLo5EjIjch7fW+caY/YpZh2nbc0Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hKJqqR76SetRQ56ncze7Jk5doFj8sck+mhbXJGKnQCFj3z7eYDAEAXgSTBQS8R+wjE3wOquTpwGc7JanmRZBWMz/Dm3wQkb3GPGO5Z/IpGnTUrfoaWODayNMja+RAp+l44LGnXdrMISKUQbr04hsxM+f20gqlr4cJlqiefacJHs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=RkEReduL; arc=fail smtp.client-ip=40.107.220.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="RkEReduL" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jZoTHe8CCpoSV5ebtQ0XZU7se4qbkTmtOTmNYxjdQisIXErNe0wStkeHJxENqKCcXS8eabf2NqP4ckTW9wss5voj0TpW9LGtAk5Lvq7hcQst5mSbL1I8TsJFOIb2SV2g0umSCIlOs3X8Vowic8SdHi/V4cJ1i9+hIMXMM1EW+oc5c3yE0nYpggfJjZ1XnQ87+LgD/o1Z42oR3lXb6rPIgLVC8ZcP1qRatOszPhUpHlovc2dPbWUwxdFrCBT6clbI+8M7QGj1YBhcpTdyr75F7oIw1FLB1sev9Hd1i2OixtFelwQxOkj7ojxRj4xtiF3ABCXKlnhS+KT4pwkDOKVlWw== 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=i852oqO+ToQ0KaZAw0hJz2psiKVisEdtIHuHewtYISA=; b=n6c8wvpmaHr1M7ELkv57tHf02jv/FpjLlcHCCD1YwsNCjWhsmjqh+fKf3IBfWqXJnaTeZTt3sLFzHKas3JZNcbPVXM0D5m8vULJ61nWeUj0AL3+PFjIZMzg2CAciNfiN+CTa7GkWZ6JE/wkfe2iRG0ILSFq+INwiK4R4U8fIrE9NppnoSKVxdfzdpZvSPDNV686RIi7PMnO1EDwFzza1HAbK8WyP4gBN0sj2zDe36coyCM59ntlMdU6I5zIzCjaECR+p4MfaYmRNnkyWLpGFC/oiXiZ8l7zj30kn76UFBrefiIDyg9b58DkO4hVeUZhAoF7vg7szS8jGBGWfhdaCKw== 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=i852oqO+ToQ0KaZAw0hJz2psiKVisEdtIHuHewtYISA=; b=RkEReduLPr8LAmaY4mW0AWaZmZ4MWNsZ+TzylaYKAsdsL3+tNwb5zr4QBVDtrQGfPO9zW40C7TUHvgfhpHczFgbntNSTan/HIr/VRsiuWXYDaGWsFP5ZjwXualNFF5txrFHVT6Os/qcoZFYjcmFfHbvEwSRKlxkv99g3UyF0wcY= Received: from DM6PR08CA0053.namprd08.prod.outlook.com (2603:10b6:5:1e0::27) by IA0PR12MB8695.namprd12.prod.outlook.com (2603:10b6:208:485::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29; Fri, 31 May 2024 04:33:11 +0000 Received: from DS3PEPF000099D9.namprd04.prod.outlook.com (2603:10b6:5:1e0:cafe::ba) by DM6PR08CA0053.outlook.office365.com (2603:10b6:5:1e0::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22 via Frontend Transport; Fri, 31 May 2024 04:33:10 +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 DS3PEPF000099D9.mail.protection.outlook.com (10.167.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:33:10 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:33:06 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 10/24] x86/sev: Move core SEV guest driver routines to common code Date: Fri, 31 May 2024 10:00:24 +0530 Message-ID: <20240531043038.3370793-11-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D9:EE_|IA0PR12MB8695:EE_ X-MS-Office365-Filtering-Correlation-Id: ddfefab4-2682-4540-f93c-08dc812ac706 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|1800799015|7416005|36860700004|376005; X-Microsoft-Antispam-Message-Info: eCyHjWHmGcrxlREhc4lsxh05NsKzLVYpMCVB28HMOUa2uOrai693/sgC8NtbPSN+UWM88maNpTGlxprsyr9PFOSo+G+mInKHtzIR/n0VAWmh68KJV1p12N/D6yomcwiASq72q9eXyXdmh1h4SH4h0Tmn80VgshjyXMZPwVyDydun/WOZ4cMjU/PSLe5vftDI8it4cHk/cERwFpHzpp0tTxVP8BxZVEkpjXnj60W5TTMXSs97ZXsQdZStsWvG4504RywglRbl0YOF8WDLbwdkMFog6D7XAf7CtlPO21AZuRd1XX2IfYo8JZ8u4qe04SocGHKsj//BWVu8O6LEZULslH2BvxD55miE3guTYSkY0KeSDQgWb+pXkAQrJdNmVNMGwEB9nShcelfDg3PnAlDAa7zRunnbdSWzGlRqA+ii2AA8Dio9DwLqIZ9a3DL2FC6TwI47Ajz5vDFKLzkT36AHLyHER1ThBmGGcbBRLOjrj3TKPq9qhMk5ROEGI8bwWGYa5KcblYKiW/u83rwuDq04X/KnktEbm6FUt0Jz9QRMMDyriL8ycB7s/qWSKl7RrqzC46qLOayMAETOKqLsTH1o7F2Hhy2k9P8i4QBR+y740rY/PyR4PleKy8rWAkOmS58Ej7sFBuPpAip7xjr/jfYqrZYV5rH8L9KNr2dgfnr8ZDBwSptQoVDTVkp8KCyqX/ndST6MxVr9z6SLb/eGkYrBiFNI/f26HI82t0kpRwwqz9jfEwT/xjGpoyr8Vref7lnjj62h+3b8HJwp8C3m0McZiHS6feu7O3VXqE29PtKYUYa5Lqti3wbCiDwMhoDUUHMKQD5SUHdz2T7CkUwqDNVBrh5hMQE5LIksPQqj8cxecMDjcKWZ5e9UMC5dtDYTV8zGuBKXt41PSqHVZzVdCz0Z+/zAppkRe/ravJuphBNEnxIGHU+IfECupjxiBFwS+/X5btlFyzCJMdjdzyncDe7/mawQ4BG9UrCQj/rwWY9Hu4U87dHRqIv/HEoxb8k7oEsxl0VvPyzLpDF7Q3msxqUIqd9p1bBlGR9ZXFj8AGlviIHogZBqYb6glDN1tRYdk8EWGXsuDnB409DljrZSZvgkGAIB0jqkgHYoH1P1nlGcmsMiBJrJcHYEtpDxcIRXe0alWQSOmj9G6iu7Bwbbs+6ZXeUxfpluLQO67zP5S/ESbS5KNXA1PMLAtKxZ+4RQ3pAgbaqVE2imaKIwz0HjQScbHbihPu/qo4N6DweJdBnE9Oxs3Q3/jfxk/A2obxPmy/L/NrqNx8UbCN9HSQbphDJyP6nnHLy1a2oO0SHLbdofsIz7crZqehOkkZWm0jkakAABpKZrsNzxO/8g4krZBIg1Mkh1ZL6AbqcwXzZS4QcLAQ1ZGS3wNCKc0bjEMN81Evrb 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)(82310400017)(1800799015)(7416005)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:33:10.6719 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ddfefab4-2682-4540-f93c-08dc812ac706 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: DS3PEPF000099D9.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8695 In order to enable Secure TSC, SEV-SNP guests need to communicate with the AMD Security Processor during early boot. However, many of the necessary SNP guest messaging functions are currently implemented in the SEV guest driver and are not available during early boot. As a result, these core SNP guest messaging functions need to be relocated to SEV common code. Later, APIs will be provided to the SEV guest driver to initialize and send SNP guest messages. Some functions in sev.c are marked __maybe_unused to ensure compilation does not break. Similarly, a few functions are stubbed out in SEV guest driver. This is pure code movement, SEV guest driver is broken after this patch. Signed-off-by: Nikunj A Dadhania --- arch/x86/include/asm/sev.h | 70 ++++ arch/x86/kernel/sev.c | 393 +++++++++++++++++++++ drivers/virt/coco/sev-guest/sev-guest.c | 442 +----------------------- arch/x86/Kconfig | 1 + drivers/virt/coco/sev-guest/Kconfig | 1 - 5 files changed, 473 insertions(+), 434 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index d06b08f7043c..9c5bd8063491 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -10,10 +10,12 @@ #include #include +#include #include #include #include +#include #define GHCB_PROTOCOL_MIN 1ULL #define GHCB_PROTOCOL_MAX 2ULL @@ -149,6 +151,9 @@ struct snp_secrets_page { u8 rsvd3[3840]; } __packed; +#define SNP_REQ_MAX_RETRY_DURATION (60*HZ) +#define SNP_REQ_RETRY_DELAY (2*HZ) + #define MAX_AUTHTAG_LEN 32 #define AUTHTAG_LEN 16 #define AAD_LEN 48 @@ -203,6 +208,31 @@ struct snp_guest_msg { #define SNP_GUEST_MSG_SIZE 4096 #define SNP_GUEST_MSG_PAYLOAD_SIZE (SNP_GUEST_MSG_SIZE - sizeof(struct snp_guest_msg)) +struct snp_guest_dev { + struct device *dev; + struct miscdevice misc; + + void *certs_data; + struct aesgcm_ctx *ctx; + /* request and response are in unencrypted memory */ + struct snp_guest_msg *request, *response; + + /* + * Avoid information leakage by double-buffering shared messages + * in fields that are in regular encrypted memory. + */ + struct snp_guest_msg *secret_request, *secret_response; + + struct snp_secrets_page *secrets; + struct snp_req_data input; + union { + struct snp_report_req report; + struct snp_derived_key_req derived_key; + struct snp_ext_report_req ext_report; + } req; + unsigned int vmpck_id; +}; + struct snp_guest_req { void *req_buf; size_t req_sz; @@ -294,6 +324,44 @@ void snp_accept_memory(phys_addr_t start, phys_addr_t end); u64 snp_get_unsupported_features(u64 status); u64 sev_get_status(void); void sev_show_status(void); + +static inline void free_shared_pages(void *buf, size_t sz) +{ + unsigned int npages = PAGE_ALIGN(sz) >> PAGE_SHIFT; + int ret; + + if (!buf) + return; + + ret = set_memory_encrypted((unsigned long)buf, npages); + if (ret) { + WARN_ONCE(ret, "failed to restore encryption mask (leak it)\n"); + return; + } + + __free_pages(virt_to_page(buf), get_order(sz)); +} + +static inline void *alloc_shared_pages(size_t sz) +{ + unsigned int npages = PAGE_ALIGN(sz) >> PAGE_SHIFT; + struct page *page; + int ret; + + page = alloc_pages(GFP_KERNEL_ACCOUNT, get_order(sz)); + if (!page) + return NULL; + + ret = set_memory_decrypted((unsigned long)page_address(page), npages); + if (ret) { + pr_err("failed to mark page shared, ret=%d\n", ret); + __free_pages(page, get_order(sz)); + return NULL; + } + + return page_address(page); +} + #else static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } @@ -324,6 +392,8 @@ static inline void snp_accept_memory(phys_addr_t start, phys_addr_t end) { } static inline u64 snp_get_unsupported_features(u64 status) { return 0; } static inline u64 sev_get_status(void) { return 0; } static inline void sev_show_status(void) { } +static inline void free_shared_pages(void *buf, size_t sz) { } +static inline void *alloc_shared_pages(size_t sz) { return NULL; } #endif #ifdef CONFIG_KVM_AMD_SEV diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 8145bf123ac9..329ae107da4a 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -2300,3 +2301,395 @@ void sev_show_status(void) } pr_cont("\n"); } + +/* Mutex to serialize the shared buffer access and command handling. */ +static DEFINE_MUTEX(snp_cmd_mutex); + +static inline u8 *get_vmpck(struct snp_guest_dev *snp_dev) +{ + return snp_dev->secrets->vmpck[snp_dev->vmpck_id]; +} + +static bool __maybe_unused assign_vmpck(struct snp_guest_dev *dev, unsigned int vmpck_id) +{ + if ((vmpck_id + 1) > VMPCK_MAX_NUM) + return false; + + dev->vmpck_id = vmpck_id; + + return true; +} + +static bool is_vmpck_empty(struct snp_guest_dev *snp_dev) +{ + char zero_key[VMPCK_KEY_LEN] = {0}; + u8 *key = get_vmpck(snp_dev); + + return !memcmp(key, zero_key, VMPCK_KEY_LEN); +} + +/* + * If an error is received from the host or AMD Secure Processor (ASP) there + * are two options. Either retry the exact same encrypted request or discontinue + * using the VMPCK. + * + * This is because in the current encryption scheme GHCB v2 uses AES-GCM to + * encrypt the requests. The IV for this scheme is the sequence number. GCM + * cannot tolerate IV reuse. + * + * The ASP FW v1.51 only increments the sequence numbers on a successful + * guest<->ASP back and forth and only accepts messages at its exact sequence + * number. + * + * So if the sequence number were to be reused the encryption scheme is + * vulnerable. If the sequence number were incremented for a fresh IV the ASP + * will reject the request. + */ +static void snp_disable_vmpck(struct snp_guest_dev *snp_dev) +{ + u8 *key = get_vmpck(snp_dev); + + if (is_vmpck_empty(snp_dev)) + return; + + dev_alert(snp_dev->dev, "Disabling VMPCK%u to prevent IV reuse.\n", snp_dev->vmpck_id); + memzero_explicit(key, VMPCK_KEY_LEN); +} + +/* Return a non-zero on success */ +static u64 snp_get_msg_seqno(struct snp_guest_dev *snp_dev) +{ + u64 count; + + count = snp_dev->secrets->os_area.msg_seqno[snp_dev->vmpck_id] + 1; + + /* + * The message sequence counter for the SNP guest request is a 64-bit + * value but the version 2 of GHCB specification defines a 32-bit storage + * for it. If the counter exceeds the 32-bit value then return zero. + * The caller should check the return value, but if the caller happens to + * not check the value and use it, then the firmware treats zero as an + * invalid number and will fail the message request. + */ + if (count >= UINT_MAX) { + dev_err(snp_dev->dev, "request message sequence counter overflow\n"); + return 0; + } + + return count; +} + +static void snp_inc_msg_seqno(struct snp_guest_dev *snp_dev) +{ + /* + * The counter is also incremented by the PSP, so increment it by 2 + * and save in secrets page. + */ + snp_dev->secrets->os_area.msg_seqno[snp_dev->vmpck_id] += 2; +} + +static struct aesgcm_ctx *snp_init_crypto(struct snp_guest_dev *snp_dev) +{ + struct aesgcm_ctx *ctx; + u8 *key; + + if (is_vmpck_empty(snp_dev)) { + pr_err("VM communication key VMPCK%u is invalid\n", snp_dev->vmpck_id); + return NULL; + } + + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL_ACCOUNT); + if (!ctx) + return NULL; + + key = get_vmpck(snp_dev); + if (aesgcm_expandkey(ctx, key, VMPCK_KEY_LEN, AUTHTAG_LEN)) { + pr_err("Crypto context initialization failed\n"); + kfree(ctx); + return NULL; + } + + return ctx; +} + +static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, struct snp_guest_req *req) +{ + struct snp_guest_msg *resp_msg = snp_dev->secret_response; + struct snp_guest_msg *req_msg = snp_dev->secret_request; + struct snp_guest_msg_hdr *req_msg_hdr = &req_msg->hdr; + struct snp_guest_msg_hdr *resp_msg_hdr = &resp_msg->hdr; + struct aesgcm_ctx *ctx = snp_dev->ctx; + u8 iv[GCM_AES_IV_SIZE] = {}; + + pr_debug("response [seqno %lld type %d version %d sz %d]\n", + resp_msg_hdr->msg_seqno, resp_msg_hdr->msg_type, resp_msg_hdr->msg_version, + resp_msg_hdr->msg_sz); + + /* Copy response from shared memory to encrypted memory. */ + memcpy(resp_msg, snp_dev->response, SNP_GUEST_MSG_SIZE); + + /* Verify that the sequence counter is incremented by 1 */ + if (unlikely(resp_msg_hdr->msg_seqno != (req_msg_hdr->msg_seqno + 1))) + return -EBADMSG; + + /* Verify response message type and version number. */ + if (resp_msg_hdr->msg_type != (req_msg_hdr->msg_type + 1) || + resp_msg_hdr->msg_version != req_msg_hdr->msg_version) + return -EBADMSG; + + /* + * If the message size is greater than our buffer length then return + * an error. + */ + if (unlikely((resp_msg_hdr->msg_sz + ctx->authsize) > req->resp_sz)) + return -EBADMSG; + + /* Decrypt the payload */ + memcpy(iv, &resp_msg_hdr->msg_seqno, min(sizeof(iv), sizeof(resp_msg_hdr->msg_seqno))); + if (!aesgcm_decrypt(ctx, req->resp_buf, resp_msg->payload, resp_msg_hdr->msg_sz, + &resp_msg_hdr->algo, AAD_LEN, iv, resp_msg_hdr->authtag)) + return -EBADMSG; + + return 0; +} + +static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, struct snp_guest_req *req) +{ + struct snp_guest_msg *msg = snp_dev->secret_request; + struct snp_guest_msg_hdr *hdr = &msg->hdr; + struct aesgcm_ctx *ctx = snp_dev->ctx; + u8 iv[GCM_AES_IV_SIZE] = {}; + + memset(msg, 0, SNP_GUEST_MSG_SIZE); + + hdr->algo = SNP_AEAD_AES_256_GCM; + hdr->hdr_version = MSG_HDR_VER; + hdr->hdr_sz = sizeof(*hdr); + hdr->msg_type = req->msg_type; + hdr->msg_version = req->msg_version; + hdr->msg_seqno = seqno; + hdr->msg_vmpck = req->vmpck_id; + hdr->msg_sz = req->req_sz; + + /* Verify the sequence number is non-zero */ + if (!hdr->msg_seqno) + return -ENOSR; + + pr_debug("request [seqno %lld type %d version %d sz %d]\n", + hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); + + if (WARN_ON((req->req_sz + ctx->authsize) > SNP_GUEST_MSG_PAYLOAD_SIZE)) + return -EBADMSG; + + memcpy(iv, &hdr->msg_seqno, min(sizeof(iv), sizeof(hdr->msg_seqno))); + aesgcm_encrypt(ctx, msg->payload, req->req_buf, req->req_sz, &hdr->algo, + AAD_LEN, iv, hdr->authtag); + + return 0; +} + +static int __handle_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, + struct snp_guest_request_ioctl *rio) +{ + unsigned long req_start = jiffies; + unsigned int override_npages = 0; + u64 override_err = 0; + int rc; + +retry_request: + /* + * Call firmware to process the request. In this function the encrypted + * message enters shared memory with the host. So after this call the + * sequence number must be incremented or the VMPCK must be deleted to + * prevent reuse of the IV. + */ + rc = snp_issue_guest_request(req, &snp_dev->input, rio); + switch (rc) { + case -ENOSPC: + /* + * If the extended guest request fails due to having too + * small of a certificate data buffer, retry the same + * guest request without the extended data request in + * order to increment the sequence number and thus avoid + * IV reuse. + */ + override_npages = req->data_npages; + req->exit_code = SVM_VMGEXIT_GUEST_REQUEST; + + /* + * Override the error to inform callers the given extended + * request buffer size was too small and give the caller the + * required buffer size. + */ + override_err = SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN); + + /* + * If this call to the firmware succeeds, the sequence number can + * be incremented allowing for continued use of the VMPCK. If + * there is an error reflected in the return value, this value + * is checked further down and the result will be the deletion + * of the VMPCK and the error code being propagated back to the + * user as an ioctl() return code. + */ + goto retry_request; + + /* + * The host may return SNP_GUEST_VMM_ERR_BUSY if the request has been + * throttled. Retry in the driver to avoid returning and reusing the + * message sequence number on a different message. + */ + case -EAGAIN: + if (jiffies - req_start > SNP_REQ_MAX_RETRY_DURATION) { + rc = -ETIMEDOUT; + break; + } + schedule_timeout_killable(SNP_REQ_RETRY_DELAY); + goto retry_request; + } + + /* + * Increment the message sequence number. There is no harm in doing + * this now because decryption uses the value stored in the response + * structure and any failure will wipe the VMPCK, preventing further + * use anyway. + */ + snp_inc_msg_seqno(snp_dev); + + if (override_err) { + rio->exitinfo2 = override_err; + + /* + * If an extended guest request was issued and the supplied certificate + * buffer was not large enough, a standard guest request was issued to + * prevent IV reuse. If the standard request was successful, return -EIO + * back to the caller as would have originally been returned. + */ + if (!rc && override_err == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN)) + rc = -EIO; + } + + if (override_npages) + req->data_npages = override_npages; + + return rc; +} + +static int __maybe_unused snp_send_guest_request(struct snp_guest_dev *snp_dev, + struct snp_guest_req *req, + struct snp_guest_request_ioctl *rio) +{ + u64 seqno; + int rc; + + guard(mutex)(&snp_cmd_mutex); + + /* Get message sequence and verify that its a non-zero */ + seqno = snp_get_msg_seqno(snp_dev); + if (!seqno) + return -EIO; + + /* Clear shared memory's response for the host to populate. */ + memset(snp_dev->response, 0, SNP_GUEST_MSG_SIZE); + + /* Encrypt the userspace provided payload in snp_dev->secret_request. */ + rc = enc_payload(snp_dev, seqno, req); + if (rc) + return rc; + + /* + * Write the fully encrypted request to the shared unencrypted + * request page. + */ + memcpy(snp_dev->request, snp_dev->secret_request, SNP_GUEST_MSG_SIZE); + + rc = __handle_guest_request(snp_dev, req, rio); + if (rc) { + if (rc == -EIO && + rio->exitinfo2 == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN)) + return rc; + + dev_alert(snp_dev->dev, + "Detected error from ASP request. rc: %d, exitinfo2: 0x%llx\n", + rc, rio->exitinfo2); + snp_disable_vmpck(snp_dev); + return rc; + } + + rc = verify_and_dec_payload(snp_dev, req); + if (rc) { + dev_alert(snp_dev->dev, "Detected unexpected decode failure from ASP. rc: %d\n", + rc); + snp_disable_vmpck(snp_dev); + return rc; + } + + return 0; +} + +static int __maybe_unused snp_guest_messaging_init(struct snp_guest_dev *snp_dev, u64 secrets_gpa) +{ + int ret = -ENOMEM; + + snp_dev->secrets = (__force void *)ioremap_encrypted(secrets_gpa, PAGE_SIZE); + if (!snp_dev->secrets) { + pr_err("Failed to map SNP secrets page.\n"); + return ret; + } + + /* Allocate secret request and response message for double buffering */ + snp_dev->secret_request = kzalloc(SNP_GUEST_MSG_SIZE, GFP_KERNEL); + if (!snp_dev->secret_request) + goto e_unmap; + + snp_dev->secret_response = kzalloc(SNP_GUEST_MSG_SIZE, GFP_KERNEL); + if (!snp_dev->secret_response) + goto e_free_secret_req; + + /* Allocate the shared page used for the request and response message. */ + snp_dev->request = alloc_shared_pages(SNP_GUEST_MSG_SIZE); + if (!snp_dev->request) + goto e_free_secret_resp; + + snp_dev->response = alloc_shared_pages(SNP_GUEST_MSG_SIZE); + if (!snp_dev->response) + goto e_free_request; + + /* Initialize the input addresses for guest request */ + snp_dev->input.req_gpa = __pa(snp_dev->request); + snp_dev->input.resp_gpa = __pa(snp_dev->response); + + ret = -EIO; + snp_dev->ctx = snp_init_crypto(snp_dev); + if (!snp_dev->ctx) { + pr_err("SNP crypto context initialization failed\n"); + goto e_free_response; + } + + return 0; + +e_free_response: + free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg)); +e_free_request: + free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg)); +e_free_secret_resp: + kfree(snp_dev->secret_response); +e_free_secret_req: + kfree(snp_dev->secret_request); +e_unmap: + iounmap(snp_dev->secrets); + + return ret; +} + +static void __maybe_unused snp_guest_messaging_exit(struct snp_guest_dev *snp_dev) +{ + if (!snp_dev) + return; + + kfree(snp_dev->ctx); + free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg)); + free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg)); + kfree(snp_dev->secret_response); + kfree(snp_dev->secret_request); + iounmap(snp_dev->secrets); +} diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 0ec376f7edec..567b3684eae5 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -30,112 +30,14 @@ #define DEVICE_NAME "sev-guest" -#define SNP_REQ_MAX_RETRY_DURATION (60*HZ) -#define SNP_REQ_RETRY_DELAY (2*HZ) - -struct snp_guest_dev { - struct device *dev; - struct miscdevice misc; - - void *certs_data; - struct aesgcm_ctx *ctx; - /* request and response are in unencrypted memory */ - struct snp_guest_msg *request, *response; - - /* - * Avoid information leakage by double-buffering shared messages - * in fields that are in regular encrypted memory. - */ - struct snp_guest_msg *secret_request, *secret_response; - - struct snp_secrets_page *secrets; - struct snp_req_data input; - union { - struct snp_report_req report; - struct snp_derived_key_req derived_key; - struct snp_ext_report_req ext_report; - } req; - unsigned int vmpck_id; -}; - static u32 vmpck_id; module_param(vmpck_id, uint, 0444); MODULE_PARM_DESC(vmpck_id, "The VMPCK ID to use when communicating with the PSP."); -/* Mutex to serialize the shared buffer access and command handling. */ -static DEFINE_MUTEX(snp_cmd_mutex); - -static inline u8 *get_vmpck(struct snp_guest_dev *snp_dev) -{ - return snp_dev->secrets->vmpck[snp_dev->vmpck_id]; -} - static bool is_vmpck_empty(struct snp_guest_dev *snp_dev) { - char zero_key[VMPCK_KEY_LEN] = {0}; - u8 *key = get_vmpck(snp_dev); - - return !memcmp(key, zero_key, VMPCK_KEY_LEN); -} - -/* - * If an error is received from the host or AMD Secure Processor (ASP) there - * are two options. Either retry the exact same encrypted request or discontinue - * using the VMPCK. - * - * This is because in the current encryption scheme GHCB v2 uses AES-GCM to - * encrypt the requests. The IV for this scheme is the sequence number. GCM - * cannot tolerate IV reuse. - * - * The ASP FW v1.51 only increments the sequence numbers on a successful - * guest<->ASP back and forth and only accepts messages at its exact sequence - * number. - * - * So if the sequence number were to be reused the encryption scheme is - * vulnerable. If the sequence number were incremented for a fresh IV the ASP - * will reject the request. - */ -static void snp_disable_vmpck(struct snp_guest_dev *snp_dev) -{ - u8 *key = get_vmpck(snp_dev); - - if (is_vmpck_empty(snp_dev)) - return; - - dev_alert(snp_dev->dev, "Disabling VMPCK%u to prevent IV reuse.\n", snp_dev->vmpck_id); - memzero_explicit(key, VMPCK_KEY_LEN); -} - -/* Return a non-zero on success */ -static u64 snp_get_msg_seqno(struct snp_guest_dev *snp_dev) -{ - u64 count; - - count = snp_dev->secrets->os_area.msg_seqno[snp_dev->vmpck_id] + 1; - - /* - * The message sequence counter for the SNP guest request is a 64-bit - * value but the version 2 of GHCB specification defines a 32-bit storage - * for it. If the counter exceeds the 32-bit value then return zero. - * The caller should check the return value, but if the caller happens to - * not check the value and use it, then the firmware treats zero as an - * invalid number and will fail the message request. - */ - if (count >= UINT_MAX) { - dev_err(snp_dev->dev, "request message sequence counter overflow\n"); - return 0; - } - - return count; -} - -static void snp_inc_msg_seqno(struct snp_guest_dev *snp_dev) -{ - /* - * The counter is also incremented by the PSP, so increment it by 2 - * and save in secrets page. - */ - snp_dev->secrets->os_area.msg_seqno[snp_dev->vmpck_id] += 2; + /* Place holder function to be removed after code movement */ + return true; } static inline struct snp_guest_dev *to_snp_dev(struct file *file) @@ -145,240 +47,11 @@ static inline struct snp_guest_dev *to_snp_dev(struct file *file) return container_of(dev, struct snp_guest_dev, misc); } -static struct aesgcm_ctx *snp_init_crypto(struct snp_guest_dev *snp_dev) -{ - struct aesgcm_ctx *ctx; - u8 *key; - - if (is_vmpck_empty(snp_dev)) { - pr_err("VM communication key VMPCK%u is invalid\n", snp_dev->vmpck_id); - return NULL; - } - - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL_ACCOUNT); - if (!ctx) - return NULL; - - key = get_vmpck(snp_dev); - if (aesgcm_expandkey(ctx, key, VMPCK_KEY_LEN, AUTHTAG_LEN)) { - pr_err("Crypto context initialization failed\n"); - kfree(ctx); - return NULL; - } - - return ctx; -} - -static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, struct snp_guest_req *req) -{ - struct snp_guest_msg *resp_msg = snp_dev->secret_response; - struct snp_guest_msg *req_msg = snp_dev->secret_request; - struct snp_guest_msg_hdr *req_msg_hdr = &req_msg->hdr; - struct snp_guest_msg_hdr *resp_msg_hdr = &resp_msg->hdr; - struct aesgcm_ctx *ctx = snp_dev->ctx; - u8 iv[GCM_AES_IV_SIZE] = {}; - - pr_debug("response [seqno %lld type %d version %d sz %d]\n", - resp_msg_hdr->msg_seqno, resp_msg_hdr->msg_type, resp_msg_hdr->msg_version, - resp_msg_hdr->msg_sz); - - /* Copy response from shared memory to encrypted memory. */ - memcpy(resp_msg, snp_dev->response, SNP_GUEST_MSG_SIZE); - - /* Verify that the sequence counter is incremented by 1 */ - if (unlikely(resp_msg_hdr->msg_seqno != (req_msg_hdr->msg_seqno + 1))) - return -EBADMSG; - - /* Verify response message type and version number. */ - if (resp_msg_hdr->msg_type != (req_msg_hdr->msg_type + 1) || - resp_msg_hdr->msg_version != req_msg_hdr->msg_version) - return -EBADMSG; - - /* - * If the message size is greater than our buffer length then return - * an error. - */ - if (unlikely((resp_msg_hdr->msg_sz + ctx->authsize) > req->resp_sz)) - return -EBADMSG; - - /* Decrypt the payload */ - memcpy(iv, &resp_msg_hdr->msg_seqno, min(sizeof(iv), sizeof(resp_msg_hdr->msg_seqno))); - if (!aesgcm_decrypt(ctx, req->resp_buf, resp_msg->payload, resp_msg_hdr->msg_sz, - &resp_msg_hdr->algo, AAD_LEN, iv, resp_msg_hdr->authtag)) - return -EBADMSG; - - return 0; -} - -static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, struct snp_guest_req *req) -{ - struct snp_guest_msg *msg = snp_dev->secret_request; - struct snp_guest_msg_hdr *hdr = &msg->hdr; - struct aesgcm_ctx *ctx = snp_dev->ctx; - u8 iv[GCM_AES_IV_SIZE] = {}; - - memset(msg, 0, SNP_GUEST_MSG_SIZE); - - hdr->algo = SNP_AEAD_AES_256_GCM; - hdr->hdr_version = MSG_HDR_VER; - hdr->hdr_sz = sizeof(*hdr); - hdr->msg_type = req->msg_type; - hdr->msg_version = req->msg_version; - hdr->msg_seqno = seqno; - hdr->msg_vmpck = req->vmpck_id; - hdr->msg_sz = req->req_sz; - - /* Verify the sequence number is non-zero */ - if (!hdr->msg_seqno) - return -ENOSR; - - pr_debug("request [seqno %lld type %d version %d sz %d]\n", - hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); - - if (WARN_ON((req->req_sz + ctx->authsize) > SNP_GUEST_MSG_PAYLOAD_SIZE)) - return -EBADMSG; - - memcpy(iv, &hdr->msg_seqno, min(sizeof(iv), sizeof(hdr->msg_seqno))); - aesgcm_encrypt(ctx, msg->payload, req->req_buf, req->req_sz, &hdr->algo, - AAD_LEN, iv, hdr->authtag); - - return 0; -} - -static int __handle_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, - struct snp_guest_request_ioctl *rio) -{ - unsigned long req_start = jiffies; - unsigned int override_npages = 0; - u64 override_err = 0; - int rc; - -retry_request: - /* - * Call firmware to process the request. In this function the encrypted - * message enters shared memory with the host. So after this call the - * sequence number must be incremented or the VMPCK must be deleted to - * prevent reuse of the IV. - */ - rc = snp_issue_guest_request(req, &snp_dev->input, rio); - switch (rc) { - case -ENOSPC: - /* - * If the extended guest request fails due to having too - * small of a certificate data buffer, retry the same - * guest request without the extended data request in - * order to increment the sequence number and thus avoid - * IV reuse. - */ - override_npages = req->data_npages; - req->exit_code = SVM_VMGEXIT_GUEST_REQUEST; - - /* - * Override the error to inform callers the given extended - * request buffer size was too small and give the caller the - * required buffer size. - */ - override_err = SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN); - - /* - * If this call to the firmware succeeds, the sequence number can - * be incremented allowing for continued use of the VMPCK. If - * there is an error reflected in the return value, this value - * is checked further down and the result will be the deletion - * of the VMPCK and the error code being propagated back to the - * user as an ioctl() return code. - */ - goto retry_request; - - /* - * The host may return SNP_GUEST_VMM_ERR_BUSY if the request has been - * throttled. Retry in the driver to avoid returning and reusing the - * message sequence number on a different message. - */ - case -EAGAIN: - if (jiffies - req_start > SNP_REQ_MAX_RETRY_DURATION) { - rc = -ETIMEDOUT; - break; - } - schedule_timeout_killable(SNP_REQ_RETRY_DELAY); - goto retry_request; - } - - /* - * Increment the message sequence number. There is no harm in doing - * this now because decryption uses the value stored in the response - * structure and any failure will wipe the VMPCK, preventing further - * use anyway. - */ - snp_inc_msg_seqno(snp_dev); - - if (override_err) { - rio->exitinfo2 = override_err; - - /* - * If an extended guest request was issued and the supplied certificate - * buffer was not large enough, a standard guest request was issued to - * prevent IV reuse. If the standard request was successful, return -EIO - * back to the caller as would have originally been returned. - */ - if (!rc && override_err == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN)) - rc = -EIO; - } - - if (override_npages) - req->data_npages = override_npages; - - return rc; -} - static int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, struct snp_guest_request_ioctl *rio) { - u64 seqno; - int rc; - - guard(mutex)(&snp_cmd_mutex); - - /* Get message sequence and verify that its a non-zero */ - seqno = snp_get_msg_seqno(snp_dev); - if (!seqno) - return -EIO; - - /* Clear shared memory's response for the host to populate. */ - memset(snp_dev->response, 0, SNP_GUEST_MSG_SIZE); - - /* Encrypt the userspace provided payload in snp_dev->secret_request. */ - rc = enc_payload(snp_dev, seqno, req); - if (rc) - return rc; - - /* - * Write the fully encrypted request to the shared unencrypted - * request page. - */ - memcpy(snp_dev->request, snp_dev->secret_request, SNP_GUEST_MSG_SIZE); - - rc = __handle_guest_request(snp_dev, req, rio); - if (rc) { - if (rc == -EIO && - rio->exitinfo2 == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN)) - return rc; - - dev_alert(snp_dev->dev, - "Detected error from ASP request. rc: %d, exitinfo2: 0x%llx\n", - rc, rio->exitinfo2); - snp_disable_vmpck(snp_dev); - return rc; - } - - rc = verify_and_dec_payload(snp_dev, req); - if (rc) { - dev_alert(snp_dev->dev, "Detected unexpected decode failure from ASP. rc: %d\n", rc); - snp_disable_vmpck(snp_dev); - return rc; - } - - return 0; + /* Place holder function to be removed after code movement */ + return -EIO; } struct snp_req_resp { @@ -617,43 +290,6 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long return ret; } -static void free_shared_pages(void *buf, size_t sz) -{ - unsigned int npages = PAGE_ALIGN(sz) >> PAGE_SHIFT; - int ret; - - if (!buf) - return; - - ret = set_memory_encrypted((unsigned long)buf, npages); - if (ret) { - WARN_ONCE(ret, "failed to restore encryption mask (leak it)\n"); - return; - } - - __free_pages(virt_to_page(buf), get_order(sz)); -} - -static void *alloc_shared_pages(size_t sz) -{ - unsigned int npages = PAGE_ALIGN(sz) >> PAGE_SHIFT; - struct page *page; - int ret; - - page = alloc_pages(GFP_KERNEL_ACCOUNT, get_order(sz)); - if (!page) - return NULL; - - ret = set_memory_decrypted((unsigned long)page_address(page), npages); - if (ret) { - pr_err("failed to mark page shared, ret=%d\n", ret); - __free_pages(page, get_order(sz)); - return NULL; - } - - return page_address(page); -} - static const struct file_operations snp_guest_fops = { .owner = THIS_MODULE, .unlocked_ioctl = snp_guest_ioctl, @@ -661,12 +297,8 @@ static const struct file_operations snp_guest_fops = { static bool assign_vmpck(struct snp_guest_dev *dev, unsigned int vmpck_id) { - if ((vmpck_id + 1) > VMPCK_MAX_NUM) - return false; - - dev->vmpck_id = vmpck_id; - - return true; + /* Place holder function to be removed after code movement */ + return false; } struct snp_msg_report_resp_hdr { @@ -793,70 +425,14 @@ static void unregister_sev_tsm(void *data) static int snp_guest_messaging_init(struct snp_guest_dev *snp_dev, u64 secrets_gpa) { - int ret = -ENOMEM; - - snp_dev->secrets = (__force void *)ioremap_encrypted(secrets_gpa, PAGE_SIZE); - if (!snp_dev->secrets) { - pr_err("Failed to map SNP secrets page.\n"); - return ret; - } - - /* Allocate secret request and response message for double buffering */ - snp_dev->secret_request = kzalloc(SNP_GUEST_MSG_SIZE, GFP_KERNEL); - if (!snp_dev->secret_request) - goto e_unmap; - - snp_dev->secret_response = kzalloc(SNP_GUEST_MSG_SIZE, GFP_KERNEL); - if (!snp_dev->secret_response) - goto e_free_secret_req; - - /* Allocate the shared page used for the request and response message. */ - snp_dev->request = alloc_shared_pages(SNP_GUEST_MSG_SIZE); - if (!snp_dev->request) - goto e_free_secret_resp; - - snp_dev->response = alloc_shared_pages(SNP_GUEST_MSG_SIZE); - if (!snp_dev->response) - goto e_free_request; - - /* Initialize the input addresses for guest request */ - snp_dev->input.req_gpa = __pa(snp_dev->request); - snp_dev->input.resp_gpa = __pa(snp_dev->response); - - ret = -EIO; - snp_dev->ctx = snp_init_crypto(snp_dev); - if (!snp_dev->ctx) { - pr_err("SNP crypto context initialization failed\n"); - goto e_free_response; - } - + /* Place holder function to be removed after code movement */ return 0; - -e_free_response: - free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg)); -e_free_request: - free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg)); -e_free_secret_resp: - kfree(snp_dev->secret_response); -e_free_secret_req: - kfree(snp_dev->secret_request); -e_unmap: - iounmap(snp_dev->secrets); - - return ret; } static void snp_guest_messaging_exit(struct snp_guest_dev *snp_dev) { - if (!snp_dev) - return; - - kfree(snp_dev->ctx); - free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg)); - free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg)); - kfree(snp_dev->secret_response); - kfree(snp_dev->secret_request); - iounmap(snp_dev->secrets); + /* Place holder function to be removed after code movement */ + return; } static int __init sev_guest_probe(struct platform_device *pdev) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 1d7122a1883e..97814cccf0e8 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1544,6 +1544,7 @@ config AMD_MEM_ENCRYPT select ARCH_HAS_CC_PLATFORM select X86_MEM_ENCRYPT select UNACCEPTED_MEMORY + select CRYPTO_LIB_AESGCM help Say yes to enable support for the encryption of system memory. This requires an AMD processor that supports Secure Memory diff --git a/drivers/virt/coco/sev-guest/Kconfig b/drivers/virt/coco/sev-guest/Kconfig index 0b772bd921d8..a6405ab6c2c3 100644 --- a/drivers/virt/coco/sev-guest/Kconfig +++ b/drivers/virt/coco/sev-guest/Kconfig @@ -2,7 +2,6 @@ config SEV_GUEST tristate "AMD SEV Guest driver" default m depends on AMD_MEM_ENCRYPT - select CRYPTO_LIB_AESGCM select TSM_REPORTS help SEV-SNP firmware provides the guest a mechanism to communicate with From patchwork Fri May 31 04:30:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681119 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2076.outbound.protection.outlook.com [40.107.95.76]) (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 DE4007E0F4; Fri, 31 May 2024 04:33:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129998; cv=fail; b=RHuXOjckWI9u9O/4ftmzwyAYEE9/KKiPKkUKdd2XVElspkMRNE/LJIZPPVCdZM1nanLHTi71XIorQrUSx3QohQ8wNMXwKSDvHBKn0DkesA9iJLFfYd9QYf9KLUoowrq3vvtZyavnOqk4OTiqpHxfVq52CKn1ZVQVqVTTo03tExQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717129998; c=relaxed/simple; bh=OAZsYKVLJyhESfuvF8bUC/4sP3dAE6f67jHjEXBJ9sw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pZEL5bvipCnsWMD96Zmh35dKjEp3siqxaGUoVa0JAYYi/YvfXPFJIpdkRGZ1lyMZEIUZKjOFGUvALZNR4xr1Pqj0pCdT7k7dMI6qFVZIP19Vdxz+M0ezf9Za2Mfv+Kjl3zCeHCSa9Gd7pfCEQTCTfA8tMStjgnLXHMTc5rn/uyQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=RPEb3HO4; arc=fail smtp.client-ip=40.107.95.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="RPEb3HO4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A9zAyEoAZssjwxcnFIalwCYn4+nWqrbwmfNN/ipHFqQHtV0qM9vUarxPslsS4A4u8ayD1L8pTRh1nFqeqFXXyRlkId0GgZKN1NMb9HgBVHzZQlBEz/zqHRzhzk4UsotFgAMWfcmv1OCHPgjBLshpyLCUQXJfK3U9YcthSRFGqX0dQZPsM0jn99COgeOi82Hx9ptpAHHMy2M4FaqzA7GcFHxKO/f2y8VUeQiSRtAI50e5C5GBcNgv0AoUsMXySlm2LP5cBNoT/QMB1kPJe+H1Bk+MGh8v7+BljUWE1khoZmGeAMm8oR4G1loPc93LfUfRbbrQNM61yQlcEKpC5K8cRw== 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=jrWrAvvGDMCEgVNFIxyCbpBpZUIKNSAjMrWbRMFXB8U=; b=k1HtCSv04t0YL4HWudwvkQDK2uZNt3/Sy4gnvYeYBAlfmKpBYObaMFKM4RV3WOGxOMwElcVd65eo9V8sMewty6KEW0rzTtFbRylbMPMBm7/wHmkpLHE/hiWlSl3ooiOMQUDw3X9pYHYzi9FtxlIDnmOiAnrFNrwu+7fKl1VM15w3QkHstFkKbYBQ8XcRmXakEyQpCZhIdii7yvFc4WvZgulZNXk4/7Ai86xIAgSuNkn/Mk7ENczHSdmHtMmUZQfkec71KIYlazi144PLTPw27HHitiscCLjLRW3VuEl0r4XV1gmTjYlvgzylQGqxnCV66bUB86vYY0YB7FdQR3CwPg== 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=jrWrAvvGDMCEgVNFIxyCbpBpZUIKNSAjMrWbRMFXB8U=; b=RPEb3HO4Nsv+nDPNf+k5x1CS8aF6jECmEeYc446pJdPqUKWSuS7b2woYgKQmI3vR+HGxiJ/xsYf5JAVNIzf2r97KURt40AwiF/hQrRnRpyjfQqDerxlFujIHMAO1/K4kRXOUiARSBHP/5MKbUe8yCrXN1SVY9pIgRuKGTFpAYhg= Received: from DM6PR07CA0130.namprd07.prod.outlook.com (2603:10b6:5:330::22) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29; Fri, 31 May 2024 04:33:14 +0000 Received: from DS3PEPF000099DA.namprd04.prod.outlook.com (2603:10b6:5:330:cafe::52) by DM6PR07CA0130.outlook.office365.com (2603:10b6:5:330::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24 via Frontend Transport; Fri, 31 May 2024 04:33:14 +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 DS3PEPF000099DA.mail.protection.outlook.com (10.167.17.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:33:14 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:33:10 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 11/24] x86/sev: Replace dev_[err,alert] with pr_[err,alert] Date: Fri, 31 May 2024 10:00:25 +0530 Message-ID: <20240531043038.3370793-12-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099DA:EE_|DM6PR12MB4219:EE_ X-MS-Office365-Filtering-Correlation-Id: 2f078f8d-6056-4d21-93e0-08dc812ac976 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|376005|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: 05QY1tqWEYb3TYRND8QoyWIFz+CKBCbL9+F7nBoBe5gXm+GB2xZRqc4N9x+GNHnq16VWe4SaiJrYTL8hIiIMyyO1Z1ZKjeO66/3UZX1DKiqf3xCFU4NwI4gufwY9wGqsRQRDrEOIMMC8Md7twyaYGCi+wdzL6FCFCaUr4NhfJgTqPRA6lOxsHGIPp4fF4Nl0MbE1Gghpzg4Pnncx9Aov/9V2/oKgF4jBMGPBQDOvp3xyMmnKymopdJXFaiUAEe3lljsf1OUuBf4gvIEK0aFqsLaWob13nN1hwLWtfl9B9g0E7rq1b4fPMOcnIT55FbjdbIBBw8j0CitdW2ZzJdnKyTvbFuPx3RjzmX7CLhioIk5gfRLVPsi5wlXhkI0egpnnrbH3tC7QITCfSQyR/r9y/Pk1x3nwxxQtQ51KCdL06/B51GC+tHkajc8QOrZnkK8QmvEkYMz4j/TxrVGpMLBEYm8TLDj65q5tXLwK4JCDNE0DDzLR+XC8JDOHzm3rRAkaoFmh4HCDkkWejv2sD+u146PFL4MrdmHeiGRKdNwn8ebnEV8MT/P3MvEOdwUgx9O6Dq57ONf0sXAWy6oaptqtaNDX3vrol0hA4DGpgMQEMVfYZGI5lwV/56C733b6pq6zhEBZoE4FxrGmBhNxjaZLLKWAzRjUlVthvWzzn60+JKtqtKSAW/3/P5ITp4EqB2yicvkJYHGOUxF255IT8IkM3f0pi3+uxRWReCPWbB+1mIZZr2ywk8Mtlul9ROD0CAj/Xme3FPDtIpSOAGD852azc+VW7IsZEsIuWJMTbysvHjguYggGVd9ecO3lsgaTh80yyxvhd8WEWm+BllsweH/Sj6SmZjgAQTFAbmSan0jmG9Yh+Dx48kuNuTrY6E5O9enEZOkDoh6FNKFDytBezHSrjhPLYKPzKOst/2X55gbc3actUcmpjIq50vCBec05LKNCAFNgaxUkLfsCVCPQxSUFbxo9FX22OGmMIF99XxfGzBljysmfkGEuOh26xZPdzvLTf+Bp+V6rDkG4LvfD8g08BVDvcmUJ/b8WHwygeO2i7zqRtSryMoVRKAyb8SZhcU5zrftM4WJIG2LDJyAU1fMkb/sUt+JljD6SZmUTaIxtORtSfb8ORcEA0VlVgm1ezN8zvgqJQrIoWM4i3YTVm6QxUiydrdw37aMBocpbKzzFSRBMq2ubiVvNC6IOEwpxIj0bH1MXOTsXH1wdYpNrmWM9U6LuTca+pUY18sReIjQtJBj+tMC8WI81wfi2CUDxA+0CADuzIyMCkm7Dsa6SIEfOZPad8iAZd/3H4zEvmkGJLPZSM5IaFpkaUU9saxHk7MG0fGc2iN0fkELHZ+hy2LhfOI7IE0MPvw0TKZiY/TKnIH4= 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)(7416005)(1800799015)(376005)(36860700004)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:33:14.7587 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2f078f8d-6056-4d21-93e0-08dc812ac976 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: DS3PEPF000099DA.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Replace the dev_err/alert with pr_err/alert after the sev-guest driver movement. No functional change. Signed-off-by: Nikunj A Dadhania --- arch/x86/kernel/sev.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 329ae107da4a..c48fbc3ba186 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2352,7 +2352,7 @@ static void snp_disable_vmpck(struct snp_guest_dev *snp_dev) if (is_vmpck_empty(snp_dev)) return; - dev_alert(snp_dev->dev, "Disabling VMPCK%u to prevent IV reuse.\n", snp_dev->vmpck_id); + pr_alert("Disabling VMPCK%u to prevent IV reuse.\n", snp_dev->vmpck_id); memzero_explicit(key, VMPCK_KEY_LEN); } @@ -2372,7 +2372,7 @@ static u64 snp_get_msg_seqno(struct snp_guest_dev *snp_dev) * invalid number and will fail the message request. */ if (count >= UINT_MAX) { - dev_err(snp_dev->dev, "request message sequence counter overflow\n"); + pr_err("request message sequence counter overflow\n"); return 0; } @@ -2608,8 +2608,7 @@ static int __maybe_unused snp_send_guest_request(struct snp_guest_dev *snp_dev, rio->exitinfo2 == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN)) return rc; - dev_alert(snp_dev->dev, - "Detected error from ASP request. rc: %d, exitinfo2: 0x%llx\n", + pr_alert("Detected error from ASP request. rc: %d, exitinfo2: 0x%llx\n", rc, rio->exitinfo2); snp_disable_vmpck(snp_dev); return rc; @@ -2617,8 +2616,7 @@ static int __maybe_unused snp_send_guest_request(struct snp_guest_dev *snp_dev, rc = verify_and_dec_payload(snp_dev, req); if (rc) { - dev_alert(snp_dev->dev, "Detected unexpected decode failure from ASP. rc: %d\n", - rc); + pr_alert("Detected unexpected decode failure from ASP. rc: %d\n", rc); snp_disable_vmpck(snp_dev); return rc; } From patchwork Fri May 31 04:30:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681120 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2050.outbound.protection.outlook.com [40.107.237.50]) (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 03D5C26AF3; Fri, 31 May 2024 04:33:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130040; cv=fail; b=gDasfRqBiJQ5oSkbb9lbKwEvgTlCk2XpAojru4/hiBWntNwDug0x3ypqBpfUdfU2YmhDAZOiyuOSXv/k5HL08DF/c7yRIE1ami8xlCjvvdUHxThxiNA1dImLMN3nbQ6mM8Jl/w2nBOtq9HbdyKNbzilw/lO7ijHcu27yhoUht0E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130040; c=relaxed/simple; bh=ccu/iD6nItxY3BYgOpxo6AYx5fNxf7HvItDUSewofT0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s5KL+KoRnrm0ELRF2ZeLw2ypXtsT/F4oBfiQS12duSkB7C/E46HKWk/VkkiXEcJlXWHs4VZCSc9bm6gMsmJDsE75fB8B6N2uUJILUAXifvMp2sMAxO8JY+ndCr6N21HHSFT+5vxIvgc43r1OVjGfB7Q5wFsjJdK5mxkbu6F7qcU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=ztUaIbIr; arc=fail smtp.client-ip=40.107.237.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="ztUaIbIr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TAVSGuqMWPQSIRN9soXrCqrg5TMSnvxAHMgSHrH07lbfpL5sHoYaa7nTCuuvT9etSOWJz0reAI0Kq8rLRnPj7PBXXxKFvomQUcRPFNXj/dbBA80TV3NwdVA93A0L7A+ZCBzo6KtcSsRVvNqlr7V9rv/kSdVKldj9H9ToPkXqENbwPEZCy2z4S3o03p0RNzQMuKUmt3U/KXRrwe1Fu3PLx4UiJsuOOPo2ITxShAzp11uBAoD1y732gTofQiKAB69PG/PVR+TqxjC4EwxiwqMXAS7R0D4igBtiXZRq/Vc3M/1/EjPj6QrcKbBcsudy5UySe5p5z1oZF1wktvbWyx59Hw== 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=8q10YdaCRaxRK67WXaizn8btLQ9ZFTUZ6u0E1DkQSys=; b=f3R62ZJYclKobxJ5d+sz7XecYq+Vm972CFXmNerfqF3mBQaU+PbbOykoJEZ8rB4UR9H0KJCZctV/M7sq37i/MBcZldd9jXA2MXG2mcqj97ddNBeCseGUbDcb0Vr8+JtJSKbb1meaSDyyQkBfYlyLyGJ+owxjQPPBrtM2/a6GMN6DQTOK56w5AwFm7y75yJLUJg/i7najqEb0+cc+gxV26GRtVDWdraUYjjCQ+4TgOobvg11DblkywTuP/+D3b+mBsHOpH7DeNnAGZoIXUsFDTGWBY58VcJusSYyN4ptIyuSSy/PgDoY6D1WgDLU20HtYHPHG8GKWJj2LdZh6xqWFMA== 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=8q10YdaCRaxRK67WXaizn8btLQ9ZFTUZ6u0E1DkQSys=; b=ztUaIbIrM+abbltXo6HmTsT/s0gzU9OohYRv6CV/k5fx2YIfIxZUUSzqusLD3gkl6GFOKpWZ7NpOooHDx487/qLvFNjqDDCT8yJuGf6OjNtwvIz6/qt+3l4CshrVpiUPpmwu4SiqHqPDujA0jgzH9DgAVVadaG5Moemopxbjd+w= Received: from DM6PR08CA0057.namprd08.prod.outlook.com (2603:10b6:5:1e0::31) by CY5PR12MB6228.namprd12.prod.outlook.com (2603:10b6:930:20::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36; Fri, 31 May 2024 04:33:56 +0000 Received: from DS3PEPF000099D7.namprd04.prod.outlook.com (2603:10b6:5:1e0:cafe::6f) by DM6PR08CA0057.outlook.office365.com (2603:10b6:5:1e0::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.23 via Frontend Transport; Fri, 31 May 2024 04:33:56 +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 DS3PEPF000099D7.mail.protection.outlook.com (10.167.17.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:33:55 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:33:14 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 12/24] x86/sev: Make snp_issue_guest_request() static Date: Fri, 31 May 2024 10:00:26 +0530 Message-ID: <20240531043038.3370793-13-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D7:EE_|CY5PR12MB6228:EE_ X-MS-Office365-Filtering-Correlation-Id: 6019402b-64dd-4896-82a0-08dc812ae20c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|376005|7416005|1800799015|36860700004; X-Microsoft-Antispam-Message-Info: SJPOiMzZV7qilS46OZraeknWN8Zh4+C/jyUFrUEVCW4SxWiTZ2Jm1Hkf6h2lD81l5/fSLZE+rXl0GfgZGZ3MHweICxUJVk3jZjdQoioTI0i6BFRHN5LyljbKOlnIot4PwGtqiR2m8rArJEzyXOir7/ahqo93xpqdMGjr+wKKFDPcfxXP5MqrIRhNSEx8S8jSFoGjJNwbH6+TuKNvfKjlxf/fPoaImBnJ8Z1h+Xw5oFgiCjqhxU/1ftFzqR9UwE9qwcqkx2Tx3not1BkS3AaA6db8uvvtzF07tZ9oHVlYnu0RKHVpJJzs8/TZP2v+u7eW+smofTQBQtquR4SbxuRRCMeMdUG9dH+dmZiaQu+36GC/b4BI6/Y00xmY6vWe2AaA3uInAFqo2osUeDG0uaaa4n3IcRg/YiBrEA35qNVOC4ghp/0RHRrjqWMhYOEPItAHOYWI1Tx2UdVuZl6ClAsNcIseSL+wdHghkisrhjm9cTCqt1rxgXKfsiDsouzTMh2coySx5q8slj+e8XvzVwjAdIfON94wN2mGVBkRuTSYH2K8iHhnVTxqhlEZTSbSinNidsLCldb6VzLx7dJ/cXpPmwaqLXiUSF7MQR24Mbzd5MeR+9ndXETZjcmdqbfYY72zPGEWjmoYSYt5dOSS67Uf54f738hIJANR/fflpF6K/40OXDpwfVnvx9Z7POFxn9VUtR3qUMmC3BirVqOiAvTMzuB2KDGWXiZdPbFlVGyZUNsDR8ilrZuI0/bBrX9PXp+Ok23zwoGoCNxvrSg8lex1PoknH/3/dUSls+JVoWR184gsB8RwtRH//MF79KcWhbOIZRkvFTFWEaHk25UIlgAaN2JPjGFhQndqUtVbUnW8jHHLw6x/6Qv35ldOoh184t2rJOr6e75Xq8Ihz0SNtOeKFlKhIJRPYDUWQGPCyUlPZudVS7KQPWfEVaWfP9m3bHQpxo1IVUlOwvt94tZsERckNIdHcwZpDB0Crp8vQfZW7CfckqxOENnxCTwxR30K6IqACBARPM8SRTvAC0YKhzekWPAN4UtYoCHHuwHWCPP9raGzz7ZSyrMtwf36G01j8sOA3tbujKCZNvTbUVf9GzzDEEbkj0GV6iDZdDMK3Z2cVeUyQUtXUc8wb+lJg/W/WkuFPS/IIvd18aMGZcjecBVCOcrnwyST0XTNPfFZgvzqNfkLaSvuwLM5U2LebPO8R6ETXjItrgxVbarRLAYal3N2FDj4B3QxvnpyUWYvGs6KmSE4i4tatWiser5GzzLCL2dONaIMUINYQ1F8MgGZUHzYIleCb8MdPf8xSw0V9f9BcRmx7/SivjvNmJ/ahu4bGTvYwt24uffAohPjzbrKsk6TkuAxLzDTg3tQYQCjr+GzOajDyPJ2qQF4jzVjBC+cFTjZ 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)(82310400017)(376005)(7416005)(1800799015)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:33:55.9910 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6019402b-64dd-4896-82a0-08dc812ae20c 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: DS3PEPF000099D7.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6228 As there is no external caller for snp_issue_guest_request() anymore, make it static and drop the prototype from the header. No functional change. Signed-off-by: Nikunj A Dadhania --- arch/x86/include/asm/sev.h | 8 -------- arch/x86/kernel/sev.c | 3 +-- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 9c5bd8063491..109185daff2c 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -318,8 +318,6 @@ void snp_set_wakeup_secondary_cpu(void); bool snp_init(struct boot_params *bp); void __noreturn snp_abort(void); void snp_dmi_setup(void); -int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data *input, - struct snp_guest_request_ioctl *rio); void snp_accept_memory(phys_addr_t start, phys_addr_t end); u64 snp_get_unsupported_features(u64 status); u64 sev_get_status(void); @@ -382,12 +380,6 @@ static inline void snp_set_wakeup_secondary_cpu(void) { } static inline bool snp_init(struct boot_params *bp) { return false; } static inline void snp_abort(void) { } static inline void snp_dmi_setup(void) { } -static inline int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data *input, - struct snp_guest_request_ioctl *rio) -{ - return -ENOTTY; -} - static inline void snp_accept_memory(phys_addr_t start, phys_addr_t end) { } static inline u64 snp_get_unsupported_features(u64 status) { return 0; } static inline u64 sev_get_status(void) { return 0; } diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index c48fbc3ba186..c2508809d4e2 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2192,7 +2192,7 @@ static int __init init_sev_config(char *str) } __setup("sev=", init_sev_config); -int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data *input, +static int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data *input, struct snp_guest_request_ioctl *rio) { struct ghcb_state state; @@ -2255,7 +2255,6 @@ int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data *inpu return ret; } -EXPORT_SYMBOL_GPL(snp_issue_guest_request); static struct platform_device sev_guest_device = { .name = "sev-guest", From patchwork Fri May 31 04:30:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681121 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2073.outbound.protection.outlook.com [40.107.244.73]) (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 1856D7C082; Fri, 31 May 2024 04:34:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130043; cv=fail; b=QDtCobIftYt7i+XTwGOStAO3QSz9wHUii5GnmXVkOfi+g6aWWsfvChZVkigd3ndbdhmYcIqtEBhp6j4gZW7WgEWDRSnba/r9+yJj+gmAFN6VgA540wV6sd1B0MZQS5MKa5yaSX3nxXJyYf1lMFdCKnILRdS9G6Ymdhifkbkdi/M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130043; c=relaxed/simple; bh=7iOy7jEbugZeh6Ep2WThL3qqnqUlAsRqtvU2TByY3js=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kWSGxDOzBzocFT0EQOJpBdh+9mwLiFVTkGdKVXIFvEU6ZlL7S6haCW5FvPNXSdutE/C6411I5Dhtj8UKEAX/hwuvoNp8eJ93DduuXwlHvXRw+DQIgVKwWUHFH9MFJLD79jGxOBCf9damxUOUJQcf6C4I/h0gvosK35u1Agnd1SE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=le7UidrR; arc=fail smtp.client-ip=40.107.244.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="le7UidrR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m4fY9K7nZgQZHEjL2WYIj9wWfq5C8xFqjOg3QiajNxBEV2DwLyhFQ5t0Dwb8iiVCFdA4ClhKA7UbDNVLriw7ZSxXHmiiJbUTbvRG6Kr92suRPICu/H8QHKHisnZK9ayvuJdM88JH08swpOuOP39QaIOt7DY2cMTTOB9L/zStm+vjdlii+OZBH83/FjzWda/o1gmqOG/+OhN3kRDyzITZjijPrBeZzv6Q6Jf3FfY9F68gZ+bEaSYbygXr1LdAhS3UNn5YwwrkkXtgVY2MMijaRlOwGe/6A5aXgtydfPeZ9QfpEwsDXaTcZoIEuu1+tyIYl6rzUNw0r7kN/1laTkSoLA== 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=JeUBT5NwoaLYVjepKfRfq5f4ozzVbIJrikYohYDTCsY=; b=GguOjc7IgWwhj/UY9v7NAOh6On+BTAxRZDCBtiUndXbtpPntvyvhiUhSPN1JthWzCcUG6Ctekz9GOckOCunWmjg4ihQ2QG+Wkknxl4f7JIGxYpomJE//3FvbWSkueERMLo/yMGg5mkO2Sn1SZPQ3JGKpBD5EBIWRRjXMCHU8BBiuTHvbZSblWd57dVMtFYLRvZS0xtOlJOeJe+dvfNoyjqK1yV8oPcamZDLGDvgqGn/Ml7uuw4da+tTipdFE8GJcRnMCP2cDoIZvvrMMHOwsopy1IRpW5b2vRm/c7jekICmbjiPBs+32ji6rYELao2oXjbYY2XqRhZElMF926EGobg== 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=JeUBT5NwoaLYVjepKfRfq5f4ozzVbIJrikYohYDTCsY=; b=le7UidrRcWP08kgM93nxvumFwbV01E028Vx0k+OJ4BopK8Ib//i7qplc7Q1W2kDfyEHmKEZVFXcC47JYIrRUV0kJU5IFlCAzspN0GmnP0Uqdni/GMhuyH5OCAfqoWFXGvshK+ahu5joI9VAUHgzZwfIjdXcdtYJBGVSOZxE0tbQ= Received: from DM6PR08CA0049.namprd08.prod.outlook.com (2603:10b6:5:1e0::23) by PH7PR12MB8825.namprd12.prod.outlook.com (2603:10b6:510:26a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.34; Fri, 31 May 2024 04:33:57 +0000 Received: from DS3PEPF000099D7.namprd04.prod.outlook.com (2603:10b6:5:1e0:cafe::a8) by DM6PR08CA0049.outlook.office365.com (2603:10b6:5:1e0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24 via Frontend Transport; Fri, 31 May 2024 04:33:56 +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 DS3PEPF000099D7.mail.protection.outlook.com (10.167.17.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:33:56 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:33:52 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 13/24] x86/sev: Make sev-guest driver functional again Date: Fri, 31 May 2024 10:00:27 +0530 Message-ID: <20240531043038.3370793-14-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D7:EE_|PH7PR12MB8825:EE_ X-MS-Office365-Filtering-Correlation-Id: 92abd6ca-7cab-4a75-b83f-08dc812ae283 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|82310400017|7416005|376005|36860700004; X-Microsoft-Antispam-Message-Info: vDvCb6wUFh2nocAZSh2Xs6/rUuIL2VTabL2wAzORilmqSbc+QwctX3YSETXa3zulU9NYaGEcg55wuKV8VgbOU8bRldIlhlG2FA+hS6uE6RrYztpgWzOyARXWkSBlZpmfq3h1+OScorz9hdcdrZvzgKnl7jkaRqVIDu54WEeUwV9/tyl5oHXCYBLMlt8nzc/VD9kN5Zh0F/s9Wggbxo3EePdH19lF2z+GX40ivOYtzfUH5QKJpfKlHKt6ZBAqHcIkTirYalJ7NvFllYMrj9ncZ4wgmyIYIqCeEsX6RyBnNcGiiwdc6hlFcSfygX4le/JJj2jWSjh+YEXsj1t5XiX5TlDq83kCt3Z56GF92X3N8NMH6MgQLUnlBVVBQlhHHFE0cK3oyDHflyU7ZU2JeeLcsH+KT7LCsBo0N7z253lmJ2lfGwdSqfFXRSsmakVMkvgDsfdtEC64qzuIUGULee27507YQRmfOg7V4ErfNuocrCJZlqeKExeAQDcResyf0YRuXkOAcX4g+JcHM0t8uEtxCsOCbhbOzaMK8xAvP5dvzdI8sWzv2BBAp4j7Y9fi12uEimkQUP4xE93SMiYq4qsFHLHf+HmS8WDkzkfWA7y7I++0w5VLb3by+M3HX5XlWwH+op0WyWDuHjs8TLZergzk6Aqn+5ycUBRhzRhiMQyOBYiPV0lbbxxFaqCfV3cXapfqBSs007Fi7Qssr4A/TkeMMNt3iK+yIh4LgVKm7IvDnnJUM65l4qqsBBRAQm3+PppPCK5UHwLfdNvifJY6czJyJ4l6ANAcpcbzqAIIcP42jkRp1hfJF5QOq+gfq6959Dpig7CURuQWIN0Alz/D5faP4o+ZItsbxeWqwLr1N5FxVQPCadx+JMjiluvApdGgvXM+5Scr0mYk5/Id7Nm0QDd0a0muKvtUd7iEzYj03fXKxRdLt/i3/gliENDz4lseQ6kMDVBpZFjdY5DfK7SfgbBKn1XeHrRS53UjvG5ic2FsL0mM1FRXVMMygfKVVx6OklplJWetx5S4z4eIgM82uZdSOS8XKzQ6czEjhijycHGp3tejME4g1FDu6LU67qvWVmog+1Vw60wgsGQmfeeK6dlfUXNs1MwSFGwgZlxplibaQAjZKtRs/E5Lh4F8Vi7Rp8xiuI4mL7QWqvON1inrivVkneYG0Th9h3dXnkjzdCeG3soxW1Sh5mq/sM3rMipWhwc3ZlbAG8vJQsbnjnbGQ+Zr3kD/J89UxPjSk1/vVLb9XKfpyrOKVZzPJY9bjJSXwdymWV5Uaomke856oZFNqy22veGUu0mhwEvHR/lAcE/xP12HXlqG+wiIV0iQ+QL/H9CpsITrq455yvT7FLRjglywu4gzvyjSgdX4+scctfc/RQ0= 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)(1800799015)(82310400017)(7416005)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:33:56.7879 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 92abd6ca-7cab-4a75-b83f-08dc812ae283 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: DS3PEPF000099D7.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8825 After the pure mechanical code movement of core SEV guest driver routines, SEV guest driver is not yet functional. Export SNP guest messaging APIs for the sev-guest driver. Drop the stubbed routines in sev-guest driver and use the newly exported APIs Signed-off-by: Nikunj A Dadhania --- arch/x86/include/asm/sev.h | 14 ++++++++++ arch/x86/kernel/sev.c | 23 +++++++++------ drivers/virt/coco/sev-guest/sev-guest.c | 37 ++----------------------- 3 files changed, 31 insertions(+), 43 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 109185daff2c..f58052fd6cb3 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -322,6 +322,12 @@ void snp_accept_memory(phys_addr_t start, phys_addr_t end); u64 snp_get_unsupported_features(u64 status); u64 sev_get_status(void); void sev_show_status(void); +bool snp_assign_vmpck(struct snp_guest_dev *snp_dev, unsigned int vmpck_id); +bool snp_is_vmpck_empty(struct snp_guest_dev *snp_dev); +int snp_guest_messaging_init(struct snp_guest_dev *snp_dev, u64 secrets_gpa); +void snp_guest_messaging_exit(struct snp_guest_dev *snp_dev); +int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, + struct snp_guest_request_ioctl *rio); static inline void free_shared_pages(void *buf, size_t sz) { @@ -384,6 +390,14 @@ static inline void snp_accept_memory(phys_addr_t start, phys_addr_t end) { } static inline u64 snp_get_unsupported_features(u64 status) { return 0; } static inline u64 sev_get_status(void) { return 0; } static inline void sev_show_status(void) { } +static inline bool snp_assign_vmpck(struct snp_guest_dev *snp_dev, + unsigned int vmpck_id) { return false; } +static inline bool snp_is_vmpck_empty(struct snp_guest_dev *snp_dev) { return true; } +static inline int +snp_guest_messaging_init(struct snp_guest_dev *snp_dev, u64 secrets_gpa) { return -EINVAL; } +static inline void snp_guest_messaging_exit(struct snp_guest_dev *snp_dev) { } +static inline int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, + struct snp_guest_request_ioctl *rio) { return -EINVAL; } static inline void free_shared_pages(void *buf, size_t sz) { } static inline void *alloc_shared_pages(size_t sz) { return NULL; } #endif diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index c2508809d4e2..878575b05b2d 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2309,7 +2309,7 @@ static inline u8 *get_vmpck(struct snp_guest_dev *snp_dev) return snp_dev->secrets->vmpck[snp_dev->vmpck_id]; } -static bool __maybe_unused assign_vmpck(struct snp_guest_dev *dev, unsigned int vmpck_id) +bool snp_assign_vmpck(struct snp_guest_dev *dev, unsigned int vmpck_id) { if ((vmpck_id + 1) > VMPCK_MAX_NUM) return false; @@ -2318,14 +2318,16 @@ static bool __maybe_unused assign_vmpck(struct snp_guest_dev *dev, unsigned int return true; } +EXPORT_SYMBOL_GPL(snp_assign_vmpck); -static bool is_vmpck_empty(struct snp_guest_dev *snp_dev) +bool snp_is_vmpck_empty(struct snp_guest_dev *snp_dev) { char zero_key[VMPCK_KEY_LEN] = {0}; u8 *key = get_vmpck(snp_dev); return !memcmp(key, zero_key, VMPCK_KEY_LEN); } +EXPORT_SYMBOL_GPL(snp_is_vmpck_empty); /* * If an error is received from the host or AMD Secure Processor (ASP) there @@ -2348,7 +2350,7 @@ static void snp_disable_vmpck(struct snp_guest_dev *snp_dev) { u8 *key = get_vmpck(snp_dev); - if (is_vmpck_empty(snp_dev)) + if (snp_is_vmpck_empty(snp_dev)) return; pr_alert("Disabling VMPCK%u to prevent IV reuse.\n", snp_dev->vmpck_id); @@ -2392,7 +2394,7 @@ static struct aesgcm_ctx *snp_init_crypto(struct snp_guest_dev *snp_dev) struct aesgcm_ctx *ctx; u8 *key; - if (is_vmpck_empty(snp_dev)) { + if (snp_is_vmpck_empty(snp_dev)) { pr_err("VM communication key VMPCK%u is invalid\n", snp_dev->vmpck_id); return NULL; } @@ -2573,9 +2575,9 @@ static int __handle_guest_request(struct snp_guest_dev *snp_dev, struct snp_gues return rc; } -static int __maybe_unused snp_send_guest_request(struct snp_guest_dev *snp_dev, - struct snp_guest_req *req, - struct snp_guest_request_ioctl *rio) +int snp_send_guest_request(struct snp_guest_dev *snp_dev, + struct snp_guest_req *req, + struct snp_guest_request_ioctl *rio) { u64 seqno; int rc; @@ -2622,8 +2624,9 @@ static int __maybe_unused snp_send_guest_request(struct snp_guest_dev *snp_dev, return 0; } +EXPORT_SYMBOL_GPL(snp_send_guest_request); -static int __maybe_unused snp_guest_messaging_init(struct snp_guest_dev *snp_dev, u64 secrets_gpa) +int snp_guest_messaging_init(struct snp_guest_dev *snp_dev, u64 secrets_gpa) { int ret = -ENOMEM; @@ -2677,8 +2680,9 @@ static int __maybe_unused snp_guest_messaging_init(struct snp_guest_dev *snp_dev return ret; } +EXPORT_SYMBOL_GPL(snp_guest_messaging_init); -static void __maybe_unused snp_guest_messaging_exit(struct snp_guest_dev *snp_dev) +void snp_guest_messaging_exit(struct snp_guest_dev *snp_dev) { if (!snp_dev) return; @@ -2690,3 +2694,4 @@ static void __maybe_unused snp_guest_messaging_exit(struct snp_guest_dev *snp_de kfree(snp_dev->secret_request); iounmap(snp_dev->secrets); } +EXPORT_SYMBOL_GPL(snp_guest_messaging_exit); diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 567b3684eae5..41878bd968d5 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -34,12 +34,6 @@ static u32 vmpck_id; module_param(vmpck_id, uint, 0444); MODULE_PARM_DESC(vmpck_id, "The VMPCK ID to use when communicating with the PSP."); -static bool is_vmpck_empty(struct snp_guest_dev *snp_dev) -{ - /* Place holder function to be removed after code movement */ - return true; -} - static inline struct snp_guest_dev *to_snp_dev(struct file *file) { struct miscdevice *dev = file->private_data; @@ -47,13 +41,6 @@ static inline struct snp_guest_dev *to_snp_dev(struct file *file) return container_of(dev, struct snp_guest_dev, misc); } -static int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, - struct snp_guest_request_ioctl *rio) -{ - /* Place holder function to be removed after code movement */ - return -EIO; -} - struct snp_req_resp { sockptr_t req_data; sockptr_t resp_data; @@ -258,7 +245,7 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long return -EINVAL; /* Check if the VMPCK is not empty */ - if (is_vmpck_empty(snp_dev)) { + if (snp_is_vmpck_empty(snp_dev)) { dev_err_ratelimited(snp_dev->dev, "VMPCK is disabled\n"); return -ENOTTY; } @@ -295,12 +282,6 @@ static const struct file_operations snp_guest_fops = { .unlocked_ioctl = snp_guest_ioctl, }; -static bool assign_vmpck(struct snp_guest_dev *dev, unsigned int vmpck_id) -{ - /* Place holder function to be removed after code movement */ - return false; -} - struct snp_msg_report_resp_hdr { u32 status; u32 report_size; @@ -332,7 +313,7 @@ static int sev_report_new(struct tsm_report *report, void *data) return -ENOMEM; /* Check if the VMPCK is not empty */ - if (is_vmpck_empty(snp_dev)) { + if (snp_is_vmpck_empty(snp_dev)) { dev_err_ratelimited(snp_dev->dev, "VMPCK is disabled\n"); return -ENOTTY; } @@ -423,18 +404,6 @@ static void unregister_sev_tsm(void *data) tsm_unregister(&sev_tsm_ops); } -static int snp_guest_messaging_init(struct snp_guest_dev *snp_dev, u64 secrets_gpa) -{ - /* Place holder function to be removed after code movement */ - return 0; -} - -static void snp_guest_messaging_exit(struct snp_guest_dev *snp_dev) -{ - /* Place holder function to be removed after code movement */ - return; -} - static int __init sev_guest_probe(struct platform_device *pdev) { struct sev_guest_platform_data *data; @@ -456,7 +425,7 @@ static int __init sev_guest_probe(struct platform_device *pdev) return -ENOMEM; ret = -EINVAL; - if (!assign_vmpck(snp_dev, vmpck_id)) { + if (!snp_assign_vmpck(snp_dev, vmpck_id)) { dev_err(dev, "Invalid VMPCK%d communication key\n", vmpck_id); return ret; } From patchwork Fri May 31 04:30:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681122 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2075.outbound.protection.outlook.com [40.107.223.75]) (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 5DE617BB01; Fri, 31 May 2024 04:34:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130044; cv=fail; b=iS9D6Fylix9ZaHEgjd9ioltk0+FvwgfrJ5qmIbJG49QwoAE4NHzKUq1cibyqNHT5lNxtdtnIIKZ4TUTrZ8bA4ahQdFWg0nTdxSOPcLFfIKwQV+KhETBOkv3OII1rwErF78WTdraR3hp5LNKN/C+afJb6TutiDtwoWQQtcxv+WiE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130044; c=relaxed/simple; bh=5qSYz184dG55AgMt1KcS/YHhgJrEhgfTvgTTCjahzBo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TQZCggPXISwHsYHaml62Y/6iAsS5Uy9D1mfVucKyP0kn5C2XmpbwSDz6YjcomPAGCnCeoaC/KFX/1zfBfJSZzL6KcgimKjyc3Ssn34FyGUQPI6l3hL0kHzgA3S+dDinuS6BKS59CbqQJ7srMQYf/DhThReQZZT0IMFx0ZT+HO1w= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=z4o0+qUz; arc=fail smtp.client-ip=40.107.223.75 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="z4o0+qUz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iWIlg/+9SaMQM0244FC56ey/Q6YqLlmSSGHqeSvaWoh+akMrecvQzqJUkYgQwsFo2pK+pEpS6cOFakVKZp9CYBs6scxu4bLjWYxos6M8qSt/EZiKOJOOHYMwfsep7DEguG5g9mInetfxw/rIp7EeSAnjRKZ5llOaegDRS1W8uD+Enfoz/BGhEpXqnwdcP2tnJi+yISVc9FyN8oJ0qLuTFUN1/CIV94+ErNHkTjMUj/xTikKJmbXvKPXa6GcegTe9ic/YmN8u276c9iBoDKT9Z5bDvhmAmNiWHjUdM++87pYcPpFEzfcTmW6hu0fA8fSPR/HBIKMjPuEVrKI2lSXdTg== 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=dcHu6ihXJZRoVgQf2gK8G/BljboPy4aUZTH6uo1HfZM=; b=fi06Zkc6xInTWsVjC0nop/SdqBp3Yt/CVTSesqHWKKGjCXEvNYl12HT03KgplTFrTwW+z6vkOY4w09gCVwIyl+bq9QjHiWEQyRVwOVLKzcb9X0Z1mLCzcyj5CSPHMZaowGyi2k9JV+OJt08OAc4RHXh6BXCG50Kn4t4dgaOZ13kRZXN/h3JZFgwAJnq9/ztPgPL1uqZcMqG0XUDd/I4rDxRvGPpyq6dPJ6iV+aMPhb2qd++hY6d20h9lJMN0p6GW0jW60mS5kaBQtp+3OvL1Q2ibaZozaQWKipUvIH852bBPDemWcZ2U571/L9H+DlJg2RxvbD0S2h7Be9Kbav4IfQ== 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=dcHu6ihXJZRoVgQf2gK8G/BljboPy4aUZTH6uo1HfZM=; b=z4o0+qUzaibxsijnfj7Y4OZV9PChw8jbTeD8rKNl7zuBM+dUHwCZBZKDicAwjhWFMwI48IeZRR39Sb0qxo31UfW7bs7ud+W3PVXRL55E1eEWNPleZE3rx0cMRn19DTKg5WIndoNghQBA5N1vOJYXdOrLDdfu/Rmln9netWgQyLg= Received: from DM6PR02CA0155.namprd02.prod.outlook.com (2603:10b6:5:332::22) by SA1PR12MB6727.namprd12.prod.outlook.com (2603:10b6:806:256::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22; Fri, 31 May 2024 04:34:00 +0000 Received: from DS3PEPF000099D4.namprd04.prod.outlook.com (2603:10b6:5:332:cafe::e) by DM6PR02CA0155.outlook.office365.com (2603:10b6:5:332::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22 via Frontend Transport; Fri, 31 May 2024 04:34:00 +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 DS3PEPF000099D4.mail.protection.outlook.com (10.167.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:34:00 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:33:56 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 14/24] x86/sev: Handle failures from snp_init() Date: Fri, 31 May 2024 10:00:28 +0530 Message-ID: <20240531043038.3370793-15-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D4:EE_|SA1PR12MB6727:EE_ X-MS-Office365-Filtering-Correlation-Id: 659662a1-d348-4595-2fb9-08dc812ae48f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|376005|1800799015|36860700004|7416005; X-Microsoft-Antispam-Message-Info: TXFTJ2UsDgqUjfvPcTlelKNAcfVfe9o52+uw5FeM1+1MttIkZGZLEfjkSR3GoYF+24cR0jftruJNSAbBUZkNlIxLBbcBUHkr5y3qjitRTpXW0iMZw6IilIeiXHSb6oPYTLmYjiI+gf0pTd4knzgitC+fCy6f+RQ5QXFeleMijwo+8fCR5ugzQF+6NbKq5ZQHPVOefDVwUTFneSmFgQkZEHb8BT4yn0CrG9gXq/E1Lv7LmuSZ1OK8NzVGCGsRj9mkuiXqgbAaWYyFO47GcfzMKO3+keNqQVw9JxJZ3ND8XadV7eHU5y28Pg4hACNYCBpZhxFnvKEQuLTRDaIM1H6a9Jkw3sb9LdvQA9fickdICsci+wg8irv1pA2vdzIKeQ5nL8/guWm9gRFuIJLAo1kRqXWtW3fU8Lz5WMzsBBAThmoybuJkw+CsqQlpGaM5M/4EK5vt2CEDuxQbgoJ+0y8RMqE0SP7DLbO4QEfSA7qMLxh0/mZU2/fQIUstFgXfYEIJxXXB73/1YeRyA7QpTntAvu7gzNU78MOzWtnDcUMBJ7Jv/Yhp8Q0FgqXRfdlRYQW7pccYeYOWI5PHlW7A1+86riPUwemE+Bp3xoSKt/ncVwvo/8d+ZMAXgP7ovQsrI13TOFNgEijE8Q9fHmZ+0sD9Q3U9UuFaQ019//x+OefAPLUfF2vE5xkUIjRsaul+rWui2h018EEglbX8kRAHwg8CrFduJAuI5YIH1STPTVeTU5yV/okguKgYOvJ75gG1eAlX6ApewnL7xIgXE//eMSO7dFMk99VyQTrMni7S9p0HwFd2KcRJ2Eng7GpDWhIl203vLNJR0GCPvpGraHcv75kZPtF0swsJBkM5j9nc19jBVzds8yStQxnQsBFmt4VCBxpQ6dcvuJU2B7o+RoFJZxwZUNbgHDWtCC81UkSzju34ugNvOewmBkRbO9t24G8KZrcOQxT44kLiGNO/VQeqV94+DwdA1HoLBdQYCnB8TMH8gGNCcTUxhB3kB2ELdj3rl710VJmXtHa3mXJG19HICSz3Ggj5zDc8iKJcMJBYJDh2M+At1JYyzMTh+pjLjBbWh2gcT280kSIJyqnwMlrGrOZ1ShKpnNBEZk8Di2vi3Imzo1a0gxB9Tl7iXvQR5qdUiUGa9Vm2H+LnvEOm8XWECIXF+350Ksa/f6s9XMfGZmQtM9i806Eokz7kbKE91o05kcslPyNi3JEffewa3cK9xkFotKiRp1Aoqm9qmV8D3qmhZAlxHdC6sKm8i+uJH0cd/JVoXmJlm7n1spHqIO8rOS6I8YI18/PXGeF4KQR9UwkZoZl4yxDKtIgFZC2s35Mz4uiAHNGTYKkFPiS7Ri9JdVJjcgnzXLBP3LFoLfW0FwmnTEBaBai0YEuvXtp0+svatj0L 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)(82310400017)(376005)(1800799015)(36860700004)(7416005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:34:00.2185 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 659662a1-d348-4595-2fb9-08dc812ae48f 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: DS3PEPF000099D4.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6727 Failures from the snp_init() are currently being ignored by sme_enable(). Add missing error handling for cases where snp_init() fails to retrieve SEV-SNP CC blob or encounters issues while parsing CC blob. SNP guests will error out early with this change. Signed-off-by: Nikunj A Dadhania --- arch/x86/mm/mem_encrypt_identity.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c index ac33b2263a43..e83b363c5e68 100644 --- a/arch/x86/mm/mem_encrypt_identity.c +++ b/arch/x86/mm/mem_encrypt_identity.c @@ -535,6 +535,13 @@ void __head sme_enable(struct boot_params *bp) if (snp && !(msr & MSR_AMD64_SEV_SNP_ENABLED)) snp_abort(); + /* + * The SEV-SNP CC blob should be present and parsing CC blob should + * succeed when SEV-SNP is enabled. + */ + if (!snp && (msr & MSR_AMD64_SEV_SNP_ENABLED)) + snp_abort(); + /* Check if memory encryption is enabled */ if (feature_mask == AMD_SME_BIT) { if (!(bp->hdr.xloadflags & XLF_MEM_ENCRYPTION)) From patchwork Fri May 31 04:30:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681123 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2057.outbound.protection.outlook.com [40.107.237.57]) (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 D00FF2135B; Fri, 31 May 2024 04:34:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130075; cv=fail; b=m0jrfe+FssqvlyHykFqcolLFpgmrmZaQwtDXcOH1cYmB6VrjcFtwTkk7Cd35jYlhK2phIt93JXNddeblgjC6a6PuX8A36cYTPUad/k40h2gf8yl0dBs9MUux1BH7yBL65KgS6zEfPHSh3Gd6qW2AjK77X04igeR1wLIPoYLsb88= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130075; c=relaxed/simple; bh=7RatBNCnIbDRhEKO1UiiuqJEpLxL39hIQkT7wV0TAJw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QKJZUoNn9Kj4qfLC5ZRRqgf9k2OEQyIf2iZjReagK2ZaLwMLyOINC54hSoPz11/3HAnc14ZNP/PfHmYaVbylDgZ/cy7PTcocdfd+DNE4pXw88C2PBTPpxUbaGapSo31yUvYklJYjaLGeJJt8iyMJDzYegmtwG0Hz6NRIMklU0cc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=gogVyGb+; arc=fail smtp.client-ip=40.107.237.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="gogVyGb+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j37lGsRfELBG8p5AIOwFGecRoEI7qnR46YIothLtZBSrnhwvDRRybS3MaAhD5MODKCqbqL+wgAkKUXkCbTpfzc8J3dRYeSPM/g+PXGAxSefu/y6uN8wKAkN92b1TJ5HHL2wqewMM40vC5rQ4Sf9Y87N1kS744gKMoFwVo46fpVLvWVAEFrIZS3DB4rOTCgv80WipnAZh9amD8uAq2ISmTymFeDUZjFli1cg0PEZgVa/zI+fKwxrH0qyU2DzjHSNLdc27wfYmQ2ZR0KOb8SK5YJePEPPICfsVYFzKFZheNvA6xx8BRf+oqaaozeolV/mfx0BrPkCrtVEdnhvKLdJTcg== 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=8FW1kVb2HUuaBogO5Iihlfq+YjSLq/wBGzEKbi3itwQ=; b=ZQJiD3NLjQwOFlljMeNZm1Nb6HkO/k81h9aHMSmlsF+sSaMheG9uNjWw9qjeC/j1L35IkM8E13xdovW01CMTkYWzR8mTPniSGZNbED1K0I0xJjI2keo1ku8Zjnx7AvWbQ01wuaLFDRSmlajhhJCgDaezzHlUOTLN7zc3p7DZ3ia10AXGmCkOQhz45klEY/1ZmwWRbWHv46OVoR9XdprrVOXmJ7ecH3hc4monhYDFgYo1mS/UhfLDewJaO5LYAso57h870KAoR0uxxVib43blXNEyLsMg4bjPMuO2wxxXvRFdHmjvrJTSCzv+H7g3txu365+B0smRfBBVQSlEVBcJEw== 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=8FW1kVb2HUuaBogO5Iihlfq+YjSLq/wBGzEKbi3itwQ=; b=gogVyGb+x7v31ArH5MSBHXy1u1EhlQ4VlI0/RYGcuI4FPISzOjpc7dReCzkSeuvhhXlLmCxOGFg3QZLJ2vsehKwiBVrJsYLYLTP8j/S6mKNNuokt15wNQropcYaAHmSd+ieq0hqNWK8fbjBDC3fj1QT70/ieDw1ljdQfIM0RLII= Received: from CH2PR07CA0058.namprd07.prod.outlook.com (2603:10b6:610:5b::32) by DM6PR12MB4042.namprd12.prod.outlook.com (2603:10b6:5:215::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22; Fri, 31 May 2024 04:34:29 +0000 Received: from DS3PEPF000099D8.namprd04.prod.outlook.com (2603:10b6:610:5b:cafe::21) by CH2PR07CA0058.outlook.office365.com (2603:10b6:610:5b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.28 via Frontend Transport; Fri, 31 May 2024 04:34:29 +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 DS3PEPF000099D8.mail.protection.outlook.com (10.167.17.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:34:03 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:33:59 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 15/24] x86/sev: Cache the secrets page address Date: Fri, 31 May 2024 10:00:29 +0530 Message-ID: <20240531043038.3370793-16-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D8:EE_|DM6PR12MB4042:EE_ X-MS-Office365-Filtering-Correlation-Id: da6abbc3-0884-434c-82c0-08dc812af5e2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|376005|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: 2Kq+m/pCm2g3gkTQpcTIhbARQ5ZWSVIW6OFWVSHbrJTO8A4zCr/yoh+s+RUAnDOvLr2yCn8QdN3ytKaAyoReN8TQ1rWyQipAgSPPuQMkoHaTCqtHfXOjDaTamT20LS27+iSMjGORqrifjq5jRte3zjbvPQj5qg4qQueYKccDkRBdleS8JWWsJc7uZr0UDy0BycEeDqjSSnhDMwbvG9NTtcjVHC6pimwe+6sQGiwSn/V5gzwlV1HmwXcbnfusTob0uVpqq0MrhUpsHFKOmNW0Li3Mk83BMTjG9Za+zAZrGhBQr4THFy+bUDT2QtwRcZd9zbg25ibe3hTDyN0HdzHcM2K7NafscolYsYBEKt52q9rnpca4DCTFc2hUtpou4wzYtH6FlzUpzCDLAyL0iE3Hd3nvQvp14PuZ/EAcd/RQ0CPdRdd/4VAV261cfZhqZUin99kqKDBJMueu45tAtqlFG2drtDY0NzLpKmAKddCX/aojOzypdOSwVShasWOA3xs3POw4ZaLXtO8EVKBs7oejKfnAGzlEwDjdXXF096zCrHbbCNVuSkJJQjZh7GjNlVg/IYJvte++8cMhAyd2HV3Vg0Fo7IddF0yGVbEd4O7QxLWw/Kf7Gf7AyDpr3wRldguKrNfI3O16nl95vMKlPruvzyAATouHewHglfyvqmhNrE58A2Ui7Mri+0nqiRemStZjG4ZU/uL/972KnJ3YNUlFcZH8dkDSz2uDZ/D+nFbMUlT1CDxp/AcFw2hlRuc0bNNhNpXnnAEQx0YoMufHXxdw3tFNENJrqO7E1hKjYFBkLwe2rn7BbQi2jVmvxtxdaXODYl+mIIV2HZSGzctSksZmB6v/Wvrj+HCZkrbP2QvC4JuCdxNc8To4TXidl+b4jC/83GfJkRUUg0d+cVyJZ7oChqFvcXs+DxqaAHISDalEs19UduHD/W4j0bxBcQ4/cLAe7gr1VujBAcU6pE5x6SHDtzjI1O9dAUrnCEjMAosRzN/7S8TLF0SqHwMnVI51sQ1lN9yJyDSPnoOhGP1mE4DAwI9t7tcpk2KIiHKcKtL6T1T7RIxks5o586JOG5P8ZSVWr8FVD3Jk2/NN9XbhDjxa5TuqmGKQlfwkXfXpSzoSId9klf4soL6eOfW2UY4xyTXY3b3rcZCl/vH73/4rVbQHAmsxm2cfIRsXkR+DtYBI52EO5ylIsKo7R7kwick/h3TJBQIOysKJqF1M/aalP1DDKyQt1l5+u8ZSHjTJq4jLZqmmuOyYaZTt/IRkg3FIVUPQpFGaG7flcNDz7apBm1Vi+8Taeen1U+sxQmO8uDs/zSenN5L1ow6rViOuTjD6LQ9LfJEZUTQ1phOhQreGBL+U1QdgdTdiFVPHZBOQ0vPerKNmLdmuUiz469O1QHav8xs+ 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)(7416005)(1800799015)(376005)(36860700004)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:34:03.8952 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da6abbc3-0884-434c-82c0-08dc812af5e2 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: DS3PEPF000099D8.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4042 Instead of calling get_secrets_page() that parses the CC blob every time for getting the secrets page physical address(secrets_pa), save the secrets page physical address during snp_init() from the CC blob. Now that there are no users of get_secrets_page() drop the function. Signed-off-by: Nikunj A Dadhania --- arch/x86/kernel/sev.c | 51 ++++++++++--------------------------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 878575b05b2d..141a670d2a85 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -93,6 +93,9 @@ static struct ghcb *boot_ghcb __section(".data"); /* Bitmap of SEV features supported by the hypervisor */ static u64 sev_hv_features __ro_after_init; +/* Secrets page physical address from the CC blob */ +static u64 secrets_pa __ro_after_init; + /* #VC handler runtime per-CPU data */ struct sev_es_runtime_data { struct ghcb ghcb_page; @@ -619,45 +622,13 @@ void noinstr __sev_es_nmi_complete(void) __sev_put_ghcb(&state); } -static u64 __init get_secrets_page(void) -{ - u64 pa_data = boot_params.cc_blob_address; - struct cc_blob_sev_info info; - void *map; - - /* - * The CC blob contains the address of the secrets page, check if the - * blob is present. - */ - if (!pa_data) - return 0; - - map = early_memremap(pa_data, sizeof(info)); - if (!map) { - pr_err("Unable to locate SNP secrets page: failed to map the Confidential Computing blob.\n"); - return 0; - } - memcpy(&info, map, sizeof(info)); - early_memunmap(map, sizeof(info)); - - /* smoke-test the secrets page passed */ - if (!info.secrets_phys || info.secrets_len != PAGE_SIZE) - return 0; - - return info.secrets_phys; -} - static u64 __init get_snp_jump_table_addr(void) { struct snp_secrets_page *secrets; void __iomem *mem; - u64 pa, addr; - - pa = get_secrets_page(); - if (!pa) - return 0; + u64 addr; - mem = ioremap_encrypted(pa, PAGE_SIZE); + mem = ioremap_encrypted(secrets_pa, PAGE_SIZE); if (!mem) { pr_err("Unable to locate AP jump table address: failed to map the SNP secrets page.\n"); return 0; @@ -2107,6 +2078,11 @@ bool __head snp_init(struct boot_params *bp) if (!cc_info) return false; + if (cc_info->secrets_phys && cc_info->secrets_len == PAGE_SIZE) + secrets_pa = cc_info->secrets_phys; + else + return false; + setup_cpuid_table(cc_info); /* @@ -2264,16 +2240,11 @@ static struct platform_device sev_guest_device = { static int __init snp_init_platform_device(void) { struct sev_guest_platform_data data; - u64 gpa; if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) return -ENODEV; - gpa = get_secrets_page(); - if (!gpa) - return -ENODEV; - - data.secrets_gpa = gpa; + data.secrets_gpa = secrets_pa; if (platform_device_add_data(&sev_guest_device, &data, sizeof(data))) return -ENODEV; From patchwork Fri May 31 04:30:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681124 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2066.outbound.protection.outlook.com [40.107.244.66]) (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 08A9781730; Fri, 31 May 2024 04:34:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130078; cv=fail; b=fx2QaxYAL1rTbAt7ix6FoejcIFvzM9C3gTt16vdBRnc/82IXb5adIVXJsQkCdfmvSXswpQfBaWYhYr2+7NOZdisW+1blrAXOsAaisAaOX6x36fe/YnsB4bDbrzaJxtrEOK5NiiFXOncWAtjadhlUYdjhIjk1FjlfITfo4AeTRiA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130078; c=relaxed/simple; bh=cQGOlved0tQmJKoUYAdNx2BMn1EbWhqcNlTE0N0mVI0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BSj/ZwQtXymEBQf5zdX6nn74WL/MpwU6ElYibcbK+Y5Ue7ZLE3Ybm53E1N6C6ZZhnUWj/6JrJucDjedfMpK1pafhHxJAUt4nuE8IUpv4JRTIKgbS+E5Sn75qUrh8dIVsMr9+1yJqYlSTAL2LCPaPNQ5+PLwXfCRX0W9kwzn7Hzg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=D4YyPTRV; arc=fail smtp.client-ip=40.107.244.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="D4YyPTRV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bM20h0yyZvmvhiI44rp215zV/6JOBKZgooCCHPnwuM1qEo/kxNvWQEjOuVJHdtH+JFUHWOujY90I6yFBGan9arvryE9XOVOvNCaZtc0478XNXe8WoQswklnnz0CSaJsQgJ/8vXbnO21P6XgyB2RgIzu/Jk2jpQkrGnWT05LeLaF2TKsjqK9A1DBZAv39wwKCE1DAxxmIFfktnb6YTP5+ny/ru7GJSEVRK6Q1bUqPIJSVc1ogTXViwBx5dola3FZ0K5KvEyyRiODc+jEl1GJ1YSye6K1mZf5x4i59y8AULDlbdT4hYP4Xji8nh2KgK8aEm/02OioF6jYdUIY/0blfHw== 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=BJGPFCKzNEwl3egjrviH4RCpCB7V93sRbJj49WF3LQM=; b=APYlB4n6pUyO+imFUppInP8ciC1BDBcbFoDsXLGYrz0UwSDZgjgO8+EcPsniDluleMIEvfzV8Irqh5LZGx7gSvrYLCdUTQo9QjfcMyo1S+HgQMMWi/srk/dFFvVsnTxVLEyVadetc1on2r98aZ7TDujN9h88QN6Yuo6PfylDMVhuD5Qj2SMUpEe8LSyPihXw4+c0/zpCX8mDb7nMbsJpRzqK9zaWAeUpQVV32fxzoIAsz6a4hX3VkoqyVxXKIhYTAuMzY5fX3MzXrziGoitmaIeJmjVelo3kopCtEmGMcm/guOc1cBnQWufvZrgeBsfaWopQqA7jFZMzgtRFbolpwg== 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=BJGPFCKzNEwl3egjrviH4RCpCB7V93sRbJj49WF3LQM=; b=D4YyPTRV+IkrCI9hx4bYiinYInhrEpCudBjNSWb+h065KjBNVFVEKwAPrrja0iK6kBRmcNKkY/Y4H1jEIyjX1IdFZpbKLLTKrDttki1EiBMwRuRLoS4NOKpVNLUS8Btd4tXfJseaaMWudO4vzgI/gAKvjXqKfBfbO/R0Li5xRlE= Received: from CH2PR17CA0019.namprd17.prod.outlook.com (2603:10b6:610:53::29) by IA0PR12MB7676.namprd12.prod.outlook.com (2603:10b6:208:432::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.25; Fri, 31 May 2024 04:34:32 +0000 Received: from DS3PEPF000099D5.namprd04.prod.outlook.com (2603:10b6:610:53:cafe::b3) by CH2PR17CA0019.outlook.office365.com (2603:10b6:610:53::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.18 via Frontend Transport; Fri, 31 May 2024 04:34:32 +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 DS3PEPF000099D5.mail.protection.outlook.com (10.167.17.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:34:32 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:34:03 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 16/24] x86/sev: Drop sev_guest_platform_data structure Date: Fri, 31 May 2024 10:00:30 +0530 Message-ID: <20240531043038.3370793-17-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D5:EE_|IA0PR12MB7676:EE_ X-MS-Office365-Filtering-Correlation-Id: 71de84fb-8915-46cb-5437-08dc812af7da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|376005|7416005|1800799015|82310400017; X-Microsoft-Antispam-Message-Info: mNCday6T2p5gKxF4RKv1jPVN8gBsVjO6CTo4QAOErve5XUGpKuIKsWp4qgECp51/pLKUHyOAcGVBsjZf5W5UlksH+n9WuRD6E56ohjLSQy126menS303fk6zEU/BuG4/b2GM47v+WI0v7WaNj34TmOk0v8fEWDoUFRPAtBW0R7uNo3Fi/J/6qxPmFpD3LjDAjEO+rPsw+KXJNvLcv0qVZ90txsPfhpuE0T/kDYXj23+sbNQluChp7TYKQREbVlbHS3ZdoYd4EyGLmnaz9DUa5HOLe5j1yD7Ofui2VU10KnpgNgMonFXPLG3h5MZg60Sz+8FsruHmmi2Y/Z0M3pFpTPjHqFA2k30NTOx8IvNX0K5z0FINL7r59tyzX2YHK15fHU5zvl9V+BSccSJpMDf7ZFLzhf9rDydw4J/ovAZ/O5zixF3Fgv4z/ZB9VmRAJ7FB4wWixbTl5YIqezjLQtU8ju7T6d/pWGGfnMXUzDTu7CejO2nvN3BgAqgZYFeJMwo3P7i4M2hk5k65Pec29cffLJhb2MT4YE7Q1cTo8r2nkDgqFB31/a56CEC5CZLfaaA4XGj6LQpQp0ubtXfsMNAPk8XfSuI4hyKU/0uxjYnPsPHsx26I5ez/puxsM0LKEABkMeODEzoV9k1fl280wcWmcC/LkezMswZ8KSFCcNPkr/aJTSLXLEhVVkkWfH9kii52vb93nv5qx2eP9I2APkSFI/Sm7E3eKR8nxOspo8Hf3QjY/O0itHv+swNs7peKdsBTDzr+PpSvb1I/YShradNYXjklkIx2iuCVCPwCP4i/2oB2/kNIAleLvgP+Zds3/iZ6CjvZx07HoluTGlTuLNVuJ6ParRrAJc48qjk1h5QKiqPqXNlFG1W5N7nU8qmV5055dC9nE5DeYQsjk7wWnvBFfLjMKGZNaxJlS33p3iO0Jg2ynVHbSHPN6E56sYDxbdo0QSuwfEW36v9fS7Q2dkvqqWfZuqiIb+VZ7JpZllpVh42OmdzZWDVQcPSbjblDKx69N2eCubhgVU5lgWkNmF7V20z2okGOcmT2IXngJ7EFPwrKn+X0LpPtdLunVGb+g6v83YqyBqjCJHniFHxV9fh65dToXahdGG5KPMhCpYCJjOWz+lGDf0YSFGT6GwwuM4HcSy4Wz+u23/oaObeWnVtk+yAzry3w2EJoLBl9K76B8uGC3ylFtjM5ecnBkwfuqL1OPhbRjelyeeUFOqXxKGr1B4rYf1etDJjzvbh+ze/fqgmIMxQtCb7xJ/+1f71zoDNIFJgDOkcTS9LtP3C+qfc1uEExJQ3mclAHATi+eLMi9LG7iuzmaeGjTY8B1kdw3SszAG3hHw36LwS86oKmg2xpwWStSJXR76wkut2Tzdz0N3/uqXO8X2lIp7fCdTr8LlS6 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)(376005)(7416005)(1800799015)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:34:32.5720 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 71de84fb-8915-46cb-5437-08dc812af7da 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: DS3PEPF000099D5.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7676 SEV guest platform data structure was used to pass the secrets page physical address. As the SNP guest messaging initialization routines are local and secrets page address is cached in sev.c, use that instead of sending it to the SEV guest driver and getting the same address back. Signed-off-by: Nikunj A Dadhania --- arch/x86/include/asm/sev.h | 9 ++------- arch/x86/kernel/sev.c | 10 ++-------- drivers/virt/coco/sev-guest/sev-guest.c | 8 +------- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index f58052fd6cb3..128bf71302a3 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -116,10 +116,6 @@ struct snp_req_data { unsigned long resp_gpa; }; -struct sev_guest_platform_data { - u64 secrets_gpa; -}; - #define VMPCK_MAX_NUM 4 /* @@ -324,7 +320,7 @@ u64 sev_get_status(void); void sev_show_status(void); bool snp_assign_vmpck(struct snp_guest_dev *snp_dev, unsigned int vmpck_id); bool snp_is_vmpck_empty(struct snp_guest_dev *snp_dev); -int snp_guest_messaging_init(struct snp_guest_dev *snp_dev, u64 secrets_gpa); +int snp_guest_messaging_init(struct snp_guest_dev *snp_dev); void snp_guest_messaging_exit(struct snp_guest_dev *snp_dev); int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, struct snp_guest_request_ioctl *rio); @@ -393,8 +389,7 @@ static inline void sev_show_status(void) { } static inline bool snp_assign_vmpck(struct snp_guest_dev *snp_dev, unsigned int vmpck_id) { return false; } static inline bool snp_is_vmpck_empty(struct snp_guest_dev *snp_dev) { return true; } -static inline int -snp_guest_messaging_init(struct snp_guest_dev *snp_dev, u64 secrets_gpa) { return -EINVAL; } +static inline int snp_guest_messaging_init(struct snp_guest_dev *snp_dev) { return -EINVAL; } static inline void snp_guest_messaging_exit(struct snp_guest_dev *snp_dev) { } static inline int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, struct snp_guest_request_ioctl *rio) { return -EINVAL; } diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 141a670d2a85..c56cb2f15ec7 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2239,15 +2239,9 @@ static struct platform_device sev_guest_device = { static int __init snp_init_platform_device(void) { - struct sev_guest_platform_data data; - if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) return -ENODEV; - data.secrets_gpa = secrets_pa; - if (platform_device_add_data(&sev_guest_device, &data, sizeof(data))) - return -ENODEV; - if (platform_device_register(&sev_guest_device)) return -ENODEV; @@ -2597,11 +2591,11 @@ int snp_send_guest_request(struct snp_guest_dev *snp_dev, } EXPORT_SYMBOL_GPL(snp_send_guest_request); -int snp_guest_messaging_init(struct snp_guest_dev *snp_dev, u64 secrets_gpa) +int snp_guest_messaging_init(struct snp_guest_dev *snp_dev) { int ret = -ENOMEM; - snp_dev->secrets = (__force void *)ioremap_encrypted(secrets_gpa, PAGE_SIZE); + snp_dev->secrets = (__force void *)ioremap_encrypted(secrets_pa, PAGE_SIZE); if (!snp_dev->secrets) { pr_err("Failed to map SNP secrets page.\n"); return ret; diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 41878bd968d5..8d026d485028 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -406,7 +406,6 @@ static void unregister_sev_tsm(void *data) static int __init sev_guest_probe(struct platform_device *pdev) { - struct sev_guest_platform_data *data; struct device *dev = &pdev->dev; struct snp_guest_dev *snp_dev; struct miscdevice *misc; @@ -415,11 +414,6 @@ static int __init sev_guest_probe(struct platform_device *pdev) if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) return -ENODEV; - if (!dev->platform_data) - return -ENODEV; - - data = (struct sev_guest_platform_data *)dev->platform_data; - snp_dev = devm_kzalloc(&pdev->dev, sizeof(struct snp_guest_dev), GFP_KERNEL); if (!snp_dev) return -ENOMEM; @@ -430,7 +424,7 @@ static int __init sev_guest_probe(struct platform_device *pdev) return ret; } - if (snp_guest_messaging_init(snp_dev, data->secrets_gpa)) { + if (snp_guest_messaging_init(snp_dev)) { dev_err(dev, "Unable to setup SNP Guest messaging using VMPCK%u\n", snp_dev->vmpck_id); return ret; From patchwork Fri May 31 04:30:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681125 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2089.outbound.protection.outlook.com [40.107.244.89]) (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 D301480028; Fri, 31 May 2024 04:34:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130083; cv=fail; b=Q8M2i/Njuum4iCaEOo/Jmetdo7tKsZ5KeptXQiPnMvqtvlk3QEefop8pDS2ewwK1wGdJYl0ol41oSwkvXiHq1RNYAq+LntYT/9wcpS3lHzl9gE2Ublta1INnEfPSluEWGmBIRfHu6RGG9vNj8hc9317tAGvXA09Q4vRHpBJeU/c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130083; c=relaxed/simple; bh=vLrKq49G5EtzXifK3qXve/+xABeDSStTWEiwGb0yu/0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UDzV3IJ2uXrq2DvIOOThTVtiPIcf9Doa4OD6BOltWjlsU8XtJjCOx36JBCPQupPCSJxPLfq4PZ7scQBrmB26wTcPIvv1W1HdMamgPkBUhOeQhTBoc1IqkJcKtNlhepuXVaTOd5r4jZcehIG4fw0aaGrm9q5C5P5uVGNvQwnbXTA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=QI/Y1fLa; arc=fail smtp.client-ip=40.107.244.89 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="QI/Y1fLa" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I1wnKJ5XnMxsdGuvARsuYAAs4OKn/KmL9PDxItQX75O67KeykH2E9+LtQsDydEqXJD1jJzl2aGERwN9I0NIfF5zkRK3lG9Tt7zqiF7p5Bh0BnSqj+09+3CHhY5LuurGA+RonjyKnFnqEvoeEBRCtC6u+dAItaNJV9mI8lmZdb1owN7XZrIs5IpkTEj0kaOk/9rud5TnfKFr+riAAs4gvg7fb29EENc2zP5uSXMK3vn7ZKyfmT3U07ayg1MpGglmN1fXEHD7o/F1/YO4n2ff9laHqNWCeT2mWjW8mTjXtasJhVBFTL1EvBwX5wuqXzSsFC5PI0ccZtH6/ri6Y1RrMdQ== 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=VI9Q6jL4aJyvI91x+hBzrKswrSdPdeIgmfBHMt4oUSY=; b=DZchoarwx+DA6lejeX/ayIlDfDp9tMZ5Y1czrL15rFUfQLwEEe4P23XJsR48dcogaRKlijQEAqRFKEsgXW4kgyyFOCXv6C0chXtGXHU8yEX8b4Gf926+s+Q5gMq8muAtC0VqOOol4ZMEgV1LxLU9OXwZzfF7Nf+C+ZVjziNXWaDZx9IwrfIBe3Lv2/h8Xh5lflXnmrvq+wi2WNSKKlwqX4iydEB8KZp3bQXkcc2Qyx82kVRRJeKyulzdnM8wulCIh1nkge3LSaQxei7KJhRRsyxwnobSNEuQ+oFAH5ltlvtdGCLBsD8xULoQWIniS7EnC897h27EUGX8eYR14u4Swg== 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=VI9Q6jL4aJyvI91x+hBzrKswrSdPdeIgmfBHMt4oUSY=; b=QI/Y1fLaDrhw6CigwmaVm2uy3Jh+LGvfjhOQVNGWN/n1Hxi0xjATUwJRvEAjUcMqIp2NsjT4frTeHOlF+75s3pwhpwDscXWKPFmmar0SYk66ajJTHaCa8KkW7l0Ohj6dAd3n7aMnrm4sW30q1Eyyf+5kiMctn7yP86yvBewr0uQ= Received: from DM6PR08CA0051.namprd08.prod.outlook.com (2603:10b6:5:1e0::25) by DS0PR12MB8295.namprd12.prod.outlook.com (2603:10b6:8:f6::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.34; Fri, 31 May 2024 04:34:39 +0000 Received: from DS3PEPF000099D9.namprd04.prod.outlook.com (2603:10b6:5:1e0:cafe::70) by DM6PR08CA0051.outlook.office365.com (2603:10b6:5:1e0::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22 via Frontend Transport; Fri, 31 May 2024 04:34:39 +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 DS3PEPF000099D9.mail.protection.outlook.com (10.167.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:34:39 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:34:32 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 17/24] x86/cc: Add CC_ATTR_GUEST_SECURE_TSC Date: Fri, 31 May 2024 10:00:31 +0530 Message-ID: <20240531043038.3370793-18-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D9:EE_|DS0PR12MB8295:EE_ X-MS-Office365-Filtering-Correlation-Id: 9feed928-dbb8-4b23-493d-08dc812afc07 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|36860700004|7416005|82310400017|1800799015; X-Microsoft-Antispam-Message-Info: kNHObO0beHzohndf9cJn/kh9NufRkWkR2MkxKLWLJghrko2Os3c1bgRViybE3MkBGvStiX4+lMHY5jdqkyUfF+dEOZf3qd+c7/ZJGx9azQQEWNTNaWhMJSEr9n7CCpERRwEZrSz+vTQzszfQAFyccPOwsKdTnIval2tcXHD4lTCAvycwdgkOLENf/H1S9L5Pd1AmLjBUxgGjxpQP/hys2VQO5bEQA+HIccM+6S1wwGiXVaVSW6CTbpgvxt2/FDlYxA8jXW0B2yBicNY2KnUAH4g2qhw8h6cczlnuH9HAZJ6kOTOOumFqNbXsB45FHcMFo9idAlp5BNTK7lTFhPOsl+p/vsXGq41Uwgbo1bdPFOfmxPYN+uAxf+yhU9GRn2QABKCmV/Y01Pi7sZv0A7YuEQl0Ybq0qZpbcJgGHBA7mmenGyOfzI1fyUtD/Yw7/rXqjXS/2OZlBPo2xDS2iQherBp9xd2zSuDh0i+4YGb/frsqYf0lLutQk5c+AK9bt/tBmvV5CmMfOSFTxBYSoRoHykLqy6BqYq6M4I3+I383dS5wxIMFikbi97QP1tSswkG4OpicAjTVlGptSP3sHAVA3IVM3Hm6MQesO0XWvDZpkzlJPL/sHlqyXf+wm1baQ53jbn2QYha5RSPU61C7+b8D/Mnnygttvcbl6ZkGdAjM4Gd71Bk8QYkRKQJZL7AbgayI6pa+3rYz2E/a6iUpfmsRKJ1zlwws9IM6Cj6CIIiEirN7ZAjQkkR65sr6T53DcBuTqQAL+yF/HQ34L02MDr7wwdEF1kQ42lDO+YmQkXJU+UVxNc/IXMAX7xKfezUJcG/NRtaJzq2i4I1aiFhcHh2z2rwC8e8t7NMuMZ3ZNqeOxeE9facpBYdie/YDkycuqkaV5t3rDE7Uc1AIlHhVYsrsamsw7WbUUDORHzx3kqUMDN1nUYZ001ZH6aTdr9/P5zu13qu1xnacJQALPJ+fe+Y9d+UjFlq/JgGqqUytdnQim5Py1Y5ZojESqT6NNypVntk4ocar6ZcwPy0SNpFT7VSDWEbSeQVAsE4xhHNNSqXes26Ewwt6sz8SYJguUptypYNj6y045hoQmYgfPOudWWBDeThU3j7jBPd70nZ9QvMH1r3o3n4Pye985nU0VB+kb7mOBSkbmwBH2mDJunycfzmt5B4opp4sXuc4b++Oye2ZsXfpKwyjdIhYeYS18I6DPlT7cz8TUEA5hIuDHKzPc8hhGEehn71xvl74W5eaf2NXJ6942I0XgVe1xGikTSxaE6r+E8KTwTlG69D6aX03gOuuHcWj1VGhjc+RPAVgqDc9InwuC7zSWVQH68H5ZOcOGvdf/o/GtFkTUglDcVozvvJLcPyxSk2M/yOYdTCB8vqFfnkmQEee7WMzZEz7l3Zdfit/ 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)(376005)(36860700004)(7416005)(82310400017)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:34:39.5775 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9feed928-dbb8-4b23-493d-08dc812afc07 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: DS3PEPF000099D9.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8295 Add confidential compute platform attribute CC_ATTR_GUEST_SECURE_TSC that can be used by the guest to query whether the Secure TSC feature is active. Signed-off-by: Nikunj A Dadhania --- include/linux/cc_platform.h | 8 ++++++++ arch/x86/coco/core.c | 3 +++ 2 files changed, 11 insertions(+) diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h index 60693a145894..57ec5c63277e 100644 --- a/include/linux/cc_platform.h +++ b/include/linux/cc_platform.h @@ -98,6 +98,14 @@ enum cc_attr { * enabled to run SEV-SNP guests. */ CC_ATTR_HOST_SEV_SNP, + + /** + * @CC_ATTR_GUEST_SECURE_TSC: Secure TSC is active. + * + * The platform/OS is running as a guest/virtual machine and actively + * using AMD SEV-SNP Secure TSC feature. + */ + CC_ATTR_GUEST_SECURE_TSC, }; #ifdef CONFIG_ARCH_HAS_CC_PLATFORM diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index b31ef2424d19..df981e3ba80c 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -101,6 +101,9 @@ static bool noinstr amd_cc_platform_has(enum cc_attr attr) case CC_ATTR_HOST_SEV_SNP: return cc_flags.host_sev_snp; + case CC_ATTR_GUEST_SECURE_TSC: + return sev_status & MSR_AMD64_SNP_SECURE_TSC; + default: return false; } From patchwork Fri May 31 04:30:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681126 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2055.outbound.protection.outlook.com [40.107.94.55]) (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 72330823BC; Fri, 31 May 2024 04:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130084; cv=fail; b=hFKEznWoABTZUEJ6cwL7n31DFU+N425nCKIPajT3qymjpprZxdP5Lj01jW4Nv31r4nxvVIHiyvd5GT+hOI3zA7MzUZHT+5IKteONtcZ9nL/b4y2QQ7etuk4pdITEPkmJWfBuAMyrNa7XF18oit/XO7zikWj/2KEmMx2TCSHPkcY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130084; c=relaxed/simple; bh=tp1vMkb7i2BpoJ85KK0ZmC6pZS3sYv7hsvwjTQWBRD8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pk5PaIpGKChV6hsxoVNoTbX9qNd3IGoQNRtN3JGVaVtNGh96WC4om23WkUCtzeuJAe8DIOX8oXAQfp72OWmIe+sfOsuUde/c/5ySk1IIA1AL7acHKdXu1rPEmJ/2OltGyygcWwpTVXlD6GB008mS/0gh8vNcdLxfvTn2uUqe95E= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=He3qPR7U; arc=fail smtp.client-ip=40.107.94.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="He3qPR7U" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IdALJ7XQq784jgQKi6ofYgJXWnWqxkFqqJ74NVlgRghrDfjvT8Fu7KHC0Vznw4WQGfAh047IKi5M4eiR5Rtr5zsBmP1kggzpMbQ3omGJFVtHEaNgDtpCgVveCGoFdVL2qwsny1DuB145vSdNBZnryWBrRAFp2H09uMwH8WlhtDXPROrA7pjhrFGU3A42GQi5G4eudU2iRYSsKXiEuIKbBpYQRFedKMxA1zdwkSYbg5bJklehHTlrFa7C9a+KleE8jXo6diUOVlSQOaGllx8O1oJn6LOuRPxpQrgFKbY9Do4umWbZVUqWuF+duzYVBS8PPYfYpyFJINovvh5ozAh6Kw== 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=/jWlAnrnYANpPBOexW5g/QcD4cGrSyswF7bO1sXX9GQ=; b=nzIm/nUG3S+T0Bj8Q8+K+nDC88FYH/fT9gSyfHdCVQ9K2EYA3ByI0eJw7BCutLglGgdsg0ofZILU7O/Da1Q+DkG8B85F6HtI3V5RUuUj3uWznbuB/ZRzjMHYdfLd5q/aA+RX2K6Hwy/YU2jPJqEybWZ3u7y9v+aNMNDEsH3Zr4jWHGP6RvAJVoKkaE4YXOgv0QUbV43KlBboqSa8E3u7PTWcq72rLDYmZ7NTW1Y2o3U/Pa8yasyqtPX48HQVxvQCgVjFl9KRCwIdbAea/aajSEIXk2XJfqrbhlYYgmhRUV5r6Luthm51dxWg5Hb9FL4woh+Ni0ttpctuMi5koEUf1Q== 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=/jWlAnrnYANpPBOexW5g/QcD4cGrSyswF7bO1sXX9GQ=; b=He3qPR7UF9uer41oE7gsC5jeEa4N1oTqOon4OtUNe8qDnXPR50I9LtvclxcBBxesB3RpQVEpaxWCCQDqCquDlRuaeGxY38h/3U6vTbFCkHQf0QDX4RoOGmyWhXH6nTf8c0sS81gpoTx7d8Mv/YqRgP+KFSQfXhx+EhwvxvHmZZE= Received: from DM6PR08CA0043.namprd08.prod.outlook.com (2603:10b6:5:1e0::17) by SA0PR12MB4496.namprd12.prod.outlook.com (2603:10b6:806:9b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22; Fri, 31 May 2024 04:34:40 +0000 Received: from DS3PEPF000099D9.namprd04.prod.outlook.com (2603:10b6:5:1e0:cafe::16) by DM6PR08CA0043.outlook.office365.com (2603:10b6:5:1e0::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24 via Frontend Transport; Fri, 31 May 2024 04:34:40 +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 DS3PEPF000099D9.mail.protection.outlook.com (10.167.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:34:39 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:34:35 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 18/24] x86/sev: Add Secure TSC support for SNP guests Date: Fri, 31 May 2024 10:00:32 +0530 Message-ID: <20240531043038.3370793-19-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D9:EE_|SA0PR12MB4496:EE_ X-MS-Office365-Filtering-Correlation-Id: 284de39a-db75-49f6-e3fd-08dc812afc42 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|36860700004|7416005|1800799015|376005; X-Microsoft-Antispam-Message-Info: x0Tt4qP3F9oIt108gEdkoOkF0xTHed7/kLtKAH3HHP7MLNJga41F7qSbiV/9e/9nTi5xIP5/ZzDad4+md1LFEGFf8pj7O+2VpRj2/0Tt2N6gBJM5emJn5tBoit4XtGDUi0R0eZ5ExnFBaB4c/HnvU3h6hh2wAXtNmrpIvjStPjZpJ4uJzgJ2hrk9RCo1oJh+W/7BA8URZybFuYH0Qo6MHfsJ42Ar1uBf0N/icqrbKtVFASLnKpMEClvT6CfQszZEzt5QaiRb7sWcYxzRo6n69FDlVzhrpWLShkhS1o/ft6ANfOxPktjna10mdkpxxlkwhu3wJWG29o0zR4pKt3+eWDLDwY/K7VYwpmVXTWmwv5aRHznDCHwmbQ9nGSmiPpBI3x2DDbcZNg69GXOPSQaScVJgqRs51wvz8hoAc9W2lXdSNmPtYAibhOQ6h/LgZsCg+z8JUnPyIOEqDNWAe4AgmpCWy1Xa0Rr/FDEqXOt99o9f9guIdnWPsZq6k/ih35QXdsZcb8aMEluSpMk9DwIMhwf60pFqnLFY6tAQrHcEMNVLVlpajt+lYi4MUafgWJN8aiUkNm97np8g/MnvTPx5UEFA7g3IBj3RV6ee+HjRnYT8DWJVhPVaj0hwe5ZT7t1f8AQTYIkitVgrYqdtEqpgvPFISZeEX9bX9BmesmHdMcQWULZNaPqm0fZWEO1lkW1bZ1BpGTcdvDrMAETnsdC+l5Sxw8bdx/l6/GRXgk77CFL3O1w6NUtpGhhOACcVu4c8cVOCnaPn5kjnwj6iCSd3e43q8Ko/GzKrENyKzDMw1sqsMBKlYo+scUc3UhgylPOmYqdWBCMQ/kUt3hskUk7CAbhK9cfhxbiBjKdY5UhIdM21pKSxX/q8dzjy0n3wfcEPWWNP7iXzmAIP5DaZtsSC96QddrgB9O411fzKuNeTsY8W+x1xemcGSzImMirgJ4nUV0t+4Wplc3INjla2tBYL+9xNR/f3LnERFPXUBSwEqnLNq6F3LZmmuOUJ7AjjfeSO/blU4q/bpW4mSdtii3sXyiXH8i6RklaiBpw9JrqcRShDq8kdMEMKQ63OLaXKrghpuJHrw6EqjsBB1vYv80iEYLfvO1m26XhD3EP+HJccwh1k933OI9evh9Zwiiki1NRG+S5RCwhS4aOqAuyAuTfE0j9UqARBow2HAed/hUePQkS4mP4BQ34OwKAOFyTVru/nVsOW3LjuVcdMve1uFeznuEudmcsP2dzqgr3wEI6cqnNuUs/ONL6WJ2c4c/5hfZhPIYHfrb5j1R2dmY80oHURJk8s8wtnjHKdVunblwUacnFSwrq9LzGBIycxpME9DsXuzH+cq0leJMKfuVLhxuhyje3ZaWgpTNGTWOgvYiohDgQ= 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)(82310400017)(36860700004)(7416005)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:34:39.9838 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 284de39a-db75-49f6-e3fd-08dc812afc42 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: DS3PEPF000099D9.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4496 Add support for Secure TSC in SNP enabled guests. Secure TSC allows guest to securely use RDTSC/RDTSCP instructions as the parameters being used cannot be changed by the hypervisor once the guest is launched. Secure TSC enabled guests need to query TSC info from the AMD Security Processor. This communication channel is encrypted between the AMD Security Processor and the guest, the hypervisor is just the conduit to deliver the guest messages to the AMD Security Processor. Each message is protected with an AEAD (AES-256 GCM). Use minimal AES GCM library to encrypt/decrypt SNP Guest messages to communicate with the PSP. Use the mem_encrypt_init() to fetch SNP TSC info from the AMD Security Processor and initialize the snp_tsc_scale and snp_tsc_offset. During secondary CPU initialization set VMSA fields GUEST_TSC_SCALE (offset 2F0h) and GUEST_TSC_OFFSET(offset 2F8h) with snp_tsc_scale and snp_tsc_offset respectively. Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda --- arch/x86/include/asm/sev-common.h | 1 + arch/x86/include/asm/sev.h | 22 ++++++++ arch/x86/include/asm/svm.h | 6 ++- arch/x86/kernel/sev.c | 90 +++++++++++++++++++++++++++++++ arch/x86/mm/mem_encrypt.c | 4 ++ 5 files changed, 121 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-common.h index 5a8246dd532f..2cd9a6a45b39 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -163,6 +163,7 @@ struct snp_psc_desc { #define GHCB_TERM_NOT_VMPL0 3 /* SNP guest is not running at VMPL-0 */ #define GHCB_TERM_CPUID 4 /* CPUID-validation failure */ #define GHCB_TERM_CPUID_HV 5 /* CPUID failure during hypervisor fallback */ +#define GHCB_TERM_SECURE_TSC 6 /* Secure TSC initialization failed */ #define GHCB_RESP_CODE(v) ((v) & GHCB_MSR_INFO_MASK) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 128bf71302a3..d6dc44c12fea 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -173,6 +173,9 @@ enum msg_type { SNP_MSG_VMRK_REQ, SNP_MSG_VMRK_RSP, + SNP_MSG_TSC_INFO_REQ = 17, + SNP_MSG_TSC_INFO_RSP, + SNP_MSG_TYPE_MAX }; @@ -204,6 +207,22 @@ struct snp_guest_msg { #define SNP_GUEST_MSG_SIZE 4096 #define SNP_GUEST_MSG_PAYLOAD_SIZE (SNP_GUEST_MSG_SIZE - sizeof(struct snp_guest_msg)) +#define SNP_TSC_INFO_REQ_SZ 128 +#define SNP_TSC_INFO_RESP_SZ 128 + +struct snp_tsc_info_req { + u8 rsvd[SNP_TSC_INFO_REQ_SZ]; +} __packed; + +struct snp_tsc_info_resp { + u32 status; + u32 rsvd1; + u64 tsc_scale; + u64 tsc_offset; + u32 tsc_factor; + u8 rsvd2[100]; +} __packed; + struct snp_guest_dev { struct device *dev; struct miscdevice misc; @@ -225,6 +244,7 @@ struct snp_guest_dev { struct snp_report_req report; struct snp_derived_key_req derived_key; struct snp_ext_report_req ext_report; + struct snp_tsc_info_req tsc_info; } req; unsigned int vmpck_id; }; @@ -362,6 +382,7 @@ static inline void *alloc_shared_pages(size_t sz) return page_address(page); } +void __init snp_secure_tsc_prepare(void); #else static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } @@ -395,6 +416,7 @@ static inline int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct s struct snp_guest_request_ioctl *rio) { return -EINVAL; } static inline void free_shared_pages(void *buf, size_t sz) { } static inline void *alloc_shared_pages(size_t sz) { return NULL; } +static inline void __init snp_secure_tsc_prepare(void) { } #endif #ifdef CONFIG_KVM_AMD_SEV diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 728c98175b9c..91d6c8a79aa2 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -410,7 +410,9 @@ struct sev_es_save_area { u8 reserved_0x298[80]; u32 pkru; u32 tsc_aux; - u8 reserved_0x2f0[24]; + u64 tsc_scale; + u64 tsc_offset; + u8 reserved_0x300[8]; u64 rcx; u64 rdx; u64 rbx; @@ -542,7 +544,7 @@ static inline void __unused_size_checks(void) BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x1c0); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x248); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x298); - BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x2f0); + BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x300); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x320); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x380); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x3f0); diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index c56cb2f15ec7..b4458af92a73 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -96,6 +96,10 @@ static u64 sev_hv_features __ro_after_init; /* Secrets page physical address from the CC blob */ static u64 secrets_pa __ro_after_init; +/* Secure TSC values read using TSC_INFO SNP Guest request */ +static u64 snp_tsc_scale __ro_after_init; +static u64 snp_tsc_offset __ro_after_init; + /* #VC handler runtime per-CPU data */ struct sev_es_runtime_data { struct ghcb ghcb_page; @@ -1045,6 +1049,12 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip) vmsa->vmpl = 0; vmsa->sev_features = sev_status >> 2; + /* Set Secure TSC parameters */ + if (cc_platform_has(CC_ATTR_GUEST_SECURE_TSC)) { + vmsa->tsc_scale = snp_tsc_scale; + vmsa->tsc_offset = snp_tsc_offset; + } + /* Switch the page over to a VMSA page now that it is initialized */ ret = snp_set_vmsa(vmsa, true); if (ret) { @@ -2660,3 +2670,83 @@ void snp_guest_messaging_exit(struct snp_guest_dev *snp_dev) iounmap(snp_dev->secrets); } EXPORT_SYMBOL_GPL(snp_guest_messaging_exit); + +static struct snp_guest_dev tsc_snp_dev __initdata; + +static int __init snp_get_tsc_info(void) +{ + struct snp_tsc_info_req *tsc_req = &tsc_snp_dev.req.tsc_info; + static u8 buf[SNP_TSC_INFO_RESP_SZ + AUTHTAG_LEN]; + struct snp_guest_request_ioctl rio; + struct snp_tsc_info_resp tsc_resp; + struct snp_guest_req req; + int rc; + + /* + * The intermediate response buffer is used while decrypting the + * response payload. Make sure that it has enough space to cover the + * authtag. + */ + BUILD_BUG_ON(sizeof(buf) < (sizeof(tsc_resp) + AUTHTAG_LEN)); + + if (!snp_assign_vmpck(&tsc_snp_dev, 0)) + return -EINVAL; + + rc = snp_guest_messaging_init(&tsc_snp_dev); + if (rc) + return rc; + + memset(tsc_req, 0, sizeof(*tsc_req)); + memset(&req, 0, sizeof(req)); + memset(&rio, 0, sizeof(rio)); + memset(buf, 0, sizeof(buf)); + + req.msg_version = MSG_HDR_VER; + req.msg_type = SNP_MSG_TSC_INFO_REQ; + req.vmpck_id = tsc_snp_dev.vmpck_id; + req.req_buf = tsc_req; + req.req_sz = sizeof(*tsc_req); + req.resp_buf = buf; + req.resp_sz = sizeof(tsc_resp) + AUTHTAG_LEN; + req.exit_code = SVM_VMGEXIT_GUEST_REQUEST; + + rc = snp_send_guest_request(&tsc_snp_dev, &req, &rio); + if (rc) + goto err_req; + + memcpy(&tsc_resp, buf, sizeof(tsc_resp)); + pr_debug("%s: response status %x scale %llx offset %llx factor %x\n", + __func__, tsc_resp.status, tsc_resp.tsc_scale, tsc_resp.tsc_offset, + tsc_resp.tsc_factor); + + if (tsc_resp.status == 0) { + snp_tsc_scale = tsc_resp.tsc_scale; + snp_tsc_offset = tsc_resp.tsc_offset; + } else { + pr_err("Failed to get TSC info, response status %x\n", tsc_resp.status); + rc = -EIO; + } + +err_req: + /* The response buffer contains the sensitive data, explicitly clear it. */ + memzero_explicit(buf, sizeof(buf)); + memzero_explicit(&tsc_resp, sizeof(tsc_resp)); + memzero_explicit(&req, sizeof(req)); + + snp_guest_messaging_exit(&tsc_snp_dev); + + return rc; +} + +void __init snp_secure_tsc_prepare(void) +{ + if (!cc_platform_has(CC_ATTR_GUEST_SECURE_TSC)) + return; + + if (snp_get_tsc_info()) { + pr_alert("Unable to retrieve Secure TSC info from ASP\n"); + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SECURE_TSC); + } + + pr_debug("SecureTSC enabled"); +} diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 0a120d85d7bb..996ca27f0b72 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -94,6 +94,10 @@ void __init mem_encrypt_init(void) /* Call into SWIOTLB to update the SWIOTLB DMA buffers */ swiotlb_update_mem_attributes(); + /* Initialize SNP Secure TSC */ + if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) + snp_secure_tsc_prepare(); + print_mem_encrypt_feature_info(); } From patchwork Fri May 31 04:30:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681127 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2073.outbound.protection.outlook.com [40.107.93.73]) (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 EB18582D75; Fri, 31 May 2024 04:34:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130089; cv=fail; b=YV5Iwss8GazGMnd5xCF8p6DQ+pIAA0MhU2Du1zV3tbKsbEShvJ5RP1iy8AgRdja2xWmFmZu1gCTNpkDtrmGpQ8zpLB14Z/Vjw/7T04NOKdzwSlzs4n0AtyP5SSjn5GZIZhKu6wAW4WAyzWO9wkZi11aBXkJQ1m1O9lJ7+R3KkHo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130089; c=relaxed/simple; bh=KsIMJLJ6CQpyeDM/RXcWA6TadtVbGCuait48LQRKyZ4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m6Tff/XcbWWFxrDOOMfVHD00dwEF1YJfiam49sfwRGkbTO0+RQUb3P6AtFJavfZyfJqYTwQnzt7YUkz54kzpPjg+oJX+8Om++JjYwBW02dGkPowoy9x4D+CZK26+HrYuALk6+/Nt+KACbqtx2QVbaVN1dQ8fUatG+kdFTFXj4mI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=RSci858z; arc=fail smtp.client-ip=40.107.93.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="RSci858z" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ikIfu/R/IcMYO5A6qlHcZteYUq63yxendsAROh4u4xyg1IZYnrf7LtOzNQ58+7aO7Nj5GzaP9u5AaMPD4yKngZqkOX3BAO1RZ2w8kpqrl6k0XYfwOcvCJ+7/AhSCLOPYzq8S7cqdJXn0zi0+IdHtqzCIly42VGxOXaXWSYUGitpzsK7O4qc0eqZsVbYhh/uXZPg3YfC6wwTfV0ax+AWzgju035MMqFou9WFYGBK/ecF7204Mk2NWqH8ZgI3yRb/ZpFr6CIE6nq4cqIN3vau3KdLBhhgEax8piY3tKGr7qhLpz/NMD8vr7H6A+ibMkiEsNpp2wWN4o+jbyQJkZQHLZw== 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=DUqWOlsFxSY/Iq1jJTOUQHjey9t23YQnLfGpxy2azLQ=; b=OT3ofulVWMOO0ECB9/At+VdFp2n3MdVh736Nm/f/voUpFsFqFKgk+ectV5USoNQ0bnbEYPQwkGJtvc/US2VS/ye+8jM+R4evBXVfE0rtMJrIV3QErt+OFsRzjXpGm8sDNPDYe0VCA9ykfsiDM3v4bA29Jjox0rw/9Blfn4yTQru1B5oPD5NQZlgL2Oq2fx26W4bSyud0KABaqz3D39d7fRQz8x8uxP6VtXgF1JoqHyDNXW+GvARt1Enl9JP6zb2jbvWyNGaX+HAmRYyVnyHz38mHJlaNZEy35BAIt4S4UeFJPT7/ks2z2jL142HcwDHXPYexyEgAMk0l7HjNDy+z7A== 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=DUqWOlsFxSY/Iq1jJTOUQHjey9t23YQnLfGpxy2azLQ=; b=RSci858zlSeqrhs6UBu0qdjckzMqrsbM4ny2+EES0JQTiFxtx6m9TTFOjMNtH1q5a/2BMtSDeHlm4Mw2hI/5uVmbI8MYxP/SmUMAr9mKn7/Mbk4eRBnCTnt9HkXolNX98Kc/l2UBWYeBy9fxGq88ls9aesgz2IUKG6fJOH5bbVI= Received: from DM6PR17CA0036.namprd17.prod.outlook.com (2603:10b6:5:1b3::49) by SJ0PR12MB7035.namprd12.prod.outlook.com (2603:10b6:a03:47c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.22; Fri, 31 May 2024 04:34:43 +0000 Received: from DS3PEPF000099D6.namprd04.prod.outlook.com (2603:10b6:5:1b3:cafe::c0) by DM6PR17CA0036.outlook.office365.com (2603:10b6:5:1b3::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22 via Frontend Transport; Fri, 31 May 2024 04:34:43 +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 DS3PEPF000099D6.mail.protection.outlook.com (10.167.17.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:34:43 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:34:39 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 19/24] x86/sev: Change TSC MSR behavior for Secure TSC enabled guests Date: Fri, 31 May 2024 10:00:33 +0530 Message-ID: <20240531043038.3370793-20-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D6:EE_|SJ0PR12MB7035:EE_ X-MS-Office365-Filtering-Correlation-Id: 8609ff7f-fb54-45fb-bb36-08dc812afe65 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|7416005|1800799015|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: C2mmlB6iQoYkg6qptsHFkqh42fHGGQde9GUg8OkJBS51jt3kjzgKEy9qFWmo1QvepYzdN5LMxlPNdeB5usvNElMhU93GEa2BquDDUA03tJy2JXr5kTlB7OVgo2lQEl/wAoRecWmgggAFaP7XlDyAntA33oqYkTHVR6DJeTBNJBWXr72g+FGH2ePMSpmJgbnIV0+80IrMywSGX3MlfeTl4Q4ktXi+Q4XavIxqb4g+l/nYzu5FbjW1pxHpcpsrd9U+JjhMerEG7pwwtXHLK6gQ4xJMRLcVz7XtKy1XH3wy6a9Y1ggu+bdNqdBWtjMNAicTwwxkMPPa6K2L5B5SC8tAKc/5HPvAaxzsMgSQON5WX2ocM2wBt8Wyq0jVdJl1pRP7o7Vj+2qcGp78gkNeuiDdubkSWqAU64DjtiXfxxdfzIOZFUlcR42CIVi4eS0cWvFp5oKS+piqJP96wApLu20gBE4lrXEq1pyft0AapQCJp0PLMP1aqY+hKd+Z+2JUQ/4NH7TL0hJc9KwJTiH3Xj1GCoqWdov8GSCA/Ks2NqFLoLtocugP2I0ha4834Q1SJaNegHCW41yP3GK2PPqiZOP6qto7+yrEl3eTpgx0H5oQb8ybs3jYDC6i/2pZeC7sHqxarRxFn97AY7ELmgzjCeEmrPizI/bT8KaHKpmPwgGV3NmBbVP8ty937GiI8NxuLJ2tCdunz5NZC7Vt2V0l9gM3gtJaMQSLRqRTU5WkBK8yTpWrJncLDyLjKjF5Aq4K4fVFOZ9kgUMk//bjvRxvxlHyQlFqkgWOsG5ayUHR7Wi3xa/QDFbpMmIMfRDcVTg+7aLc3HBUk4uDUBJ8jtKnfJnWH2cpDfTjF33ZAoLmKktXIdNvH29p+WfFUtDmzwftbHULqFqvvfPsS2Bsm+Xu+ZCgnNinBmxWRuYYrdrePXJS10wJRBrM3DEMzX5zYHgEXqFZpTqj0Pe3jgUbR0I3C4Ddfb3FtKJ4c6tFz4YtSxBU2FE42QNo7SmLqjSRdI9oDW9hh5NfaSpP0KhJl7hudhTq8KKcByn7yaJRw3plqqW+Pl3jlSbMQThkGijKU0NteSG3QzF3naNow4Zn8bZBCLED0yP1JyGP5I6BfJ3Hx8MYPn+r6OgoLxMWs6Y8rURbonSx5Kd73U1bfs36w8UOlINVtemP+5YwNq0htmSbOyFVNgPFn2nwMzhyZOSi8BeW/d/8eNWki1ufPDGXo3qRAk73XgiJg66N4sT6dCbjxscE3AHqq1uSbTd+Avf7hsszevd81Ji6HSxvdI3SIv+t41iJ85YAVN+dNzJ8M1csFbv6wKqx9nTnMI1Sv5PkBmOhGZhiQeVjcDoh/B91C5vhVOOTnd2CcQ5dpxgJP8zXC9ESRd0= 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)(376005)(7416005)(1800799015)(36860700004)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:34:43.5519 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8609ff7f-fb54-45fb-bb36-08dc812afe65 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: DS3PEPF000099D6.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB7035 Secure TSC enabled guests should not write MSR_IA32_TSC(10H) register as the subsequent TSC value reads are undefined. MSR_IA32_TSC related accesses should not exit to the hypervisor for such guests. Accesses to MSR_IA32_TSC needs special handling in the #VC handler for the guests with Secure TSC enabled. Writes to MSR_IA32_TSC should be ignored, and reads of MSR_IA32_TSC should return the result of the RDTSC instruction. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky Tested-by: Peter Gonda --- arch/x86/kernel/sev.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index b4458af92a73..1f6a8d85c816 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -1191,6 +1191,30 @@ static enum es_result vc_handle_msr(struct ghcb *ghcb, struct es_em_ctxt *ctxt) /* Is it a WRMSR? */ exit_info_1 = (ctxt->insn.opcode.bytes[1] == 0x30) ? 1 : 0; + /* + * TSC related accesses should not exit to the hypervisor when a + * guest is executing with SecureTSC enabled, so special handling + * is required for accesses of MSR_IA32_TSC: + * + * Writes: Writing to MSR_IA32_TSC can cause subsequent reads + * of the TSC to return undefined values, so ignore all + * writes. + * Reads: Reads of MSR_IA32_TSC should return the current TSC + * value, use the value returned by RDTSC. + */ + if (regs->cx == MSR_IA32_TSC && cc_platform_has(CC_ATTR_GUEST_SECURE_TSC)) { + u64 tsc; + + if (exit_info_1) + return ES_OK; + + tsc = rdtsc(); + regs->ax = UINT_MAX & tsc; + regs->dx = UINT_MAX & (tsc >> 32); + + return ES_OK; + } + ghcb_set_rcx(ghcb, regs->cx); if (exit_info_1) { ghcb_set_rax(ghcb, regs->ax); From patchwork Fri May 31 04:30:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681128 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2062.outbound.protection.outlook.com [40.107.237.62]) (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 E6C8C823BC; Fri, 31 May 2024 04:34:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130091; cv=fail; b=gANCK0/+IrgrB0eR6UhyJg7xSAlRnPn14c0799GSfcpjQIWhPVLszOqzAPqb9+KPsDO+GNZxyg89MZsokYm/LPH4ukOwo86JUgQyUJyhtcmEGUz78+gmszOGQ4+24RDlfFqCQvbm/nydvWDPV5LK/3GaGCr7vBucfzOW7d6gReQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130091; c=relaxed/simple; bh=Qhaju30KipVL3Ll8fiKoLEqeztNPGqtph/BGVhSyR00=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P+2QvwCjtK683FvF30nA5gUv76J5EdHeeM/XZMlN9Lf2W4wRlHclncS7BXua3s6CK3Crua4ZYGtNv1A7eVSUxS2MoAmf5fqwOFKxl4AZNEQWuF0t7qFYEJyIfvw3pA4SB5EeBhq8GWkmvZV0AU/9en/RLh67OF0CeXqbQTrn9z4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=mqxqcnqx; arc=fail smtp.client-ip=40.107.237.62 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="mqxqcnqx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XU80TUA+KqrFw8thbC8/HSX3sr5cdmnPfwedzxjrBUAT2hMdPtWnpNhl3S3jF2aCb/WlxVyMka1AsAsDYHpTgFSDFXZ1gjIRiuf6hE/aFkwDaknPo0WIkftAmxIryBt29piblJ4rhP50sGHuHoxqbhyMYphLTlQcChYzXxt5ZlL7K8N5usJxkTctQ5kbCoiAo5TONesCY09bq67PwAA7m3jWvnd1PzQeuprOm+Ck4SqMdnKnSbsgbPF/1jtM86ABE61SyiGqJvESq4Xjfet3HzpWcz1IlcjbxsSQ6z/T5H9/zC3Bs77+qXlshdNGKvnIy/n7ToW+OV5nrMtwC+6xCg== 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=cqwMbsLTloE6koXkAIOHwo2P0VGFRONchM4ZooyM3iY=; b=Ml7VVGVrHfirmqhVJD+TAvkl03lmzKYGGFNPL5FtqYl0j8xuYjvx7jwLpmcl/G2hlTv+PdihfmsKOlR9vAqJF8LRo2eozogQZMi/TtzOjVPVylxWHwG6OOmn60crtPleX6OEkwnw81RP/yjSZDDNiKGEX8pB53mwWfQy2JtXrE/TBdMr3m8NuRRhp/OLsRNp0KybOtc/Bft1BBLrpZkgOv+yveRsYNRvD1r3osabPjnZJUhsxyPEoOnV5T3Eso/WMGHdXlwp69SakZ/pbq095BsHscQzEA38fp+itfp6OOe/6rSwL/6p5wpV5uV5v0jta2OihJ8KA2etNXmfgNLMVw== 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=cqwMbsLTloE6koXkAIOHwo2P0VGFRONchM4ZooyM3iY=; b=mqxqcnqx0cBnC+/1ulozspS+ZYG4FhdhVu64h6tKQ5yqiw+grn3m61BndMcgaTNEQB59nLjlmSFrF3HWIo/CmJ1oSDPHCRX2nCb87CFu1FNxsRJZwpaGR1ddgvEBcU1kc2sfDXmbRYnnvtszntk2QA4k0qlIEdMPfDR2xjuIdso= Received: from CH2PR07CA0046.namprd07.prod.outlook.com (2603:10b6:610:5b::20) by MN2PR12MB4424.namprd12.prod.outlook.com (2603:10b6:208:26a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22; Fri, 31 May 2024 04:34:47 +0000 Received: from DS3PEPF000099D8.namprd04.prod.outlook.com (2603:10b6:610:5b:cafe::68) by CH2PR07CA0046.outlook.office365.com (2603:10b6:610:5b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22 via Frontend Transport; Fri, 31 May 2024 04:34:47 +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 DS3PEPF000099D8.mail.protection.outlook.com (10.167.17.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:34:47 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:34:43 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 20/24] x86/sev: Prevent RDTSC/RDTSCP interception for Secure TSC enabled guests Date: Fri, 31 May 2024 10:00:34 +0530 Message-ID: <20240531043038.3370793-21-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D8:EE_|MN2PR12MB4424:EE_ X-MS-Office365-Filtering-Correlation-Id: ab0180ac-01c1-4996-7b14-08dc812b0080 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|7416005|1800799015|82310400017|36860700004; X-Microsoft-Antispam-Message-Info: IQMvkIeLADztyziUK7JbWdZLnJNqgYYBYqJ/uIFG6CtmqDWJiFE1oZbJ0vJh/iNPNwo6fq/0CfhOkKF7t9vC1AZUkmUYKZSItKfUbMzWqUchP64ZZGvF4nVmfu2EMU0Kytvln0cnhMb/fGkMSnkITN7cq78u58J4+Aoh3ZvoR8TuTzOpmB8gZ1hL0Yxex60GE9w98ciobrlsPfxCQucrQ4p55Wtht3dmFvnFDEaqifQojFg8Xif/TEg4NzT/4na2bCFhPvHaHQPAG9xz9VvXOeksIReRH+1ThaNcraciXmaAxwLZvFHfVhruGcYQm0+88BqGw4yrU+zxqDt3ykMrj0EO6e7rVsoFpMRkWeNcvd0maHj/fMuge9kbMeFpb4MZdIMfFk6kRKnTUan5iKJwcHm11p9RW9GnxAdwBYR9hvBCMV8bZTauDfJ4ItY8pjOllJQA4pDXO+uncauIhUklw6tBm3Thth0dUzcOYeq5I3Ie+LHPq9jDjfdTKvXkXeeAnSoS9kM2VJ1HEQKdgqkmBxnp0AsAQfaANipv3TzK4gwwbwTlybKaqx/DXVY+jY558TXhMeVv/E+dj6fFS+QooH92I2b8GFmjM+AaMb4ptErpooVChtylVqrQPeKoAQIzGtzJuosRHrStim3c0SqO2l3z8w/rJpfkKoRUbZ3Ae/wlTkUoHMkLRD4KBsvPj7XEen/DYsxpnd/e1cZqMEfgBs776GlYf8YXUCU6z7LGnD5igeN9i3VtOat7EfyB4YqdzwUnggEox/nCRcstovN34niydPtxyEpmQP4RyiRE/qw4IEu6gy0NgNU79ulU/3Jm8ryOqNf8m/OAZOiTjdSGZB48qAIl7dNuXM6ba4w5+WoYAsViSM8q2ypdLGPzIR5mkZCMvd3eOtMQCbv0ukklEK0cNOCjl2rmYHCl2M6VPyGAhZKXOJoYx9wbHPOIzga0j1Xqjs0Z+mIOnR8ohr7ea6mq21RV4LRBmrnQJJ6Ewva4EP8761f4JmPcCajHgdoW2wVDIacieTd5aiF/ec6gjnK3Hl+KborwfT95q9bfEUt9DAXVe2zHXyBIGj7+mHfsaGc7GCwYxbhHU4/v3X7F92XkYasTkPY1TKfcCvaVFz98Y3MfcZk7JqGzfPrJ0wxQzT/zDqW/5xpmp3s4UGUKvnujizAGRt5TnLfUVvptxM/12oOa/dQGE3QRfL03LuaPzVJIoI2h+1MHuoDFjER8Wsdkubah6i/pA54uT3ptaVwqdwHxYL8+7hRvWt1NYOdPxfYMWe8VEN6iBx0o+ALI12vooqwdNdMdLTPNCfGqgO1MpGpE28JC14ujgfOX3r01JQzQmE9jE7rZinTZ7wfSRZWjCY0DnNtzvPHay6DQYvc= 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)(376005)(7416005)(1800799015)(82310400017)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:34:47.0983 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab0180ac-01c1-4996-7b14-08dc812b0080 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: DS3PEPF000099D8.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4424 The hypervisor should not be intercepting RDTSC/RDTSCP when Secure TSC is enabled. A #VC exception will be generated if the RDTSC/RDTSCP instructions are being intercepted. If this should occur and Secure TSC is enabled, terminate guest execution. Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda --- arch/x86/kernel/sev-shared.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index b4f8fa0f722c..58888a086dcd 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -998,6 +998,16 @@ static enum es_result vc_handle_rdtsc(struct ghcb *ghcb, bool rdtscp = (exit_code == SVM_EXIT_RDTSCP); enum es_result ret; + /* + * RDTSC and RDTSCP should not be intercepted when Secure TSC is + * enabled. Terminate the SNP guest when the interception is enabled. + * This file is included from kernel/sev.c and boot/compressed/sev.c, + * use sev_status here as cc_platform_has() is not available when + * compiling boot/compressed/sev.c. + */ + if (sev_status & MSR_AMD64_SNP_SECURE_TSC) + return ES_VMM_ERROR; + ret = sev_es_ghcb_hv_call(ghcb, ctxt, exit_code, 0, 0); if (ret != ES_OK) return ret; From patchwork Fri May 31 04:30:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681129 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2072.outbound.protection.outlook.com [40.107.220.72]) (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 697E4187572; Fri, 31 May 2024 04:34:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130098; cv=fail; b=J7Y/PwEdgBy/7j07wb4KG4L49oxUXqrwGOon9+RzoeIXSS61tGaNGzEevHQXW0xBLasrd+HY+aSiwy/msbnwPOJLLVUwG/SPY3BZ9aLPrvgIpei9ZBvn7BF4yU/7xcZRzZWU7i8ZYNU1AhmaAojTHplLgeFL1ZFo8c6fldUHJhA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130098; c=relaxed/simple; bh=wjgsaMYeT1GD78TxdoMUeB43JDwnow8CRuB1a5G31SY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=p3V3bot4ueScWZzSXLg3TzSDjr0fdGUj+FRFcSWy+JKql+nfO0t8pAXuW6J/DNjAgqb4Fu8W9dkqnlm23rjKrtp5UIGyPr+8TSQj8rx+ZFYisSRP98h5M4gRIZelnj0W8et/3RWZgiAKiAcS2davPkuGcmGh/Qv+9KzYtTnOs+w= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=hhJHTjZO; arc=fail smtp.client-ip=40.107.220.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="hhJHTjZO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AI9XakDAJccOJtmrh6ibu5CuDsCEtx85uAYJJtQlmrHjCHSkZ6/KORSOV9mb1Up1F4iGd7O3Gbhns8XpPtb6tx7OCjBViYRavh0c26gX6ZjYdKLjF599X5wR3AzN4d7vsyJUw+d+MF07Y9IzFht5W+roduSqhfNYop+Sc9P9HIlUQNhFybb9+yyOiiLf2cfVHKP6/Du0tI8K4QgTWTDiN+xZTx9RxvSQkzr5Qh1eGBYx+imsA2H/Aw8Xa/A3kf2ssmML6IHptJBBC85Yy0fxiMYlqxVJGUdaqXbsC0TjfLOG5rdKNoR1J22qGvTWnjE4LEtP6kAAUBZoglhB6aWlNw== 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=UAaAbe3aro4EM2xBQdGp/o69Ah/mnZD76EyvwIMZKr0=; b=lzGnVYNlV3vKtV3sgvcKgcgleSuzke4Ov5G0lN4+3uZyvO7NZhAPSRotPrdHx3ME+4htsfq48sRArLAgkyXMF2gn5oMD62lWdTYhtAssovfVb1fG+s04JTnRgbTx4YIFYpQWz3pDhNwZw/vw2KQ6tV0CFDkn+z2fIV+zkfUYgXCLQABCWrtpmkXt8Qv4qiO/BGf7Mtbtg4wx4tZiZPEC49ieP78oQ9fsm5MESgi88ry2XgoVLOAWej0ZSbSX3CpbA62lLjlMfBrDSc3QzX4DlHFZTE0GOHCiR37/Pjo7jBlHC7wT2ncr56UOQekbCHNb/lyr5YhFqByCnRH0WVEJZA== 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=UAaAbe3aro4EM2xBQdGp/o69Ah/mnZD76EyvwIMZKr0=; b=hhJHTjZOPJ4M9uFVgC26T9YdfNr+I3hNJ/9qYfaX0G3ZToUtCe5RJ3h/R7uVOlKjjY0Kg8Ab7fnRbfLKBnobh1cq+dRyKy2JvzCFv5ksJ5j7daCwAaKh9gdUspDNEaQ2Y0Mg3BPZ06TMVSj2MBDPaydiqhbb8E4Gn//mozGO8+0= Received: from DM6PR08CA0054.namprd08.prod.outlook.com (2603:10b6:5:1e0::28) by LV2PR12MB5893.namprd12.prod.outlook.com (2603:10b6:408:175::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Fri, 31 May 2024 04:34:50 +0000 Received: from DS3PEPF000099D7.namprd04.prod.outlook.com (2603:10b6:5:1e0:cafe::a6) by DM6PR08CA0054.outlook.office365.com (2603:10b6:5:1e0::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22 via Frontend Transport; Fri, 31 May 2024 04:34:50 +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 DS3PEPF000099D7.mail.protection.outlook.com (10.167.17.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:34:50 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:34:46 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 21/24] x86/kvmclock: Skip kvmclock when Secure TSC is available Date: Fri, 31 May 2024 10:00:35 +0530 Message-ID: <20240531043038.3370793-22-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D7:EE_|LV2PR12MB5893:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d9619f1-44d7-43d5-c642-08dc812b02ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|1800799015|36860700004|7416005|376005; X-Microsoft-Antispam-Message-Info: vMqFn3yiNJCkV1Gr1r+o8GqsAE3DJGcERatRsHP09qqqHfgtrdT5TYAzgkHeuXV9UITW+6rlOEMcwvlovMweQ4vcOw8hjHsrBa/b3OT1IyW2v2W0NMTz24DeEJUTcqZYdGzz/PvGl+TSRHyo0X3oP6aHbJ+8sBJ35BT2ZWAHq7CuUt+SZW+CpT0s2kousMFxCq8FHyqHXFpMTyeSZSHWyEjED62MVUF8tZM7PNZg31eN1xeQ2NroQIEnqYkHfjl0Q+v91i2LgeXFpnMhEeEO8Xv93AaaQKi4dUkKr0IZ2+XH/ZriWfmYQCEbmblyZty4Cjzv68o+P/oObVCLnZlcT0hibcKGxvoLocGhpv26Z9ehTON2bsAQBZnTmRtXs9XXRb+KTRab0Mrf7WNrcte1Nuyr0qz2/2LPLg8LfzQIRaAs1e9clux68dFMfZ27v2OX+R7496WD1/3tw0DYnojUOA6S8ubW29OZX7o4rKKtLj+dassR64Q2feNZL4uM9QwkPwQozFZyZ36sbUUOMzJelZspIXA06LQM+v5fJfRGQxwPkNagX24GsJosv+1BhtEieAlKFRrsO7Qvbas/3P1wDZ0+KeYtkGb7YOzsxmXAhLGY5fwkqPeAU+FqvPGOt4SUjIjxp3VjacgiRxLYRdp0MnLAy66rEkKMAWQmvxbtiRc+bV69FTNWjidyoBHi0D5vQkqbwqRgXI5j2cq2XDCNGZaB21+FyOlXjdgDaggYGom8GvDqsanw8JA7U4UJTuh7lONvc2MRQCk6iocXza19H2xjtbpbhHmTE3HzvM/2lFF/qjSOyuKyFs1N9fMN9iWuPzjHTcrXwe3ny8YPC7wENx3EJqRmmDIbhtpeXfc68xWkPOR9JEB7sHYm1Y/Bg+VtfoowSHzGlAX0CVBw7/d4bbYAa++PAmVwEm1JjjccMcW026/gsfz0bEP13OghGigDnI2GmR/zvWPUkAwCkpvrI9/daJLTMgbGj0O8nsYMLWxfOycvvF7OxMLTBYk32f0Yi6qpOF0U+qP/xnrcJnN7YhnSRRhvOqGbOwqnEmp7EYks2FcQAs6wGebV9l6Q26Crhqki9XvLvUL+zPojuQf1Cpfx8ORFSwvHlegr/NcG65/E+6SfsirMK3NLkNVZumc39y63q9ZcbL/v3UVp1u5t5au2ugRm162BKz45gFxngqcY56fF2eybTTO6A69ureBh8IfKxFeEVGnM8Cm8W6i7+IjvQJ1BjQfxNFIAIetfnE90X/Dnr3YV2HZ32IfrFiyfmzLVOuJrfB8YSx8cJDmh2+L+d8//LBXZo5Pbn2tOeQQJkmSQg/471s4vKh7ExeLEmcrICztpL6wSSyl7hLOkixWoLGGhOkS5W9BBFZC4TIvOxDsuAS2k95SCubO3mr56 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)(82310400017)(1800799015)(36860700004)(7416005)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:34:50.7571 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9d9619f1-44d7-43d5-c642-08dc812b02ae 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: DS3PEPF000099D7.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5893 For AMD SNP guests having Secure TSC enabled, skip using the kvmclock. The guest kernel will fallback and use Secure TSC based clocksource. Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda --- arch/x86/kernel/kvmclock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 5b2c15214a6b..3d03b4c937b9 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -289,7 +289,7 @@ void __init kvmclock_init(void) { u8 flags; - if (!kvm_para_available() || !kvmclock) + if (!kvm_para_available() || !kvmclock || cc_platform_has(CC_ATTR_GUEST_SECURE_TSC)) return; if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE2)) { From patchwork Fri May 31 04:30:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681130 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2040.outbound.protection.outlook.com [40.107.244.40]) (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 DF4D080635; Fri, 31 May 2024 04:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130123; cv=fail; b=h8d6YQiqZKXC3Sou5Fj4vsxRdnUjRsR5gD9EoLh0s3BSFykjlOot0bEcduqt8wBu2RJjZ5IGSklR1m/sNh9nUsFj3F2qsZL5HbVuUZ2paRGIdTCDNqQjufBhsutGBj84slEIGfhowcCzJx+LIbi5RdATzIoxe1G8EPpaFeteXKk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130123; c=relaxed/simple; bh=vnPjgsazrE0DLG/RAQFERCMwjQJODdgEwWkp1VPdOSg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MYzkOtN4OGmmToxFb3zB0YK/PZ78VwGW8sAoAGJtQXTEc6XefSTsErAtfYJbOTl5/IWpSlNb73+VhTDo+nTO/vzDdf0WfkWvNtT5NVcaFxWQmYkYWFKM+h6ugVfD5s0L2rAy4fJP1/PNFcyTcVV4KrU+AWxGMEL0sy0Z9Fe6h38= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=nQiM5mja; arc=fail smtp.client-ip=40.107.244.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="nQiM5mja" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kIVcmELYfvONud3j4LmqueE4TIrhpTUqOYt1n33zUZZbqtO/73D1QXkftYEIRzVuZ/GMVoVeq/rpStzKXyYKu6hBtKblIgAyUKeG2et3hjX7Vs1sJ78Eh683gWTh71xwTwWuhR1SuuRLIP1AeDvFfcTXxbsqcERCbykojL4rTE9PVai1nB5DmB76ublUFssox2xxCP74B3CnxTrXw334ifhN1qarztDWYXQrwpgMNiz51GEeVc5kAafjvpgSNuKfVkA5y16CAi0Px50flG4+FRzrYR2L1aC5+zXdMjJ3c0MVvJBjWsxKkBzbnB/rJZPP13N6knjhmphJGCyWMp/pWQ== 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=E6Lxe5JM+FwSNitnLsD3ANphwWwHa5rTM9keIbTAN0o=; b=K2G6IWYePPmAMPZrkwTW0vmROcw1jtW2jF0K4MFMy5Z5wPmSHMsTpskkDRS203giuSMxHE/2Dt7idp5cBYQYyoPusr4BijttaXtCKtThJhLS5y4CYsmWg4UbZUdHnIrvp3q1UX8PKLdss+Tpr8YJJWlN4G1lIBlPGbi92UMeTf5UpDbZOEBDyvpRl8eIR9UhOXD10ExocFRLCRbBOUtf/FhXAJ4t36H+Foz9saggROKt56Xsa8WQ7lhOSmNHQl221pne5xoWKDm9xy/KmVL3i1f+smPOou/caN8q+U/y7Z0kAw49lk7jCLGUDJ2lXlCjr1gi2hAKdt6oI0ziHz6kgA== 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=E6Lxe5JM+FwSNitnLsD3ANphwWwHa5rTM9keIbTAN0o=; b=nQiM5mjaLhb8XVlcVS8efT/T2Pup1VcqGCRiy4A54Dwis3AC6maEZ8B3dEWCpUwJJFsSIqW9p/VeBuUzsxq6bmHGJXflzwetFjIzWdxEfALBwpPZ41NLEChR8C8DFHB7l1n7zd3aWau+Y0dz2oFh1We79dTnNDZLKp4GhtC5ozQ= Received: from DM6PR03CA0013.namprd03.prod.outlook.com (2603:10b6:5:40::26) by BL1PR12MB5756.namprd12.prod.outlook.com (2603:10b6:208:393::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.19; Fri, 31 May 2024 04:35:19 +0000 Received: from DS3PEPF000099D4.namprd04.prod.outlook.com (2603:10b6:5:40:cafe::91) by DM6PR03CA0013.outlook.office365.com (2603:10b6:5:40::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22 via Frontend Transport; Fri, 31 May 2024 04:35:19 +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 DS3PEPF000099D4.mail.protection.outlook.com (10.167.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:35:19 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:34:50 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 22/24] x86/sev: Mark Secure TSC as reliable Date: Fri, 31 May 2024 10:00:36 +0530 Message-ID: <20240531043038.3370793-23-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D4:EE_|BL1PR12MB5756:EE_ X-MS-Office365-Filtering-Correlation-Id: e857bd07-0a99-4b32-99b3-08dc812b13d7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|82310400017|36860700004|376005|7416005; X-Microsoft-Antispam-Message-Info: Bqz8vnDFXAMogvlQjFPsC3qKR/dXVL/jx5TOaio/J5HAp2KqClZU0hlkIU0FCvoYsQ04VEIYTUWk8PN36HGniw8E7RotAIxUDtGeQ6tPWm6rXA8D8yHrzOYgJTu7e4R8Z6NcwRbrxYNPHt+rj9EFi+OggQoHpWhIHyoLQRRrj/V78NFpO2OclzcvABE3QF2Adh4Zo+7pwkCj47n5rJ/AaC0FO8viXUz7LK2IxCGtuxPvgAaKgbIMumQDdUeMSQlUcVIbhXZM68FzpCKvxdEoteW6utOGqtS3JwqaDRgnS6SgW4g72VuWCEbXUqhtnAomzWkIww70FLC7G2k9h7hjFzCdg4yd1pDlLDlk+y6w3jeFtxRZoC1NllydzOU4fpixCL06RrWdhH8J2wwnTQpBFS2lGJxhi0imhyT7nPcgC9vLHnxWBeq1wuu/N8wb7cw4AcMRqjVb0fhJR1gT7cgL8rCBNZy/zOLtSDCx2h29UkNAgfNk8tZw18MPmc1mWKlCSRRiPSF7bhgoDS6ltfeMD4UPIkOhibpeAmjtScpFpp3RE3gzhIS3F8TNoqva3UV0qd/YOtHYseXKhQVcUt7s3TrzI8CuCpfTivfE4Gl+/cqANcAJb4LPRdHMExLynjfx6qPfT0r9ajdeWvnbl3oTVf6Kt2N1U96kmWd/PKLXRG71nSmE8BvOmZxgHdTprlEVks5F82e2B7O/EGj1c5cGIxyKh3F/fXZTK6C+166XFrjtaEQZtZC0fxKTzRfIyb7TH1ihhI0sPjAR8/cuS7xj83vB44AL7Sa2L8fH3vX8UJ95wQM0L/bhmQmOAK0GTxrrXnCd3tyTzZ9mYVv3lrwcMeLC4eZQi+tPiz7SEZUvps/xyOU9dU+V0xT9R0yFo719EZ9y+7bPx+xIeIbj0/suR+UkuYKbisNibZ6ZGXoBpMhF2YrQm0hYugoe9qZXUvEOrBjdvYi/Las+pD9Aa96B2M605UJaM4l5TWTE8rGdgsF3V8FUaGk4d2QJqy1akshqx0OxqN6F1lSAtnOcUUMlE3Tw8tZebfNE+H4aPy3vJjY8cSP6IOVNz0F/pQ58PIjx7RiqHUlTGGzsmUhFEY6jChoctim+oc1C5TvgZqQdcbirRoPENnC1ZPw2a7PwgQ+ltcOs+uaddnau6XbLPPjYDV99E6Z9YQmiGMzDof+3Tf642R0rmwvu2BDdjZpHKaaolAftnZEqlDKSlPEbCbHdZQCs9/FdfNmMy4ZKOlZES6sjxHKWlm4rywuoaOokXxtcpmEzMmZBkJqHMNtfzYl5KNFa15ROQgrNDaJjHn/+onuzWoBMB/PMlzqUryjJpzTW863dDrlmuTMtU2H/5tpX7EMNaduGJNS77Kiz+RbrY/AJlp1IeiN7oNeUUgwtFztm 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)(1800799015)(82310400017)(36860700004)(376005)(7416005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:35:19.5147 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e857bd07-0a99-4b32-99b3-08dc812b13d7 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: DS3PEPF000099D4.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5756 AMD SNP guests may have Secure TSC feature enabled. Use the Secure TSC as the only reliable clock source in SEV-SNP guests when enabled, bypassing unstable calibration. Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda --- arch/x86/mm/mem_encrypt_amd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index 422602f6039b..e275741eb073 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -510,6 +510,10 @@ void __init sme_early_init(void) */ x86_init.resources.dmi_setup = snp_dmi_setup; } + + /* Mark the TSC as reliable when Secure TSC is enabled */ + if (sev_status & MSR_AMD64_SNP_SECURE_TSC) + setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); } void __init mem_encrypt_free_decrypted_mem(void) From patchwork Fri May 31 04:30:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681131 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2042.outbound.protection.outlook.com [40.107.93.42]) (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 2F5F978C88; Fri, 31 May 2024 04:35:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130129; cv=fail; b=OIluAZN+Ao3Fy0UJBuvqmUb6/K3UueC3KkOE2+BsDgVgYSM+bZz+7qLUv7mlOHiSkl7pNAT+ecX0q6vHgFZ0Pm85UCfbGrSZByeQFjkSG1aUUb90/ZhwQwoNzgRIK7RA4usPgS9qCG9CiuXcMPpGJ7BlTg35IcGNrapgwSIJ5vE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130129; c=relaxed/simple; bh=sMUEgS2OAgLUi3hCkfqVE3W55RNR9QGPfw4LxwPs2VA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RncX1fgy+tPt31+/odWeQ++DhvdX2bqvpbt2xTgxnMLovMw0zSRtNphfJjvzrlOCES//SYpGI8NHv7nn49r1V9H+9w99B0KLGyyWYx3PSwy4Z5VBMKgaPMYosMjoIctwmAyqDof1/BVwLVnFq0zkNFTFJ2qVJKLSlmRAXyXy+Ds= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=nx1NmRNg; arc=fail smtp.client-ip=40.107.93.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="nx1NmRNg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K5Q9mXq1fKeUsTgLAhaz3E4DqhD8s4KIiuBLIdLtn+S5dvgTjSOn7P+CGl3APywvT76JQbqVb+0PcKkggWrCgmoS3AJ2QmxLOsw25N5ZCL5kCss11O2UORYduh45Xglmu0R+ODQEFuhVJYzsqK1MtYJifsegoTAvRZPylVxgM6Q+1nXJ9FS/tfhP6cmKdnt2YVKiV61nPguOLBba6ZwUymmkXX7A22s142yg+uqLIzwa17ZSd5oglvCfkNpFO4neb75WvopCwv9QDv5qCpKpCCJP7RIFr0p+Ir/pAWD/SdLTHq0syLIHfQxk9babvr0tSLXy/76Xz72nLs5UindvTA== 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=GxzyqnMqVWcls0UcDrE4oX6b/GsUu1v5GwYmfO4Rbxw=; b=Utci9CKusG8vT5nDQyFGNOADu6NbzX9ujrXHjEkKosWRv2ENGyZVcfZfvbUPv4lqfY+i5ofcSuQCgrf7Jrv0Pv4HhPcgwsyAUTn+mefCBiZYC/BGXq4wT8gLI3qBHXcEfi/A3xDCvwO0f5GJUgA+S20fNk3dMkUOBd0ZC3d9GxRyqFwKL5U56/+FLCk3oqvPDuC6Mx3bQY4p2/vWF0wx8d4otMBT1lBWL6DU/p3vE30BDZlzmAI7gcxXAytimjQf2tbaGQxAayt2CmCUCdkHYtuangYpy1ce5odXsLO82SN3+Y6H2TtIgzDlMSeU10oomU7IeSyzdFdLXKNssLMRXg== 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=GxzyqnMqVWcls0UcDrE4oX6b/GsUu1v5GwYmfO4Rbxw=; b=nx1NmRNgkEUmqHbPNiN6N1WZRPeoDBPmRBsT4SfqILvkgMkHRcfBAvv9s4JO68AfbwHAOE42pjiqwCsKojBGwHm97ZafbJzgz5noFlskLQOp20ILPmQSt6uD72OxiSK22hJzChiCK4LkqkxyWYQM8XjB1l3ewRUWBt2dVr1VW3U= Received: from DM6PR03CA0011.namprd03.prod.outlook.com (2603:10b6:5:40::24) by MW6PR12MB8949.namprd12.prod.outlook.com (2603:10b6:303:248::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29; Fri, 31 May 2024 04:35:26 +0000 Received: from DS3PEPF000099D4.namprd04.prod.outlook.com (2603:10b6:5:40:cafe::80) by DM6PR03CA0011.outlook.office365.com (2603:10b6:5:40::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24 via Frontend Transport; Fri, 31 May 2024 04:35:25 +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 DS3PEPF000099D4.mail.protection.outlook.com (10.167.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:35:25 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:34:54 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 23/24] x86/cpu/amd: Do not print FW_BUG for Secure TSC Date: Fri, 31 May 2024 10:00:37 +0530 Message-ID: <20240531043038.3370793-24-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D4:EE_|MW6PR12MB8949:EE_ X-MS-Office365-Filtering-Correlation-Id: a1bda054-1237-4f32-9299-08dc812b179f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|82310400017|36860700004|1800799015|376005; X-Microsoft-Antispam-Message-Info: 5RS8HSc2E/OCDat6Rx92pHUuBgv/kMmsGmELsphdOqEnygsQaGBPgy9MTUOYDY61ZMVrLnQayJa2gl3G5S+B7r4390eACezyIH7qJJBV6JIlfk7dzVcuIO8bTvDy6z4HtJ5uUMeN8VnUA7vLt1GIKBk+b3JTKD9R4ZtmVuH8ydbo0NxXIJ+sW5Tn3jdwof1ZsKwVYAftRTVJz8TSvb6HUNs3zTzQG5OivZ0GYfGTSrhWfHshsCwBtwhkBC0a3VJ+P1gdUmzVgZC7lcfqN4oXb3SOyGtqufEca5i42aTZnvpw7mLfq+VDnRTF6uewnVTxTD16TGEecAE+qWKnVmnz+EPTzzya+fZDp9vErVBcq5260DodOygzzxnPkIS4RkAzBAm4j6Hn+Urv7X2GHFJ2ht5QMXOS6UcpqvyGe2C9GItYIllUmyNU35UuK4XMVg6/nNeVPt2A59NuLO9uufCXNfC+iydUTwug0dXRN49crvMRuh7DFiwToiH5XAefeaGDHnmb1KbucrqTAQvA1t6p7zrg/GRO7rCgcTatlZ08zZHgB89vKqbAB7UX/1xAOkulhlcTc+NDbTWHLzNT4cP0CNocZU7TwXgimnfu8mGWq87D4umnQzrnpRCYO0hmIW6UUgayXaXXORrXafRIGVUt6c1XIC0DcAWsNqJEjWBBlcSdUaffGmXdElM1tJZJyirTsbyuSwHdnUVCuwGFieXIzWN27f5Naa8Ae4z5amD7akaoUblFzaF65M7fClrOlsxSmrxYIDPlchnuPQQGkVTUcADnOi1AwNWdbKMjQIM0VXXmxwfzahfQdc6KMq7B/klc8Gb0JCA2srQJIlgrBjzEbusA7d+CCCL8aX3T/0u/xhuuu5rqfYlGixPdqJb1hAa3umPCPinrYdzckOIXq208OYW2IXz1KKhMtaHxBEyj8sXzmCk8ALOWObwVAwZs0Fz89io5x3RhYG5fjTjMAXbTWo4/26Crs6VxMvXoAfkNPJ5HdClXDBnOwCE69Il1mlwio5E/DE/YxacXMIYkmV9mi0dXP5raFrCUcIiHQ8UYXVmPVPzpoqC8uPAsNcOUlns5I6SMKH75CkaOJxyEGqlfVAgQz6h6gFj9P7y+Ici5jIj4XmYF8x1twDOAYi8aRDsD2zvrpMwLYmwq2/lNUZyBY7T7i8WUFlwcYRS28j/FAo5061TTXnEp58hxzueq2WfZ8sox6EmAtN/74Xvjp4vEYYvGrh2DNqzH7nNhaRwPXjd6bgKs7YqksMqPeXWGJnBlABn/xF2j90Rs4ocFosIS+T5sraRQDKs1Ky1UboivVFskwse0dWgVvmDY5UKirC4k0Z0iCBYTgNrk9g1MqnIC1zVm9M7Y474ZPhZSbEPeQy7O6/PtGtC9ntiB3J1flJWf 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)(7416005)(82310400017)(36860700004)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:35:25.8897 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a1bda054-1237-4f32-9299-08dc812b179f 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: DS3PEPF000099D4.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8949 When SecureTSC is enabled and TscInvariant (bit 8) in CPUID_8000_0007_edx is set, kernel complains with the below firmware bug: [Firmware Bug]: TSC doesn't count with P0 frequency! Secure TSC need not run at P0 frequency, the TSC frequency is set by the VMM as part of the SNP_LAUNCH_START command. Avoid the check when Secure TSC is enabled Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda --- arch/x86/kernel/cpu/amd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 44df3f11e731..905e57ca324f 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -370,7 +370,8 @@ static void bsp_determine_snp(struct cpuinfo_x86 *c) static void bsp_init_amd(struct cpuinfo_x86 *c) { - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) { + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC) && + !cc_platform_has(CC_ATTR_GUEST_SECURE_TSC)) { if (c->x86 > 0x10 || (c->x86 == 0x10 && c->x86_model >= 0x2)) { From patchwork Fri May 31 04:30:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681132 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2043.outbound.protection.outlook.com [40.107.243.43]) (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 DC84778C8C; Fri, 31 May 2024 04:35:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130130; cv=fail; b=iftrvCj8wfNGkM3b5JwGZrtsYKyeIJ4y74nLb6dDmVQyF8mdhmsSw7nFfSVJFU4lBUl262q4dbIlGHYqJqF4Fh3LiyV/VnKHlHw8SCT4a53V1BZUrm/OKUAV0d0W921Y6QrGDJGh4qfeT9fJAAnWJGW42THQfnlLy3LAK3zcLOA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130130; c=relaxed/simple; bh=s9ZaVU6rUpEL0ipla3Jmedzbd+/UXlp0Tr4hvBroiX4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t2VRILMHm0xo+YO3mDktROU3aAMymdWXV+y349TpWE/GdW9I0FzG1lXF1UyTXQcLROdgjILd3DUMet8ojRELcJVi5fiVzwEiBK+EJIfjrFEwYGxMVOQ9TvlQZ+umiNDgAeTc3S9X8To6KLHKodxeZOCfYVXfGp8PK+oxPacQpNw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=jO4tOWzq; arc=fail smtp.client-ip=40.107.243.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="jO4tOWzq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gZdg/POCod5sI0ko9gazNXaBz3108Qtsd2/VE5716jsD70nXZ14z69guuexJZ/YtIJTmep50kirKZmSv0Sy83eMOlYDvKTbGMLJJfO/BD9JJn4ofX+2y9MtCQq7kiTc5m6Ue1eGi4rxDb6sw0h9kLSTh1WJsSKa7NRrqkS79fR4P9eL6l/Jswj5oTsWRrBMaUL7arJfzDqKLAc3RgZZE8W2qOUfSesOFN8Cl3jd1YT/DQA8O56wI/E0tyoQj1UA6yq3APVtCv9/u5sCYC3aMuPiNOvngcIozXoc/6dFcZ1p89TFtEtIBcdbA7YRx62w3/I93UpPVDOF40Wj3jhwouw== 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=l1ysbsAln7bP/WKAos1tZO5uWElhxX1Y/5p1lLqlJ2s=; b=MZQSS0/kIvBKARJlXtQXrWrYci7AjrUMLXmXKoxj/5xNHAX9tYivyFGX/YMp7mpcqbYjdUm7hUMN9va8CpyASZqdBuSOyvVwSZBElNuvo/2uoQvjHhQ3vxtuL/GHd2A5EqfoKhFWyxKYdELQEI6EVlxwbGi9CPlV5yCg1uO5EfECYJKZgPtW6lLYcdqF31oR3gLPNI//rdUbvvD7WbHFxJgYhErm4ud9CQ8+K7JMXLQTf55cS+FdW55ZSOoQDvcnNzQtME63Aj1otpbUwait+1mPDwd6qnpqathpWmMtUlbTQeye/zkJSkwysPTudz+kgYfL+BM6ZyoI3SE+ZZULLQ== 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=l1ysbsAln7bP/WKAos1tZO5uWElhxX1Y/5p1lLqlJ2s=; b=jO4tOWzqx7HGvlPoGMAt3O4oY2bGemWu7rc99Sr6xgR1tFC35JffFcxWnxBnOs0rP3U9mEil+ClPczikLc58RFGsIDQW1zlB1Ia41LBBUCD/kawkB8lBDvexaAuyDnBfVB2Vxt037tuUbKU7d6V0fmD8otlOUp+7FbkLLAW2bVE= Received: from DM6PR08CA0064.namprd08.prod.outlook.com (2603:10b6:5:1e0::38) by DS0PR12MB7653.namprd12.prod.outlook.com (2603:10b6:8:13e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Fri, 31 May 2024 04:35:26 +0000 Received: from DS3PEPF000099D7.namprd04.prod.outlook.com (2603:10b6:5:1e0:cafe::f2) by DM6PR08CA0064.outlook.office365.com (2603:10b6:5:1e0::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.25 via Frontend Transport; Fri, 31 May 2024 04:35:26 +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 DS3PEPF000099D7.mail.protection.outlook.com (10.167.17.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:35:26 +0000 Received: from gomati.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.2507.35; Thu, 30 May 2024 23:35:22 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 24/24] x86/sev: Enable Secure TSC for SNP guests Date: Fri, 31 May 2024 10:00:38 +0530 Message-ID: <20240531043038.3370793-25-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS3PEPF000099D7:EE_|DS0PR12MB7653:EE_ X-MS-Office365-Filtering-Correlation-Id: d369892d-c5c0-4e14-ea80-08dc812b1810 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|7416005|376005|36860700004|1800799015; X-Microsoft-Antispam-Message-Info: ZWFbvhTDWZxCpHegyv4k1FBk6suzcrzsqYapq9AdtTKqRGsNYkI2EVB3iXb/cEpXyfkLkzWDj4gH5PlwRAndn+K0rsOK0/KpYT9HUABXE0ZG6Lb49VAC/bL+iMvU5mgoAUO6/Sav94CtoE5JH/PYo33P+WnPm4dglq1oHAUg+69k71x3hUCmxj+SxJ+Fk2eBXp/Y1LGqujgOBoZpX6ZuPp1Q9rvVVwQdWTMu6RD9Xy4eM2AiQ4IZKhIUecrbWxng07HdCo14oKOHagPiaNC5fE4q6d+SkGe1qgkp3f5L1zeXjHZh7rksf+sw4fuBurp//YBM2lGtaO02rdyHEuIup+TieuJ9jzuaAwy5D3jxFO/1aNc1XbWRkkBnzTZ2skqPr0eSxCqAO6ph2Qfi8aMumsDeDpouXACftDpR21cBh0neoDSH6ASG+FaU4QeR3g4kvEy01dbrkMfuvGXi6PCLM9n0NxUsv10SQGcznxDrZpa3K1Vv1PiWnFu8D2Z7CpY3CYlU/WSzwtm7LUIrGJBj5LHW/r7aMOOZEJ/ZRSLdoHCoY1R1VrhpGNkR5LQKYkcGp1Dk11UvDlfaa9XYoZ7BhOxKk0wxWqfXdVwLAZ7qkvE6L9J4QivDRlqgWp+Jm0eaX1LdQCbbPeIgw1uZUh2R6cCvXiByuByUYxSObRci0qIYrnc0TO/N5xin1ZrVSTDH6Rkubx5KGv7tZA+mWCiN4dCjG9R1U/JXel7krHOOvyfLf4HD+u8iNCffDGkLzJTRLqpgSAvSkeObqot/7mrcOvd48cuXQzl3Xh7BEMrZGox9nmCQOnP3EMlcO45jgrF4tQkMu8n61NLo0GOZxLkest9M6RlP5T5b8ufZzAu4fOxKPoMhRiNewzd7l45KKtDyJ60LGWOSQnQ7IXDyOuXpT94dP23aDI4X1grEz4JnSA8slvWr3ySy9fHRGbE5w/RGrNhHgNAa+L7doDwaCGWmMm09uDKQBM5J2FFNk/iZzskj2Ik+LQmVMEalgsbB8PELxAORXP+Dm6C2pYJOhDQy5dvaqd2zd/qnCVMmvCktgL93XlHpfGOshmTe/mTBzGpKIyMlW5/WyIHwk4bG9nzDhlVJ+N1QmrQ+Q1HHVBXjYRKZL6Thb9FoWJIYqQrrdvtFncLF4MKuVlYRmul3A3we+nV0vM5/m+mZsAX8yPLeBaLOc7ePTKoWhDMVmoT11fbSZKkrONtixOeWc/jKGMlIGYiO2CYbFLiCmXTi+Rmu4GT4WEXvjXk4rW7HRpAlB8hv0ORqEf2lzIhmVGtlE5nV89PzpAyl3dHE94OXHVziGkI/aJnU0HAbio6eyuDKAlLEQPziV672odbmKGKlt2bMjPOWJg9NRutI2ySmTqobhc9M4i5eP+9eqqbwjQTBq+tw 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)(82310400017)(7416005)(376005)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:35:26.6325 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d369892d-c5c0-4e14-ea80-08dc812b1810 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: DS3PEPF000099D7.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7653 Now that all the required plumbing is done for enabling SNP Secure TSC feature, add Secure TSC to SNP features present list. Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda --- arch/x86/boot/compressed/sev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 0457a9d7e515..9474a92e8c5d 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -363,7 +363,8 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code) * by the guest kernel. As and when a new feature is implemented in the * guest kernel, a corresponding bit should be added to the mask. */ -#define SNP_FEATURES_PRESENT MSR_AMD64_SNP_DEBUG_SWAP +#define SNP_FEATURES_PRESENT (MSR_AMD64_SNP_DEBUG_SWAP | \ + MSR_AMD64_SNP_SECURE_TSC) u64 snp_get_unsupported_features(u64 status) {