From nobody Sun May 19 14:32:51 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 1E119EC5 for ; Fri, 26 Apr 2024 00:42:34 +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=1714092156; cv=fail; b=lCCPqLqzMRRx+8/3agTQfa9HxZYxbZni24XlO2dJUtXYbrWomGEGKLRVYpg10BGcubpOo9EsFqtCOs8S5TPOlbRymuKxVM7laeLrbw7d8hcbpKz5mkBSdpuTmNqsXmDinQpi4PfYaypCon23Ame1sgLU1ivlWKfPir4cCf98Rj8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714092156; c=relaxed/simple; bh=0RetvHtJXLM6lpX2/OSvflcnawVVGie5gKyQK95RI3E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=edzRD2B8wL5wdIYUcifaKA9k1pToEarRSBpdKfqA2a4QLh4a/9ldXjq0Nr6CmKsLCU3kwMAoo8OjnvPijSwyelMKj1sfAaCmsQDMfrujSl24CZBCgJjVncwNRP75ytrbKuBSwd2YJ/26DtnpnSshfhP9dcMz3MU79yZkz9G71rs= 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=4qFFnc89; 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="4qFFnc89" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UF3VrbC649OcPjtEw+QHEUyks157kl+p+xbLzBI0/aNKqdViEk7yUJAR+vHfdWKk+DxN/vJ5OcgfC6hsF0GTK+4Ce1w9pnixdNC0RXczdjYCAcsBDnN8ocLFEJxk3m12HtvgEEHsXaU+ozNHQKuU9GfkjEV+Ktc9NXXUBRo7h0u5yTkmuk/Nvzm+Sl01PQRgHaTfFgr6dwiudrcS6yZANX5YO9WfOgoLOIDpfi52CaLhMNqm02yvbD8Kpeh5cYfkKc1bzb6e/ggW5dS5gcpeU+lNHToLxkN35je24zrrnvdvQboloLZ2SfdBBaN34vpMV8ahnF1BfnD9bRgHv+rH0g== 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=b2eTkdvJBhnd9MXbddikR6LxOiTu84iJjzumusFQfxc=; b=PBGh33k3zZQd+G9/gWT330f6CownZQ3csl2gELpej68t+LXY+YV92EYbQ1LPpBRpgu699o4Y8Fp+G1WWTechNxZDRfvzqn87YexMbdnjcJWTjB5fNNF5fh6yr1/Rw6pzNdktFzU9H4ef1wgGXL8XZELpagxJPtOmUV1UJ2PzjbEbLWWohDRFtH0kOcSJs0doYAVO9ZoDnufnD3l/BuGrF6HA88onfzAn1s3nL/aafBpQ7mG+XypXQEsKbXKn5gFoGaTpXt/C3pa61DAUYC8H5eTwzSF3bpqDKeAjbVNZh02hzXpTm//j6GSnU7y1GHNIKnKvFD+StdRKKtB7XDx59A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linutronix.de 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=b2eTkdvJBhnd9MXbddikR6LxOiTu84iJjzumusFQfxc=; b=4qFFnc8924upEncuNJXDBH+vGAozfgGcWq+eFNfOyZMJ0gi/YuJ3dicyxWPetT9kFUA3j6fknbgkdHozhChDoz7f9VNCnwkuYaGLeACinfIMJCXtQu3M9QDrQL23N4cHayQ8layOcsbChzX5/8DzRBeup2m3p99vTwUq0L9/7hE= Received: from BN8PR04CA0042.namprd04.prod.outlook.com (2603:10b6:408:d4::16) by SJ2PR12MB8875.namprd12.prod.outlook.com (2603:10b6:a03:543::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.24; Fri, 26 Apr 2024 00:42:31 +0000 Received: from BN3PEPF0000B06E.namprd21.prod.outlook.com (2603:10b6:408:d4:cafe::86) by BN8PR04CA0042.outlook.office365.com (2603:10b6:408:d4::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.26 via Frontend Transport; Fri, 26 Apr 2024 00:42:31 +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 BN3PEPF0000B06E.mail.protection.outlook.com (10.167.243.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.0 via Frontend Transport; Fri, 26 Apr 2024 00:42:31 +0000 Received: from ethanolx7e2ehost.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 25 Apr 2024 19:42:22 -0500 From: Ashish Kalra To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , Subject: [PATCH v3 1/2] x86/e820: Expose API to update e820 kexec and firmware tables externally. Date: Fri, 26 Apr 2024 00:41:56 +0000 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: 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: BN3PEPF0000B06E:EE_|SJ2PR12MB8875:EE_ X-MS-Office365-Filtering-Correlation-Id: c2f03805-06e2-4100-8d13-08dc6589c1dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|7416005|82310400014|36860700004; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?GIvK0Y0tD83y6IITKH3SVQNQocqDhSDe0nVycrdjVtRsw2QFloc4A/BgiyNt?= =?us-ascii?Q?/1JbnfQZCFHHXeYCIvoyZPEJNF/qvq+m4M8I/loVXZcWcy+vCCQnKNY3V4Nu?= =?us-ascii?Q?xEWpXrJU4Lty1Yfcg0jAK9h7Sqb//4LOSyzpO9yPtf9FcEu04zRLnTmKUIzv?= =?us-ascii?Q?UFtfQxM6KswG2jwD3jjg/62Kda5Yz/RBx6h7LYhp8BIbKkG/xCVysmcFlNTA?= =?us-ascii?Q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gmNsDe8ByIwdWFx4L?= =?us-ascii?Q?j/SQtTPrpvVJ+jYo8u66nnW++qy0WXc3GhDMPuNmTNuW/5naB48cKh3UpCt3?= =?us-ascii?Q?sBJQf1bdQGQmUoYXmEqUUA05X9K7HWxNOLNQwRAAdMWfIUL46wUMW+qJUJ1R?= =?us-ascii?Q?K677NSxRPZ8uF+SkaCgD0KHU9rYy1VFGGKfPGHL+fnD3P6+/MqVGFf8sTDav?= =?us-ascii?Q?E5BjoR4SuxrnJYIkKZzc5bdI3SObiQAqOoV0cfV+YsMIw72Q3WEwGeDLKnue?= =?us-ascii?Q?095gXpOZw4BDF7InW6tpPUvw0FIH?= 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)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2024 00:42:31.6680 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c2f03805-06e2-4100-8d13-08dc6589c1dc 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: BN3PEPF0000B06E.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8875 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Export a new API helper function e820__range_update_table() to update both e820_table_kexec and e820_table_firmware. Move all current users of e820__range_update_kexec() to use this new helper function. Signed-off-by: Ashish Kalra --- arch/x86/include/asm/e820/api.h | 2 ++ arch/x86/kernel/e820.c | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/ap= i.h index e8f58ddd06d9..eeb44e71aa66 100644 --- a/arch/x86/include/asm/e820/api.h +++ b/arch/x86/include/asm/e820/api.h @@ -18,6 +18,8 @@ extern void e820__range_add (u64 start, u64 size, enum = e820_type type); extern u64 e820__range_update(u64 start, u64 size, enum e820_type old_typ= e, enum e820_type new_type); extern u64 e820__range_remove(u64 start, u64 size, enum e820_type old_typ= e, bool check_type); =20 +extern u64 e820__range_update_table(struct e820_table *t, u64 start, u64 = size, enum e820_type old_type, enum e820_type new_type); + extern void e820__print_table(char *who); extern int e820__update_table(struct e820_table *table); extern void e820__update_table_print(void); diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index 6f1b379e3b38..872e133d2718 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -532,9 +532,9 @@ u64 __init e820__range_update(u64 start, u64 size, enum= e820_type old_type, enum return __e820__range_update(e820_table, start, size, old_type, new_type); } =20 -static u64 __init e820__range_update_kexec(u64 start, u64 size, enum e820_= type old_type, enum e820_type new_type) +u64 __init e820__range_update_table(struct e820_table *t, u64 start, u64 s= ize, enum e820_type old_type, enum e820_type new_type) { - return __e820__range_update(e820_table_kexec, start, size, old_type, new_= type); + return __e820__range_update(t, start, size, old_type, new_type); } =20 /* Remove a range of memory from the E820 table: */ @@ -806,7 +806,7 @@ u64 __init e820__memblock_alloc_reserved(u64 size, u64 = align) =20 addr =3D memblock_phys_alloc(size, align); if (addr) { - e820__range_update_kexec(addr, size, E820_TYPE_RAM, E820_TYPE_RESERVED); + e820__range_update_table(e820_table_kexec, addr, size, E820_TYPE_RAM, E8= 20_TYPE_RESERVED); pr_info("update e820_table_kexec for e820__memblock_alloc_reserved()\n"); e820__update_table_kexec(); } --=20 2.34.1 From nobody Sun May 19 14:32:51 2024 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2042.outbound.protection.outlook.com [40.107.93.42]) (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 0012D1849 for ; Fri, 26 Apr 2024 00:43:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714092221; cv=fail; b=RxCGyXoUdTs5ZRHsGNGqwTIJf+jxrjZkTXRGKaJyP73F5T1ZxjP9Mb/I/NU2RNaHv0PjzE6Tns4OrstBGcG7MK/ipTMwFgnWQ3ygjVtRRGDx3TkAZvv/hsbMu9GC/IZNyiHCrg48aa+aCwGU9RGlemFVTgcLAQUrTq5yaRFaCkg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714092221; c=relaxed/simple; bh=i4EFzn/xLRHAfn4ezunLiSUtaFRmm4iF/9Pmf8mA3fc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QcRhGX3DIgYISK1rt3ZsHan2CEUvSh4wxSqlTpjpkpaYZ6t+vIL1xakZ3t+avkOFWBy3c+orQzUKu4iiH4vO0lq8KtMNMOWyyMYkD3p8gPyl9A/bfy6oRIKPbc4xVq5i1on9DiUTHGaXUjyfcxbadEuZoFiQSCCx2dqRFXusFQs= 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=ibITmCSF; arc=fail smtp.client-ip=40.107.93.42 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="ibITmCSF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hp5fqPdJWSfUIqU6+u3B1CPCGjOwZjJD81M1mk7jSwiY5t0g9GlE7ViOwp2LECpPg8/HKEVEu5gjQivy1lF+Yhbyouxio67oiHGPH5YnuyXSbGHeKnO6IchTvM8VbtVekk+dUq9hBGQOuy1gL5KT62nUvGGagv6C5KaYYth4E5L9Mr7oaipA15uFdVeTvsdvkfL9CYHs10+um9SNApciuS1+v2wRMpSybRByrn3vMmom4ofKCwGH7jQawlXVF7xyu9WfXJUdLB6Zqm0fMwu2cL7iKXUfr9hQMMBYznyC70zCKMOEvGlVEkgCEfsQ+WiIQANZgo4y/dAghF+RNAwlXQ== 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=USJ1ki66vZ9TpK4RSxeLHCiQ7qg0of77UYFjZwKWt4c=; b=XmM406psX5kQNAvyDzMef09wiO1qPqs1EQj6qWRFP7usaiEGqRzsgSEICH3ImID/uzjr+/l20Tv+95wbdd+uKLW0LF1vln9cOMKuNfE2bXK9acqiuhSiJKJ+hmWwAuZb0MVlx9C2PTp3hdq+flDELWDwFGL6nJGyAJbmbAqj7GxiJC4MBivuXj+sYJXHwWSC/B4d5L8SVQhHHQTk9rhDvUik3xLIgbxiodz44YV+gRF802vm62+tg+x6HdOdEsbMV+KzxS8KkA4lfTqxOcHcVTdtrH1Hn9QixBY2Bb4wu54KzJ7XadP0dw8w8laVh8LnIteqTWcGSY2UJ5JQpJyjbg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linutronix.de 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=USJ1ki66vZ9TpK4RSxeLHCiQ7qg0of77UYFjZwKWt4c=; b=ibITmCSF1oKlc4/F0uVw3e2/OzIPznhZMqOaWIwcZ8i7U52hRbAm9vT+dlKPpWyAlSfrQhsNOQCrwY9BCyQgm5LYkzeIPwwOxkFuwGDP+BrU1a7o7GMkQODE6A+nkz4v1BqBx/oTT4lm0+9ySbIjn2B/NHeJpQn21AsNr6tgq2w= Received: from BY5PR04CA0003.namprd04.prod.outlook.com (2603:10b6:a03:1d0::13) by PH0PR12MB7983.namprd12.prod.outlook.com (2603:10b6:510:28e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.46; Fri, 26 Apr 2024 00:43:34 +0000 Received: from SJ5PEPF000001CD.namprd05.prod.outlook.com (2603:10b6:a03:1d0:cafe::db) by BY5PR04CA0003.outlook.office365.com (2603:10b6:a03:1d0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.26 via Frontend Transport; Fri, 26 Apr 2024 00:43:34 +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 SJ5PEPF000001CD.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; Fri, 26 Apr 2024 00:43:34 +0000 Received: from ethanolx7e2ehost.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 25 Apr 2024 19:43:32 -0500 From: Ashish Kalra To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , Subject: [PATCH v3 2/2] x86/sev: Add callback to apply RMP table fixups for kexec Date: Fri, 26 Apr 2024 00:43:18 +0000 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: 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: SJ5PEPF000001CD:EE_|PH0PR12MB7983:EE_ X-MS-Office365-Filtering-Correlation-Id: ef97083d-794d-4c5b-eb8c-08dc6589e726 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?n7CdzFclEZw6WJo+EVa1t3r1uwBFn057izOvrsaFRx/2zFbd+e82qLQuppgr?= =?us-ascii?Q?eg+fuiq6frynPzMjUK9eiO+xsVyEIsa8HAmqhfJB6EwqZdt8KYS+mBzH5bLf?= =?us-ascii?Q?jcvhQraswSCM6wtaNr/quZzNg0WZ5EQrlg6HNjXtH6PgLQJRvMIFRO4fy77O?= =?us-ascii?Q?eIfbMUlJ2bR7n4SXshWSWhsfwnVtuuSUkA01Ag6Snd34k4pY3FwAUAkciMT0?= =?us-ascii?Q?bN6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i7H5Kn8N7x0lyc?= =?us-ascii?Q?yMgDngMgVwN1Px1e5TkydJS/73KiORUEmoKFwYreRntcD63Nns5EbVMLcYJO?= =?us-ascii?Q?vkT7XHEMoYTBsoofV1oTIK1PJLENfPHf7iTJApBZRj+fx4MAwkJLsD/P83eM?= =?us-ascii?Q?U4gbQj+CL6EW22mRBY9ANdYkBBqQaJS83nHyoEHAOH6IUMf4zW21aHufacXG?= =?us-ascii?Q?uLNx344xBpzQPU61nmXJuPGUf48AadDmT1RIbOiGPAEkwLJX0VniFUqXnj8U?= =?us-ascii?Q?i2jIZU4knd26lf0R6Pyq71BU4iiJ?= 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)(376005)(82310400014)(1800799015)(7416005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2024 00:43:34.1530 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ef97083d-794d-4c5b-eb8c-08dc6589e726 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: SJ5PEPF000001CD.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7983 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Handle cases where the RMP table placement in the BIOS is not 2M aligned and then the kexec kernel could try to allocate from within that chunk and that causes a fatal RMP fault. The kexec failure is illustrated below from the kernel logs: [ 0.000000] SEV-SNP: RMP table physical range [0x0000007ffe800000 - 0x00= 0000807f0fffff] [ 0.000000] BIOS-provided physical RAM map: [ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000008efff] usable [ 0.000000] BIOS-e820: [mem 0x000000000008f000-0x000000000008ffff] ACPI = NVS [ 0.000000] BIOS-e820: [mem 0x0000000000090000-0x000000000009ffff] usable [ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000005a14afff] usable [ 0.000000] BIOS-e820: [mem 0x000000005a14b000-0x000000005a34afff] reser= ved [ 0.000000] BIOS-e820: [mem 0x000000005a34b000-0x0000000067acefff] usable [ 0.000000] BIOS-e820: [mem 0x0000000067acf000-0x000000006dfcefff] reser= ved [ 0.000000] BIOS-e820: [mem 0x000000006dfcf000-0x000000006edfefff] ACPI = NVS [ 0.000000] BIOS-e820: [mem 0x000000006edff000-0x000000006effefff] ACPI = data [ 0.000000] BIOS-e820: [mem 0x000000006efff000-0x000000006effffff] usable [ 0.000000] BIOS-e820: [mem 0x000000006f000000-0x000000006f00afff] ACPI = NVS [ 0.000000] BIOS-e820: [mem 0x000000006f00b000-0x000000006fffffff] usable [ 0.000000] BIOS-e820: [mem 0x0000000070000000-0x000000008fffffff] reser= ved [ 0.000000] BIOS-e820: [mem 0x00000000aa000000-0x00000000aaffffff] reser= ved [ 0.000000] BIOS-e820: [mem 0x00000000c5000000-0x00000000c5ffffff] reser= ved [ 0.000000] BIOS-e820: [mem 0x00000000e0000000-0x00000000e0ffffff] reser= ved [ 0.000000] BIOS-e820: [mem 0x00000000fd000000-0x00000000ffffffff] reser= ved [ 0.000000] BIOS-e820: [mem 0x0000000100000000-0x000000407fcfffff] usable [ 0.000000] BIOS-e820: [mem 0x000000407fd00000-0x000000407fffffff] reser= ved [ 0.000000] BIOS-e820: [mem 0x0000004080000000-0x0000007ffe7fffff] usable [ 0.000000] BIOS-e820: [mem 0x0000007ffe800000-0x000000807f0fffff] reser= ved [ 0.000000] BIOS-e820: [mem 0x000000807f100000-0x000000807f1fefff] usable As seen here in the e820 memory map, the end range of RMP table is not alig= ned to 2MB and not reserved and usable as RAM. Subsequently, kexec -s (KEXEC_FILE_LOAD syscall) loads it's purgatory code = and boot_param, command line and other setup data into this RAM region as seen = in the kexec logs below, which leads to fatal RMP fault during kexec boot. [ 173.113085] Loaded purgatory at 0x807f1fa000 [ 173.113099] Loaded boot_param, command line and misc at 0x807f1f8000 buf= sz=3D0x1350 memsz=3D0x2000 [ 173.113107] Loaded 64bit kernel at 0x7ffae00000 bufsz=3D0xd06200 memsz= =3D0x3894000 [ 173.113291] Loaded initrd at 0x7ff6c89000 bufsz=3D0x4176014 memsz=3D0x41= 76014 [ 173.113296] E820 memmap: [ 173.113298] 0000000000000000-000000000008efff (1) [ 173.113300] 000000000008f000-000000000008ffff (4) [ 173.113302] 0000000000090000-000000000009ffff (1) [ 173.113303] 0000000000100000-000000005a14afff (1) [ 173.113305] 000000005a14b000-000000005a34afff (2) [ 173.113306] 000000005a34b000-0000000067acefff (1) [ 173.113308] 0000000067acf000-000000006dfcefff (2) [ 173.113309] 000000006dfcf000-000000006edfefff (4) [ 173.113311] 000000006edff000-000000006effefff (3) [ 173.113312] 000000006efff000-000000006effffff (1) [ 173.113314] 000000006f000000-000000006f00afff (4) [ 173.113315] 000000006f00b000-000000006fffffff (1) [ 173.113317] 0000000070000000-000000008fffffff (2) [ 173.113318] 00000000aa000000-00000000aaffffff (2) [ 173.113319] 00000000c5000000-00000000c5ffffff (2) [ 173.113321] 00000000e0000000-00000000e0ffffff (2) [ 173.113322] 00000000fd000000-00000000ffffffff (2) [ 173.113324] 0000000100000000-000000407fcfffff (1) [ 173.113325] 000000407fd00000-000000407fffffff (2) [ 173.113327] 0000004080000000-0000007ffe7fffff (1) [ 173.113328] 0000007ffe800000-000000807f0fffff (2) [ 173.113330] 000000807f100000-000000807f1fefff (1) [ 173.113331] 000000807f1ff000-000000807fffffff (2) [ 173.690528] nr_segments =3D 4 [ 173.690533] segment[0]: buf=3D0x00000000e626d1a2 bufsz=3D0x4000 mem=3D0x= 807f1fa000 memsz=3D0x5000 [ 173.690546] segment[1]: buf=3D0x0000000029c67bd6 bufsz=3D0x1350 mem=3D0x= 807f1f8000 memsz=3D0x2000 [ 173.690552] segment[2]: buf=3D0x0000000045c60183 bufsz=3D0xd06200 mem=3D= 0x7ffae00000 memsz=3D0x3894000 [ 173.697994] segment[3]: buf=3D0x000000006e54f08d bufsz=3D0x4176014 mem= =3D0x7ff6c89000 memsz=3D0x4177000 [ 173.708672] kexec_file_load: type:0, start:0x807f1fa150 head:0x1184d0002= flags:0x0 Check if RMP table start & end physical range in e820 tables are not aligned to 2MB and in that case map this range to reserved in all the three e820 tables. Fixes: c3b86e61b756 ("x86/cpufeatures: Enable/unmask SEV-SNP CPU feature") Signed-off-by: Ashish Kalra --- arch/x86/include/asm/sev.h | 2 ++ arch/x86/mm/mem_encrypt.c | 13 ++++++++++++ arch/x86/virt/svm/sev.c | 42 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 7f57382afee4..24300927a476 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -269,6 +269,7 @@ int rmp_make_private(u64 pfn, u64 gpa, enum pg_level le= vel, u32 asid, bool immut int rmp_make_shared(u64 pfn, enum pg_level level); void snp_leak_pages(u64 pfn, unsigned int npages); void kdump_sev_callback(void); +void snp_rmptable_e820_fixup(void); #else static inline bool snp_probe_rmptable_info(void) { return false; } static inline int snp_lookup_rmpentry(u64 pfn, bool *assigned, int *level)= { return -ENODEV; } @@ -282,6 +283,7 @@ static inline int rmp_make_private(u64 pfn, u64 gpa, en= um pg_level level, u32 as static inline int rmp_make_shared(u64 pfn, enum pg_level level) { return -= ENODEV; } static inline void snp_leak_pages(u64 pfn, unsigned int npages) {} static inline void kdump_sev_callback(void) { } +static inline void snp_rmptable_e820_fixup(void) {} #endif =20 #endif diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 6f3b3e028718..d88c942dd311 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -102,6 +102,19 @@ void __init mem_encrypt_setup_arch(void) phys_addr_t total_mem =3D memblock_phys_mem_size(); unsigned long size; =20 + /* + * Invoke callback to do RMP table fixups which needs to be called + * during setup_arch() after the e820 tables have been setup + * in e820__memory_setup() and this function is appropriate to + * invoke the callback to apply any memory encryption platform specific + * quirks. The callback to do RMP table fixups cannot be invoked from + * snp_init() as snp_init() is called from sme_enable() in + * startup_64() which is before setup_arch() and e820 tables + * have still not been setup. + */ + if (cc_platform_has(CC_ATTR_HOST_SEV_SNP)) + snp_rmptable_e820_fixup(); + if (!cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) return; =20 diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index ab0e8448bb6e..1b4b99b26bec 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -163,6 +163,48 @@ bool snp_probe_rmptable_info(void) return true; } =20 +static void __init __snp_e820_tables_fixup(u64 pa) +{ + if (IS_ALIGNED(pa, PMD_SIZE)) + return; + + /* + * Check if RMP table start and end physical range + * in e820_tables are not aligned to 2MB and in that case map + * this range in all the three e820 tables to be reserved. + * The e820_table needs to be updated as it is converted to + * kernel memory resources and used by KEXEC_FILE_LOAD syscall + * to load kexec segments. The e820_table_firmware needs to be + * updated as it is exposed to sysfs and used by KEXEC_LOAD + * syscall to load kexec segments and e820_table_kexec needs + * to be updated as it passed to kexec-ed kernel. + */ + pa =3D ALIGN_DOWN(pa, PMD_SIZE); + if (e820__mapped_any(pa, pa + PMD_SIZE, E820_TYPE_RAM)) { + pr_info("Reserving start/end of RMP table on a 2MB boundary [0x%016llx]\= n", pa); + e820__range_update(pa, PMD_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED); + e820__range_update_table(e820_table_kexec, pa, PMD_SIZE, E820_TYPE_RAM, = E820_TYPE_RESERVED); + e820__range_update_table(e820_table_firmware, pa, PMD_SIZE, E820_TYPE_RA= M, E820_TYPE_RESERVED); + } +} + +/* + * Callback to do any RMP table fixups, needs to be called + * after e820__memory_setup(), after the e820 tables are + * setup/populated and before e820__reserve_resources(), before + * the e820 map has been converted to the standard Linux memory + * resources and e820 map is no longer used and modifying it + * has no effect. Handle cases where the RMP table placement in + * the BIOS is not 2M aligned and then the kexec kernel could + * try to allocate from within that chunk and that causes a + * fatal RMP fault. + */ +void __init snp_rmptable_e820_fixup(void) +{ + __snp_e820_tables_fixup(probed_rmp_base); + __snp_e820_tables_fixup(probed_rmp_base + probed_rmp_size); +} + /* * Do the necessary preparations which are verified by the firmware as * described in the SNP_INIT_EX firmware command description in the SNP --=20 2.34.1