From patchwork Tue Feb 25 21:00:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 868239 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2059.outbound.protection.outlook.com [40.107.94.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 D577E1A9B46; Tue, 25 Feb 2025 21:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740517230; cv=fail; b=oXitd6pC7pynr4Dz+vBzByLwP7sbt+wZkOFwO/XrUSKyFB0r+79Eqe03/+wlitk5ZcNnubLgfJstrvx7w4CfsckVXhNgHYxNKoRCU4Ogy20XanJkdN2ZDU55RV6PiRfRuj/zV6uyZF2K8aU+abTVQoUz+TI5L9LDyI3KloRZryQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740517230; c=relaxed/simple; bh=6CDhjWJYn1EfXkD3bfYs7kB3C5YO7TKwy+jKrYyspOc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n2nM68YBFNE+EfvJX+CIy09KJ/HH4Z1M7DB4C7WeNK0+9AUXHmZUfqiMw/wg/jE7AzQKp3rMORWP7MKXjd+xS+/MCHYKYDx/CiT2MWLE7KI1q1ssWHrioXKogZdMUwiKH0oSgre8FsBnxGrN0rheLeYepxstgj2st6x9CJFzCn8= 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=BjGeK4Pu; arc=fail smtp.client-ip=40.107.94.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="BjGeK4Pu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tRZpm4h1xDpk8nItz2nj3ZG5x7yWk+Hb/9MRwrK27DpIwwN4NhEu9FJM7anYRVLkZOw8HiBm0SddeZ5MWNJiB8Vak75h5XjFDXfkdSuZYrU/Nl1Zb5acdqVPzujTtg+YcA9x53zaQoMyCZBuZuHQfBu5WGGswmL1dx1CBF224+d6bIQmdVj29utvox2JR0ft8ZM77TBG1q6hYmvmWsi9g/U11/58vCre9ny0sJLu4qN7xnoADOoOL9t4TJ1+CjrawVoL1cD/mDSwkCT5LwsXhaln9cJdOqPDLAfMt8Kp8h8pP7gMWyV8WucrM/On2PH16hk/CIwUipm+KBfYDt4JSQ== 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=9VkwU7vFimV1arO5EjDIioS83t8NaVrIuA8G83ZSp4s=; b=nj7COtQctXAyYIqkDXkYN/9VFEtYHE7JW9epCkTLbWGJw6CTZ+lz4zfE4XXDZr41azlMzyVKGl+j+IcyPkTXh2crl0VWy359aj4N8fEO8dJMX/dfWJDyPEi3uNC5OvHXdOXExnDIvCcVCaLr0X8M59uyZaWvZVSuM0J8FVlyao/RlPryJU/2o/FRp0DPpoFvAiIgbpPZ/rJdYDEvvMGwCU78LMVWEye+REwjz0+jMnIM0kgL1XOM1tOpxIQF93BgrFjSgXPmR4Ww9c1AITuz7tSj3RC9uR412Xe07PYiiGXH7B6TNrIi7uatbIYSp7WD3LS+VilixfJLDzWkFxGotQ== 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=9VkwU7vFimV1arO5EjDIioS83t8NaVrIuA8G83ZSp4s=; b=BjGeK4PuV/GgdW/Rn7+CKqyYkL5yAFwNIu3UDJ7Tb+9/uQTghCl2ttM0yHwg3qTuxLA7Bzy+A7L+guR18EbFa9AmMlqyDw5kEDUMpGAIcE2zIJ8RLNroi/eQOebABOHDOG3PvyjEMaGAKo34CpuGPyaRJqyzLac38F4GbqaC0W0= Received: from SJ0PR13CA0055.namprd13.prod.outlook.com (2603:10b6:a03:2c2::30) by MW4PR12MB7117.namprd12.prod.outlook.com (2603:10b6:303:221::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.18; Tue, 25 Feb 2025 21:00:20 +0000 Received: from CO1PEPF000042A7.namprd03.prod.outlook.com (2603:10b6:a03:2c2:cafe::62) by SJ0PR13CA0055.outlook.office365.com (2603:10b6:a03:2c2::30) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8489.15 via Frontend Transport; Tue, 25 Feb 2025 21:00:20 +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 CO1PEPF000042A7.mail.protection.outlook.com (10.167.243.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8489.16 via Frontend Transport; Tue, 25 Feb 2025 21:00:19 +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; Tue, 25 Feb 2025 15:00:18 -0600 From: Ashish Kalra To: , , , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v5 2/7] crypto: ccp: Ensure implicit SEV/SNP init and shutdown in ioctls Date: Tue, 25 Feb 2025 21:00:09 +0000 Message-ID: <1d7b31af0eb36d860907c1e89e553e642f3882e0.1740512583.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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042A7:EE_|MW4PR12MB7117:EE_ X-MS-Office365-Filtering-Correlation-Id: 87f456f8-1821-4b6d-9152-08dd55df69f7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|82310400026|7416014|36860700013|921020; X-Microsoft-Antispam-Message-Info: yZhx80rpk7pG9vOdU263IHv6nl3mwvabPPbUQtsXYsV0ALB+/O6Nr4oEgRTSf3kgS4ZPCnoZSFaBQNJpN6iaVu9UVV/n7WunV++jT7SJq25KZhqxOo2g415vJKNDRzMq0mR3o2kV8+tOiDOB7G+6gi8Y9cjibBCEekOX5rb+NOF8C+k9c/8HZlqVYXHlWhMkUEgRN46EqvA8bkA/6ILIrxApoAQyPZyIZmnji0rQtJdV8G1Kmi5K9fN2IhawphoXdPsoZNdQDoc9B6eFCn0uk0mr4eYBG6MZ89KbwQvdFeZzVdBudxxuXGEwHkoKCZH/WNfwyiZleSKzsRiMnNvZQCqAXngRvv8gkkmdSF7mfg7U+DmvDjA+XRwd3qL2jbWunwKSoBj6qmpFrDWnYWyx7+AZFS4SvF2Wl5DGSNz4qcawN1InYSKyM+EgwPQytWNmJxss9N9iHB/iIQGAfMVYDwJJm21Pxd315zVjb/Q4gFtN8r/KU1k/TwoSjLCfvKSbHcGbieThiQg9b/XOL2VzSBugUI/EUMMN2JNgcg5QsjCKftQebz+dGbwaOwasuYK6x5sPcJaq8dEL/EEAiQkqEFNvr89KOM6F0F0sKF7PHmvjeP+5DYKW85ywi6K8OdN1CqfL4sLVqvdYP0TuyhOfsp08DuNtie7mBRsQxxDe1UgI9hwfpwQonw0GhcL9No1SYRB0HWqrBvy1Cr7KkZgH21dNN2tEOW4QWnB7B/q1mmFXhEYtF5Xl+Y0fL1oFJuHgtMToFA86i+DSmV3QiWmKSqzQ0ErJBHgPscNLYIYBccgnNJ+v/DJnN6vU0Fy6MFqR4xXHC2hYP8ysQE2046kTsjegt1u734SLfbPNKNS8Tw6uN0LjazQGaQv/3DIPWtr11VmP6XpweJKUYL0Aqdl3u/JurZ2u0lqQCW58BoESbcaHl7p9Kpwu/E0kJigSz9+3I4w3Tk9ee6L1eVWw7M1QM7gGqrsy+B3z/MgekvnYD+WLElQgT6zFmzFGkb/2ruZBMMpFWqE3/EGy1cIgg+yj/DdMJfcCJb6kNNpA9qg0mCjFev6mEy8hJ4Mre4237fsDJdvwWBK+DEnHdzve3R3CHkqdrUGQWax6/mdVCiZdAz3gt2+aJ88EnrA5Uejz6bWmt9R6EuLVK9+tOvqp8cb7ARBRro4+CqaFg01GZw3YiUkwJkaGgrC4eRZBnkuRy9yC3FLJXjegfo4HKkd5cae88tjVwNpcEu5R69+CcJbRWrHunK/8mvqf1QwxfaySqhPM8wleVctW18c61aChynMbjcV1swSu0ervTHfpFc8mdwa9W4Rq1KvtxAB71Qz9UEy3a04lVDz9UzWNQ8CqGiypZ1LC0lpzCB8WggdZqC9EU2APb6Y+GylS+s6h9MQs9jn1U6yHxqpYv+oUH5zrff7pON0AfmW5pmqqKwdZWHzlyyM9Y/75Q2hyONd+YtVSRgb/zvycjR+UFyfrXO4o18jAyevg3/Nj4VtQfZiywLW8p0allTyDkTe41aMf0+K1lluk 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)(82310400026)(7416014)(36860700013)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2025 21:00:19.8816 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 87f456f8-1821-4b6d-9152-08dd55df69f7 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: CO1PEPF000042A7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7117 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. Suggested-by: Tom Lendacky Signed-off-by: Ashish Kalra --- drivers/crypto/ccp/sev-dev.c | 145 +++++++++++++++++++++++++++-------- 1 file changed, 115 insertions(+), 30 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 8962a0dbc66f..14847f1c05fc 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1459,28 +1459,38 @@ 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; if (sev->state == SEV_STATE_UNINIT) { - rc = __sev_platform_init_locked(&argp->error); - if (rc) + rc = __sev_platform_init_locked(&error); + if (rc) { + argp->error = SEV_RET_INVALID_PLATFORM_STATE; 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; @@ -1508,9 +1518,12 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable) cmd: if (sev->state == SEV_STATE_UNINIT) { - ret = __sev_platform_init_locked(&argp->error); - if (ret) + ret = __sev_platform_init_locked(&error); + if (ret) { + argp->error = SEV_RET_INVALID_PLATFORM_STATE; goto e_free_blob; + } + shutdown_required = true; } ret = __sev_do_cmd_locked(SEV_CMD_PEK_CSR, &data, &argp->error); @@ -1529,6 +1542,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; } @@ -1746,8 +1762,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; @@ -1776,14 +1793,20 @@ static int sev_ioctl_do_pek_import(struct sev_issue_cmd *argp, bool writable) /* If platform is not in INIT state then transition it to INIT */ if (sev->state != SEV_STATE_INIT) { - ret = __sev_platform_init_locked(&argp->error); - if (ret) + ret = __sev_platform_init_locked(&error); + if (ret) { + argp->error = SEV_RET_INVALID_PLATFORM_STATE; 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); @@ -1900,17 +1923,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; @@ -1951,6 +1965,18 @@ 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(&error); + if (ret) { + argp->error = SEV_RET_INVALID_PLATFORM_STATE; + 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. */ @@ -1977,6 +2003,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); @@ -1986,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, error; void *data; - int ret; - if (!sev->snp_initialized || !argp->data) + if (!argp->data) return -EINVAL; status_page = alloc_page(GFP_KERNEL_ACCOUNT); @@ -2000,6 +2030,15 @@ 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(&error); + if (ret) { + argp->error = SEV_RET_INVALID_PLATFORM_STATE; + 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). @@ -2028,6 +2067,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; } @@ -2036,21 +2078,36 @@ 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(&error); + if (ret) { + argp->error = SEV_RET_INVALID_PLATFORM_STATE; + 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) @@ -2059,17 +2116,32 @@ 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(&error); + if (ret) { + argp->error = SEV_RET_INVALID_PLATFORM_STATE; + 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) @@ -2088,8 +2160,21 @@ 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(&error); + if (ret) { + argp->error = SEV_RET_INVALID_PLATFORM_STATE; + 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 Tue Feb 25 21:00: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: 868238 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2088.outbound.protection.outlook.com [40.107.102.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 914E820FA9A; Tue, 25 Feb 2025 21:01:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740517264; cv=fail; b=lZ4niW1ote4jjHauvJLNmx/iYeC1KPbmNQy14TqF8JQmaKWReLvXwfOC9OJKR+6Drl4f7dI5ntRyGPPiaTFUIs5uHzqHQiVYUrMivnJIWpt2KJBZV3977iDrovRxk7LsucXVmh5GCqJNfl0zKFPPXGTWprvhig/Zxg7kwFFDRzA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740517264; c=relaxed/simple; bh=GDcns6ImL1n54rhNMMUmFOcZEjdqnAV3IeIcu+bWrDA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AKd5a8FdqV13XCnvbAgeW4UdvAdbf4lyBBH7kBdDfAM9eWCtJYMlQ+00ch1CneFRI62miKL9ZLbBvkDBWN8noF/e1t/+9Qc/V/SNUpHFyj4q3A1IuCZ3pN6MTxfDZtReoI0MoFqC/jTcTm/tlxbee7WSlQqgYVhUOjgq8LXq1VM= 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=NWNvDGuB; arc=fail smtp.client-ip=40.107.102.88 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="NWNvDGuB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Bi800vAiyt5OeZryBWOYDcHA5ix2eJb84F3dFJm2etfFxdWl1qxFJNHiUyJTpUfxIO6awndeOi/1zWxCwGR3meHz3OdyAEepvlUUzWzwQskUmeTm0Sketxe0zMZ6EU8iHFiou5I5/bb0MtLuRa/bZb4DGyVuqrTUkXJq6zEjcYlEDAKZhspoyGVFszcNO065YQ1wOLiEiBd5CZP9au6v07GRRUFZytJmLLkgB7K8siiVIkd/XkfOG94Y4GIksKRInQ85Hq8tI/U0ncj6lRbeldhrIkpTPDHVe0UY6MW8Kf+Ad33Hpr8J7DA2MvJYhcT02EHblB0Hs2BE/fwFqqZ1Xg== 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=mToQB7N40CXBzM0v7vvsPNe3+CmyYg6yXdtPOCLDuCk=; b=FSm7dwRFdyjTlc4OTH0HNwiLiWBDjLrdmjWi3NMcNyTRjw1rm80wzSW0g2GfABob6uR8ZebEKLbncMvt8L0nI6fZNlzkXPKpcEPbFNXKjy4IYiyp6wIDE5YJekSxpCfdQZq96TWcG8SEZ2VipahzfBF0CNh3Jt+RrOy6JI4RsvXqRnuCbCGlPrpoSwq0aK79cXBplNUEh2KpU5uZO01ACB2D0bN8WqOxjsr66ecBsp+dUVXy6QKGKDA1dUeYKbyqUAnetkHBFRdAqtlIUL4IeGVYK0+pzuO5ExT0zNYBL+Bsdvm5fJPhQbagO14Wxx/0iW64GANE3FOwaw8RYF+S7g== 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=mToQB7N40CXBzM0v7vvsPNe3+CmyYg6yXdtPOCLDuCk=; b=NWNvDGuBg9r/DdkK3UzcGDvsZw4TBWWqQnfsCsvbr0RJSKgqJs+dbiyx5r4WJImJk7h4Ua8wNELBulpf2rkStQMFpSx68CVd859ob6F//vEOiwe1E4Qgau4LO1kru3fj8Uw5l93kty/kFp9t+hjgScYRrdhmBnDmPvWCaRrtweA= Received: from BY3PR05CA0015.namprd05.prod.outlook.com (2603:10b6:a03:254::20) by MN2PR12MB4271.namprd12.prod.outlook.com (2603:10b6:208:1d7::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8466.21; Tue, 25 Feb 2025 21:00:58 +0000 Received: from CO1PEPF000042AB.namprd03.prod.outlook.com (2603:10b6:a03:254:cafe::e1) by BY3PR05CA0015.outlook.office365.com (2603:10b6:a03:254::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8489.16 via Frontend Transport; Tue, 25 Feb 2025 21:00: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 CO1PEPF000042AB.mail.protection.outlook.com (10.167.243.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8489.16 via Frontend Transport; Tue, 25 Feb 2025 21:00: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; Tue, 25 Feb 2025 15:00:56 -0600 From: Ashish Kalra To: , , , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v5 4/7] crypto: ccp: Register SNP panic notifier only if SNP is enabled Date: Tue, 25 Feb 2025 21:00:47 +0000 Message-ID: <29e8c21eae96b2cbe0614d04cfa1014b424134b1.1740512583.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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042AB:EE_|MN2PR12MB4271:EE_ X-MS-Office365-Filtering-Correlation-Id: b14eb413-21bf-49aa-7ad2-08dd55df8073 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|7416014|376014|82310400026|1800799024|36860700013|921020; X-Microsoft-Antispam-Message-Info: BzS35aADPdPVlYI31yQMscCONgkE3meNJfmx9PuEBvptSbEvhCvoU+sZpXwTyeViUOuKwMU0X88Ub1/ugAbQjbVdPG3WT7N2rZY6nCDd5VeXtMid2dU435E5wwy87/TLTNVG0ArpkHKvvPrqinsGf12c3atL1TCClSXpUGvJkEhS9gXWmYho3xOZUSq1HAVR15zS9RBs08bCQGGLou4M614kyHZFXhzYfyVy1OzpLQageFB34FzeXSIF/49zxm3fobpgECKLGWEEKrm8m3frO+tCPygkU6R9ROkdnII1xtr2NKwe7sOTbLj1LiwIfj+LcBHxX88gKCotzlCaFTrTbgJgUyIX7NvwcTvEbs/4e8indsfWPLmGZhAGis/SkpzQhLKv//OgHd0Hybtmein56XDgdxBShrxtFzBD7gviOMknbyZpwtPnEaj/2obVVn/sUq6zTIoucD6PFFfH7d05mV+yc1QC4b93RoV6r7COW2Ed90fCA9V71qGLYQdk12TylEMdjAnU63txg9LF++8u8CH1kbl81LR324s0t2um7gEwnPudPW6aBwUbQGcbVj9wwXFYm20Bw9xzhoYL3NMRKCLx3XG4rn/tZnLTf+g1qxk0dpjCf94Z9+KZMLkTVWFHPmSbSCm7nnftNgSDAizqCX59EOMtgXHRwMKTE/A3172kHFuwHJPJ1X1AkMD3OtPowoKYUqKvaA1H2BAoEEYs+sKGfSlqGURrGF7xUl1OubHYnPpdmhELCo6gU05A0iCsrVWf5N4m8jvhO8BWcQfXtTaZd5xgvDBx2jhTwSRwDPwzPd7QtU/sWCIjfSpJWenYPv9P2Ex7MOYQHvQ0iNdYRdWRGdX3uHMFW/Wf9QQ7+baMTg/KWOw4btO3YgHJarHW9wLQmAJ83OHPv5JJEro24XawjroKyZCacOJceN+IKc98d5Tqpot/VdU2vn9LikiyOKM2qQi9mvvFgj6e68Qi1kvAUv1dxKrymt+xYM6v5BdZcq/GYCFmSZgsuOK9BQHdiHTqoRTV29Kl/tM22dhXbQvYxkHzePhOrDzqlVAmGj61eWKkCQCPqbKRLJajvLewvVS4myjJTXGFXzwi3lJ/+xk/QRuencDSglkyLgNhclNgFwAhQri9ptyCS0IBkYUy9nMQvYAV30vDvccFZRRDEgNLPZR1jErENRXnv2PhVKINPTi7L2b2ctBt98djqgbqitApEwbdJxCz07F0InrHXXIhQkNehqP3d3rUdNvlcc5MeASmHtw92Fr77JxBTFulVtuQZJbLrw4PQq8pCBuye0ozNKLWbya62uv7goXHXF+qIwCgD2LRhqye8RNCmDAfG+TtiG6TEJ5mzcnYXBm/PV7liHn7KkPuirY81pXj+WHoa0oKMq2Rsgpeqo5d1+ihuVMO66DyBJqnL63PSYT90jwoxCvgFxEABw+UlC6hLPs0xmOLj/XZlNUV/voWAnTgHcjZSmY1pYXRk3orl+SnjDxV8YlQWHPHElU76yEFVUs6vbxLdshehgOJcIfTrtFA 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)(1800799024)(36860700013)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2025 21:00:57.6191 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b14eb413-21bf-49aa-7ad2-08dd55df8073 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: CO1PEPF000042AB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4271 From: Ashish Kalra Currently, the SNP panic notifier is registered on module initialization regardless of whether SNP is being enabled or initialized. Instead, register the SNP panic notifier only when SNP is actually initialized and unregister the notifier when SNP is shutdown. 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 c784de6c77c3..b3479a2896d0 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; @@ -1198,6 +1205,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; @@ -1754,6 +1764,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; @@ -2481,10 +2494,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) { @@ -2533,8 +2542,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: @@ -2551,7 +2558,4 @@ void sev_pci_exit(void) return; sev_firmware_shutdown(sev); - - atomic_notifier_chain_unregister(&panic_notifier_list, - &snp_panic_notifier); } From patchwork Tue Feb 25 21:01:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 868237 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2072.outbound.protection.outlook.com [40.107.94.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 CC2DD212B32; Tue, 25 Feb 2025 21:01:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740517309; cv=fail; b=OZAC5VbVWN36gvTWr6YrIufn+FvQfrFJk+AIfZpuivFe7BxMBG23ofZYhT7wcXd21VRpMQVLk2R8Y7M2O9pzZiZrLxaCx5+IDf8t5VgmwcL+U/PL99M4oop46YLaS6eIezIJoALuAfbD30xlxafoJij0WldbKuS84mIWRcDNAy8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740517309; c=relaxed/simple; bh=5M8q7AlUVMOVcRmAPQbHPU6y74MAsDMBSHiVAW1QVXQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Aptq3JzXZ5/odAcLeJeS5hQmZ59Imh9V1x7EZ7WFb0v7/bRhQV7Q277icM4ywlw9Fdr33KRlPj3s20zOTamPePU0An8goRdI8g3MCW8CBnN8Vtkf0rILdEm4NnYWJDUSFCexV4EWjOtkp3YcpUvCaTuvUxkq0XtFoPHWo9DDjbg= 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=F667efCY; arc=fail smtp.client-ip=40.107.94.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="F667efCY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fcn4MqTSTUeDRf3N880l5h2clC8alLIzaULcN7Ucclvp7FWBT3iZ8DzVC1RcKATdr2OUj8jm680Y3U7g1a26urAw3YJIw/0T/IhW85KtSnnnf8G4h/zw1BCIPyoZO0rnlpubrDns6x+4DW4b9/BiGmt+O5qrWXo4iu7dadLICGZSWuOk5AADZz83pD8/8D30ejg7pa35z7xBC+4f03GZ4ZG77mHpVX/2GKKqp7CMJ10/0Z7sBu7hI/UAjMU2A80tV6WzjrS6JTYecc6SGOQRTfWgBYJvdbvIjFPvurKNOVcjjU+thbH8MZq6W91UvnwsWophdHq1tns/j9tFiyocJw== 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=T/jGJRlHghRALuWwtHv4TbPUQayeCZ2sJZ5IAeU+xr0=; b=DT8lQD8fDPG+WAOTclfNE2NU/zY2HbL/z9bReRDBk7KGfvV7hNCohJOMU93TQ7hrBrKcGMGnhV8e39kQRJzSBZxtH4ogQzK1MQfferWBRc3b/1dQFwvdyMnpNCWuGwBUZaCv3mq8tzoR3nMBjfcCwiwdz0TYLMy4jQwRBIWN3wqmqdaVA4pAo91lMzQTYz1BYKi5V4Qmp9FXNr5Xg+ZqH17N1HWX9THPsJ7AOTKnB4Eu5uZ04+olp02kQAUfc/l4FmcN87zPgXDBREPZxXtPM+MlCXGTAN7/B7rBKq2KzOY4CiVBZUQWC4PIn0ATHtL2H9WLZw3bqnjMspcLwvB5/Q== 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=T/jGJRlHghRALuWwtHv4TbPUQayeCZ2sJZ5IAeU+xr0=; b=F667efCY/9v/cI8rkPOLZ8f8niubaNoohr3hJrVoGbT1rGDzPBKWazYY2IMrUPf9L/FufVEsqhlU3PIq0o379FhH8F9oXTxTCJcxlaYavby6RnR2Gzdq20hOzBHrM6j9LgXmLbxFsZnjtRVg5m0FwhZ3c31Dt5uACAS7QEUWzWE= Received: from BN9P223CA0024.NAMP223.PROD.OUTLOOK.COM (2603:10b6:408:10b::29) by PH7PR12MB9174.namprd12.prod.outlook.com (2603:10b6:510:2ed::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.18; Tue, 25 Feb 2025 21:01:45 +0000 Received: from BN1PEPF00006000.namprd05.prod.outlook.com (2603:10b6:408:10b:cafe::f) by BN9P223CA0024.outlook.office365.com (2603:10b6:408:10b::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8466.20 via Frontend Transport; Tue, 25 Feb 2025 21:01:44 +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 BN1PEPF00006000.mail.protection.outlook.com (10.167.243.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8489.16 via Frontend Transport; Tue, 25 Feb 2025 21:01:44 +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; Tue, 25 Feb 2025 15:01:43 -0600 From: Ashish Kalra To: , , , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v5 6/7] KVM: SVM: Add support to initialize SEV/SNP functionality in KVM Date: Tue, 25 Feb 2025 21:01:33 +0000 Message-ID: <27a491ee16015824b416e72921b02a02c27433f7.1740512583.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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00006000:EE_|PH7PR12MB9174:EE_ X-MS-Office365-Filtering-Correlation-Id: f5db8c53-8b95-4aaa-e8d5-08dd55df9c7d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|376014|7416014|1800799024|36860700013|921020|7053199007; X-Microsoft-Antispam-Message-Info: X+4/Prkj9ffO6wsA8NFKBFmrn1MVkvud22dOv/0i1cu1sZSw4v2/Pd3z/hIjmM83LrobRI+47mjvkHJWRjqMC4PCYuZsMfMkB0vnCaWGLOqPPthgVxAAgFmpB6/cEY71OEMWpn0w9viQhV1edhpXhAE3A31vZlyPSytOYZdSFvSSNw7TcnEg9yNI1ihkrrD3cmXeh+FsE6CvysyOl1opx4fz9oYuiUpwEmKVGsmB21/YUO74FgiP9lNKhQmJGODa9nxlqLLVbta+CUHaNnSvO0TieMsXfmdGmyYEs5uZchRM81H7HJEprzRzJhqdep50oajTM95FeVYTSLrPBpvMGOpV0vL8WXYfnF3No6HDRw58jvOFW7OjkdhTPW7bvNKe+GprHb9+Gr/gtDaE4z05fatPMv+YE9xE3NPZ9kPVmGT5JceqqdY6AO3x72hE+msoeAqJ/yE//tqvo5b7iYeiEEJ8IODfrNZL2NIPKLqAfLZi1O7LlnwTL6DuAxToVIP6Xqtxz9otEuqIYuFfeEFKYRZ3fcWa8fbVUyLMbKtou2X/J8cu3TwOTse79JsrxdEXZyEZgZM9EEkPqw3Aed3DvtP8ndU8d3c4Zc6V8EJiCJtjTkt8UaaZQK50pKX9RfdrAkUSalybQHqcm9QDPSxxDLx7hnucjfvyF+2sGM2F/KNckU5XLVCiQnD3OZ6wJrfdhmb8qSI/hP4L745OS5vsuhTZn/pdN87YZE6O2Ue/8Orirpv8yeEvNLlgFvu6m6ReWlgGNghTS1Enqf5Q/EkF+iPtyxtPx9Irw04qqPJtpaQckgLYVpa7Xk4A2Qod1LRCp5X/jWzIMn0cIaamZwj1D9Bi/MPTCC9XdeQVKigJZL8M+BbzXc8CrUObYEIGzLMWugrBdq0KqrG4ca36jbwvpOPQt7qCyt7mV6Rs0UgLw+DJIWQ7ZLAVAJGFXyuv1fn7s8IS2D3GMgDFbjGMZ4yHuBKToTfGXd+5Ca0MWx1SGM579QQ6l61fnIF6e27vHn80wgsRKRz3UQY3KrQNRPU3ntLpbwXgPhWMGk2d8WZjNM35tsrJDPkXc9mEjSKoild7sU5/E07XDRdD5HbTVhpjvUt+LQeubBW4xE8jXJo/UQWvo4AC9wUmJ7oMiwoYeMLb7dTUZP0qFWD/H7Dr9F8FxnW8kwyPa66XbxhcZigzN/jQOBkIj0fLk4+GuaOpPXUhJpe1PNeob6JYWL3iHcXZ5mqKtSTHer5UcOS4YdcDeK/TWJMawEUJCYXt4ifiM0QzHzFHInu/ySaNgOpE8avuJ1FiIX9crOjC+48A0s2kXM3KjDw0JFbVhfe2UKv/XzSbOaFmXqRcPcPlQa8/5aaxIWV7BB7FrDRvEwNDpp58BKS3SVJ5gfKhoAlk+OISsTwyT6DClESiepVzV4EZuqkWniYv6jZuXhrGOozNgnNWIIEHQHUQt8Hg4ChDmm+MeoZQ0/X1BaPwxWwDWScDF0nzcxsFrcxa6cmwIsYNLEH5g0c91UPReyBony5L2U7yobJc 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)(1800799024)(36860700013)(921020)(7053199007); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2025 21:01:44.7418 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f5db8c53-8b95-4aaa-e8d5-08dd55df9c7d 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: BN1PEPF00006000.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9174 From: Ashish Kalra Move platform initialization of SEV/SNP from CCP 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 CCP driver at load time to initialize SEV/SNP. If required, this behavior can be altered with KVM module parameters to not do SEV/SNP platform initialization at module load time. Additionally, a corresponding SEV/SNP platform shutdown is invoked during KVM module unload time. Suggested-by: Sean Christopherson Reviewed-by: Tom Lendacky Signed-off-by: Ashish Kalra --- 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..0bc6c0486071 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; + + /* + * Always perform SEV initialization at setup time to avoid + * complications when performing SEV initialization later + * (such as suspending active guests, etc.). + */ + 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)