From nobody Wed Oct 8 07:30:22 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2066.outbound.protection.outlook.com [40.107.220.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 A0215265296; Tue, 1 Jul 2025 20:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751400941; cv=fail; b=MMp4R2mAXKJe2JeIXHmawb1vAV5BdWxKzIAeB/13IyaBZ2KQ0WFEzvuh8qHfC5g7nNDkdmpPnorbf8OhWCWgUK/qK9noNLo0xNcfvv8XxY7zoUhQFlS4DHF4jou1aKIXkUGKyaU4ZrG2WNJ+WqwALs6SuDUKMlLU1Dy2lut5jBU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751400941; c=relaxed/simple; bh=pzDi2ixdXHvMOQ75IAaxTvZ8Oif5Tj+v9heTVJOt9UQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fN1YjbLBBCSlYY98SRxXDARModInHFPRXy3jDzCmHT91cswVNvs8Mfhzjn1sCK7CGa9/jguKMJuoptRJZhbnbS2xcIg01m5YVPhJ/6+QB0FHxtjUWfW68rxCRdmIWptD663Lj4q8YncP1aMiESxMEdztyfZvW6oAZmDNS3zROJ4= 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=ptgrBGN9; arc=fail smtp.client-ip=40.107.220.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="ptgrBGN9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=V8Fnyx6ij2CZTag26fJW0QkgwXJxpDvIuT1GI/cssqQE2PKHDcaiE/cLx06vqhEnQ0arx9nxKBfUuP9NeC9fYItDlhazAzyF0Hb4CTgUZQO92CSjEL4gqNl75TjovcO5+8Bw1jn+TQknemkjIv/H8B2z+9M7MkufZ+KUC6JmiP72JvzJJVLd69fBLfA5n5MiGhwjQjCs9JDIFjkha+O9cq0d+CAzqIWJndxZSBhoZqTB0TN2u25Qqm1RiGdnHfggVInNNfEevMHMqo40KIas/wq0dOzdHYGQV3XipJb9uPYJRixlCz+TOJuSVGpPUUe9vK/GpNux3FVri/oaf56QUA== 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=0oWqI/fausB4ZH8cWR/XakSkviVBgx/hBGvQgPL7DN0=; b=Pb/Rxfn0QSlqHZe1OSj6V9IJN8eCzKJI1WO8vhQQYxzT8OaM3E5E8QnwPB1g0nKPvUhiz2XdFnHeb5LpyF0Mv0GFTChbWJBMIv+8HTsn+Kb14l7DsTsm+ppsFr9vtRRYL70srFd1WYvEKPAdNpWsdS6tsdM2lh+LCQEAXTXPmb4TjrYl6QItXGLCaS2Wkpu1DRY/lp1wPLpiNt9kaGm0lv3juxUvpDRNoKSTDyvYkH0nDjEtxVW56rAgLwOya4ib0TZ5kuwbHdPmQShZPhkbVPqPtOaGVKScW8KtBlJyFIHTiIlLov7RdWIZXPoG+m7chfUObKCO0i2rDl7HnIfr8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=0oWqI/fausB4ZH8cWR/XakSkviVBgx/hBGvQgPL7DN0=; b=ptgrBGN9YQ4Kj1pG2d9BsV5xAsz0EtPK343lK2U35JlBlfKQMuQiB+5HoMNwd356q5Ocpx2SrXE81GSLYj8GgAksUSl6837KQlf2WQTZjd3p4yCip6zEbzhQwUYn4E/sjkRlq06NyDCLzmGjNf3c6TMaVK6BK+Njg3EyRPWx/IQ= Received: from CH5P221CA0006.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:1f2::19) by SA1PR12MB8096.namprd12.prod.outlook.com (2603:10b6:806:326::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.19; Tue, 1 Jul 2025 20:15:35 +0000 Received: from DS2PEPF00003439.namprd02.prod.outlook.com (2603:10b6:610:1f2:cafe::b5) by CH5P221CA0006.outlook.office365.com (2603:10b6:610:1f2::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8901.19 via Frontend Transport; Tue, 1 Jul 2025 20:15:35 +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 DS2PEPF00003439.mail.protection.outlook.com (10.167.18.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8901.15 via Frontend Transport; Tue, 1 Jul 2025 20:15:34 +0000 Received: from purico-ed09host.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, 1 Jul 2025 15:15:30 -0500 From: Ashish Kalra To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Subject: [PATCH v5 3/7] crypto: ccp - Add support for SNP_FEATURE_INFO command Date: Tue, 1 Jul 2025 20:15:21 +0000 Message-ID: <5048d1bab32530214e7f3e4d73a4756cf374dee6.1751397223.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: DS2PEPF00003439:EE_|SA1PR12MB8096:EE_ X-MS-Office365-Filtering-Correlation-Id: da25ddac-c94b-4de4-a401-08ddb8dc097b 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: =?us-ascii?Q?BrLIZu/YwQYUgQ/3497C2jhB+w20DLyfXJcy2i+0l2zDLOMxWOnfi2wXJwuT?= =?us-ascii?Q?7aexeg3kCYEGluCGc3TPvwwD0HoAwm7D/bT1/aNpjGf/qezIpHWS2vPmp3RX?= =?us-ascii?Q?vdZZGyqkZ5UzQF0UrH+V4WYfkEeIDmpbL+kYUZlSKrk2AVyATAElhGO5C1fA?= =?us-ascii?Q?FhSNdo9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= =?us-ascii?Q?x+2vJuonkGMRTORuWu0al3LaJle9HhDccQvdo7KvAm2/a5Yl3VX9M4NhKrPD?= =?us-ascii?Q?ivdvIx6aud5iEYrCscqOWb0H/Ma+V/dz+2RaDTOjUc2MsGXlfGCo+RvMDR62?= =?us-ascii?Q?6Zz21I0GU9P/+mMJM8jE1XC8z9TM7uKw7A6XrkOuq0hBSrMPw+sdy8tuze+r?= =?us-ascii?Q?SmpwP395wmni95M0u9xVDD6CHuCr6N+VbNvq3DqYovNr61oEE2LDw8cPixRp?= =?us-ascii?Q?hEqIUyhnEfGCwbz+BlXQu4g5PC80BuFMZwJdO7v3ireEk+Q4MX+CdwL7Hju3?= =?us-ascii?Q?L/CsFDdC8z7TIeuW6eOShTM0XRrO8sdTwEN/fDw7fV/wKu4Do/afyaxIVPc+?= =?us-ascii?Q?XuYJLGo1MihJFhh6KWzXuNCkLqH3QbGpd4+88w28cPf4t8awtNT+wemZ9Rxx?= =?us-ascii?Q?3c7mo7YYaX9j+b7py4A4CbmovJI19aCuGc0+KPy7poBuETG2Le1sV/eIOQ?= =?us-ascii?Q?=3D=3D?= 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: 01 Jul 2025 20:15:34.7130 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da25ddac-c94b-4de4-a401-08ddb8dc097b 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: DS2PEPF00003439.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8096 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra The FEATURE_INFO command provides hypervisors a programmatic means to learn about the supported features of the currently loaded firmware. FEATURE_INFO command leverages the same mechanism as the CPUID instruction. Instead of using the CPUID instruction to retrieve Fn8000_0024, software can use FEATURE_INFO. Switch to using SNP platform status instead of SEV platform status if SNP is enabled and cache SNP platform status and feature information from CPUID 0x7fff_0024, sub-function 0, in the sev_device structure. Suggested-by: Tom Lendacky Signed-off-by: Ashish Kalra --- drivers/crypto/ccp/sev-dev.c | 72 ++++++++++++++++++++++++++++++++++++ drivers/crypto/ccp/sev-dev.h | 3 ++ include/linux/psp-sev.h | 29 +++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 5a2e1651d171..d1517a91a27d 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -233,6 +233,7 @@ static int sev_cmd_buffer_len(int cmd) case SEV_CMD_SNP_GUEST_REQUEST: return sizeof(struct sev_data_snp_guest_= request); case SEV_CMD_SNP_CONFIG: return sizeof(struct sev_user_data_snp_config); case SEV_CMD_SNP_COMMIT: return sizeof(struct sev_data_snp_commit); + case SEV_CMD_SNP_FEATURE_INFO: return sizeof(struct sev_data_snp_feature= _info); default: return 0; } =20 @@ -1073,6 +1074,67 @@ static void snp_set_hsave_pa(void *arg) wrmsrq(MSR_VM_HSAVE_PA, 0); } =20 +static int snp_get_platform_data(struct sev_device *sev, int *error) +{ + struct sev_data_snp_feature_info snp_feat_info; + struct snp_feature_info *feat_info; + struct sev_data_snp_addr buf; + struct page *page; + int rc; + + /* + * This function is expected to be called before SNP is not + * initialized. + */ + if (sev->snp_initialized) + return -EINVAL; + + buf.address =3D __psp_pa(&sev->snp_plat_status); + rc =3D sev_do_cmd(SEV_CMD_SNP_PLATFORM_STATUS, &buf, error); + if (rc) { + dev_err(sev->dev, "SNP PLATFORM_STATUS command failed, ret =3D %d, error= =3D %#x\n", + rc, *error); + return rc; + } + + sev->api_major =3D sev->snp_plat_status.api_major; + sev->api_minor =3D sev->snp_plat_status.api_minor; + sev->build =3D sev->snp_plat_status.build_id; + + /* + * Do feature discovery of the currently loaded firmware, + * and cache feature information from CPUID 0x8000_0024, + * sub-function 0. + */ + if (!sev->snp_plat_status.feature_info) + return 0; + + /* + * Use dynamically allocated structure for the SNP_FEATURE_INFO + * command to ensure structure is 8-byte aligned, and does not + * cross a page boundary. + */ + page =3D alloc_page(GFP_KERNEL); + if (!page) + return -ENOMEM; + + feat_info =3D page_address(page); + snp_feat_info.length =3D sizeof(snp_feat_info); + snp_feat_info.ecx_in =3D 0; + snp_feat_info.feature_info_paddr =3D __psp_pa(feat_info); + + rc =3D sev_do_cmd(SEV_CMD_SNP_FEATURE_INFO, &snp_feat_info, error); + if (!rc) + sev->snp_feat_info_0 =3D *feat_info; + else + dev_err(sev->dev, "SNP FEATURE_INFO command failed, ret =3D %d, error = =3D %#x\n", + rc, *error); + + __free_page(page); + + return rc; +} + static int snp_filter_reserved_mem_regions(struct resource *rs, void *arg) { struct sev_data_range_list *range_list =3D arg; @@ -1599,6 +1661,16 @@ static int sev_get_api_version(void) struct sev_user_data_status status; int error =3D 0, ret; =20 + /* + * Cache SNP platform status and SNP feature information + * if SNP is available. + */ + if (cc_platform_has(CC_ATTR_HOST_SEV_SNP)) { + ret =3D snp_get_platform_data(sev, &error); + if (ret) + return 1; + } + ret =3D sev_platform_status(&status, &error); if (ret) { dev_err(sev->dev, diff --git a/drivers/crypto/ccp/sev-dev.h b/drivers/crypto/ccp/sev-dev.h index 24dd8ff8afaa..5aed2595c9ae 100644 --- a/drivers/crypto/ccp/sev-dev.h +++ b/drivers/crypto/ccp/sev-dev.h @@ -58,6 +58,9 @@ struct sev_device { bool snp_initialized; =20 struct sev_user_data_status sev_plat_status; + + struct sev_user_data_snp_status snp_plat_status; + struct snp_feature_info snp_feat_info_0; }; =20 int sev_dev_init(struct psp_device *psp); diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index 0f5f94137f6d..935547c26985 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -107,6 +107,7 @@ enum sev_cmd { SEV_CMD_SNP_DOWNLOAD_FIRMWARE_EX =3D 0x0CA, SEV_CMD_SNP_COMMIT =3D 0x0CB, SEV_CMD_SNP_VLEK_LOAD =3D 0x0CD, + SEV_CMD_SNP_FEATURE_INFO =3D 0x0CE, =20 SEV_CMD_MAX, }; @@ -814,6 +815,34 @@ struct sev_data_snp_commit { u32 len; } __packed; =20 +/** + * struct sev_data_snp_feature_info - SEV_SNP_FEATURE_INFO structure + * + * @length: len of the command buffer read by the PSP + * @ecx_in: subfunction index + * @feature_info_paddr : SPA of the FEATURE_INFO structure + */ +struct sev_data_snp_feature_info { + u32 length; + u32 ecx_in; + u64 feature_info_paddr; +} __packed; + +/** + * struct feature_info - FEATURE_INFO structure + * + * @eax: output of SNP_FEATURE_INFO command + * @ebx: output of SNP_FEATURE_INFO command + * @ecx: output of SNP_FEATURE_INFO command + * #edx: output of SNP_FEATURE_INFO command + */ +struct snp_feature_info { + u32 eax; + u32 ebx; + u32 ecx; + u32 edx; +} __packed; + #ifdef CONFIG_CRYPTO_DEV_SP_PSP =20 /** --=20 2.34.1