From nobody Fri Nov 29 18:40:59 2024 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2052.outbound.protection.outlook.com [40.107.94.52]) (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 7944214A4D6; Tue, 17 Sep 2024 20:16:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726604203; cv=fail; b=h3IyHwNLRQXZOfoT6XkdydIw3yRxCmwqRVPx0IBZVbbLSjBEuKgKr3SKTmAWwUeNDuGvvywLRsxtRuKdNRjrXFpSV2cuJA4qdHHM4Mm/XVY+m7rs9wuMQNHzyJalRRMF7bHpIaGwVbEWZFIYI3CaFQvHQDFVBLT9qh9UN58YQaU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726604203; c=relaxed/simple; bh=x+x3I4U5DGo/49XGe8AnE6PNbB4UDkeGFIU5/UfY8Fg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=un7IeUS/2DLj7mY/bQJkXKCK4Q84VF18Lj09pKMOdzQwUadSUaxhqe6cREuFoUdnUttZXN2kkPzloMiRzA7LzeC96NH7XyyPW37czb9UbbMZXlxgSfeg5Z4oiNXen0UEqM35j3LWGm0U4RqUYvBWhM9J7CHnicKBeBD8Mzi6sgw= 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=TH73XsqZ; arc=fail smtp.client-ip=40.107.94.52 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="TH73XsqZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yv+yPs9z+AIwoRxA2TFdX9BpKT+p/EX43DdLs27a8hW8iREtT6TFuiHW7WAM1VRWvoQX4/PwWX6dtNTLq+8Lgei7X77HGKAB+7pHzqbLkV9t8mrf2r9NkS07xNBe/sA1A01IRASawkvGkpbQKTEOpZKO5RMSMGN2KROZzyUGcqg7DREPiJMqTuN/NahtHZtFVWFiwrfaMnumiozbjocd4EL9LqPBrn3dTclnc3WNwkkkI2T413+P09Y/vu0ZWP8zzVPcUoZrFqRd85CJT0C5TaPQ1udbVlPPvyD5JJI4xjuAuFr8+lp75UiE9Kd8JcheZKn0KjWbzfN9RCjKAb7gKA== 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=SeX+2fdrpjOugp/vIMl68H+LI7jCjigkld9Vmo2D9WQ=; b=vBBvOJcNKcp4bW0VW8p3rU9e0GUFxnLI1FjCFdmE7g4SEPe8jhEWhrlZLJ2fE5e7u+jMCEouuYWzLNA65H3L2RJJq7207qCwXEz+IOJumJ4pOOqvAxA305Zz6gnjeGpBaELYr7//+ik220KbDKhzTkKWuwIPjvcCgL/mZitUhrdvVevGlSz2H83Tilu2LYliksv3YmmYWLyWg5IDf8k4AisJbHV6sVZOSfjh0rA2/U/a+HS3OC48tKWr/yE1nFiN3nPmY9qJSByKkSFxQpS/p7Vt0IFtWAcfr2UGpz5IuFRfJ8VOeb1MJ9zJhijE2FRYwXCoMzpzhXatkfunmT61+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=SeX+2fdrpjOugp/vIMl68H+LI7jCjigkld9Vmo2D9WQ=; b=TH73XsqZwwObeUtXJDCVK9q9az8qUaHAVT2owICEXZeGWTkW9Y4PKu6TYlakyHKOqc3cugaRybhq+T8kSzxLudVaAGL48zGeUT5JSYESq6IOe995SE1JHl7tW/Hqu0SkpV8EKitfuqzBN4gtTMgxXFyHya1jhiiG0cyxd77NVDo= Received: from SJ0PR13CA0126.namprd13.prod.outlook.com (2603:10b6:a03:2c6::11) by CY5PR12MB6408.namprd12.prod.outlook.com (2603:10b6:930:3b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.24; Tue, 17 Sep 2024 20:16:37 +0000 Received: from SJ5PEPF00000205.namprd05.prod.outlook.com (2603:10b6:a03:2c6:cafe::f8) by SJ0PR13CA0126.outlook.office365.com (2603:10b6:a03:2c6::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Tue, 17 Sep 2024 20:16:37 +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 SJ5PEPF00000205.mail.protection.outlook.com (10.167.244.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Tue, 17 Sep 2024 20:16:37 +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, 17 Sep 2024 15:16:34 -0500 From: Ashish Kalra To: , , , , , , , CC: , , , , , , , Subject: [PATCH v2 2/3] crypto: ccp: Add support for SNP_FEATURE_INFO command Date: Tue, 17 Sep 2024 20:16:25 +0000 Message-ID: <0f225b9d547694cc473ec14d90d1a821845534c3.1726602374.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: SJ5PEPF00000205:EE_|CY5PR12MB6408:EE_ X-MS-Office365-Filtering-Correlation-Id: 78f72041-6395-4d08-86c0-08dcd755a22a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|82310400026|376014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?FOz4JVAakgK9lVevjQFnNyLNmN+WB8zY6aw5cJL7UoED7B+qJ4xg8JF+UQJP?= =?us-ascii?Q?LwUwCw9mFCbBo7rjTBnn+kM1U/7NWMlPp/hGryQ55pQeqs53oASHgvvBdpKT?= =?us-ascii?Q?2MMIBb+44z9OvgTYUP25xRcRq+hypTEWXieQMQ7RUIra3B/macofdmt65pOF?= =?us-ascii?Q?2PtQyG39eCTna2FYKs0Z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?Q?283o2wCV5I8NrkGHS7KuFk/zfzl+MHFR7kqgEUu3jZqjKDgkUNr4DuJDNgDL?= =?us-ascii?Q?smjCbpcx+ouTuUYOm7eSZWwqtSAhLMU/GNgHe2w98gq/WXLFyq1efvs6Oqt1?= =?us-ascii?Q?OvhbFM+wdaum4ejImlNCjD50hBfLPOLtztqSo4a3NWAPH51Diti2ttvLZxgb?= =?us-ascii?Q?KfxlZ8ZgA0gy9+3uu+5YcObUTCACjylvg7fe0rvvd7nwrbCJ6aLIoEaP7z93?= =?us-ascii?Q?pd7AVkzLpwYFuRjcOF1rBuurjVhHvC3jNG+MN4ohSAd/nRoyNaJfg8WFPeKf?= =?us-ascii?Q?UvuCPjTCofYPclFmKn9qBItbZs/8WwJNpJ4KPIcmJYCICtCBvh/7X6xkR3MY?= =?us-ascii?Q?HTwybXQ9SM3R4isEFQovtQjW3OGdlFXn?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(82310400026)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2024 20:16:37.0624 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 78f72041-6395-4d08-86c0-08dcd755a22a 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: SJ5PEPF00000205.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6408 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra The FEATURE_INFO command provides host and guests 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. Host/Hypervisor would use the FEATURE_INFO command, while guests would actually issue the CPUID instruction. The hypervisor can provide Fn8000_0024 values to the guest via the CPUID page in SNP_LAUNCH_UPDATE. As with all CPUID output recorded in that page, the hypervisor can filter Fn8000_0024. The firmware will examine Fn8000_0024 and apply its CPUID policy. During CCP module initialization, after firmware update, the SNP platform status and feature information from CPUID 0x8000_0024, sub-function 0, are cached in the sev_device structure. Signed-off-by: Ashish Kalra --- drivers/crypto/ccp/sev-dev.c | 47 ++++++++++++++++++++++++++++++++++++ drivers/crypto/ccp/sev-dev.h | 3 +++ include/linux/psp-sev.h | 29 ++++++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index af018afd9cd7..564daf748293 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -223,6 +223,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 snp_feature_info); default: return 0; } =20 @@ -1063,6 +1064,50 @@ static void snp_set_hsave_pa(void *arg) wrmsrl(MSR_VM_HSAVE_PA, 0); } =20 +static void snp_get_platform_data(void) +{ + struct sev_device *sev =3D psp_master->sev_data; + struct sev_data_snp_feature_info snp_feat_info; + struct snp_feature_info *feat_info; + struct sev_data_snp_addr buf; + int error =3D 0, rc; + + if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) + return; + + /* + * The output buffer must be firmware page if SEV-SNP is + * initialized. + */ + if (sev->snp_initialized) + return; + + buf.address =3D __psp_pa(&sev->snp_plat_status); + rc =3D __sev_do_cmd_locked(SEV_CMD_SNP_PLATFORM_STATUS, &buf, &error); + + /* + * Do feature discovery of the currently loaded firmware, + * and cache feature information from CPUID 0x8000_0024, + * sub-function 0. + */ + if (!rc && sev->snp_plat_status.feature_info) { + /* + * Use dynamically allocated structure for the SNP_FEATURE_INFO + * command to handle any alignment and page boundary check + * requirements. + */ + feat_info =3D kzalloc(sizeof(*feat_info), GFP_KERNEL); + 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_locked(SEV_CMD_SNP_FEATURE_INFO, &snp_feat_info, &er= ror); + if (!rc) + sev->feat_info =3D *feat_info; + kfree(feat_info); + } +} + static int snp_filter_reserved_mem_regions(struct resource *rs, void *arg) { struct sev_data_range_list *range_list =3D arg; @@ -2415,6 +2460,8 @@ void sev_pci_init(void) api_major, api_minor, build, sev->api_major, sev->api_minor, sev->build); =20 + snp_get_platform_data(); + /* Initialize the platform */ args.probe =3D true; rc =3D sev_platform_init(&args); diff --git a/drivers/crypto/ccp/sev-dev.h b/drivers/crypto/ccp/sev-dev.h index 3e4e5574e88a..1c1a51e52d2b 100644 --- a/drivers/crypto/ccp/sev-dev.h +++ b/drivers/crypto/ccp/sev-dev.h @@ -57,6 +57,9 @@ struct sev_device { bool cmd_buf_backup_active; =20 bool snp_initialized; + + struct sev_user_data_snp_status snp_plat_status; + struct snp_feature_info feat_info; }; =20 int sev_dev_init(struct psp_device *psp); diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index 903ddfea8585..6068a89839e1 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, }; @@ -812,6 +813,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