From patchwork Mon Dec 9 23:24:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashish Kalra X-Patchwork-Id: 849428 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2065.outbound.protection.outlook.com [40.107.244.65]) (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 93C991F63EC; Mon, 9 Dec 2024 23:25:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786710; cv=fail; b=bjTSSKt6Xk3XoFtWC/HXNLQP7DpQLo+5lFL4lRtF+DGGPRtkXGXMdWRLnY8PLeHWQJatOTLvwmz38MSTT/r1jualn/MYJyC9roRKXRkyJ8htSfa6ZkD2U4oz/g2FdHzyHVbN3rWfjhiOa5Sz7LIrPjsfnDWhytltssD4FiJ2BaE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786710; c=relaxed/simple; bh=nC4nDhhuZhiejHkgsKkG6b3O7AfJhMWx+eGgOnSCiUw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m0en/MkYujBO24tNR2oQyxPbsRsFP8pfwYE7EulwBppwbZUGndGur0lKnR6+xZ0ZygwbqcG87wgpleFKge+IGxctn7J8sRGb1fPUXUnnDPINGtRtWpPnsPCoMSMw3Ay+wuS5ZlQgi1Dv1vQtj4mQF2izwFElX5wXfIT/N2hFdLk= 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=XVCDK+LS; arc=fail smtp.client-ip=40.107.244.65 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="XVCDK+LS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VV+9OS3UaGI4CkGzfXt2Ar7FUrtC5zyZSXhfaZwmUgywvQ0Qqc2PPHtKByROLvoOLVig8g2R+4LE9mF7vfmEfD73hTSQMRjC7/xi1GawceyraMP4Rmq0mcMKuANolrTt4GBU9zI10ssM4BaX1ikNGaPCUXkm0tMlcK8cac90petM3QTgYtipcQP/BYHaxI8C53okVo8uMbjQxymuTbGqy2/OhHJFVfwUyl4UAowbDSojYnjON1dyeOmSX6SQQ2tNuvjA1C/2nMIkr9WaMmZ4WHdv+yqsBcghLQArQwa/woBTTvon+WraJjGzyx4K9oMqDQdU/r3sIRj/T1RqbxUCnA== 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=d3aTvgJf/NX3OYxmFkFXPUTlVTg10nZpFvubQL8+Luo=; b=Dbd8CetUfki/oZfb1xEoMHxBr6Xcl3quJwVxTCnDsB30zE9vA4ZZXcyAy/c+epRaNclLRAAbqVRF8T9jwAECqdBbVHz4fgNV/AqpxZ7ov6drWiN2zrent58ljHsTLsz30AZ1C5WozXQMMN8GwoG5SwmL1rI1B3lrIllTf4kZTlmkEY31n5CyVNSNdtuISYXOCta5++PnuQv/06+jYx5FnhQ6q+qxFMBEmfVo3x0meLN/wJpzJIpMdep9BhXEsmqpv7qoCHqpBzIY2RBhouwxoV/pn4L3dcHKZJe6pDlPi7zAOvufwYB429F4UggMqOW+UCs6hduPbRk9NK4L4Ts6cw== 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=d3aTvgJf/NX3OYxmFkFXPUTlVTg10nZpFvubQL8+Luo=; b=XVCDK+LSPr+33yVbhwLGbAGR/L/0gOCHSFF663n1F/xgYN3wRFd8ALvqh96CNgVbQE9KlUZfjQ60EyYfnSQEcbIdZyg+ZOGLTDU6MLz2bCQFAc/r5Sm+XJCw/dKtzMY6PVitJ7fjwuawErI1PVdoKGqg+sCjuFZfNGO+T8ePlQ8= Received: from SN7P222CA0021.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::6) by DM3PR12MB9352.namprd12.prod.outlook.com (2603:10b6:0:4a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.12; Mon, 9 Dec 2024 23:25:05 +0000 Received: from SA2PEPF00003F64.namprd04.prod.outlook.com (2603:10b6:806:124:cafe::73) by SN7P222CA0021.outlook.office365.com (2603:10b6:806:124::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.14 via Frontend Transport; Mon, 9 Dec 2024 23:25:05 +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 SA2PEPF00003F64.mail.protection.outlook.com (10.167.248.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Mon, 9 Dec 2024 23:25:05 +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; Mon, 9 Dec 2024 17:25:03 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , Subject: [PATCH 1/7] crypto: ccp: Move dev_info/err messages for SEV/SNP initialization Date: Mon, 9 Dec 2024 23:24:42 +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: SA2PEPF00003F64:EE_|DM3PR12MB9352:EE_ X-MS-Office365-Filtering-Correlation-Id: 66818e36-bf14-4ba4-e306-08dd18a8b680 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|7416014|36860700013|82310400026|921020; X-Microsoft-Antispam-Message-Info: K077LqdKrFmshcr4X4ivu9BjorUpVT6P7TbmlbA7m4Qn/SZE9DeYRunVmDVp2q8zrTadyH6AsyNEfeV9FMhM99YIO0vHlc8IIm//+A0eCasBATLgIguJzdFyF+3j2db29Ub6YRkgUlzaOO2iVG0DWecBu1ty6R+VnaCQ/mu/5R7QAbyzBQP0fL+B7IlsU2nWl/tWkmb3TRY5Lr2TBTqN0U88drHZX7LPuY64BYHkGPxE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0yClpukg4DjIO9xNtCmzgUFZ/wCGUhdx3fKGFhxTrsCqDgz5Ot58Su/RrksiCID6GLqmHqvuAM4R40tf2QcI6gcyV0G33Cdrl9A2RhjJt3A+UvajVKGHauhP6jp8zTNxAoMF9Hl9x1mW31miytdlVNsfNI6XSjxxzdD9kPW6SHDJpLQAsQ== 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)(376014)(7416014)(36860700013)(82310400026)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 23:25:05.1169 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 66818e36-bf14-4ba4-e306-08dd18a8b680 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: SA2PEPF00003F64.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB9352 From: Ashish Kalra Remove dev_info and dev_err messages related to SEV/SNP initialization from callers and instead move those inside __sev_platform_init_locked() and __sev_snp_init_locked(). This allows both _sev_platform_init_locked() and various SEV/SNP ioctls to call __sev_platform_init_locked() and __sev_snp_init_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 | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index af018afd9cd7..a17796729725 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1177,19 +1177,27 @@ static int __sev_snp_init_locked(int *error) rc = __sev_do_cmd_locked(cmd, arg, error); if (rc) - return rc; + goto err; /* 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) - return rc; + goto err; 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 0; + +err: + dev_err(sev->dev, "SEV-SNP: failed to INIT rc %d, error %#x\n", + rc, *error); return rc; } @@ -1268,7 +1276,7 @@ static int __sev_platform_init_locked(int *error) rc = __sev_platform_init_handle_init_ex_path(sev); if (rc) - return rc; + goto err; rc = __sev_do_init_locked(&psp_ret); if (rc && psp_ret == SEV_RET_SECURE_DATA_INVALID) { @@ -1288,7 +1296,7 @@ static int __sev_platform_init_locked(int *error) *error = psp_ret; if (rc) - return rc; + goto err; sev->state = SEV_STATE_INIT; @@ -1296,7 +1304,7 @@ static int __sev_platform_init_locked(int *error) wbinvd_on_all_cpus(); rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, error); if (rc) - return rc; + goto err; dev_dbg(sev->dev, "SEV firmware initialized\n"); @@ -1304,6 +1312,11 @@ static int __sev_platform_init_locked(int *error) sev->api_minor, sev->build); return 0; + +err: + dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n", + psp_ret, rc); + return rc; } static int _sev_platform_init_locked(struct sev_platform_init_args *args) @@ -1329,8 +1342,7 @@ static int _sev_platform_init_locked(struct sev_platform_init_args *args) * 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_info(sev->dev, "SEV-SNP: failed, continue to INIT SEV firmware\n"); } /* Defer legacy SEV/SEV-ES support if allowed by caller/module. */ From patchwork Mon Dec 9 23:25:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashish Kalra X-Patchwork-Id: 848481 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2077.outbound.protection.outlook.com [40.107.92.77]) (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 1BD531FD78B; Mon, 9 Dec 2024 23:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786731; cv=fail; b=SiU4lcLE0pBMnU7aPTtrhBohIz2mvQ9RobrjdWhQrro3BVVsDgy4RiTe4SKclYnw7I6Ksd8vOfhdgmL3G9/PfXG19CGlkLW4FbdCjk7B7iigmc7XGUO5oZzV4xFVCf/8eK8hSGaEuZVx1JzYCXwb1JfnFkhxxsJ4jTGtEKhBBSE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786731; c=relaxed/simple; bh=UQW7ojek5ljET2pPQ+4Hpvk76wSJhEUuhgnJVBIqW+Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t3t+1XMqczQrj6UJiM4H26gGrahfhW2x02vOFfH3rttcIW4AQkIvPs5Zra7z7WM7SiHoCuDKCZXkQ6sCqj6WXDU8lL2D03aSP3rgUH38Xbgjsnhma23BAqWf8bX3fjQCG/MCNlRIAaksh6nI7mijBf54aTQfCO4CnceMsnFV2hA= 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=V0NoV7HV; arc=fail smtp.client-ip=40.107.92.77 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="V0NoV7HV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=b5p3/x8rKtTQvY4dd40P8cY3/Uz8s0YHYCuuvhP+DXSd2X01/pCLGC4qmaDGzTx1si9yEpBucM4IjCQzHO8q7aMsA1OJ4AdmORXNG/DiboHDA/d+Y44j9SwGAS9ZOVcjt3lOGGxZp2+bEIQyiZGlbTwLQfkPg8m82B4h4bs1lIPROOvCJ/H9uuMmkmv0LTi+A19ONPmqMqMnG9Osl7emJ1RLzyRHAHYc+YeIPKCkUxEDIQEKwsfbFmknM8japZ7USW1cR7enVoHlJcly5UaSVKGqxKISOpQC8zzCLUlg93Adchl9XzOIZwmLx7qwQHdUVdT6nNi7vM4lKe4dKAIngg== 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=rkEfdr6q4hJqBVJ/yMQParUHiblmJCjjaQQf507BzJA=; b=N9laZrhTVhHv07Rlh3JMyYZRQRnRYHjuu1m+4G6rukb5jc+XbvJ6pFPqethD5oRtM/OUwRV75vl0/GFXuEy1Vui+x7biPpa66/nGH43NzHOq0kZYrapc2k+PFHV+69lXzenmsaAmB50g5Nt42nUk00U1COJ5SmvnKDRPFRZ//zRVQjKqIAkuv3KlLpKSGkveus+ZW2Kkh+PzxxJEFOb/KZV4YNOhwB6QrKgqp5KkhM95aaCjgeeh9WixHM460MU77DzatSRjT9PRsxKRKdyeemhwC1abpu1iVE7vUhwLfKFKGYSp41KmsfjpFEd12RR1crZ0Fv20OBM6SK4DNca00g== 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=rkEfdr6q4hJqBVJ/yMQParUHiblmJCjjaQQf507BzJA=; b=V0NoV7HVImgVivYtR/qjm0X4OCavYh47t290uCZJ6SpcBp4ok4Ko4Dfe+9ClWs6fjgwokpSuFeZqTwwVZqEjtsErNnRLxydsE5a3g91ftBoUu4+CUNtdumbwlVKYm7PxESNpzNndg91C9FXU4PGGzxufpVgT3gI9+9JcOKxjGqE= Received: from SA1PR05CA0014.namprd05.prod.outlook.com (2603:10b6:806:2d2::23) by PH0PR12MB7485.namprd12.prod.outlook.com (2603:10b6:510:1e9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Mon, 9 Dec 2024 23:25:22 +0000 Received: from SA2PEPF00003F62.namprd04.prod.outlook.com (2603:10b6:806:2d2:cafe::23) by SA1PR05CA0014.outlook.office365.com (2603:10b6:806:2d2::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.13 via Frontend Transport; Mon, 9 Dec 2024 23:25: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 SA2PEPF00003F62.mail.protection.outlook.com (10.167.248.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Mon, 9 Dec 2024 23:25:22 +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; Mon, 9 Dec 2024 17:25:21 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , Subject: [PATCH 2/7] crypto: ccp: Fix implicit SEV/SNP init and shutdown in ioctls Date: Mon, 9 Dec 2024 23:25:12 +0000 Message-ID: <649eb6196ec94bcfe4504151e9369dd6f8c0b2db.1733785468.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: SA2PEPF00003F62:EE_|PH0PR12MB7485:EE_ X-MS-Office365-Filtering-Correlation-Id: 40479a46-cc8f-4e60-eb8d-08dd18a8c0ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|82310400026|376014|7416014|921020; X-Microsoft-Antispam-Message-Info: MrrM5wjq9r75sYgDSDPV0b058CZTH+mFP+JJB+j8BrWC6EIe8WKj0EFSvcU3crsO+kUlvDD7Z2AFEgawhwSWHa9HnpeF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HhVMLyUBG6u4l09JpK+6kgdwxeJHgAPKC52+84m1WmlES4/gCV9tcG1unRARwm5Borr/4wPJFLzg8IDGZO6Ftpn+y9nJunL8/fC1qdPVswvqL7BNfeZcpsmMFxoq+UtrNx0uUX9uPaLO3ZheJ9goUsFwJjh+2C2CxSTYRwaaseXH/ElyEXxg1Vn25MkZ8fksI6k61pSOhK5FI757anQkWonVb4KVpYftWidZBdny6NYqVG//X15buSHPUv5ArgR7LKPIRA636DJ/okrK20+21kVIJTjxzlZH/VJd7K9zl24OCCMjU1FvJ5ibd2XK/lJKhSn/V5g== 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)(376014)(7416014)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 23:25:22.3899 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 40479a46-cc8f-4e60-eb8d-08dd18a8c0ce 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: SA2PEPF00003F62.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7485 From: Ashish Kalra Modify the behavior of implicit SEV initialization in some of the SEV ioctls to do both SEV initialization and shutdown and adds 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. Signed-off-by: Ashish Kalra --- drivers/crypto/ccp/sev-dev.c | 149 +++++++++++++++++++++++++++++------ 1 file changed, 125 insertions(+), 24 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index a17796729725..d8673d8836f1 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1453,7 +1453,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, ret, error; if (!writable) return -EPERM; @@ -1462,19 +1463,30 @@ 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; + } + + rc = __sev_do_cmd_locked(cmd, NULL, &argp->error); + + if (shutdown_required) { + ret = __sev_platform_shutdown_locked(&error); + if (ret) + dev_err(sev->dev, "SEV: failed to SHUTDOWN error %#x, rc %d\n", + error, ret); } - return __sev_do_cmd_locked(cmd, NULL, &argp->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; + int ret, rc, error; void *blob = NULL; - int ret; if (!writable) return -EPERM; @@ -1505,6 +1517,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); @@ -1523,6 +1536,13 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable) } e_free_blob: + if (shutdown_required) { + rc = __sev_platform_shutdown_locked(&error); + if (rc) + dev_err(sev->dev, "SEV: failed to SHUTDOWN error %#x, rc %d\n", + error, rc); + } + kfree(blob); return ret; } @@ -1738,8 +1758,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, rc, error; if (!writable) return -EPERM; @@ -1771,11 +1792,19 @@ 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) { + rc = __sev_platform_shutdown_locked(&error); + if (rc) + dev_err(sev->dev, "SEV: failed to SHUTDOWN error %#x, rc %d\n", + error, rc); + } + kfree(oca_blob); e_free_pek: kfree(pek_blob); @@ -1892,17 +1921,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, rc, error; if (copy_from_user(&input, (void __user *)argp->data, sizeof(input))) return -EFAULT; @@ -1943,6 +1963,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) + return -EPERM; + 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. */ @@ -1969,6 +1999,13 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable) } e_free_cert: + if (shutdown_required) { + rc = __sev_platform_shutdown_locked(&error); + if (rc) + dev_err(sev->dev, "SEV: failed to SHUTDOWN error %#x, rc %d\n", + error, rc); + } + kfree(cert_blob); e_free_pdh: kfree(pdh_blob); @@ -1978,12 +2015,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, rc, error; void *data; - int ret; - if (!sev->snp_initialized || !argp->data) + if (!argp->data) return -EINVAL; status_page = alloc_page(GFP_KERNEL_ACCOUNT); @@ -1992,6 +2030,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). @@ -2020,6 +2065,13 @@ static int sev_ioctl_do_snp_platform_status(struct sev_issue_cmd *argp) ret = -EFAULT; cleanup: + if (shutdown_required) { + rc = __sev_snp_shutdown_locked(&error, false); + if (rc) + dev_err(sev->dev, "SEV-SNP: failed to SHUTDOWN error %#x, rc %d\n", + error, rc); + } + __free_pages(status_page, 0); return ret; } @@ -2028,21 +2080,38 @@ 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, rc, 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) { + rc = __sev_snp_shutdown_locked(&error, false); + if (rc) + dev_err(sev->dev, "SEV-SNP: failed to SHUTDOWN error %#x, rc %d\n", + error, rc); + } + + 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, rc, error; - if (!sev->snp_initialized || !argp->data) + if (!argp->data) return -EINVAL; if (!writable) @@ -2051,17 +2120,34 @@ 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) { + rc = __sev_snp_shutdown_locked(&error, false); + if (rc) + dev_err(sev->dev, "SEV-SNP: failed to SHUTDOWN error %#x, rc %d\n", + error, rc); + } + + 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, rc, error; void *blob; - int ret; - if (!sev->snp_initialized || !argp->data) + if (!argp->data) return -EINVAL; if (!writable) @@ -2080,8 +2166,23 @@ 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) { + rc = __sev_snp_shutdown_locked(&error, false); + if (rc) + dev_err(sev->dev, "SEV-SNP: failed to SHUTDOWN error %#x, rc %d\n", + error, rc); + } + +cleanup: kfree(blob); return ret; From patchwork Mon Dec 9 23:25:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashish Kalra X-Patchwork-Id: 849427 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2049.outbound.protection.outlook.com [40.107.244.49]) (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 D70521F63F1; Mon, 9 Dec 2024 23:25:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786744; cv=fail; b=qzbzq66zETVwZC5i6xSUsKr03XurqWqoreYFk8V/RQ5UCSpRR9SrwdIoltoqkudlYhNSFYjVr8QxPqGdVmLpCcZqQb8wZDBk2g6I3d984LEJC04SYUAumnyI9QtNoVks+8V8QS2rfgYaHaOlQlUsbiDS/+Q2pMbt2nXTumvQfDw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786744; c=relaxed/simple; bh=i5jU1X56vzj1nFBc7I+Miw+DhGUHikyugO0P89N9wrQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YjJOGfdg7lOVC6ZlI6XWajULOCIY1nDBJmQrUt0Vm1Ms/Nn86lgTjui0RW5B5FrjOi85BsoCPBfzg6Ue2Ks6KpXaJO8dwQnEnsWRoA5iM76+tfBdl9HKuVW8d+5wtqvpGOeZrTbqXvzTmf22osXc3QvOaAryinY/v7HCvX5oZpc= 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=lYT16ELS; arc=fail smtp.client-ip=40.107.244.49 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="lYT16ELS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XWtSOZoNCwcITu897bjBauF71PiJg52/GErzVbcrcf+Aq5VRNyucDoOJR10XLFH9eHH0rRdsJrYzDsJjnxSB6bnC/T2e0QqYHepmYc2lpbOqcUh7LRtYkV69JYDZrqLmyMgofmtCWUkk/dIQ01ge1boSobTg5wi7wylOCnCvMzKOhu+TuuklMmjQmuIpAVhdUURFH4SNtImjnzsfJTA9xyuGWmnzFtpG2ZfvRuy8ExZovjM2l4uWW6v7R+Vnw4OQzag6Qoiqv+qCbfngLdLpPdn7A8qJJPTTs7ic95zKVxgVzOJt4tlGeePVubVW9WpMhEbaBb/j012LiUr6ZYWaLw== 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=IXBJ7t7MKmDFRuKxWJRhNMkHsBmKAyCkraYottVCnAQ=; b=KHOiByA2GwgQMY8d8JMJ95BWEZ8/qtiVcIfONmd8PwdkgGnlWc4ZPznmttsWxdGUV3tZn7WaK2Wyu1CxVrguOLG5j6pqIGrzZSKnW8hBb2WiZzkd1n6zm5J47QOiQUlOFKJGPoH7nVmnlDLJGuM2Q/UxWHV0aiRPV1izVS7BwlAfMjRkKul6rLiUa1+R/NvzgljxvRzZlrMZ2HWcTUM/BTmsb4okJhD6v2oE/mqRDJNVyUoC/JJ3IS60eUV30qVz0talEmne5KcMWhK9vsd39pyl1qBW34bDFpFoYmzD76J1dRXQMcCnEuWMDp/J5RnQujZPnxNDukYJOLNj0LripQ== 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=IXBJ7t7MKmDFRuKxWJRhNMkHsBmKAyCkraYottVCnAQ=; b=lYT16ELSU/RXH6up1ETqcxW9SdPrZvrHTsCGKE7OfBuX1ma932PGhJ20cWGxZSmbYjE1ukpafNwB2e95GuXknJIeBXO/1mHut9VYFEw2tW5Dx6fKSlaG2DX7HzVvKe0UHVz4SuSe9KUiwf7bA9p8hbptmzHT+UPblB+J1lXdTTM= Received: from SN1PR12CA0067.namprd12.prod.outlook.com (2603:10b6:802:20::38) by CY8PR12MB7658.namprd12.prod.outlook.com (2603:10b6:930:9e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Mon, 9 Dec 2024 23:25:39 +0000 Received: from SA2PEPF00003F68.namprd04.prod.outlook.com (2603:10b6:802:20:cafe::7f) by SN1PR12CA0067.outlook.office365.com (2603:10b6:802:20::38) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.12 via Frontend Transport; Mon, 9 Dec 2024 23:25: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 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.8230.7 via Frontend Transport; Mon, 9 Dec 2024 23:25: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; Mon, 9 Dec 2024 17:25:38 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , Subject: [PATCH 3/7] crypto: ccp: Reset TMR size at SNP Shutdown Date: Mon, 9 Dec 2024 23:25:29 +0000 Message-ID: <38fd273759f9dc3d8703634cd921b08296997494.1733785468.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_|CY8PR12MB7658:EE_ X-MS-Office365-Filtering-Correlation-Id: cfc4cf91-682a-43df-953b-08dd18a8cb0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|7416014|376014|82310400026|921020; X-Microsoft-Antispam-Message-Info: Ux3kyJfOxhOVKD/HkiM8s6wcvWW7SwoizlJe3BWui4MXYCI594ZJ+SXrvrKwRsEkhrcKtI1Wj0Myi/K4dV+JYfulQbV59CAmP8FD3+mtf6O8o3df/LgZ2oPAaKupqpLoyEYk+VKULfN+7kbPoTAdlt/RDIZSLIH2w3PZaGxps4Rjj8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+fs3wOzlt9csuGFwij/j108R36L2IjHMur/jbiTrDa2NP1RsdwMpbMGfq+1itk+csL+GASA8ZTIymecVNWj2910MB7k/CEjjWXIAC6LKwOG4sDZ33LYgE7xeM88Z8Cn+hegKDEWoOlrJR6Bi0TqJCVFhdpwcqfFt+WK7R3KQ9k68No9Op4cyxP9bLyViePjXpvj6ARZHBSmVmGjF2rdRx2WAWai6mFtqT8GI1pQY6yfdnlFx7wGZw== 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)(7416014)(376014)(82310400026)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 23:25:39.6066 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cfc4cf91-682a-43df-953b-08dd18a8cb0f 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: CY8PR12MB7658 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. Signed-off-by: Ashish Kalra --- 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 d8673d8836f1..bc121ad9ec26 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1750,6 +1750,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 Mon Dec 9 23:25:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashish Kalra X-Patchwork-Id: 848480 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2080.outbound.protection.outlook.com [40.107.95.80]) (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 F0F371F63F1; Mon, 9 Dec 2024 23:26:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786762; cv=fail; b=Kv/gSD3eUYurogemtDGqwb1AS0t+N2Jlj6x0jw3tSEd7ZvYs7p3sRZgzGyAbvGRVrf9ndnQMymWxjJkzasCDOMEKX10CDN/riyteKZqG3oCD4JzGgfUyLXE6b1rTCbhFduxDoB6QX2kNJ8dX+ZEVDHjgDsqGWy3tKXHwARNmPP4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786762; c=relaxed/simple; bh=XRLuIHd6NAb/t02SM3hp2yGUDoL8UifW160vn1Sn5pM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ShlgkKRgIo6fEWWIG1umUV2NF+Gf5yCF/mHxgVHKzRhBOcXS0uDKuV4ljgwLwp7TA0qk9ve/k2srzrLdM2MiblghJ7Kw4kV6x8yXXpRV+FqCBp1Suk4aZWdVziZLAJZQGMkPMT2DfC2EcIApBgC119CwPp7kQgw7+DXZq6kLJ/g= 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=pcJdeoXQ; arc=fail smtp.client-ip=40.107.95.80 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="pcJdeoXQ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wvEJj4okxEmQSrWZ1kykljPeVtPpQOZ1SHFPiWb/3Af+R5t7XRCb/+/+htRj9NygNyAuB+4bb6H6j9/bSx8e5+nSNBR3xWtbwqw3Hlnreb3FOuZPMFDAHi0WQZLuYh5LiD/qwYsCpFoWHiFJeiBls4cACP6YcBfG9VxLHivbpz/ekcS1XjnKJjLVVhPLChFfLkrFray03i8bMeJLZL2K0yzd9kUWzdJKpBq3EBBlHsqU/0wbCUHJMdQHJT8iNb2QcWikeHvus2norgAm/vfSMjeb36uQBLK6HFcDCHwZKePhqEHoDk9m3yQo36r+h/8dbvMk56uvTz+k9DHu0ZCMGA== 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=gyG780XwFfTd6tHy6LEsfWfQuw2LNmfo4IVc60oMAJU=; b=mH93MfgcxXXsctIA3CQ3rxa4PaKbmqahJbz9jIOTjRzs/qCsULxXUsw/fN8NWWURMbAp1vbWP07Ck+o3YFCA8N+k9pNK7iIS+bfuQyzwkpwI65buOanflqqdLxXRG+mRUjMlDE/WAdzovKDnRGk5iSFRjdXUT+FTHrEgExDTeFyb1dIMTzzusLWsg9PdZQIQnc1bhHkns8UaSdLwJw/cxcn2UumSqOMCUoHvnMHH199k1ByJQQqUU0mKsUK55iSbxUH3k+RpuIFuSdWVUS15QWTBr0NM5jgoCd64ySKTEbDPkJIL1F42QcxQl4mWbcztfz1itKwlN6RZ0BZoDjCJmw== 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=gyG780XwFfTd6tHy6LEsfWfQuw2LNmfo4IVc60oMAJU=; b=pcJdeoXQuQUYbmAjK4ZPT/HG5VmyVoaok+X+NNIoNOA5JMvuqbnmdWtYL9iJe9vs9q9ZxWjJ6NVzztAqXQeq4QbTfataiHI6kgHcikRTlmSybc1edTKYj50jwCtjo3bGa3Xp2o8ZIr3H52nN2qw7EnJcs36masxCNTjUhROO37U= Received: from SA1P222CA0124.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c5::12) by CY5PR12MB6227.namprd12.prod.outlook.com (2603:10b6:930:21::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Mon, 9 Dec 2024 23:25:57 +0000 Received: from SA2PEPF00003F65.namprd04.prod.outlook.com (2603:10b6:806:3c5:cafe::1c) by SA1P222CA0124.outlook.office365.com (2603:10b6:806:3c5::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.15 via Frontend Transport; Mon, 9 Dec 2024 23:25: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 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.8230.7 via Frontend Transport; Mon, 9 Dec 2024 23:25:57 +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; Mon, 9 Dec 2024 17:25:56 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , Subject: [PATCH 4/7] crypto: ccp: Register SNP panic notifier only if SNP is enabled Date: Mon, 9 Dec 2024 23:25: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: SA2PEPF00003F65:EE_|CY5PR12MB6227:EE_ X-MS-Office365-Filtering-Correlation-Id: 143f93e3-2c0c-45c0-3995-08dd18a8d590 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|7416014|376014|36860700013|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: eKvQlk3MPkGJk5D4xA8eJOIgXupJKISxnLrYiwqpiAIK5VTSK8EVsNR2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/pMMD2zEcBncx1z6BjG+T/+tOi+CmpTxkcQRP6oLMbuG62XYj1eAeteUwqbWGdgLVChbSpo+dCoUKBlqlhsFbYYFODL4hsFnNc5CNC7EeoDE1uBH8cX70RwWFj7u734numZXdJezwY0IYNiyaKFXM/xQHX43OWVkA+H44ADXuCVWdXwWAEDb4KMm6stqgffgG9Y6a6rnr8VIqSQx64XvsE/9OQR7Sfh7izNeVfonv/WU8bhlnTcAjHRKcI0Xqr8PwbaBbF40BUc2to0g0h23L7djW9l6DarK5WmFnBxQuzDPheIGc96CtAY3An2xPL3cPyAc0Fq6/kVqpDQhpA1Edb9ka1Zs4J20zgoRoS+AhV/H+sknQ== 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)(376014)(36860700013)(82310400026)(1800799024)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 23:25:57.2268 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 143f93e3-2c0c-45c0-3995-08dd18a8d590 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: CY5PR12MB6227 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. Signed-off-by: Ashish Kalra --- drivers/crypto/ccp/sev-dev.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index bc121ad9ec26..21faf4c4c4ec 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; @@ -1191,6 +1198,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; @@ -1750,6 +1760,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; @@ -2489,10 +2502,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) { @@ -2541,8 +2550,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: @@ -2560,6 +2567,4 @@ void sev_pci_exit(void) sev_firmware_shutdown(sev); - atomic_notifier_chain_unregister(&panic_notifier_list, - &snp_panic_notifier); } From patchwork Mon Dec 9 23:26:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashish Kalra X-Patchwork-Id: 849426 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2066.outbound.protection.outlook.com [40.107.243.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 5D08B1F63F7; Mon, 9 Dec 2024 23:26:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786778; cv=fail; b=Sgoz16A1uCKoMGJPHi/5jYfohfZLOBy5Cpc8bhsBR4Rh0rcdW77E6d9U3adH+LR0P4gGnVPpTs/Kd0Gzwrk88gStKXYsXJeb7vpxZq84cITlgu9lYVB5TVWERGuO/BJof1fkMfi7CPQWzr30ED3wHxgnEE3Zv/Q1XwXClHuaa+0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786778; c=relaxed/simple; bh=Xj6xU4HvdyCfXcWyrW0YWOysGCKY3b9ga9+q950Toj0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZwmJ/TUPHpqeWa99HhM2A35ZOsovBgivQzp7H1IZgBRvUVG/02fifjZ6pd4eAsXFfOj0myHOnG2VKQLWzdNMzTo6cjBDZBrOU7Jg+giMRRMXx4B7Ej3mFPyLrhIRBTfhp16pwDhAbNmAAwgw0mPK+aOIEQkLAHG5CPq7KIQSjkA= 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=0QOYvBpq; arc=fail smtp.client-ip=40.107.243.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="0QOYvBpq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Vp1oVC2/Nb4pKfODorwwFIpsKYYBFC/vjkuMyklGCED7JAi8OXtID3ZwOGCzVncKX4traXi1S0p7WIPdviQa/gcCGlOcCKGYR+uqm2iYSKD5CAs1S0aqoZpDBAbqIaGBTVp1xRt4E/NF6ew7hrfVLze7P8j8nIkvZJ+Ee/r5Sbn44ZPdGwTTTYQK5pvYGJgj5bChpxtgN/oPSjRgAY557Ti+BTNQzYDaFFXyBORs0g2Zpw8EPfR3ChhsQKpYisQPImhrEdl9dorZPkUiY4yZNoGCkWWafnh/lbUYdxvOrMSqws214LJefUUknGEiLNq+6+eriROclyAf1Ujl/eueFQ== 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=UeClOsYnsfYv/ynEGCv0F2Oaq0h9asa4VflWepZi3h0=; b=OrwpAimK0WV1W6/NejM4oFmTZv0vmzvvCqXKCx0sIcuCBOV6hOuLCacKnaEG7RG7ZxRaR7+B0RG+cp3VqkmP49L4PURKNed/7AoI067+1VrVZXxNFSJP7TaSpxsQw8/hvMc7vxDQaeXa5qQDEwtv74FYEycgh7+r3qoz6bc0RyATY5T5B+IRkgVuQnADcAcopPLcuJMxj1XQ54PHej0jx9CHzlAn0di6jQ2itu5QVGBQbLj5jxNH7vuf1Jw6h9dqhgS3QVnyenTw+UTQK65G/q66j4ZD/eqb8t/pYUSMcDSaeYpTM/WnHyajzwghuHWL5Ni1+opzbu2IQHUDTB7PVg== 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=UeClOsYnsfYv/ynEGCv0F2Oaq0h9asa4VflWepZi3h0=; b=0QOYvBpql6yuDI6VgfMEEt74yXD29YPg+zIjUWk17LjGbZPgIB437HiQ3MeQD4ixlqCsC30gt2wtwZEI93I60MNzwcsuJYU86nupKU9JwRqeI5LpAfvg9hVYW2hxQDe/BBwtqrBQTPaAFEzdDN97rTJ5EeaLVI4O/1chP4Z/RS4= Received: from SA1P222CA0121.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c5::9) by SA0PR12MB4463.namprd12.prod.outlook.com (2603:10b6:806:92::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.12; Mon, 9 Dec 2024 23:26:14 +0000 Received: from SA2PEPF00003F65.namprd04.prod.outlook.com (2603:10b6:806:3c5:cafe::2f) by SA1P222CA0121.outlook.office365.com (2603:10b6:806:3c5::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.14 via Frontend Transport; Mon, 9 Dec 2024 23:26: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 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.8230.7 via Frontend Transport; Mon, 9 Dec 2024 23:26:14 +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; Mon, 9 Dec 2024 17:26:13 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , Subject: [PATCH 5/7] crypto: ccp: Add new SEV/SNP platform shutdown API Date: Mon, 9 Dec 2024 23:26:03 +0000 Message-ID: <7a247f583553ea0b24ff772885570082a42f8c2f.1733785468.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_|SA0PR12MB4463:EE_ X-MS-Office365-Filtering-Correlation-Id: b93cb5da-fe0a-4225-ed40-08dd18a8dfa3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|7416014|376014|82310400026|36860700013|1800799024|921020; X-Microsoft-Antispam-Message-Info: 6HxMNmag1V5WKKbaLX+IWlQagMtibN1Td/ohL4n6LP6IYJUPpJ3IOFwOpesMGw1hCvdgb6qnnqblNC+DBT19X0vIJDN9onLIr0mhbArvF/18J6ba42BoT0MYEUHgespI5+tCtcjKqGqzpV+WVugHy1rn1D7sVQhwLtUX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BTre08Usx4ewYaN0s0QMRO9fT3Awjb/tcgpxek3xpkDZC58RZ5dFyzRmtvXfEZDOqtOwUx055ISJSTnawpVsmS7Qy/oErnajbuM5W5BU6xnSqq1Rgn8euTrHiq/swXPozHKRBdBdr2nCC47LPpyaHFKKmgbPkHwHQPLaN8tdKDWaeuovpN4eDmxF0L2oNYC9XG5sKWF8Z4iaX36hUZ2vYZxWTM7NCK+fboBiKk2/OKyM03yFm+ffLlBRxJzyppRezJLqf3h3c6yfg== 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)(376014)(82310400026)(36860700013)(1800799024)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 23:26:14.1331 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b93cb5da-fe0a-4225-ed40-08dd18a8dfa3 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: SA0PR12MB4463 From: Ashish Kalra Add new API interface to do SEV/SNP platform shutdown when KVM module is unloaded. Signed-off-by: Ashish Kalra --- 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 21faf4c4c4ec..b8938c96915b 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -2468,6 +2468,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 903ddfea8585..fea20fbe2a8a 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -945,6 +945,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 */ @@ -979,6 +980,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 Mon Dec 9 23:26:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashish Kalra X-Patchwork-Id: 848479 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2067.outbound.protection.outlook.com [40.107.220.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 0807D1BEF97; Mon, 9 Dec 2024 23:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786796; cv=fail; b=mnWHFPhYP0mgKmAxF+425QySbS2MjCM9pumwYXCkuoB2WbGtpo/ze1FMfQfbZi5cfhr+Ha/AqSTnpLHcDCvA0dQhH1dlj8BiKDeL1Z9ik3Gu3U6qrt/sdx/cOxWeyrbkQrVhjHo6B5iJRcePCVKhgdYfcD1hTLdfBpI1GbdPo3k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786796; c=relaxed/simple; bh=F/35dmvZkldhrQbnwFCsE8SqWQPzl6ppWOkk7uyXRnI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WXioWPhAReYPAAT1N83gA7IwuML4bdiaHGTPHQhQbf2SdfSL+ZUHEfA2dMjt/S5GgEpOQFLAKguS1WKtEHfcQxXkflmGl33OJqwtDbTcvDC0plco3dfo+FlQv29gY7IGu4LOKRLygihQNW5NNVpOMiu+kaS+0s7wsKWvsiBNDqQ= 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=XLnwj0Qo; arc=fail smtp.client-ip=40.107.220.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="XLnwj0Qo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lZDCU6zOnQgapBNUYcD0Kc0TQFF3X0NY3VkeRk5oYwK6Lct/lQ5AbM9GD0WXD3RFeUg9AywVG8i1QbHQZxns58j5Et5A7nPSlTd+HoG0L2Gq7JhQx3G2X9yXlfSq0IOl6AxivfcL/OJ58XgeRXVILG1vBU8fhv091x7vcnGEBKuBTbmMo4kJ2P2vFb2HS4RW2GC+l7krY2em1wiO+6rthoyH2SJd1FfgVoTv8Kfwl2vpe0Yjhb5gqXPmEiba8MobcWI78DvXy3jwKNMbv0YxT1NAO4IZ3GKOMMtgWtQg1Q8kuOCqOMz6yWDOBLyKZfnKA9FzjGuThWY+DSNvSBEFTg== 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=6lEVj5KqtcuT71cWqXxzZRa5CQVzK5eTVd6RS65Lz3k=; b=BkSwiLCMcLuhRWNUM1rjS2liHFFfv8nA92PQ0quZKCIAVCB+ZNdCcZGWoe1Yyu/X5gC3aq8L3hr7WXmKNo7GN+k7R3Nn4NSrroPNoB9ItyrgK+VC2xsNnkINwPmKsJmaoKFqoxJycLoVPgpoxzzbsxlcHM651L3QBgD//kWpAN2jEzVSnYx1HjKcwmanfTUt9oCXmIvifuZ83bZOI/lu7NOIMCD1qRGznwSbHY9Hmai2aQEAho4oZjxPc33/bzME+N17Nd7DNoT1OOUvyyFr96QxiTSR5INCjJwiqI+dIeGQtWrR5Lw7BqDWans9x7AgcJqYsTmz12etbePm+c6oTg== 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=6lEVj5KqtcuT71cWqXxzZRa5CQVzK5eTVd6RS65Lz3k=; b=XLnwj0QozrPv6N2ev4+UDKTKyPbHTIAPvKZlPcw4dwu5ZLkj2ey1fWWm5T1XcZzaIkLPBtV7h8jgo8lLZg7NKEYUcpPzvPUWwoG1mLIh5T1VvcKWxlUoEXH3mCy+saeKSNCBACfQ77KmkRXz1dIS5vSNYe8VSxbhbWwNko3WnLY= Received: from SN7P222CA0009.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::34) by DS7PR12MB9526.namprd12.prod.outlook.com (2603:10b6:8:251::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Mon, 9 Dec 2024 23:26:31 +0000 Received: from SA2PEPF00003F64.namprd04.prod.outlook.com (2603:10b6:806:124:cafe::5a) by SN7P222CA0009.outlook.office365.com (2603:10b6:806:124::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.15 via Frontend Transport; Mon, 9 Dec 2024 23:26: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 SA2PEPF00003F64.mail.protection.outlook.com (10.167.248.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Mon, 9 Dec 2024 23:26: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; Mon, 9 Dec 2024 17:26:29 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , Subject: [PATCH 6/7] KVM: SVM: Add support to initialize SEV/SNP functionality in KVM Date: Mon, 9 Dec 2024 23:26:20 +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: SA2PEPF00003F64:EE_|DS7PR12MB9526:EE_ X-MS-Office365-Filtering-Correlation-Id: 34a8658f-cbee-48d1-c3e8-08dd18a8e98c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|7416014|82310400026|36860700013|1800799024|921020; X-Microsoft-Antispam-Message-Info: n+dGOxg+SAjUyGDGJFgodO/20f4S1C0X59t7rZ1JsTV7x/vevykgrTdJkPqfApAIC6ZAokjaV7CedP1U91UsZDPw2jDYO6BIE6e0nseR0T0Hw/qaFhhDCYz/Mt7D6EUT2AAqkV7MbVu/J0t8pTF6lyEBdtTnb7ejSuRCONo+Y5buEAIlKdlJ4RR7lNmicnGq0MIrkePzYTAjUvC0vZgCRzXRjxShyl1X0ZCD9BPpO4RgRpaAtpkOAO8Y1fMxrhuSWh8leg/Vsl8irHNMNwUy/+211wi9ybfmbvcOnhW9zfmwkAD52szT22k1kBYLJ8twppnuREt/1oAGXhqF93q58K02hDqHR72I2zuEHXW/+llxpnU/DpTeB4gL6l/Z4FdOybZDXdI+V1cx6IhsG/ON0CWekT601pxoFRFzz9iQvkY/O7v0CViMVxtdx4H/xcbCxvWuvPWkbPg5OWUTpPfLbrHfQwyubo5QmwOPnNQ51UPChYDxUDhh0HT5RLzg61hQJhCKLnG7WCCBtMiWn7kGxd/oj7UGRQiiCzSwSZG78M+Ae+knSPQiLjMIcQLGquZaJWoPLX3kRylqo4yzvkFAMHe1/P8efwC34wkfG3WO8iiLMIUdGdyidLZRTQ7ozIJqSlBm+F4yuJfJVnuwTJL0WZVBQexeH5SfLhb9dUj+UD3qszE7MfM8pT8SVdO0K0ciqq8M6fzqk6SgMgky9l27TrEB2/1ZyKHhdg+qlvs4+LHefq3VghAjkj4uVDA2UenRIc2875wshNHnezbIgxlm5bXRxhNdLzF2aMt3XVet296lt0vSqC7wHOR69a7+8OSvyieKEzdslFHyNQMNPT1NMCPTna1YKV7Ev4wCcDh/7uO1v5lJVSk0pbBWVF6KJWhRmAN/x4y+1QCjplTMHj5BtBMJhf7+bN94nqLhy/sNTt1Pj1n9oum8evYoIS2gQyhJE0iH1H5V+agQPDeUpdY9fKq1dDWNJCnmOwxAtEg4P9x8SkjgyLBt3AxCzRjgPxuvbG6wIkSZR//Axx6hw6CBZTahiJHPvm2XnNMe4yHp35Azp3AcbBpO3Qp0OHvEbAbbzHWnjX3p47NxzCa+2dFEGayiaT0V0i70uKfZCu1zzXrbcPAZtQQIXbC0wgsrHllRClgHnHjlZqdLv5GHnrC3l1mDqE/xBDzon3tQMkESBE2YPjQt8NyH2MfR3bem5laTyhMst/wNyUUGTxmUJc3HEyuMU2vWnnKEYdx/wix4DhjsxbxZ4UWHJPeDZn5o14chTjvo6sN24Pc84EnjuTEB8W9NKj2cnvas7BH4+pXUwM4riVmOR/vB4H4+iR7eBaiG2M9F4oDFloydj89AqQGEr6LOm020OGqsQiwlCOxEd8EGaTd9acRn8Ss+WY34LYYDcLMTyHSv6ZuPpA/wgWPAHiBucdWXcsNWXDV81R64VvYiZOKJ5onDKLciAbx7XLLfqTqrba5bgwFnlgLTKuem6Q== 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)(7416014)(82310400026)(36860700013)(1800799024)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 23:26:30.7586 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 34a8658f-cbee-48d1-c3e8-08dd18a8e98c 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: SA2PEPF00003F64.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB9526 From: Ashish Kalra Remove platform initialization of SEV/SNP from PSP driver probe time and move it to KVM module load time so that KVM can do SEV/SNP platform initialization explicitly if it actually wants to use SEV/SNP functionality. With this patch, KVM will 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. Signed-off-by: Ashish Kalra --- arch/x86/kvm/svm/sev.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 72674b8825c4..ffb5c907c5bb 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2966,6 +2966,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; @@ -3082,6 +3083,13 @@ 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; + + /* Do SEV/SNP INIT */ + init_args.probe = true; + sev_platform_init(&init_args); } void sev_hardware_unsetup(void) @@ -3097,6 +3105,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/SNP Shutdown */ + sev_platform_shutdown(); } int sev_cpu_init(struct svm_cpu_data *sd) From patchwork Mon Dec 9 23:26:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashish Kalra X-Patchwork-Id: 849425 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2059.outbound.protection.outlook.com [40.107.92.59]) (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 23B861F63ED; Mon, 9 Dec 2024 23:26:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786813; cv=fail; b=hHfwgvSaEdMOsBmOO1I6NxRTlfX+PmQnCBX7DjaQ1j+3JfkR8xqRROnMVm8QTTZrULQXTPskMHXq1XSaGQma9BI3D6xsB/uoPn025UdwCR/ejukmpwqyu6MZlMqf2HrJzG9iQ04AGZQb7atCBEHX7JOK/GumW6ieR9K/rPwWvps= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733786813; c=relaxed/simple; bh=+K/vxkwEDi5ITWxFyyh9ydzrNB1ByGyVWGA+yYpUH0I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OV7abQcQqclDTA/06pU0JN+M0NKQXXOUXUgwB/3I1fCxWb4GxQmoyg43ucSFzaJNCXq/NBY3YT5TVd5KBjfAbK0nv1kivL7iVKuVh/slXmIVXrL5pW0bh5G+CVnD4P/VBK7wBqLt0/cNVRAnbNOacbqwrPbrTHcgHT+47TRi8Dc= 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=iodtDyV5; arc=fail smtp.client-ip=40.107.92.59 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="iodtDyV5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ePZzRSgWlDgyhAUtDdPtdlUqvR5BGCBOZqPgsh+6K7j9eyISykrT+sCj6Ymw+anYshDdmLLHBxu/D+BoW13RDDDyV9E+FBb2G2UrQqmiatFnObkXNiMcwlxZorsiX1wuXx17AJ9k/QKuBEkoEXLvUMC+D0KPY2gjHs+Ka42xSP98s0ceJnuorl5nMfZdliLW6aQk/lcCfc7gIT3DefZX3IB49Yc7mrzHJNNNP3sxxMcAv4twHwG8HnaB8r6SnSM8ImSu2FSUI/oICKjODx52tb7O6vb7WL2jY11UBtdlCEoLuAIQrkSI4Y6S1U//ee4MCuFK4QqxprBBjrAHzUMfrw== 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=TrAwe1BAilVXJlrfkQ47r9N2MLlEwHGTplDZfKUWkbM=; b=vVwVJrlDQwieE6g3tpwU85fmwzyZORzI3itMqEWTTUG5kJb3kuVhKuMYbPSNJgjUAxbReedJLUQByBYiqXqjv6VwPbG3b1OMWwJjLs2Swo049T5ucaNFCwKP9vXSBBVyGmsuoSCe74ynJO/ZHDXvYLddbIZ7kkYdz+Yr5pjPz3F2O89EIa9lRBS5bgsw1h3jwTKLlKehvfqOt98NbcN27hAEq+7XrPOm9ifdIorSujzavAGidZ26wiqFZ1y2ACqU07cypEIFYxahJXmYQUQlA9RkClJVpAhHQOjEI14uHxOytVE1A/KaeEr8e8uTMbcBYGQCMPNn1p5IOuhnc2VZ+A== 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=TrAwe1BAilVXJlrfkQ47r9N2MLlEwHGTplDZfKUWkbM=; b=iodtDyV5A44rGP9tJRITHVYaJf2px8IiHkBjpvuSj3xUNyZ4lOOxpPi03nJ9g/CYQC5MNcpOKar63YlmfCvyb6iLXjlqVmbeFGVI8CsS6v9IydX9hrJUK0pyfFuaoZ7qFEACU0Ti0UOjDfje1j//94Prn/gsoWBeP3kHGUkZZ3U= Received: from SA0PR11CA0179.namprd11.prod.outlook.com (2603:10b6:806:1bb::34) by SN7PR12MB7249.namprd12.prod.outlook.com (2603:10b6:806:2a9::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.24; Mon, 9 Dec 2024 23:26:48 +0000 Received: from SA2PEPF00003F63.namprd04.prod.outlook.com (2603:10b6:806:1bb:cafe::5e) by SA0PR11CA0179.outlook.office365.com (2603:10b6:806:1bb::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.12 via Frontend Transport; Mon, 9 Dec 2024 23:26:48 +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.8230.7 via Frontend Transport; Mon, 9 Dec 2024 23:26:47 +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; Mon, 9 Dec 2024 17:26:46 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , Subject: [PATCH 7/7] crypto: ccp: Move SEV/SNP Platform initialization to KVM Date: Mon, 9 Dec 2024 23:26:37 +0000 Message-ID: <9ab04dfe22c067eb412ed4198b26c5d1482c6c22.1733785468.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: SA2PEPF00003F63:EE_|SN7PR12MB7249:EE_ X-MS-Office365-Filtering-Correlation-Id: ee84bfba-3cb7-48f0-a7e4-08dd18a8f379 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|7416014|1800799024|36860700013|921020; X-Microsoft-Antispam-Message-Info: iycZSwUYS7G6kQOb+1ckHthZaIrn88c7uHohfwHUQsMz3SMyfec74RRGsOoRND2VqVvLNP+1fSWzqHzW9ceMKiCtRCd2HzeW80xJfrNRGJ9mbceuBhv+mFEWt8nafgre/hcSleAhldBXqz4ZPnbFGwJI44QFmnGEkvxP02jdAMlRpJynuJ/FSg21iPI7E/OivWFUUxJqCRC8E4zEvPQL25b7whhcpG8dD734j5S52RhFsX6abJN+IZqMxAULZNKrywsA/gzVf6Pw8vvqRCe7wwjsrA9JSxyi+o59kWlJj0ShAgRRI2JBybrAmUIC0w/h5kAfD7oM8eK/vxZXsQzkhwnej6Gb91JEBkRD8co4nIj7zYtI6oPtFhfl08APTo4uefwF88SnvnEqfGS9bCywP9xefMq53/3qop2WeWiJaABavbGqW5KKJpVvFlsN0QZqfL+/iEplrR5PruEyOTEV3P9RtlfzYAI8fejLWlWUGg3ABzC/EoStI3onLdTPAchFTi4lXwCioaMuJakgDLikYrs0MctCx34dAmSixHUz+isEVYXT22rAJJKogSOAFvOE8EdyTcHOXgEQhFlw6qycJooaNnaC85NsIvH5BgtOIL7OFte3GPO0BdbAWbqFPayPN5krvOOYJiymox4yK1CGhHF/8oNZXWq2AFOOANRTsuD5L7r2tSIuUdkFAiX0VwoCnKGoNiHhRZO90oj/vEuD5vGxGjKZLrHPRQfpw1tvzdQGCi+cTT4ChOucwbEEDL7aiIqR8wJEhoMmlxnu4gih6kFHwGFYHjWkP89mxpc6gUsqtnKjx5yc8H0AvxkRnULIqPHPohjCHFoCoB60QpqFutnAc5QZJM658Ov1gP/3EQaQ4oerwak8U6yw7HRt586H3DRDUKEYugiy9vcBIgPX62D8SLc/ccKYeKIhdmpiXkT+lLpzWU9ScYkyKasjplBdQZcQsiCa9938oZpNxxyZj8rd8LWlBJ00VBybbyGKRTd+39EME4lPsF4geuPo2vZOgKtOvhTpZAVOx3Y3cUFqGX8+wNLsZLZTTU3eexU8meHgglI4cBMo1q12SrAXUiADai5aGdPjXkVfY5zZ4i/MmpGDS0Ab7ukkziy+TWziVfP7tles3s7pzW+N1m37C7Qa6Rd9AdXCq2hHm5vR3RhqmBg4es47s70oQFrOd6+yVLBORmQlqbeeL3Jn3322rKLSdHmOp3WfNzSlGNfY3RrYdnZD6ZpUpWC022fqgCH01NBft9EBmDnPcxTUGyBpjh5r0xMYURogXq+FgpJ1IMUN2ZRm9iQbKt/hvnGdm9kaWYqmvZ88q2tCqZry70HyqHmGE+JQ6kpK86lAGy4av2DC8kQtBMnLGS3+E9P1nOndgfRulzc7l624D1Wwb2VvP40aiO74fD0w1m66BLqm/EEZiKtf+srJTYD+SPgrbaVX1q3zFKLr5Rm7GmmfYgfev5ptH1a2XMSuOcA9fnVv/VGW7A== 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)(82310400026)(7416014)(1800799024)(36860700013)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 23:26:47.4105 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ee84bfba-3cb7-48f0-a7e4-08dd18a8f379 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: SN7PR12MB7249 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. Signed-off-by: Ashish Kalra --- drivers/crypto/ccp/sev-dev.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index b8938c96915b..52dce46745ba 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -2528,9 +2528,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; @@ -2553,16 +2551,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: @@ -2577,7 +2565,4 @@ void sev_pci_exit(void) if (!sev) return; - - sev_firmware_shutdown(sev); - }