From nobody Tue Oct 7 03:46:27 2025 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2060.outbound.protection.outlook.com [40.107.236.60]) (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 EE74E54F81; Mon, 14 Jul 2025 22:39:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752532786; cv=fail; b=ZPp4VuM6GwPZ/mkPQIKWDHDt3Z5V3sf8bTSgAJCTHCZE+fvzAcnmdanJFSre2dmd4qynD3u0TLDDSRX+YcNPuQ5VHkKv+sij9lx3Zs08kIubEGgjGLOqI5xthDbY0FsHpnjQ6aoi7R8EFXlhFDwZLSvIipIgkEvt3rtEjGAIZ6E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752532786; c=relaxed/simple; bh=SB1wYF+yx0cHIZHraE2D44TLNggMmV9xD/BmgNIDs1s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LJSGMIWmo2MfUrVZTuzGlRqugvs+14AayHag5FpmChFmbs837JJ8ALoaghmL0q+w96c3PGfz/k8GAPl0zcOAkISo0ZLnJ8VQhvEnhT+H5JJawK333+H+ynRUEl86vL9p8yc8xDRNg91lebIwRzxD/Z5mUiUL+MY7UN9nfjqSlI4= 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=vanPR930; arc=fail smtp.client-ip=40.107.236.60 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="vanPR930" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uBU/N6Sn41J1gzrdgHaofdiUMwGNpDBLhwtBKUu2xPk/w72f0QuI561xWYr5+wXlgxoc2eX0CnLBGNbv5KnFlP1q4aSuSG15byldmTdyILgXNqccY5HzzWr1JBVVaWFcg3XbuqYlPMbwFMKH/1CFWpVuxmDf8Kg1R6lei1jU7rKzXo8cGs2ZwXTYHy5CPs4bVQOsWDCGV1jBe6uHil6bJPl9UmqNa/whYR+BCz35V1rWI+lUI2M/bWeE02J6pQX9XLzqcvS0kGIdKd6U8igxDgLKGbZfpuV+3Oo8hPwRIYWHK/Rk9xta7ztSl2YmkEK+dyl8FR0s4iFaUb6qgYoPIw== 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=xkKLJnlF/78OEYVfLA8TArPEL2ti8EssOb2Dwys1WIY=; b=pqJmK1AprkCskQR7IFE9O+OtX0yBDG5IOFONEt3MD9qrpb76Raer69AizFTaSCVCQHmJ/jiYWO9GWEn1LNQtEohkUhXstP9BpEbOJznCcx4ynTo8Uj1s7kq1SgGMllX0fIxjtJ3gDgTjiKituXk+xG96qt9qXfOoYBrg9RYGUhxqTb07OfrTJANcaSlBpstiOhXuUAmUfnsBR4SPCwM1MsiYk5psEYNqHOHaK3nlTG67jRH99dnz/KfBAG5ICjOlZNC6oNuv54UfM+MuHbSTlfzrp534h630RqrJt7RcX6BP9TVJ+KnqcoO/DjXB1oPVKwTEAB5tFNUNKTJ0iBg3+w== 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=xkKLJnlF/78OEYVfLA8TArPEL2ti8EssOb2Dwys1WIY=; b=vanPR930j6BTLxQ+mJtXXXimNyrj5HRmRo0bQpsSge1U9vp8CjY9ui8gnZXjGT3ymZYFEheaWbREPxEEHNI9rDKz8DroWxIwPLAXICDoi4PlzKfPzmTfyFMGB29LVHtuTKaVj63g+YUsvS2vTyoixagu0eLQcofOm3mMwkBQy1Y= Received: from SN7PR04CA0227.namprd04.prod.outlook.com (2603:10b6:806:127::22) by CY5PR12MB9053.namprd12.prod.outlook.com (2603:10b6:930:37::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.25; Mon, 14 Jul 2025 22:39:39 +0000 Received: from SN1PEPF0002BA50.namprd03.prod.outlook.com (2603:10b6:806:127:cafe::84) by SN7PR04CA0227.outlook.office365.com (2603:10b6:806:127::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.32 via Frontend Transport; Mon, 14 Jul 2025 22:39: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 SN1PEPF0002BA50.mail.protection.outlook.com (10.167.242.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Mon, 14 Jul 2025 22:39: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; Mon, 14 Jul 2025 17:39:35 -0500 From: Ashish Kalra To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Subject: [PATCH v6 1/7] crypto: ccp - New bit-field definitions for SNP_PLATFORM_STATUS command Date: Mon, 14 Jul 2025 22:39:25 +0000 Message-ID: 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: SN1PEPF0002BA50:EE_|CY5PR12MB9053:EE_ X-MS-Office365-Filtering-Correlation-Id: f1777250-b31f-4ad6-f917-08ddc327507e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|7416014|376014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?8iuc6IWDrIqbmVdsOXU2ZYEgMupUMzphSqfdSDnSULJYDoVofNH7gqHKgTUQ?= =?us-ascii?Q?cUHXRrTSB8GkQRRhfnqGOEnQA4U/OEsvBxXu5X07zj1KI5gd87F/TM5unAZr?= =?us-ascii?Q?e303npCzCI87unHgpy/ZmuZ6C83W0qAvlg/ASjNJ11xwNuYLDnSNvg5N7M/c?= =?us-ascii?Q?VLgS4yrxJKiltGcyXTYVFPGPLxB2dbvcgbGyq0dou8F0ikHDWNe10rUdLm7p?= =?us-ascii?Q?bX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60DJbMOAfKRNulO/Cw?= =?us-ascii?Q?SiiXGmljJNxIeJU0hAhb6yJjQmJWSiwlyUJIWr/RCtdKnwE3qoBIcrN+4oZn?= =?us-ascii?Q?PvyQG2+qpZNjTmHMnZ86o/R0u/L4jg1FStSPTJN2woAnkf2P/m1MVxWYWDoX?= =?us-ascii?Q?VJBVR//xRtoYZZIkACf0FZKFUFIOlwSwwMx+zupCTS8rMBeyCUaHhyfpKDFe?= =?us-ascii?Q?Wv21Xhoy2VOEyThBFj59NFtZd2linMg6Mktl0Mat9GzthzC+MuNaEPzeUDjO?= =?us-ascii?Q?7qUU33FdWxdfABB0Sz94HKy4LoLQjHrxAkFlqGQtvTTx+2L+XXtQA8BKAM/J?= =?us-ascii?Q?NF1S+9RcfsYJU6/OZ7OOkzEodcehA9OgThxOKzOPMKlGaGb1PUD1zxdqy/tN?= =?us-ascii?Q?G9oeGIHKhKYGKDnj7RR0Nzt1LjJvfpWSAxTZ35N4mzI6LMQsfaBtFVJUEw?= =?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)(82310400026)(36860700013)(1800799024)(7416014)(376014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2025 22:39:37.7466 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f1777250-b31f-4ad6-f917-08ddc327507e 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: SN1PEPF0002BA50.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB9053 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Define new bit-field definitions returned by SNP_PLATFORM_STATUS command such as new capabilities like SNP_FEATURE_INFO command availability, ciphertext hiding enabled and capability. Reviewed-by: Tom Lendacky Signed-off-by: Ashish Kalra --- include/uapi/linux/psp-sev.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/psp-sev.h b/include/uapi/linux/psp-sev.h index eeb20dfb1fda..c2fd324623c4 100644 --- a/include/uapi/linux/psp-sev.h +++ b/include/uapi/linux/psp-sev.h @@ -185,6 +185,10 @@ struct sev_user_data_get_id2 { * @mask_chip_id: whether chip id is present in attestation reports or not * @mask_chip_key: whether attestation reports are signed or not * @vlek_en: VLEK (Version Loaded Endorsement Key) hashstick is loaded + * @feature_info: whether SNP_FEATURE_INFO command is available + * @rapl_dis: whether RAPL is disabled + * @ciphertext_hiding_cap: whether platform has ciphertext hiding capabili= ty + * @ciphertext_hiding_en: whether ciphertext hiding is enabled * @rsvd1: reserved * @guest_count: the number of guest currently managed by the firmware * @current_tcb_version: current TCB version @@ -200,7 +204,11 @@ struct sev_user_data_snp_status { __u32 mask_chip_id:1; /* Out */ __u32 mask_chip_key:1; /* Out */ __u32 vlek_en:1; /* Out */ - __u32 rsvd1:29; + __u32 feature_info:1; /* Out */ + __u32 rapl_dis:1; /* Out */ + __u32 ciphertext_hiding_cap:1; /* Out */ + __u32 ciphertext_hiding_en:1; /* Out */ + __u32 rsvd1:25; __u32 guest_count; /* Out */ __u64 current_tcb_version; /* Out */ __u64 reported_tcb_version; /* Out */ --=20 2.34.1 From nobody Tue Oct 7 03:46:27 2025 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2055.outbound.protection.outlook.com [40.107.236.55]) (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 2842D23ABB9; Mon, 14 Jul 2025 22:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752532801; cv=fail; b=PNOXbZkBcdnLlGlAi8JAfSGLPd4wePog+gJzVIRG/ixV6mvsv46aEE4Ev4n0cEaXmM+vtx+zWNqB8RnjqRv90fmnSe7ONhghK516ja5sm94+GwoBuWrgWZQn2yGYrovbvmylAWWi7tCNXiCcvaV343W8UpK91FqVyWfBJN4Hn5E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752532801; c=relaxed/simple; bh=6qWq0iY1vj8BVVAWKLvKpxS6hB4nytt/u11JQdBH2oc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EGZfub7aZb34BkLtqY/l3gVyZweZErAJs7k4cgjChe34QF1zqTu94xw8la0rOIUZs6BjlpL0/7ELvLsu7CPM8aX1q2pI+VjCsMk3OhfVxAdGHm0ezvLWfCTBR6HJVtBfg12uANAhOPU2SxEIV/EgC2jvNESBVAlMuT1LgQkA1Gs= 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=ebwsnViq; arc=fail smtp.client-ip=40.107.236.55 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="ebwsnViq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ykbLecUJgY3c0g85fyxb/fQld8+lbKwQpxKK16k3QxjA9uBTCG72y+n6+qoAJdQgm+JfmgD7TQUtCSCX+20TS06SIKFu/gDsB3pbLhG9DTkGYUbf7Eul2QbGzlsdeIdM4aYIf9HvXccM67RZkayxu6RGul4mtspZjQX2d+Ok3dU/W5KfiUH5wJOb7/3klqZIXK+gUTUbL+Q0gsOtueOIGq8dpBn/Cx9p+dmeYvmYiuN8XnnlpwlHQ0TK3T+tQXcFwcbfBZMUK42JormP+Rm2sLuLlEB31qVu0OszEkqz0NlObkuh9Y1eKuhv58vIPDCm9pBAiQ0Bm8xfP4e1GkC9KQ== 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=KmVMMcDneRK2iE1QcHklTDa33H/bBW96LFaSTQxc5nA=; b=ITZwrLgPMtsKOAip6sGa07e6jCQ7F4GiGkOGZXHBWkUnZ/zfkd8sVSnwfKDNr+Gag7F7Gf1FD59S3sF/vH7IbaXcIr6RPsIm+xXeoHq53JP4RXn5VDyHjhVDV/cn2M5NtRx8xLGzci/5eiNvtvpmpqqz/CqEIpNump1tWyf+ngOXwDkf9CCfIZ5wp247iC3DYs4EfG4H+tnuTydSm2MwstmSo6kZw8I6xPKRiSrKmx301IJqwv9gJSlV7iYU8KAivCnzhBdfCqMaaVjKDWQjpLbWhRpI2CX1auXSdxZOSH0BXNualGAw/GI5HkJfSwdoxuP1qO5hoTgxLUzkEfAiRQ== 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=KmVMMcDneRK2iE1QcHklTDa33H/bBW96LFaSTQxc5nA=; b=ebwsnViq0hdyFqK1wAJXCqBbgyEcBSahDtUGr4ME7uWgZpCN3VqJHWun9V93Xm074vQWsZNjGUkpE8Uu/T9ew73lZnec2tK7FjMU7nU6UXUX8EBZURVPvNTvhKZsG3/U7vBXfU5iTc4ov6sqgwjqXfwSpEF9MuudLMTtgqNjHQI= Received: from SA1PR04CA0001.namprd04.prod.outlook.com (2603:10b6:806:2ce::8) by SA1PR12MB7247.namprd12.prod.outlook.com (2603:10b6:806:2bb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.32; Mon, 14 Jul 2025 22:39:54 +0000 Received: from SN1PEPF0002BA4F.namprd03.prod.outlook.com (2603:10b6:806:2ce:cafe::9a) by SA1PR04CA0001.outlook.office365.com (2603:10b6:806:2ce::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.33 via Frontend Transport; Mon, 14 Jul 2025 22:39:54 +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 SN1PEPF0002BA4F.mail.protection.outlook.com (10.167.242.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Mon, 14 Jul 2025 22:39:54 +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; Mon, 14 Jul 2025 17:39:52 -0500 From: Ashish Kalra To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Subject: [PATCH v6 2/7] crypto: ccp - Cache SEV platform status and platform state Date: Mon, 14 Jul 2025 22:39:42 +0000 Message-ID: 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: SN1PEPF0002BA4F:EE_|SA1PR12MB7247:EE_ X-MS-Office365-Filtering-Correlation-Id: b1636ef2-1fd2-4dc6-13b6-08ddc3275a7d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|36860700013|7416014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?BWMpoM8H4kZ8JcOT21z2JRnZkPMmoCEDefopimtspk3XvLJIQ5HQFie8SHzU?= =?us-ascii?Q?pGryPo8xY2/U1b/q38h/uCVkaB5KdhmmD1WWCWXJC1doLBotsZkZZ0nxLLRu?= =?us-ascii?Q?kF5Q8TokVtHWraJBrt3EfLFlIkGRMGqW4FpJNQ1SlDksSpDvAzNui60cUWQ1?= =?us-ascii?Q?rVcQd6vYUxy1yvtXsueLj7klzdOdRl7TA4sXBKLZ6aLf+V2ZqeH80rB85RVf?= =?us-ascii?Q?s66PxKftPG3s70lXZZOdMobEmht6TbpDZ+cdk3RjH9ZBnDfrniRqfVKp56Ma?= =?us-ascii?Q?+DQ8f4399K+G+HNae902+12rMoIbpUyRwKW2XJ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85gjIEh8Rzo4mAfrn/64Jf4Uruep19c36eUJN?= =?us-ascii?Q?aKYGdenoW1BrZRx512cLj3Z6IL/rb6xd0t81VBvTAsfEgVH4ygHMzce8OnBm?= =?us-ascii?Q?RD3sc/gV2co8H6+lxWx+4HUTABrYjrhJY4vgpif3rJln2k/+pVRd6KX7aMmu?= =?us-ascii?Q?baa8SLhNX31oJOb2yxDOAEcjmKPFexUH53n3DY3Lvo1EqOtHmPEIoEOqx6zF?= =?us-ascii?Q?wfItxftjG5pLbyx0FFrcMjBc7TRsQ56u1Yhfqlpu4n8NSvvmoQ8J/TM2lNIB?= =?us-ascii?Q?HPz6ewNp3v+QXPSW9o9Lra+4l6kf/8+S5R4F+mujCT06mnbV4V//44duCg?= =?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)(82310400026)(1800799024)(376014)(36860700013)(7416014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2025 22:39:54.5118 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b1636ef2-1fd2-4dc6-13b6-08ddc3275a7d 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: SN1PEPF0002BA4F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7247 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Cache the SEV platform status into sev_device structure and use this cached SEV platform status for api_major/minor/build. The platform state is unique between SEV and SNP and hence needs to be tracked independently. Remove the state field from sev_device structure and instead track SEV state from the cached SEV platform status. Suggested-by: Tom Lendacky Reviewed-by: Tom Lendacky Signed-off-by: Ashish Kalra --- drivers/crypto/ccp/sev-dev.c | 22 ++++++++++++---------- drivers/crypto/ccp/sev-dev.h | 3 ++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index e058ba027792..528013be1c0a 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1286,7 +1286,7 @@ static int __sev_platform_init_locked(int *error) =20 sev =3D psp_master->sev_data; =20 - if (sev->state =3D=3D SEV_STATE_INIT) + if (sev->sev_plat_status.state =3D=3D SEV_STATE_INIT) return 0; =20 __sev_platform_init_handle_tmr(sev); @@ -1318,7 +1318,7 @@ static int __sev_platform_init_locked(int *error) return rc; } =20 - sev->state =3D SEV_STATE_INIT; + sev->sev_plat_status.state =3D SEV_STATE_INIT; =20 /* Prepare for first SEV guest launch after INIT */ wbinvd_on_all_cpus(); @@ -1347,7 +1347,7 @@ static int _sev_platform_init_locked(struct sev_platf= orm_init_args *args) =20 sev =3D psp_master->sev_data; =20 - if (sev->state =3D=3D SEV_STATE_INIT) + if (sev->sev_plat_status.state =3D=3D SEV_STATE_INIT) return 0; =20 rc =3D __sev_snp_init_locked(&args->error); @@ -1384,7 +1384,7 @@ static int __sev_platform_shutdown_locked(int *error) =20 sev =3D psp->sev_data; =20 - if (sev->state =3D=3D SEV_STATE_UNINIT) + if (sev->sev_plat_status.state =3D=3D SEV_STATE_UNINIT) return 0; =20 ret =3D __sev_do_cmd_locked(SEV_CMD_SHUTDOWN, NULL, error); @@ -1394,7 +1394,7 @@ static int __sev_platform_shutdown_locked(int *error) return ret; } =20 - sev->state =3D SEV_STATE_UNINIT; + sev->sev_plat_status.state =3D SEV_STATE_UNINIT; dev_dbg(sev->dev, "SEV firmware shutdown\n"); =20 return ret; @@ -1502,7 +1502,7 @@ static int sev_ioctl_do_pek_pdh_gen(int cmd, struct s= ev_issue_cmd *argp, bool wr if (!writable) return -EPERM; =20 - if (sev->state =3D=3D SEV_STATE_UNINIT) { + if (sev->sev_plat_status.state =3D=3D SEV_STATE_UNINIT) { rc =3D sev_move_to_init_state(argp, &shutdown_required); if (rc) return rc; @@ -1551,7 +1551,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd = *argp, bool writable) data.len =3D input.length; =20 cmd: - if (sev->state =3D=3D SEV_STATE_UNINIT) { + if (sev->sev_plat_status.state =3D=3D SEV_STATE_UNINIT) { ret =3D sev_move_to_init_state(argp, &shutdown_required); if (ret) goto e_free_blob; @@ -1606,10 +1606,12 @@ static int sev_get_api_version(void) return 1; } =20 + /* Cache SEV platform status */ + sev->sev_plat_status =3D status; + sev->api_major =3D status.api_major; sev->api_minor =3D status.api_minor; sev->build =3D status.build; - sev->state =3D status.state; =20 return 0; } @@ -1837,7 +1839,7 @@ static int sev_ioctl_do_pek_import(struct sev_issue_c= md *argp, bool writable) data.oca_cert_len =3D input.oca_cert_len; =20 /* If platform is not in INIT state then transition it to INIT */ - if (sev->state !=3D SEV_STATE_INIT) { + if (sev->sev_plat_status.state !=3D SEV_STATE_INIT) { ret =3D sev_move_to_init_state(argp, &shutdown_required); if (ret) goto e_free_oca; @@ -2008,7 +2010,7 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_c= md *argp, bool writable) =20 cmd: /* If platform is not in INIT state then transition it to INIT. */ - if (sev->state !=3D SEV_STATE_INIT) { + if (sev->sev_plat_status.state !=3D SEV_STATE_INIT) { if (!writable) { ret =3D -EPERM; goto e_free_cert; diff --git a/drivers/crypto/ccp/sev-dev.h b/drivers/crypto/ccp/sev-dev.h index 3e4e5574e88a..24dd8ff8afaa 100644 --- a/drivers/crypto/ccp/sev-dev.h +++ b/drivers/crypto/ccp/sev-dev.h @@ -42,7 +42,6 @@ struct sev_device { =20 struct sev_vdata *vdata; =20 - int state; unsigned int int_rcvd; wait_queue_head_t int_queue; struct sev_misc_dev *misc; @@ -57,6 +56,8 @@ struct sev_device { bool cmd_buf_backup_active; =20 bool snp_initialized; + + struct sev_user_data_status sev_plat_status; }; =20 int sev_dev_init(struct psp_device *psp); --=20 2.34.1 From nobody Tue Oct 7 03:46:27 2025 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2075.outbound.protection.outlook.com [40.107.94.75]) (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 5720D5103F; Mon, 14 Jul 2025 22:40:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752532821; cv=fail; b=m+V71/rl4IcaNVKtDQWsgkoinJWvfqH5wwPC0ZpROg/gD36Gmz69V/1xQ9Qi2Nb7walGcn2CHH7SETm2e6Z0UdDXWbtVTzwMeOdaNJwMTtnTzRcx4JtEvHQyLr7h7NhMzcxiX0Cg3BcWFYj7jikEb2EOlTj6/CxpvP1K4XeeVIA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752532821; c=relaxed/simple; bh=Kn7P7bwZ5A+JdQciInEzBqnrHvcTZKRDFC9AVROgplo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UOTQV7Yp6/A375RtzIWyb8CYcFSRcPCaxhHsxJHhXAobdi/zhYLjBNJM99khgMI4XALNvGFZQ1A2pCfU1miQVvueVczX27+XZOBJ8mw19IdHFtKXpeZ58C5nifd/rs7quBatWzXc8aVp7jga+OKv9fBSBx2TER9g86N78+N1i4U= 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=Kz6Hd79F; arc=fail smtp.client-ip=40.107.94.75 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="Kz6Hd79F" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sGuabx2fpvgvoR9IJ0CUwl00sQrJAHv2znFCOGS08H36guWICAmLBCy36XwxflFYx7IgDVqJSAzs1rnMdWvlukvn6cg1NpRxXs30rKNHmdwCGKz+lalTqaT1P0phrKPvIkHYdCnMCyRIiqpjyfGS7yFOs9Dh05EhBfl7yprjoId1tn6baKn2liu1T4/8RQK+XJaRUWaPv5g3m8KQVCpQd12q+ARa/QpsnIXScywgt05joLdP4RWTPfkPD4Xy54rJM/hnoCs53vNd8vctOWWaSXG8lmqX97+hiGAZl7hxRN1D2RU/BEem+z/CW3KUVDwHI5pKpOkPG1RwoIeWrkJDBQ== 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=wVkrIfZuUsioM+cnyA+r6AfReIZf83aAxm+tgNechCA=; b=ZHPa9T1M+6iLDKHThcJGLMIFk1uTPHIphU9NSpTCzCoxdkVpGjCgoXjneUngUDc3HCI6djbAtwUozl2056DKDmGDDXEzkA/KIGOGIaQYN6tk4ErzRtVKis2+OWE/itfFh+4zJLIlKyWXDRZJh9q23eltc8B2LecYgubXG5K/sZStYj1aySYVBKXMf7l5FRUy+HnfWBHnaz4Gxh3CSqVnOxPgC6CBn1J3yl996kk0xnqDfDbHvN8O8ASTLmHuXvamWiO23N+M7HCX6V44MZci1lk1YfprWgpWP+H+5QpED0uaNg/INy6N/k56A2YYG+mB1xGea/9BIwAdFnIrrlQliw== 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=wVkrIfZuUsioM+cnyA+r6AfReIZf83aAxm+tgNechCA=; b=Kz6Hd79FSkk4SUrE0VqRVfNcGRjLKYMp2cbZLEWvP2zLRXrS7vNy5z6A9FV6PUMVuLIS+aGYvoBPkd+F8oLZ8xqbHUQd6Uvjc9eMw5t9FIjquix2O1UEbo6JPV12RdWKuHDhdNs4VhE9kxVEuTtHArD9VQX9CF1ECTGbB3YQLbw= Received: from SN4PR0501CA0123.namprd05.prod.outlook.com (2603:10b6:803:42::40) by SA3PR12MB7999.namprd12.prod.outlook.com (2603:10b6:806:312::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.26; Mon, 14 Jul 2025 22:40:12 +0000 Received: from SN1PEPF0002BA4B.namprd03.prod.outlook.com (2603:10b6:803:42:cafe::60) by SN4PR0501CA0123.outlook.office365.com (2603:10b6:803:42::40) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.13 via Frontend Transport; Mon, 14 Jul 2025 22:40:12 +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 SN1PEPF0002BA4B.mail.protection.outlook.com (10.167.242.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Mon, 14 Jul 2025 22:40:12 +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; Mon, 14 Jul 2025 17:40:09 -0500 From: Ashish Kalra To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Subject: [PATCH v6 3/7] crypto: ccp - Add support for SNP_FEATURE_INFO command Date: Mon, 14 Jul 2025 22:39:58 +0000 Message-ID: <7fe696f2cfda1e6cd3c24af5b0a93c70ac692667.1752531191.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: SN1PEPF0002BA4B:EE_|SA3PR12MB7999:EE_ X-MS-Office365-Filtering-Correlation-Id: a476f167-c9cc-4d32-8fa1-08ddc3276559 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024|7416014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?pTNOtQB5J0UW1XWWfhgyZdO+47RZOvt9ZLMfrEi3DvfFq0LlFaoT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8NdOseG0/3zsB3bFbldNn3Ss/CGdS?= =?us-ascii?Q?2nTwq+l+4apId7T9MKUXD7FU/Ab7Hg0mSDdfcdDFEv2H3bRjnkwBy8/3fGFI?= =?us-ascii?Q?iWzs2HezyNHX48DTKUC8NMSd46eQiGYeonIFJJ8vbgONeBqbiRo5ROYg2FNz?= =?us-ascii?Q?fWAKKvMiD7AqhVX0zz7SApRDiwcRi7RbdNkfPhxb20M6TTXp6E13c19+qIQA?= =?us-ascii?Q?nuAmHzRJ8Mh9Y6hB25K9iX4hYnXAX4qCpY8wh85y8WaBibra1a4/dabw0gNE?= =?us-ascii?Q?o80SDoD9Q1mL+/Iqwn5XEYrK7i7YnE6biohOnFtqj3nasvVVRPW6cErqUSTs?= =?us-ascii?Q?uhUdNGIybNzjWPcKn1cIIgQ24cbaCY91krULaPxzYIIrRRppQTHFnjEtpA1y?= =?us-ascii?Q?uwZRms5JIrt3JkcjfKCRMNxmDiEmV1RIs1oBxSTHNNO/X7wCp5NOT1bNHBYW?= =?us-ascii?Q?BWKxAIts7TGMI5zDLSMK/gWg5NLTQ7t4DRwUP2ei0o2in88z1pGcNhBacHSN?= =?us-ascii?Q?fiuBvKTkJzokapUyj/XxlgdotYUfhfqOF7w2ahUzR6rYhMhs58pBzsGq8x/u?= =?us-ascii?Q?2EqJ8M8kTSE3LwSAfPmZ9DtfEPhodqRD1SuTuKi8ZCgJunVMDhCnKFI9vw?= =?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)(82310400026)(36860700013)(376014)(1800799024)(7416014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2025 22:40:12.7573 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a476f167-c9cc-4d32-8fa1-08ddc3276559 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: SN1PEPF0002BA4B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7999 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra The FEATURE_INFO command provides hypervisors with a programmatic means to learn about the supported features of the currently loaded firmware. This command mimics the CPUID instruction relative to sub-leaf input and the four unsigned integer output values. To obtain information regarding the features present in the currently loaded SEV firmware, use the SNP_FEATURE_INFO command. Cache the SNP platform status and feature information from CPUID 0x8000_0024 in the sev_device structure. If SNP is enabled, utilize this cached SNP platform status for the API major, minor and build version. Signed-off-by: Ashish Kalra Reviewed-by: Tom Lendacky --- 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 528013be1c0a..8f4e22751bc4 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..5fb6ae0f51cc 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 : System Physical Address of the FEATURE_INFO struc= ture + */ +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 From nobody Tue Oct 7 03:46:27 2025 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2081.outbound.protection.outlook.com [40.107.92.81]) (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 B6D9022DA1F; Mon, 14 Jul 2025 22:40:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752532839; cv=fail; b=i8Lc1ke+SMVFSrOLv7+FoGqp3bEsGbRl8pM+JtuadEWmnId5lwwAQWqi5NGJ5BpsEGE8TiUP5u763uVs0yA135pds3Zb8Zf66UOk+p8ivQZNizxwimwXZS/eTDAD9xXwRLRgmWzOhF9Jj2FaMn+U/yFueUPmgs/P402Qwl4sAz4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752532839; c=relaxed/simple; bh=EbCfapcfKNXTw9Wn0+yaQtHA8gtCQ+ExdT5njBRoUHg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QYVa2NCqJqauKvcK8jRuv5+OtYBXMijNgULWfQDlCgNt+Pp4fUZbf7p6g9TqFtYEU+Ob2IR6lz/+9A31+rrfmQkIMMqNWEBbMjGMgw+0mzCW+U8l21JIsGS3cV3+0rBkdgYgSZp336JnjuG2xiVvIk4AWgYDzaXzdIdAgJ519hY= 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=wibqIVuF; arc=fail smtp.client-ip=40.107.92.81 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="wibqIVuF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rNM3YfMQSNy33ZrrmIbpFqQXc7L6Bd0tRXUCWfhwhCJKeUQ1rMpkF5o0M5hP3FxVTAjBcPAqcOL5ReLjAhRYmZDmpszXTya/KH1txzbfuOBVVTrjHcNq9/lia3BdY+YPdHaV7byvk06zkCuHqrwRHCwDQv0Oxs1vzgzbd5NVGQorYnMm/HZstZkOSVs2CQXLTY1FcXKCUiiHyFyTk7uQqgVitIBqXXCJFkFuwmoHZlCRDakpCNV/ngQrc6t71/EI0V79ed9U5EmJDcVm9FgmRwIQ8BY2iUOzNEWqYVCGqfG9aVpDcwR9+2TESuoocGLMZHeviYhF/wsGruUXs3CLIQ== 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=JJCiynNmCfzkXzvlMNkD8O9M1HMiKr9Bqv7ewdRFvZo=; b=GkCHNFr1xCG8D9dhHhXc09kWUKtTqcqxI1YyTPfTXdFmHx4sIIadEGYqLeSDE5NRnuCcR6AraeKWmC+Sbx1qc8W0Jac81+f3iF8ns6daGzAjld3GryWox1pzPGA8/DmkDsUSxA0DHNqnnQvd1qmZPHzfhg1oW4e4o2O2eU3n2ldSi1SHm2JAkss9b10v5ZjQNg0LnRtDfPfNwjSP7USRnIl1NaEr3Zjxh8T4KkzBjaaCgRTpWJKenzW5qBnI1wBFynx+xbZosWxgrx7jsLIQuf5N6+ZrE/mmM2AL3o+fqi2gRjAZF4aardtDbjNH8NHco+q/ocOSgZRu+t525ivOAw== 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=JJCiynNmCfzkXzvlMNkD8O9M1HMiKr9Bqv7ewdRFvZo=; b=wibqIVuFlVm3kHTEQR/YppLbu+kY+/mw5NdsOU8HsjSR+p7WpBE8rWLj5pZjLg+6CLciZG+w48AUQR8ACKpZWD6TKM48tU8lJv3RRvNiyNyGeidpIEnKs20cWRTjcagSrkbrNufwgDi9nq5l5Bw1V8lLY8APzz28/HAEgYcMxEs= Received: from SN7PR04CA0233.namprd04.prod.outlook.com (2603:10b6:806:127::28) by CY5PR12MB6225.namprd12.prod.outlook.com (2603:10b6:930:23::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.25; Mon, 14 Jul 2025 22:40:30 +0000 Received: from SN1PEPF0002BA50.namprd03.prod.outlook.com (2603:10b6:806:127:cafe::c0) by SN7PR04CA0233.outlook.office365.com (2603:10b6:806:127::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.32 via Frontend Transport; Mon, 14 Jul 2025 22:40: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 SN1PEPF0002BA50.mail.protection.outlook.com (10.167.242.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Mon, 14 Jul 2025 22:40:30 +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; Mon, 14 Jul 2025 17:40:28 -0500 From: Ashish Kalra To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Subject: [PATCH v6 4/7] crypto: ccp - Introduce new API interface to indicate SEV-SNP Ciphertext hiding feature Date: Mon, 14 Jul 2025 22:40:18 +0000 Message-ID: <2afb8bf011d6d40419b880303f4556299a1a2c46.1752531191.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: SN1PEPF0002BA50:EE_|CY5PR12MB6225:EE_ X-MS-Office365-Filtering-Correlation-Id: d17624c9-37fc-4dab-f45a-08ddc3276fca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|7416014|82310400026|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?EIZOUcc4tqbmEf2BxrxJmTHXcC2KgaTe9j5PAWmcV+qaTvbq9+2Un4edUFpj?= =?us-ascii?Q?UPTMnkPgzP0MfbEHU2bSulxwcTZshJfZqaQcgxS7OkqsN/8LcH7eMFgcucbP?= =?us-ascii?Q?oIFsB9DXDgrirR8c6HAmYb4G2PlZ1UELPv6iUUABjMxWN3kKWln9V7tvOT4p?= =?us-ascii?Q?T4tG1uwmebD4+J26arO1YMF0shZm1sSk0EA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rTRzkh4Z4TYlGD55kRvo/4o4B1NUX+gmad2nXtb+tz?= =?us-ascii?Q?fRURSfRTMEbXOhqgIudiOsa7Ia0rZACaKWghGCSZvic+Np2CqFna9npDPnOp?= =?us-ascii?Q?gd+80fArOqxxS/3/tJpzDJ7wkoY8Mb7TF83DjUWTW+296Rva0E+pZ7iXi8h6?= =?us-ascii?Q?NkXuU7al1qrDGEoa+VzypKpGLNJa2UUm7GZR7UiEkp4zRqiSyJt9buL1PS+t?= =?us-ascii?Q?Pc3QpWrBErQKbHT1nMJBj/q3V3keF+3pyvg6vWQ3dPrCaGorGDkbvIl/R9f2?= =?us-ascii?Q?/jCse1r4D84/QqYTVX653940Gw6SJMH1OcbxfDKxuk7qo+mU5I7Z3M6EX3B7?= =?us-ascii?Q?bweFYx6YHgXoYobqbwYxaffnuR+t+l5phJaMUzC/xI0+gNFthDYG23oGge9n?= =?us-ascii?Q?sSRsBPEb1C34Yf++eR3ih/WBxAHauMVS741Vdqh7zs6sUjK+E9FST649rw?= =?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)(1800799024)(36860700013)(376014)(7416014)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2025 22:40:30.2539 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d17624c9-37fc-4dab-f45a-08ddc3276fca 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: SN1PEPF0002BA50.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6225 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Implement an API that checks the overall feature support for SEV-SNP ciphertext hiding. This API verifies both the support of the SEV firmware for the feature and its enablement in the platform's BIOS. Signed-off-by: Ashish Kalra Reviewed-by: Tom Lendacky --- drivers/crypto/ccp/sev-dev.c | 21 +++++++++++++++++++++ include/linux/psp-sev.h | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 8f4e22751bc4..ed18cd113724 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1074,6 +1074,27 @@ static void snp_set_hsave_pa(void *arg) wrmsrq(MSR_VM_HSAVE_PA, 0); } =20 +bool sev_is_snp_ciphertext_hiding_supported(void) +{ + struct psp_device *psp =3D psp_master; + struct sev_device *sev; + + if (!psp || !psp->sev_data) + return false; + + sev =3D psp->sev_data; + + /* + * Feature information indicates if CipherTextHiding feature is + * supported by the SEV firmware and additionally platform status + * indicates if CipherTextHiding feature is enabled in the + * Platform BIOS. + */ + return ((sev->snp_feat_info_0.ecx & SNP_CIPHER_TEXT_HIDING_SUPPORTED) && + sev->snp_plat_status.ciphertext_hiding_cap); +} +EXPORT_SYMBOL_GPL(sev_is_snp_ciphertext_hiding_supported); + static int snp_get_platform_data(struct sev_device *sev, int *error) { struct sev_data_snp_feature_info snp_feat_info; diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index 5fb6ae0f51cc..d83185b4268b 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -843,6 +843,8 @@ struct snp_feature_info { u32 edx; } __packed; =20 +#define SNP_CIPHER_TEXT_HIDING_SUPPORTED BIT(3) + #ifdef CONFIG_CRYPTO_DEV_SP_PSP =20 /** @@ -986,6 +988,7 @@ 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); +bool sev_is_snp_ciphertext_hiding_supported(void); =20 #else /* !CONFIG_CRYPTO_DEV_SP_PSP */ =20 @@ -1022,6 +1025,8 @@ static inline void snp_free_firmware_page(void *addr)= { } =20 static inline void sev_platform_shutdown(void) { } =20 +static inline bool sev_is_snp_ciphertext_hiding_supported(void) { return f= alse; } + #endif /* CONFIG_CRYPTO_DEV_SP_PSP */ =20 #endif /* __PSP_SEV_H__ */ --=20 2.34.1 From nobody Tue Oct 7 03:46:27 2025 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 77291277807; Mon, 14 Jul 2025 22:40:51 +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=1752532853; cv=fail; b=Y2gScmKglIcLBbvWFNDq5LajSrfdQBFwfJL0BtTxsPfDOTGhwoVBy3cYIcZ3mjE/KUh4Nbtw9cvj9bXBv5JYF0dKPv09eTo6keBrvliYLxRefXc0D4WL6/nVqiB5cgdkogFt7NTRAOIwBRyIIMk61sn0pPDkimopIbYBZ9ApVTk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752532853; c=relaxed/simple; bh=DrdIwmQcEyUIZaviWN5Vb74iRPbx/egsmIL7S6KzMtE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JoredJfF4hKsJFh4NNaJaTKXHcnuxeslBiAfpiX9fuBnzfzStEAlcO/nF6QRPsPXbFcuDgJ8BOvXbcv1PZ0errPxKBvwrNI4HTLYI3IEvCsQlKjHqb23cFEw/uaOFdzzjtGuvR5BnziUJGpUn121S3O47WLCbzOGEPUQ0Dj/LgI= 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=XAIRNvHv; 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="XAIRNvHv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=p1Z8W6E6vL7OqeFv2abkOEYbobZhuhJJ9xPpsrfxQgyq+rxAwnhFt+0ZQX7cg1MOBICACVZqlMAo2PXrnUpHxOSpnjlMMycmHD/lGx7F/ARlv1CLtg1Rx1E1/4xdHrtESFz3teOmVHJD+fifL7/aA4w9yLKyDvTjc3TMhxQF0vG50MMkJdIJUTl2UVlP9zds4Oqa+ODK3nL4sJluqWYMCTGdCIyRzFAEpTCURX9mVYYGhLYPG3VuKwyXNJvUWbhnddNjxgzwASkNbVvYcL5tg+2dxNmez0/JS257evmeqBzokMdeImjq2/zzfa6QFs5eGhwUI3P5tjJAx37eo/5CQw== 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=m0sQaaodKfUXnQidfh9Kkx4clbtAKOiP4+nB5dc5Gkk=; b=XPqix9ZKKlIAa/MAHkPNG3J4PTwmU8vzGE8adEOernTs7LuuxYcK0n9CKJJxT+uBEgPxYfCOA9dqfiBdipBSIsAR8oq56mpYzTlrdKJnfPRqA7ecPtkZ34xcYx2+ZfeQAofM93RCx7DRXVTdTkleC9OIMEa9hhgVrkQwPKiWCW+mloKQIpUAzfQLEXolnID7LquVbVtytVo5VI0/xMNfyQ3XI5KAL1A4Gzw8fv9ByR/oP7SF0D3XiVr61mMmScdRi/vn9IdtS05MMdm9baOnhUuLcZCua0gnUfUobm1xn6OfAmvXbpqZ+36KA8OXyQtamaEWOc/7rYp98qcgmfbuMw== 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=m0sQaaodKfUXnQidfh9Kkx4clbtAKOiP4+nB5dc5Gkk=; b=XAIRNvHvssgZiwHPhbR0BOO47YUS9hFVeVd5DXhTKalaImZIrQU0t+Qmwa1Zvjl03NobpOqsKbkYGIhT6rR8I1iyjwXgI/rn47DM09XTrPM+b/kjzi8KG91jfPDQCxDnR01+3gfhXRfqrDhY3vUIlkP8aI0bfzNWurgewds9iak= Received: from SA0PR11CA0019.namprd11.prod.outlook.com (2603:10b6:806:d3::24) by MW4PR12MB7468.namprd12.prod.outlook.com (2603:10b6:303:212::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.32; Mon, 14 Jul 2025 22:40:47 +0000 Received: from SN1PEPF0002BA4C.namprd03.prod.outlook.com (2603:10b6:806:d3:cafe::1c) by SA0PR11CA0019.outlook.office365.com (2603:10b6:806:d3::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.32 via Frontend Transport; Mon, 14 Jul 2025 22:40:47 +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 SN1PEPF0002BA4C.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Mon, 14 Jul 2025 22:40:46 +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; Mon, 14 Jul 2025 17:40:44 -0500 From: Ashish Kalra To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Subject: [PATCH v6 5/7] crypto: ccp - Add support to enable CipherTextHiding on SNP_INIT_EX Date: Mon, 14 Jul 2025 22:40:34 +0000 Message-ID: <15640300c8980b671b34b0b4290976d77c1629cf.1752531191.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: SN1PEPF0002BA4C:EE_|MW4PR12MB7468:EE_ X-MS-Office365-Filtering-Correlation-Id: 5ab13d9f-ce5f-451e-2a31-08ddc32779c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014|7416014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?3HthDrIXdR0XM2xGXJ1qF8cQ6oabNu8ai1WiGWe+72NhkxfMUvNqLHtfGP82?= =?us-ascii?Q?7alhTZifyyVUUEd53DAso4KP/XJzjPa2kaBvxbRPIjfI3XFrhlOEuTRiKOv5?= =?us-ascii?Q?xSWYvlLoK62WsPFqqq1psTa4LhnI+BgU3i005WQe1aINqzQpQu45ETKqupDA?= =?us-ascii?Q?sP9VncZe9j6Su7L586b4aPWaHszhMgHLyC/wZ0LP7Pdy1K86BvLr9jZ+U5WO?= =?us-ascii?Q?29GtwKPxpwsZVIh0+kUTPS8GHLH8lBMCHe4QJWYxsOXiwS5Qfx13dKkIYvTf?= =?us-ascii?Q?ubwnTRdVaBV6Fhc21EMD2AKN9X45iG0w0PdSRHCt0ZsTPljuvULNdqQhbBYg?= =?us-ascii?Q?OveqD/jTs4xwSFUiH7TZypKLh1oh3fyvQ7vlLDXlJX+u4TGxJ3WIZ2gY5eKS?= =?us-ascii?Q?Y18YTu9/PIThmEcmmEJkY2vJQ34cOarEUIYWSOsv/Nft00SlaJzWMvm3yRYr?= =?us-ascii?Q?+nDU//yTO3iFE11K0NNFjqSSWJPdP995zWZ1V7FUudI+gCiy06Z5zpNEFMgs?= =?us-ascii?Q?tLP3Gc0P8geH22P/0oTpHrE0lCjWsZEeVQqwftdZZNLqblVpIe7KKwKm5rqP?= =?us-ascii?Q?DhV5bC212714DTV6wE/pr1K++8d62/6ROsmPwY+N1OUmPuOIuhIhNEXd0kId?= =?us-ascii?Q?kCJtxFAcZqj1n4amdgN4tYlbYFPkXPKqTV3TOMwr32HZKIymh8ApKi299xq4?= =?us-ascii?Q?tQ9qB0vWungnm3Xe3xiQ7m/ubsSi4ReCbCvuMsKKEDIPx8WOv3o/7BgJPQKE?= =?us-ascii?Q?6WLmqDJNmo5+QE1pp9SEOwhIBOuzXqd2smrZsFMj6plK2Ct3ObR4EwMNPD65?= =?us-ascii?Q?J7+AzqUAdj7LAwHgMAJukz1Z9UVOyi4H8cYDh/xzvF8vfazwE41YU6ONBmB3?= =?us-ascii?Q?IBz/x5lrUufFSzixJFRhKgDjxrWGtUgPqa6n7TwzV6/HBU4hd6gF1eFosZ6U?= =?us-ascii?Q?5iZPD5olFrCJYiYCCa8HVhIGBG/70zz1xa2BYH49vTF4+xZ9LOXkkZX0QhJm?= =?us-ascii?Q?eVKOOuaQV3YPSjPxJftIrPTuEP3x+xrhFIAoQwOoZr0g5bF67Xbh1u5v2g2v?= =?us-ascii?Q?G4Wtj6rXCKMKFvXbneXrSBXdoPmdyOjUvIE8nukqFBdwoG3WjHsjGSZ1tKct?= =?us-ascii?Q?iC1N0olezEIi6tRJ2ZIOXMafi34BtKyFVm9S6LH5WLx/NQhs9IK+GgWCKd7M?= =?us-ascii?Q?Ls502eb8+5R7n308PNNSX6GBlSbjRdbZjaIUOxTtx7Klmt9zLAJXTgUVoKbI?= =?us-ascii?Q?dfWNX6SvUdhU3FmzAe4tivEE8i4tohRLFNsrGY6QeHEqtqkd5o0BSK34AdnB?= =?us-ascii?Q?qBm41bSA+s/ESmXvJINAeZREXouEfDcoOIxNcKW5oXkbh8u/fBv7pb68ADVQ?= =?us-ascii?Q?hKrBqkyd3xXeKevnO5or/kRLayT5AF4+CwiPcadZjOsNccqybChZUDh6Ow0w?= =?us-ascii?Q?mJBO6trYwvLwlpjyfQopGUoAdqV/m79aZY6PUNEmHwp+RhbWfo0QkCYAa93j?= =?us-ascii?Q?a2nc842z72QWMpHF+JDmJ8nIpACWHwPODXTkpdn+Z/rXvlGkgdrScVri2g?= =?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)(36860700013)(1800799024)(82310400026)(376014)(7416014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2025 22:40:46.9620 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5ab13d9f-ce5f-451e-2a31-08ddc32779c0 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: SN1PEPF0002BA4C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7468 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra To enable ciphertext hiding, it must be specified in the SNP_INIT_EX command as part of SNP initialization. Modify the sev_platform_init_args structure, which is used as input to sev_platform_init(), to include a field that, when non-zero, indicates that ciphertext hiding should be enabled and specifies the maximum ASID that can be used for an SEV-SNP guest. Signed-off-by: Ashish Kalra Reviewed-by: Tom Lendacky --- drivers/crypto/ccp/sev-dev.c | 12 +++++++++--- include/linux/psp-sev.h | 10 ++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index ed18cd113724..9709c140ab19 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1186,7 +1186,7 @@ static int snp_filter_reserved_mem_regions(struct res= ource *rs, void *arg) return 0; } =20 -static int __sev_snp_init_locked(int *error) +static int __sev_snp_init_locked(int *error, unsigned int max_snp_asid) { struct psp_device *psp =3D psp_master; struct sev_data_snp_init_ex data; @@ -1247,6 +1247,12 @@ static int __sev_snp_init_locked(int *error) } =20 memset(&data, 0, sizeof(data)); + + if (max_snp_asid) { + data.ciphertext_hiding_en =3D 1; + data.max_snp_asid =3D max_snp_asid; + } + data.init_rmp =3D 1; data.list_paddr_en =3D 1; data.list_paddr =3D __psp_pa(snp_range_list); @@ -1433,7 +1439,7 @@ static int _sev_platform_init_locked(struct sev_platf= orm_init_args *args) if (sev->sev_plat_status.state =3D=3D SEV_STATE_INIT) return 0; =20 - rc =3D __sev_snp_init_locked(&args->error); + rc =3D __sev_snp_init_locked(&args->error, args->max_snp_asid); if (rc && rc !=3D -ENODEV) return rc; =20 @@ -1516,7 +1522,7 @@ static int snp_move_to_init_state(struct sev_issue_cm= d *argp, bool *shutdown_req { int error, rc; =20 - rc =3D __sev_snp_init_locked(&error); + rc =3D __sev_snp_init_locked(&error, 0); if (rc) { argp->error =3D SEV_RET_INVALID_PLATFORM_STATE; return rc; diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index d83185b4268b..e0dbcb4b4fd9 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -748,10 +748,13 @@ struct sev_data_snp_guest_request { struct sev_data_snp_init_ex { u32 init_rmp:1; u32 list_paddr_en:1; - u32 rsvd:30; + u32 rapl_dis:1; + u32 ciphertext_hiding_en:1; + u32 rsvd:28; u32 rsvd1; u64 list_paddr; - u8 rsvd2[48]; + u16 max_snp_asid; + u8 rsvd2[46]; } __packed; =20 /** @@ -800,10 +803,13 @@ struct sev_data_snp_shutdown_ex { * @probe: True if this is being called as part of CCP module probe, which * will defer SEV_INIT/SEV_INIT_EX firmware initialization until needed * unless psp_init_on_probe module param is set + * @max_snp_asid: When non-zero, enable ciphertext hiding and specify the + * maximum ASID that can be used for an SEV-SNP guest. */ struct sev_platform_init_args { int error; bool probe; + unsigned int max_snp_asid; }; =20 /** --=20 2.34.1 From nobody Tue Oct 7 03:46:27 2025 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2068.outbound.protection.outlook.com [40.107.223.68]) (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 3FBF523AB88; Mon, 14 Jul 2025 22:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752532870; cv=fail; b=AuPUwvZLCWSdP7AP4Jy59C38iTKGtkTf/bSqnNgcEzPU6VTdWoFm89jPzitMcuwVwcmuWk6yOAE3tdLZOFALs7pODF2SrNvx0eOtffdogCUXVrnA0F1gDdrumMVJzaYHyeOT4ovrwhQsj5PLEQIyzmH13rIoLvh4z53GGC/Fruo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752532870; c=relaxed/simple; bh=k3b3Kwl4w+k8mCBNRiH/whks0Y+Q0o/aDRxhlmx/92Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cDy2WKJSt1bqBLyKTGdJo03NeUXml9BlaKE22l9dRFg4/kFYBgGrQ2i2pqgs4h6QJ8NviAsg2ely+3WsoWyacjv/wWpAISGF4lgNyEp8BR71h49QZktjZEotqFn1eoPG+3YZW2Dh3g3I15QKwpKqbSe5o1aDMwsioAK0UXM2aBQ= 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=3IasiAKm; arc=fail smtp.client-ip=40.107.223.68 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="3IasiAKm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Kiafzn67VqTT3aU+FlJZjUBUdIGZRvz8eCbUuUdacqXtUZqv63m65VkoLy0QxokGE7qgHs4/rmfHAG/G527LViyWKN3KOUVcp/NKjNAGhifiecxmkzbX1J4icYFHcIphzraaeiCwCA4KMXu6iAhUxmJkwqvsgcFbfLjTOVU4EcDml6V079AqPsdWBMrofw8GHFNlV/KnQGCc0Knf+ahbIBuzsfhpaYaeTnI5ItzxltvLhUOjo85XWd2sew+YTVnntIQqViO896MBSSDzCh/ptMmlVuulHKkl13P0OBcgpeL3Jt4Jdb1Fvo+sMhDN31qljg4cyLE1sHPEeM2u35Vr/Q== 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=pLk1Y0waLJHmC1DyGlS8nXASij51QxXm174IApykxg4=; b=GaI0POQtHAM8ymAJAxTWa0jNmWX8OA75cZzxP7DAcJr3QNCGzXbtfwvREMPTB1ULddWbLAW4VAAw4lEmy/N8GvkqIdOE25dytXykfcy/2+JCMiiR0OSKfIgFL2hZEQt5jAMmFA7DEkex848sct2PmLwGYwy+LFM0YVJdhoTAkO6RAp7B5OUK9HMJZh3oJIbQHcnfOhVrjKOJMFDTBNQyls3A71JHRGomt1aODHAOQPIHlwaBtbkoNduIK1OUCbS6BdTeGFWrrD90gM26IoyWqooIpyAO7xGea5Ao+tGKQCXh1tUp8EU9mOkqc3Vt23+7ukFEXn3o8VQPjzK7Adjg7Q== 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=pLk1Y0waLJHmC1DyGlS8nXASij51QxXm174IApykxg4=; b=3IasiAKmDortwS+oenqKNu/iBWGSsO9iiOHTWOIFjTXIYlprIVRMhCBPQQN7TI3LZ02wmn39pyMXRthpWAyR5yukt9+T8MM4ONxi7xZk5bqQeSSCkE8LcW04t8fYwpXI2nJYHSMzpowltCkTdSqHdJkhIbG/LJnCKClxDRH151k= Received: from SA1P222CA0077.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:2c1::24) by CH3PR12MB7524.namprd12.prod.outlook.com (2603:10b6:610:146::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.25; Mon, 14 Jul 2025 22:41:05 +0000 Received: from SN1PEPF0002BA4E.namprd03.prod.outlook.com (2603:10b6:806:2c1:cafe::4d) by SA1P222CA0077.outlook.office365.com (2603:10b6:806:2c1::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.32 via Frontend Transport; Mon, 14 Jul 2025 22:41: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 SN1PEPF0002BA4E.mail.protection.outlook.com (10.167.242.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Mon, 14 Jul 2025 22:41:04 +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; Mon, 14 Jul 2025 17:41:01 -0500 From: Ashish Kalra To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Subject: [PATCH v6 6/7] KVM: SEV: Introduce new min,max sev_es and sev_snp asid variables Date: Mon, 14 Jul 2025 22:40:51 +0000 Message-ID: <7f36b17d23fab99d101de62ed2145af88d1a7273.1752531191.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: SN1PEPF0002BA4E:EE_|CH3PR12MB7524:EE_ X-MS-Office365-Filtering-Correlation-Id: 917c421d-0fa0-42d1-007c-08ddc3278420 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|36860700013|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?iTU3peXxOhix/7vGR0JK0Z3iLU6XPNo3KZ4QSHFaPNrZFr/J1NccwmKNLtfK?= =?us-ascii?Q?km2b8Rarn3x6RWaEPsy8MVuVLZmfOk2d+UR2tqaTFcEv11VOavkDjcf5Ytj7?= =?us-ascii?Q?b1AvLgROgrrI9FDYMK9QNcW05zwMGW6IiJfAbsSLzC6IBawreQ4wb60NwUuD?= =?us-ascii?Q?QduQg87F/vFYsWbBt3XPZlweN6YXMLDwcRXIIYe4eYi1SinFMqxeorTHckxG?= =?us-ascii?Q?V5QDAvG+0hbyHFTJFEuFPe9k8XWPVHDSkASnlxLTggg9hKd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C4OALrPWurm6d0e2logz29EIGr9SLdlXzxclgm84cS4TpYSXD1uN0s?= =?us-ascii?Q?oiFa/TONC6U08VHp9uQdtLi6O29txilZIW+xb22WWWgE98yui0rl/a/zIlI/?= =?us-ascii?Q?IbVmo26gnUvD9rgXEKUFiaqO0UItyx7g+9qIwyMpMaM91K942GO8Y10GDWr1?= =?us-ascii?Q?OIO4Dh5BPwV05N0fP2d1NhBMyGKNafOX2AXYZl2zdEm4FT7Hd738eqZndjOn?= =?us-ascii?Q?/n8LeMwCFFzHvTxQ0Iw0+2iiOSI8UjIUiAO6KKtxxcYRgnbi2IyCa2ZQyHXe?= =?us-ascii?Q?y99MMagXh4A7ItHcBRTnH8HrgDDKe7t7lLp/gQzWg2xMHdteI5Qd+zqlkrOe?= =?us-ascii?Q?2+D5G+g3meIW4cKo/WS4jAhxqf3DvH0VTolhdAz22UY1WD/WMLZoi+1Jfw?= =?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)(82310400026)(7416014)(376014)(36860700013)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2025 22:41:04.3669 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 917c421d-0fa0-42d1-007c-08ddc3278420 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: SN1PEPF0002BA4E.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7524 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Introduce new min, max sev_es_asid and sev_snp_asid variables. The new {min,max}_{sev_es,snp}_asid variables along with existing {min,max}_sev_asid variable simplifies partitioning of the SEV and SEV-ES+ ASID space. Suggested-by: Sean Christopherson Reviewed-by: Tom Lendacky Signed-off-by: Ashish Kalra --- arch/x86/kvm/svm/sev.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 95668e84ab86..77f7c103134e 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -85,6 +85,10 @@ static DECLARE_RWSEM(sev_deactivate_lock); static DEFINE_MUTEX(sev_bitmap_lock); unsigned int max_sev_asid; static unsigned int min_sev_asid; +static unsigned int max_sev_es_asid; +static unsigned int min_sev_es_asid; +static unsigned int max_snp_asid; +static unsigned int min_snp_asid; static unsigned long sev_me_mask; static unsigned int nr_asids; static unsigned long *sev_asid_bitmap; @@ -173,20 +177,31 @@ static void sev_misc_cg_uncharge(struct kvm_sev_info = *sev) misc_cg_uncharge(type, sev->misc_cg, 1); } =20 -static int sev_asid_new(struct kvm_sev_info *sev) +static int sev_asid_new(struct kvm_sev_info *sev, unsigned long vm_type) { /* * SEV-enabled guests must use asid from min_sev_asid to max_sev_asid. * SEV-ES-enabled guest can use from 1 to min_sev_asid - 1. - * Note: min ASID can end up larger than the max if basic SEV support is - * effectively disabled by disallowing use of ASIDs for SEV guests. */ - unsigned int min_asid =3D sev->es_active ? 1 : min_sev_asid; - unsigned int max_asid =3D sev->es_active ? min_sev_asid - 1 : max_sev_asi= d; - unsigned int asid; + unsigned int min_asid, max_asid, asid; bool retry =3D true; int ret; =20 + if (vm_type =3D=3D KVM_X86_SNP_VM) { + min_asid =3D min_snp_asid; + max_asid =3D max_snp_asid; + } else if (sev->es_active) { + min_asid =3D min_sev_es_asid; + max_asid =3D max_sev_es_asid; + } else { + min_asid =3D min_sev_asid; + max_asid =3D max_sev_asid; + } + + /* + * The min ASID can end up larger than the max if basic SEV support is + * effectively disabled by disallowing use of ASIDs for SEV guests. + */ if (min_asid > max_asid) return -ENOTTY; =20 @@ -440,7 +455,7 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm= _sev_cmd *argp, if (vm_type =3D=3D KVM_X86_SNP_VM) sev->vmsa_features |=3D SVM_SEV_FEAT_SNP_ACTIVE; =20 - ret =3D sev_asid_new(sev); + ret =3D sev_asid_new(sev, vm_type); if (ret) goto e_no_asid; =20 @@ -3021,6 +3036,9 @@ void __init sev_hardware_setup(void) if (min_sev_asid =3D=3D 1) goto out; =20 + min_sev_es_asid =3D min_snp_asid =3D 1; + max_sev_es_asid =3D max_snp_asid =3D min_sev_asid - 1; + sev_es_asid_count =3D min_sev_asid - 1; WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_SEV_ES, sev_es_asid_count)); sev_es_supported =3D true; @@ -3044,11 +3062,11 @@ void __init sev_hardware_setup(void) if (boot_cpu_has(X86_FEATURE_SEV_ES)) pr_info("SEV-ES %s (ASIDs %u - %u)\n", str_enabled_disabled(sev_es_supported), - min_sev_asid > 1 ? 1 : 0, min_sev_asid - 1); + min_sev_es_asid, max_sev_es_asid); if (boot_cpu_has(X86_FEATURE_SEV_SNP)) pr_info("SEV-SNP %s (ASIDs %u - %u)\n", str_enabled_disabled(sev_snp_supported), - min_sev_asid > 1 ? 1 : 0, min_sev_asid - 1); + min_snp_asid, max_snp_asid); =20 sev_enabled =3D sev_supported; sev_es_enabled =3D sev_es_supported; --=20 2.34.1 From nobody Tue Oct 7 03:46:27 2025 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2082.outbound.protection.outlook.com [40.107.95.82]) (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 D834523AB88; Mon, 14 Jul 2025 22:41:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752532886; cv=fail; b=RqdMkvR/Cz2Wxe7jMUHcUnskbpZs4wOYBUTRZUb803c5Wkft4CILVi4V9tfHy8TuiWBv7yNDsBix6CTl+olawziGpSHZ5HNhriqSA/pb8oDuc/72tgO0AENu6ytAjHAbmcbo7NnAfVyxWUS9akOqmJRytt1bLepxSVv8hL9IkhQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752532886; c=relaxed/simple; bh=NyAYI3qjl0np09laPyxW1YlwippYa2OOYUeEBkClB0Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tuWNRXV4wEmduJHOgdmAO1AIAv6ocrkcALcFj51OTS8XcpynQb0JxLlq5u98sNvO+t/JwfdHbu0SEcxeDmmbf/0efUQjsTMxjzbp019e3KTXWSOX7B1higB83ZcmoqvJDjOPWbScmHRxELGCa/GdGbHKwarEiJuOT39N2lUOE8c= 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=yKZ/t+H5; arc=fail smtp.client-ip=40.107.95.82 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="yKZ/t+H5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=V+K8kQYA2fuwhrUOKgbuJo9zYoTNS9/bePElQDo9plURJZJsTbWce4muYW+bKe1vZbi6bEonWibbAz4XVumDmdP2Uilzsn3oSY1hIjHuS5D7xOoFNTVFgVYV/mVov5MwrsnRbNZug52A58FQDma0lZOkz7vOARfq9vM6Awso5jOhG6XbrNq1W1VdLio4L/BYSpBwnbdZVBr29gTd+xSh798DK/Mdrjw5f39js7T5i6tZbp2wmHIFTs+AUCQEdASpUeqvZdtAClfyFjB4ZqiEOSQa2ECqrrRpZ2665bwtOC0YczCxurLBjLtbY4UrkhDZoXOKIJkUR50tB2JFeqUSxQ== 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=eUQl+Oru6hsFYf5JeVi++pjrywDP0IuX7BWDiSoedAU=; b=Tvf8EcSSE3pwNLazKBYS6X3BUz9YqWOkINAEYdbTglK8A2UlLM6Cm480g9Xe9bHZZWnyjh+Eca/QmtQvBQena9AEMF4SEulu0Q4rTbNHKbkuwFjpkMGNsZhb9dlQo246LpMkhcMqDOO5BN3/M+sfBN3fVHisB4aq04AsupdCe1TOjGjFhhsbFqeqQC1YVLvHXO3LpfXZjuf1g0jLR8YcJJ+Dqv5LZfnB/6++T5yhin2Lcb7iwHQA6ccpRG8b51YBAiCPjyGA/PPiwMKK9OwAgVkf7HwJhsxf16GTA+NDXwGW0oSZxuL3TGST+ibo1Mjd7nO3RQT2RS9et2bMrX26Jg== 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=eUQl+Oru6hsFYf5JeVi++pjrywDP0IuX7BWDiSoedAU=; b=yKZ/t+H5SrngAfzm3EerKxt+sOTWItvZflpyuoFCNkkcDIRdmSkHeg/wN3lhFY8nNOt23gYM7U+g97WA5pDFn3dnHcFOf3m2ZZrz7D3MF42wHF8oTD3INR3evhb1EXhIbNiSTc8tMH5PnAlkCdMGrr4dgoQ3gJ+qQKWS+kkcixA= Received: from SN7PR04CA0219.namprd04.prod.outlook.com (2603:10b6:806:127::14) by SA1PR12MB9516.namprd12.prod.outlook.com (2603:10b6:806:45b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.35; Mon, 14 Jul 2025 22:41:21 +0000 Received: from SN1PEPF0002BA50.namprd03.prod.outlook.com (2603:10b6:806:127:cafe::43) by SN7PR04CA0219.outlook.office365.com (2603:10b6:806:127::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.33 via Frontend Transport; Mon, 14 Jul 2025 22:41:21 +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 SN1PEPF0002BA50.mail.protection.outlook.com (10.167.242.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Mon, 14 Jul 2025 22:41:20 +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; Mon, 14 Jul 2025 17:41:18 -0500 From: Ashish Kalra To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Subject: [PATCH v6 7/7] KVM: SEV: Add SEV-SNP CipherTextHiding support Date: Mon, 14 Jul 2025 22:41:08 +0000 Message-ID: <1b60078dabee495d789fee68b01e8433b4791c69.1752531191.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: SN1PEPF0002BA50:EE_|SA1PR12MB9516:EE_ X-MS-Office365-Filtering-Correlation-Id: 2dc4baec-db23-44d6-794c-08ddc3278e05 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|7416014|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?vcV+PrDsvkMz0Tiem71sAfjNuUmnUDd3oV61Jk1z9IH0vM9H1Ebg58EKgjLA?= =?us-ascii?Q?Bm9/WKoTGVrw+K1hVdzL/VgXy5P68H5zdGIN5uhGMuxBG7Owsh0wHqV9La3b?= =?us-ascii?Q?Y4aj573lgt7YIrh8AFndsl+tQSVcghtZ5ipsmUVjm1jxPwwyBsqyl2YgHG5i?= =?us-ascii?Q?Qh7NRqYnknKiay4AIxNnDgaEZc7dvVEA79/4tYuUTn/KM1bbCYiEKx5+aQVQ?= =?us-ascii?Q?ib33kuAqSkSrZ5EA7C5rxBby1AQRLKBvMRRXHYypnB1sHNs/TuAH20KuhrBP?= =?us-ascii?Q?+GJ7n1wxUbmybKomiPhQRpE8Dx6R0+x0SKG16Tk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ZItZQa+a6mywhKcAKSjoAh/Dpcx3XJqgLJC3Wy5NIaqoCyJXTD84mE/fn?= =?us-ascii?Q?ugJks8TnW8K0DG6SmhVrxVR3hpKYti7SyIbvb/GAb3j7HFlRMe6m4egg/6ae?= =?us-ascii?Q?DnXOWB+7qv4vQjddEgjjI/IGDYjuislxqm+C4rqf9vCljG8v+NFaxHdu8cUH?= =?us-ascii?Q?kcT0f1rBvnxoiRsqdBQhEz43teM76QMaAb0Ou/lZxl+K/4pE7bGV89Af5keN?= =?us-ascii?Q?Kf9c0d2+DoVhgXk+ZZdcbB6OVLDgD8j11bfjLYkr0nOP87oGGqGjn/0BO3xC?= =?us-ascii?Q?Ge9VOxhyWA8SbqOJwDxOwrA7d+l9GLDV5EKjYlSm/wk/c0Il6bhpVUtjNA?= =?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)(36860700013)(376014)(7416014)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2025 22:41:20.9674 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2dc4baec-db23-44d6-794c-08ddc3278e05 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: SN1PEPF0002BA50.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB9516 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Ciphertext hiding prevents host accesses from reading the ciphertext of SNP guest private memory. Instead of reading ciphertext, the host reads will see constant default values (0xff). The SEV ASID space is split into SEV and SEV-ES/SEV-SNP ASID ranges. Enabling ciphertext hiding further splits the SEV-ES/SEV-SNP ASID space into separate ASID ranges for SEV-ES and SEV-SNP guests. Add new module parameter to the KVM module to enable ciphertext hiding support and a user configurable system-wide maximum SNP ASID value. If the module parameter value is "max" then the complete SEV-ES/SEV-SNP ASID space is allocated to SEV-SNP guests. Suggested-by: Sean Christopherson Signed-off-by: Ashish Kalra Reviewed-by: Tom Lendacky --- .../admin-guide/kernel-parameters.txt | 18 ++++++ arch/x86/kvm/svm/sev.c | 61 ++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 6305257de698..de086bfd7e27 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2942,6 +2942,24 @@ (enabled). Disable by KVM if hardware lacks support for NPT. =20 + kvm-amd.ciphertext_hiding_asids=3D + [KVM,AMD] Ciphertext hiding prevents host accesses from reading + the ciphertext of SNP guest private memory. Instead of reading + ciphertext, the host will see constant default values (0xff). + The SEV ASID space is split into SEV and joint SEV-ES and SEV-SNP + ASID space. Ciphertext hiding further partitions the joint + SEV-ES/SEV-SNP ASID space into separate SEV-ES and SEV-SNP ASID + ranges with the SEV-SNP ASID range starting at 1. For SEV-ES/ + SEV-SNP guests the maximum ASID available is MIN_SEV_ASID - 1 + where MIN_SEV_ASID value is discovered by CPUID Fn8000_001F[EDX]. + + Format: { | "max" } + A non-zero value enables SEV-SNP ciphertext hiding feature and sets + the ASID range available for SEV-SNP guests. + A Value of "max" assigns all ASIDs available in the joint SEV-ES + and SEV-SNP ASID range to SNP guests, effectively disabling + SEV-ES. + kvm-arm.mode=3D [KVM,ARM,EARLY] Select one of KVM/arm64's modes of operation. diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 77f7c103134e..b795ec988025 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -59,6 +59,11 @@ static bool sev_es_debug_swap_enabled =3D true; module_param_named(debug_swap, sev_es_debug_swap_enabled, bool, 0444); static u64 sev_supported_vmsa_features; =20 +static char ciphertext_hiding_asids[16]; +module_param_string(ciphertext_hiding_asids, ciphertext_hiding_asids, + sizeof(ciphertext_hiding_asids), 0444); +MODULE_PARM_DESC(ciphertext_hiding_asids, " Enable ciphertext hiding for = SEV-SNP guests and specify the number of ASIDs to use ('max' to utilize all= available SEV-SNP ASIDs"); + #define AP_RESET_HOLD_NONE 0 #define AP_RESET_HOLD_NAE_EVENT 1 #define AP_RESET_HOLD_MSR_PROTO 2 @@ -201,6 +206,9 @@ static int sev_asid_new(struct kvm_sev_info *sev, unsig= ned long vm_type) /* * The min ASID can end up larger than the max if basic SEV support is * effectively disabled by disallowing use of ASIDs for SEV guests. + * Similarly for SEV-ES guests the min ASID can end up larger than the + * max when ciphertext hiding is enabled, effectively disabling SEV-ES + * support. */ if (min_asid > max_asid) return -ENOTTY; @@ -2258,6 +2266,7 @@ static int sev_gmem_post_populate(struct kvm *kvm, gf= n_t gfn_start, kvm_pfn_t pf ret =3D -EFAULT; goto err; } + kunmap_local(vaddr); } =20 @@ -2938,10 +2947,48 @@ static bool is_sev_snp_initialized(void) return initialized; } =20 +static bool check_and_enable_sev_snp_ciphertext_hiding(void) +{ + unsigned int ciphertext_hiding_asid_nr =3D 0; + + if (!sev_is_snp_ciphertext_hiding_supported()) { + pr_warn("Module parameter ciphertext_hiding_asids specified but cipherte= xt hiding not supported\n"); + return false; + } + + if (isdigit(ciphertext_hiding_asids[0])) { + if (kstrtoint(ciphertext_hiding_asids, 10, &ciphertext_hiding_asid_nr)) + goto invalid_parameter; + + /* Do sanity check on user-defined ciphertext_hiding_asids */ + if (ciphertext_hiding_asid_nr >=3D min_sev_asid) { + pr_warn("Module parameter ciphertext_hiding_asids (%u) exceeds or equal= s minimum SEV ASID (%u)\n", + ciphertext_hiding_asid_nr, min_sev_asid); + return false; + } + } else if (!strcmp(ciphertext_hiding_asids, "max")) { + ciphertext_hiding_asid_nr =3D min_sev_asid - 1; + } + + if (ciphertext_hiding_asid_nr) { + max_snp_asid =3D ciphertext_hiding_asid_nr; + min_sev_es_asid =3D max_snp_asid + 1; + pr_info("SEV-SNP ciphertext hiding enabled\n"); + + return true; + } + +invalid_parameter: + pr_warn("Module parameter ciphertext_hiding_asids (%s) invalid\n", + ciphertext_hiding_asids); + return false; +} + 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 =3D {0}; + bool snp_ciphertext_hiding_enabled =3D false; bool sev_snp_supported =3D false; bool sev_es_supported =3D false; bool sev_supported =3D false; @@ -3039,6 +3086,14 @@ void __init sev_hardware_setup(void) min_sev_es_asid =3D min_snp_asid =3D 1; max_sev_es_asid =3D max_snp_asid =3D min_sev_asid - 1; =20 + /* + * The ciphertext hiding feature partitions the joint SEV-ES/SEV-SNP + * ASID range into separate SEV-ES and SEV-SNP ASID ranges with + * the SEV-SNP ASID starting at 1. + */ + if (ciphertext_hiding_asids[0]) + snp_ciphertext_hiding_enabled =3D check_and_enable_sev_snp_ciphertext_hi= ding(); + sev_es_asid_count =3D min_sev_asid - 1; WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_SEV_ES, sev_es_asid_count)); sev_es_supported =3D true; @@ -3047,6 +3102,8 @@ void __init sev_hardware_setup(void) out: if (sev_enabled) { init_args.probe =3D true; + if (snp_ciphertext_hiding_enabled) + init_args.max_snp_asid =3D max_snp_asid; if (sev_platform_init(&init_args)) sev_supported =3D sev_es_supported =3D sev_snp_supported =3D false; else if (sev_snp_supported) @@ -3061,7 +3118,9 @@ void __init sev_hardware_setup(void) min_sev_asid, max_sev_asid); if (boot_cpu_has(X86_FEATURE_SEV_ES)) pr_info("SEV-ES %s (ASIDs %u - %u)\n", - str_enabled_disabled(sev_es_supported), + sev_es_supported ? min_sev_es_asid <=3D max_sev_es_asid ? "enabled" : + "unusable" : + "disabled", min_sev_es_asid, max_sev_es_asid); if (boot_cpu_has(X86_FEATURE_SEV_SNP)) pr_info("SEV-SNP %s (ASIDs %u - %u)\n", --=20 2.34.1