From patchwork Wed Feb 19 20:52:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 13982931 X-Patchwork-Delegate: herbert@gondor.apana.org.au Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2074.outbound.protection.outlook.com [40.107.101.74]) (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 D096924E4A9; Wed, 19 Feb 2025 20:53:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998382; cv=fail; b=mAQwC/o8vdOcASECqzKg9DzFAiytUffZpvDPC4BEr7msfww+9jKaW1aR0RJmqfG3tw9/RrP4TWUghnYcYJ5J23x6BZD6rdaQxhqC0slUUsUKnw8imEr18TogsrBvyjXU22FFI42xbPe1weIK5q2CXF9Z/LIX3eSp6wMKMxYRjQM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998382; c=relaxed/simple; bh=BZvOrQJ+p5meUoHw7nyJSop/ykr7RF8M79/J1HoAzcw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l+hZ+vr72eOFtSgBSffuiL7oB8tZD7p3lSwzC5jAK73mWs4Zmkhkbz+C5ZoEUOgZQOjv6X9RdmEMZ6vwuAMgXyG6mUnB09G1gmUsOAFfw5/WLATwwUtqQV/d2dAA/+8WIi+7VjjcG6MF1XEyed0CxJB+ceY+67ighsNRI0xxtOo= 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=wSTxUCPK; arc=fail smtp.client-ip=40.107.101.74 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="wSTxUCPK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cYDCim+G442Be/olPgWGV3BtXuoDkx0sOIk7KrpGs16588MFomI5l/+e7/ZsLjtjjTWkg6f7UHN5eriF0uuwqZEqyctWjmVmfekYOX6Ob3c5eoKVx9I4cNhBDPzny/Yq9P86RP/6u4eA5HGly8o1U4vqhmJ7UCc6RecOI7mJBzd4scf1q3DfZrDBCbQmNkPibrNlNvccTR9COsLHThQHDGpTuIZ+Wq41/eeuOkTP/UgdiBH/PYHewNjutOk2F+xIIYnzHD8xv+gbZE1B7gLFM2RCXxKcEXli+o6c6tsiTRnWzGEAjhUrKgeRvjfeW+qPWdt+lgaNr1olZcvYLpYoOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=CyUBinyGvr/+nkXZUn9bohRCyqfJeEPSA0fa2wsfugY=; b=hzVXPuAEypVxllbdMMl1tjRokGvoCzgV+q7HH6FEN2QyZJ+P9zGEn9TNdpix3r/OufT4WbciauPFyMlklmVWvJO1hmwwrgEoSM6+aw5Fe9vMMS4Y4FLB/qowTkPTx/iVMzlLX91TiViSGQwYGWgOrp/EDGMlMqk/F5cDoOnhXAWoowAxLfsyKQEvoRWb/hEw5AtCbHAoQB4T1a5uy2hP1qAKpt0dM9O+op9LjgCroZNt5Iv1a1baLVE3HCdWszQCSMqV89JHvmuDYr7/lt972Ii1BmHWqx82st1yrRbh+gOrzS7+ftLP2kIAh3HIrCKBt5ddLc0hzKG/J25jbo7bgw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.com 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=CyUBinyGvr/+nkXZUn9bohRCyqfJeEPSA0fa2wsfugY=; b=wSTxUCPK6+vuiFjktX0kqJVSZbJgnH8DbMUk2G3M7lgkOiu2q55HoP2hHRPSC0oiTtkVGj80+dlDRwepHjdng1iiyFkBTb7FTkkcJgJrLeZkMy0ojwkrpvKhShmT73zPoLeod61Daivf66gnBQgzv9x86oF2UcacMQ9ELKbQUYY= Received: from SN6PR2101CA0003.namprd21.prod.outlook.com (2603:10b6:805:106::13) by MW4PR12MB6729.namprd12.prod.outlook.com (2603:10b6:303:1ed::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.19; Wed, 19 Feb 2025 20:52:57 +0000 Received: from SA2PEPF00003F67.namprd04.prod.outlook.com (2603:10b6:805:106:cafe::49) by SN6PR2101CA0003.outlook.office365.com (2603:10b6:805:106::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8466.3 via Frontend Transport; Wed, 19 Feb 2025 20:52:57 +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 SA2PEPF00003F67.mail.protection.outlook.com (10.167.248.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8466.11 via Frontend Transport; Wed, 19 Feb 2025 20:52:56 +0000 Received: from ethanolx7e2ehost.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.39; Wed, 19 Feb 2025 14:52:55 -0600 From: Ashish Kalra To: , , , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v4 1/7] crypto: ccp: Move dev_info/err messages for SEV/SNP init and shutdown Date: Wed, 19 Feb 2025 20:52:46 +0000 Message-ID: <5fe0faa1070d5225c19e3df207825d0e337ee3b9.1739997129.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F67:EE_|MW4PR12MB6729:EE_ X-MS-Office365-Filtering-Correlation-Id: 09450bd4-950d-4e11-1b9f-08dd51276355 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|36860700013|376014|82310400026|921020; X-Microsoft-Antispam-Message-Info: CrD0OfFNxDbdBKc1kRJNCvuJ/eStBhZ1s8a/2g0JW5acLOaQi40ZYEMWZGUONd0WP8qj48DRleX3n1Htby1TNwNTyh8k5+8waCxjUlNHhRjSbOKnHkRtNP/xRUHnsUkqs7ivz626kWMiI+o1PE2zRu+7uIWQz9yvRIlftI8SIGvsQvYwkdoWeEUCkuGkFcZW/NWVfTzUBLVgRE04RYfvihjOYFu6UvD7ZUXO8ZUZSASY2z8bmSbb4+ksIZyDcKgYv8nfnYbmpCch1/0A/+DbwR/f3K0o4H4duLaHCdv629eHNpZZee7qbpn+X/HZSLNyGBLJY/JSfPWFHlW8I9QUIxFXWVEp7GpA0Em6DrlUGZ3c39d5qNxNRGplSqWPsD2xAGk9rKgkiL+lqXqcP/e9+KmaffT3g5qFF9O+rMZ7ZerAcrCepKky04C7Zp5ZVyb3DcacdjWnMtVEL+Go69gq4WI67VwBoBeBc3Hcm81mLtOTDx/9YHleRFuohu6Lwtnw8OW/057XrROWL6uRd6HbDu9zy/wrZ0ye6rCHQcqApTfrBb8ewZzYhZmkY9MZyZworVnNEIyEHb2N/fbUvEJrTNy6T0PDYQpVBJH8Ez95YmyTiper1yuKUO15xzJyrRUZqWr5LhHCLAqYtgi++3iH0qU4GPTN6otoHmqZ4AYcjdQU1RvRsLpM5OF9b5OR/Mkm5kUy74Nio/BuCCOWkROkhAXFkgoCAdDRhUZ1z3d1QxYEOC4hEkVQJq5z+s2UCurhX9VhYuXat3fWjxoKHd1DYsUMi9QwA8lIkE7rI0EJ+hE7qmcRzZjM07W6RQq0UiylVh+zEM4LdxTyHEdSHsDDpo/gWsZ9bj6huu06FyA1cd1V8vvV4S/plKrWxXJUdy+EGJFJAlyzS0sxkn+UDVcCKXHzMYJ8zJfz5WetWhwD3pHG52i3+Nzzq3EvgyikcMJwWc8nP7pvO5zg6V4UO/V4VJc7cjPDiB2JfDSutQL1vf5IqdWVADR43jG3b45AoPg8h+ryFN28tLvQl9UdtD5Yoo6THs1hNbXcGX8QFzzZW7uTMpRGdWX1sMBwO9t+LUUySowyX7MasasDIzdnwrYuDaIy4+0cKv+AAzJhZfRC04tqn89YogTHPMBdhQ6Gd17FhC9w5BG6gcac6JnxFxXQZ35FPWrkb2UgemCHG/XucqtSldwO4TKBRzpTMpI9QWFN/MCrQ2ClXpLJCB40z7x+V6IlsyiEF/Q05a1uTykyQ06SPN9WSBiEf/LXLLNPmDm9yW8JcSs9n0QRht07vPrqrc4WOpE8d4EfTQK3DrQSGrrX8zrpq47/pkKVg/oItojn69lHhApyDVtg/tPEYQROjlpaBLA5nVZQhtdaTmqbq1wFzI7HYHhuXzZ6muvUt3tpnzRvCmEk0mygNSKwgijiiQw8TtLHaAbDECsYAqwbMLjTW4UlDok4bJXCsqP8GjP6445vd6YREVSJwgHViWm7mP9sI6Fwp52BDR4WJN+afgUp/v8vHIG/CuHRLXxe2eWK 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:(13230040)(7416014)(1800799024)(36860700013)(376014)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2025 20:52:56.7637 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 09450bd4-950d-4e11-1b9f-08dd51276355 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: SA2PEPF00003F67.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6729 From: Ashish Kalra Move dev_info and dev_err messages related to SEV/SNP initialization and shutdown into __sev_platform_init_locked(), __sev_snp_init_locked() and __sev_platform_shutdown_locked(), __sev_snp_shutdown_locked() so that they don't need to be issued from callers. This allows both _sev_platform_init_locked() and various SEV/SNP ioctls to call __sev_platform_init_locked(), __sev_snp_init_locked() and __sev_platform_shutdown_locked(), __sev_snp_shutdown_locked() for implicit SEV/SNP initialization and shutdown without additionally printing any errors/success messages. Signed-off-by: Ashish Kalra --- drivers/crypto/ccp/sev-dev.c | 39 +++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 2e87ca0e292a..8f5c474b9d1c 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1176,21 +1176,30 @@ static int __sev_snp_init_locked(int *error) wbinvd_on_all_cpus(); rc = __sev_do_cmd_locked(cmd, arg, error); - if (rc) + if (rc) { + dev_err(sev->dev, "SEV-SNP: failed to INIT rc %d, error %#x\n", + rc, *error); return rc; + } /* Prepare for first SNP guest launch after INIT. */ wbinvd_on_all_cpus(); rc = __sev_do_cmd_locked(SEV_CMD_SNP_DF_FLUSH, NULL, error); - if (rc) + if (rc) { + dev_err(sev->dev, "SEV-SNP: SNP_DF_FLUSH failed rc %d, error %#x\n", + rc, *error); return rc; + } sev->snp_initialized = true; dev_dbg(sev->dev, "SEV-SNP firmware initialized\n"); + dev_info(sev->dev, "SEV-SNP API:%d.%d build:%d\n", sev->api_major, + sev->api_minor, sev->build); + sev_es_tmr_size = SNP_TMR_SIZE; - return rc; + return 0; } static void __sev_platform_init_handle_tmr(struct sev_device *sev) @@ -1267,8 +1276,10 @@ static int __sev_platform_init_locked(int *error) __sev_platform_init_handle_tmr(sev); rc = __sev_platform_init_handle_init_ex_path(sev); - if (rc) + if (rc) { + dev_err(sev->dev, "SEV: handle_init_ex_path failed, rc %d\n", rc); return rc; + } rc = __sev_do_init_locked(&psp_ret); if (rc && psp_ret == SEV_RET_SECURE_DATA_INVALID) { @@ -1287,16 +1298,22 @@ static int __sev_platform_init_locked(int *error) if (error) *error = psp_ret; - if (rc) + if (rc) { + dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n", + psp_ret, rc); return rc; + } sev->state = SEV_STATE_INIT; /* Prepare for first SEV guest launch after INIT */ wbinvd_on_all_cpus(); rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, error); - if (rc) + if (rc) { + dev_err(sev->dev, "SEV: DF_FLUSH failed %#x, rc %d\n", + *error, rc); return rc; + } dev_dbg(sev->dev, "SEV firmware initialized\n"); @@ -1367,8 +1384,11 @@ static int __sev_platform_shutdown_locked(int *error) return 0; ret = __sev_do_cmd_locked(SEV_CMD_SHUTDOWN, NULL, error); - if (ret) + if (ret) { + dev_err(sev->dev, "SEV: failed to SHUTDOWN error %#x, rc %d\n", + *error, ret); return ret; + } sev->state = SEV_STATE_UNINIT; dev_dbg(sev->dev, "SEV firmware shutdown\n"); @@ -1684,7 +1704,7 @@ static int __sev_snp_shutdown_locked(int *error, bool panic) if (*error == SEV_RET_DFFLUSH_REQUIRED) { ret = __sev_do_cmd_locked(SEV_CMD_SNP_DF_FLUSH, NULL, NULL); if (ret) { - dev_err(sev->dev, "SEV-SNP DF_FLUSH failed\n"); + dev_err(sev->dev, "SEV-SNP DF_FLUSH failed, ret = %d\n", ret); return ret; } /* reissue the shutdown command */ @@ -1692,7 +1712,8 @@ static int __sev_snp_shutdown_locked(int *error, bool panic) error); } if (ret) { - dev_err(sev->dev, "SEV-SNP firmware shutdown failed\n"); + dev_err(sev->dev, "SEV-SNP firmware shutdown failed, rc %d, error %#x\n", + ret, *error); return ret; } From patchwork Wed Feb 19 20:53:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 13982932 X-Patchwork-Delegate: herbert@gondor.apana.org.au Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2042.outbound.protection.outlook.com [40.107.95.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 B1D4324E4DF; Wed, 19 Feb 2025 20:53:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998404; cv=fail; b=Cd24r87L+N6rzn3NaRGbp1+/3Mg6IiZX0uJgR8KlwEe3wjqezeB/FHhqiBDEGO1bbIb1cPTNVtrFqCvDVCw8nC/BFgBHi5yiuMFd3y4k/7zD1/6q7bnb0XflirWg7G3Ki0dzV167SdAxuPvNMVeYw4u55DEdkESg9Bl+oV6cpqE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998404; c=relaxed/simple; bh=lVTZpvyoSUkrzmOCJIEqpuj0D2xl84NArtg0EuDc5zo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZibRPYx6QAjLjcfKrP3FhE8loSq4FuKj0BE9EuqRDWt9/8wdvWCrwHG78v2Rfqq07L6W6mZrk+aXZedrAU4bDwb05q1kCSd3fNGLwAJwVP4qlENnRLXDwrg8rB/LbJ3ftd6gH3U7xf42jtQ1WpYwLEwBLymswC7hvnjgFVPqfu0= 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=BJGXvmg2; arc=fail smtp.client-ip=40.107.95.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="BJGXvmg2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dIhl5+vOPUedeCEJVvn+ploJuhNbBSZEy5/vXeLOec2FYUDBvSedF3ZqRMSazKc7LhLTLEEcyH4CGhy0KqcLZQfqMYwqc+zA9kCYmiXm2V89rY0Uvonx/083dDVuQYwNLbpvRRfw0J4kMH4+HT8F+neAOcRapNBhaKI2a1mEzYAueuHCpVhuG/SgNgyxSkO4rnMv0amHI/y2DRp2HFL4XkKAej3RJFwbc9AuXUMQWcsx6B47SXUy8IYtWdc/G6sV3Qm/W9t5anpS0AInsi3SYcsvwtCHMJeRltfBfENCzt84yglwCHRLJGke+AaViXbr0LYZNzi1dW/gpcHR1Ooy4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=HJWPtt5PbtmZfn7LOlE8UFgnhPVCPyJ4vf7z3j6R5Go=; b=DpCDvhkjNDl98t/IMV7WOpz+p7sV++kvGNL8VLTHRLh4F6ypaVIG6v4j56BlZbf1R8RDMkmTfPBROBz96xFW/76XjGJOw/g2eT0q8gPq6ygXBU9lYDVa2XW9qo721oDRz0LH4Lckq33/2VVJd0Fu0R4odL7MVXsmYa2z7SNCq8gV95vMpux/wgFjBdtRzQwsIuacpysNaDI/YAR6FE7RV5wl6FviJtXaRbk+w2+O9ogWmQEjQThyW4NaEz5rmCeyocAnVRZyRtodGhupTYHZ6SIa4coP1lZS3NfOaooxR6uyDY1Zm3xMMBDmfTJ/4kJLBrgo6vP+BPMxS94Lt1t9cw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.com 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=HJWPtt5PbtmZfn7LOlE8UFgnhPVCPyJ4vf7z3j6R5Go=; b=BJGXvmg2w7tL016J9SNKVUSu4EOLbapILSxZmAdcz6ohmm6kvImnd5oGPG5lxOo1OU0c0RxxECGh5Pcv6koigAtJDGhIit1V6dCApu+a+r5Z43DSkIbuoLs3+qRQ01ZOcN4ZLHUIkQFJxI9rmLFTqV1nwTJtqiBSAGEOA6MOONo= Received: from SN6PR2101CA0005.namprd21.prod.outlook.com (2603:10b6:805:106::15) by MN0PR12MB6152.namprd12.prod.outlook.com (2603:10b6:208:3c4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8466.14; Wed, 19 Feb 2025 20:53:16 +0000 Received: from SA2PEPF00003F67.namprd04.prod.outlook.com (2603:10b6:805:106:cafe::4) by SN6PR2101CA0005.outlook.office365.com (2603:10b6:805:106::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8466.3 via Frontend Transport; Wed, 19 Feb 2025 20:53:16 +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 SA2PEPF00003F67.mail.protection.outlook.com (10.167.248.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8466.11 via Frontend Transport; Wed, 19 Feb 2025 20:53:16 +0000 Received: from ethanolx7e2ehost.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.39; Wed, 19 Feb 2025 14:53:15 -0600 From: Ashish Kalra To: , , , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v4 2/7] crypto: ccp: Ensure implicit SEV/SNP init and shutdown in ioctls Date: Wed, 19 Feb 2025 20:53:05 +0000 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F67:EE_|MN0PR12MB6152:EE_ X-MS-Office365-Filtering-Correlation-Id: f7b37efe-b56f-4cab-340f-08dd51276ef2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|82310400026|36860700013|376014|921020; X-Microsoft-Antispam-Message-Info: +jNFduSN0yZSbPINO9Fe/T19l529YAU5OrsATGFpnnI72aa68ExwVwfY49LMDo5ypcESSeNvm8R6+mXNDY/cTAGbFkP7A2XgtKOYgX1JpbSO3aVADtVyw+Q0Ga/mxoQfVac1Vl4E12JnxnxSm6eJ4wbOEJtPBTQBs9cMdSswy0m4rc6Hpo8LGFGdDuoYbHVweJZf+yWZd/WGw/ph7opz8qZ7Q6XES1kE2UxoY3GkL98uw9I6l+uiRjTWFeQoYyx8zhQIkFY0hbECDHuGtsxemakIkV1OhYDN46O/B3B0rzYjsA1G8x6yRlgXoxbQNiHZmpt+KKM9W/wVmgWDw7HyBQWt3CGWTTXu7GLzEacoJ1D7lz61OdZ9woTUw/KzDsNIhp2KwsdQ7UXAS3zSlgh06RJ5UMLK9RCgblfJmsncAO2kK2jzj8ygaWtiDFdUWV48Bc0n55yESk0SHdTibtUu4qOWUwDOSIGRBbRBnO/xzm54MR0r51lEy2pHw9U7NUawE03j1ZyfMZGvZCh2YlqLwk10oaKxuop7SzuSfSIT5W5B8bbDQzU4UyWkr4AavL7RdrhzTHuWJ8w1ruQ7EQpUUAIzLHlWEMV3B7xuBYGyUc1IdhjQSzFJnLW91d8Io/I8fevQh7ULdiPPAIiBu/ckYsVTqu2MeoNTrG3ckZcPrAuX0uBUAc830No3y5GFOzmOzjp63QYyExmeHEF7Em5u+ztNi/7HBnOggeHkAB26mhdm/6/NnFJ5pXs0FkhSTdSbQo6JatSvx3Ixolo8T2P0aqMex+MiS1YI6j0GTYOodaooRNAZUl1fIcn+nYRMxyQS5YYgikcnqmBuE7abXKwIKoygVopIUa0kxKRuTOzCC0EMYauKIpx7vURN1KAZpYuZv4HiY8bNuhD0oWKGcib1454VFT9LvOHzGPgQQdOa9z8+ciXtiQ6XjXpuECFyO3icbRJdqS3WLgzrOZqVpaXldD9pF/KbNaPNIkOLQMIHYjzla9gEl/0WqbDCfCjeRng/dbfSZ9SjO+P8yoVCOsyjgP9jBAdQbu7OHDkOQ30jLI3EaqmT5+LOOwZRcW0txlDGKicBwtIZ3YlqpxmknZesU/Ot5bVVhNS/jkFhz62tSx1I0UfsUj/vSTq8sGef+tuom/YVN3OrH+TSVVBunM9eGvui7tE3vj73P+PGwly6N4na/GufulO7CZOZLbV8Xk7klOrQC9CKkE6mdg4Sz4Gq9B9+mojTywKxXagvcU0GqucubDrraayIjdbj0ZWuGPx0cK8aSwStEBIvea2134w5x08v1XqU+XVUEdytZlwrhkgClB4VfmBiQT86cKr97mtxdCo3O3blCvfP8aRfY/NziaOTSp41I6+5e3epMRxeRogjzYukBC4zTQaDKogaop8YcesO7TaJ22NPHFpNGrrvdQhSqFTUpR/YTO0rOtFi1pEufcvS2vpL5Y/cx8h7xdezFT0eLQ5Er+aufZ3z2PldcZuCdmNtSsvewAm44vexeUaqtXG4+gU+MzAfCc4uAo+p 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:(13230040)(1800799024)(7416014)(82310400026)(36860700013)(376014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2025 20:53:16.2482 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f7b37efe-b56f-4cab-340f-08dd51276ef2 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: SA2PEPF00003F67.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6152 From: Ashish Kalra Modify the behavior of implicit SEV initialization in some of the SEV ioctls to do both SEV initialization and shutdown and add implicit SNP initialization and shutdown to some of the SNP ioctls so that the change of SEV/SNP platform initialization not being done during PSP driver probe time does not break userspace tools such as sevtool, etc. Prior to this patch, SEV has always been initialized before these ioctls as SEV initialization is done as part of PSP module probe, but now with SEV initialization being moved to KVM module load instead of PSP driver probe, the implied SEV INIT actually makes sense and gets used and additionally to maintain SEV platform state consistency before and after the ioctl SEV shutdown needs to be done after the firmware call. It is important to do SEV Shutdown here with the SEV/SNP initialization moving to KVM, an implicit SEV INIT here as part of the SEV ioctls not followed with SEV Shutdown will cause SEV to remain in INIT state and then a future SNP INIT in KVM module load will fail. Similarly, prior to this patch, SNP has always been initialized before these ioctls as SNP initialization is done as part of PSP module probe, therefore, to keep a consistent behavior, SNP init needs to be done here implicitly as part of these ioctls followed with SNP shutdown before returning from the ioctl to maintain the consistent platform state before and after the ioctl. Signed-off-by: Ashish Kalra --- drivers/crypto/ccp/sev-dev.c | 117 ++++++++++++++++++++++++++++------- 1 file changed, 93 insertions(+), 24 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 8f5c474b9d1c..b06f43eb18f7 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1461,7 +1461,8 @@ static int sev_ioctl_do_platform_status(struct sev_issue_cmd *argp) static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp, bool writable) { struct sev_device *sev = psp_master->sev_data; - int rc; + bool shutdown_required = false; + int rc, error; if (!writable) return -EPERM; @@ -1470,19 +1471,26 @@ static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp, bool wr rc = __sev_platform_init_locked(&argp->error); if (rc) return rc; + shutdown_required = true; } - return __sev_do_cmd_locked(cmd, NULL, &argp->error); + rc = __sev_do_cmd_locked(cmd, NULL, &argp->error); + + if (shutdown_required) + __sev_platform_shutdown_locked(&error); + + return rc; } static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable) { struct sev_device *sev = psp_master->sev_data; struct sev_user_data_pek_csr input; + bool shutdown_required = false; struct sev_data_pek_csr data; void __user *input_address; void *blob = NULL; - int ret; + int ret, error; if (!writable) return -EPERM; @@ -1513,6 +1521,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable) ret = __sev_platform_init_locked(&argp->error); if (ret) goto e_free_blob; + shutdown_required = true; } ret = __sev_do_cmd_locked(SEV_CMD_PEK_CSR, &data, &argp->error); @@ -1531,6 +1540,9 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable) } e_free_blob: + if (shutdown_required) + __sev_platform_shutdown_locked(&error); + kfree(blob); return ret; } @@ -1747,8 +1759,9 @@ static int sev_ioctl_do_pek_import(struct sev_issue_cmd *argp, bool writable) struct sev_device *sev = psp_master->sev_data; struct sev_user_data_pek_cert_import input; struct sev_data_pek_cert_import data; + bool shutdown_required = false; void *pek_blob, *oca_blob; - int ret; + int ret, error; if (!writable) return -EPERM; @@ -1780,11 +1793,15 @@ static int sev_ioctl_do_pek_import(struct sev_issue_cmd *argp, bool writable) ret = __sev_platform_init_locked(&argp->error); if (ret) goto e_free_oca; + shutdown_required = true; } ret = __sev_do_cmd_locked(SEV_CMD_PEK_CERT_IMPORT, &data, &argp->error); e_free_oca: + if (shutdown_required) + __sev_platform_shutdown_locked(&error); + kfree(oca_blob); e_free_pek: kfree(pek_blob); @@ -1901,17 +1918,8 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable) struct sev_data_pdh_cert_export data; void __user *input_cert_chain_address; void __user *input_pdh_cert_address; - int ret; - - /* If platform is not in INIT state then transition it to INIT. */ - if (sev->state != SEV_STATE_INIT) { - if (!writable) - return -EPERM; - - ret = __sev_platform_init_locked(&argp->error); - if (ret) - return ret; - } + bool shutdown_required = false; + int ret, error; if (copy_from_user(&input, (void __user *)argp->data, sizeof(input))) return -EFAULT; @@ -1952,6 +1960,16 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable) data.cert_chain_len = input.cert_chain_len; cmd: + /* If platform is not in INIT state then transition it to INIT. */ + if (sev->state != SEV_STATE_INIT) { + if (!writable) + goto e_free_cert; + ret = __sev_platform_init_locked(&argp->error); + if (ret) + goto e_free_cert; + shutdown_required = true; + } + ret = __sev_do_cmd_locked(SEV_CMD_PDH_CERT_EXPORT, &data, &argp->error); /* If we query the length, FW responded with expected data. */ @@ -1978,6 +1996,9 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable) } e_free_cert: + if (shutdown_required) + __sev_platform_shutdown_locked(&error); + kfree(cert_blob); e_free_pdh: kfree(pdh_blob); @@ -1987,12 +2008,13 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable) static int sev_ioctl_do_snp_platform_status(struct sev_issue_cmd *argp) { struct sev_device *sev = psp_master->sev_data; + bool shutdown_required = false; struct sev_data_snp_addr buf; struct page *status_page; + int ret, error; void *data; - int ret; - if (!sev->snp_initialized || !argp->data) + if (!argp->data) return -EINVAL; status_page = alloc_page(GFP_KERNEL_ACCOUNT); @@ -2001,6 +2023,13 @@ static int sev_ioctl_do_snp_platform_status(struct sev_issue_cmd *argp) data = page_address(status_page); + if (!sev->snp_initialized) { + ret = __sev_snp_init_locked(&argp->error); + if (ret) + goto cleanup; + shutdown_required = true; + } + /* * Firmware expects status page to be in firmware-owned state, otherwise * it will report firmware error code INVALID_PAGE_STATE (0x1A). @@ -2029,6 +2058,9 @@ static int sev_ioctl_do_snp_platform_status(struct sev_issue_cmd *argp) ret = -EFAULT; cleanup: + if (shutdown_required) + __sev_snp_shutdown_locked(&error, false); + __free_pages(status_page, 0); return ret; } @@ -2037,21 +2069,34 @@ static int sev_ioctl_do_snp_commit(struct sev_issue_cmd *argp) { struct sev_device *sev = psp_master->sev_data; struct sev_data_snp_commit buf; + bool shutdown_required = false; + int ret, error; - if (!sev->snp_initialized) - return -EINVAL; + if (!sev->snp_initialized) { + ret = __sev_snp_init_locked(&argp->error); + if (ret) + return ret; + shutdown_required = true; + } buf.len = sizeof(buf); - return __sev_do_cmd_locked(SEV_CMD_SNP_COMMIT, &buf, &argp->error); + ret = __sev_do_cmd_locked(SEV_CMD_SNP_COMMIT, &buf, &argp->error); + + if (shutdown_required) + __sev_snp_shutdown_locked(&error, false); + + return ret; } static int sev_ioctl_do_snp_set_config(struct sev_issue_cmd *argp, bool writable) { struct sev_device *sev = psp_master->sev_data; struct sev_user_data_snp_config config; + bool shutdown_required = false; + int ret, error; - if (!sev->snp_initialized || !argp->data) + if (!argp->data) return -EINVAL; if (!writable) @@ -2060,17 +2105,30 @@ static int sev_ioctl_do_snp_set_config(struct sev_issue_cmd *argp, bool writable if (copy_from_user(&config, (void __user *)argp->data, sizeof(config))) return -EFAULT; - return __sev_do_cmd_locked(SEV_CMD_SNP_CONFIG, &config, &argp->error); + if (!sev->snp_initialized) { + ret = __sev_snp_init_locked(&argp->error); + if (ret) + return ret; + shutdown_required = true; + } + + ret = __sev_do_cmd_locked(SEV_CMD_SNP_CONFIG, &config, &argp->error); + + if (shutdown_required) + __sev_snp_shutdown_locked(&error, false); + + return ret; } static int sev_ioctl_do_snp_vlek_load(struct sev_issue_cmd *argp, bool writable) { struct sev_device *sev = psp_master->sev_data; struct sev_user_data_snp_vlek_load input; + bool shutdown_required = false; + int ret, error; void *blob; - int ret; - if (!sev->snp_initialized || !argp->data) + if (!argp->data) return -EINVAL; if (!writable) @@ -2089,8 +2147,19 @@ static int sev_ioctl_do_snp_vlek_load(struct sev_issue_cmd *argp, bool writable) input.vlek_wrapped_address = __psp_pa(blob); + if (!sev->snp_initialized) { + ret = __sev_snp_init_locked(&argp->error); + if (ret) + goto cleanup; + shutdown_required = true; + } + ret = __sev_do_cmd_locked(SEV_CMD_SNP_VLEK_LOAD, &input, &argp->error); + if (shutdown_required) + __sev_snp_shutdown_locked(&error, false); + +cleanup: kfree(blob); return ret; From patchwork Wed Feb 19 20:53:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 13982933 X-Patchwork-Delegate: herbert@gondor.apana.org.au Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2072.outbound.protection.outlook.com [40.107.92.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 19D1022AE42; Wed, 19 Feb 2025 20:53:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998426; cv=fail; b=G8gU9dFZbOBP92wnszIRasEMAHBgbfhe+igKqeSBAA+4j7x8sQN9dKOLhIX8SlIc9yMnqhpWtN24TT1skkgdtsbdEDWNc1Hr9xSJ8lyaMocB6KXFvKD+GQeEiRyGvoKtRnunJepeXg1EctgEpga9L9+QZKokeDv8ERKGVtgbY30= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998426; c=relaxed/simple; bh=rc0PEVZEPyl5upwRQRbB2iIgu6Md90RXtS/d5UICpjo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NNbpYEXKRNRP4P7YN1d+9RCRIS9UmZrq+mtB70twofMudsrqTu1mBhXrHm6YizCNQtyifNvWToyGzFGLNMRs1YsyGOeLbOe4F3zb3zQhlybw8HvUzymq+59BQyHOsL0aNBcd70DRNOCfKXHCmt8l+FrK7Izv2oYjkPgFrjnzCHc= 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=FwrEObf0; arc=fail smtp.client-ip=40.107.92.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="FwrEObf0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MuouIKmJAgaKS+dIAVG5I3U17dp2/fyMz56lnbL8gKHpm+A1bZb7d6p1KTVMi056DFS+SF7H71HBv3M9Doy5o3QtWa8d0uW3eMo/6g8Xq+z7KqPbIopUWeJJa6DYYxJOqY7t7x3XJ7SB2G0bPgqiYPvBTJMtc/qP1UcNzwHJ0EPyK8067AWSAirYWddOBlemOaZGSZ56mu9YouyQCSq3dMhIrSeqmxTqtFOdXdECBQYznnH8g1aeDzWun4ie3hV9aMYMLRV5TM1WT1KNuukTpq6uZr8gsJzrJ/qeYpPpFwxWVuI9t9H1LpGvVgZj0n11xYamGXWNokM2YdA+Y0IYDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=CMvHjYc5ynOjQ/EDweMX4f3PwadTvtrXejG+AecteXw=; b=WmdhCU6KDwa9rY3OENVGXYilCyz78rYJYLr9jmMx/jSEtEPj56e86/UtYAx+KwdvzRPuuG5T1cxe6tqp5Lq2Gk7xBAc6f6HHn8jNhEoTkcWUzJz3FfkG8a91wZMvQREz1iESzAXyh5JwspcJ5vuzup3JMtQev/IJ/XxQE0MATq1kN/KjVbq9Q11EshFxc8dgfilkhenExXQvoEZ27XNNMBZTCHmrATPmeUAaoFwHhV99uEKNqpso/a7puV79gNKjfWVsQJIlnEXG/c3P176k9pZCrNniN5P1+TV3QMAplcdubRAuQ/QIOCu7/JwmO1UgAXyalwvJaaHc4IWFmjKawA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.com 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=CMvHjYc5ynOjQ/EDweMX4f3PwadTvtrXejG+AecteXw=; b=FwrEObf062//H6WEpzFAPMsQrFNmq7/Yb45jeTOumzIo1cbuowGv+7rUPNxk/50FVOnM/u6iCA7uT/Z124cwHKuCWOZ6WMXYU8r/GdsKym4X7RTYe4nsq9Pl0PijgS6GT0x+D0hMj3l+kTtOImKoUciVjXmCvuqFKbBdEwy5RAU= Received: from SA1PR04CA0009.namprd04.prod.outlook.com (2603:10b6:806:2ce::25) by PH0PR12MB7957.namprd12.prod.outlook.com (2603:10b6:510:281::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.19; Wed, 19 Feb 2025 20:53:39 +0000 Received: from SA2PEPF00003F61.namprd04.prod.outlook.com (2603:10b6:806:2ce:cafe::b0) by SA1PR04CA0009.outlook.office365.com (2603:10b6:806:2ce::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8466.15 via Frontend Transport; Wed, 19 Feb 2025 20:53: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 SA2PEPF00003F61.mail.protection.outlook.com (10.167.248.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8466.11 via Frontend Transport; Wed, 19 Feb 2025 20:53:39 +0000 Received: from ethanolx7e2ehost.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.39; Wed, 19 Feb 2025 14:53:38 -0600 From: Ashish Kalra To: , , , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v4 3/7] crypto: ccp: Reset TMR size at SNP Shutdown Date: Wed, 19 Feb 2025 20:53:27 +0000 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F61:EE_|PH0PR12MB7957:EE_ X-MS-Office365-Filtering-Correlation-Id: d8c72760-17e0-465f-3db0-08dd51277c9b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|7416014|36860700013|921020; X-Microsoft-Antispam-Message-Info: tRNGUmPPv5coBME/+2SrJyqOP19ai3jfXDDSaHDALHG8NBQeff+ncvy/E7qbPcqs8eeSnax46BUyOuUHy9vrO3IWDXqjHUABm4SNlmDZJOvLLi0XPiUvniQwq86+YnZeQ1g1e5ExWgxqm/LGY84aK59aNQNGfy1fAuBmiu66Dnpng3ZHPRbCK4RjFVFFpGYrnpr2GsLiP9jZOLoam3MFdg44qSAHlroz7f8yR1KqI68FByFeey896lVg21X5MJ+fOYwlyZNAulippx77pWmNUQaicSXozJFZiuSkj0wVITLupzDyQpBBoa4+jQ6GP63lUPIzkLSKNJrhYzd/QOCTMGIuArcKB1YaVpzQAeYdWcYvml+etQp71zDIOAOD+9aMEuOahsOBj8nByU2K4qltZjKVE7I3Kly6NjfwnlFvyNMoJkzERP6z17313XLzDsZL1hrpJdJl1JHS8a8lmjqdICVbKK/MyiP8V3OTttfJhBdBCsVKRQLx6jq4Y8DiGhshm8+jf4WLi5T1RnN7STPQwd0LpdaHEB4wkZu1cE9NCwcG5+OpRqB0gCDw1wcZ+YB4Z/u8gJQAnTBA+vwO55lVe+VE2Fxx+/3E0IB0dZioexlFOJiEWmT5Jm9SsxSTjPI9oqV4balGCfyCnCBXayr0epCymojrBpVceH/f8Ts5cgHdjkUGB8A20yOdDr8Y6S5Kmm+kG356DOxpqxw+xulecxBQ6qtg7h+LXh6lbccjYMCWve2WKrcbIOyXKE6RMCYX8TnMPWdutid43uCfZEsfrU5eSkVQdxnBMc2zJN4crrqvBu6dzqeHuaLx6BG7tUJZt17YgAMUDF12JPtfQErPEUkmQJR+i6SV2SM7wffO8CBC8geKQ3SC6EU9jvFylg2hbgTLc8o0C59YjrMBDK4/w0I5AZzxrmPChdoKJ/dP3sG2gjgkAQD7uY9kp+ugUa1TOwPlhlAmyw9F/B6xTer72Dm7xGz7xmRN9m3Dab2kQLozc3fKSpYGcOK3wueJu+hITck0peSgezd+i6KH0vu/cbWQck+65OZ9HHqeQZ+Wcfr6FfO0YgzloLAr2i5Bvvl0omIICO1bBTpW9HjpyFbCAX84beDDNzy7UyI3YFsoORZvM+YmqJkMNGL27tFBimYJ9d/AoeBSAdB3XvJAQiNrK26I02yLrPyUsI/5TDPdZl6ltgZwHJiTMMLkAQ+XYCjKU9gxNvlecHE8MbbKMyY0pTQvp1+hZWTCHyvwt9jIi3G3DHTijxwTib5E+G0pRqqBkUfhjUgu/8TTwcoiBFPJusWyiGkZjQBxxzh8h/UJYjVqnt08h7v1vwuHEXXJeD0HX+cG4s/YNL18yq1rm+qIfX/EPlOeCpvz534HUXjtQX5kKTsyj3MHz0/gkEEaaWwmo1GZ+1Af/FxaT2/XjNsS9NDgXLLJpFKVd1pA11gDsf4eM1jxtwWJbOdpcvWjg60RZ0ycgrFQN6eSUtri6pkTQb8I3dRUko4vXuK1tFLE8ksENvnk2oX39xUTOyjP6+VB 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:(13230040)(82310400026)(1800799024)(376014)(7416014)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2025 20:53:39.1664 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d8c72760-17e0-465f-3db0-08dd51277c9b 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: SA2PEPF00003F61.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7957 From: Ashish Kalra When SEV-SNP is enabled the TMR needs to be 2MB aligned and 2MB sized, ensure that TMR size is reset back to default when SNP is shutdown as SNP initialization and shutdown as part of some SNP ioctls may leave TMR size modified and cause subsequent SEV only initialization to fail. Signed-off-by: Ashish Kalra Acked-by: Dionna Glaze Reviewed-by: Tom Lendacky --- drivers/crypto/ccp/sev-dev.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index b06f43eb18f7..be8a84ce24c7 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1751,6 +1751,9 @@ static int __sev_snp_shutdown_locked(int *error, bool panic) sev->snp_initialized = false; dev_dbg(sev->dev, "SEV-SNP firmware shutdown\n"); + /* Reset TMR size back to default */ + sev_es_tmr_size = SEV_TMR_SIZE; + return ret; } From patchwork Wed Feb 19 20:53:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 13982934 X-Patchwork-Delegate: herbert@gondor.apana.org.au Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2047.outbound.protection.outlook.com [40.107.237.47]) (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 619DC24E4D6; Wed, 19 Feb 2025 20:54:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.47 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998444; cv=fail; b=rVy6t/Wo0q60G20t9q0U6RhguY4DRpea0e96Cvreo2ZN6Yu2imm8QCw96AUOkPIwnmgdy178HXz9/VoMLEKVZr09YU9F/2PfjYg74h2jMpgpR1Oe+Xlny/oqw3XEdLJwQThX59Y2jorv5oqAX08I7bBnTunD154/ngYZHYxhYIg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998444; c=relaxed/simple; bh=W+zO5H/yBf0Y87amRVHWmTXBwTzyJ0I7tqfdus2z+CM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qpPmsjhMsWD+jO+p8EyBJvk6GkFmjs9+O33nQBL3BnulhUQHAGnohqOgWrghuLi0VH5j71/6EFDbLheEaxEzTqPAR2mzuTr7FWf00Sm6sRmz5F4JQnET4oz6BD5xECx7531ajsc39O8s2nViJVhBqa0TSy9gjtJNu7pX/aKVzrw= 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=1eHErlWs; arc=fail smtp.client-ip=40.107.237.47 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="1eHErlWs" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WsIjni8Uht+Iurk1CAy8M6x7M64i1MuSdtpPZ2OdTPHAHyGUIxggnKlusQVll7QUbo2vbPU4RvA3BWSxsNPAtyvJJCKs36OniIaoK3MJkJZt29x2Nk3KAIZrWSBhzkETDqBKoCUuENx5aqRbQLMC4DLPZm0LZX2e7+NZdzhJT0dsmK5eORjrGsW1TxeTARIWpFEwehzx5vP8BtXxn63bX/9pMpmv/ySp2vHc+8wMvTBuBrOcr4rubZjVFVUm/Mfv3/6aiqVyo/PXYOjEcD87irQZNsN8NkMNU6FcWXqyGsz4gJODTO8RQzZJadHdVSdi0RrAUyJl+ybo9moeXrlKgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=57ZM5GRB6jlWiRwDBCaJDG0EsZvhM3yo2Ff9O9KJt5Q=; b=nFpWpoql+QemvwAAwjD5epWCVZVykLX16fa0VbZmhym3JM7quPtDdpUX+oyNUx561hZN3otbAgNP8gglpvAEeTCBEsSNDtvC4v53zDYRdWepZp6HcXY/kTlhAmO8zdP+G/hprtkc1DA5e1cdYwHtnG8//mTFCcdf3FM8wDB9SFa1NcqyUu0MzYbyq4jGw2YeE9bkKXd1Hen3RoendUq23wIvPrxkL0V2PSYXxJCpjaLMPzAlDq1YwWFivBHAbrkD7PLulU7JrVrXyWzyhP/OqQT1rFNS1Srsbdgo65sUWOrsc2N9ovAirxqnm5DfPKjXcw3KTWij48zG8xh2wUDtGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.com 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=57ZM5GRB6jlWiRwDBCaJDG0EsZvhM3yo2Ff9O9KJt5Q=; b=1eHErlWsGrpjfouCfJhYzHYIItdxKjIfO6NDinYilFabK1Uv6Bc/2FbAkQAQTMCrxXYJyxRKiFWMuMs0i3n5zq5ew+6WfCFQY6WDABeOwKM7WAWDDOiIsQOz0ZwmVLJ3d6kjOfYkh8mexM55v9c22osPKfTWzVJSd0geC3VIhVk= Received: from SA9PR11CA0029.namprd11.prod.outlook.com (2603:10b6:806:6e::34) by MW3PR12MB4458.namprd12.prod.outlook.com (2603:10b6:303:5d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8466.15; Wed, 19 Feb 2025 20:53:58 +0000 Received: from SA2PEPF00003F63.namprd04.prod.outlook.com (2603:10b6:806:6e:cafe::94) by SA9PR11CA0029.outlook.office365.com (2603:10b6:806:6e::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8445.19 via Frontend Transport; Wed, 19 Feb 2025 20:53:58 +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 SA2PEPF00003F63.mail.protection.outlook.com (10.167.248.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8466.11 via Frontend Transport; Wed, 19 Feb 2025 20:53:58 +0000 Received: from ethanolx7e2ehost.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.39; Wed, 19 Feb 2025 14:53:57 -0600 From: Ashish Kalra To: , , , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v4 4/7] crypto: ccp: Register SNP panic notifier only if SNP is enabled Date: Wed, 19 Feb 2025 20:53:47 +0000 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F63:EE_|MW3PR12MB4458:EE_ X-MS-Office365-Filtering-Correlation-Id: 61599ddc-e851-4564-3d9f-08dd512787ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|7416014|36860700013|82310400026|921020; X-Microsoft-Antispam-Message-Info: clS1axELE+osr1LK/HtMUE1UY2O0YgV/18RSiccoR4Ax9reloPpfGzmkSgmKsB+r34wG6BgiahcLrt1l58Es3YhH7tqkqX2xFW2R8wgPpD7XWuBcg75ai44ErzW7s7wuz1KG9jt7sC7rl3GnPZJvKlnHcHxEiJxuq3yk1aL8XGjA5yXaVXjWdpVUyVbmjAEkjpT29GZmkGex93dUcmmA2VO0SoG7TdjZ63Sfuc07kQfNL7HQr7kg8I6aqak4UXtXyNFYnRw6rgHIulren6mqAXpoygi4cq5GgroKhEIG4dc+S2YdZtavTuy4MZ5TBbpMem2hu2r04j+v+61HTVFieg76LbStvd8xIFUtc/4UOn/8gHKYLOqHjVxrDXcZv9EQBEoxggOAnOA1B10I0ZZ9xphkhd33VHuuXpkH93i/ajESuvwJUhSealSq7lvKHs9lQN6hrU5X3ydnbsTYVk3caKsIzZzQLyPhOog6+5NNs4I+//EFH20fZZ9WFZwCj2z0OiFWR+o4j+OYTaMLkQ2zyxJ9Nf6dP09TWSw2Eda/71yr0rNJ8pcE3LcA8MCDkt8IPP+1PNjkkyssM+0ztH0Bz4UxHJCwm/QFOQqzEP1UU8kvFunAsbLlCIBjnwhjafl0q//fsrGJ7ydJBYGyJapaP59UGi7Knilg+Q84EHzMiuc2wc7Wfpao+62RAz2PzvPJDvG2wYWznCrlrn+lTffXkMg3dmdGHcZffQaplgI992J0cYjR0/YdVkMvYVgbNgfWtaN4oi3+4rsJSQKjQVKsyE+cmPj5FDp/RqvlWiw3JkJSCHnLqRLqj7p+VoJw4AlMnswrZtkmKMhMFa56svunmSo/fpl1NmhOpGe29OKWNvB5w446YpNihIHR0BPZFU1LRy2/kAvAkQXf13prDB0Azu81+gUXLkvWiW8aTkHovRgdDyLzM4LtPy+TlIP1dx2YPzO3nEjtvoYLYWV9qDSFdpDxXDcv7HCc29QlDFUn+GA3vCLrfFAma8EKU/DaIiTmSk9Lv1xfDwpWjeIZlog8fmtvmebPHEHNurXGNI6y3OCdAtf3M4Mxb1hQU+vblJxCZ0oNEThuT9PWR7rdDuX/gcm9o8CtRpjxxF9MTNkmmvzJjrTUcPnO514aD3OLevKkVa56N71CB8Gx2jvAWpW/P/SRtTxnZ57AyhQeygW3LWO4Slmdp4fW4PAIrT2lDuHIzFgT1ASnDMtJZlmNadUbHj6dgeQX8MYrufToikK1dSGP2Re8aG3dJvdOjUjDkC4EaYNhlCEY293jqNCwsln/jMCThMMt6PezPNrcZfQQEpPMvHJrsCQX1rWNAWD8srJKXpzNFc1k12ZC3cc9H7s6pq0OjjElUpvjkmXXpGuwHIbxNt9TVxoxowhA8AnlJGFnFTHFku7J+aK7f9Rp8FtmOcMoUWioF9Dq7oz1e7zXv3WXeVDlsHEXffXrZAf+P+anth4bZHhoawkSNQAx4NqfpsZr/0DP5vhGHr/DwGqmCTmFru4UqwEB5CBopIv+LNG2 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:(13230040)(376014)(1800799024)(7416014)(36860700013)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2025 20:53:58.1809 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 61599ddc-e851-4564-3d9f-08dd512787ee 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: SA2PEPF00003F63.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4458 From: Ashish Kalra Register the SNP panic notifier if and only if SNP is actually initialized and deregistering the notifier when shutting down SNP in PSP driver when KVM module is unloaded. Currently the SNP panic notifier is being registered irrespective of SNP being enabled/initialized and with this change the SNP panic notifier is registered only if SNP support is enabled and initialized. Reviewed-by: Dionna Glaze Reviewed-by: Alexey Kardashevskiy Signed-off-by: Ashish Kalra --- drivers/crypto/ccp/sev-dev.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index be8a84ce24c7..582304638319 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -109,6 +109,13 @@ static void *sev_init_ex_buffer; */ static struct sev_data_range_list *snp_range_list; +static int snp_shutdown_on_panic(struct notifier_block *nb, + unsigned long reason, void *arg); + +static struct notifier_block snp_panic_notifier = { + .notifier_call = snp_shutdown_on_panic, +}; + static inline bool sev_version_greater_or_equal(u8 maj, u8 min) { struct sev_device *sev = psp_master->sev_data; @@ -1197,6 +1204,9 @@ static int __sev_snp_init_locked(int *error) dev_info(sev->dev, "SEV-SNP API:%d.%d build:%d\n", sev->api_major, sev->api_minor, sev->build); + atomic_notifier_chain_register(&panic_notifier_list, + &snp_panic_notifier); + sev_es_tmr_size = SNP_TMR_SIZE; return 0; @@ -1751,6 +1761,9 @@ static int __sev_snp_shutdown_locked(int *error, bool panic) sev->snp_initialized = false; dev_dbg(sev->dev, "SEV-SNP firmware shutdown\n"); + atomic_notifier_chain_unregister(&panic_notifier_list, + &snp_panic_notifier); + /* Reset TMR size back to default */ sev_es_tmr_size = SEV_TMR_SIZE; @@ -2466,10 +2479,6 @@ static int snp_shutdown_on_panic(struct notifier_block *nb, return NOTIFY_DONE; } -static struct notifier_block snp_panic_notifier = { - .notifier_call = snp_shutdown_on_panic, -}; - int sev_issue_cmd_external_user(struct file *filep, unsigned int cmd, void *data, int *error) { @@ -2518,8 +2527,6 @@ void sev_pci_init(void) dev_info(sev->dev, "SEV%s API:%d.%d build:%d\n", sev->snp_initialized ? "-SNP" : "", sev->api_major, sev->api_minor, sev->build); - atomic_notifier_chain_register(&panic_notifier_list, - &snp_panic_notifier); return; err: @@ -2536,7 +2543,4 @@ void sev_pci_exit(void) return; sev_firmware_shutdown(sev); - - atomic_notifier_chain_unregister(&panic_notifier_list, - &snp_panic_notifier); } From patchwork Wed Feb 19 20:54:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 13982935 X-Patchwork-Delegate: herbert@gondor.apana.org.au Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2083.outbound.protection.outlook.com [40.107.212.83]) (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 6183724E4C1; Wed, 19 Feb 2025 20:54:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998464; cv=fail; b=fFd7oJLETlDUwYF6dUMG06Rbh5s0+MhE07pSIuY5ifERfHTccUvhrEiE6PsEmKfTjukxlNds3KHFBz9G08n6k3Yy1ixleHRDMYWwOcY82YM3BQ9yS/JUSMo6anKTihpOijlu8LNZRAipab0VEzMQ1gIhfYrIoKj7Oscy0NTLCsA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998464; c=relaxed/simple; bh=WYbT+AmiVMWm+AA52NaWjchjIiFHSzSWd2SfK/Gm3XE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=B7fD6WX1b68dKLUnLoRkape2hjmZZRwZyCD90m1rdn4H5HlhhYvi1UnYrwe64T1MG39beyXRC2MM6KsgHmb4R+A1TAewChsbtGNkC/5SHx+dZLWMXrgrSRxeR4u6rTlNpPfVWBZXewidU7t5Tf39GkHftFS9PMuK74fMKf0gqRc= 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=i7Nx6z1L; arc=fail smtp.client-ip=40.107.212.83 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="i7Nx6z1L" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=W8+IGlVNy7Bn7z5WW960VUcLnoRGI/QvYt+Rk42AwVUodIAArQAdByLti/Q3v3IrEw+bNryXmcyEtFWwZiNg4LDU93AEetZw82Kl+J2jchJSzfcWruy8yBMNEwsR4Gk+bfopBzi03EB2/Q7x5Y5StkpQ1HkPX7WH4KnF9XamkLsOa4V4JEXbm7RvGKW3pvURVDF0x0csAXaIn1FYmlekc1fS5bfa7OdFnqO+Z2hW6pauaty+YPQXy0Z8u06W60CrJLFHfHowu8qTFGG5XIhvRpLzaFa6KmmJkXgApAGklwJEaBdDrUJ3IgRtrxJurUhQ1I13K6fVoI77ibs+crc1kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=IMUIw1S6UVR5OnjgPGqc9W4MN21GsmtC7CkLMVx5oNM=; b=BG8vuS7tfFZEU/XMOaM2BaGNLXlp8OVUJnzvOCK2w/niq+gEs/jg+vd0olJFT8zfnj0OaFoCTw7qNKmBUNdP8AYSICkHI80S1kA1X2TRbAgq2sk1r8A4T/eu7vh2SaVpJDU5GV5DvCEc7NAkJgAGxHWDS7x1dcUNqHMb90NhlF+OVD1qvWHy7+lNWAErQZ2cCFYwW7QG+MVZNeBKDf9fRSf/r81W013NjwLhJmfTD7+BhCYTd37jErxaM2m/viIeto53IC1jnxsbIZQD1Ma+n6zLuHHw0fdqCsdOo+oVrhZosw6i3oR5EmUUaI7DUbNezlfhBPzpYYCNtdaWkXe8Xg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.com 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=IMUIw1S6UVR5OnjgPGqc9W4MN21GsmtC7CkLMVx5oNM=; b=i7Nx6z1Lm78cHqiGdDhqsRJAP+Ox7XlMtilwAYpk7aXSWCJYFz0ACAenrwLRreC7rbwkRdUS5pFmeIVcVUy8xc1fmCsLoWTv+8VHUzmDcHzR/ILMVLgXShT03igmPNn9NRKMdNc4yH8ywuKvcME/sMVY/Wd099pQIdXzrcF6Hiw= Received: from SA1PR04CA0013.namprd04.prod.outlook.com (2603:10b6:806:2ce::19) by SA1PR12MB7272.namprd12.prod.outlook.com (2603:10b6:806:2b6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.19; Wed, 19 Feb 2025 20:54:18 +0000 Received: from SA2PEPF00003F61.namprd04.prod.outlook.com (2603:10b6:806:2ce:cafe::16) by SA1PR04CA0013.outlook.office365.com (2603:10b6:806:2ce::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8466.15 via Frontend Transport; Wed, 19 Feb 2025 20:54:18 +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 SA2PEPF00003F61.mail.protection.outlook.com (10.167.248.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8466.11 via Frontend Transport; Wed, 19 Feb 2025 20:54:18 +0000 Received: from ethanolx7e2ehost.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.39; Wed, 19 Feb 2025 14:54:17 -0600 From: Ashish Kalra To: , , , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v4 5/7] crypto: ccp: Add new SEV/SNP platform shutdown API Date: Wed, 19 Feb 2025 20:54:08 +0000 Message-ID: <3751510d09c0811811e46e857942bf238aa52d05.1739997129.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F61:EE_|SA1PR12MB7272:EE_ X-MS-Office365-Filtering-Correlation-Id: 67c8e487-482b-41ce-5753-08dd51279400 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|36860700013|1800799024|921020; X-Microsoft-Antispam-Message-Info: eg5695M4nrQPlKk2vN5Jqxk9fSU2d778Yfo4s2wGcYTQsTPk+Rql7elcBpfS+d7DhXvmw3AviRZScoCPLIN9FOg2uLNz+wPrrtvzVa/xZCoykGr4WpRTC9X2trK53aHdpAm9XfOtUG3fue5jnS8mhMs175SZJmDSXnz9eVyNEwcrg8sQQDDANs+tl1vPRdPl9AqO9jjA+w071oPLJcp3nDxZXSW0DaMlHH8DePJ43RbqUUnjCNhcGiPN6oIQj0TRsQMCC5Y4TGSPVYseIu3GRuzL7bX6aqTUzLhN4hMuTTLvGFwaEGfYDS18JrJqI/fhAUJlmqLqhaRU4gaioeE2kjuptf9hHN1nzmc4OqF1PXaOkvUi7zWEVAPD6VG7/xfhwscr/7q2V0oQXkJSR0wwasSrKi0KkqRq0ZUZXPqjwYAT4D9wbR1031P699ufKLSDgdS/6OdSf5bWAFdI0kvH4gNyNKRj+BpxyROQ/lRVk4vWcnxwaymGB1rb4A0mT5+Z/23MnQgZN9n/h5c3z1ffJxsMdJ9vk1J1nhaW9aDy+xeiPadhcKdnagZZjShSitk0UNNKmqpO6/zeCGKCfcJR8Sekx28YjryhlF3sUYDQEDcTRZe3qbRhhd6M/vWzQyqFPVyYwvnJYs9iaE6zvRenBcNUyLYW0WUx/xJKfbP6EQTChG9kjBI9oXzoqcNGPNGVFMWnRQrTSPC2TPefwQOXoaQ1d7v6WHkAdOwPh10W0XdgH69cqDdNCGZJBYGhomiPGZH31LVfSsKVIRl1hZXj3zTHrOEPR3O431jRIdWDcDKM+ZZb9HOqoqNDFJD3Ib0EUzMvxazG1qCbfXk/C38my9pEIC3/9AopOjT75HCvlkcgldbBQTdUlqPYM+EgLtraMTjj6DcwiN7MIf1pN2WyO2h7QG1GLk75LBFF5Jpt8HNB69yMyftxVhrTlioPyejjJ7h/k2dX8scFM5rYvbWzSy8Afk2v9UyHWefWsGq91wRLH3qe/qj3CkWHNyw1VxDyLkyLah3XJFGJWAlUs+LF7q1jXFMFq0dSk7Tgc0v0xiR+Msx77O+4y9I6ay7ObqtJAWcoLPw3aQiRyg9CWK5SBWqWuV5cR3CNH7E59HW5StAXXZZiCMtGUU0x5dLBlgG9pMc8NkgmMJszRtqZib7S+Bzr/5WbHFtf9+3lOidCLhcGxd7ju3zXwi1FJXDEniaey0KoiguafTubNd+EFVazLyl55UuOo2ll4QIqQK51T32Cx3Ck5ka6QvGE150oGBRu+I5T3ZCJM9IF9yWB4sV52zfN9vnHn8qU57i22ORC3xh530V/ES4vw7LeFGZo1EQcFWH64cesCnzS/YiHnlw61qcp5onVRJUKelR4PRzMDag8l8EMVLYWtCjrkmGdI9Lbko+p2mL+3rYChSgNJbk8ONT6pwKrzj+LwHqovVAZcc7R1/XsLrNY/+KLMVeXJ7RPguRkEURcvVxf2olARkON3QN1CaROAbiszpGKvm1VVeZCQ/ms9cf1XYrgOj9pm21G 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:(13230040)(82310400026)(376014)(7416014)(36860700013)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2025 20:54:18.4321 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 67c8e487-482b-41ce-5753-08dd51279400 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: SA2PEPF00003F61.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7272 From: Ashish Kalra Add new API interface to do SEV/SNP platform shutdown when KVM module is unloaded. Reviewed-by: Dionna Glaze Signed-off-by: Ashish Kalra Reviewed-by: Tom Lendacky --- drivers/crypto/ccp/sev-dev.c | 13 +++++++++++++ include/linux/psp-sev.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 582304638319..f0f3e6d29200 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -2445,6 +2445,19 @@ static void sev_firmware_shutdown(struct sev_device *sev) mutex_unlock(&sev_cmd_mutex); } +void sev_platform_shutdown(void) +{ + struct sev_device *sev; + + if (!psp_master || !psp_master->sev_data) + return; + + sev = psp_master->sev_data; + + sev_firmware_shutdown(sev); +} +EXPORT_SYMBOL_GPL(sev_platform_shutdown); + void sev_dev_destroy(struct psp_device *psp) { struct sev_device *sev = psp->sev_data; diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index f3cad182d4ef..0b3a36bdaa90 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -954,6 +954,7 @@ int sev_do_cmd(int cmd, void *data, int *psp_ret); void *psp_copy_user_blob(u64 uaddr, u32 len); void *snp_alloc_firmware_page(gfp_t mask); void snp_free_firmware_page(void *addr); +void sev_platform_shutdown(void); #else /* !CONFIG_CRYPTO_DEV_SP_PSP */ @@ -988,6 +989,8 @@ static inline void *snp_alloc_firmware_page(gfp_t mask) static inline void snp_free_firmware_page(void *addr) { } +static inline void sev_platform_shutdown(void) { } + #endif /* CONFIG_CRYPTO_DEV_SP_PSP */ #endif /* __PSP_SEV_H__ */ From patchwork Wed Feb 19 20:54:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 13982936 X-Patchwork-Delegate: herbert@gondor.apana.org.au Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2086.outbound.protection.outlook.com [40.107.220.86]) (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 C6D1F24E4B4; Wed, 19 Feb 2025 20:55:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998503; cv=fail; b=DVFnjzIv8Ik0lRBSmODMYDe05PIlqL7uR5JjyQrgsiyFiPa4rcj9qiBLEfS+5p/i/4J6adYqkioc/I+Y8g+m14sqju6uQX2gB39UFhhhGJPMoMIwvJo9LW54Q09srCdAUxCySYuV+4ZY45AxzAU61870gzoRyCQXMa53yukJw2k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998503; c=relaxed/simple; bh=iGVKnAsE1ba95GWCRw58c/50CmL9pjDOget8VIkoeU0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QETh07e4j6iNI9/8wa7YSgO1LJII7shL7hH5qOdXPIRZGav99sSrh4uyWliAtjaw+DDpYOWrRsjgj+nyJjscxFmUAUBkUA6po/FA1z4kH8DmaXaLCSIUtfjSkdwAtAWuNQeWt+Y03NEsZybhpNW7Nim0aWY36ojrI49RR+UazG4= 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=Bv21L0lU; arc=fail smtp.client-ip=40.107.220.86 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="Bv21L0lU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xISBvrI+wmknMchk0YHJb3t7aWTF4G+yUoKqXbGrDAHmf97z491q5EWNkiGPgPGeZr2LfN5uG4RTlqqZquVozMzu7nBM757VFLQg162H3pmezOpOWGAZoJqDJea9+ghKt3tn32ikcZ2j+dKhAiK+/t+pyoE3osO+NMMnfksdxNJKR0PDrUzj+F/tyE95GWuNYQQfjmaMIbUWPTNAHNOpmlJ4Gz+kmvAIXhleoWJJqI1S/y2Zw3fql9NLkLLYyb4MUC8+v1w8GwtqnmB0VSBi+onyN8sjzeTeLjAF0eWGkpNuwqp37CZhQs1SY654iLjdCG0HxmuELl21S/609PSmIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=WihQCoGliPJv20KI8JNgvXzX95k2sNXJNrEBuEfF0RI=; b=oABhEdj51cVI3LJ5o/0jIcClDUtR7wZ9+Co7Oba1VLnSc2TXJSBeR8CDwMcfOEbNrTL3Mr4JnnH7QwC6brnix7Aux1gAwak+iyiwaQlh52fkPlsfkmAh21meaA6BWwYvw5gfir8bxYk0g3DNYM0kVBEYzQAR7HDxxmyVqWTJUJ2JYG5TNNjU9HODTySnOF+iO5a8ozjXP0DYem8EK61SQ9L067ZhhSDlDwgdx8PLTHYMLID//Rlj3tzWkcsz/1wYDXkTjJHrmoTfJbkWkz8jfdiksRh9aQi9y1Fomby0W3QSOPsvWOAMcc/HFvk4TK6dw4k/Inlm7L0Ou2Y8Bcqolw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.com 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=WihQCoGliPJv20KI8JNgvXzX95k2sNXJNrEBuEfF0RI=; b=Bv21L0lUx8Rwd2tW990bF6avWv2qA+4VCxZJuJ1/9g7JATlIkBb55PRR6U611JqRIe9+GWgd/K8v2oQQIEfNAnqECuFp9fexrrvgS/NN4uknFa4KqT7+kPrPx3iWsPtCjpDBMItRs4BKWelV+VRQNM9DEsQ+CVTTwRyacdrkZHs= Received: from SA0PR13CA0020.namprd13.prod.outlook.com (2603:10b6:806:130::25) by DS0PR12MB7778.namprd12.prod.outlook.com (2603:10b6:8:151::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8466.14; Wed, 19 Feb 2025 20:54:53 +0000 Received: from SA2PEPF00003F68.namprd04.prod.outlook.com (2603:10b6:806:130:cafe::e4) by SA0PR13CA0020.outlook.office365.com (2603:10b6:806:130::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8466.14 via Frontend Transport; Wed, 19 Feb 2025 20:54:53 +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 SA2PEPF00003F68.mail.protection.outlook.com (10.167.248.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8466.11 via Frontend Transport; Wed, 19 Feb 2025 20:54:52 +0000 Received: from ethanolx7e2ehost.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.39; Wed, 19 Feb 2025 14:54:51 -0600 From: Ashish Kalra To: , , , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v4 6/7] KVM: SVM: Add support to initialize SEV/SNP functionality in KVM Date: Wed, 19 Feb 2025 20:54:42 +0000 Message-ID: <5346a666758c21ec25d26ae184a2d1a9324f3b55.1739997129.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F68:EE_|DS0PR12MB7778:EE_ X-MS-Office365-Filtering-Correlation-Id: b63c6abe-502b-4ae8-024f-08dd5127a89b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|7416014|376014|7053199007|921020; X-Microsoft-Antispam-Message-Info: p8v4dSLJ9m0PHA49UxCpaA+EZjbHhY+IH1vBECAFeGvhpXoysGVqNDYkjT+iBuI5+v7t1JgeJ83BDE2r6ckL0YhqRp8y3LIHtvgS6tuCqQffMNWHERYtN5FGzyNL9m82VMOwV2U1vMpU67BcYYysvmQmbGZOkI/1epfNHiBO8E2J9hxSenpICNvLmdkT4CXeYFbSaZ3mv2lahZbbJ4D89BrIb2ym3iiTyzSW1oo03vBihMbZsF/2rJ33sFDrBOx3YCi9tSmCCWK0/HfrGWUSO8PEIb43T0Up5jX0OY/cib11vwrtD38JPQyi8fcwzvCOOImeZV9TsKsAx5UvPNRjR9AmrZtr4/81wYieuW3zzzBVrnJz4GPOM9eQxJ2CeDY7nfTRvz1yAQWWOaf52AhcnAOaJ5snnd3IBVD4NQgHf3wEWRj6V4rorabrqBu7Ph9oYB/3L8g6CbMHVVVV268IELezgBulnbalbYLNtZHTyd8K8cHUpW2yVuW9gRy6g+jhd4+C1Zzd5WIr0Q8bzFe4Vv8yyEMG1fr377qVH+9Z6XTUklXyiZa+WsCcBW0+Wyb18kc0M373sFYHZbtYPkkxAitIY4VN7wFaBJvO3qA0U0gcMc1S2vSNalbrj/z7SlDwNGDVf+WFGhBeM8WCQRzNf74Je8cK2tvFvNsC1OAX6DUz3EnaecxVTDGftoTDEkO3jn125H6IUUQadiwpxZf77Ra4XwhJQvDRTiRJCxnhCrKrXXTqZ5OrasIQ3UPuU+9wc0aOJygejmJ3Wlo5y1XUuVY58LcQ1ThZMfBlUuRtT1nsCdTY7vJnwgGS6MYPyp8zbp+KVYDf1NZY8hrR3mXvpQ7+8TX2LeFTkZboTKYfhHpORLKt047jsoYrdEAaHWPNPnqHeCOCnJ/DdYAGPDmqBiZp9gzJ+A5ZosRlQgOE1clErhn/AwsROTnevC77B0iUmrvBOCP1/b/mM8scyD38NXT8QP95WwxONSPXThxcAyjXK7WhMaJcxUD7EiAL/HjAqF7Fjp5qT33aLbPm17Ao7/Oaovbdc7uArFp1BtnXIOkLIFbwh1r9ivLoD54xxdqDgY8oDGFj4/IbjoEZsmzsvoukepkKrMPDWmoPdSnaeSndvPF6Hdj8/XefrCGnJkyMKvAQPdvGw/fAQlJDdtAotb4Dmm6lVw5fVnOjnpqhXohuIkLP00aNHzXMZXabfmh67S0dBZTqHAJVkbuY28t49T2cKAShniLSI7StcGbIa6nVGduFk2Akz7GFMjXNk+wDyPmKhc4CY1uQ2K3kNLnC3GOscHY8IIPH92j/udL2Im9kfu3XeF5laQAZ9ZJj+7Ge6RxDrwWxPhcSgiPW43s1TYcLRS3bXAQ8E4r1ljMUXXkliVh8uKpaOkOnknN+MpKuQANRtMkqpCCq34ybihedG/VQ9f9WkAmdaKLmM2iWS1M3i7+Zve6xzz8gle7S1TthrcuxelYCV9iXeEBOz/7vxtN+NG3IKtTuZ9vBlMywEdRb15e06rtIdZ9lEqzbJOy7 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:(13230040)(1800799024)(36860700013)(82310400026)(7416014)(376014)(7053199007)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2025 20:54:52.9846 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b63c6abe-502b-4ae8-024f-08dd5127a89b 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: SA2PEPF00003F68.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7778 From: Ashish Kalra Move platform initialization of SEV/SNP from PSP driver probe time to KVM module load time so that KVM can do SEV/SNP platform initialization explicitly if it actually wants to use SEV/SNP functionality. Add support for KVM to explicitly call into the PSP driver at load time to initialize SEV/SNP by default but this behavior can be altered with KVM module parameters to not do SEV/SNP platform initialization at module load time if required. Additionally SEV/SNP platform shutdown is invoked during KVM module unload time. Suggested-by: Sean Christopherson Signed-off-by: Ashish Kalra Reviewed-by: Tom Lendacky --- arch/x86/kvm/svm/sev.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 74525651770a..213d4c15a9da 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2933,6 +2933,7 @@ void __init sev_set_cpu_caps(void) void __init sev_hardware_setup(void) { unsigned int eax, ebx, ecx, edx, sev_asid_count, sev_es_asid_count; + struct sev_platform_init_args init_args = {0}; bool sev_snp_supported = false; bool sev_es_supported = false; bool sev_supported = false; @@ -3059,6 +3060,17 @@ void __init sev_hardware_setup(void) sev_supported_vmsa_features = 0; if (sev_es_debug_swap_enabled) sev_supported_vmsa_features |= SVM_SEV_FEAT_DEBUG_SWAP; + + if (!sev_enabled) + return; + + /* + * NOTE: Always do SNP INIT regardless of sev_snp_supported + * as SNP INIT has to be done to launch legacy SEV/SEV-ES + * VMs in case SNP is enabled system-wide. + */ + init_args.probe = true; + sev_platform_init(&init_args); } void sev_hardware_unsetup(void) @@ -3074,6 +3086,9 @@ void sev_hardware_unsetup(void) misc_cg_set_capacity(MISC_CG_RES_SEV, 0); misc_cg_set_capacity(MISC_CG_RES_SEV_ES, 0); + + /* Do SEV and SNP Shutdown */ + sev_platform_shutdown(); } int sev_cpu_init(struct svm_cpu_data *sd) From patchwork Wed Feb 19 20:55:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 13982937 X-Patchwork-Delegate: herbert@gondor.apana.org.au Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2066.outbound.protection.outlook.com [40.107.101.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 7FD2124E4D6; Wed, 19 Feb 2025 20:55:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998537; cv=fail; b=QjezJijVF+2ZKAvJpjGbrNNJCHCimsHX3ts3Z6Cuo+VbFgUhL+7V6RN4W/OjDNX6aDPIJg/eYmhGkRkU81ZcJvKlTyRFRNZ2eC3ZjsVeWdXTuhxPnT/g3+NRhihVt18o4R4MDL7r8dp1QbFAJaa1m0zNThLqQBY1sr5YDoy9MFo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739998537; c=relaxed/simple; bh=CRtSmnyk7QUzZKw4wxQgUCGOs555cCW45JMunGHi14k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o7wzlbjdKXAtKx0nABMdrks25cP3NKOeYzE1ZY0T9QJuXCm64720N3hV9rg+bOAVvu2+Yi1VxpII6lzoHR2v/9QbKmn9YMBL1Dr5164eOfZS9RAVc3+oBOhV+LnxhHoae7Rc3h6ieXGnxPibJIcTHzks+4JOKy7nOXtCArZ+UvA= 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=wYRMalgX; arc=fail smtp.client-ip=40.107.101.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="wYRMalgX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cS0Zvv0pZkhntr1YZdcNk25s7lND27FEQLf12OBSpV9anJM1MTIAiGiu/zttKtOBekyRAmXj+rKrz0lfrF/E8zlZ1PhuhYv7GSgW2Qyd5D1PBYMNRD1MnxvnxXhZk1s/eissQlB5TWPxMB3TmnH4v3Jn8ouOOlNxdlnvS4SchRt0F7khWUBSQpiv/CJDoulIYWwEDLg2KsjvdchX89EFHv0Oa+WtaL8mzmV++TOOLFqJJy/MKHJJhZAOGQbiMYzQdckx5R+SZ4tkFgd5olZ5dXZbIHrVn181PLSQpq/6GC//oXIdXYkuiFa4P+AAjmYr8O0NOSFIzTb8pHeM7eoHzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=+OMf7YKzdonrl+A/dNaQSnqr9xhHGzFSjksCHYi/ids=; b=RqbTiGWRN9wGMJ49dtioPmnBUSNAWX63zoJaB+b/611Tx9dEAkh57mB/rGeEuwRViygmREZaLY1DBxD7yt5UI7bzIHko1hwlLorutGXXcCxRniQI/M3wMYsDHIoJD/AAOnnubhcZOOBwezcqfRaPxrPj2fxhuACEcnWqAoY0ACysxGXeO49RH4gdXYRMCOy+5lboIhEWOgvtlxRC2KkB19uvJt/Je1M7kP3Rkz6d9lgXLIh1T0YqvIIEOXM5Zy9B/3HTIWpqptFv08us0eYxZsnTzz9lfCrnCVMDbQG8JLJ3uo3dCJrnjFRFSxMWBvq6kdaFseShADF1BhORszu/gA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.com 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=+OMf7YKzdonrl+A/dNaQSnqr9xhHGzFSjksCHYi/ids=; b=wYRMalgX2ko6/UjYI7ie1N8ukBLD8oRqNrUt/cUz2Kw/ZdQPlJEAVnVMQvvtUWO91H2nC/gOa1/thZleDlBUKHtD8wxH7nk7n9U7hDXhHu0q4iCo2ff7Sbh3MthSyn9UJ/tRE4wfUaROKPQCANHsEX/rp57oYZFJ0xEIUtpEtGM= Received: from SN7PR04CA0057.namprd04.prod.outlook.com (2603:10b6:806:120::32) by SJ0PR12MB6926.namprd12.prod.outlook.com (2603:10b6:a03:485::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.19; Wed, 19 Feb 2025 20:55:30 +0000 Received: from SA2PEPF00003F65.namprd04.prod.outlook.com (2603:10b6:806:120:cafe::94) by SN7PR04CA0057.outlook.office365.com (2603:10b6:806:120::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8466.16 via Frontend Transport; Wed, 19 Feb 2025 20:55:30 +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 SA2PEPF00003F65.mail.protection.outlook.com (10.167.248.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8466.11 via Frontend Transport; Wed, 19 Feb 2025 20:55:30 +0000 Received: from ethanolx7e2ehost.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.39; Wed, 19 Feb 2025 14:55:29 -0600 From: Ashish Kalra To: , , , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v4 7/7] crypto: ccp: Move SEV/SNP Platform initialization to KVM Date: Wed, 19 Feb 2025 20:55:18 +0000 Message-ID: <8ddb15b23f5c7c9a250109a402b6541e5bc72d0f.1739997129.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F65:EE_|SJ0PR12MB6926:EE_ X-MS-Office365-Filtering-Correlation-Id: 18fecac6-0a95-45ec-eaa7-08dd5127bebc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|7416014|376014|36860700013|921020|7053199007; X-Microsoft-Antispam-Message-Info: JAEvTWLJyTtDBpFX+1HGI/SdBOAHK7yQuU/df2TGchilKRmLYMj5wDiBEfaSoIwTI1a8u1RZH0ouaz8eHOFq5QRLRYD/V4+Ok71zLrj/Zbmev6QHc0yaP6uUsrsGsQZYgNVTNuKvtQ2df26yeXlx/a/rscRaAZTvTCnjCacGH2GRdc8aqy0SiuBvyl9xPzBUQrPxTiz3tn8MZk4UBX5WqY3SCrNU3FyqIjRMD3UnHOnY5zaMEoFAiUw1n3YLK3y6WF5KU346UNteb+7eDFWmk4tN2rIisyKsggV4q2ZVtXMERLSFiiI1nNANku/y3psMnsySUmVDEsOccaTkm0TRsJXDE0sDNNuTIPYjHEHomfjQH6ib9Rq76kf94tzW3+oTojRfA5UkYiIZO0gedaiQZpVaybdJUF500M8Gxx98P+mVbSBkcyzhq5BE++GAacVpx8yTpkxmUHamykSMHihjJLsYDy/tescw6leg/2+uvOoevaRFc/xjg9nr4Sc9nL0I4vMcluhvB9bay6jXK6H50Jphnls2mCxeost/nGhXLE+Q+y5kc0Tete61AQb54/9YbJT839jiM1C6VXLdlTyEfTJpoHbNBZ1KAaJa1XZpchHAyue6Lz/alaqCMsM/44di0ThqwMqpsrYlk1LIs7xHlPT86wEC+r7WTSbH3UrMbFqiyJUltO/TAa4B7ZQKxtzKJyRFqfAVUwJPJQISTCbSqodqfo7OXCy2ZKxjdPK2u95EmyquAHMnv49pqyZEBPCATq8qFID+G3JmIQ45HjUZeVrX6yaTDT+v5kypMcQSDkUYZHSEaXybvTOH+s452KSM9uf5YOl2RIxZpjuXPEfzf6WgYWqq0jCJ8Tf0a2/Hx0t5vw/iDmjKPZ8hI0rpBAUk1euIIVBIxpMvbLwRfK31IhnaScHQJSjB/FPXxWOEgWSEd5Q5MZv1sMCNotz2BAV6kpyqW8uMIHm7zYnsUYPG/5fd3xwWGfQZfxaiIJJwDdFm8r/GJRpAwSr7SGUITL3Hi1DI/J8YPwbntyZ5HsKFr4WrD6ZW0K8cnWKTayyhLfqKo6xX611y7Er8CmIiOMEfj4tD+AQ9F9xeBTBmxk4UOKp0bX8o2xjfFoOfphZrkteYQHIkMD5splcWeMwHY+DBLH6MXD146eMC/kd6J3VC4xSespQfgGTzXUmlyNZWif4FICcFyD5jDEa+6dmMuqMCm8OAhUwyyja517TBAmEyopiURnTZsnsh7EDSCC3e7l/fb5t76me2xSpQiqXZnSPjPSQSf6K8r7VzSkaknBX9tapoDTGXMo99MlfLSD65MMtrENWhbZyJd3JRXwlQe7QUtr4wuWVCgnEpsy0FkXriJP99AGdTBI/zlNVTfsFWeQTKpvIQ2fqpDNXmzfvzWNPa29aE7kcemuNcFhlzIYAu9aaidf6bRVCzJxC3PtX3tD/5EbBv5BlKtAB9tMBwuGlFV4cFwAGXirGsnB/i4u2UFBXSDE+zHonKUrGIQSkUNq6b05hRoWSwFRnJoVYEsO4M 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:(13230040)(82310400026)(1800799024)(7416014)(376014)(36860700013)(921020)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2025 20:55:30.1323 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 18fecac6-0a95-45ec-eaa7-08dd5127bebc 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: SA2PEPF00003F65.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6926 From: Ashish Kalra SNP initialization is forced during PSP driver probe purely because SNP can't be initialized if VMs are running. But the only in-tree user of SEV/SNP functionality is KVM, and KVM depends on PSP driver for the same. Forcing SEV/SNP initialization because a hypervisor could be running legacy non-confidential VMs make no sense. This patch removes SEV/SNP initialization from the PSP driver probe time and moves the requirement to initialize SEV/SNP functionality to KVM if it wants to use SEV/SNP. Suggested-by: Sean Christopherson Reviewed-by: Alexey Kardashevskiy Signed-off-by: Ashish Kalra --- drivers/crypto/ccp/sev-dev.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index f0f3e6d29200..99a663dbc2b6 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1346,18 +1346,13 @@ static int _sev_platform_init_locked(struct sev_platform_init_args *args) if (sev->state == SEV_STATE_INIT) return 0; - /* - * Legacy guests cannot be running while SNP_INIT(_EX) is executing, - * so perform SEV-SNP initialization at probe time. - */ rc = __sev_snp_init_locked(&args->error); if (rc && rc != -ENODEV) { /* * Don't abort the probe if SNP INIT failed, * continue to initialize the legacy SEV firmware. */ - dev_err(sev->dev, "SEV-SNP: failed to INIT rc %d, error %#x\n", - rc, args->error); + dev_err(sev->dev, "SEV-SNP: failed to INIT, continue SEV INIT\n"); } /* Defer legacy SEV/SEV-ES support if allowed by caller/module. */ @@ -2505,9 +2500,7 @@ EXPORT_SYMBOL_GPL(sev_issue_cmd_external_user); void sev_pci_init(void) { struct sev_device *sev = psp_master->sev_data; - struct sev_platform_init_args args = {0}; u8 api_major, api_minor, build; - int rc; if (!sev) return; @@ -2530,16 +2523,6 @@ void sev_pci_init(void) api_major, api_minor, build, sev->api_major, sev->api_minor, sev->build); - /* Initialize the platform */ - args.probe = true; - rc = sev_platform_init(&args); - if (rc) - dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n", - args.error, rc); - - dev_info(sev->dev, "SEV%s API:%d.%d build:%d\n", sev->snp_initialized ? - "-SNP" : "", sev->api_major, sev->api_minor, sev->build); - return; err: @@ -2550,10 +2533,4 @@ void sev_pci_init(void) void sev_pci_exit(void) { - struct sev_device *sev = psp_master->sev_data; - - if (!sev) - return; - - sev_firmware_shutdown(sev); }