From nobody Sat May 18 05:34:49 2024 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2068.outbound.protection.outlook.com [40.107.96.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 18BD316130D for ; Wed, 24 Apr 2024 15:58:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974318; cv=fail; b=ghsvat8GLkpUtm/Jz34A47SZbOYnmq+5VHclwPliYT8EDLEmFrLa4607pxBV5XzkS8HY1WM1RAyQl5sUwKOar5n3BUDx7BVI+JQ+0A+fVEJTC/+ooPuzqwA2pOXvQD8gk3x0km0xK8SQL+J2rz/MZkvTtQNYFA3O845gEvxBUqg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974318; c=relaxed/simple; bh=IoPkAJCI+2qNOgE4ZNvBFMwjvGyVKF04WO2eSNkc3xM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j6/eicrp2kWYPXnHCdZmAMnXFr9X5KrIh0y1Z3me7e6ctu+zXi7r97TBt1sQCumK5ka83UzABqBXHLuBW0Gv+NZ+RSWCSIj8B4RmuPLDRKeNGd3tb68dy2siYHYwELgNzevYGtzoCre/CMSNYo79X+GfLkU7WE++jr2XUv7v0/I= 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=hY4JBgVW; arc=fail smtp.client-ip=40.107.96.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="hY4JBgVW" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ogv5Sm7TBIo1DZaOKiEnUDt+m7imYr18/4qYcHLI2E4vSi/39+8+MsrABjD0wtuX9Jpz5YwpR+vEQ4oqxrOK7uXdt5bX8HWnghZfEVprqm6Kw5HQEizTGJ34VfH/53RAL1qEGBMsXMql9m9jXzEiVVaBQtd2gYtNYaGa9QLFCsOX/9eJ8kY9uwRdirlrDQ884GETJeIAMCLLhc2tCWgIhjwIHmYtmM0JM13PhImUhPAAFfqezQVfAMN6VGPLQ0W7TtetYB4RgLNMTd8yarrutllu7s6SDfH6QI0m2mgriDdFlHHFZ+JHd2oBYD8tujy1WjO98KH++91y3+sTUUTPzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=/fvoIpw98EGryWgKZZYrMRJWz18TwCVHQc7OK/87QBM=; b=nP4MOd4va4kyQft+EyLoJMXS9qwQf15vBFs2Pp+wHkkxMNKqSBfA0DeQW7X6cq4t8oT2o9J56/R0rnXaaXmqHZ+EnuxPRPNE9Xz482/m8O4ZpDVglHRFfWrkqulR06O/iLGsC6wcFs5yZRKDndhjzb+EGYCzS5xhwM2ePP49KqBgBcR2KIu4BPXsUDUOQunAya7oKzCgW+Omdkd6+LISmblh3BukypNwANgrYq4hzT+VNMZq4ZFWe+tKjGpP+tRKEuu9mxRq0Ib9AdDTXn4qVnem9ZvE05ZpF6Oa2CWoMxnxwj39BTYoRPqaVlEcWL+OQBuwLAGNIH0zwlOavRQiew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=/fvoIpw98EGryWgKZZYrMRJWz18TwCVHQc7OK/87QBM=; b=hY4JBgVWQ16yKsutxpLix2aTc/R+6xn27ZOoGZLzdQjVEEsTdXQGI6vDKkEKEBJi1Gl6nbhD4YWLWpJDaLxTWwxk4OFEPh/b3E9RymlFxrN5pbV3L19fYYnSgRsuw7ZNoU+4GNbggFKp6IlU3iqPKqne4Jrxyk57sXIA1XU/ro4= Received: from PH7PR17CA0002.namprd17.prod.outlook.com (2603:10b6:510:324::22) by MN0PR12MB6223.namprd12.prod.outlook.com (2603:10b6:208:3c1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.23; Wed, 24 Apr 2024 15:58:33 +0000 Received: from CY4PEPF0000EE31.namprd05.prod.outlook.com (2603:10b6:510:324:cafe::f1) by PH7PR17CA0002.outlook.office365.com (2603:10b6:510:324::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22 via Frontend Transport; Wed, 24 Apr 2024 15:58:33 +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 CY4PEPF0000EE31.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:58:33 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 10:58:32 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 01/15] x86/sev: Shorten snp_secrets_page_layout to snp_secrets_page Date: Wed, 24 Apr 2024 10:57:57 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE31:EE_|MN0PR12MB6223:EE_ X-MS-Office365-Filtering-Correlation-Id: a95481e7-91a6-47de-fc9e-08dc647764d6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|376005|82310400014|36860700004; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Fcsi80JUm0GQamSUSBr/BS2m5dwj4/pJBKT4b7VkdBF63kOZD4o7QkTjryc5?= =?us-ascii?Q?aNMECxOHMJrtcBUUV7q4zBQEtpDIq9Du6k5WXxt4N4Kj300vvFR507Ga+jwo?= =?us-ascii?Q?CjqQQS+jUgQlfjgRS8jdLvWKIDwYWSbcDNNEGfW8Eql6ZkZMxXJO5OuwFRM0?= =?us-ascii?Q?8hoFa/7+zu3ct1dZXBUZDW+qoJcfTRRXwyMwwQxZGzW+fbymJZysTvblKbRd?= =?us-ascii?Q?mU6ZT+GOIoLB1F0XGWPXibXfcc1UjKrV/XniPNn5FKZKS9QngEQGN3y0jugo?= =?us-ascii?Q?x5zqTNXjiKkFi8c6u/HyB/jQGLSKz1rnPZbl3MVZN1WmN1AchYXVdE4No3NH?= =?us-ascii?Q?RWrX90U8NAt+g4qe5bFnBrSgAwixOJPVh/qDOjTawnGghZQXuXOHfzzgJN87?= =?us-ascii?Q?FxoGfM1C9RPORe2elOUMQaRvHjkIOjVks5HWKLJfeD6FJHg4fVRDW7euZ6dq?= =?us-ascii?Q?KzxuK5wZINBcWhVEC6TaDY/jBUvGIFSKMXUP2I16R3NVf8IX/ESNVN87l3Ox?= =?us-ascii?Q?ltTJkqF3zw/miXi04ImEcO2wxG9jah39DjjULTMkMFiCK6IVWzaQRMGj73dA?= =?us-ascii?Q?9jyYS8fQv/tW1JrmO8/AhsPL2KMSrOdgWFi/Wb+U5ElHW1OhsrqFcfuY9Ktz?= =?us-ascii?Q?HN9fYe1zzSXFRgHqvSYro3LB8hIZEg5BXw5X9RwLPVUwzh57vTS0BOixL6t+?= =?us-ascii?Q?d7sciFyhVkkOnzwh8sXtQBRZO/N2rk3aXs+0Z/h7G58kfqRVfoHpNd9MIHvb?= =?us-ascii?Q?wFblGG1bwin8+jMK0z0rUkEURXGvlWEy7nCjB3u8M2NVMRA3uO137drI+uvR?= =?us-ascii?Q?rIqGn4WWrWvMaOnSRc63umUC0K/Zi6LvfQhoMrnPb+GK+R1X2kR++5tCizn0?= =?us-ascii?Q?REWwKG0I1usyD4aGOlsHdh72KfvTCnYEIWnwxmQE7ZLoPLf7lGSMhLryB09l?= =?us-ascii?Q?WYGp+NaDecZ/gZxx7TB8AYgO1F3vppneEOkaA4TC83SM06M551wO8YuYqPw7?= =?us-ascii?Q?vN23JCrgs9lQeF63TYqpkdTKBvcie60cWLDZBvB+itWA4kAE5/pv1q6RT7kN?= =?us-ascii?Q?SnXZDulYOFxGdu/dM+7UoQMr9f9GNiiQULgr1Q3PnVVl6lv24SaldFLz9znN?= =?us-ascii?Q?uDi8sRZk9Qi4bzX5qe0XOeDb0ilxnXcaebxdq87gR6Ukj/nPppuTr+YJ2muo?= =?us-ascii?Q?fgGLhf4+a3tbUluMugF8uzFxmsNhVATGFs1IgD9zD8ZH4/IJeCHIDw1J/LtR?= =?us-ascii?Q?pC30JdADc9m7XYcdFYanfF+rUsnBbIAIVXyYj3N5A4hWFWCuWGLMohUESjc3?= =?us-ascii?Q?AA4zTdc7dFFRQtcBZG7h72R1GzJxBcdDEn9xRFzXTsnO3w/1oU7+nm3SJiD6?= =?us-ascii?Q?pTGnZ2hCEqMJ3FFAd5FInzp/LLU7?= 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:(13230031)(7416005)(1800799015)(376005)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:58:33.3990 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a95481e7-91a6-47de-fc9e-08dc647764d6 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: CY4PEPF0000EE31.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6223 Content-Type: text/plain; charset="utf-8" Ending a struct name with "layout" is a little redundant, so shorten the snp_secrets_page_layout name to just snp_secrets_page. No functional change. Signed-off-by: Tom Lendacky Tested-by: Joerg Roedel --- arch/x86/include/asm/sev.h | 2 +- arch/x86/kernel/sev.c | 4 ++-- drivers/virt/coco/sev-guest/sev-guest.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 7f57382afee4..48bc397db649 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -140,7 +140,7 @@ struct secrets_os_area { #define VMPCK_KEY_LEN 32 =20 /* See the SNP spec version 0.9 for secrets page format */ -struct snp_secrets_page_layout { +struct snp_secrets_page { u32 version; u32 imien : 1, rsvd1 : 31; diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 995f94467101..6949fbccec40 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -648,7 +648,7 @@ static u64 __init get_secrets_page(void) =20 static u64 __init get_snp_jump_table_addr(void) { - struct snp_secrets_page_layout *layout; + struct snp_secrets_page *layout; void __iomem *mem; u64 pa, addr; =20 @@ -662,7 +662,7 @@ static u64 __init get_snp_jump_table_addr(void) return 0; } =20 - layout =3D (__force struct snp_secrets_page_layout *)mem; + layout =3D (__force struct snp_secrets_page *)mem; =20 addr =3D layout->os_area.ap_jump_table_pa; iounmap(mem); diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/se= v-guest/sev-guest.c index 87f241825bc3..04a7bd1e4314 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -59,7 +59,7 @@ struct snp_guest_dev { */ struct snp_guest_msg secret_request, secret_response; =20 - struct snp_secrets_page_layout *layout; + struct snp_secrets_page *layout; struct snp_req_data input; union { struct snp_report_req report; @@ -743,7 +743,7 @@ static const struct file_operations snp_guest_fops =3D { .unlocked_ioctl =3D snp_guest_ioctl, }; =20 -static u8 *get_vmpck(int id, struct snp_secrets_page_layout *layout, u32 *= *seqno) +static u8 *get_vmpck(int id, struct snp_secrets_page *layout, u32 **seqno) { u8 *key =3D NULL; =20 @@ -897,8 +897,8 @@ static void unregister_sev_tsm(void *data) =20 static int __init sev_guest_probe(struct platform_device *pdev) { - struct snp_secrets_page_layout *layout; struct sev_guest_platform_data *data; + struct snp_secrets_page *layout; struct device *dev =3D &pdev->dev; struct snp_guest_dev *snp_dev; struct miscdevice *misc; --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2046.outbound.protection.outlook.com [40.107.236.46]) (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 4301A1607A2 for ; Wed, 24 Apr 2024 15:58:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974327; cv=fail; b=Mbm/41DZOlpi7wCUVEDxNpTiM4OZwxaTgqRixIh/z6vY+Zr6iovPSgH6jOXVXZTiAwjocSJw4sqiDLMHrY3M5msje2eRVtnGU0u0wLZZ6yp5ZvZe1/P/hEeO2LWD1Hi3bc8XYDFni6YjgplEcwNuwoLEss9qFhbP9ikNRQzPJI4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974327; c=relaxed/simple; bh=hGY0aZ2pkvJy0ri57i/f7i49Ef7mViQiA4B9s/3dkZM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Z6r2kgnya6F8/OhZcBcq0qB/uF1/AqZivcZLph5M0c28VSwT9zxCEy03ZiSk2/6+bm/QXZxCk4BcurESMulbi36MlEqkKda4vvaGto2AFuWrfcdLcFTjU0HCLiVLVfiuaZYR5vXMtxZXEo/Som1w7e4l9/rybzptHbSlMvr1irY= 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=umVpiWhr; arc=fail smtp.client-ip=40.107.236.46 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="umVpiWhr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d9Tjpi7fcvlURIg69BAMZzt0Q4AWeuQeHV/c5LRSZs1km0s+ZqncOkXrsuUfAgQ696qaWiwzscfvl1PiOnpHgnX1t7gBwJmG3rtfOWToRNDTV6OY6r6zX0y+yuCazPDjIO9eVYMUolptIxbhe/KMFyTTq/KNohyFi9hxxusdnJgcHmVyWl8qsp6gACcuH2FVhkTw6tLxaM2u4rOeLXD5Ee89a7mLm7/JCNy20CQcs38UZrcyft4Dibf2jnw6Tbc/CWE7qEQZA2Vkvug3cYy97pa+FZ001b0ThSV1EGKZ6wpacGyX6/LvyegFphM0mtjbEMhpxGsScerTJnwNM7C+4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=15ew4f9ZgZLu4/xHtI+LHBBQOnr2HhxMiiEK/WZoX5s=; b=eV8+w/NSvT3wOUwD1dzegW7hv6oBKv6st+oIidzwS8L430UPt1Gu/7UqMpUe2KWl8eDzwzz231TjYR7yOEMCLaLupRIWJyZizZwoMmXy3RKi4LuYwJsXExNyBss8EIJUR0C2FRJTIQtlZC7aEVGsXNHihWXARnBibhAfW7Nq6Wt+5R7o2LmBEH/xhvUuaVCQVBUgqhY5mP/HXbK96cpei8vhbQ/6HVJWytQniNNFhjl5WsqQAAIVUMI7x5iQhylnvL1Blkm3rfl9MmqBTAGP+2a95DlMaX8z1qk7SNm1wiYpvSIOFhybnlfq3HZNeeogkMurrjOccNI+ViP/eEPSrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=15ew4f9ZgZLu4/xHtI+LHBBQOnr2HhxMiiEK/WZoX5s=; b=umVpiWhr/DYllRDBrFIb0VsItuVNbsLGz3RbM3/F+AH/aGhbabAY2b45dG1Z3UX8ZYPFqo9/TOiGxv2Pafmfbhy1RiQvo7xKOw85TtjCfxSbmrZyWi5VQiK8vBcoxMOlVZv7nXWWwu/PL0bY5sQaJbaPfOSvYMEUL3B0evHqGsA= Received: from PH7PR17CA0021.namprd17.prod.outlook.com (2603:10b6:510:324::27) by MW4PR12MB7482.namprd12.prod.outlook.com (2603:10b6:303:212::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.24; Wed, 24 Apr 2024 15:58:43 +0000 Received: from CY4PEPF0000EE31.namprd05.prod.outlook.com (2603:10b6:510:324:cafe::82) by PH7PR17CA0021.outlook.office365.com (2603:10b6:510:324::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.23 via Frontend Transport; Wed, 24 Apr 2024 15:58:43 +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 CY4PEPF0000EE31.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:58:42 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 10:58:39 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 02/15] x86/sev: Rename snp_init() in the boot/compressed/sev.c file Date: Wed, 24 Apr 2024 10:57:58 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE31:EE_|MW4PR12MB7482:EE_ X-MS-Office365-Filtering-Correlation-Id: 79c73520-3685-40f2-9a19-08dc64776a66 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|82310400014|36860700004|7416005|1800799015; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Orpz8IxLAX9h6TLjK26euNOyQAe+4/vOXQ6Vvp2bu3s2jdp4I8t7OJo9ho4m?= =?us-ascii?Q?PCvG7I+q2XK2vxGxVnOwbmDn34ICF+IGhLwVmQnS4EVN5kIUojbjRH4ShgG9?= =?us-ascii?Q?1FKQVZ2lVS55Sash1EvNfufTM/WUSnUZ8zNKB+zVBjUMrQ/kwD+cB+dtK2rN?= =?us-ascii?Q?YYqU1letawhnljdraicrayMXzjJgbKG9OHzDSbPHTyd9QvPd3aycjCx6cqAV?= =?us-ascii?Q?knOhWK2etrCsgg5vJLYP7pu5KbXJR6DwLOA7qkpuu0OHhsPUOUR6wc2Ie8mo?= =?us-ascii?Q?yDcCYkCUtsvRww2z/T/AfwIUXx56/jaKpIq2Jdz3t/3/ZBmE/jcR+9GD4wDJ?= =?us-ascii?Q?WHNENsRBe3Wz3eo9jILPHKFIuK6uLNGz/kOcTJkBgbz9xkVZm0DBSYBMcGJf?= =?us-ascii?Q?372SuiHAhg7mNZPMn4Ky7KGcKjy+ZbUXcANeYitNwcO6+sKY8VuEHvSJI2G/?= =?us-ascii?Q?qwVoYpVXWpS9eJpmupfVoK2vX9Hh7+eDXIMZsGR5sOlz+uhl9wBOWaMcSYRH?= =?us-ascii?Q?aMQSHVkdJT3OP4MnxdvTD6HwEfkJOVqL61J5GVKdRqESPoBP9+9tEhKg1y2E?= =?us-ascii?Q?04ckep1VCNR+BvmZQ3MDFH8Gm+fDvfK+5HBJxtGH3XUq6ibIxMX+p0nn+2JY?= =?us-ascii?Q?KZ+5Ln17D1Ez09exYjYTeUlCjUoZfBB8hIuhFJ798KNsBaYTy92bG+j7a+uV?= =?us-ascii?Q?C1M92HWk3mTDHTc4sUk3BV6oOaJUzPyilnLVmURQe7xNBCvwLjKfYeF4eRel?= =?us-ascii?Q?V5cq6JLlc9kFJ8tM0pS1CjtKtBvf7aUqf+D2dGuHTR1ix2eknggOGpLC6sDK?= =?us-ascii?Q?Tz5HFSrnHsiJLaXce90gwclI01ou0l3tUImUg0vOBsSm6UlXklfhoJAMqvFo?= =?us-ascii?Q?Kj3cOxzltnJXZ9dA/pHQRPoZalIxlXG5IkZ+5u2pqbzGoGkHgYxSLRZbwaMw?= =?us-ascii?Q?SdbvU+2CZ6BAiuitDCCsKLSxOd7T00Rt841OBZnRv7FM/cEuKXYsPjjJhVox?= =?us-ascii?Q?L6G5wRXt6wHbi/A2+JSZ2o5I1YEUVGxqcntX7ahgl2hexVRY5IPIgFUmuJIt?= =?us-ascii?Q?Emh96suppSOW7jKW43OP9e6dGtCN4B8QfqAJ52EeWIemmRQ/eWw3P2N4xzts?= =?us-ascii?Q?anuF2pXdtY4hjMwMc0pY578r/yjp29GvhiWlqaBFObpWZYWl2+ff26mEutLg?= =?us-ascii?Q?+aZJW59cCjDw5tXcjzyfADEQA1d60raUFjcDlIouhIRnblulYxwbnERkojba?= =?us-ascii?Q?vvKsAi9CeI8COUAkZUMBObF4GerRboTu34WZscOheMPUyM3Lkj7LfEnwGuip?= =?us-ascii?Q?zrIRRfU90PVZra6Aonbns9kvh//vWX7+NaDy9KHpHzQIZM0R2feY4OOJk+sa?= =?us-ascii?Q?alSOgHBD+2hth4TFZeEM/H/FiFtV?= 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:(13230031)(376005)(82310400014)(36860700004)(7416005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:58:42.7314 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 79c73520-3685-40f2-9a19-08dc64776a66 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: CY4PEPF0000EE31.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7482 Content-Type: text/plain; charset="utf-8" The snp_init() function in boot/compressed/sev.c is local to that file, is not called from outside of the file and is independent of the snp_init() function in kernel/sev.c. Change the name to better differentiate when each function is used. Move the renamed snp_init() and related functions up in the file to avoid having to add a forward declaration and make the function static. No functional change. Signed-off-by: Tom Lendacky Tested-by: Joerg Roedel --- arch/x86/boot/compressed/sev.c | 162 ++++++++++++++++----------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index ec71846d28c9..5ad0ff4664f1 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -413,6 +413,85 @@ void snp_check_features(void) } } =20 +/* Search for Confidential Computing blob in the EFI config table. */ +static struct cc_blob_sev_info *find_cc_blob_efi(struct boot_params *bp) +{ + unsigned long cfg_table_pa; + unsigned int cfg_table_len; + int ret; + + ret =3D efi_get_conf_table(bp, &cfg_table_pa, &cfg_table_len); + if (ret) + return NULL; + + return (struct cc_blob_sev_info *)efi_find_vendor_table(bp, cfg_table_pa, + cfg_table_len, + EFI_CC_BLOB_GUID); +} + +/* + * Initial set up of SNP relies on information provided by the + * Confidential Computing blob, which can be passed to the boot kernel + * by firmware/bootloader in the following ways: + * + * - via an entry in the EFI config table + * - via a setup_data structure, as defined by the Linux Boot Protocol + * + * Scan for the blob in that order. + */ +static struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp) +{ + struct cc_blob_sev_info *cc_info; + + cc_info =3D find_cc_blob_efi(bp); + if (cc_info) + goto found_cc_info; + + cc_info =3D find_cc_blob_setup_data(bp); + if (!cc_info) + return NULL; + +found_cc_info: + if (cc_info->magic !=3D CC_BLOB_SEV_HDR_MAGIC) + sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); + + return cc_info; +} + +/* + * Indicate SNP based on presence of SNP-specific CC blob. Subsequent chec= ks + * will verify the SNP CPUID/MSR bits. + */ +static bool early_snp_init(struct boot_params *bp) +{ + struct cc_blob_sev_info *cc_info; + + if (!bp) + return false; + + cc_info =3D find_cc_blob(bp); + if (!cc_info) + return false; + + /* + * If a SNP-specific Confidential Computing blob is present, then + * firmware/bootloader have indicated SNP support. Verifying this + * involves CPUID checks which will be more reliable if the SNP + * CPUID table is used. See comments over snp_setup_cpuid_table() for + * more details. + */ + setup_cpuid_table(cc_info); + + /* + * Pass run-time kernel a pointer to CC info via boot_params so EFI + * config table doesn't need to be searched again during early startup + * phase. + */ + bp->cc_blob_address =3D (u32)(unsigned long)cc_info; + + return true; +} + /* * sev_check_cpu_support - Check for SEV support in the CPU capabilities * @@ -463,7 +542,7 @@ void sev_enable(struct boot_params *bp) bp->cc_blob_address =3D 0; =20 /* - * Do an initial SEV capability check before snp_init() which + * Do an initial SEV capability check before early_snp_init() which * loads the CPUID page and the same checks afterwards are done * without the hypervisor and are trustworthy. * @@ -478,7 +557,7 @@ void sev_enable(struct boot_params *bp) * Setup/preliminary detection of SNP. This will be sanity-checked * against CPUID/MSR values later. */ - snp =3D snp_init(bp); + snp =3D early_snp_init(bp); =20 /* Now repeat the checks with the SNP CPUID table. */ =20 @@ -535,85 +614,6 @@ u64 sev_get_status(void) return m.q; } =20 -/* Search for Confidential Computing blob in the EFI config table. */ -static struct cc_blob_sev_info *find_cc_blob_efi(struct boot_params *bp) -{ - unsigned long cfg_table_pa; - unsigned int cfg_table_len; - int ret; - - ret =3D efi_get_conf_table(bp, &cfg_table_pa, &cfg_table_len); - if (ret) - return NULL; - - return (struct cc_blob_sev_info *)efi_find_vendor_table(bp, cfg_table_pa, - cfg_table_len, - EFI_CC_BLOB_GUID); -} - -/* - * Initial set up of SNP relies on information provided by the - * Confidential Computing blob, which can be passed to the boot kernel - * by firmware/bootloader in the following ways: - * - * - via an entry in the EFI config table - * - via a setup_data structure, as defined by the Linux Boot Protocol - * - * Scan for the blob in that order. - */ -static struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp) -{ - struct cc_blob_sev_info *cc_info; - - cc_info =3D find_cc_blob_efi(bp); - if (cc_info) - goto found_cc_info; - - cc_info =3D find_cc_blob_setup_data(bp); - if (!cc_info) - return NULL; - -found_cc_info: - if (cc_info->magic !=3D CC_BLOB_SEV_HDR_MAGIC) - sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); - - return cc_info; -} - -/* - * Indicate SNP based on presence of SNP-specific CC blob. Subsequent chec= ks - * will verify the SNP CPUID/MSR bits. - */ -bool snp_init(struct boot_params *bp) -{ - struct cc_blob_sev_info *cc_info; - - if (!bp) - return false; - - cc_info =3D find_cc_blob(bp); - if (!cc_info) - return false; - - /* - * If a SNP-specific Confidential Computing blob is present, then - * firmware/bootloader have indicated SNP support. Verifying this - * involves CPUID checks which will be more reliable if the SNP - * CPUID table is used. See comments over snp_setup_cpuid_table() for - * more details. - */ - setup_cpuid_table(cc_info); - - /* - * Pass run-time kernel a pointer to CC info via boot_params so EFI - * config table doesn't need to be searched again during early startup - * phase. - */ - bp->cc_blob_address =3D (u32)(unsigned long)cc_info; - - return true; -} - void sev_prep_identity_maps(unsigned long top_level_pgt) { /* --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2061.outbound.protection.outlook.com [40.107.93.61]) (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 D30E41649DB for ; Wed, 24 Apr 2024 15:58:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974332; cv=fail; b=OWjrf9oidOE6Y/zLLgprxW8x5Klo7eG2O2b+L3zu+yOMNygRJq/5klmUsUhJaObT6L5aIC4xwrRRHxoDlCZp+PEwtq/axTVtdTFON82QFe2MJM4tw339ih/sdwN+jvizOn50LUh3TzuuRflVFPbTGPnX77haqBTcnaU/UG7a6kQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974332; c=relaxed/simple; bh=NA+MQQ1spUiJ5qyQR2IEak0qZZ8Nb59mjPmcb3W6zTs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CEdQ2+GcMBGgzWPqbWYoRerGoagUKCl6bTwAqViWSQfbDPHpwW1B1zX2Mv9SFLEjZUYb6s73j2ASMEImfX1YGu1mESbvYle9SefycMbCtib5Zwbdbb9GVZ54Pq6fdQi1jv5+MlHH0Ki8qkvUC232l4XCE2ZVPg4Yn5+qL4jwpAU= 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=cGy6T1fC; arc=fail smtp.client-ip=40.107.93.61 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="cGy6T1fC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PkYnPgPz1enEHrdzIJw1y8PI3hdHgAW/gn8wuT01cHc5YKrm3Rm9gaAS3AXESValjqNfr4F2OAHbADyd3d94aqsMrAzoIg2r2ZI96Y0RcefrZ03Xg1TO09r19cnmaGxLuTBNvw47/KG6INotj9i364SrB9DaqqxNVd6ESvb4KH7EeZ/Ex/ioXgauO5SoH5ICohkY6z86hImmak4kQ80giBjtNSHgawLmo/Gw6Pc3LpBAboOsvV0g8If9IximFk+ylM+G7Cyu46jhfiTfXc1S7aqK4nzjhT0l3b+zbTd8/89fnOIPdAz/xl+BgZpL1izcga6CT+Vb/OFrUE3djE64rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=bf6ndJ/A4gb88kzQ8k9yLqu7IKvmb6aKaA2Sh//c/u0=; b=nTt5G6X/1JO3V/V+F6Rc3DhUyhqUqHPldfCheiuj68aayh6WnnohJOg9+LnTRCpo6PJqrZc5X39SeAeLaHbv8MJXGb9ok/Qb7RRcHknPGpS4aQVn8Ab9mV7+pSL7Q9KLzOMx+ghY0SagWJofWoO78yuvPebr2PnoZ90zEG7L49a+oM1Dc5kBRLKqdcpX7ZW926REZMVDRoNTwUcKT/5GDUdTru7pnaKlGedTzLdh9jE/JZry65+8SL3Gu8SQxThmm8CJLBjF7s/unw5lp4/bpc7afnPv50DoIL+s+QuYk6UJY0AeYgY9X02Ui77d4lFDOiyFVL2TpqGALDJGLr/ytQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=bf6ndJ/A4gb88kzQ8k9yLqu7IKvmb6aKaA2Sh//c/u0=; b=cGy6T1fCCJ6pXGsOzTLg3a2YDIuifVqw/Ailutzro70NZ192TEox4rm3R5JGrFevTktqIcPWCYBkRJglbOW5nUTWNg2j9BU5xKslewIvYBkkHQZkWZmEpoQdS6BlxI/l3SC3O0z63nntUUv5uzYZwIL+iPIfaSavGU3XoCcP1kA= Received: from PH7PR17CA0003.namprd17.prod.outlook.com (2603:10b6:510:324::23) by LV2PR12MB5918.namprd12.prod.outlook.com (2603:10b6:408:174::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.24; Wed, 24 Apr 2024 15:58:47 +0000 Received: from CY4PEPF0000EE31.namprd05.prod.outlook.com (2603:10b6:510:324:cafe::b7) by PH7PR17CA0003.outlook.office365.com (2603:10b6:510:324::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.23 via Frontend Transport; Wed, 24 Apr 2024 15:58: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 CY4PEPF0000EE31.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:58:47 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 10:58:46 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 03/15] x86/sev: Make the VMPL0 checking more straight forward Date: Wed, 24 Apr 2024 10:57:59 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE31:EE_|LV2PR12MB5918:EE_ X-MS-Office365-Filtering-Correlation-Id: a433dfd5-0bc7-438f-2658-08dc64776d0b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|7416005|1800799015|36860700004|82310400014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?5/rYA/jYGeb/Kwm5PPTNYFC0L4sZaLuHNk0nN1tdXV7vMJ+BZCiOnZwXbXDi?= =?us-ascii?Q?cBz3OHGQKRJt9zfDUTn9eG+9WMc12if/w7sgisq3OBPCfW7bmJOuGbjgYm5j?= =?us-ascii?Q?JAe51KY0K5CEkavbCVYmBG17DYAfmUAYbpkK6C10mBGha7uCFFjZoFCezpuJ?= =?us-ascii?Q?9tXJS9dKB9FQJnpzTBX0yy2PDYYcxGkgCWZZmn+nS0/tjFubp9YLQ9ZxvKuP?= =?us-ascii?Q?5HAW5+N7YH0s5gryj97xia3zsWdC4Ip7zB10EleiypDjQhTwebpjCbriNvfV?= =?us-ascii?Q?oRvUtY/NtOMaqdQ3sC8VIuKWGRcuZ9dlU5IxHGg7iXDxMMoLCexXIn0perX8?= =?us-ascii?Q?DDohKOUPaJw+fTOg/ofHbCBcygM+3ZGACQ9sXqbljCqjVy7T27TCzfCAZF+7?= =?us-ascii?Q?asM/se16B/ZKDsR9mTReNwy5OoqVX1TyLHUN52QXDQUdSkqej57qtmSL+TcI?= =?us-ascii?Q?MdZHCMHIu0V+KjmwvCfLZ1bJbljefs2qxz6xHRe3lyJy3w4vubKXM9JvDzu7?= =?us-ascii?Q?ImBJ3o9J78/Ao7iPxzJNBW04mY45aVShBI4hQOnucqGLD5DoSiQ3xirldmji?= =?us-ascii?Q?rr75NVgUpvto+M0VwZPO/VfTEg8W90Jw4VYXOVhPwOQ4d0l7LZYXSWZAn5ik?= =?us-ascii?Q?JpHBx7XHWPQBUbirD1AAhUmcGa5C/fIwIgAqB/vRnr8bwohxWWtpY9wCk9Ut?= =?us-ascii?Q?r2VAeQKSoooUEic1jGeIfsQjvKFCab1cK8AK2J9k7w7skgj+wjNF0XHfqhMN?= =?us-ascii?Q?5lEKBFtMPan/KZ4SqUndUWZdTLbeUaZCSC3g9NtLHceL32oDk2YzAFCyxF/2?= =?us-ascii?Q?C0YK3UwzITyM3cD7VHImgp3Feo/0l9/sxtfZ7IDfzg2aRyU3N45vT6TMgWvF?= =?us-ascii?Q?OtpKOZYmvBLBrq0RGeLTZAJsc/3jYfh8hR3WDgUjmviF1Svos7DeaM5jSKmC?= =?us-ascii?Q?fZa+hE9FTfYNx0d1C4SZvEIo2I1UvvKs96VHPZBYEIEzIWVtr8nPg0W/6yFB?= =?us-ascii?Q?k5+CEndHaWGSRsqy8mZ6xallXu9GfIJPuZugypDgxbFGlDeqxtx39Ox2NQNK?= =?us-ascii?Q?tasIIrko7UxKLmQQr6Hsbk+7eGr8vFd9m+Fp5MC0W8Mey/awaqHkhE/yN+4R?= =?us-ascii?Q?PfiYdhiSwzHB8FNLbGxDto3PI1LYf+VNXNBE3VQ368ZU+7UcJqoT9hDLJh3L?= =?us-ascii?Q?DgrvybzJqvWbCpzF+Hyfuc4j/cGtHbLn+jtCKbq1TEPZInGcFuFexRniCDp8?= =?us-ascii?Q?Eb+tsD36gQWw4+Tl2O9s0D7bgGPhHs4UvGvsR8Wur6GqacFXGoWvZXLCx2CC?= =?us-ascii?Q?Fw254cZmHpZVxtvOv35+t7UnPWTUGcNAcIsQ2TviZXoGas/x5ISeCHnjP1Ga?= =?us-ascii?Q?8b3pUJmgq80MfD/+5gxa39booV9l?= 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:(13230031)(376005)(7416005)(1800799015)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:58:47.2146 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a433dfd5-0bc7-438f-2658-08dc64776d0b 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: CY4PEPF0000EE31.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5918 Content-Type: text/plain; charset="utf-8" Currently, the enforce_vmpl0() function uses a set argument when modifying the VMPL1 permissions used to test for VMPL0. If the guest is not running at VMPL0, the guest self-terminates. The function is just a wrapper for a fixed RMPADJUST function. Eliminate the function and perform the RMPADJUST directly. No functional change. Signed-off-by: Tom Lendacky Tested-by: Joerg Roedel --- arch/x86/boot/compressed/sev.c | 35 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 5ad0ff4664f1..0457a9d7e515 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -335,26 +335,6 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned = long exit_code) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ); } =20 -static void enforce_vmpl0(void) -{ - u64 attrs; - int err; - - /* - * RMPADJUST modifies RMP permissions of a lesser-privileged (numerically - * higher) privilege level. Here, clear the VMPL1 permission mask of the - * GHCB page. If the guest is not running at VMPL0, this will fail. - * - * If the guest is running at VMPL0, it will succeed. Even if that operat= ion - * modifies permission bits, it is still ok to do so currently because Li= nux - * SNP guests are supported only on VMPL0 so VMPL1 or higher permission m= asks - * changing is a don't-care. - */ - attrs =3D 1; - if (rmpadjust((unsigned long)&boot_ghcb_page, RMP_PG_SIZE_4K, attrs)) - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0); -} - /* * SNP_FEATURES_IMPL_REQ is the mask of SNP features that will need * guest side implementation for proper functioning of the guest. If any @@ -588,7 +568,20 @@ void sev_enable(struct boot_params *bp) if (!(get_hv_features() & GHCB_HV_FT_SNP)) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); =20 - enforce_vmpl0(); + /* + * Enforce running at VMPL0. + * + * RMPADJUST modifies RMP permissions of a lesser-privileged (numerically + * higher) privilege level. Here, clear the VMPL1 permission mask of the + * GHCB page. If the guest is not running at VMPL0, this will fail. + * + * If the guest is running at VMPL0, it will succeed. Even if that opera= tion + * modifies permission bits, it is still ok to do so currently because L= inux + * SNP guests running at VMPL0 only run at VMPL0, so VMPL1 or higher + * permission mask changes are a don't-care. + */ + if (rmpadjust((unsigned long)&boot_ghcb_page, RMP_PG_SIZE_4K, 1)) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0); } =20 if (snp && !(sev_status & MSR_AMD64_SEV_SNP_ENABLED)) --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2041.outbound.protection.outlook.com [40.107.93.41]) (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 6391B1649DB for ; Wed, 24 Apr 2024 15:58:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974339; cv=fail; b=jLSBPLTopfNremhjAoieySFJTHe4SpS+QBVwJK5GLSgyt2+A7egO3qslEbuj4w9Yl7bZvQOJx/RwhGsxRgNDxD/0J5+7TvWeUsCg+bwigBHRlcn0qu8GmGNvEtb+3F/5V8McYHN0mIk7CSXicuAnBK53kRYXIlV7fatHWojEsK8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974339; c=relaxed/simple; bh=1rq7LJSUQAHQZGrsm7htbyZqFp3tpiGuY2jCSOMF3HU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j1YnPgGnlvdKNhvkaskAkFKbebAGh5vaCxl9tU6/CrlE55EQFo9ImMcKpiCOLa7cRw3CwI5JyPbm7p9735/VFMbjKverr9vy8EPP1pCMBmzVQwPgo7sOb9iUYFsEHjVStzOlHwDCBxLDbe1YMf7ZKzf6ZRqN1z9S2lKhpbB7+sU= 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=pf2W+TG0; arc=fail smtp.client-ip=40.107.93.41 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="pf2W+TG0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OftVwEIsqurTy8PitjHP7k6MiVUYRWYDio+Bmyp8rBt18MnbnKXtvEZl1NARivWNr846ypIMNYWq6niAH80M4HOcaD5qGEINi61bV1jcvC3f+Dz0LKvDX1lHUcOhferxpOrO81j/hONA5DozR2Vlb3w7yvDeE4zAygZFAH4MAI+KHKJ5veZvMYvzwDbyPW5Gf465rekokGkRZIpecjzBjvjpGIUE+/v+wwMWCHYjiXdxS4Cvroo69ORoQ3YAmkV79dmZwT8JdZJZnO40QwXG4cn/CBXc/Wnw/cEefC0tUb9huEAXgpOp+Yi7vEiCnR1qIq/8zby91rXoZQ3/9fTCww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=Qa9qGzd4f67WtUpq1M7yG8u8qe9Yy9BZe6DqeXmZ8FA=; b=Cn2YRaCrIrin9e2vGl0bilW0FvY4+/hicKlK7yzrKVi6awcVoV0DqegAgSR3LBy1U4q0C2JnfOZxpA2DdnyNYdUyFH1tfLVHOUioyGtDLCtvMuX3daXupBemNDYgE9XBHk9NCJ0L/J9/pQvjUemPaIz2WtLXHIXbS28Tf8TzwEAamfbz7eOVVbSIal3kO0KU7lf77BVJE18xB6j1DdCU3eagsZDdLEP3hJ3xU8zaiGoXw4jkoB8596o8Dfne5TtMuDOaz8OfwKAPHrMpZO9B8c1aXs/QurZtXoAeYNMOnpW5Obl+iDBx7vih6n6vE+bKI84Qy3xKcgiQu3WuiUhXdQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=Qa9qGzd4f67WtUpq1M7yG8u8qe9Yy9BZe6DqeXmZ8FA=; b=pf2W+TG0b6qDFYJAS+O9dypfwQiq42TjgBcyJNb6WBHUgxkMDHv20YEtsghPFJg/BJArNtMAIA4mDV7VluW/6Nbn19lvaffJWn50wWWYj6TiC31sx0MVSKRMX0Sl4LfUxe/yfcvGsQ+DK0EOeRBYw8MwFKua4adEJrTv2rp/A9g= Received: from BL0PR0102CA0064.prod.exchangelabs.com (2603:10b6:208:25::41) by MW4PR12MB7239.namprd12.prod.outlook.com (2603:10b6:303:228::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22; Wed, 24 Apr 2024 15:58:54 +0000 Received: from MN1PEPF0000F0E5.namprd04.prod.outlook.com (2603:10b6:208:25:cafe::23) by BL0PR0102CA0064.outlook.office365.com (2603:10b6:208:25::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.33 via Frontend Transport; Wed, 24 Apr 2024 15:58: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 MN1PEPF0000F0E5.mail.protection.outlook.com (10.167.242.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:58:54 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 10:58:53 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 04/15] x86/sev: Check for the presence of an SVSM in the SNP Secrets page Date: Wed, 24 Apr 2024 10:58:00 -0500 Message-ID: <6cf54cac47f212f4c2b59b123855d8c183989022.1713974291.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E5:EE_|MW4PR12MB7239:EE_ X-MS-Office365-Filtering-Correlation-Id: 84658c38-b411-4e66-2d21-08dc64777151 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400014|376005|1800799015|7416005|36860700004; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?PmGNqMO3veAitb+XPlMp5UVOCyeNq5T0n0WuDUVOIz4IOetlY0UZHcw4nCMy?= =?us-ascii?Q?35e8rMErkRvJ/EQYdS9RchM4Zj2FLq0W7QjGgMdC5cLPZCi4PGuu7QBWogkn?= =?us-ascii?Q?I66zD4gDvqRzv1R4Entd+kprQ9uMYrAYnPKd2KItTSp0GihcVa1ADoDe1ZSP?= =?us-ascii?Q?oV+1aSDXfka5TZD1kOFBAQUs5ZjUcL3VLO2E51SkGI0c+lqt8+Qd25VPWkQD?= =?us-ascii?Q?Lckw2xNmDgo971wXxzSYkXVh22JF0I4BuTldmPjNKRtFdipuXqNDMkbOhRkh?= =?us-ascii?Q?XYArAVAEunxZgd64b3eJqZi/zHLiI2VduGZauMWWExN37/cmYEL2MvzkMoXM?= =?us-ascii?Q?dQ+qYsMHKXW83w0mCM35f/80lJDZhNyN3ZW5mJYsnhTtNh7porOQxveN59Dz?= =?us-ascii?Q?tym76HRPc/wggxNfXFkv1fckc5D7Da+HMAiwN9IJzWi3FdzMQnhnmJzWoSWQ?= =?us-ascii?Q?uvTW2PX+XKMSaPO7sg0EKKEl1GgyeuocjDiybWnD4kggMWCvguRTcl6Y7n4S?= =?us-ascii?Q?S0tlMlVtityIVN3EhlDoJ9ODF3UZybo1+BrHXTWfbcDaPIqLHVlaK0ENHIpW?= =?us-ascii?Q?0Fe1JAI9hV6gxABSqg7hlw342tTxC5t1iT4HWksvGjJxegvjj+4w33je+HuR?= =?us-ascii?Q?MkpRcQVrVeTu1LX5sQ8qQgoEu13oyTispq1AhI26oVZB6CAEiBMnld60J/Jh?= =?us-ascii?Q?ztLMp0DYLvADDbLxmFjlvApeFMoJHswJkTbrBOBXN0HTtPP1awIXEoS8F5yG?= =?us-ascii?Q?takVZK+bJTzIhofkE19qJNu220EWHktrxGPT+v4Ucmsve8y7jhlsoTvmWSKg?= =?us-ascii?Q?M5aGi8qn16E5UUYcMyeB+WxSpIk4xO/1amxEUG3kgvmPFEYorS/jRhZGjCu+?= =?us-ascii?Q?Lrhnk9bkDn0JufccSBAznARufxhXeUnY8ePkRDg5LcaUL2ak0h0DyOUfR/Nx?= =?us-ascii?Q?g3Uuwnffq++MDojNkEP4DLvEWwg/5J4QIQrPm+WMt71KRzJPh2F2xVe+cC5E?= =?us-ascii?Q?fYjcxzNhSvHkKhKPLNfqGYRI1n2QGSMkdIdxFAVvchdaj1UwVHw2u5q2vLk3?= =?us-ascii?Q?ilS38sgv8qbsdDWI3he0zF1fXT/PcF11BVyu5GstBsSwFsLihASEzsL5MOIW?= =?us-ascii?Q?85zHKEYXCTbr7+wi7v33f8SHY6bdGTpekz1RVf+g5l8xa5WGJG0zwwqv+kGg?= =?us-ascii?Q?iNvW89MJTBgeDrF74yjTzBcJiKx0J2X8tt9yzYgxtqDqyOlhtIEvGeBupMUH?= =?us-ascii?Q?G3M5C+UaxLGIfx0b362GTSoVwlR+jo5kIvylQqvWbmpht57HVwjgFxbkGlNs?= =?us-ascii?Q?IsPlFEeOiw5DUqDl5sxq7YdnIhyqIY/Wav6ynlNBFnA148b4xWNK0XnANc/1?= =?us-ascii?Q?tHFqL8w/pwHlwG7OJauxwe5Mrwsx?= 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:(13230031)(82310400014)(376005)(1800799015)(7416005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:58:54.4330 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 84658c38-b411-4e66-2d21-08dc64777151 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: MN1PEPF0000F0E5.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7239 Content-Type: text/plain; charset="utf-8" During early boot phases, check for the presence of an SVSM when running as an SEV-SNP guest. An SVSM is present if not running at VMPL0 and the 64-bit value at offset 0x148 into the secrets page is non-zero. If an SVSM is present, save the SVSM Calling Area address (CAA), located at offset 0x150 into the secrets page, and set the VMPL level of the guest, which should be non-zero, to indicate the presence of an SVSM. Signed-off-by: Tom Lendacky Tested-by: Joerg Roedel --- .../arch/x86/amd-memory-encryption.rst | 22 ++++++ arch/x86/boot/compressed/sev.c | 8 +++ arch/x86/include/asm/sev-common.h | 4 ++ arch/x86/include/asm/sev.h | 25 ++++++- arch/x86/kernel/sev-shared.c | 70 +++++++++++++++++++ arch/x86/kernel/sev.c | 7 ++ 6 files changed, 135 insertions(+), 1 deletion(-) diff --git a/Documentation/arch/x86/amd-memory-encryption.rst b/Documentati= on/arch/x86/amd-memory-encryption.rst index 414bc7402ae7..32737718d4a2 100644 --- a/Documentation/arch/x86/amd-memory-encryption.rst +++ b/Documentation/arch/x86/amd-memory-encryption.rst @@ -130,4 +130,26 @@ SNP feature support. =20 More details in AMD64 APM[1] Vol 2: 15.34.10 SEV_STATUS MSR =20 +Secure VM Service Module (SVSM) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D + +SNP provides a feature called Virtual Machine Privilege Levels (VMPL). The= most +privileged VMPL is 0 with numerically higher numbers having lesser privile= ges. +More details in AMD64 APM[1] Vol 2: 15.35.7 Virtual Machine Privilege Leve= ls. + +The VMPL feature provides the ability to run software services at a more +privileged level than the guest OS is running at. This provides a secure +environment for services within the guest's SNP environment, while protect= ing +the service from hypervisor interference. An example of a secure service +would be a virtual TPM (vTPM). Additionally, certain operations require the +guest to be running at VMPL0 in order for them to be performed. For exampl= e, +the PVALIDATE instruction is required to be executed at VMPL0. + +When a guest is not running at VMPL0, it needs to communicate with the sof= tware +running at VMPL0 to perform privileged operations or to interact with secu= re +services. This software running at VMPL0 is known as a Secure VM Service M= odule +(SVSM). Discovery of an SVSM and the API used to communicate with it is +documented in Secure VM Service Module for SEV-SNP Guests[2]. + [1] https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/p= rogrammer-references/24593.pdf +[2] https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/s= pecifications/58019.pdf diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 0457a9d7e515..cb771b380a6b 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -12,6 +12,7 @@ */ #include "misc.h" =20 +#include #include #include #include @@ -462,6 +463,13 @@ static bool early_snp_init(struct boot_params *bp) */ setup_cpuid_table(cc_info); =20 + /* + * Record the SVSM Calling Area (CA) address if the guest is not + * running at VMPL0. The CA will be used to communicate with the + * SVSM to perform the SVSM services. + */ + setup_svsm_ca(cc_info); + /* * Pass run-time kernel a pointer to CC info via boot_params so EFI * config table doesn't need to be searched again during early startup diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-c= ommon.h index b463fcbd4b90..1225744a069b 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -159,6 +159,10 @@ struct snp_psc_desc { #define GHCB_TERM_NOT_VMPL0 3 /* SNP guest is not running at VMPL-0 */ #define GHCB_TERM_CPUID 4 /* CPUID-validation failure */ #define GHCB_TERM_CPUID_HV 5 /* CPUID failure during hypervisor fallback = */ +#define GHCB_TERM_SECRETS_PAGE 6 /* Secrets page failure */ +#define GHCB_TERM_NO_SVSM 7 /* SVSM is not advertised in the secrets page= */ +#define GHCB_TERM_SVSM_VMPL0 8 /* SVSM is present but has set VMPL to 0 */ +#define GHCB_TERM_SVSM_CAA 9 /* SVSM is present but CAA is not page align= ed */ =20 #define GHCB_RESP_CODE(v) ((v) & GHCB_MSR_INFO_MASK) =20 diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 48bc397db649..56f7d843f7a4 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -152,9 +152,32 @@ struct snp_secrets_page { u8 vmpck2[VMPCK_KEY_LEN]; u8 vmpck3[VMPCK_KEY_LEN]; struct secrets_os_area os_area; - u8 rsvd3[3840]; + + u8 vmsa_tweak_bitmap[64]; + + /* SVSM fields */ + u64 svsm_base; + u64 svsm_size; + u64 svsm_caa; + u32 svsm_max_version; + u8 svsm_guest_vmpl; + u8 rsvd3[3]; + + /* Remainder of page */ + u8 rsvd4[3744]; } __packed; =20 +/* + * The SVSM Calling Area (CA) related structures. + */ +struct svsm_ca { + u8 call_pending; + u8 mem_available; + u8 rsvd1[6]; + + u8 svsm_buffer[PAGE_SIZE - 8]; +}; + #ifdef CONFIG_AMD_MEM_ENCRYPT extern void __sev_es_ist_enter(struct pt_regs *regs); extern void __sev_es_ist_exit(void); diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index b4f8fa0f722c..46ea4e5e118a 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -23,6 +23,21 @@ #define sev_printk_rtl(fmt, ...) #endif =20 +/* + * SVSM related information: + * When running under an SVSM, the VMPL that Linux is executing at must = be + * non-zero. The VMPL is therefore used to indicate the presence of an S= VSM. + * + * During boot, the page tables are set up as identity mapped and later + * changed to use kernel virtual addresses. Maintain separate virtual and + * physical addresses for the CAA to allow SVSM functions to be used dur= ing + * early boot, both with identity mapped virtual addresses and proper ke= rnel + * virtual addresses. + */ +static u8 vmpl __ro_after_init; +static struct svsm_ca *boot_svsm_caa __ro_after_init; +static u64 boot_svsm_caa_pa __ro_after_init; + /* I/O parameters for CPUID-related helpers */ struct cpuid_leaf { u32 fn; @@ -1269,3 +1284,58 @@ static enum es_result vc_check_opcode_bytes(struct e= s_em_ctxt *ctxt, =20 return ES_UNSUPPORTED; } + +/* + * Maintain the GPA of the SVSM Calling Area (CA) in order to utilize the = SVSM + * services needed when not running in VMPL0. + */ +static void __head setup_svsm_ca(const struct cc_blob_sev_info *cc_info) +{ + struct snp_secrets_page *secrets_page; + u64 caa; + + BUILD_BUG_ON(sizeof(*secrets_page) !=3D PAGE_SIZE); + + /* + * RMPADJUST modifies RMP permissions of a lesser-privileged (numerically + * higher) privilege level. Here, clear the VMPL1 permission mask of the + * GHCB page. If the guest is not running at VMPL0, this will fail. + * + * If the guest is running at VMPL0, it will succeed. Even if that operat= ion + * modifies permission bits, it is still ok to do so currently because Li= nux + * SNP guests running at VMPL0 only run at VMPL0, so VMPL1 or higher + * permission mask changes are a don't-care. + * + * Use __pa() since this routine is running identity mapped when called, + * both by the decompressor code and the early kernel code. + */ + if (!rmpadjust((unsigned long)__pa(&boot_ghcb_page), RMP_PG_SIZE_4K, 1)) + return; + + /* + * Not running at VMPL0, ensure everything has been properly supplied + * for running under an SVSM. + */ + if (!cc_info || !cc_info->secrets_phys || cc_info->secrets_len !=3D PAGE_= SIZE) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SECRETS_PAGE); + + secrets_page =3D (struct snp_secrets_page *)cc_info->secrets_phys; + if (!secrets_page->svsm_size) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NO_SVSM); + + if (!secrets_page->svsm_guest_vmpl) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SVSM_VMPL0); + + vmpl =3D secrets_page->svsm_guest_vmpl; + + caa =3D secrets_page->svsm_caa; + if (!PAGE_ALIGNED(caa)) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SVSM_CAA); + + /* + * The CA is identity mapped when this routine is called, both by the + * decompressor code and the early kernel code. + */ + boot_svsm_caa =3D (struct svsm_ca *)caa; + boot_svsm_caa_pa =3D caa; +} diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 6949fbccec40..a500df807e79 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2108,6 +2108,13 @@ bool __head snp_init(struct boot_params *bp) =20 setup_cpuid_table(cc_info); =20 + /* + * Record the SVSM Calling Area address (CAA) if the guest is not + * running at VMPL0. The CA will be used to communicate with the + * SVSM to perform the SVSM services. + */ + setup_svsm_ca(cc_info); + /* * The CC blob will be used later to access the secrets page. Cache * it here like the boot kernel does. --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2074.outbound.protection.outlook.com [40.107.93.74]) (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 C2F191635DD for ; Wed, 24 Apr 2024 15:59:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974349; cv=fail; b=IUF6dxoe10/NWkQBgnYwrigWTFeNrK6HCRlLOx3hxJuDBDdTAN7B/byxGTGY7Dzd62G6h01+3IAtKzq6728kGGSRfSPHqG59peTSqdIgNTLulQ5qmpfr+wrrgx9fWLdLWTEaXYpcviLMCnAqFZVSBrvgb8p4RwxLMrUAqv0QfC4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974349; c=relaxed/simple; bh=3YDaHiutIgYlNhCcDi1GSw7qspv9UJtm6SG6Fqae198=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WRKiyKVr7pGURkWCkSVGG4br0u12rKEx6rcXAI81iyTuYARPRLTAayBsuFHbEnuLu2CjAbofw7d9JzyITXTtZ7Ruv+5DzXjmyb0+AfHLgG8WuP6l8Lc2LLuALRgKxHmcrq+Qyzd3r8IG9wKjcGNi1F2hwxDGhJDUKqG/nV5s1B4= 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=HSK7HZJ/; arc=fail smtp.client-ip=40.107.93.74 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="HSK7HZJ/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N5uW2qek0rTxI5FBvx+MYItgyVz0fgQiqA0uBZQhmWGUBrXyFkFytHc8RSN4JtjutXAXTM2xksY9/1jMnPZHc3eGFiY5yGdGq2D4xlE2AojvxCB93WHMu+vKwSui0tNI5OXKUHN16equDgeXUeZPkqSxpCKq07tV7YDbhLfdGH16J9mWvLqmDJWhzGsBx09s2WAR4AJFAzOrW+xFGdCFqrz3eJWLMPj5ZJPf6Zz1OT9vi2GG9/28rfo20We101MJOSw+y1qWXSkCzQiUlMvv3QimMeL0mMUfk/2eYJr7QMUzdX64ZPhi0RY3wM/Q4wrfiwvVpospfyZOh6yiPhU0hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=kF5LZWyAiNqLqtvx7E6KrWBu6pECVjNrZrovtybdqYg=; b=GjfVV5OMAwiBuJ1XqIYR4vLZyVYEemIs+8nR1+f1ZF/YP55bNioypa0CkPikhpg+/No8/mnHBMAsrzx3DficgijhdAA5NKsnM82kGrBxwMt5XmynBeM9TsAOiBgFxSObIomF6mb/R5pQwUu8TUOPuasz6HeEcyHq7rOTSdZCuHwPKjNbJVPRRZN4iVbWgr3V9xYfPMeqIXgSdIvuRnYfdMqwdAbajK6iy5rDlhwHSN6TBjwkkrKVRrpN6rb3/vQKka0R/qSBGfjewOgQaOQxATW7EOIO+AWTXZML+xvgOOim9r5oXFXc61jf8mO65+FYosdeoudTblX8HYLrmx/KFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=kF5LZWyAiNqLqtvx7E6KrWBu6pECVjNrZrovtybdqYg=; b=HSK7HZJ/nHElEewBALuDtHDsLjfs/4RkC7b9PcRenUl3tkbpYFTJ24MHoP6s23HznW5yfSVuGL8ETtHcCnFnz5NyJKLyi6GZjGmfFNXQukqBXy5OFmZ5Sogy50kYAr121Z4BQLryJN2TpR2VIxfUJGFAQyQlJ9zKHHjkNsgHwl4= Received: from MN2PR22CA0021.namprd22.prod.outlook.com (2603:10b6:208:238::26) by SJ2PR12MB8064.namprd12.prod.outlook.com (2603:10b6:a03:4cc::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.23; Wed, 24 Apr 2024 15:59:03 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:238:cafe::55) by MN2PR22CA0021.outlook.office365.com (2603:10b6:208:238::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22 via Frontend Transport; Wed, 24 Apr 2024 15:59:02 +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 MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:59:02 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 10:59:00 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 05/15] x86/sev: Use kernel provided SVSM Calling Areas Date: Wed, 24 Apr 2024 10:58:01 -0500 Message-ID: <07266b47e749267ef9a9ccbc9e8e9df78ed54857.1713974291.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E2:EE_|SJ2PR12MB8064:EE_ X-MS-Office365-Filtering-Correlation-Id: 7f98f65f-f5b0-40e6-8e2e-08dc64777640 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|1800799015|82310400014|7416005|36860700004; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?9PrZQq4VJQ2LyKvfb9OyjJrK8/VDvb0vdnB4K52Lkn6xwG9gj1tmh8VDVwji?= =?us-ascii?Q?TKKD/qm95u7L3LrmmexK9dYiS3Stot8qSEEgIV5PjgNJc0z9HOMpdjQi6y1Z?= =?us-ascii?Q?4x6k3NSIsopiyVNjTI41NkrD7oN/7rzn0F77Go7z9RNinjR4Dt/A6cuhFstY?= =?us-ascii?Q?7vHYx7VhQG8RM5HZvT8zoD3TEUBkfAEOHDZP+LptceVRPyflcNTRAav9caDC?= =?us-ascii?Q?pkTnHB9X5RSSi5kzAlfdyeIYp65iakOvzHFJwRyE5iXSK9hQdoDuoBA/kIXh?= =?us-ascii?Q?peB3JIb6c+2KBhH8R/IoAzbFbGJVyrbdQSeK6bmA/5KYvQBOYvPNBoJMs+0b?= =?us-ascii?Q?t45RfKTNcsSSaFv8XO2JrMIpBvHjzYFhj/xUvVNH/HmqruezXWM0AZFw7fWQ?= =?us-ascii?Q?49q//bPmmNWOuP4pbsCUq0oIGgbBGOif5GJmDU8YhPuPbuybIIuSTO3xFXzt?= =?us-ascii?Q?sslvXxa61ee4fph+gODezjklQ0sK9wX3iJn3jpQ9jD9ZEPv/c2zJvyCM5AWL?= =?us-ascii?Q?o0yf1PxBD+1nNwFOUqFcU3ZU2XQAPfRV+AreoHZdXE+w62v9n6d2duDQgZh3?= =?us-ascii?Q?Hcid8Tgp1H2ObgIe7D990TihkHWVQ7oUWM9S2dLMnY7e3BEsQQvlhZzW88fn?= =?us-ascii?Q?X/PZOZLUMyfii/kWTWfsu1Y/Aan0G1WzC99DPwrw2T8ijmXU7iFA0h7x/Iq6?= =?us-ascii?Q?uK0hdUOioT4JqheunbDKpKofVvab85tOIU/2XTGMBBpF+IYVuPAYoVxsys2a?= =?us-ascii?Q?s83+wfZRMtYkdIanr1h43wQUniohswAvp87F/nmFknBn6vh8/mESoWmf6rZ+?= =?us-ascii?Q?gaH4KrWHOpz1FZF0KEHEt2lyRjQG2w736ASAZIbU2//Wg/F0hQTpVV3grVrG?= =?us-ascii?Q?R+FtMPHUphNBU4vhmxR7dQD/0L01bykPNyzQO6Sez6v62YgI5B3a+dcELjM4?= =?us-ascii?Q?CoElxE38/IrF1QUZk7P5ZKYsycPLgBpIbO9YgWG4W9S/YBOWFsfk4RhaneKm?= =?us-ascii?Q?8i8EojRewdJi0KDR3NXtVTLgo2KHcbbApHUokkHVXoP2wtgGJZ/x6b6JhSLK?= =?us-ascii?Q?XYUM6r+quf2wJfR4lzLQpZvTijlEj3tsMlXCuwiCgyXQnNCIyu/1I7hJVbfc?= =?us-ascii?Q?v2AZZyFDGy1ga3QDTlpsAsdcXcHj0uFkaluneo7H396Kq0sh9jniCCQcNa0I?= =?us-ascii?Q?e6sk1+6R7OzA7gHKsgQmlEYAE/WqHXmahbPVZcwb/SK6Ti8Vq5UACmMYVzSf?= =?us-ascii?Q?V/C7c7qF4NKV4MhuaVrepYwaTPZvaCf+NPIUgYkvBIDJoKrDf4+KRs4ZuJh6?= =?us-ascii?Q?N3BdrDwuFP1HYkl7w8OMzOpd0SHIbsN2LNjWrZlLdEkVdXi7JXU5ccgh8kTo?= =?us-ascii?Q?/s3QkH6RWwZe53ML9y/p8Cst1Iu5?= 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:(13230031)(376005)(1800799015)(82310400014)(7416005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:59:02.7127 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7f98f65f-f5b0-40e6-8e2e-08dc64777640 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: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8064 Content-Type: text/plain; charset="utf-8" The SVSM Calling Area (CA) is used to communicate between Linux and the SVSM. Since the firmware supplied CA for the BSP is likely to be in reserved memory, switch off that CA to a kernel provided CA so that access and use of the CA is available during boot. The CA switch is done using the SVSM core protocol SVSM_CORE_REMAP_CA call. An SVSM call is executed by filling out the SVSM CA and setting the proper register state as documented by the SVSM protocol. The SVSM is invoked by by requesting the hypervisor to run VMPL0. Once it is safe to allocate/reserve memory, allocate a CA for each CPU. After allocating the new CAs, the BSP will switch from the boot CA to the per-CPU CA. The CA for an AP is identified to the SVSM when creating the VMSA in preparation for booting the AP. Signed-off-by: Tom Lendacky Tested-by: Joerg Roedel --- arch/x86/include/asm/sev-common.h | 13 ++ arch/x86/include/asm/sev.h | 32 +++++ arch/x86/include/uapi/asm/svm.h | 1 + arch/x86/kernel/sev-shared.c | 94 +++++++++++++- arch/x86/kernel/sev.c | 207 +++++++++++++++++++++++++----- arch/x86/mm/mem_encrypt_amd.c | 8 +- 6 files changed, 320 insertions(+), 35 deletions(-) diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-c= ommon.h index 1225744a069b..4cc716660d4b 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -96,6 +96,19 @@ enum psc_op { /* GHCBData[63:32] */ \ (((u64)(val) & GENMASK_ULL(63, 32)) >> 32) =20 +/* GHCB Run at VMPL Request/Response */ +#define GHCB_MSR_VMPL_REQ 0x016 +#define GHCB_MSR_VMPL_REQ_LEVEL(v) \ + /* GHCBData[39:32] */ \ + (((u64)(v) & GENMASK_ULL(7, 0) << 32) | \ + /* GHCBDdata[11:0] */ \ + GHCB_MSR_VMPL_REQ) + +#define GHCB_MSR_VMPL_RESP 0x017 +#define GHCB_MSR_VMPL_RESP_VAL(v) \ + /* GHCBData[63:32] */ \ + (((u64)(v) & GENMASK_ULL(63, 32)) >> 32) + /* GHCB Hypervisor Feature Request/Response */ #define GHCB_MSR_HV_FT_REQ 0x080 #define GHCB_MSR_HV_FT_RESP 0x081 diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 56f7d843f7a4..8f180fd3cbf0 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -178,6 +178,36 @@ struct svsm_ca { u8 svsm_buffer[PAGE_SIZE - 8]; }; =20 +#define SVSM_SUCCESS 0 +#define SVSM_ERR_INCOMPLETE 0x80000000 +#define SVSM_ERR_UNSUPPORTED_PROTOCOL 0x80000001 +#define SVSM_ERR_UNSUPPORTED_CALL 0x80000002 +#define SVSM_ERR_INVALID_ADDRESS 0x80000003 +#define SVSM_ERR_INVALID_FORMAT 0x80000004 +#define SVSM_ERR_INVALID_PARAMETER 0x80000005 +#define SVSM_ERR_INVALID_REQUEST 0x80000006 +#define SVSM_ERR_BUSY 0x80000007 + +/* + * SVSM protocol structure + */ +struct svsm_call { + struct svsm_ca *caa; + u64 rax; + u64 rcx; + u64 rdx; + u64 r8; + u64 r9; + u64 rax_out; + u64 rcx_out; + u64 rdx_out; + u64 r8_out; + u64 r9_out; +}; + +#define SVSM_CORE_CALL(x) ((0ULL << 32) | (x)) +#define SVSM_CORE_REMAP_CA 0 + #ifdef CONFIG_AMD_MEM_ENCRYPT extern void __sev_es_ist_enter(struct pt_regs *regs); extern void __sev_es_ist_exit(void); @@ -252,6 +282,7 @@ void snp_accept_memory(phys_addr_t start, phys_addr_t e= nd); u64 snp_get_unsupported_features(u64 status); u64 sev_get_status(void); void sev_show_status(void); +void snp_remap_svsm_ca(void); #else static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } @@ -281,6 +312,7 @@ static inline void snp_accept_memory(phys_addr_t start,= phys_addr_t end) { } static inline u64 snp_get_unsupported_features(u64 status) { return 0; } static inline u64 sev_get_status(void) { return 0; } static inline void sev_show_status(void) { } +static inline void snp_remap_svsm_ca(void) { } #endif =20 #ifdef CONFIG_KVM_AMD_SEV diff --git a/arch/x86/include/uapi/asm/svm.h b/arch/x86/include/uapi/asm/sv= m.h index 80e1df482337..1814b413fd57 100644 --- a/arch/x86/include/uapi/asm/svm.h +++ b/arch/x86/include/uapi/asm/svm.h @@ -115,6 +115,7 @@ #define SVM_VMGEXIT_AP_CREATE_ON_INIT 0 #define SVM_VMGEXIT_AP_CREATE 1 #define SVM_VMGEXIT_AP_DESTROY 2 +#define SVM_VMGEXIT_SNP_RUN_VMPL 0x80000018 #define SVM_VMGEXIT_HV_FEATURES 0x8000fffd #define SVM_VMGEXIT_TERM_REQUEST 0x8000fffe #define SVM_VMGEXIT_TERM_REASON(reason_set, reason_code) \ diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index 46ea4e5e118a..6f57eb804e70 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -18,9 +18,11 @@ #define sev_printk_rtl(fmt, ...) printk_ratelimited(fmt, ##__VA_ARGS__) #else #undef WARN -#define WARN(condition, format...) (!!(condition)) +#define WARN(condition, format...) (!!(condition)) #define sev_printk(fmt, ...) #define sev_printk_rtl(fmt, ...) +#undef vc_forward_exception +#define vc_forward_exception(c) panic("SNP: Hypervisor requested exceptio= n\n") #endif =20 /* @@ -244,6 +246,96 @@ static enum es_result verify_exception_info(struct ghc= b *ghcb, struct es_em_ctxt return ES_VMM_ERROR; } =20 +static __always_inline void issue_svsm_call(struct svsm_call *call, u8 *pe= nding) +{ + /* + * Issue the VMGEXIT to run the SVSM: + * - Load the SVSM register state (RAX, RCX, RDX, R8 and R9) + * - Set the CA call pending field to 1 + * - Issue VMGEXIT + * - Save the SVSM return register state (RAX, RCX, RDX, R8 and R9) + * - Perform atomic exchange of the CA call pending field + */ + asm volatile("mov %9, %%r8\n\t" + "mov %10, %%r9\n\t" + "movb $1, %11\n\t" + "rep; vmmcall\n\t" + "mov %%r8, %3\n\t" + "mov %%r9, %4\n\t" + "xchgb %5, %11\n\t" + : "=3Da" (call->rax_out), "=3Dc" (call->rcx_out), "=3Dd" (call->rdx= _out), + "=3Dm" (call->r8_out), "=3Dm" (call->r9_out), + "+r" (*pending) + : "a" (call->rax), "c" (call->rcx), "d" (call->rdx), + "r" (call->r8), "r" (call->r9), + "m" (call->caa->call_pending) + : "r8", "r9", "memory"); +} + +static int __svsm_msr_protocol(struct svsm_call *call) +{ + u64 val, resp; + u8 pending; + + val =3D sev_es_rd_ghcb_msr(); + + sev_es_wr_ghcb_msr(GHCB_MSR_VMPL_REQ_LEVEL(0)); + + pending =3D 0; + issue_svsm_call(call, &pending); + + resp =3D sev_es_rd_ghcb_msr(); + + sev_es_wr_ghcb_msr(val); + + if (pending) + return -EINVAL; + + if (GHCB_RESP_CODE(resp) !=3D GHCB_MSR_VMPL_RESP) + return -EINVAL; + + if (GHCB_MSR_VMPL_RESP_VAL(resp) !=3D 0) + return -EINVAL; + + return call->rax_out; +} + +static int __svsm_ghcb_protocol(struct ghcb *ghcb, struct svsm_call *call) +{ + struct es_em_ctxt ctxt; + u8 pending; + + vc_ghcb_invalidate(ghcb); + + /* Fill in protocol and format specifiers */ + ghcb->protocol_version =3D ghcb_version; + ghcb->ghcb_usage =3D GHCB_DEFAULT_USAGE; + + ghcb_set_sw_exit_code(ghcb, SVM_VMGEXIT_SNP_RUN_VMPL); + ghcb_set_sw_exit_info_1(ghcb, 0); + ghcb_set_sw_exit_info_2(ghcb, 0); + + sev_es_wr_ghcb_msr(__pa(ghcb)); + + pending =3D 0; + issue_svsm_call(call, &pending); + + if (pending) + return -EINVAL; + + switch (verify_exception_info(ghcb, &ctxt)) { + case ES_OK: + break; + case ES_EXCEPTION: + vc_forward_exception(&ctxt); + fallthrough; + default: + return -EINVAL; + } + + return call->rax_out; +} + static enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, struct es_em_ctxt *ctxt, u64 exit_code, u64 exit_info_1, diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index a500df807e79..21f3cc40d662 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -133,8 +133,13 @@ struct ghcb_state { struct ghcb *ghcb; }; =20 +/* For early boot SVSM communication */ +static struct svsm_ca boot_svsm_ca_page __aligned(PAGE_SIZE); + static DEFINE_PER_CPU(struct sev_es_runtime_data*, runtime_data); static DEFINE_PER_CPU(struct sev_es_save_area *, sev_vmsa); +static DEFINE_PER_CPU(struct svsm_ca *, svsm_caa); +static DEFINE_PER_CPU(u64, svsm_caa_pa); =20 struct sev_config { __u64 debug : 1, @@ -150,6 +155,15 @@ struct sev_config { */ ghcbs_initialized : 1, =20 + /* + * A flag used to indicate when the per-CPU SVSM CA is to be + * used instead of the boot SVSM CA. + * + * For APs, the per-CPU SVSM CA is created as part of the AP + * bringup, so this flag can be used globally for the BSP and APs. + */ + cas_initialized : 1, + __reserved : 62; }; =20 @@ -572,9 +586,42 @@ static enum es_result vc_ioio_check(struct es_em_ctxt = *ctxt, u16 port, size_t si return ES_EXCEPTION; } =20 +static __always_inline void vc_forward_exception(struct es_em_ctxt *ctxt) +{ + long error_code =3D ctxt->fi.error_code; + int trapnr =3D ctxt->fi.vector; + + ctxt->regs->orig_ax =3D ctxt->fi.error_code; + + switch (trapnr) { + case X86_TRAP_GP: + exc_general_protection(ctxt->regs, error_code); + break; + case X86_TRAP_UD: + exc_invalid_op(ctxt->regs); + break; + case X86_TRAP_PF: + write_cr2(ctxt->fi.cr2); + exc_page_fault(ctxt->regs, error_code); + break; + case X86_TRAP_AC: + exc_alignment_check(ctxt->regs, error_code); + break; + default: + pr_emerg("Unsupported exception in #VC instruction emulation - can't con= tinue\n"); + BUG(); + } +} + /* Include code shared with pre-decompression boot stage */ #include "sev-shared.c" =20 +static struct svsm_ca *__svsm_get_caa(void) +{ + return sev_cfg.cas_initialized ? this_cpu_read(svsm_caa) + : boot_svsm_caa; +} + static noinstr void __sev_put_ghcb(struct ghcb_state *state) { struct sev_es_runtime_data *data; @@ -600,6 +647,42 @@ static noinstr void __sev_put_ghcb(struct ghcb_state *= state) } } =20 +static int svsm_protocol(struct svsm_call *call) +{ + struct ghcb_state state; + unsigned long flags; + struct ghcb *ghcb; + int ret; + + /* + * This can be called very early in the boot, use native functions in + * order to avoid paravirt issues. + */ + flags =3D native_save_fl(); + if (flags & X86_EFLAGS_IF) + native_irq_disable(); + + if (sev_cfg.ghcbs_initialized) + ghcb =3D __sev_get_ghcb(&state); + else if (boot_ghcb) + ghcb =3D boot_ghcb; + else + ghcb =3D NULL; + + do { + ret =3D ghcb ? __svsm_ghcb_protocol(ghcb, call) + : __svsm_msr_protocol(call); + } while (ret =3D=3D SVSM_ERR_BUSY); + + if (sev_cfg.ghcbs_initialized) + __sev_put_ghcb(&state); + + if (flags & X86_EFLAGS_IF) + native_irq_enable(); + + return ret; +} + void noinstr __sev_es_nmi_complete(void) { struct ghcb_state state; @@ -1346,6 +1429,18 @@ static void __init alloc_runtime_data(int cpu) panic("Can't allocate SEV-ES runtime data"); =20 per_cpu(runtime_data, cpu) =3D data; + + if (vmpl) { + struct svsm_ca *caa; + + /* Allocate the SVSM CA page if an SVSM is present */ + caa =3D memblock_alloc(sizeof(*caa), PAGE_SIZE); + if (!caa) + panic("Can't allocate SVSM CA page\n"); + + per_cpu(svsm_caa, cpu) =3D caa; + per_cpu(svsm_caa_pa, cpu) =3D __pa(caa); + } } =20 static void __init init_ghcb(int cpu) @@ -1395,6 +1490,31 @@ void __init sev_es_init_vc_handling(void) init_ghcb(cpu); } =20 + /* If running under an SVSM, switch to the per-cpu CA */ + if (vmpl) { + struct svsm_call call =3D {}; + unsigned long flags; + int ret; + + local_irq_save(flags); + + /* + * SVSM_CORE_REMAP_CA call: + * RAX =3D 0 (Protocol=3D0, CallID=3D0) + * RCX =3D New CA GPA + */ + call.caa =3D __svsm_get_caa(); + call.rax =3D SVSM_CORE_CALL(SVSM_CORE_REMAP_CA); + call.rcx =3D this_cpu_read(svsm_caa_pa); + ret =3D svsm_protocol(&call); + if (ret !=3D SVSM_SUCCESS) + panic("Can't remap the SVSM CA, ret=3D%#x (%d)\n", ret, ret); + + sev_cfg.cas_initialized =3D true; + + local_irq_restore(flags); + } + sev_es_setup_play_dead(); =20 /* Secondary CPUs use the runtime #VC handler */ @@ -1819,33 +1939,6 @@ static enum es_result vc_handle_exitcode(struct es_e= m_ctxt *ctxt, return result; } =20 -static __always_inline void vc_forward_exception(struct es_em_ctxt *ctxt) -{ - long error_code =3D ctxt->fi.error_code; - int trapnr =3D ctxt->fi.vector; - - ctxt->regs->orig_ax =3D ctxt->fi.error_code; - - switch (trapnr) { - case X86_TRAP_GP: - exc_general_protection(ctxt->regs, error_code); - break; - case X86_TRAP_UD: - exc_invalid_op(ctxt->regs); - break; - case X86_TRAP_PF: - write_cr2(ctxt->fi.cr2); - exc_page_fault(ctxt->regs, error_code); - break; - case X86_TRAP_AC: - exc_alignment_check(ctxt->regs, error_code); - break; - default: - pr_emerg("Unsupported exception in #VC instruction emulation - can't con= tinue\n"); - BUG(); - } -} - static __always_inline bool is_vc2_stack(unsigned long sp) { return (sp >=3D __this_cpu_ist_bottom_va(VC2) && sp < __this_cpu_ist_top_= va(VC2)); @@ -2095,6 +2188,50 @@ static __head struct cc_blob_sev_info *find_cc_blob(= struct boot_params *bp) return cc_info; } =20 +static __head void setup_svsm(struct cc_blob_sev_info *cc_info) +{ + struct svsm_call call =3D {}; + int ret; + u64 pa; + + /* + * Record the SVSM Calling Area address (CAA) if the guest is not + * running at VMPL0. The CA will be used to communicate with the + * SVSM to perform the SVSM services. + */ + setup_svsm_ca(cc_info); + + /* Nothing to do if not running under an SVSM. */ + if (!vmpl) + return; + + /* + * It is very early in the boot and the kernel is running identity + * mapped but without having adjusted the pagetables to where the + * kernel was loaded (physbase), so the get the CA address using + * RIP-relative addressing. + */ + pa =3D (u64)&RIP_REL_REF(boot_svsm_ca_page); + + /* + * Switch over to the boot SVSM CA while the current CA is still + * addressable. There is no GHCB at this point so use the MSR protocol. + * + * SVSM_CORE_REMAP_CA call: + * RAX =3D 0 (Protocol=3D0, CallID=3D0) + * RCX =3D New CA GPA + */ + call.caa =3D __svsm_get_caa(); + call.rax =3D SVSM_CORE_CALL(SVSM_CORE_REMAP_CA); + call.rcx =3D pa; + ret =3D svsm_protocol(&call); + if (ret !=3D SVSM_SUCCESS) + panic("Can't remap the SVSM CA, ret=3D%#x (%d)\n", ret, ret); + + boot_svsm_caa =3D (struct svsm_ca *)pa; + boot_svsm_caa_pa =3D pa; +} + bool __head snp_init(struct boot_params *bp) { struct cc_blob_sev_info *cc_info; @@ -2108,12 +2245,7 @@ bool __head snp_init(struct boot_params *bp) =20 setup_cpuid_table(cc_info); =20 - /* - * Record the SVSM Calling Area address (CAA) if the guest is not - * running at VMPL0. The CA will be used to communicate with the - * SVSM to perform the SVSM services. - */ - setup_svsm_ca(cc_info); + setup_svsm(cc_info); =20 /* * The CC blob will be used later to access the secrets page. Cache @@ -2306,3 +2438,12 @@ void sev_show_status(void) } pr_cont("\n"); } + +void __init snp_remap_svsm_ca(void) +{ + if (!vmpl) + return; + + /* Update the CAA to a proper kernel address */ + boot_svsm_caa =3D &boot_svsm_ca_page; +} diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index 422602f6039b..6155020e4d2d 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -2,7 +2,7 @@ /* * AMD Memory Encryption Support * - * Copyright (C) 2016 Advanced Micro Devices, Inc. + * Copyright (C) 2016-2024 Advanced Micro Devices, Inc. * * Author: Tom Lendacky */ @@ -510,6 +510,12 @@ void __init sme_early_init(void) */ x86_init.resources.dmi_setup =3D snp_dmi_setup; } + + /* + * Switch the SVSM CA mapping (if active) from identity mapped to + * kernel mapped. + */ + snp_remap_svsm_ca(); } =20 void __init mem_encrypt_free_decrypted_mem(void) --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2044.outbound.protection.outlook.com [40.107.94.44]) (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 1FC2D16D4D2 for ; Wed, 24 Apr 2024 15:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974355; cv=fail; b=PHtwSEL6pG3heH/UWnAKeDBq5zJSbkV/0ngSaIQf07EOI8nWdAf1rGFu3lTQmmU8kBGX+M24eqgZ7nSjrnn0dTvL3I+wVH+VrH0rQ9Y0Lakm8veG4j8aMNSMC28QQXZv74irlunn5gwicYZUuLAaf3TXnF1JjP9xIgSbTbmzNnw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974355; c=relaxed/simple; bh=sCcOo5h4Z+8EsVu4ndMgeSUqeVaeUN9UzDUDT0H6lbY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FeS3sTX3l/IwjFkQazPEonsKI5pzqlMO7cWoH1r4HYK0uHjq6gOfWQFC8oTfuKMOwrIWD2GC50Gn1pUdwQaAg0pdEDBgiI/m93gxcfU6DBc3NKAgp+9aFqdZty9NiE1+56lZkoga7heWVery4r/y3SQqCDOCRn0PDphNhJPM654= 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=ysNm+zs+; arc=fail smtp.client-ip=40.107.94.44 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="ysNm+zs+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WE4jmMFJciqYyK3tFDvUndckYlbIb8f1yQbUknPYMCwhlj3c/nH1JgGBgxBrWiWVJu3KN81s6/ZQGp+3DJtM+0MQqYHodhX24zOo1Ojkae9SAn4dvmubWZQ0q5Jh75oTtVeg1KYsfppAI2AWFq7oA8I5a/HHX3XmVUWHnZ4g3SCLneTpG9B8o7kqn8Upm0l/jEw2ld6KzcCu9r9DsEJ08Mn05m2cnvDMe3hcbcIrNOdmqxJFv+7g2n81KUSjRwxwTacv1n/j8Yy1270T0P/+Edo2Kysm9crqGwIyMzfFqXrM/FK7knqqbquPGnoLj7t9rqY/yDrLbjDDo6/XFHHdqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=HlYJi1OB8n2mSK38q8l9MCV/mrF8TxZGEl/0Xxm9djU=; b=DeJGe4D5NdPEzlGPTWemxi5hiT0/G2U+oxmPVhO2At3cmf3rBH8tTtthdQd2rultBHfRP5YJL6Y5NUVLqiBPaFMKRcz/V7mHyxjcZLg3F+gFKWpsl8HjcBvyohxurmBoMWBB/qwxL2Qvip/Vc74/pE+11TuDGu20EAra6pVltcDNYB2nUKky2Rw8RupYsFKd+rpYSoePTj215EotwfToHUd0SKnLPy8lYFOH7EynX48aSPtFENWqlX61Ww+QRnRzvPUGYyPliC65u7B0lP+rzs1eX65o06BmG970cFexTtztDhw/hVWE/ycGSwp482nI/LKs/BBqMvLoo2Y6aL5SSg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=HlYJi1OB8n2mSK38q8l9MCV/mrF8TxZGEl/0Xxm9djU=; b=ysNm+zs+fYFJHWEeP3n7iFjru3k3SkMbOFL0EvZ0HTgdh6WDWWR6m/9oVtMiAuXQ8BvZPKWTpTwbOrcoGexS9beAh7EMYyhZDCTVyHlQcaQLvy/KMyBQuoQxUiB1xDQMbL7UkP9WMtrVPTeTNzv4UyM00AoHdzm3ss7YrWiYEKQ= Received: from MN2PR22CA0001.namprd22.prod.outlook.com (2603:10b6:208:238::6) by SN7PR12MB7250.namprd12.prod.outlook.com (2603:10b6:806:2aa::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 15:59:10 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:238:cafe::2e) by MN2PR22CA0001.outlook.office365.com (2603:10b6:208:238::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.24 via Frontend Transport; Wed, 24 Apr 2024 15:59:09 +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 MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:59:09 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 10:59:07 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 06/15] x86/sev: Perform PVALIDATE using the SVSM when not at VMPL0 Date: Wed, 24 Apr 2024 10:58:02 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E2:EE_|SN7PR12MB7250:EE_ X-MS-Office365-Filtering-Correlation-Id: 8ec7ae87-eeb3-4b9a-c188-08dc64777a7f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?aB/UlrTvhaJmgkfBsqksTsJt8EGV5EoBeNSqxSa+qjyG/D2zK7xUX4snY2UK?= =?us-ascii?Q?K1CaHR99mIOMtsLhXFC5f4CkY+/gX4jKunTVgnF8rn2mCawyoYkgnskRelgQ?= =?us-ascii?Q?skv2yTQMfa8QlekQumFVC2hS5KXAOq44lICtXITVgHRCa74kWmpUO0s20tsM?= =?us-ascii?Q?5KS66rdf+0gbDCbOteQXkQUOK27E5pTbkTkA5IfmqVTo6eXTVjlqnQyAL0Lv?= =?us-ascii?Q?fAYM7CRlDILm33yY4FLQ08zNIxoCSFjOJ3l8ZTbApQHa3nopi1tZt2Zxl2uZ?= =?us-ascii?Q?xcjFFrw/11E4N/g5UdoeuWl0O6GyBrCP1xkJBD0ILDEKpMggqy3/4u8u/aKN?= =?us-ascii?Q?EG7b/O3y/YDMa9g8gwPy86PWbVGL0w3QCY2o535COodfr6LaHaGxX8GT9MIS?= =?us-ascii?Q?pF2u1nDKZY67g6NWNOXdUpPCxGGqVyoZNIF/MQUPYCNVJjGMqJgYqhqD6Tpj?= =?us-ascii?Q?c9GNVh4s1YAU6IOdXVgaK5HO8k0D/z0XhV2y1dkTq2DOdV6n4lDcwn7juAkx?= =?us-ascii?Q?eJevctBWQS4vpEZ3ApsrsWemGtegjRjm0d3PV7VKD5wJWStK6OZOwTAKuj+I?= =?us-ascii?Q?OvbYwgdxl6m0slW5fSbUjj4eY32BPjnNhZy5VjfRSwVpJ3M7RxQGoh62VlIX?= =?us-ascii?Q?uAz244/jBtANiGdfs4QsggHvUFaWX8BMfTeRiEltEevU4U251pw6jkuyMl9M?= =?us-ascii?Q?HSFAMHsWH6fEqpaleh3YFi+Hn8t82VLEww8kb+iyel0gKAgrFKVS3KxKH/sn?= =?us-ascii?Q?rz1lbukTOE+7FRqct3eGOxJWS7VHHeiLirs+/ke0cuH/LtfEVSEKcGOyG8Ty?= =?us-ascii?Q?Riiu6SIqqbUYeBPEgHwGPEF0DRz3z1cvuOzp4Em5O5njAA8dNJOkhILNduQP?= =?us-ascii?Q?Fg+kaYNQNbF+Y1balZozLkBCcdSIibYppwbVD6U+l34ZUFOO735a02hIFz44?= =?us-ascii?Q?A3UBVOHWn9SQ/9IiCcBC0/joOL0gvIujxdHFhy7PKjSqHEMQiRVhx3zVAxok?= =?us-ascii?Q?jfc57yuS6xhVD0w+Hq7gjDCX27RHsMxn7jfS/E21/JHf4ZWVsvPOAGnhzKKR?= =?us-ascii?Q?a6UO7L5IMM5K1cgPBmfXWbfru84ofYwEOiH1+mKU7PtEFqGNjrX73rpIjmVB?= =?us-ascii?Q?WKKRo+mXTRNJAlx6EiTQhyJWkbrB4RJEYVLPZK4WSccDe2YIhDShm1iSpCTF?= =?us-ascii?Q?lojlHqWBIsR1zduPJLCoChyoOmgp+jtigL5r9gyh6ki2Q/HgM5+w1Nsg6iMU?= =?us-ascii?Q?r9vqqXPA5wO02yLxmNliBcDuYAScyK4NsjupUqszdrzT79HRUNvDOegF3ITH?= =?us-ascii?Q?4p5R4NSzqTowuJEjE9GIzqG18iUMX9S+cak1tfDiv/B79doMlRlS2Xpfti3b?= =?us-ascii?Q?ZxQAfm5W5WtN1zVqhRihuB3UCbMS?= 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:(13230031)(1800799015)(376005)(7416005)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:59:09.8377 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8ec7ae87-eeb3-4b9a-c188-08dc64777a7f 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: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7250 Content-Type: text/plain; charset="utf-8" The PVALIDATE instruction can only be performed at VMPL0. An SVSM will be present when running at VMPL1 or a lower privilege level. When an SVSM is present, use the SVSM_CORE_PVALIDATE call to perform memory validation instead of issuing the PVALIDATE instruction directly. The validation of a single 4K page is now explicitly identified as such in the function name, pvalidate_4k_page(). The pvalidate_pages() function is used for validating 1 or more pages at either 4K or 2M in size. Each function, however, determines whether it can issue the PVALIDATE directly or whether the SVSM needs to be invoked. Signed-off-by: Tom Lendacky Tested-by: Joerg Roedel --- arch/x86/boot/compressed/sev.c | 45 ++++++++- arch/x86/include/asm/sev.h | 22 ++++ arch/x86/kernel/sev-shared.c | 179 ++++++++++++++++++++++++++++++++- arch/x86/kernel/sev.c | 25 +++-- 4 files changed, 253 insertions(+), 18 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index cb771b380a6b..32a1e98ffaa9 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -130,6 +130,34 @@ static bool fault_in_kernel_space(unsigned long addres= s) /* Include code for early handlers */ #include "../../kernel/sev-shared.c" =20 +static struct svsm_ca *__svsm_get_caa(void) +{ + return boot_svsm_caa; +} + +static u64 __svsm_get_caa_pa(void) +{ + return boot_svsm_caa_pa; +} + +static int svsm_protocol(struct svsm_call *call) +{ + struct ghcb *ghcb; + int ret; + + if (boot_ghcb) + ghcb =3D boot_ghcb; + else + ghcb =3D NULL; + + do { + ret =3D ghcb ? __svsm_ghcb_protocol(ghcb, call) + : __svsm_msr_protocol(call); + } while (ret =3D=3D SVSM_ERR_BUSY); + + return ret; +} + bool sev_snp_enabled(void) { return sev_status & MSR_AMD64_SEV_SNP_ENABLED; @@ -146,8 +174,8 @@ static void __page_state_change(unsigned long paddr, en= um psc_op op) * If private -> shared then invalidate the page before requesting the * state change in the RMP table. */ - if (op =3D=3D SNP_PAGE_STATE_SHARED && pvalidate(paddr, RMP_PG_SIZE_4K, 0= )) - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PVALIDATE); + if (op =3D=3D SNP_PAGE_STATE_SHARED) + pvalidate_4k_page(paddr, paddr, 0); =20 /* Issue VMGEXIT to change the page state in RMP table. */ sev_es_wr_ghcb_msr(GHCB_MSR_PSC_REQ_GFN(paddr >> PAGE_SHIFT, op)); @@ -162,8 +190,8 @@ static void __page_state_change(unsigned long paddr, en= um psc_op op) * Now that page state is changed in the RMP table, validate it so that i= t is * consistent with the RMP entry. */ - if (op =3D=3D SNP_PAGE_STATE_PRIVATE && pvalidate(paddr, RMP_PG_SIZE_4K, = 1)) - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PVALIDATE); + if (op =3D=3D SNP_PAGE_STATE_PRIVATE) + pvalidate_4k_page(paddr, paddr, 1); } =20 void snp_set_page_private(unsigned long paddr) @@ -256,6 +284,15 @@ void sev_es_shutdown_ghcb(void) if (!sev_es_check_cpu_features()) error("SEV-ES CPU Features missing."); =20 + /* + * The boot_ghcb value is used to determine whether to use the GHCB MSR + * protocol or the GHCB shared page to perform a GHCB request. Since the + * GHCB page is being changed to encrypted, it can't be used to perform + * GHCB requests. Clear the boot_ghcb variable so that the GHCB MSR + * protocol is used to change the GHCB page over to an encrypted page. + */ + boot_ghcb =3D NULL; + /* * GHCB Page must be flushed from the cache and mapped encrypted again. * Otherwise the running kernel will see strange cache effects when diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 8f180fd3cbf0..e6f1ed3f6ce3 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -187,6 +187,27 @@ struct svsm_ca { #define SVSM_ERR_INVALID_PARAMETER 0x80000005 #define SVSM_ERR_INVALID_REQUEST 0x80000006 #define SVSM_ERR_BUSY 0x80000007 +#define SVSM_PVALIDATE_FAIL_SIZEMISMATCH 0x80001006 + +/* + * The SVSM PVALIDATE related structures + */ +struct svsm_pvalidate_entry { + u64 page_size : 2, + action : 1, + ignore_cf : 1, + rsvd : 8, + pfn : 52; +}; + +struct svsm_pvalidate_call { + u16 entries; + u16 next; + + u8 rsvd1[4]; + + struct svsm_pvalidate_entry entry[]; +}; =20 /* * SVSM protocol structure @@ -207,6 +228,7 @@ struct svsm_call { =20 #define SVSM_CORE_CALL(x) ((0ULL << 32) | (x)) #define SVSM_CORE_REMAP_CA 0 +#define SVSM_CORE_PVALIDATE 1 =20 #ifdef CONFIG_AMD_MEM_ENCRYPT extern void __sev_es_ist_enter(struct pt_regs *regs); diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index 6f57eb804e70..b415b10a0823 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -40,6 +40,9 @@ static u8 vmpl __ro_after_init; static struct svsm_ca *boot_svsm_caa __ro_after_init; static u64 boot_svsm_caa_pa __ro_after_init; =20 +static struct svsm_ca *__svsm_get_caa(void); +static u64 __svsm_get_caa_pa(void); + /* I/O parameters for CPUID-related helpers */ struct cpuid_leaf { u32 fn; @@ -102,6 +105,8 @@ static u32 cpuid_std_range_max __ro_after_init; static u32 cpuid_hyp_range_max __ro_after_init; static u32 cpuid_ext_range_max __ro_after_init; =20 +static int svsm_protocol(struct svsm_call *call); + static bool __init sev_es_check_cpu_features(void) { if (!has_cpuflag(X86_FEATURE_RDRAND)) { @@ -1186,7 +1191,65 @@ static void __head setup_cpuid_table(const struct cc= _blob_sev_info *cc_info) } } =20 -static void pvalidate_pages(struct snp_psc_desc *desc) +static int base_pvalidate_4k_page(unsigned long vaddr, bool validate) +{ + return pvalidate(vaddr, RMP_PG_SIZE_4K, validate); +} + +static int svsm_pvalidate_4k_page(unsigned long paddr, bool validate) +{ + struct svsm_pvalidate_call *pvalidate_call; + struct svsm_call call =3D {}; + u64 pvalidate_call_pa; + unsigned long flags; + int ret; + + /* + * This can be called very early in the boot, use native functions in + * order to avoid paravirt issues. + */ + flags =3D native_save_fl(); + if (flags & X86_EFLAGS_IF) + native_irq_disable(); + + call.caa =3D __svsm_get_caa(); + + pvalidate_call =3D (struct svsm_pvalidate_call *)call.caa->svsm_buffer; + pvalidate_call_pa =3D __svsm_get_caa_pa() + offsetof(struct svsm_ca, svsm= _buffer); + + pvalidate_call->entries =3D 1; + pvalidate_call->next =3D 0; + pvalidate_call->entry[0].page_size =3D RMP_PG_SIZE_4K; + pvalidate_call->entry[0].action =3D validate; + pvalidate_call->entry[0].ignore_cf =3D 0; + pvalidate_call->entry[0].pfn =3D paddr >> PAGE_SHIFT; + + /* Protocol 0, Call ID 1 */ + call.rax =3D SVSM_CORE_CALL(SVSM_CORE_PVALIDATE); + call.rcx =3D pvalidate_call_pa; + + ret =3D svsm_protocol(&call); + + if (flags & X86_EFLAGS_IF) + native_irq_enable(); + + return ret; +} + +static void pvalidate_4k_page(unsigned long vaddr, unsigned long paddr, bo= ol validate) +{ + int ret; + + ret =3D vmpl ? svsm_pvalidate_4k_page(paddr, validate) + : base_pvalidate_4k_page(vaddr, validate); + + if (ret) { + WARN(1, "Failed to validate address 0x%lx ret %d", vaddr, ret); + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PVALIDATE); + } +} + +static void base_pvalidate_pages(struct snp_psc_desc *desc) { struct psc_entry *e; unsigned long vaddr; @@ -1220,6 +1283,120 @@ static void pvalidate_pages(struct snp_psc_desc *de= sc) } } =20 +static void svsm_pvalidate_pages(struct snp_psc_desc *desc) +{ + struct svsm_pvalidate_call *pvalidate_call; + struct svsm_pvalidate_entry *pe; + unsigned int call_count, i; + struct svsm_call call =3D {}; + u64 pvalidate_call_pa; + struct psc_entry *e; + unsigned long flags; + unsigned long vaddr; + bool action; + int ret; + + /* + * This can be called very early in the boot, use native functions in + * order to avoid paravirt issues. + */ + flags =3D native_save_fl(); + if (flags & X86_EFLAGS_IF) + native_irq_disable(); + + call.caa =3D __svsm_get_caa(); + + pvalidate_call =3D (struct svsm_pvalidate_call *)call.caa->svsm_buffer; + pvalidate_call_pa =3D __svsm_get_caa_pa() + offsetof(struct svsm_ca, svsm= _buffer); + + /* Calculate how many entries the CA buffer can hold */ + call_count =3D sizeof(call.caa->svsm_buffer); + call_count -=3D offsetof(struct svsm_pvalidate_call, entry); + call_count /=3D sizeof(pvalidate_call->entry[0]); + + /* Protocol 0, Call ID 1 */ + call.rax =3D SVSM_CORE_CALL(SVSM_CORE_PVALIDATE); + call.rcx =3D pvalidate_call_pa; + + pvalidate_call->entries =3D 0; + pvalidate_call->next =3D 0; + + for (i =3D 0; i <=3D desc->hdr.end_entry; i++) { + e =3D &desc->entries[i]; + pe =3D &pvalidate_call->entry[pvalidate_call->entries]; + + pe->page_size =3D e->pagesize ? RMP_PG_SIZE_2M : RMP_PG_SIZE_4K; + pe->action =3D e->operation =3D=3D SNP_PAGE_STATE_PRIVATE; + pe->ignore_cf =3D 0; + pe->pfn =3D e->gfn; + + pvalidate_call->entries++; + if (pvalidate_call->entries < call_count && i !=3D desc->hdr.end_entry) + continue; + + ret =3D svsm_protocol(&call); + if (ret =3D=3D SVSM_PVALIDATE_FAIL_SIZEMISMATCH && + pvalidate_call->entry[pvalidate_call->next].page_size =3D=3D RMP_PG_= SIZE_2M) { + u64 pfn, pfn_end; + + /* + * The "next" field is the index of the failed entry. Calculate the + * index of the entry after the failed entry before the fields are + * cleared so that processing can continue on from that point (take + * into account the for loop adding 1 to the entry). + */ + i -=3D pvalidate_call->entries - pvalidate_call->next; + i +=3D 1; + + action =3D pvalidate_call->entry[pvalidate_call->next].action; + pfn =3D pvalidate_call->entry[pvalidate_call->next].pfn; + pfn_end =3D pfn + 511; + + pvalidate_call->entries =3D 0; + pvalidate_call->next =3D 0; + for (; pfn <=3D pfn_end; pfn++) { + pe =3D &pvalidate_call->entry[pvalidate_call->entries]; + + pe->page_size =3D RMP_PG_SIZE_4K; + pe->action =3D action; + pe->ignore_cf =3D 0; + pe->pfn =3D pfn; + + pvalidate_call->entries++; + if (pvalidate_call->entries < call_count && pfn !=3D pfn_end) + continue; + + ret =3D svsm_protocol(&call); + if (ret !=3D SVSM_SUCCESS) + break; + + pvalidate_call->entries =3D 0; + pvalidate_call->next =3D 0; + } + } + + if (ret !=3D SVSM_SUCCESS) { + pe =3D &pvalidate_call->entry[pvalidate_call->next]; + vaddr =3D (unsigned long)pfn_to_kaddr(pe->pfn); + + WARN(1, "Failed to validate address %lx ret=3D%#x (%d)", vaddr, ret, re= t); + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PVALIDATE); + } + + pvalidate_call->entries =3D 0; + pvalidate_call->next =3D 0; + } + + if (flags & X86_EFLAGS_IF) + native_irq_enable(); +} + +static void pvalidate_pages(struct snp_psc_desc *desc) +{ + vmpl ? svsm_pvalidate_pages(desc) + : base_pvalidate_pages(desc); +} + static int vmgexit_psc(struct ghcb *ghcb, struct snp_psc_desc *desc) { int cur_entry, end_entry, ret =3D 0; diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 21f3cc40d662..49cf4a6f1f31 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -622,6 +622,12 @@ static struct svsm_ca *__svsm_get_caa(void) : boot_svsm_caa; } =20 +static u64 __svsm_get_caa_pa(void) +{ + return sev_cfg.cas_initialized ? this_cpu_read(svsm_caa_pa) + : boot_svsm_caa_pa; +} + static noinstr void __sev_put_ghcb(struct ghcb_state *state) { struct sev_es_runtime_data *data; @@ -792,7 +798,6 @@ early_set_pages_state(unsigned long vaddr, unsigned lon= g paddr, { unsigned long paddr_end; u64 val; - int ret; =20 vaddr =3D vaddr & PAGE_MASK; =20 @@ -800,12 +805,9 @@ early_set_pages_state(unsigned long vaddr, unsigned lo= ng paddr, paddr_end =3D paddr + (npages << PAGE_SHIFT); =20 while (paddr < paddr_end) { - if (op =3D=3D SNP_PAGE_STATE_SHARED) { - /* Page validation must be rescinded before changing to shared */ - ret =3D pvalidate(vaddr, RMP_PG_SIZE_4K, false); - if (WARN(ret, "Failed to validate address 0x%lx ret %d", paddr, ret)) - goto e_term; - } + /* Page validation must be rescinded before changing to shared */ + if (op =3D=3D SNP_PAGE_STATE_SHARED) + pvalidate_4k_page(vaddr, paddr, false); =20 /* * Use the MSR protocol because this function can be called before @@ -827,12 +829,9 @@ early_set_pages_state(unsigned long vaddr, unsigned lo= ng paddr, paddr, GHCB_MSR_PSC_RESP_VAL(val))) goto e_term; =20 - if (op =3D=3D SNP_PAGE_STATE_PRIVATE) { - /* Page validation must be performed after changing to private */ - ret =3D pvalidate(vaddr, RMP_PG_SIZE_4K, true); - if (WARN(ret, "Failed to validate address 0x%lx ret %d", paddr, ret)) - goto e_term; - } + /* Page validation must be performed after changing to private */ + if (op =3D=3D SNP_PAGE_STATE_PRIVATE) + pvalidate_4k_page(vaddr, paddr, true); =20 vaddr +=3D PAGE_SIZE; paddr +=3D PAGE_SIZE; --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2067.outbound.protection.outlook.com [40.107.220.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AC0816D4DF for ; Wed, 24 Apr 2024 15:59:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974362; cv=fail; b=YVepQ3Xpf59ZdRGHCI5ipEypOBiQBXDybrD+J2/txYqLzkB2mduaXPKfyBHqfROdKTK2IJyP3EEPTSK25Tnc0RnXMLLreClEqnyJFxXFgEHmzwqEWs+kv7mdb09ngKumnuiHNGgqqfTp07BPL/v7Jk+tX0iFkio2z+HFeghp8dk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974362; c=relaxed/simple; bh=g0lvhI16/x1l6lhdM7mujOiwopYTLwY1K46pX4MklJI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QMLt/ifvglqt+4U7XM1BXrTwloSzrU71bMsdk+jqibtqsv9mbdC46OcgeNQbgMsjOmsCkQKJfscPf/LwRqI22PD3TfWfHUPv8yHpf52JO8BHvkvigoYKAu4OnzDVy4yQ7pcWt8O6N+c1eNxfh5TLf0gAENX6PFNN1x6651FqKZU= 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=jwnfxq05; arc=fail smtp.client-ip=40.107.220.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="jwnfxq05" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c7sOIXe/WjGWpmxzTYxGvfX0KNs/RtVlWSY96jqjeCaMCLBQ5T0ILNqxgBY1Vik4YHw7FFtIdQBfR/VxDjYOpPyJPhGG3M2N2/OerTtdb1r6tHm0QrIjNWSrTQrwdESi0PRH3APOfFLtWBwyUKpNX05hQIuPs4fl53HGinGkxVV0xhB6VwJlLa+wdE7LKiKsi/VgJPfhThlcTDkox6Pc8v9zGCCFgvdr8eOzXAKrqUIgekh9O+scL1/friQIXD+kue8FMvSce+ezIvrde3eRU6c2K4vqtf4pp9tIfovTl07pt3QYfiomWLwHIfO/P2u3aJRsm61v2rg4kXr/ZOyi8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=68XD4w4zy2aQ37wXDm6eqki0dDbqxQElwvNiTKlVfis=; b=i8IFQT2VjJgMRt06JJsP3NzZ+JTDTaelq/wvPdB2XlUI82ve/o+0AlEWGvx96G6+JkrgDuRdJ7XeRtXVDF7aqG398GIGNePuNIKep88jPbNSwQHpphRTOj/4hu69ZZi8Zhd1NwkNFf4qqXm6SO7Sn1Xg9SxllM3nj0hX03sNa5IH12SyOCow9oZNAStkseXnuZXXm23tsf9tRFtKVXdpXSGvDvo1AN67bXxHJ37oXPExKwnofkAuJsEP8s2rUCTGXwB/v627iN/jA0gEHE8BfiFGU1heeWz1UT/QoKad0BiamwmXKXXz1VkZi8eyfPUO9Fla3dNHf1EUy2OBwzAVXA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=68XD4w4zy2aQ37wXDm6eqki0dDbqxQElwvNiTKlVfis=; b=jwnfxq05Ox0vERDUBhG5ARj6QTtm4WbVehA1PGCq+U2Na8h4QSWdKXr1uc34uWZpaOMye4+4L109fLDFTEqWTblcWdEv+RpEUVkuVuvGrRGCjTOPOxQFbdhik2JEnsayiBl+x7LJ5036s3BEuEgtwQjjcuJB0p3ULfXyg7GmowU= Received: from BL1PR13CA0014.namprd13.prod.outlook.com (2603:10b6:208:256::19) by BY5PR12MB4065.namprd12.prod.outlook.com (2603:10b6:a03:202::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.46; Wed, 24 Apr 2024 15:59:16 +0000 Received: from MN1PEPF0000F0DE.namprd04.prod.outlook.com (2603:10b6:208:256:cafe::d5) by BL1PR13CA0014.outlook.office365.com (2603:10b6:208:256::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22 via Frontend Transport; Wed, 24 Apr 2024 15:59:15 +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 MN1PEPF0000F0DE.mail.protection.outlook.com (10.167.242.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:59:15 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 10:59:14 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 07/15] x86/sev: Use the SVSM to create a vCPU when not in VMPL0 Date: Wed, 24 Apr 2024 10:58:03 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0DE:EE_|BY5PR12MB4065:EE_ X-MS-Office365-Filtering-Correlation-Id: 612b44eb-d6fd-4364-7678-08dc64777e12 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?WbB/4X2Rh3aPY7uLJ5Uf5eguMwS4gt4U7cGWC3NqLsjbDhOCt0Jf16/e7Len?= =?us-ascii?Q?bI3loSLRwuE/dsH75nLeq3rq4vHXm699D4uRbevqlDYs019sux/nLI+VnQ/U?= =?us-ascii?Q?Gw7kuAQZZk6TKvKs3k7V8nD8kINa2aV32NjvhQ9Dul7U299e7tZxmUEWdnlK?= =?us-ascii?Q?oX7gRFWqytSoRqv4ZK291eRz3adRfT1UJz7ejvaPsoBARmYQBvYq/dBR88HZ?= =?us-ascii?Q?uGoOQ589dPGnX5jDPXL8cTNWyVXojBryJZJtobTtcr3pHSIRKhGfeaBRHSMM?= =?us-ascii?Q?fSKltl05vL5lfbfLDKnFj5Nyv0N2iQUNQtsI4qUGpOwz61bhvQgfYeDw51vf?= =?us-ascii?Q?whZcNr6lk+GO1xP9OfPS5cqO8M343j+1SI/kI+g9UsgMp6+j5Gj3sAqSnATL?= =?us-ascii?Q?VlSyHlhZAQdXSrYVx2wHuMLjtj8uhdIO4buOqBaNMkOjlhN8ICec2HD5BBFd?= =?us-ascii?Q?srLWypLX36SHo8R0kZyw7hosBheFWIl+QFeLVD8kyS/ceDpFzX/Qxopr6Yoe?= =?us-ascii?Q?Ylo/zT7L66wiJ/uIiyWzUXmAJd6qScUNVRj4boI9WsBHgZDTc9kozGx08ocx?= =?us-ascii?Q?eLMvOjZJts3fGvJqZ+19+o5ajsPg2p/ck6/2DzMmO2BsHVZTbqWZGmv1Xgit?= =?us-ascii?Q?Spp2ri3wGG8IkCYnw4FipEuBmuRq7Ujb9no0T5fEYbomiQb758v3eZx47UVb?= =?us-ascii?Q?+jdZ/uv2AdU/uUO1YufPqqHqpswUa0dfhrBGxRHuxWJQ2RpiMh5+9fpfagG0?= =?us-ascii?Q?7ohBhqjVr1qNyCpuGltwuQFuZxMeiJLT4A3unJqi/naPiBvnSRqR0EG0ec3U?= =?us-ascii?Q?pT8qN0DHzyQAcgBw7r7/xzaB9lyt7kjFEiP9Bst8CdHyJXq98EAoOiCHrmxB?= =?us-ascii?Q?TDP8QOiNdZpO0XhHtzfUmi0ZhWow5zK/cbBZ4dlkA2TUoTS5oquxwo2E7Akc?= =?us-ascii?Q?6kj6XzU0gn8HDOin984cUPikU9lxUyufTCwMstslmj8lwlEO6XLALV3jgpsc?= =?us-ascii?Q?J9vrOf3Ljj+z2aUtsa7W5U65KB/SL4/FtEGW9shAIvLdILpcSq1yRH4zkIqo?= =?us-ascii?Q?wTOLLStUdQOOLfOv3Q7v47W8TzKXIQi8EzmOB4NY8NhawZFLk5H6M8w5Wmb7?= =?us-ascii?Q?JMyASsBfwc1ItYtpceyt/8sM1BKwwlMu4JVpcYesRPfw6fNmm+gw205eNJfQ?= =?us-ascii?Q?X2SZhIxFQYghqeQVSn7PgxxHuFGThmA+GK8HlvcH5dAV2qh7RbU3lhbMkqoi?= =?us-ascii?Q?l6fN9c2EDSoQkXpZcXBr4nDQTzO4dCggWUNhm0EGTXUb+/bqcKj9XQhvSuZd?= =?us-ascii?Q?ayLHeFxYA5apKcYJDNgUbrdCTXUI2Plf5I0Pk/j0K+KxcQg1ghqPdp+xsqtk?= =?us-ascii?Q?/UiOZiBbHRGN9Hmz98de6nHKyA6X?= 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:(13230031)(36860700004)(1800799015)(376005)(7416005)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:59:15.8324 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 612b44eb-d6fd-4364-7678-08dc64777e12 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: MN1PEPF0000F0DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4065 Content-Type: text/plain; charset="utf-8" Using the RMPADJUST instruction, the VSMA attribute can only be changed at VMPL0. An SVSM will be present when running at VMPL1 or a lower privilege level. When an SVSM is present, use the SVSM_CORE_CREATE_VCPU call or the SVSM_CORE_DESTROY_VCPU call to perform VMSA attribute changes. Use the VMPL level supplied by the SVSM for the VMSA when starting the AP. Signed-off-by: Tom Lendacky Tested-by: Joerg Roedel --- arch/x86/include/asm/sev.h | 2 ++ arch/x86/kernel/sev.c | 60 +++++++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index e6f1ed3f6ce3..a7312b936d16 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -229,6 +229,8 @@ struct svsm_call { #define SVSM_CORE_CALL(x) ((0ULL << 32) | (x)) #define SVSM_CORE_REMAP_CA 0 #define SVSM_CORE_PVALIDATE 1 +#define SVSM_CORE_CREATE_VCPU 2 +#define SVSM_CORE_DELETE_VCPU 3 =20 #ifdef CONFIG_AMD_MEM_ENCRYPT extern void __sev_es_ist_enter(struct pt_regs *regs); diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 49cf4a6f1f31..3f4342b31736 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -995,7 +995,7 @@ void snp_accept_memory(phys_addr_t start, phys_addr_t e= nd) set_pages_state(vaddr, npages, SNP_PAGE_STATE_PRIVATE); } =20 -static int snp_set_vmsa(void *va, bool vmsa) +static int base_snp_set_vmsa(void *va, bool vmsa) { u64 attrs; =20 @@ -1013,6 +1013,40 @@ static int snp_set_vmsa(void *va, bool vmsa) return rmpadjust((unsigned long)va, RMP_PG_SIZE_4K, attrs); } =20 +static int svsm_snp_set_vmsa(void *va, void *caa, int apic_id, bool vmsa) +{ + struct svsm_call call =3D {}; + unsigned long flags; + int ret; + + local_irq_save(flags); + + call.caa =3D this_cpu_read(svsm_caa); + call.rcx =3D __pa(va); + + if (vmsa) { + /* Protocol 0, Call ID 2 */ + call.rax =3D SVSM_CORE_CALL(SVSM_CORE_CREATE_VCPU); + call.rdx =3D __pa(caa); + call.r8 =3D apic_id; + } else { + /* Protocol 0, Call ID 3 */ + call.rax =3D SVSM_CORE_CALL(SVSM_CORE_DELETE_VCPU); + } + + ret =3D svsm_protocol(&call); + + local_irq_restore(flags); + + return ret; +} + +static int snp_set_vmsa(void *va, void *caa, int apic_id, bool vmsa) +{ + return vmpl ? svsm_snp_set_vmsa(va, caa, apic_id, vmsa) + : base_snp_set_vmsa(va, vmsa); +} + #define __ATTR_BASE (SVM_SELECTOR_P_MASK | SVM_SELECTOR_S_MASK) #define INIT_CS_ATTRIBS (__ATTR_BASE | SVM_SELECTOR_READ_MASK | SVM_SELEC= TOR_CODE_MASK) #define INIT_DS_ATTRIBS (__ATTR_BASE | SVM_SELECTOR_WRITE_MASK) @@ -1044,11 +1078,11 @@ static void *snp_alloc_vmsa_page(int cpu) return page_address(p + 1); } =20 -static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa) +static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa, int apic_id) { int err; =20 - err =3D snp_set_vmsa(vmsa, false); + err =3D snp_set_vmsa(vmsa, NULL, apic_id, false); if (err) pr_err("clear VMSA page failed (%u), leaking page\n", err); else @@ -1059,6 +1093,7 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsign= ed long start_ip) { struct sev_es_save_area *cur_vmsa, *vmsa; struct ghcb_state state; + struct svsm_ca *caa; unsigned long flags; struct ghcb *ghcb; u8 sipi_vector; @@ -1105,6 +1140,12 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsig= ned long start_ip) if (!vmsa) return -ENOMEM; =20 + /* + * If an SVSM is present, then the SVSM CAA per-CPU variable will + * have a value, otherwise it will be NULL. + */ + caa =3D per_cpu(svsm_caa, cpu); + /* CR4 should maintain the MCE value */ cr4 =3D native_read_cr4() & X86_CR4_MCE; =20 @@ -1152,11 +1193,11 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsi= gned long start_ip) * VMPL level * SEV_FEATURES (matches the SEV STATUS MSR right shifted 2 bits) */ - vmsa->vmpl =3D 0; + vmsa->vmpl =3D vmpl; vmsa->sev_features =3D sev_status >> 2; =20 /* Switch the page over to a VMSA page now that it is initialized */ - ret =3D snp_set_vmsa(vmsa, true); + ret =3D snp_set_vmsa(vmsa, caa, apic_id, true); if (ret) { pr_err("set VMSA page failed (%u)\n", ret); free_page((unsigned long)vmsa); @@ -1172,7 +1213,10 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsig= ned long start_ip) vc_ghcb_invalidate(ghcb); ghcb_set_rax(ghcb, vmsa->sev_features); ghcb_set_sw_exit_code(ghcb, SVM_VMGEXIT_AP_CREATION); - ghcb_set_sw_exit_info_1(ghcb, ((u64)apic_id << 32) | SVM_VMGEXIT_AP_CREAT= E); + ghcb_set_sw_exit_info_1(ghcb, + ((u64)apic_id << 32) | + ((u64)vmpl << 16) | + SVM_VMGEXIT_AP_CREATE); ghcb_set_sw_exit_info_2(ghcb, __pa(vmsa)); =20 sev_es_wr_ghcb_msr(__pa(ghcb)); @@ -1190,13 +1234,13 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsi= gned long start_ip) =20 /* Perform cleanup if there was an error */ if (ret) { - snp_cleanup_vmsa(vmsa); + snp_cleanup_vmsa(vmsa, apic_id); vmsa =3D NULL; } =20 /* Free up any previous VMSA page */ if (cur_vmsa) - snp_cleanup_vmsa(cur_vmsa); + snp_cleanup_vmsa(cur_vmsa, apic_id); =20 /* Record the current VMSA page */ per_cpu(sev_vmsa, cpu) =3D vmsa; --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2049.outbound.protection.outlook.com [40.107.93.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0135616D4DF for ; Wed, 24 Apr 2024 15:59:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974370; cv=fail; b=iiMgOB8/0zY8/cHm2U4r3JQfWMS+4Svne1HEAfJkfOx0uqlVOZzLtrDZDt6InLApFatR9jqPy6yPtwZT3RDllgE/zXMqTOXISfJT0zbOoNtBoDagEZjZ97DjMm9US7UKaZczK9P3dvcueHjX6DauNu0PZGefpkfzFd4O8bRrqj4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974370; c=relaxed/simple; bh=JhAdD1wMcgWO6XIuEnFwVsj2aXgmWch6vopvUUiVyyc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uoNv71HADb4dfFcDwJIlNjynBTTbsAySlH4k8XWObLPoYrei3HogXmHmeAVfO5IyHNWFJHtuFuBoWjgjF7AwLusFerUos4U/z17c3UWqSWpwMMhUQuppO+fMbSWz57cztFXfg27KFl3yagZmqwyXvs/3qHLdgIs3diMI4SX7KFc= 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=a/Zd+kLV; arc=fail smtp.client-ip=40.107.93.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="a/Zd+kLV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CDAVogOjkKs1MeuiNcIgg71JrE4CY+bRt6lWq1H4jvfdR1H7S3Vfir3sdI4f+/m0ZZY2X8gMquy3ASjKEtnm6xwGc6m5hwcfHI5GHcXFc8eqV76gM4se2jLYn9M8v1X531T1rIEL0uJ5LcYv7INX6K50ZBq5UOrk0rkFTu7TDUFZoS+TfPJIj6UkBtQD+K2onF/AVaTl3XKpM93mUZnTuqiP0ehOL/HWEQWWwBiikUCTs+b0DxdcskMsmbd5JqPelgi3CA1I0DW5UAfW2QrBRHos1N3OtVJNgoI6n5K3AJ0O5UdT+RhD0Mton25iI6oJqCpUZzaztxcANatucrm7Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=4K3CwHj8lUBipV0Su0kgRY2TCUaYltx9lZIDJlMISiw=; b=Gkz1WMQUZAQDPjsrBG3fT5DeBluhyL6nEwFzYNZ1kad5iO4enC/EMh1oWlbjYORlGoRj84CyCJ66EkFJ021CKa6kikFqBwqt+D9fHeknwu2cdUU5P+/GfddNKeAjgAdo9APWBdBuuhguOt0PO0RdUTHmfNZ/6c5ctwXQnR9QC9Z2pwjytKh4PqwJNU4iM5AfHxM/QoSMkLafvmUxffJX0gZXx5OVl0PKsbSqGi0biSTdcgJEYjcTMB35lUJBtvNgRVkl21tl793O/ASrgpEtC+HwrrQ4slEphxZnTZmOHchZx584rfB9cBIa7lGMEXjW/EOME4uLxoM1QY2Q046oGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=4K3CwHj8lUBipV0Su0kgRY2TCUaYltx9lZIDJlMISiw=; b=a/Zd+kLVQ5Hows3UvJxT0nnkoE2jEw81YTGUca4dOcaNK8i1thHJ8kz/nAbPGNQ10Kg7hmJc39TWaVS7G55fhByZMYP3cZOAQlpQV1PXhEEAQzk6dlF9b9CeNZ6o7VWRRkk7B07cjtdNhrSSBEcrdHNuV8x4R1RdX4gnTA2/FkA= Received: from MN2PR22CA0021.namprd22.prod.outlook.com (2603:10b6:208:238::26) by DM4PR12MB6375.namprd12.prod.outlook.com (2603:10b6:8:a2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 15:59:23 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:238:cafe::2b) by MN2PR22CA0021.outlook.office365.com (2603:10b6:208:238::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22 via Frontend Transport; Wed, 24 Apr 2024 15:59:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:59:22 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 10:59:22 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 08/15] x86/sev: Provide SVSM discovery support Date: Wed, 24 Apr 2024 10:58:04 -0500 Message-ID: <0b460ba621d39fda47694332f09301b440619efc.1713974291.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E2:EE_|DM4PR12MB6375:EE_ X-MS-Office365-Filtering-Correlation-Id: b2e670ea-64c9-4117-b974-08dc6477824d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?L5pG56aI+kruH1sSsb2+f0JLZbXd+HYyqhJ7pMaQTSag/ionZIVPMu0Z01gu?= =?us-ascii?Q?cB4r7RogQXw19GPnHGZ+T7FfgHf9QSTLtKR41RT/BjIdv+G/QS3mM4qTskpQ?= =?us-ascii?Q?VqN9f+D0vlJKv4Ds2vMapIHJlum0lOOOmwyD8RylxodLKw3/gflWs776nstv?= =?us-ascii?Q?wDNfxTW3jWy0A8PLyGeSLxmZjkbJXM8BNBXehrxigo07fQsq2Xh+UK5Z8gvl?= =?us-ascii?Q?dLmT4ATxg6Y9mBcFiNu5ieYc8CTfI6wEfUFt1gfFYxDPFQUCZDixX7Itjg+p?= =?us-ascii?Q?ZFdawXxMentwO3Y/ox9ZEt3dHcyvljkiYP3S1DHMgVzE7EGnwJCU7Qtyr1EB?= =?us-ascii?Q?tjM4/lujZXYrjwRzPJP6GTl7ijhzzz+Fmb/xRDnVRhw16qWocqpeAYY4Yz7n?= =?us-ascii?Q?RIFOrZAEPSjsK7s+FHDMhf1FnGyfvLWiIk9lJP4NSjou+dz8mIBVWhn9a5Nk?= =?us-ascii?Q?AG3ENxxCNMKr7MKlRvjWCt3r9pQWiAl0asYO4v3fQ7wxP6WYxhpEGwtghZPM?= =?us-ascii?Q?SQUEcPfgZ2tt6ObPBPJsw3AmBzb64K1KfNZpfSKHP53cT8Ndtsm5Oovzns8R?= =?us-ascii?Q?xyuBJ57Gv/vj/CkrzyV+2w7UpAomroVaJfdIoNF1kiMXwVGfyP9P7TDLFW65?= =?us-ascii?Q?cTvJ22oxsPRLeIMdEz99GWR3aKy+TsgzXG3cpvSkBh7IiU849TumaL59m3Tu?= =?us-ascii?Q?HEwQM1V+ErwzbSQYP1dEbBxz0v8M6n2zRyK7xpl1AUEtmVB8PdcXSVycsqZb?= =?us-ascii?Q?XEKvPP82JGs/n5daSUM/rIJQ2cmKm7USQR/SRHOi2btJK2HnC3gI9+5wMfcH?= =?us-ascii?Q?Hb/ccEeZBhVgnQ1QmOUNIMBOXLpO3PjbLtN8fVMtu/fVqn2Vla8R9sxHtx1B?= =?us-ascii?Q?7z3aUazbqvpH2pSnCrbnh0G49HmKu7Xs0ATTp/KDtW1XS5vNn0bLzI5jmd6q?= =?us-ascii?Q?wnWzouHyv02nKZSI9ZZBLd6hXENES4dTDn9x+jeE59EbPt+O0XajdIw4FCHo?= =?us-ascii?Q?ENLnEn4VZTMNLKvr9Uxb4LkMvjiqqUEdY4rg4rviTvNItdMjeJcWvT/jrNb1?= =?us-ascii?Q?2dXJQt5FUC/SmtQOY8zZk5z8yB1bEIaIdBv0gSslmiUbNIi+iFXqJEsidv9d?= =?us-ascii?Q?1h0UEc3vW5Nk35prRmFg2wxuCtA3ANF41DEIpkvxu2EXUeNfeOjKEYO5mido?= =?us-ascii?Q?SCazqm3BCazER+oOnJXtWEgO5V40JB2FdlccOkNl9LlDuSV+XkxYNvqtmXBV?= =?us-ascii?Q?zoxBWMvzwm2P9+XgpxmjexazyV1dsv1mpIbBaCzgT/nWfy1luXzooStsnAiV?= =?us-ascii?Q?WJmC17FCvT6XDopVgWQimKqZ6yO3tj6hOWK00jwkp5SA3IYRyQb1/TXZYBtX?= =?us-ascii?Q?v4a1zlM=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:(13230031)(1800799015)(36860700004)(7416005)(376005)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:59:22.9316 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2e670ea-64c9-4117-b974-08dc6477824d 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: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6375 Content-Type: text/plain; charset="utf-8" The SVSM specification documents an alternative method of discovery for the SVSM using a reserved CPUID bit and a reserved MSR. For the CPUID support, the SNP CPUID table is updated to set bit 28 of the EAX register of the 0x8000001f leaf when an SVSM is present. This bit has been reserved for use in this capacity. For the MSR support, a new reserved MSR 0xc001f000 has been defined. A #VC should be generated when accessing this MSR. The #VC handler is expected to ignore writes to this MSR and return the physical calling area address (CAA) on reads of this MSR. Signed-off-by: Tom Lendacky Tested-by: Joerg Roedel --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/kernel/sev-shared.c | 11 +++++++++++ arch/x86/kernel/sev.c | 17 +++++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index 3c7434329661..a17a81b3189b 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -446,6 +446,7 @@ #define X86_FEATURE_V_TSC_AUX (19*32+ 9) /* "" Virtual TSC_AUX */ #define X86_FEATURE_SME_COHERENT (19*32+10) /* "" AMD hardware-enforced ca= che coherency */ #define X86_FEATURE_DEBUG_SWAP (19*32+14) /* AMD SEV-ES full debug state = swap support */ +#define X86_FEATURE_SVSM_PRESENT (19*32+28) /* "" SNP SVSM is present */ =20 /* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word = 20 */ #define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0) /* "" No Nested Data Brea= kpoints */ diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-in= dex.h index e022e6eb766c..45ffa27569f4 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -660,6 +660,8 @@ #define MSR_AMD64_RMP_BASE 0xc0010132 #define MSR_AMD64_RMP_END 0xc0010133 =20 +#define MSR_SVSM_CAA 0xc001f000 + /* AMD Collaborative Processor Performance Control MSRs */ #define MSR_AMD_CPPC_CAP1 0xc00102b0 #define MSR_AMD_CPPC_ENABLE 0xc00102b1 diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index b415b10a0823..50db783f151e 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -1561,6 +1561,8 @@ static enum es_result vc_check_opcode_bytes(struct es= _em_ctxt *ctxt, static void __head setup_svsm_ca(const struct cc_blob_sev_info *cc_info) { struct snp_secrets_page *secrets_page; + struct snp_cpuid_table *cpuid_table; + unsigned int i; u64 caa; =20 BUILD_BUG_ON(sizeof(*secrets_page) !=3D PAGE_SIZE); @@ -1607,4 +1609,13 @@ static void __head setup_svsm_ca(const struct cc_blo= b_sev_info *cc_info) */ boot_svsm_caa =3D (struct svsm_ca *)caa; boot_svsm_caa_pa =3D caa; + + /* Advertise the SVSM presence via CPUID. */ + cpuid_table =3D (struct snp_cpuid_table *)snp_cpuid_get_table(); + for (i =3D 0; i < cpuid_table->count; i++) { + struct snp_cpuid_fn *fn =3D &cpuid_table->fn[i]; + + if (fn->eax_in =3D=3D 0x8000001f) + fn->eax |=3D BIT(28); + } } diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 3f4342b31736..69a756781d90 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -1326,12 +1326,29 @@ int __init sev_es_efi_map_ghcbs(pgd_t *pgd) return 0; } =20 +static enum es_result vc_handle_svsm_caa_msr(struct es_em_ctxt *ctxt) +{ + struct pt_regs *regs =3D ctxt->regs; + + /* Writes to the SVSM CAA msr are ignored */ + if (ctxt->insn.opcode.bytes[1] =3D=3D 0x30) + return ES_OK; + + regs->ax =3D lower_32_bits(this_cpu_read(svsm_caa_pa)); + regs->dx =3D upper_32_bits(this_cpu_read(svsm_caa_pa)); + + return ES_OK; +} + static enum es_result vc_handle_msr(struct ghcb *ghcb, struct es_em_ctxt *= ctxt) { struct pt_regs *regs =3D ctxt->regs; enum es_result ret; u64 exit_info_1; =20 + if (regs->cx =3D=3D MSR_SVSM_CAA) + return vc_handle_svsm_caa_msr(ctxt); + /* Is it a WRMSR? */ exit_info_1 =3D (ctxt->insn.opcode.bytes[1] =3D=3D 0x30) ? 1 : 0; =20 --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2086.outbound.protection.outlook.com [40.107.243.86]) (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 D3CBD16D9AB for ; Wed, 24 Apr 2024 15:59:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974375; cv=fail; b=biFXHS7cuAR4IF2zGsWWGBNGxE6RHDnRHw20XO/aK85BYSWeBzO09WcwaxlWxN0lrrohfgVc7OgdTnQe1VkhWiu91W2MnM2f4F+R3AUaX2YShwp7SRrfTzBVAIzWtfc5ESDxyTwI1XDplK4wauQg8n8yhfxNGH9DLCSrvd960JM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974375; c=relaxed/simple; bh=EnYkbDXFiKrUE1tEngplsbMPZmqcveY0jPZoTpN7QZA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V2GWwf4wGB5BovmtaEZ3Y73kc459jlCLK4Ycj/dIhhF8ZxxB5fc2jyGH6nWo3jM/TwEdhqtB1onC2QrqT9JUX0PNkehuwk+ArfUFfoDz/h0bq18GgvX3z8IrcUgBecFGPugWmsfHk1HcKecj/KfmDOc5GXPc+9Nc4BhVhJi4PBE= 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=bOGiU8hT; arc=fail smtp.client-ip=40.107.243.86 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="bOGiU8hT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hoO4mohY04F2cf2dPTAQrvkdRsIIduMUyfvTrZBlNDiqU+ISWvh3kz4AiPuMC1/nUQUEeezNZNj1QNjUQmg4XlH1PDlldfW/Z0qUp5BUCvtowk6pn40wYFuPE7qWrNjeiIRZ5kV8s8z55gW8hCpRn5vwTVnh3vRsQmmilyK8WKxtP5vyT4q0xdsLtqPOC2TDlAjCKNLGdbIuEmxOG1HvAU7SPRE9X8AXAFvdGgI4PMr8Eg36CV/W7XKYim6dpPLv0S13WIK8BLtxZH8g8bYPrFk34In4lSB1nMb0k3yiSOS2KTXgmKLBEU4xBPDKol7BmJUAjderbrnERdTVgNF9EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=xjytLRT56OtsSgL9H3V29yrzuL7VwCpbjwgjYJY+6Ts=; b=JYflXXj8RxheFLqj2uTzStDTy94MIRHwiJb72e9pHao/s5P6TsPAtKmrSOuxfGsFjak8c64qUo+A2whZQ6hXLoBOvuA+CYcAddK/N5l9vulcf424ReK0MNK6ZwAbRJkTmE0W7dEhpQGd3onARdj77guWw2pa5LrHerH5XFnVpZI9TWC5dVFuohpFWcdlUZRusJ8mnsf8Q4nIoCjrdzrEmaeYpD+GZ98CIVv5IRS7XwXtnR2j3e+Iksk126vqrQBVxZ/Is/jXVjHuLN9K9oBAuxaQ6b2djL0lqTuQZeQdGvZAT6OPbPYO9vH/EvssIu9DpWyYjwc4iY+1yibJxta05Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=xjytLRT56OtsSgL9H3V29yrzuL7VwCpbjwgjYJY+6Ts=; b=bOGiU8hTBiXM7uyaLwpV2v3jlRSDSuHDSvqz77OKEuN6ap/ghYTCAc46QHgY8nSQccCedMlz8d5rLQe0u8IcRoMFyHcPA7L/Ro6XKpA6yyyj6lN4/lyhl/vjgb/Yq0lSZWJGl0zzxbgyNrpMfwbZ4R51S/t+O3Eo+0YwTiY3wyo= Received: from MN2PR20CA0036.namprd20.prod.outlook.com (2603:10b6:208:e8::49) by MN2PR12MB4110.namprd12.prod.outlook.com (2603:10b6:208:1dd::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22; Wed, 24 Apr 2024 15:59:30 +0000 Received: from MN1PEPF0000F0DF.namprd04.prod.outlook.com (2603:10b6:208:e8:cafe::c5) by MN2PR20CA0036.outlook.office365.com (2603:10b6:208:e8::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22 via Frontend Transport; Wed, 24 Apr 2024 15:59: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 MN1PEPF0000F0DF.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:59:30 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 10:59:29 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 09/15] x86/sev: Provide guest VMPL level to userspace Date: Wed, 24 Apr 2024 10:58:05 -0500 Message-ID: <435f78e07c76e25d2d857138724098bc2a729b0a.1713974291.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0DF:EE_|MN2PR12MB4110:EE_ X-MS-Office365-Filtering-Correlation-Id: 485ef792-bb82-4a31-8952-08dc6477868c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400014|376005|7416005|1800799015|36860700004; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?WyBQEqLLA69SXXtLENTJbD2o4SNzLk3LKeOS51sNlkSjtT9aC48/AYWJLAWR?= =?us-ascii?Q?LTgKMHyKYHW7V8w1gQXIF9792D8+DUu5tSTH6buFLGxUnEwkdMKFEJEkMZH1?= =?us-ascii?Q?+B0eoEMBgx1Ka77e8aKRstKfGNA4+uO6ogai6ZfMa8Nlq+sO/HWafI43oUIN?= =?us-ascii?Q?WbM5oon86PsOCsBDWzo19IRZAs2B17ol1jzShDKAcOAET4qEBLhkwHrN3XO+?= =?us-ascii?Q?/Mht94CTDJDFOui8LHDXJEiNmnJHg2zMmGfld8ghWuMOOFNRFrF8IL0EdVKT?= =?us-ascii?Q?pRG/0umtRcQwOWDi9n9y32cntkW3Y+86ZpI5/WLRnW0aQ+bagZ3Eme5Pwez0?= =?us-ascii?Q?MjeAlQdlfLO/l68EB0c4mvQKE0Hfkg0DBIOonEioz0XLk1437qHEuiuVMlt+?= =?us-ascii?Q?ySMsFHOZpAxf6zJHs396mtAZE9BssBXnT/ZHUnwYvjg4XDQHf8PMSazow0/j?= =?us-ascii?Q?SLBsff8ZL8P4tSh6IuX/fn09kqxNbjSghQKjbMwPh/EtCR0aUcU4FazJeiGn?= =?us-ascii?Q?eVDoZThHTT+kMHNd3ZSUwBPJtjLH6N7t69CyZ7y3PCOAp8e8t9FWUiZlPZ9J?= =?us-ascii?Q?eybL5iGfwJNVv8mYlXaVk/rLeJbBBXeAfW09nR+QmG9nlM2ZrAVRCyGTiSjw?= =?us-ascii?Q?JnaOwhWzZO7gPnlgF48w2uuTIvjWBPEq7WU6wOZyEwVExJbbczEKNQ6ftvWD?= =?us-ascii?Q?9jAfvfeOwq3R8MIiWod6jSjJmwbM1MC6D+/T29Bgu0UtKio20bY/Ts2qZ1LT?= =?us-ascii?Q?i/pDxYqICR+VsXn5M1EQG+9Si+2XmirCRJsgvcu5IDqZ9nBxA8Fn0zhd0Pju?= =?us-ascii?Q?agngThnb3xaKnzfuleHlJbRUA2Pk6FyRAEI1tKSQ+KIF3glhjL9LLxBmwJLw?= =?us-ascii?Q?Ncsa0DUxigzz9xFuzCY8Sv29v8OyTEjAuWsi+spvl5tDqX2qCxMBdxswMG6v?= =?us-ascii?Q?MDe+b45VB8Jamim7s26BP7B5WxmabDHo1H4L2SY/ZIbNZZiavgtjJyvtJ20I?= =?us-ascii?Q?PEjkHVSU7c8q9laGVamLwpHLHbG7HQc5D8cTdTsR7fWaDXnv9qdNm36QBlXF?= =?us-ascii?Q?fNUVnwkAxmw/uprqj7WLlsTd/bFYT1C/ySHRilKDVU4T86r+CuZtKmRInCiV?= =?us-ascii?Q?4/kkPWYOCgg81qDnaGgy5SYSxWYnouXxpxbHmIFrM/BUuPfabiNViSi73/TJ?= =?us-ascii?Q?4xrOdlJEVhXVLs1+dDXm/ceq9gQZQ0CMJhiRlZLvNH2QFO3ObuRy89/O6WE6?= =?us-ascii?Q?S+Tls7BNbROaJ9Vhmy8/zemsEzc9VO+dRiGSxoxyxewQzWN8rMNskp6UDql0?= =?us-ascii?Q?DKR2jNWEcMxDKWi7hsDGEDP1o/I6aRaxC1Z8OxzuMnQ3c3hC+ocr/X5EdU7Q?= =?us-ascii?Q?1IpO+nrAHHTgFHZQQg2T4ihYuKW2?= 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:(13230031)(82310400014)(376005)(7416005)(1800799015)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:59:30.0542 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 485ef792-bb82-4a31-8952-08dc6477868c 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: MN1PEPF0000F0DF.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4110 Content-Type: text/plain; charset="utf-8" Requesting an attestation report from userspace involves providing the VMPL level for the report. Currently any value from 0-3 is valid because Linux enforces running at VMPL0. When an SVSM is present, though, Linux will not be running at VMPL0 and only VMPL values starting at the VMPL level Linux is running at to 3 are valid. In order to allow userspace to determine the minimum VMPL value that can be supplied to an attestation report, create a sysfs entry that can be used to retrieve the current VMPL level of Linux. Signed-off-by: Tom Lendacky Tested-by: Joerg Roedel --- arch/x86/kernel/sev.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 69a756781d90..8edf7362136b 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2507,3 +2507,40 @@ void __init snp_remap_svsm_ca(void) /* Update the CAA to a proper kernel address */ boot_svsm_caa =3D &boot_svsm_ca_page; } + +static ssize_t vmpl_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%d\n", vmpl); +} + +static struct kobj_attribute vmpl_attr =3D __ATTR_RO(vmpl); + +static struct attribute *vmpl_attrs[] =3D { + &vmpl_attr.attr, + NULL +}; + +static struct attribute_group sev_attr_group =3D { + .attrs =3D vmpl_attrs, +}; + +static int __init sev_sysfs_init(void) +{ + struct kobject *sev_kobj; + int ret; + + if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) + return -ENODEV; + + sev_kobj =3D kobject_create_and_add("sev", kernel_kobj); + if (!sev_kobj) + return -ENOMEM; + + ret =3D sysfs_create_group(sev_kobj, &sev_attr_group); + if (ret) + kobject_put(sev_kobj); + + return ret; +} +arch_initcall(sev_sysfs_init); --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2044.outbound.protection.outlook.com [40.107.244.44]) (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 5E51316192C for ; Wed, 24 Apr 2024 15:59:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974381; cv=fail; b=TQB6eQUdZsfWWnckv7duRc6WlgMGUZCogUSbSsX/cfwF8umc0iXuYFsl9vwxtjOwu7AWPIMmqO6HI6kZY5imh4eioQViYPuGlQbGzHfY2p1v/TTaUxfG0ZN8NxNnhLpC8wFTn05KJ8hKeOOB1PeiWFWj8PHlYq7hk4hWDFpDkpw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974381; c=relaxed/simple; bh=k5dqfCB1Ny7K9oxiexb9YQ/Q3eD7iadwyVpqzh3QELo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cbGfJsxKYWz57/GaZj6n7iV9HP6wm5nxonUZkvSBmb7Jzusir+dp/s6DLoHjLNPfvmSTGBxc9fT3Z88WEXfqo/D8ihJiQRFVYebLX5oxO5qQs9BpkbUNZwOqYlcJg41AD6o3/4z8OfC0ptzJ/Gc+HFheSIFy3WYzBrP3MAt+bCw= 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=Y9oLYYoW; arc=fail smtp.client-ip=40.107.244.44 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="Y9oLYYoW" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nWkTPhs4s2pHLskt6c2sCGaB2hF1YMKJRKs3qzWP3jojKEIrm5rLmaZHcldNyHzVeHuFeWhiB4b88sf4bV0S1VIUM9yhPdHeG4hr4SfWdfq9/4HB4tk/K6nxD0/yO00uDUMF3nogZoIdydC2tuxWrlZ/PHCeIgg3O00ynu0MPdGuwugaZ7BnFL0TwsYGG+qH8pe1WAb7vVZFVuqlBPI2yVVfbo+uytpczDn6sIllgpOoWnGN615sgxr8WFvqVNhnAlbzSqPQy/0oTDkhzqGE/EQ7ZH9tOKcLZ2qEpm5TH5CjxUwghCZLSa0VVuJqK66XfNd0uv8K+qQ9Jc9jkp48ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=tJrOw01MQaT9tkIKTDOXvm9NDgY/m/tu/OEjNakftDE=; b=GGb7g+/Ed45h01St1GGXnPueGWTG4t9MPlGwgyph8wUbWJN2GsRpXVlFYuVUsrYPaXEHy8zkmfgoVPgQLS40cD5PcZ6BoBOJK39FOQD7UOkQ3bWHYnoMVu/2hBfOgGZah/cSOai19kQGQB5xUVOpovim2Y3fUWSOHQ7Sni9HdxE3L+vL7MUNV3W+6w58M+hJoX9Lexl1/pQjWzkv1ZburG6EzIH4BDOannsm6Re43GwE5PEcksIILvX5iXYLQfU34k/N9ohZB7DoMES7bmPIfUB0OPc/kIFYAZTo63EygotfdY+F+Av0/JVtsPIGD5Gcp6VqQQRdb7xEJZH5PhM8ag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=tJrOw01MQaT9tkIKTDOXvm9NDgY/m/tu/OEjNakftDE=; b=Y9oLYYoW18uz4sP7ls7kLGwGOg4WyAyXGCWw8tugMM3pba0z74EmMxOSx0xi7vfvizvqgPG5rrbywMWkhSg3odCv+5i8ed71NDku7y9NonsEQlTfugYO5ehdMTbYymw9Lb67ZnsKwg+sbLr+sy1N+cL3b5/Dm37mwqVGBVv7mwY= Received: from BL0PR1501CA0036.namprd15.prod.outlook.com (2603:10b6:207:17::49) by SA1PR12MB8141.namprd12.prod.outlook.com (2603:10b6:806:339::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 15:59:37 +0000 Received: from MN1PEPF0000F0E3.namprd04.prod.outlook.com (2603:10b6:207:17:cafe::8b) by BL0PR1501CA0036.outlook.office365.com (2603:10b6:207:17::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.34 via Frontend Transport; Wed, 24 Apr 2024 15:59: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 MN1PEPF0000F0E3.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:59:37 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 10:59:36 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 10/15] virt: sev-guest: Choose the VMPCK key based on executing VMPL Date: Wed, 24 Apr 2024 10:58:06 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E3:EE_|SA1PR12MB8141:EE_ X-MS-Office365-Filtering-Correlation-Id: aae7bcbd-84cb-472c-972f-08dc64778acd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?h48vaUyOU3JrT6udw8KY/t4wBUhZ1SNvSHxkSUXPMTnZjKN0erB1Ukb9mUN7?= =?us-ascii?Q?83xgejRe6QBmfqa5Lgyzu+DOCNakFlkuX7uHd3PudDZStlrGJgPPnOxRENgj?= =?us-ascii?Q?BubiWqTspbGgLSnd3OXi4KehKh0q1nRlkSc5FrtrlemSn5DWWg/s/YuvwlU0?= =?us-ascii?Q?lNLieujRdVhFYCFGojPBxbByWl/Ltso0kgVDRkJiiXe+7XG8AUdzFaq2tnTR?= =?us-ascii?Q?bwm6lRhmk+dvmarp2yKktUzInEqgSqhCqSpYGvJmCe9A+scfQeSd+YWP1afh?= =?us-ascii?Q?7A41nlYJfOnadyl99ZiKNKWZxIZvYkAu+FnNeK/OYs15IRI0NFLRYW/w1TsM?= =?us-ascii?Q?jRo8fuTzvwscvFT56ZA0GrxIbVYodSVxM/0uHSaVBIyaktk6+WN97KaNb5JV?= =?us-ascii?Q?xP10k8vLZPrKBAwdfDHbPnPLc+naqlMu6K2OXzyly+v6dB/GR+bV6ScdC2Sf?= =?us-ascii?Q?5uZkwqagHz9zTd5CTy19Yv83wYraaw7CEiNXocAakY9QFomL2QGYPrKTOogI?= =?us-ascii?Q?NygBPyZvkRGVY+/jHxHYlPr4bYfpT3f+2jVS+xwAQApjf/O+gmOxlXzacQbL?= =?us-ascii?Q?qO+4ObcALzTn2ZIMh/0M+YIBF0/L+a4tP26Wp5Qoek8nlMwrIoWUS7FOSNtN?= =?us-ascii?Q?n7CxFawlNsQAG2Aq3NC6IV8w3JhCBtj7RqSy48oH6dsBpCabx0/KqPZxEujW?= =?us-ascii?Q?KfrRMDJk3ubs3YR2rEfsyjODuhPtRzph7mwuFes0rXlHkR/9uZRbJYlLsNnB?= =?us-ascii?Q?4aekBemxn1s7Sc+15qsy0Y7FBCVrOHBnyq0raB2o0bFjSvuTvf1pnDze1JST?= =?us-ascii?Q?kkJEbk13+Yzec9cFXFGtT2G5V00AaLmj/ZlJNCQL1X1fh3MlKRBxz/uCXlQq?= =?us-ascii?Q?gJlmG1oY9FivnI2poI20wE5PzLKiIEIkS0D0p2L8IYnivNuGj/ixiU7loxcr?= =?us-ascii?Q?umIyxgVE9PslqWrEZg0RMxz6ndmCdu/U/++hwgJ86K70gsZXBf3DGheV6/j0?= =?us-ascii?Q?iBEXQch4RhVe+dm13ztbE+Iro2X5uy2S9qPgTo0zLj49Mliuzdlk70nFvBbM?= =?us-ascii?Q?XhEKMTclr0RIG2/VVyOE7cGD5iesxqRjYM4Kc/JyDNfGbnMhrgNE5Y4Uo3q2?= =?us-ascii?Q?9ivq0fGWdpScGPp/A5gAWfgrbc+7tD3LeyPx7FL8lNFkslEXlESfyt997hv/?= =?us-ascii?Q?W3sOai0UGBaPIQk0WZx+x8G2c0pO7vjs0ETcZHff1BrffKWs8adUG1aiWZNM?= =?us-ascii?Q?tCC3HRc84pxvuUUjXI3zQ60xgunGmwyyWkn7Z+7XPWj3dMTjngRFjmttQqvh?= =?us-ascii?Q?KBsZdDimeLqZ6C3Wgg1YfuF5Zn3AKE5SFimoIk+ZwPCgHsN5XCdqSfRIl5Op?= =?us-ascii?Q?P7aFjAg=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:(13230031)(1800799015)(36860700004)(82310400014)(7416005)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:59:37.1914 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aae7bcbd-84cb-472c-972f-08dc64778acd 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: MN1PEPF0000F0E3.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8141 Content-Type: text/plain; charset="utf-8" Currently, the sev-guest driver uses the vmpck-0 key by default. When an SVSM is present the kernel is running at a VMPL other than 0 and the vmpck-0 key is no longer available. If a specific vmpck key has not be requested by the user via the vmpck_id module parameter, choose the vmpck key based on the active VMPL level. Signed-off-by: Tom Lendacky Tested-by: Joerg Roedel --- arch/x86/include/asm/sev.h | 2 ++ arch/x86/kernel/sev.c | 6 ++++++ drivers/virt/coco/sev-guest/sev-guest.c | 10 +++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index a7312b936d16..64fcadd6d602 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -307,6 +307,7 @@ u64 snp_get_unsupported_features(u64 status); u64 sev_get_status(void); void sev_show_status(void); void snp_remap_svsm_ca(void); +int snp_get_vmpl(void); #else static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } @@ -337,6 +338,7 @@ static inline u64 snp_get_unsupported_features(u64 stat= us) { return 0; } static inline u64 sev_get_status(void) { return 0; } static inline void sev_show_status(void) { } static inline void snp_remap_svsm_ca(void) { } +static inline int snp_get_vmpl(void) { return 0; } #endif =20 #ifdef CONFIG_KVM_AMD_SEV diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 8edf7362136b..75f11da867a3 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2454,6 +2454,12 @@ int snp_issue_guest_request(u64 exit_code, struct sn= p_req_data *input, struct sn } EXPORT_SYMBOL_GPL(snp_issue_guest_request); =20 +int snp_get_vmpl(void) +{ + return vmpl; +} +EXPORT_SYMBOL_GPL(snp_get_vmpl); + static struct platform_device sev_guest_device =3D { .name =3D "sev-guest", .id =3D -1, diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/se= v-guest/sev-guest.c index 04a7bd1e4314..e7dd7df86427 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -2,7 +2,7 @@ /* * AMD Secure Encrypted Virtualization (SEV) guest driver interface * - * Copyright (C) 2021 Advanced Micro Devices, Inc. + * Copyright (C) 2021-2024 Advanced Micro Devices, Inc. * * Author: Brijesh Singh */ @@ -70,8 +70,8 @@ struct snp_guest_dev { u8 *vmpck; }; =20 -static u32 vmpck_id; -module_param(vmpck_id, uint, 0444); +static int vmpck_id =3D -1; +module_param(vmpck_id, int, 0444); MODULE_PARM_DESC(vmpck_id, "The VMPCK ID to use when communicating with th= e PSP."); =20 /* Mutex to serialize the shared buffer access and command handling. */ @@ -923,6 +923,10 @@ static int __init sev_guest_probe(struct platform_devi= ce *pdev) if (!snp_dev) goto e_unmap; =20 + /* Adjust the default VMPCK key based on the executing VMPL level */ + if (vmpck_id =3D=3D -1) + vmpck_id =3D snp_get_vmpl(); + ret =3D -EINVAL; snp_dev->vmpck =3D get_vmpck(vmpck_id, layout, &snp_dev->os_area_msg_seqn= o); if (!snp_dev->vmpck) { --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2059.outbound.protection.outlook.com [40.107.244.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC80C1635AA for ; Wed, 24 Apr 2024 15:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974388; cv=fail; b=WA2rPz563hGXGm+nJv+kNHiBdqHesUeM6AYAVN4UU9I+d7gmAmLT/nvv7Ywd2CObufU3G2oEXai13gF9DvGna+sKU6+hmhN6vJPBJrQjQqVVdiOGmxaBO4c2jrkcrRZyfXkaSpMviJ5SxuXs8OHtB4pCPH8BvGgXGeA06VWaaB4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974388; c=relaxed/simple; bh=aQzJxzu3JRsRJBqn4CP9lcLBDKf2NUkFj2gkoWxADW4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HmfcVZD2TVQSQdN0FyzXrqPOyw7qRc5+JtpvIpPpFUEJMiWYIrtB+FN0ytHJJnHa+P9UNIa159LVcO9/qcivE55PWqV7XdDf+eRgcjtxxa9ZLDRYpN3a3ItLJKFwop2KjpSlQKKyNMHBUFyLyLFm3q1soNfbt6372h9d4FCDj1M= 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=ByGv1uvO; arc=fail smtp.client-ip=40.107.244.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="ByGv1uvO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bFnKQV18g/RoTLwLkH94LxVcQQCnimR+pMi9rnj/CSRPLuzHEqo+C3LTpOnPqnsWeEVGNEfeIljckZcswy0YgSW0cdSSqNFo40P5TQ8wGHnB57h+wVq7CT0cKVCNd0OzSyj0eBtMT1grVfTTGZaZ9VVHS9oHmhzHc9l/g8aDDPLHGnyVyLrR3pOsv7SRu68TqjUDdbjjBK3tU6AdtQ1HISrTBV6P7JHtUAyxpiEIkvapKudcC7dW4bnYwGIurezmknNn3BVaVN/pDAnCFz+vdqJfKw1w1AORwCuLv51h6Y6SwTua4h5ezVk/frFVi6s7RYC9//mNfA075OqekxtoCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=wscLJsvbE4NqlGls8/En2OLJd4BFLUy66OVcbTqEIVg=; b=HDhhY2/I8SUkFVdRaCWGODrbXYtRbekrWiicSy/0AFYnDikSZw+HglSJ/9x7mvonyRmSYMEZA1KMmmpFyH4VHbFSKSqN88tvZROnw/2K/z802gTiRGNqfbruuJS8GS7VdemJKHVl4rIwwAANtJXl+xGrN2TSb4ZMzBEjGxGuLBrSx49m75YLiUjrBSgmgAIFOTf1nGooeiHIqivh5Xlq8ctPkuGM0BLHGy2jlOvu1A2SRMjmBl6o027Ym5B6ZIY9BSdmEEtElRiX7648SQZ48e2TeLbs7vR62j02jp7ct3zQtptfrppKhViV8U/n2rbsqhmCkQzISWn5R0NeQdwKfg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=wscLJsvbE4NqlGls8/En2OLJd4BFLUy66OVcbTqEIVg=; b=ByGv1uvO5tvBOQh0sBWh/oWf/sK1W3PDK4zzdk4P9FKyNCGnB6dqBCCcXiqJQLKakYhl7zbdRoz1l7ncSd3EtZ3YcHqO+ku91XpZWZSi2LzjXecJq2wgiZovxQZyxEY/JptyJeqhq60+nJjTdisq4AdRBErUZLa4WJ2T3ocdhf4= Received: from MN2PR20CA0017.namprd20.prod.outlook.com (2603:10b6:208:e8::30) by SJ2PR12MB9163.namprd12.prod.outlook.com (2603:10b6:a03:559::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 15:59:44 +0000 Received: from MN1PEPF0000F0DF.namprd04.prod.outlook.com (2603:10b6:208:e8:cafe::60) by MN2PR20CA0017.outlook.office365.com (2603:10b6:208:e8::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.31 via Frontend Transport; Wed, 24 Apr 2024 15:59:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0DF.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:59:44 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 10:59:43 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 11/15] configfs-tsm: Allow the privlevel_floor attribute to be updated Date: Wed, 24 Apr 2024 10:58:07 -0500 Message-ID: <731690ebf2434c553a08bb06e5bc6cd8fe48a4bc.1713974291.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0DF:EE_|SJ2PR12MB9163:EE_ X-MS-Office365-Filtering-Correlation-Id: 25999511-9fe5-45dc-c3c8-08dc64778f22 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?cE4xpYK1cWDDu12HEuVJW5Opb/Fla7lTkICno9RYG55WGkoyW14iMpnH6g2I?= =?us-ascii?Q?/QVzJW7lcVSVzRwz9TJqIgPh+BhfRZDrVyiic43bC7UJOWDj7BwK1IulPsls?= =?us-ascii?Q?yl+SQEDXH4TbkxuV69ccjhipWET35+W2QBhJOS/bLy10UuaTT7k+nWcOq/i9?= =?us-ascii?Q?mfTk62NFZSOeQSvWIPLiAvu4iggRS2EJqgC/5Bx66X3RNmI9+KtHBvcDTyiU?= =?us-ascii?Q?jbQcK1rGe0YqyG2E+gZZuvQxICkq2PjfB8qFi8XyHeATR5d3zxWFeJzyXXOw?= =?us-ascii?Q?JDwOcKe/fKwMMdP7hl5VjegYElkctmnjQ5mE3/9niYjegmbAw9p2cnJ38D6K?= =?us-ascii?Q?z/C3brMamkDTew+q25vsMdgW1+CmabWNk94RYj7N6wD2Jqa69BMdihJMOBjV?= =?us-ascii?Q?QPaku/yWlcSYFYbgOh1PUVmC0AcvpDRw9egIJCxJ6ZLYj3zlFy5tQpzNOuwy?= =?us-ascii?Q?WWVk4PXhTtsE1m6t8xJAEOlmGcgsyQCfVwr5c+4fnpu20LRb1kGMiDNQe7Mw?= =?us-ascii?Q?27MDvr3JDPsTNv8JGPbaUse3H0KQI5LL07t4C/XumD0voJI/AU12ehviyCq5?= =?us-ascii?Q?hlF/x+UeMK9OZvdl7vE2t12aIzeKbezpRQcdSMzZFEq6wxCQ/Akb06DN1OLW?= =?us-ascii?Q?JyxyUTomDdrYuVbwvACeyVU/4IUGXN5nNs2b0pOZmdfxK7c+z25hTayHXMGM?= =?us-ascii?Q?X7mu4bWdssOuTpbPVeTTdlmKfkkUsJg1GhdezOg+cs2IKsdGlaWFG88wJyos?= =?us-ascii?Q?PriWNH/qCHgIEkXluoTUdeFGitHRRO8KOHD5rLb7YYyyyTzomJjIOiiafF/K?= =?us-ascii?Q?YpINSH1OfsTl35qutMHpAUm5E0TIAs2RjtgTwvnyPW7C7s/SMMkK+ExvjSP7?= =?us-ascii?Q?9yMHnEHz6yyjqVfRatHHglBvbiHeqmgbAH6YPws6w0WaC98P7/FjxiRu2sKt?= =?us-ascii?Q?Z7F4KsiYK7DYKEvF/ttIPgw37Fzo8DANroJflpfUirhahCvK4hgrY9ESPCPh?= =?us-ascii?Q?Yeel4S1cx6Zm+vht8EmdRGtc+Q6t39VBFuwIKg8FmUMTqLEuyLUSCoakt/rZ?= =?us-ascii?Q?op0YPH1fYzw9GIZhT0w3jGrsKYx5ymluT74oYFFi9utRz2d4U5eNcCOchxl+?= =?us-ascii?Q?k6jkEaN+dtzpuXoJrbZgYKSke9B1yn5Y327l6iJPu6yHjqpgqC2MhKWXMx+S?= =?us-ascii?Q?Gf94A9bO4WgP3fE4uWU4l36P9tcYXo1OFzx/Aqpw6U9YuxCjoQOt2eYx+zmA?= =?us-ascii?Q?4Ceq5+6A4gZSMueEBcDLQr03Kb8LAn2EJiZDov/AZFbaI+11Jw5J3vH5yeuG?= =?us-ascii?Q?syNtNDR74rleU7tXjSIh3hf+RbLOwbrtNyDZqQ+il0r4xTAJgNlaPdBBgJOL?= =?us-ascii?Q?ymdTKCxbiLuqv27alhanKiZZucMo?= 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:(13230031)(82310400014)(376005)(1800799015)(7416005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:59:44.3980 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 25999511-9fe5-45dc-c3c8-08dc64778f22 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: MN1PEPF0000F0DF.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9163 Content-Type: text/plain; charset="utf-8" With the introduction of an SVSM, Linux will be running at a non-zero VMPL. Any request for an attestation report at a higher privilege VMPL than what Linux is currently running will result in an error. Allow for the privlevel_floor attribute to be updated dynamically so that the attribute may be set dynamically. Set the privlevel_floor attribute to be the value of the vmpck_id being used. Signed-off-by: Tom Lendacky Acked-by: Dan Williams Tested-by: Joerg Roedel --- drivers/virt/coco/sev-guest/sev-guest.c | 5 ++++- include/linux/tsm.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/se= v-guest/sev-guest.c index e7dd7df86427..2abb51bd034f 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -885,7 +885,7 @@ static int sev_report_new(struct tsm_report *report, vo= id *data) return 0; } =20 -static const struct tsm_ops sev_tsm_ops =3D { +static struct tsm_ops sev_tsm_ops =3D { .name =3D KBUILD_MODNAME, .report_new =3D sev_report_new, }; @@ -972,6 +972,9 @@ static int __init sev_guest_probe(struct platform_devic= e *pdev) snp_dev->input.resp_gpa =3D __pa(snp_dev->response); snp_dev->input.data_gpa =3D __pa(snp_dev->certs_data); =20 + /* Set the privlevel_floor attribute based on the vmpck_id */ + sev_tsm_ops.privlevel_floor =3D vmpck_id; + ret =3D tsm_register(&sev_tsm_ops, snp_dev, &tsm_report_extra_type); if (ret) goto e_free_cert_data; diff --git a/include/linux/tsm.h b/include/linux/tsm.h index de8324a2223c..50c5769657d8 100644 --- a/include/linux/tsm.h +++ b/include/linux/tsm.h @@ -54,7 +54,7 @@ struct tsm_report { */ struct tsm_ops { const char *name; - const unsigned int privlevel_floor; + unsigned int privlevel_floor; int (*report_new)(struct tsm_report *report, void *data); }; =20 --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2081.outbound.protection.outlook.com [40.107.223.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 523E81635AA for ; Wed, 24 Apr 2024 15:59:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974397; cv=fail; b=o2w9WKS3agy3turvd1Uk3DH7eaVb/RRNYM9mpUPXm45oARKmnIM7+3dhD2wL5TOgZTSLQXpJzJwRHvi8KNzl+U4L2+RqAe/Ii8REMW5I1+aHlpToaBJQrMYjSFuPevDdiTTnP3E78FoaOk4b994sELtA/jBISC4OFMjBytaRUII= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974397; c=relaxed/simple; bh=Sq6lw5mGILMoX/LWK00+p33/9Jd8eRerh3YOoRTzFIs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BwD1T6+C8cUz2xSHfL067O3K7Ezr3lrg/yeqOyqBnGOjhknQrIuC3wDuuy40wWMd61oR9DzLol39i9/CPVfg3jlmWzXroW6qJ0tKZVFq1rHAoelc26BEFHuEpD4GlROxLgWWrr2ot1RgHJUiXy2R5SPq3K4dUQlDnVEPDAxsOV8= 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=3OEWoETG; arc=fail smtp.client-ip=40.107.223.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="3OEWoETG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QKjXEyyQO/v0jFJ0NzPgyyMQ/FVe75KbDt8s3brWnr8r0Qv15f8xCKnr/Ubi8a5jK7LT1FQeaqrkuQg80nWIg5hSReE1wvc3prPRXu+VCEqJbCZ7VylOSSDzaqjRcf/1jTyek2DSMCqX3SRnmECclMxjMUBVlASyzCjSFiuWwI96USd/qTWfrC4vmR04SbB3ARuGkxd517DiPnWTUQh4lsE3NDLmFQveg5UT0YXK2unm7mDy1TC9Her4X53vLiI8/ItdOxTYxzfg9LXAcvVM6wxve63LJrFsJc5UFSY2Yq/9+mULY5M2KWOfDSt5YaqSWkadIwQKH3juLUc2YUGEyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=3zLSYjw0FK+2RjD5YSIL8TRuugJd5EXzQpGHQo0AbJc=; b=HXb6Evcxm1ywKWUi/S+8ov03B3eZrmbNZdhE1yCfqX+MIZi+/OurcQcNAyseZMJbBJOg8a+0C0hYUfLMbpHWT7JA4gW52XBbRtKxwxKBamAhk2QxlmFEk1Q5FXvf3N0FCmJa4yYwZ0qmakoVPBYzTpVx7KSBPKWdwRg3y8ZHKuRtdq66bkEm1WJVmFX9gBi7cjqv3foJqeZluKoe/c0SZmwVe5MZntKEyDd14bNkDlUoeyg3iPArniBEHySp/GHHUF2P0dwUjCs7UZ9Rcj4NBx14Irq3uMpU87Tace36RuKi05GDVwz2M1WCxbJmXmUaIjYMsdzUCFmKr/erMHP45w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=3zLSYjw0FK+2RjD5YSIL8TRuugJd5EXzQpGHQo0AbJc=; b=3OEWoETGUg6QEFE+m8yZ9yDP1f7hOVoEhim0WzT5CbdxIaASnjgqAHbzocnXXmhW3GEmY0CiFWI7tbeCBFOnZJRVHvnJlQZoskf8vvFqn04aqbeQfpGGEmwcMdPvDx4LoY5qHH7SGQ0fVI/eFoMDT+mQjFC5ya4t3k7P9JCVd+U= Received: from MN2PR22CA0016.namprd22.prod.outlook.com (2603:10b6:208:238::21) by SA3PR12MB9178.namprd12.prod.outlook.com (2603:10b6:806:396::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 15:59:54 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:238:cafe::38) by MN2PR22CA0016.outlook.office365.com (2603:10b6:208:238::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22 via Frontend Transport; Wed, 24 Apr 2024 15:59:53 +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 MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:59:53 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 10:59:50 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra , Joel Becker , Christoph Hellwig Subject: [PATCH v4 12/15] fs/configfs: Add a callback to determine attribute visibility Date: Wed, 24 Apr 2024 10:58:08 -0500 Message-ID: <53e67e416fb4da085f32d8a3626c5c6e656554f9.1713974291.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E2:EE_|SA3PR12MB9178:EE_ X-MS-Office365-Filtering-Correlation-Id: bf541b24-09c5-4d69-b30f-08dc6477949a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?huLLzXsX3UGeVYPDBD9xdoPQ7zf1imLsgdXYZz6hFO+OupR2t3ZnFiZzl11X?= =?us-ascii?Q?6Z0mK9OVi801BOcwYz1hMHWccOoCUxQrY3654tGMxchUfq4kLO2iOBvhl+Lt?= =?us-ascii?Q?PBWskuYB4aLIqmSWg3Mt3HM7DPmMvD+/fy14TiMuWwiQRIRstayrNTmTOjra?= =?us-ascii?Q?Acp6AurhcJ1Y9ndF9+5rR28ePkYSx/IKC+gKASySZajFSUDLbcbUT5TQryeP?= =?us-ascii?Q?Tw4sxIdxiUM2Sg3EiT3CXp5q2ZbOitMni+p77SB7nNdvJ0/KqNEoYPoTXzY+?= =?us-ascii?Q?ZI+uKfZ3Rf2QosUivGTMiabLpOWiYt1RoflWHo5fSAzXO9j4YXToWp8Z/k76?= =?us-ascii?Q?pGJLZkIxIbAy7F3UKpX3MZUr1hofGxPUmeKVyBxhTBNxuC7pm39pGUwc7xo0?= =?us-ascii?Q?nrjeVBMhl9lijqjVy567nL5Lm3L2HVsJXuslx5vgrZKPImL5CKn9HQq0fPKe?= =?us-ascii?Q?oiLVOvNen756RCercT0eJ62XdSugxJquFsa2WJbrH70j2NF272xO+6hRfDhM?= =?us-ascii?Q?RShldBAwzx/7UmLhwN/7Nr/xvFQ9gk7JYv7iHCnHTd8DcFhpTZdGHisSE+Wd?= =?us-ascii?Q?3Mnk94oYmfEqx/82vmyn9eN03jE2KRcAblIC8pm5zUsmahZjj+Tgri+OJVte?= =?us-ascii?Q?NIeunrhr8YRbxd45qScTPr0TGry+MSHSY75j0EFBNb4Qv9EibEsCt4iBwJII?= =?us-ascii?Q?Zl2Scic1FqKCRMBZa1vWu4rDllRjOY4dzLT+JwyZOXmswI+4v90sd6dUb/Yi?= =?us-ascii?Q?GdylzQ/xl/EoF3kEYNea1q+XIWnTZQWoTYyuUEmuCotX+NWHOLxDvbNJ5/lS?= =?us-ascii?Q?GC3UTd2FLWzJdjN0aw00o/8VRzDWeOj2BpgK3/cgjLoRxjCadFZDLowHdINy?= =?us-ascii?Q?uHcMf2+8cYY3ZO+pq4nT3tcruryCbb3bgLzNFSxor0n7G07bjUVUgrU4/7kT?= =?us-ascii?Q?PChMLsZEZvli75WwofH2MswkZaMIdj8/AVJGwsNDgAktPDZeejJZdJAaWhVL?= =?us-ascii?Q?vEGJpW23VMogiR/wY6qzyvzAtryV2fsZpUddswy9vjdX5A219zI5q4MyTbXT?= =?us-ascii?Q?Ty1wnJDvVWOFamf83JFOyRSnntnIeLglF2L2oxRjdS5U+wm5vn3K7wFQEzkc?= =?us-ascii?Q?glkdezt2UqhkKKeZyfgsU3UsMwFblFHI2bSoGfaPoxRWzx2uADtasiFojDEE?= =?us-ascii?Q?SDUSqEp2AjhhHUjPTPpmpwV7CJM36u1jwRb6MFixiRBIgC3su8IjdfBbL6nU?= =?us-ascii?Q?5tQSbPWBNyfI/ThilKy3YBCjsEbnizanlp3gY0T20QkeY07ojO6mVAw1vKIF?= =?us-ascii?Q?YtG5AI2HFZijnoUTN3SDY6HxcM+XxNTt3R4GjLfGzhCU6v4MQQScznzIXa4y?= =?us-ascii?Q?HHAtO4eXKCFoR8y3oG/AU/BvwjDv?= 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:(13230031)(36860700004)(1800799015)(7416005)(376005)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:59:53.6351 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf541b24-09c5-4d69-b30f-08dc6477949a 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: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9178 Content-Type: text/plain; charset="utf-8" In order to support dynamic decisions as to whether an attribute should be created, add a callback that returns a bool to indicate whether the attribute should be displayed. If no callback is registered, the attribute is displayed by default. Cc: Joel Becker Cc: Christoph Hellwig Co-developed-by: Dan Williams Signed-off-by: Dan Williams Signed-off-by: Tom Lendacky Tested-by: Joerg Roedel --- fs/configfs/dir.c | 20 ++++++++++++++++++++ include/linux/configfs.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index 18677cd4e62f..463e66258507 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c @@ -580,6 +580,7 @@ static void detach_attrs(struct config_item * item) static int populate_attrs(struct config_item *item) { const struct config_item_type *t =3D item->ci_type; + struct configfs_group_operations *ops; struct configfs_attribute *attr; struct configfs_bin_attribute *bin_attr; int error =3D 0; @@ -587,14 +588,33 @@ static int populate_attrs(struct config_item *item) =20 if (!t) return -EINVAL; + + ops =3D t->ct_group_ops; + if (!ops) { + struct config_group *g =3D item->ci_group; + + /* + * No item specific group operations, check if the item's group + * has group operations. + */ + if (g && g->cg_item.ci_type) + ops =3D g->cg_item.ci_type->ct_group_ops; + } + if (t->ct_attrs) { for (i =3D 0; (attr =3D t->ct_attrs[i]) !=3D NULL; i++) { + if (ops && ops->is_visible && !ops->is_visible(item, attr, i)) + continue; + if ((error =3D configfs_create_file(item, attr))) break; } } if (t->ct_bin_attrs) { for (i =3D 0; (bin_attr =3D t->ct_bin_attrs[i]) !=3D NULL; i++) { + if (ops && ops->is_bin_visible && !ops->is_bin_visible(item, bin_attr, = i)) + continue; + error =3D configfs_create_bin_file(item, bin_attr); if (error) break; diff --git a/include/linux/configfs.h b/include/linux/configfs.h index 2606711adb18..c771e9d0d0b9 100644 --- a/include/linux/configfs.h +++ b/include/linux/configfs.h @@ -216,6 +216,9 @@ struct configfs_group_operations { struct config_group *(*make_group)(struct config_group *group, const char= *name); void (*disconnect_notify)(struct config_group *group, struct config_item = *item); void (*drop_item)(struct config_group *group, struct config_item *item); + bool (*is_visible)(struct config_item *item, struct configfs_attribute *a= ttr, int n); + bool (*is_bin_visible)(struct config_item *item, struct configfs_bin_attr= ibute *attr, + int n); }; =20 struct configfs_subsystem { --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2067.outbound.protection.outlook.com [40.107.220.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54BCC16E867 for ; Wed, 24 Apr 2024 16:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974403; cv=fail; b=u1AyMPxRXV1ZVKcsb3z0eORyEFbZb9NWknSSp5OkXhfZ6ntFfQxKc4UAJ/yi5bsK3efG5NdhMxxhLlGMiuQ39tLKh5e5cXytLl3fq1C4m+aUtoEcMw74rwnjkq+Fa3PoKJyWD6ntlEmmDyuHARjkA6kUY7PPCSq1MiyHWCGs/VM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974403; c=relaxed/simple; bh=wy7aDX8tf+ati0+pYqgMQR3JQYi0YlzmJAMDfkd4X+c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=li4+hQW21VrGvaZjkUeh3T3MhmCuTdNIpD92CrX7GPbB21FlAy21AiEZpwVC5Sow+Zn9O638q9NrH7c4a6w6J/N9BFfPBV3SAgBZq5UZwz8XZ+K5Ewiob3AKsVaNuaIA5ZYuU1vgjyYtoTlCG2bAk7fKWWIddjz8YlpcGfUZupE= 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=te6UTktb; arc=fail smtp.client-ip=40.107.220.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="te6UTktb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DvSS4RTCCO58GeIXH+Yj5bj9wrUOVOz/GGGeowI5Bv0ihx/I+rUVhRJyQrMkRLY2DTJk513M3Off3wfD+1ggosfhea9dQnNM//gShF/qlm22kb4XeZASgxM4DvQE5YMFo4i4buRpOuC5haf7vimfISU65EumtCacDSf3R6Ads0FhVhcU+DDlevvWtrHTBgGDlvg5dSW3Y6eVmRS6vTH+iUWTCXNsXV7L8z5JCbXy/yiS39naWLSEt2JnV8aCRNQ6B0pAJ/gn/j4t5WIhF414IAUDFUP2i1U4JA01wXJ3ugH+oWSe++PT+J/MiG8KJ3G8Rq0fdPRgBUwOsqwbl7bCDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=8SyjicdSOWwOB3m96d4X3yFbAiePR7eUGLRD/l6zmEk=; b=ar1Ka7Z3WpgaUH78IeqJ72REPTTqK+5qlsAClEFYrRiY1Q56dKrL78I0HAPq5KA2NO4J4Hgq1/IFOvERWiGxC9D2+AvJc40QjhnrGCcgbqKmW3hnTfLrhl1pTYpu42S/Q6AWLZ0TxgzkJgoVKnrXN9JkrOkjEmZjH/+BVoluhv9EhafHlGDBYPOE1z1XBDO1EGOq/WjytMv+54suuatBcsCczuyAjkisQWRuiGl6CY8WVm6mZ+5l/1+EbJISn8G8MfR5jQ/kFmadNbbDQsT7loosF+xjSouUJ8ad9E4SBoCKZ3ZU7cBxuKwC2hAneZqjXuytBftknxtAgSyRNL68xQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=8SyjicdSOWwOB3m96d4X3yFbAiePR7eUGLRD/l6zmEk=; b=te6UTktbRyhTvyETNLy1OCzIT2uJ76/X3NFXfOEY2c0puf7XcqcSoymutWcyMlwc/jCjuiHRi9k3I3hmyTZgPdf+A4ZdwC70imCjVzn4TzvNFStmfqoLdm3EitQ7osjUMr/0F/Hhad/5wfoMZAS70fduC3g9Ah3VM6o/v48FSxk= Received: from MN2PR03CA0018.namprd03.prod.outlook.com (2603:10b6:208:23a::23) by PH7PR12MB5593.namprd12.prod.outlook.com (2603:10b6:510:133::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 15:59:58 +0000 Received: from MN1PEPF0000F0E1.namprd04.prod.outlook.com (2603:10b6:208:23a:cafe::8f) by MN2PR03CA0018.outlook.office365.com (2603:10b6:208:23a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.23 via Frontend Transport; Wed, 24 Apr 2024 15:59:58 +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 MN1PEPF0000F0E1.mail.protection.outlook.com (10.167.242.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 15:59:58 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 10:59:57 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 13/15] x86/sev: Take advantage of configfs visibility support in TSM Date: Wed, 24 Apr 2024 10:58:09 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E1:EE_|PH7PR12MB5593:EE_ X-MS-Office365-Filtering-Correlation-Id: 62561f00-9790-4df0-3127-08dc647797a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?AmYVGDJbeL+nBd4kgJ46Ph74HDYEMQP5lOPR3NTjSFLWMbF6Ok/o2Fktrabn?= =?us-ascii?Q?JJJTm7P8MfopRSUDuE1PMEfgiUKjB8E5lm+jZptwlRo1jzwW+Ma1nJ8EyvLe?= =?us-ascii?Q?EtzjDSbkc+q8Kc3o9EPkiNY2NMCATyZrWw8HI8hFSR+WrMlHFo4Oxq6/GfOI?= =?us-ascii?Q?bRcMCPckU+pLgZ/J0XyINRcFDe5DTjsKpTL/m/Lp9Zzf8HvxSJ5PSxiblC54?= =?us-ascii?Q?Cn41ad+8hc9O0X0BCCdPVGtj1Xr3sOil3lZbOA7lQxxbEZqj96SipMxPypzM?= =?us-ascii?Q?Sh4cYHvYDzTZtU3TNHu9FLBEC2fSciK4cjV+VnapMDxPfKVjvRKx1varty2R?= =?us-ascii?Q?xhXPf5qHC8oGdIXvrGK90P1v+X9TxliegURq6/DJkHueXFspoUKbVjWCep3K?= =?us-ascii?Q?IHxAHqrbSwNLkatqEBOunnHoja52jInMmuYD2VDi7VGWLP3FaFdFWKPJ8MAK?= =?us-ascii?Q?0eQhrf4hyxjiJTZT4yjdvPPM9WFOV8HAni3Y1s1svLbxcn7jFTlCvTrtIhF/?= =?us-ascii?Q?h+sNu5FOwsq9iuOwgXjeGNSBm7jYS0KU0iIPJLD6o7b3RkYOGYnEhC7enOIQ?= =?us-ascii?Q?Y7REY+Ki6AG4pnhPg08h3ETbyrX5vksYiBNCleBZ1NGMFL8l5QW3c/1TGL1F?= =?us-ascii?Q?f2OMSEV3nyWJGa5jORVT4DkEhlOp3h+z+klb568ZOksWHnsXcGJCvj6dqYff?= =?us-ascii?Q?tLGwKNNU2y1ZgY2mzlq2H2NQN3wJz6kbIKsQycbGjpXuInSCH4KAxKepEP8t?= =?us-ascii?Q?tuhcqxw9WHA0o1lLIsngo38FYM0attBXZrzmYZgXvg1xOoPViPaPxED1rgn1?= =?us-ascii?Q?jNt9+F2KdOBGb7/UVQJ5S57nvUXnxL2lfqg8HXBr0Il8v+1OlxR/Sp4NAeQQ?= =?us-ascii?Q?lwrQ2CZnIVqsA3vObnBbnF0NjKPMdwotd2qZvQ//qZ3g5V1BSUahTIS9zL4h?= =?us-ascii?Q?9DiBtPzXHPGjYoRWZ6MxRq+eY9UD1HIrODZJMD/twxrUpOQkRHce3u+WYudK?= =?us-ascii?Q?9Dmor53JK3vkT7tNsqveOfjThbezjSFQwWNs7NSrnweLCRTTQgukDd+XNVot?= =?us-ascii?Q?2tvRuFjulz1EAXt2lfu/QriSYAUi4IZPYErS//CGr9IyCKzCQJ0zj0Gi4M9t?= =?us-ascii?Q?G0gZYc0yI3jAcAo7HsTErAOsJkgYoa9MYZNfbQRyEq4CP0cx1yoZiZqFSR8M?= =?us-ascii?Q?6OCMj7fML3YxX2jvv38W5FtPcfLXHyeq5uFQCQsGGhEw7GP118AKDtDz1UEp?= =?us-ascii?Q?pOUdMpCpkQFySlx054+JQn7BB7aipaMQx8ToKS9Z+qWglrLamdhfmf7+7xAj?= =?us-ascii?Q?BdFrOWn2r/2Bao3flHpEmOL9ANXBaKhjF8H6vD2MNhNGqhR/+xJPPqJcPpqz?= =?us-ascii?Q?/Tq8yYc2wpo4t5oQa21Zen/S+SiZ?= 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:(13230031)(36860700004)(82310400014)(376005)(1800799015)(7416005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 15:59:58.7042 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 62561f00-9790-4df0-3127-08dc647797a0 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: MN1PEPF0000F0E1.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5593 Content-Type: text/plain; charset="utf-8" The TSM attestation report support provides multiple configfs attribute types (both for standard and binary attributes) to allow for additional attributes to be displayed for SNP as compared to TDX. With the ability to hide attributes via configfs, consoldate the multiple attribute groups into a single standard attribute group and a single binary attribute group. Modify the TDX support to hide the attributes that were previously "hidden" as a result of registering the selective attribute groups. Co-developed-by: Dan Williams Signed-off-by: Dan Williams Signed-off-by: Tom Lendacky Reviewed-by: Kuppuswamy Sathyanarayanan Tested-by: Joerg Roedel --- drivers/virt/coco/sev-guest/sev-guest.c | 3 +- drivers/virt/coco/tdx-guest/tdx-guest.c | 29 ++++++++- drivers/virt/coco/tsm.c | 82 ++++++++++++------------- include/linux/tsm.h | 41 ++++++++++--- 4 files changed, 102 insertions(+), 53 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/se= v-guest/sev-guest.c index 2abb51bd034f..ec3d894cfe31 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include =20 @@ -975,7 +976,7 @@ static int __init sev_guest_probe(struct platform_devic= e *pdev) /* Set the privlevel_floor attribute based on the vmpck_id */ sev_tsm_ops.privlevel_floor =3D vmpck_id; =20 - ret =3D tsm_register(&sev_tsm_ops, snp_dev, &tsm_report_extra_type); + ret =3D tsm_register(&sev_tsm_ops, snp_dev); if (ret) goto e_free_cert_data; =20 diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/td= x-guest/tdx-guest.c index 1253bf76b570..964af57f345c 100644 --- a/drivers/virt/coco/tdx-guest/tdx-guest.c +++ b/drivers/virt/coco/tdx-guest/tdx-guest.c @@ -17,6 +17,7 @@ #include #include #include +#include =20 #include =20 @@ -249,6 +250,30 @@ static int tdx_report_new(struct tsm_report *report, v= oid *data) return ret; } =20 +static bool tdx_report_attr_visible(struct config_item *item, + struct configfs_attribute *attr, int n) +{ + switch (n) { + case TSM_REPORT_GENERATION: + case TSM_REPORT_PROVIDER: + return true; + } + + return false; +} + +static bool tdx_report_bin_attr_visible(struct config_item *item, + struct configfs_bin_attribute *attr, int n) +{ + switch (n) { + case TSM_REPORT_INBLOB: + case TSM_REPORT_OUTBLOB: + return true; + } + + return false; +} + static long tdx_guest_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -281,6 +306,8 @@ MODULE_DEVICE_TABLE(x86cpu, tdx_guest_ids); static const struct tsm_ops tdx_tsm_ops =3D { .name =3D KBUILD_MODNAME, .report_new =3D tdx_report_new, + .report_attr_visible =3D tdx_report_attr_visible, + .report_bin_attr_visible =3D tdx_report_bin_attr_visible, }; =20 static int __init tdx_guest_init(void) @@ -301,7 +328,7 @@ static int __init tdx_guest_init(void) goto free_misc; } =20 - ret =3D tsm_register(&tdx_tsm_ops, NULL, NULL); + ret =3D tsm_register(&tdx_tsm_ops, NULL); if (ret) goto free_quote; =20 diff --git a/drivers/virt/coco/tsm.c b/drivers/virt/coco/tsm.c index d1c2db83a8ca..dedb4f582630 100644 --- a/drivers/virt/coco/tsm.c +++ b/drivers/virt/coco/tsm.c @@ -14,7 +14,6 @@ =20 static struct tsm_provider { const struct tsm_ops *ops; - const struct config_item_type *type; void *data; } provider; static DECLARE_RWSEM(tsm_rwsem); @@ -252,34 +251,18 @@ static ssize_t tsm_report_auxblob_read(struct config_= item *cfg, void *buf, } CONFIGFS_BIN_ATTR_RO(tsm_report_, auxblob, NULL, TSM_OUTBLOB_MAX); =20 -#define TSM_DEFAULT_ATTRS() \ - &tsm_report_attr_generation, \ - &tsm_report_attr_provider - static struct configfs_attribute *tsm_report_attrs[] =3D { - TSM_DEFAULT_ATTRS(), + [TSM_REPORT_GENERATION] =3D &tsm_report_attr_generation, + [TSM_REPORT_PROVIDER] =3D &tsm_report_attr_provider, + [TSM_REPORT_PRIVLEVEL] =3D &tsm_report_attr_privlevel, + [TSM_REPORT_PRIVLEVEL_FLOOR] =3D &tsm_report_attr_privlevel_floor, NULL, }; =20 -static struct configfs_attribute *tsm_report_extra_attrs[] =3D { - TSM_DEFAULT_ATTRS(), - &tsm_report_attr_privlevel, - &tsm_report_attr_privlevel_floor, - NULL, -}; - -#define TSM_DEFAULT_BIN_ATTRS() \ - &tsm_report_attr_inblob, \ - &tsm_report_attr_outblob - static struct configfs_bin_attribute *tsm_report_bin_attrs[] =3D { - TSM_DEFAULT_BIN_ATTRS(), - NULL, -}; - -static struct configfs_bin_attribute *tsm_report_bin_extra_attrs[] =3D { - TSM_DEFAULT_BIN_ATTRS(), - &tsm_report_attr_auxblob, + [TSM_REPORT_INBLOB] =3D &tsm_report_attr_inblob, + [TSM_REPORT_OUTBLOB] =3D &tsm_report_attr_outblob, + [TSM_REPORT_AUXBLOB] =3D &tsm_report_attr_auxblob, NULL, }; =20 @@ -297,21 +280,12 @@ static struct configfs_item_operations tsm_report_ite= m_ops =3D { .release =3D tsm_report_item_release, }; =20 -const struct config_item_type tsm_report_default_type =3D { +static const struct config_item_type tsm_report_type =3D { .ct_owner =3D THIS_MODULE, .ct_bin_attrs =3D tsm_report_bin_attrs, .ct_attrs =3D tsm_report_attrs, .ct_item_ops =3D &tsm_report_item_ops, }; -EXPORT_SYMBOL_GPL(tsm_report_default_type); - -const struct config_item_type tsm_report_extra_type =3D { - .ct_owner =3D THIS_MODULE, - .ct_bin_attrs =3D tsm_report_bin_extra_attrs, - .ct_attrs =3D tsm_report_extra_attrs, - .ct_item_ops =3D &tsm_report_item_ops, -}; -EXPORT_SYMBOL_GPL(tsm_report_extra_type); =20 static struct config_item *tsm_report_make_item(struct config_group *group, const char *name) @@ -326,12 +300,40 @@ static struct config_item *tsm_report_make_item(struc= t config_group *group, if (!state) return ERR_PTR(-ENOMEM); =20 - config_item_init_type_name(&state->cfg, name, provider.type); + config_item_init_type_name(&state->cfg, name, &tsm_report_type); return &state->cfg; } =20 +static bool tsm_report_is_visible(struct config_item *item, + struct configfs_attribute *attr, int n) +{ + guard(rwsem_read)(&tsm_rwsem); + if (!provider.ops) + return false; + + if (!provider.ops->report_attr_visible) + return true; + + return provider.ops->report_attr_visible(item, attr, n); +} + +static bool tsm_report_is_bin_visible(struct config_item *item, + struct configfs_bin_attribute *attr, int n) +{ + guard(rwsem_read)(&tsm_rwsem); + if (!provider.ops) + return false; + + if (!provider.ops->report_bin_attr_visible) + return true; + + return provider.ops->report_bin_attr_visible(item, attr, n); +} + static struct configfs_group_operations tsm_report_group_ops =3D { .make_item =3D tsm_report_make_item, + .is_visible =3D tsm_report_is_visible, + .is_bin_visible =3D tsm_report_is_bin_visible, }; =20 static const struct config_item_type tsm_reports_type =3D { @@ -353,16 +355,10 @@ static struct configfs_subsystem tsm_configfs =3D { .su_mutex =3D __MUTEX_INITIALIZER(tsm_configfs.su_mutex), }; =20 -int tsm_register(const struct tsm_ops *ops, void *priv, - const struct config_item_type *type) +int tsm_register(const struct tsm_ops *ops, void *priv) { const struct tsm_ops *conflict; =20 - if (!type) - type =3D &tsm_report_default_type; - if (!(type =3D=3D &tsm_report_default_type || type =3D=3D &tsm_report_ext= ra_type)) - return -EINVAL; - guard(rwsem_write)(&tsm_rwsem); conflict =3D provider.ops; if (conflict) { @@ -372,7 +368,6 @@ int tsm_register(const struct tsm_ops *ops, void *priv, =20 provider.ops =3D ops; provider.data =3D priv; - provider.type =3D type; return 0; } EXPORT_SYMBOL_GPL(tsm_register); @@ -384,7 +379,6 @@ int tsm_unregister(const struct tsm_ops *ops) return -EBUSY; provider.ops =3D NULL; provider.data =3D NULL; - provider.type =3D NULL; return 0; } EXPORT_SYMBOL_GPL(tsm_unregister); diff --git a/include/linux/tsm.h b/include/linux/tsm.h index 50c5769657d8..fa19291a9854 100644 --- a/include/linux/tsm.h +++ b/include/linux/tsm.h @@ -4,6 +4,7 @@ =20 #include #include +#include =20 #define TSM_INBLOB_MAX 64 #define TSM_OUTBLOB_MAX SZ_32K @@ -42,12 +43,40 @@ struct tsm_report { u8 *auxblob; }; =20 +/** + * enum tsm_attr_index - index used to reference report attributes + * @TSM_REPORT_GENERATION: index of the report generation number attribute + * @TSM_REPORT_PROVIDER: index of the provider name attribute + * @TSM_REPORT_PRIVLEVEL: index of the desired privilege level attribute + * @TSM_REPORT_PRIVLEVEL_FLOOR: index of the minimum allowed privileg leve= l attribute + */ +enum tsm_attr_index { + TSM_REPORT_GENERATION, + TSM_REPORT_PROVIDER, + TSM_REPORT_PRIVLEVEL, + TSM_REPORT_PRIVLEVEL_FLOOR, +}; + +/** + * enum tsm_bin_attr_index - index used to reference binary report attribu= tes + * @TSM_REPORT_INBLOB: index of the binary report input attribute + * @TSM_REPORT_OUTBLOB: index of the binary report output attribute + * @TSM_REPORT_AUXBLOB: index of the binary auxiliary data attribute + */ +enum tsm_bin_attr_index { + TSM_REPORT_INBLOB, + TSM_REPORT_OUTBLOB, + TSM_REPORT_AUXBLOB, +}; + /** * struct tsm_ops - attributes and operations for tsm instances * @name: tsm id reflected in /sys/kernel/config/tsm/report/$report/provid= er * @privlevel_floor: convey base privlevel for nested scenarios * @report_new: Populate @report with the report blob and auxblob * (optional), return 0 on successful population, or -errno otherwise + * @report_attr_visible: show or hide a report attribute entry + * @report_bin_attr_visible: show or hide a report binary attribute entry * * Implementation specific ops, only one is expected to be registered at * a time i.e. only one of "sev-guest", "tdx-guest", etc. @@ -56,14 +85,12 @@ struct tsm_ops { const char *name; unsigned int privlevel_floor; int (*report_new)(struct tsm_report *report, void *data); + bool (*report_attr_visible)(struct config_item *item, + struct configfs_attribute *attr, int n); + bool (*report_bin_attr_visible)(struct config_item *item, + struct configfs_bin_attribute *attr, int n); }; =20 -extern const struct config_item_type tsm_report_default_type; - -/* publish @privlevel, @privlevel_floor, and @auxblob attributes */ -extern const struct config_item_type tsm_report_extra_type; - -int tsm_register(const struct tsm_ops *ops, void *priv, - const struct config_item_type *type); +int tsm_register(const struct tsm_ops *ops, void *priv); int tsm_unregister(const struct tsm_ops *ops); #endif /* __TSM_H */ --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2086.outbound.protection.outlook.com [40.107.223.86]) (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 65BF915FCED for ; Wed, 24 Apr 2024 16:00:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974414; cv=fail; b=X1Scz73tyIy3n6f2fFJj4kV7NklcjtKbnCku/wwYwuXu2gN4Lh9dzduzAc4YNT2aCiAiUgA6K//2v+69uRXrLAEkETxY3YqTChZeOVpRBiGDAFycL090Vcy1imumbSWKjdhLONzAQ3epdNEcPQBKOvJQ8SR1Xh54O+sl0UMGoB8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974414; c=relaxed/simple; bh=/hlUEmi/3nMxNlVWd88WDum92gfqJoGuKx5XLyEC4Wc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KgOQMOt/YkLQT3hFEVBENyXX4YvMcxTUbt9yjO91m+/ZLKz+2oSZqzrUCXqccf36E1VeH3Az3IaQHcsapYF0K569+ualtCAVTiwX2f2tPI6kL3hazxzFkYK77HrjL8YPQIjo8v3er+iQba6mD0OsmVmwab43xtVV+t+qTs1t+SE= 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=WnsXIyJI; arc=fail smtp.client-ip=40.107.223.86 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="WnsXIyJI" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MclyoeD2Sep/+IHhRWCAVDiGDySaAB4O7E8VQmwen/53H0Xw1TfdYaDCPm9MXulJi/CbzVzUB38Oy+pbSLDClswpUQk9Lp4hvslMqaNhPXTX/ixC+Nu9Ga4Yj4GtRG2DqCwDNTQkwqIjvqAjiqQSvRXTUrmjatErWGCuIhxLAIR768nFOfUtuW2Nnf3fB3NbdD2lSTiq2MMl75FeXAfyXRJDr33Uu3yvIb+gYemVGws0zysklyP4OHXx0S7mJXel8W798OACEpGLvA3HmL1J7HQYfafwlTP6yX12ORmbn9FFJJ8sOXGJQUTT49ddpDoVkPe1qiRj7VjwP6Px3ZLKWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=ELZcJgxOSXODzN2532DoRKWi17pLvwTMLPyCdzX2jG0=; b=nW/3xc6TYV16XgMibQYmYVxdL+X2nYfslyaVoXtC4QzyVojwqudAkGIjC/MK5TWxmbc2GtrQXbOILJO1s1ITnjfoZRaW3sYeGvcP5wmHhdcDLZrel1RJ9miHI69Tvm3rLhTUZy9+Zd/PRXJt9AaXOqPo8pMr9wpg+bV/8Qt0eS7LcEtKwX/kKUj6sx/RGA1cOAdb9XJe8oGTALt4OdRmcFbvhpFD28ZOrlPestZocZR/W7vg1sNTQtx77I8uZ7BKoxlGF3KX5kqJ7eaH95kzOR0IsQsRxvY/aoEuiznKW+sw5tJUJ1GePFihEK+N+r2VHD/AlHRJoPAWxgLNaXqUHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=ELZcJgxOSXODzN2532DoRKWi17pLvwTMLPyCdzX2jG0=; b=WnsXIyJI4FqKne2+DpvzJ+5ooFLlt3XIAcdUZxaQSGeksVQqtw/oDeFaivgGbrSStdnlfpqVYpqPrbJTDNTClozuxZCp/WERfX3XozaTSvHk7BBieSq2QKS/T55lyDHoFR+ASlxot3oeZlWElluGE2BWNMm7MJ6MyYxLXcm4ZHQ= Received: from MN2PR22CA0029.namprd22.prod.outlook.com (2603:10b6:208:238::34) by SA3PR12MB7808.namprd12.prod.outlook.com (2603:10b6:806:31b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 16:00:06 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:238:cafe::dc) by MN2PR22CA0029.outlook.office365.com (2603:10b6:208:238::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.23 via Frontend Transport; Wed, 24 Apr 2024 16:00:06 +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 MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 16:00:05 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 11:00:04 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 14/15] x86/sev: Extend the config-fs attestation support for an SVSM Date: Wed, 24 Apr 2024 10:58:10 -0500 Message-ID: <9a4c4a16d00834c1b7ff458e25c185ac1c9bcf79.1713974291.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E2:EE_|SA3PR12MB7808:EE_ X-MS-Office365-Filtering-Correlation-Id: 5acb26f5-9bf1-4ced-39f5-08dc64779bf6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?qYXBU6hmAAFejkU0JFyiNwQeupeY4xOlwr6orqL65E02GDZekfWlzjSDy1EG?= =?us-ascii?Q?cxrreDh5d7UvDx9jFIVs3FoQP1LoFGjZNsWn/0CZCYvncPIGWZFhg/79O6Xd?= =?us-ascii?Q?S+jkelkI5RrpyiEqfoTMpl2pUpazur8ymueeCBcnoG8ztnvK8Y7jDuVZAXDi?= =?us-ascii?Q?17F2CcrQ55K9VEAo580PBlicsS+lHsQjp087ZlPxMJe8U8pA2GIwlDwwFREo?= =?us-ascii?Q?9gsFCpP6uAQU0RqDJ2syI0VPr62EhKdJgruodMN7OTm4a2YS1+NuiNmUCpdU?= =?us-ascii?Q?n9jRzS00OQQcULJqFk9i8IIMIoa/gMXcAUgRxSR+cZ4YAp2FHmbydiBews5J?= =?us-ascii?Q?Sw8x3HgfvjdzJNi7pqcrDbs5qYQ2vxcSvxWgIskICk8n+Sype7LOZVfFPeBZ?= =?us-ascii?Q?Yud/Wdduhy90PGmnw0IsqVbLYTR3vY/RjR5wzvPy9URmo6PpoxWNQ2UK5Oe1?= =?us-ascii?Q?Vw2+ZtzQPfi2ZLqyi4LC2bIbmdJ8WrJZVOIPqGJk8iNPpajOO2k1MwmwleUR?= =?us-ascii?Q?TrqDJz+/+8EBLELUedmD+DYQsljd0HBm3AOU/bfD/az2LiXHycdP4rkvU5dP?= =?us-ascii?Q?IhB59UU7FhqmDl9LFpfwte5Tanrrv+jm4ESiqLX/M0O9HWslPomuwd7NBVnN?= =?us-ascii?Q?tdkSP+rId3YqQJJdxqdUU5jM5RPFWm7vnnq+rUvFj0cQZX5N9WY36aeH2PJz?= =?us-ascii?Q?li2uJ2h6xiuoXBpEdyBIDDIaAZPSoCNSg/UVS/JIaRRLr0zRsa65xii582Hb?= =?us-ascii?Q?iH++pPlbmqJ8b3BWS56iX5cK1lydBzfdE/AqOdZN766oNquLQ0pyBDx0NUPF?= =?us-ascii?Q?TuDyjINMIQfn5p8eTchjXbmXeoSMYJleY75hjwuy3tCt9PuajCha1hXK3MUm?= =?us-ascii?Q?Ljcuy+sgbgckxGqzBNBzqwqhGC2G+vszM6+m/mAoYhKrDd3nki074mHmw6wK?= =?us-ascii?Q?D590hlZC7DKHQOdv94ebJ14EvF9KM/jUH4v/MxL2zJbfXDbIBmFnZdHlo4eh?= =?us-ascii?Q?sgkXoqxg9Ewi+ZiE7mdPYQ2xHlvlLETwAUbcKe+xDBzjJ159Qt1oXCJ2A570?= =?us-ascii?Q?Yc2mI7DjhmeCWBTKydhUrtudugsbS2XDLNPv0B89YR+I05MtIce0Rs0i+Cwd?= =?us-ascii?Q?jSnTZOrvT3gsb7MstwA7zY44zWIb8Ucc32rStJWB0OpN0HGqUxWWH61NQWjs?= =?us-ascii?Q?HdQM8CoYiJHCvW4o0SLX0rGRpWU3uR9V+tONry7o9psMCCjTH0tl8w0UafME?= =?us-ascii?Q?kUB35NQWfLdnt3Z8iPWN7xniIsESm7sH53szOvt31MheTW/W4IX0NYfccXJi?= =?us-ascii?Q?muJgAArPekI+66mpQ4RVx5vfPAFcTX+/LrwfSTxbOLXkPus7Jh2FI8qPn0Fd?= =?us-ascii?Q?bjhkRBpvSV/axtKB/Ms/WR2YScfD?= 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:(13230031)(1800799015)(36860700004)(82310400014)(7416005)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 16:00:05.9790 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5acb26f5-9bf1-4ced-39f5-08dc64779bf6 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: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7808 Content-Type: text/plain; charset="utf-8" When an SVSM is present, the guest can also request attestation reports from the SVSM. These SVSM attestation reports can be used to attest the SVSM and any services running within the SVSM. Extend the config-fs attestation support to allow for an SVSM attestation report. This involves creating four (4) new config-fs attributes: - 'service-provider' (input) This attribute is used to determine whether the attestation request should be sent to the specified service provider or to the SEV firmware. The SVSM service provider is represented by the value 'svsm'. - 'service_guid' (input) Used for requesting the attestation of a single service within the service provider. A null GUID implies that the SVSM_ATTEST_SERVICES call should be used to request the attestation report. A non-null GUID implies that the SVSM_ATTEST_SINGLE_SERVICE call should be used. - 'service_manifest_version' (input) Used with the SVSM_ATTEST_SINGLE_SERVICE call, the service version represents a specific service manifest version be used for the attestation report. - 'manifestblob' (output) Used to return the service manifest associated with the attestation report. Only display these new attributes when running under an SVSM. Signed-off-by: Tom Lendacky Tested-by: Joerg Roedel --- Documentation/ABI/testing/configfs-tsm | 63 ++++++++ arch/x86/include/asm/sev.h | 31 +++- arch/x86/kernel/sev.c | 50 +++++++ drivers/virt/coco/sev-guest/sev-guest.c | 186 ++++++++++++++++++++++++ drivers/virt/coco/tsm.c | 93 +++++++++++- include/linux/tsm.h | 19 +++ 6 files changed, 439 insertions(+), 3 deletions(-) diff --git a/Documentation/ABI/testing/configfs-tsm b/Documentation/ABI/tes= ting/configfs-tsm index dd24202b5ba5..bc8f6efa5d6f 100644 --- a/Documentation/ABI/testing/configfs-tsm +++ b/Documentation/ABI/testing/configfs-tsm @@ -31,6 +31,18 @@ Description: Standardization v2.03 Section 4.1.8.1 MSG_REPORT_REQ. https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/spe= cifications/56421.pdf =20 +What: /sys/kernel/config/tsm/report/$name/manifestblob +Date: January, 2024 +KernelVersion: v6.10 +Contact: linux-coco@lists.linux.dev +Description: + (RO) Optional supplemental data that a TSM may emit, visibility + of this attribute depends on TSM, and may be empty if no + manifest data is available. + + See 'service_provider' for information on the format of the + manifest blob. + What: /sys/kernel/config/tsm/report/$name/provider Date: September, 2023 KernelVersion: v6.7 @@ -80,3 +92,54 @@ Contact: linux-coco@lists.linux.dev Description: (RO) Indicates the minimum permissible value that can be written to @privlevel. + +What: /sys/kernel/config/tsm/report/$name/service_provider +Date: January, 2024 +KernelVersion: v6.10 +Contact: linux-coco@lists.linux.dev +Description: + (WO) Attribute is visible if a TSM implementation provider + supports the concept of attestation reports from a service + provider for TVMs, like SEV-SNP running under an SVSM. + Specifying the service provider via this attribute will create + an attestation report as specified by the service provider. + Currently supported service-providers are: + svsm + + For the "svsm" service provider, see the Secure VM Service Module + for SEV-SNP Guests v1.00 Section 7. + https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/spe= cifications/58019.pdf + +What: /sys/kernel/config/tsm/report/$name/service_guid +Date: January, 2024 +KernelVersion: v6.10 +Contact: linux-coco@lists.linux.dev +Description: + (WO) Attribute is visible if a TSM implementation provider + supports the concept of attestation reports from a service + provider for TVMs, like SEV-SNP running under an SVSM. + Specifying an empty/null GUID (00000000-0000-0000-0000-000000) + requests all active services within the service provider be + part of the attestation report. Specifying a GUID request + an attestation report of just the specified service using the + manifest form specified by the service_manifest_version + attribute. + + See 'service_provider' for information on the format of the + service guid. + +What: /sys/kernel/config/tsm/report/$name/service_manifest_version +Date: January, 2024 +KernelVersion: v6.10 +Contact: linux-coco@lists.linux.dev +Description: + (WO) Attribute is visible if a TSM implementation provider + supports the concept of attestation reports from a service + provider for TVMs, like SEV-SNP running under an SVSM. + Indicates the service manifest version requested for the + attestation report (default 0). If this field is not set by + the user, the default manifest version of the service (the + service's initial/first manifest version) is returned. + + See 'service_provider' for information on the format of the + service manifest version. diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 64fcadd6d602..2c66e7f2a7c7 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -209,6 +209,27 @@ struct svsm_pvalidate_call { struct svsm_pvalidate_entry entry[]; }; =20 +/* + * The SVSM Attestation related structures + */ +struct svsm_location_entry { + u64 pa; + u32 len; + u8 rsvd[4]; +}; + +struct svsm_attestation_call { + struct svsm_location_entry report_buffer; + struct svsm_location_entry nonce; + struct svsm_location_entry manifest_buffer; + struct svsm_location_entry certificates_buffer; + + /* For attesting a single service */ + u8 service_guid[16]; + u32 service_manifest_version; + u8 rsvd[4]; +}; + /* * SVSM protocol structure */ @@ -232,6 +253,10 @@ struct svsm_call { #define SVSM_CORE_CREATE_VCPU 2 #define SVSM_CORE_DELETE_VCPU 3 =20 +#define SVSM_ATTEST_CALL(x) ((1ULL << 32) | (x)) +#define SVSM_ATTEST_SERVICES 0 +#define SVSM_ATTEST_SINGLE_SERVICE 1 + #ifdef CONFIG_AMD_MEM_ENCRYPT extern void __sev_es_ist_enter(struct pt_regs *regs); extern void __sev_es_ist_exit(void); @@ -302,6 +327,7 @@ bool snp_init(struct boot_params *bp); void __noreturn snp_abort(void); void snp_dmi_setup(void); int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, str= uct snp_guest_request_ioctl *rio); +int snp_issue_svsm_attestation_request(u64 call_id, struct svsm_attestatio= n_call *input); void snp_accept_memory(phys_addr_t start, phys_addr_t end); u64 snp_get_unsupported_features(u64 status); u64 sev_get_status(void); @@ -332,7 +358,10 @@ static inline int snp_issue_guest_request(u64 exit_cod= e, struct snp_req_data *in { return -ENOTTY; } - +static inline int snp_issue_svsm_attestation_request(u64 call_id, struct s= vsm_attestation_call *input) +{ + return -ENOTTY; +} static inline void snp_accept_memory(phys_addr_t start, phys_addr_t end) {= } static inline u64 snp_get_unsupported_features(u64 status) { return 0; } static inline u64 sev_get_status(void) { return 0; } diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 75f11da867a3..5e71c94b952c 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2390,6 +2390,56 @@ static int __init init_sev_config(char *str) } __setup("sev=3D", init_sev_config); =20 +static void update_attestation_input(struct svsm_call *call, struct svsm_a= ttestation_call *input) +{ + /* If (new) lengths have been returned, propograte them up */ + if (call->rcx_out !=3D call->rcx) + input->manifest_buffer.len =3D call->rcx_out; + + if (call->rdx_out !=3D call->rdx) + input->certificates_buffer.len =3D call->rdx_out; + + if (call->r8_out !=3D call->r8) + input->report_buffer.len =3D call->r8_out; +} + +int snp_issue_svsm_attestation_request(u64 call_id, struct svsm_attestatio= n_call *input) +{ + struct svsm_attestation_call *attest_call; + struct svsm_call call =3D {}; + unsigned long flags; + u64 attest_call_pa; + int ret; + + if (!vmpl) + return -EINVAL; + + local_irq_save(flags); + + call.caa =3D __svsm_get_caa(); + + attest_call =3D (struct svsm_attestation_call *)call.caa->svsm_buffer; + attest_call_pa =3D __svsm_get_caa_pa() + offsetof(struct svsm_ca, svsm_bu= ffer); + + *attest_call =3D *input; + + /* + * Set input registers for the request and set RDX and R8 to known + * values in order to detect length values being returned in them. + */ + call.rax =3D call_id; + call.rcx =3D attest_call_pa; + call.rdx =3D -1; + call.r8 =3D -1; + ret =3D svsm_protocol(&call); + update_attestation_input(&call, input); + + local_irq_restore(flags); + + return ret; +} +EXPORT_SYMBOL_GPL(snp_issue_svsm_attestation_request); + int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, str= uct snp_guest_request_ioctl *rio) { struct ghcb_state state; diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/se= v-guest/sev-guest.c index ec3d894cfe31..d37a8b27d12a 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -39,6 +39,8 @@ #define SNP_REQ_MAX_RETRY_DURATION (60*HZ) #define SNP_REQ_RETRY_DELAY (2*HZ) =20 +#define SVSM_MAX_RETRIES 3 + struct snp_guest_crypto { struct crypto_aead *tfm; u8 *iv, *authtag; @@ -784,6 +786,148 @@ struct snp_msg_cert_entry { u32 length; }; =20 +static int sev_svsm_report_new(struct tsm_report *report, void *data) +{ + unsigned int report_len, manifest_len, certificates_len; + void *report_blob, *manifest_blob, *certificates_blob; + struct svsm_attestation_call attest_call =3D {}; + struct tsm_desc *desc =3D &report->desc; + unsigned int retry_count; + unsigned int size; + bool try_again; + void *buffer; + u64 call_id; + int ret; + + /* + * Allocate pages for the request: + * - Report blob (4K) + * - Manifest blob (4K) + * - Certificate blob (16K) + * + * Above addresses must be 4K aligned + */ + report_len =3D SZ_4K; + manifest_len =3D SZ_4K; + certificates_len =3D SEV_FW_BLOB_MAX_SIZE; + + if (guid_is_null(&desc->service_guid)) { + call_id =3D SVSM_ATTEST_CALL(SVSM_ATTEST_SERVICES); + } else { + export_guid(attest_call.service_guid, &desc->service_guid); + attest_call.service_manifest_version =3D desc->service_manifest_version; + + call_id =3D SVSM_ATTEST_CALL(SVSM_ATTEST_SINGLE_SERVICE); + } + + retry_count =3D 0; + +retry: + size =3D report_len + manifest_len + certificates_len; + buffer =3D alloc_pages_exact(size, __GFP_ZERO); + if (!buffer) + return -ENOMEM; + + report_blob =3D buffer; + attest_call.report_buffer.pa =3D __pa(report_blob); + attest_call.report_buffer.len =3D report_len; + + manifest_blob =3D report_blob + report_len; + attest_call.manifest_buffer.pa =3D __pa(manifest_blob); + attest_call.manifest_buffer.len =3D manifest_len; + + certificates_blob =3D manifest_blob + manifest_len; + attest_call.certificates_buffer.pa =3D __pa(certificates_blob); + attest_call.certificates_buffer.len =3D certificates_len; + + attest_call.nonce.pa =3D __pa(desc->inblob); + attest_call.nonce.len =3D desc->inblob_len; + + ret =3D snp_issue_svsm_attestation_request(call_id, &attest_call); + switch (ret) { + case SVSM_SUCCESS: + break; + case SVSM_ERR_INVALID_PARAMETER: + ret =3D -EINVAL; + + if (retry_count >=3D SVSM_MAX_RETRIES) + goto error; + + try_again =3D false; + + if (attest_call.report_buffer.len > report_len) { + report_len =3D PAGE_ALIGN(attest_call.report_buffer.len); + try_again =3D true; + } + + if (attest_call.manifest_buffer.len > manifest_len) { + manifest_len =3D PAGE_ALIGN(attest_call.manifest_buffer.len); + try_again =3D true; + } + + if (attest_call.certificates_buffer.len > certificates_len) { + certificates_len =3D PAGE_ALIGN(attest_call.certificates_buffer.len); + try_again =3D true; + } + + /* If one of the buffers wasn't large enough, retry the request */ + if (try_again) { + free_pages_exact(buffer, size); + retry_count++; + goto retry; + } + + goto error; + case SVSM_ERR_BUSY: + ret =3D -EAGAIN; + goto error; + default: + pr_err_ratelimited("SVSM attestation request failed (%#x)\n", ret); + ret =3D -EINVAL; + goto error; + } + + ret =3D -ENOMEM; + + report_len =3D attest_call.report_buffer.len; + void *rbuf __free(kvfree) =3D kvzalloc(report_len, GFP_KERNEL); + if (!rbuf) + goto error; + + memcpy(rbuf, report_blob, report_len); + report->outblob =3D no_free_ptr(rbuf); + report->outblob_len =3D report_len; + + manifest_len =3D attest_call.manifest_buffer.len; + void *mbuf __free(kvfree) =3D kvzalloc(manifest_len, GFP_KERNEL); + if (!mbuf) + goto error; + + memcpy(mbuf, manifest_blob, manifest_len); + report->manifestblob =3D no_free_ptr(mbuf); + report->manifestblob_len =3D manifest_len; + + certificates_len =3D attest_call.certificates_buffer.len; + if (!certificates_len) + goto success; + + void *cbuf __free(kvfree) =3D kvzalloc(certificates_len, GFP_KERNEL); + if (!cbuf) + goto error; + + memcpy(cbuf, certificates_blob, certificates_len); + report->auxblob =3D no_free_ptr(cbuf); + report->auxblob_len =3D certificates_len; + +success: + ret =3D 0; + +error: + free_pages_exact(buffer, size); + + return ret; +} + static int sev_report_new(struct tsm_report *report, void *data) { struct snp_msg_cert_entry *cert_table; @@ -798,6 +942,13 @@ static int sev_report_new(struct tsm_report *report, v= oid *data) if (desc->inblob_len !=3D SNP_REPORT_USER_DATA_SIZE) return -EINVAL; =20 + if (desc->service_provider) { + if (strcmp(desc->service_provider, "svsm")) + return -EINVAL; + + return sev_svsm_report_new(report, data); + } + void *buf __free(kvfree) =3D kvzalloc(size, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -886,9 +1037,44 @@ static int sev_report_new(struct tsm_report *report, = void *data) return 0; } =20 +static bool sev_report_attr_visible(struct config_item *item, + struct configfs_attribute *attr, int n) +{ + switch (n) { + case TSM_REPORT_GENERATION: + case TSM_REPORT_PROVIDER: + case TSM_REPORT_PRIVLEVEL: + case TSM_REPORT_PRIVLEVEL_FLOOR: + return true; + case TSM_REPORT_SERVICE_PROVIDER: + case TSM_REPORT_SERVICE_GUID: + case TSM_REPORT_SERVICE_MANIFEST_VER: + return snp_get_vmpl(); + } + + return false; +} + +static bool sev_report_bin_attr_visible(struct config_item *item, + struct configfs_bin_attribute *attr, int n) +{ + switch (n) { + case TSM_REPORT_INBLOB: + case TSM_REPORT_OUTBLOB: + case TSM_REPORT_AUXBLOB: + return true; + case TSM_REPORT_MANIFESTBLOB: + return snp_get_vmpl(); + } + + return false; +} + static struct tsm_ops sev_tsm_ops =3D { .name =3D KBUILD_MODNAME, .report_new =3D sev_report_new, + .report_attr_visible =3D sev_report_attr_visible, + .report_bin_attr_visible =3D sev_report_bin_attr_visible, }; =20 static void unregister_sev_tsm(void *data) diff --git a/drivers/virt/coco/tsm.c b/drivers/virt/coco/tsm.c index dedb4f582630..3c9587e8746b 100644 --- a/drivers/virt/coco/tsm.c +++ b/drivers/virt/coco/tsm.c @@ -34,7 +34,7 @@ static DECLARE_RWSEM(tsm_rwsem); * The attestation report format is TSM provider specific, when / if a sta= ndard * materializes that can be published instead of the vendor layout. Until = then * the 'provider' attribute indicates the format of 'outblob', and optiona= lly - * 'auxblob'. + * 'auxblob' and 'manifestblob'. */ =20 struct tsm_report_state { @@ -47,6 +47,7 @@ struct tsm_report_state { enum tsm_data_select { TSM_REPORT, TSM_CERTS, + TSM_MANIFEST, }; =20 static struct tsm_report *to_tsm_report(struct config_item *cfg) @@ -118,6 +119,74 @@ static ssize_t tsm_report_privlevel_floor_show(struct = config_item *cfg, } CONFIGFS_ATTR_RO(tsm_report_, privlevel_floor); =20 +static ssize_t tsm_report_service_provider_store(struct config_item *cfg, + const char *buf, size_t len) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + size_t sp_len; + char *sp; + int rc; + + guard(rwsem_write)(&tsm_rwsem); + rc =3D try_advance_write_generation(report); + if (rc) + return rc; + + sp_len =3D (buf[len - 1] !=3D '\n') ? len : len - 1; + + sp =3D kstrndup(buf, sp_len, GFP_KERNEL); + if (!sp) + return -ENOMEM; + kfree(report->desc.service_provider); + + report->desc.service_provider =3D sp; + + return len; +} +CONFIGFS_ATTR_WO(tsm_report_, service_provider); + +static ssize_t tsm_report_service_guid_store(struct config_item *cfg, + const char *buf, size_t len) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + int rc; + + guard(rwsem_write)(&tsm_rwsem); + rc =3D try_advance_write_generation(report); + if (rc) + return rc; + + report->desc.service_guid =3D guid_null; + + rc =3D guid_parse(buf, &report->desc.service_guid); + if (rc) + return rc; + + return len; +} +CONFIGFS_ATTR_WO(tsm_report_, service_guid); + +static ssize_t tsm_report_service_manifest_version_store(struct config_ite= m *cfg, + const char *buf, size_t len) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + unsigned int val; + int rc; + + rc =3D kstrtouint(buf, 0, &val); + if (rc) + return rc; + + guard(rwsem_write)(&tsm_rwsem); + rc =3D try_advance_write_generation(report); + if (rc) + return rc; + report->desc.service_manifest_version =3D val; + + return len; +} +CONFIGFS_ATTR_WO(tsm_report_, service_manifest_version); + static ssize_t tsm_report_inblob_write(struct config_item *cfg, const void *buf, size_t count) { @@ -162,6 +231,9 @@ static ssize_t __read_report(struct tsm_report *report,= void *buf, size_t count, if (select =3D=3D TSM_REPORT) { out =3D report->outblob; len =3D report->outblob_len; + } else if (select =3D=3D TSM_MANIFEST) { + out =3D report->manifestblob; + len =3D report->manifestblob_len; } else { out =3D report->auxblob; len =3D report->auxblob_len; @@ -187,7 +259,7 @@ static ssize_t read_cached_report(struct tsm_report *re= port, void *buf, =20 /* * A given TSM backend always fills in ->outblob regardless of - * whether the report includes an auxblob or not. + * whether the report includes an auxblob/manifestblob or not. */ if (!report->outblob || state->read_generation !=3D state->write_generation) @@ -223,8 +295,10 @@ static ssize_t tsm_report_read(struct tsm_report *repo= rt, void *buf, =20 kvfree(report->outblob); kvfree(report->auxblob); + kvfree(report->manifestblob); report->outblob =3D NULL; report->auxblob =3D NULL; + report->manifestblob =3D NULL; rc =3D ops->report_new(report, provider.data); if (rc < 0) return rc; @@ -251,11 +325,23 @@ static ssize_t tsm_report_auxblob_read(struct config_= item *cfg, void *buf, } CONFIGFS_BIN_ATTR_RO(tsm_report_, auxblob, NULL, TSM_OUTBLOB_MAX); =20 +static ssize_t tsm_report_manifestblob_read(struct config_item *cfg, void = *buf, + size_t count) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + + return tsm_report_read(report, buf, count, TSM_MANIFEST); +} +CONFIGFS_BIN_ATTR_RO(tsm_report_, manifestblob, NULL, TSM_OUTBLOB_MAX); + static struct configfs_attribute *tsm_report_attrs[] =3D { [TSM_REPORT_GENERATION] =3D &tsm_report_attr_generation, [TSM_REPORT_PROVIDER] =3D &tsm_report_attr_provider, [TSM_REPORT_PRIVLEVEL] =3D &tsm_report_attr_privlevel, [TSM_REPORT_PRIVLEVEL_FLOOR] =3D &tsm_report_attr_privlevel_floor, + [TSM_REPORT_SERVICE_PROVIDER] =3D &tsm_report_attr_service_provider, + [TSM_REPORT_SERVICE_GUID] =3D &tsm_report_attr_service_guid, + [TSM_REPORT_SERVICE_MANIFEST_VER] =3D &tsm_report_attr_service_manifest_v= ersion, NULL, }; =20 @@ -263,6 +349,7 @@ static struct configfs_bin_attribute *tsm_report_bin_at= trs[] =3D { [TSM_REPORT_INBLOB] =3D &tsm_report_attr_inblob, [TSM_REPORT_OUTBLOB] =3D &tsm_report_attr_outblob, [TSM_REPORT_AUXBLOB] =3D &tsm_report_attr_auxblob, + [TSM_REPORT_MANIFESTBLOB] =3D &tsm_report_attr_manifestblob, NULL, }; =20 @@ -271,8 +358,10 @@ static void tsm_report_item_release(struct config_item= *cfg) struct tsm_report *report =3D to_tsm_report(cfg); struct tsm_report_state *state =3D to_state(report); =20 + kvfree(report->manifestblob); kvfree(report->auxblob); kvfree(report->outblob); + kfree(report->desc.service_provider); kfree(state); } =20 diff --git a/include/linux/tsm.h b/include/linux/tsm.h index fa19291a9854..7c52a16a61c3 100644 --- a/include/linux/tsm.h +++ b/include/linux/tsm.h @@ -5,6 +5,7 @@ #include #include #include +#include =20 #define TSM_INBLOB_MAX 64 #define TSM_OUTBLOB_MAX SZ_32K @@ -20,11 +21,17 @@ * @privlevel: optional privilege level to associate with @outblob * @inblob_len: sizeof @inblob * @inblob: arbitrary input data + * @service_provider: optional name of where to obtain the tsm report blob + * @service_guid: optional service-provider service guid to attest + * @service_manifest_version: optional service-provider service manifest v= ersion requested */ struct tsm_desc { unsigned int privlevel; size_t inblob_len; u8 inblob[TSM_INBLOB_MAX]; + char *service_provider; + guid_t service_guid; + unsigned int service_manifest_version; }; =20 /** @@ -34,6 +41,8 @@ struct tsm_desc { * @outblob: generated evidence to provider to the attestation agent * @auxblob_len: sizeof(@auxblob) * @auxblob: (optional) auxiliary data to the report (e.g. certificate dat= a) + * @manifestblob_len: sizeof(@manifestblob) + * @manifestblob: (optional) manifest data associated with the report */ struct tsm_report { struct tsm_desc desc; @@ -41,6 +50,8 @@ struct tsm_report { u8 *outblob; size_t auxblob_len; u8 *auxblob; + size_t manifestblob_len; + u8 *manifestblob; }; =20 /** @@ -49,12 +60,18 @@ struct tsm_report { * @TSM_REPORT_PROVIDER: index of the provider name attribute * @TSM_REPORT_PRIVLEVEL: index of the desired privilege level attribute * @TSM_REPORT_PRIVLEVEL_FLOOR: index of the minimum allowed privileg leve= l attribute + * @TSM_REPORT_SERVICE_PROVIDER: index of the service provider identifier = attribute + * @TSM_REPORT_SERVICE_GUID: index of the service GUID attribute + * @TSM_REPORT_SERVICE_MANIFEST_VER: index of the service manifest version= attribute */ enum tsm_attr_index { TSM_REPORT_GENERATION, TSM_REPORT_PROVIDER, TSM_REPORT_PRIVLEVEL, TSM_REPORT_PRIVLEVEL_FLOOR, + TSM_REPORT_SERVICE_PROVIDER, + TSM_REPORT_SERVICE_GUID, + TSM_REPORT_SERVICE_MANIFEST_VER, }; =20 /** @@ -62,11 +79,13 @@ enum tsm_attr_index { * @TSM_REPORT_INBLOB: index of the binary report input attribute * @TSM_REPORT_OUTBLOB: index of the binary report output attribute * @TSM_REPORT_AUXBLOB: index of the binary auxiliary data attribute + * @TSM_REPORT_MANIFESTBLOB: index of the binary manifest data attribute */ enum tsm_bin_attr_index { TSM_REPORT_INBLOB, TSM_REPORT_OUTBLOB, TSM_REPORT_AUXBLOB, + TSM_REPORT_MANIFESTBLOB, }; =20 /** --=20 2.43.2 From nobody Sat May 18 05:34:49 2024 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2056.outbound.protection.outlook.com [40.107.92.56]) (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 5D9A516E88C for ; Wed, 24 Apr 2024 16:00:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974423; cv=fail; b=bF6KXpgXBks/EZ4myFaJsRUYurlshStY9XeyX02Wk6f7Lvy3KdsDhvwFWvPQls1wVX9e7nyVKY7gTMHdXLGBqIGGDAD0BMmgNgt4OgPmd5J6JUSxtGjB1GU5lpSecdInk5RPWjVUm7tFx/SbXNVADRDeztfQ3z6iUCNM/rCWX1g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974423; c=relaxed/simple; bh=+38lmpMDTgZ2Niu7oLxh2G+nJKe19ji5QylGc4FUHaE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pW5GmD81GcQSdwjyEmwgmKgMy/35yQnIM5rxomKbuuKSJggwFSJCtWSlc/ks3tcRzo/zlH5V3CxwHT4/tHzmH7O4YgbrHHphovIdHBCaS2Es0Z/jTBvczjqQb8U+5m3Ep9AW75UbMzUiYBCffh7yzLvvXoYijs8yiRfQerS/LoE= 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=A2fLWdqM; arc=fail smtp.client-ip=40.107.92.56 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="A2fLWdqM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HZiE4/BiG9Z3lkvb1ZReoap9OKj24kK4bUaZU8DNsv8l5NeelHkdkhzFLiraGwmtJ/laUawwME6yIagwpnkY5W5YaT3o5AaPBTtfZ5BtxKkGBL6QqtNIEqjQFXpgfzQPdaRiwSGDkTgSFXlZ8OtqK3rnJ1BFbluNgxlf0c+duYynccY3sBp+k9mHqY/bORJ+r+HZ7dUdxKDnu3J59CattJJjlGabaPERN4lX2N9Xyl1P6H5jGfykQoR5dW7afe1QkQcO1CM+FXVJH6M/ZZIVJR6qxIr3ilSQvreLOCiTTZyVXXvgQk4z43SDq//wqqeWywnRqkX6swKfuHmoR+UNlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=CC6wYJAT7yq+DcXjqFCtejixHwkeemgza4tXTDKb0Hw=; b=VsE+ur5/TVQ0uSqHLpYP+HlEAhD9/xl+sFAVtE/OEpfNymZp2gUdCX6Uw4uPZKHT9k5RS/Sa4IZ15VAo1szeuQddsWTpkurL0JZNZksfDDi9gd6FGomINcyAdf2xgpII/aoI4H3EJEzlUnwRsdGrRweOyfJUrO9PvnuAEzW/9TI6rrWNQ0FMwFc16NGLMo+H5VnjbnPXWhsb7Whx70gDbsayHyRh8oFvRMEzE9JH0m/n5kOf3BvqfktQmbCy3f3x6ZryjX9T+ZeSbUH5FfLZti8SK2PE90cbdAgQi/8CGdnTFF2TliEGVcHv75OUbAebyUWD8iI80GwJeFeSBhfZog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=CC6wYJAT7yq+DcXjqFCtejixHwkeemgza4tXTDKb0Hw=; b=A2fLWdqMVAD7JNJoL0XWK4fD3+lHBWbTi8ogXQzFLwJLTHUGL0ks5OQ4nw9eIQ6b4WFABH0fP+L9ZsCzGkNXJ5fHO5refMA0yuhdrc1HHsjLlQHrcmgCiM/ZeSQ5YoPnI+YCIcM6AaSEjOi4vi9yPwb1mIiCMEUVKOc37zmsmsI= Received: from MN2PR08CA0010.namprd08.prod.outlook.com (2603:10b6:208:239::15) by BL1PR12MB5898.namprd12.prod.outlook.com (2603:10b6:208:396::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 16:00:13 +0000 Received: from MN1PEPF0000F0E4.namprd04.prod.outlook.com (2603:10b6:208:239:cafe::6e) by MN2PR08CA0010.outlook.office365.com (2603:10b6:208:239::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22 via Frontend Transport; Wed, 24 Apr 2024 16:00:13 +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 MN1PEPF0000F0E4.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 16:00:13 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Wed, 24 Apr 2024 11:00:12 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v4 15/15] x86/sev: Allow non-VMPL0 execution when an SVSM is present Date: Wed, 24 Apr 2024 10:58:11 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E4:EE_|BL1PR12MB5898:EE_ X-MS-Office365-Filtering-Correlation-Id: df11f22f-7735-410b-7a31-08dc6477a039 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?SvnuNda6EsdiMhvpFvgG/XKYbaVoZhFIPBw9HzVQ4L8RzOYXFoMDUP2YKmBB?= =?us-ascii?Q?p3Dsm+KNblMGLUXDHsvNdm0y4gMMV1p6LkDpeuFJcZ1v/7cvuplLCFwXt1Pd?= =?us-ascii?Q?/uwm3i9SLS8i3bUh5JTpECKTLzwuJnyyM0FH7LZF3tg3CLciAjO31LpIKRiz?= =?us-ascii?Q?mSm/5f0SHB/CvHrKsl7EiXVeDoQFkUdxDjuio23wH+VKKlmgRMNcLG2mF8xr?= =?us-ascii?Q?RPBXWtLnbokeMZbrP1CnnoEpsFeZAULOszMKXl4Ypg8gPG/E9Lr6VlTSTeKk?= =?us-ascii?Q?oKGvyEwPb0TfGuyb3zmmYtSA3n7m3zpZEWtvPzHJMY1jSbM4QrsrPO+VfKvo?= =?us-ascii?Q?qAca0A/4D+CJ9jTtBykTEriSKXZFyyrwjpWw3Gf7q/UE6nClSAvsfz1HHOjw?= =?us-ascii?Q?WgBfccUwdZ2bDRpgA6EvwhN5ICDZfne/WXYS8X5qkPO4XHQNCSYLDrWNItcH?= =?us-ascii?Q?ve9Q6BOgI1rmhb1xoG4UjJc+UxdIAAOkD64PY1dnNZrcCVTO1qgTIDx5TPPi?= =?us-ascii?Q?Mw6TLYgHZA4ZEfKCqZWAOEXHqnmvAngoDQD5uFJsG9zZs/swW6R3/F1KLy3H?= =?us-ascii?Q?7DlEm0wn84J62MZQ0g+hAT2uSPKa0duj3pbmeFvPuNS86fW2ICxr+kNC1A2X?= =?us-ascii?Q?JP4j0liaN6nxBnYYlqKL7DOjb5P4CFzJqLWdg8gX0+0DEbADalizospLvt26?= =?us-ascii?Q?xkHbymn5C72x/gDD3tgHoecd17lpm6GUZM1Lr7yPNyjmH7v8KB9afXVWEW2G?= =?us-ascii?Q?yGc/GDCA5Y4bbPau9Oc12ZrQn0GFR4GtMOQ13ZpbgClvbaehl8lL0YvAM9iD?= =?us-ascii?Q?jXT95jNcXhytNdnsXuDqm5KSiQCw5BVUGjIMXnTuvsEHOrIOYvQV8L1sIER3?= =?us-ascii?Q?KnGQXmj8aAOh/JsPVkjt2U3m+zR80KCxiBJuWuw4qsjrJY8hs4repXGv0O9p?= =?us-ascii?Q?QN6k2JSyNGwEEcFe1pvhQuSnfkEUjS6ruiSt3JHGmwpuC6Y1WEj2KYBhm99z?= =?us-ascii?Q?7tlhdXNWjHrvBOTAA0hJgGQiYH+12lkqaemHhoV607+IRET6jQBDNXLlNbS3?= =?us-ascii?Q?FIA9WaAnE1Piac39gi+kpNtWpVJVAp4Qkiy4ISb4Fn/QrJNZK8Ub04fj0lJG?= =?us-ascii?Q?KZY42dhRYGTW5lVW2DEFcSIBhxNYCvKoQVpTL1tN6ZGsHOJysD1N+yUPVI/G?= =?us-ascii?Q?P+iITkSop0PnnfyzAMmvvwQR8YeWFFdoJd3SXXSOyfO3O6E+SxZar1yYlbeC?= =?us-ascii?Q?SzdeOC9ZS9EasdbjiJMLKzNJxj8b8nPF9Sa+s5Wfl2oKMZuMhGp5F3fjc638?= =?us-ascii?Q?qpxLQGDReCPdWWQxVn9lh4roIPHjYHTJdotp5aHAABaiRUj2+HBs3snVxyHv?= =?us-ascii?Q?oeynzqwQHADowykIoppY23AkDgpr?= 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:(13230031)(36860700004)(82310400014)(7416005)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 16:00:13.1306 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: df11f22f-7735-410b-7a31-08dc6477a039 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: MN1PEPF0000F0E4.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5898 Content-Type: text/plain; charset="utf-8" To allow execution at a level other than VMPL0, an SVSM must be present. Allow the SEV-SNP guest to continue booting if an SVSM is detected and the hypervisor supports the SVSM feature as indicated in the GHCB hypervisor features bitmap. Signed-off-by: Tom Lendacky Tested-by: Joerg Roedel --- arch/x86/boot/compressed/sev.c | 12 +++++++++--- arch/x86/include/asm/sev-common.h | 1 + arch/x86/kernel/sev.c | 20 +++++++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 32a1e98ffaa9..fb1e60165cd1 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -610,11 +610,13 @@ void sev_enable(struct boot_params *bp) * features. */ if (sev_status & MSR_AMD64_SEV_SNP_ENABLED) { - if (!(get_hv_features() & GHCB_HV_FT_SNP)) + u64 hv_features =3D get_hv_features(); + + if (!(hv_features & GHCB_HV_FT_SNP)) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); =20 /* - * Enforce running at VMPL0. + * Enforce running at VMPL0 or with an SVSM. * * RMPADJUST modifies RMP permissions of a lesser-privileged (numerically * higher) privilege level. Here, clear the VMPL1 permission mask of the @@ -624,8 +626,12 @@ void sev_enable(struct boot_params *bp) * modifies permission bits, it is still ok to do so currently because L= inux * SNP guests running at VMPL0 only run at VMPL0, so VMPL1 or higher * permission mask changes are a don't-care. + * + * Running at VMPL0 is not required if an SVSM is present and the hyperv= isor + * supports the required SVSM GHCB events. */ - if (rmpadjust((unsigned long)&boot_ghcb_page, RMP_PG_SIZE_4K, 1)) + if (rmpadjust((unsigned long)&boot_ghcb_page, RMP_PG_SIZE_4K, 1) && + !(vmpl && (hv_features & GHCB_HV_FT_SNP_MULTI_VMPL))) sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0); } =20 diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-c= ommon.h index 4cc716660d4b..7a9d09458989 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -118,6 +118,7 @@ enum psc_op { =20 #define GHCB_HV_FT_SNP BIT_ULL(0) #define GHCB_HV_FT_SNP_AP_CREATION BIT_ULL(1) +#define GHCB_HV_FT_SNP_MULTI_VMPL BIT_ULL(5) =20 /* * SNP Page State Change NAE event diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 5e71c94b952c..50754cc45161 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2356,22 +2356,36 @@ static void dump_cpuid_table(void) * sort of indicator, and there's not really any other good place to do it, * so do it here. */ -static int __init report_cpuid_table(void) +static void __init report_cpuid_table(void) { const struct snp_cpuid_table *cpuid_table =3D snp_cpuid_get_table(); =20 if (!cpuid_table->count) - return 0; + return; =20 pr_info("Using SNP CPUID table, %d entries present.\n", cpuid_table->count); =20 if (sev_cfg.debug) dump_cpuid_table(); +} + +static void __init report_vmpl_level(void) +{ + if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) + return; + + pr_info("SNP running at VMPL%u.\n", vmpl); +} + +static int __init report_snp_info(void) +{ + report_vmpl_level(); + report_cpuid_table(); =20 return 0; } -arch_initcall(report_cpuid_table); +arch_initcall(report_snp_info); =20 static int __init init_sev_config(char *str) { --=20 2.43.2