From nobody Sun May 19 19:10:14 2024 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2048.outbound.protection.outlook.com [40.107.212.48]) (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 0B54F82872 for ; Fri, 26 Apr 2024 16:34:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714149247; cv=fail; b=FQgKdUG6+Xkrv7wAr7jRzQhEJEIouoYzWHlS+1tEwBQpVKqNCMofoaUa8WNUNBCmVf5ni7RxSLs5vQaPXs9uFhJeXdDNl5zDlL/7FoLpUBP5T4+aleq+frxMUQt0Osktu7iq4UScT9Wbsd7L2MbceN+vr8DvHpIEEls0QBPRUsA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714149247; c=relaxed/simple; bh=s/Eo1gvEM/a6WqbbHuEtcUxfoFAB+nJzWWl1vbDbuJY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o6jolVWOhPc+oLLAQs9sTGFnpaMjf9SuufZeQEw/Ag6FhS8zb1tfp6Xem4Y76o9PfEPhI1iMz2lvixaaSQcd5rW37Ve0OFu/ZqokCbWEu6gQkn0DPPr7F9Yy24qZ77Bn+ZdqB3IMTN2pO2XkbWL2BZjqiNa5PlP65r0sWoX3hnM= 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=qRP3J2Mf; arc=fail smtp.client-ip=40.107.212.48 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="qRP3J2Mf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=To2lvVV6FlR5CFd82r5daiUROxbRGeQKR9AKwaywC4IFJdxkxKriHYtCgQE3Cr65IRDFpJJNLnT2NPce2tZWJ+Da1WGgK3P1B5RO0Mje6wIMPJfEerhPG7GwISGSCmdtKKDbtpAMxM2VGuxjEu5o8V1fDYotayuLqPgvWodPiLqE6V9evfFBpt/n4oPnoPFoksSWtMv0BQrluo9iqfmsMBC5h4jz9QTOZIAkLhSKy8w8fD+LZuXJlBPsI634stX3nhdgenf4EMS+YYIxajEAV5bforH1wEyc9HbHsy213XYW1lNlCwBsydnXbJ52B4Nbw5o0BKw7Xcg7Xc8H2MyNgg== 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=vtjo89pLoVRqrR4hjIQOXTpukHLXWVSNk6xg6x4S7hM=; b=G9gb1TyD+9faNjJ9O2YAcCtk13+7R1gPsb/KIaqIXlU19OxXQOBbSOok96KH6S5s+X3JLZ0IAI4JqkXNCO9LPuxPr2RPKwF9pBsg2+twrAzHrIdwONbUMLs2snFQSsmcg7CzVCtDvagYlkEpsVU0FcRTaL3mLQI66VuxDE0Zd5GKjduVtEBtrtwRW9qYmlSg8kdfbxMrY6hIrqLOEEIITbULQ39yCTTLF5sTw8AMN7pWnfL4Cvw5BZDy7xcopxkGT0hInbmCFYmctEHCxMKYRsL5+Me6twLAMgQ1Qg58HhYd/4GNMm2uk3t+VqteAgkal2GpzM5rTaZtSo66VBL7Fg== 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=vtjo89pLoVRqrR4hjIQOXTpukHLXWVSNk6xg6x4S7hM=; b=qRP3J2MfTXRkFHSz1xetSAKFrRs5pMitJ2FsxltPspMCJmhUO4M7ZHngjcAZ6LXmZ+GIRsEkeTFL5GPriU8tbhXzMdASg8bABu1uXsgS1IsegnWO1OvYlIO1uQ7qNsibeogNFtc0y+k1WCLA6S8Ox14ch0wxSU1zkm7kYSvaTRA= Received: from BLAPR03CA0098.namprd03.prod.outlook.com (2603:10b6:208:32a::13) by CH2PR12MB4151.namprd12.prod.outlook.com (2603:10b6:610:78::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.31; Fri, 26 Apr 2024 16:34:00 +0000 Received: from BL02EPF00021F6B.namprd02.prod.outlook.com (2603:10b6:208:32a:cafe::18) by BLAPR03CA0098.outlook.office365.com (2603:10b6:208:32a::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22 via Frontend Transport; Fri, 26 Apr 2024 16:34:00 +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 BL02EPF00021F6B.mail.protection.outlook.com (10.167.249.7) 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 16:34:00 +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; Fri, 26 Apr 2024 11:33:59 -0500 From: Ashish Kalra To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v6 1/3] efi/x86: Fix EFI memory map corruption with kexec Date: Fri, 26 Apr 2024 16:33:48 +0000 Message-ID: <6dfe98fb95d7193ba2d692a2b6900a4d5d73db26.1714148366.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: 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: BL02EPF00021F6B:EE_|CH2PR12MB4151:EE_ X-MS-Office365-Filtering-Correlation-Id: 44bcffe2-cfd7-423b-3ba2-08dc660ead79 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400014|7416005|36860700004|376005|1800799015; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?mlqn7wGSMZrnoCdr0ilZ2puRwF4tAASxz0gkSou5z72dJO+zU2LHG6HMtF7U?= =?us-ascii?Q?kKBuBfziSytVkEylGTw45vyvAt/0egGdhDYWpzBwW6E9nlZhvrhCdJRLqKRH?= =?us-ascii?Q?Me9bCyNpcoZTQ4PIwrS3Tr+GPqY7BR6PZQ7SJ+2yNHMdcPW9oquoNP/cMi/h?= =?us-ascii?Q?6n/Ncj0F8SkHCne+QUCrjeXauXloDUuqamlw90bA6zFML04yqO18j+SG8Vw8?= =?us-ascii?Q?EuYWgTptgVmP1oD5QZh5x2FLA8eBVF68jnWhwftJ1UDAj6Isrk2d+K+A5hnA?= =?us-ascii?Q?uxBTcqAa2mO5bKeN24ECGntVbb/G5L9a3iVzey75/YmXPKl6b4YYjuIw6jji?= =?us-ascii?Q?sMr60c8NsLcZ5TMvlGuakGc5OhZwsE72BERm2EF4fjxQ6IZS8GfmGVVjCjOz?= =?us-ascii?Q?v4z7Rv5sxynT7AF065y3lfEcaMp5tNOEGbDChsdfQxMirPc9/Vni95OG12Rc?= =?us-ascii?Q?zdmxmSJAPpLJBqWgxVh4uPzrJ48TgWnyykMX516AombTWA4H2+GyjCAu0rQQ?= =?us-ascii?Q?XenNUn1W0hlNihw4R+b0WmDQkz9RusJcokyp6FbKSSKPAKxMIOsSHaoVROwX?= =?us-ascii?Q?emfY3UKte6JRuawR8bLUnASjjpL3TXFfOuIoK7hjetEQbUERrtyHoA3X/sEc?= =?us-ascii?Q?P/szN+yY4VrDutJx157vSnj+KPE/7tzeTTQxQY9lLgWv7wrEwApSfheXTpwO?= =?us-ascii?Q?G05jWwX/5q62J2dzcTrfx5g/rp700gvMH3cjEOrLiPVEMCURkfHi93MU2vll?= =?us-ascii?Q?Rqhff8el9EkrVM0ZWacblOYlx3gfLGPqaxGkJWK2Sx1cXeOHFA+YmDHEEtGV?= =?us-ascii?Q?f7E2XolOBzD4B4SkP6+giCE+9hR/WoKl0DllXn2iFzlV7j2rCAhHjPPwu8JW?= =?us-ascii?Q?EyRWn695r6IYXFcoOTQJJsbaS+FoeoP4lFxWd/hdu9JwFrIT85MphMYESPc8?= =?us-ascii?Q?F7NpP3lmBuxx4a8mIILFKAci6McNPysu65Z8kks46ZzBk5c2r0Uw7hey/oa1?= =?us-ascii?Q?QY+uakBKGL9q6JOQ0XFVRU2ak38FcMVw38shEjW4m1gGL7FebzytI4pAzsCR?= =?us-ascii?Q?vC+pZ9Ipp6jNKpMjda84ivWQIlpVav9kDB1TdqLYH8GfOeEYDkymb0tJCB3I?= =?us-ascii?Q?8hdgFGzTHPaQEV2Q92GfpSjRtR0VZbyiDBi0otT9wNYLYRiIwC9hLXzzbzYV?= =?us-ascii?Q?PWWbPXnti9Rsgvsc1V9gMitYJAWMTKVEh2OeiySBP7wMeBKXLBN7noxyKjwI?= =?us-ascii?Q?mIAsNerybIBJZ9IaDE98gnFs8qnAoPIR9l66kKYI35LTp3OgCTYOrczjg9+G?= =?us-ascii?Q?I0sp/OjfFUOQq8b18Uwfev8IpdTekxahBC/hKzPIH8k8nF1hEMZOXda8My+w?= =?us-ascii?Q?RUJ1kA9zKKf/XWuBUzEoZBgr7dFq?= 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)(7416005)(36860700004)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2024 16:34:00.4652 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 44bcffe2-cfd7-423b-3ba2-08dc660ead79 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: BL02EPF00021F6B.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4151 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra With SNP guest kexec observe the following efi memmap corruption : [ 0.000000] efi: EFI v2.7 by EDK II [ 0.000000] efi: SMBIOS=3D0x7e33f000 SMBIOS 3.0=3D0x7e33d000 ACPI=3D0x7e= 57e000 ACPI 2.0=3D0x7e57e014 MEMATTR=3D0x7cc3c018 Unaccepted=3D0x7c09e018 [ 0.000000] efi: [Firmware Bug]: Invalid EFI memory map entries: [ 0.000000] efi: mem03: [type=3D269370880|attr=3D0x0e42100e42180e41] ran= ge=3D[0x0486200e41038c18-0x200e898a0eee713ac17] (invalid) [ 0.000000] efi: mem04: [type=3D12336|attr=3D0x0e410686300e4105] range= =3D[0x100e420000000176-0x8c290f26248d200e175] (invalid) [ 0.000000] efi: mem06: [type=3D1124304408|attr=3D0x000030b400000028] ra= nge=3D[0x0e51300e45280e77-0xb44ed2142f460c1e76] (invalid) [ 0.000000] efi: mem08: [type=3D68|attr=3D0x300e540583280e41] range=3D[0= x0000011affff3cd8-0x486200e54b38c0bcd7] (invalid) [ 0.000000] efi: mem10: [type=3D1107529240|attr=3D0x0e42280e41300e41] ra= nge=3D[0x300e41058c280e42-0x38010ae54c5c328ee41] (invalid) [ 0.000000] efi: mem11: [type=3D189335566|attr=3D0x048d200e42038e18] ran= ge=3D[0x0000318c00000048-0xe42029228ce4200047] (invalid) [ 0.000000] efi: mem12: [type=3D239142534|attr=3D0x0000002400000b4b] ran= ge=3D[0x0e41380e0a7d700e-0x80f26238f22bfe500d] (invalid) [ 0.000000] efi: mem14: [type=3D239207055|attr=3D0x0e41300e43380e0a] ran= ge=3D[0x8c280e42048d200e-0xc70b028f2f27cc0a00d] (invalid) [ 0.000000] efi: mem15: [type=3D239210510|attr=3D0x00080e660b47080e] ran= ge=3D[0x0000324c0000001c-0xa78028634ce490001b] (invalid) [ 0.000000] efi: mem16: [type=3D4294848528|attr=3D0x0000329400000014] ra= nge=3D[0x0e410286100e4100-0x80f252036a218f20ff] (invalid) [ 0.000000] efi: mem19: [type=3D2250772033|attr=3D0x42180e42200e4328] ra= nge=3D[0x41280e0ab9020683-0xe0e538c28b39e62682] (invalid) [ 0.000000] efi: mem20: [type=3D16| | | | | | | | | | |WB| = |WC| ] range=3D[0x00000008ffff4438-0xffff44340090333c437] (invalid) [ 0.000000] efi: mem22: [Reserved |attr=3D0x000000c1ffff4420] range= =3D[0xffff442400003398-0x1033a04240003f397] (invalid) [ 0.000000] efi: mem23: [type=3D1141080856|attr=3D0x080e41100e43180e] ra= nge=3D[0x280e66300e4b280e-0x440dc5ee7141f4c080d] (invalid) [ 0.000000] efi: mem25: [Reserved |attr=3D0x0000000affff44a0] range= =3D[0xffff44a400003428-0x1034304a400013427] (invalid) [ 0.000000] efi: mem28: [type=3D16| | | | | | | | | | |WB| = |WC| ] range=3D[0x0000000affff4488-0xffff448400b034bc487] (invalid) [ 0.000000] efi: mem30: [Reserved |attr=3D0x0000000affff4470] range= =3D[0xffff447400003518-0x10352047400013517] (invalid) [ 0.000000] efi: mem33: [type=3D16| | | | | | | | | | |WB| = |WC| ] range=3D[0x0000000affff4458-0xffff445400b035ac457] (invalid) [ 0.000000] efi: mem35: [type=3D269372416|attr=3D0x0e42100e42180e41] ran= ge=3D[0x0486200e44038c18-0x200e8b8a0eee823ac17] (invalid) [ 0.000000] efi: mem37: [type=3D2351435330|attr=3D0x0e42100e42180e42] ra= nge=3D[0x470783380e410686-0x2002b2a041c2141e685] (invalid) [ 0.000000] efi: mem38: [type=3D1093668417|attr=3D0x100e420000000270] ra= nge=3D[0x42100e42180e4220-0xfff366a4e421b78c21f] (invalid) [ 0.000000] efi: mem39: [type=3D76357646|attr=3D0x180e42200e42280e] rang= e=3D[0x0e410686300e4105-0x4130f251a0710ae5104] (invalid) [ 0.000000] efi: mem40: [type=3D940444268|attr=3D0x0e42200e42280e41] ran= ge=3D[0x180e42200e42280e-0x300fc71c300b4f2480d] (invalid) [ 0.000000] efi: mem41: [MMIO |attr=3D0x8c280e42048d200e] range= =3D[0xffff479400003728-0x42138e0c87820292727] (invalid) [ 0.000000] efi: mem42: [type=3D1191674680|attr=3D0x0000004c0000000b] ra= nge=3D[0x300e41380e0a0246-0x470b0f26238f22b8245] (invalid) [ 0.000000] efi: mem43: [type=3D2010|attr=3D0x0301f00e4d078338] range=3D= [0x45038e180e42028f-0xe4556bf118f282528e] (invalid) [ 0.000000] efi: mem44: [type=3D1109921345|attr=3D0x300e44000000006c] ra= nge=3D[0x44080e42100e4218-0xfff39254e42138ac217] (invalid) ... This EFI memap corruption is happening with efi_arch_mem_reserve() invocati= on in case of kexec boot. ( efi_arch_mem_reserve() is invoked with the following call-stack: ) [ 0.310010] efi_arch_mem_reserve+0xb1/0x220 [ 0.311382] efi_mem_reserve+0x36/0x60 [ 0.311973] efi_bgrt_init+0x17d/0x1a0 [ 0.313265] acpi_parse_bgrt+0x12/0x20 [ 0.313858] acpi_table_parse+0x77/0xd0 [ 0.314463] acpi_boot_init+0x362/0x630 [ 0.315069] setup_arch+0xa88/0xf80 [ 0.315629] start_kernel+0x68/0xa90 [ 0.316194] x86_64_start_reservations+0x1c/0x30 [ 0.316921] x86_64_start_kernel+0xbf/0x110 [ 0.317582] common_startup_64+0x13e/0x141 efi_arch_mem_reserve() calls efi_memmap_alloc() to allocate memory for EFI memory map and due to early allocation it uses memblock allocation. Later during boot, efi_enter_virtual_mode() calls kexec_enter_virtual_mode() in case of a kexec-ed kernel boot. This function kexec_enter_virtual_mode() installs the new EFI memory map by calling efi_memmap_init_late() which remaps the efi_memmap physically alloc= ated in efi_arch_mem_reserve(), but this remapping is still using memblock alloc= ation. Subsequently, when memblock is freed later in boot flow, this remapped efi_memmap will have random corruption (similar to a use-after-free scenari= o). The corrupted EFI memory map is then passed to the next kexec-ed kernel which causes a panic when trying to use the corrupted EFI memory map. Fix this EFI memory map corruption by skipping efi_arch_mem_reserve() for k= exec. Additionally, skipping this function for kexec altogther makes sense as for kexec use case need to use the the EFI memmap passed from first kernel via setup_data and avoid any additional EFI memory map additions/updates. Signed-off-by: Ashish Kalra --- arch/x86/platform/efi/quirks.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index f0cc00032751..af7126d9c540 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -258,6 +258,26 @@ void __init efi_arch_mem_reserve(phys_addr_t addr, u64= size) int num_entries; void *new; =20 + /* + * efi_arch_mem_reserve() calls efi_memmap_alloc() to allocate memory for + * EFI memory map and due to early allocation it uses memblock allocation. + * Later during boot, efi_enter_virtual_mode() calls kexec_enter_virtual_= mode() + * in case of a kexec-ed kernel boot. This function kexec_enter_virtual_m= ode() + * installs the new EFI memory map by calling efi_memmap_init_late() which + * remaps the efi_memmap physically allocated here in efi_arch_mem_reserv= e(), + * but this remapping is still using memblock allocation. + * Subsequently, when memblock is freed later in boot flow, this remapped + * efi_memmap will have random corruption (similar to a use-after-free sc= enario). + * The corrupted EFI memory map is then passed to the next kexec-ed kernel + * which causes a panic when trying to use the corrupted EFI memory map. + * Additionally, skipping this function for kexec altogther makes sense + * as for kexec use case need to use the the EFI memmap passed from first + * kernel via setup_data and avoid any additional EFI memory map + * additions/updates. + */ + if (efi_setup) + return; + if (efi_mem_desc_lookup(addr, &md) || md.type !=3D EFI_BOOT_SERVICES_DATA) { pr_err("Failed to lookup EFI memory descriptor for %pa\n", &addr); --=20 2.34.1 From nobody Sun May 19 19:10:14 2024 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2075.outbound.protection.outlook.com [40.107.93.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26FDA2B9AF for ; Fri, 26 Apr 2024 16:34:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714149276; cv=fail; b=P7w+LdZFpUQSxwUnQD6TNYMiPRGfUabhd+z9iMZI9nhQ9RNgeK5+NmBFC4lkR5WczAWIBpZZq28wxC8uPaqE39STLfdNgFakD8al4ro7kRjlcaCwJyo9OfEozeZUc1zMH9psW9UA9Pv1cIaAo1HnDgEOOdojtdWcnajEvAyBJAk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714149276; c=relaxed/simple; bh=oeN3YWhguWxjQNeclQa+IfSOz+Df0i08/eFpNzUjq9o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MOKQXu+5/ArPmwg4LFZ7NFnOOWoWAzR2J+OPMNgFzFF0i5VaphF7nenfE/IORM9TucQjFac+HDB600+Ik0iyPWUtyXDFn4SuGu4lPCALkTspTpRV08Zjk2F05HiLz41pkn6GBAV8eZtAONe4+8kyCRJkydFSLYV8AbGK1NEZuCs= 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=Gs/CBO1j; arc=fail smtp.client-ip=40.107.93.75 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Gs/CBO1j" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gNUhQtxPFUVxUybsZU9OuX2vSw7W+Gs/P2O7Kau4z3FQ0kv+HPHL21WoYIju1Gfke483A3kOm5WZGGLV2IHR/yelmiN7MNDsOzDJdCytl9tTbgOEGfWnp1VDN0Cq59XDnP+LKVCRt57SJH6Pt3YB/GSJrG+hFD2RiuMFmdQEkYeiXoaMILQ0EQiq2Epn3EBnm1aBs17HcTwgqUUCsaqMg0H2ooXIVM4nzwbsRpSnCAA71xsOJjI9ZykqqUmMDuUEJiwMzIjFMCIgwM8syKE4CYYsPLJFA95Roaf5Owp24qfgOXoRWV2KCnuCiAorfEPpHEZTZbI1An5hk4cQwA5dbQ== 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=8In1wj4zpxqXng+/MvpIStRWhMMfirb2tsJpUKGbnWE=; b=lHfylkTxllkTMN1w0dT0slyNXDu186dQy9SFr4741GE2YY5gbe9Ffd8iSh+wO5oMwUT1Q6fpicniqOVNf7y8nI8ybpAZyFIh8HXjeog9JwPi/C9W4ShGddG7mXlFwvoq5onNFFLF6dHMHOP6Y570i4udqJuF0rpHjqWVstIai8lM1cLeocTNDvBpM7AN4ctGwf5GxZf87r4Q+pMMtbNSUDsPiy+QBD3/jvkJFWIRgNEqTnDkXEErzpiI4xfqXdvLz7Jc2T6bCEb31wrmrzJBdgkjASEj3jSckihMWmgFYlmRD0TtevSt4Bq5FaFa14baVpBGEZ50JNZ6SQ9dZLmidQ== 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=8In1wj4zpxqXng+/MvpIStRWhMMfirb2tsJpUKGbnWE=; b=Gs/CBO1jAoOIze3tOeDdwPyPnNT3m4Kr7qYniiaJvm6g1QR8IOZ7+o64Cv9V4TMrlDyCKS0BeEMPjVgXBLcMI1eAvYGrhDnF8EP0vQheMfzTMI5ToRqj1evPWMEp2I/PfsccNzHZ/oCURGeN5fJhdVKnzRLtAS0dUBCWpQAc1QA= Received: from MN2PR01CA0051.prod.exchangelabs.com (2603:10b6:208:23f::20) by SA1PR12MB5660.namprd12.prod.outlook.com (2603:10b6:806:238::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22; Fri, 26 Apr 2024 16:34:32 +0000 Received: from BL02EPF00021F6F.namprd02.prod.outlook.com (2603:10b6:208:23f:cafe::1a) by MN2PR01CA0051.outlook.office365.com (2603:10b6:208:23f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.29 via Frontend Transport; Fri, 26 Apr 2024 16:34:32 +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 BL02EPF00021F6F.mail.protection.outlook.com (10.167.249.11) 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 16:34: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; Fri, 26 Apr 2024 11:34:30 -0500 From: Ashish Kalra To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v6 2/3] x86/boot/compressed: Skip Video Memory access in Decompressor for SEV-ES/SNP. Date: Fri, 26 Apr 2024 16:34:20 +0000 Message-ID: <4cefecb927ef13cdd2288760037becc398a16f44.1714148366.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: 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: BL02EPF00021F6F:EE_|SA1PR12MB5660:EE_ X-MS-Office365-Filtering-Correlation-Id: 48843df4-754d-42ef-c08a-08dc660ec03e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|82310400014|7416005|36860700004; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?pbB3b47Rt209F3O1yzx62+gwz7zpaD0a2fN1OPKadp/IMKBF3xUlXRYuzedo?= =?us-ascii?Q?pHh2at2h5HkRZb7/xNq57Ot3YzeEOSkzTPKYntCqhdBTmcrgFoal2aN6Smmx?= =?us-ascii?Q?AXw2eT3wgRB0L6UO07SJy4VfwkmJKCETEWoIa4C+ooDK2FpYiKh8Wuo5Js8D?= =?us-ascii?Q?fLjgFF3/ykn0LaIuxtqCunQKwLBl1T1E3Cq/JT8/nhsQEZneJwfDGjbZbJZB?= =?us-ascii?Q?p9Fsm1f/s67YRgyJJSfg6VX0FtAxnA8y2Po5Row7yAx8DqFruNu60duWYg+r?= =?us-ascii?Q?wvJ06a38DHyq+y1mhF2z+nCho9orUaPsmu3zvt3fNq2BB03YOTiqdqVWvA8f?= =?us-ascii?Q?d0bf92XbpmMuJZPj0ExxoArWiZvhMfUL+8SVaCaijSEQ2fVLa2RZxaeo6eDR?= =?us-ascii?Q?W7vOtRY6Pka2gf743tU8JleenRGcLOdkITHd0sah31zJKt/Coz73CyyAIefS?= =?us-ascii?Q?/1xGi/anSkr1wHQaLn5pOs3auyXjNEtJi7ZOD3YkoE2xUqJ41YZyUAf8uVHU?= =?us-ascii?Q?A419YqNo4FLTrVfBJZi4RQvw+fDzTdcFJOXpO26DFicP1XzycpL+ReGKR14O?= =?us-ascii?Q?kJicwnFD/9svd599QI5wHlPJABD3hPpt+6aHv91s0GpolJ8D6/IS9djuMiVw?= =?us-ascii?Q?BI7OmQTwc3TJEvmDjjlmMiiO6ooSxK9jQYU9lGAZaSas7G7WxhLyGkxdlkxY?= =?us-ascii?Q?hzClHLkIhFJZoyUymgA1s3buoV4TccEJXfKzRWBlRC9Jgi3AIS4xKa8rvGQ8?= =?us-ascii?Q?+YpBPtw3J2mkTTk7F2X6xEP5UjrupHpKEv2k995VhQJTeqfUk0cBSL5eSUU+?= =?us-ascii?Q?2PM0zPcSJpJzoUanx0v4EGTcuqR5Jc3oGH8hIvfr94eov013apPDJu7bEC44?= =?us-ascii?Q?Mk74sHKxmpt+JLAd9cyXRjINcG0cJAxxYGSdApjswyQJlhE9IejznyE/6oTy?= =?us-ascii?Q?72zIey8AvyAFsHXRKJWhDqaowL5GcAgoUYUVI+rsyQ8vbYyCuFwxr8zRrCk3?= =?us-ascii?Q?fTkY2uudsnwf4msYm6Fkmi/oOoKYPOzAEl+v9+iFymlStO2rX3FlyPet2Sze?= =?us-ascii?Q?h/h+RhuCftNbBgBQIwkBUSsuM+L9iJkm9POaMuyoZAaFy6v4VpNN6a/NsHck?= =?us-ascii?Q?XW7qG1nQMxN+PP14vynBI1VMBm2hPV74jIttD4Xbl5Pw2Q0QjCWGbHrz2K4e?= =?us-ascii?Q?dHCCiV1YMEyJgZqtRO7q53qWBY9HF7Yw2VNIYhq8+AEOG4wxrBZKvzA5LgdE?= =?us-ascii?Q?LUv940d1V/mbqFL/ifFrk4RNEh/QoYzvTxpfiB2Z1bI9PcDIF1cQ0763s4GQ?= =?us-ascii?Q?ONPAEDRY7bEaqlXJfr5/56gKnQnx21yWYF7iNbRTzBYTwpLA3N6D61qnU5Kr?= =?us-ascii?Q?eLI/5udAUA2Nfnl3m/zCJffeXB7l?= 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)(82310400014)(7416005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2024 16:34:31.9743 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 48843df4-754d-42ef-c08a-08dc660ec03e 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: BL02EPF00021F6F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB5660 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Accessing guest video memory/RAM during kernel decompressor causes guest termination as boot stage2 #VC handler for SEV-ES/SNP systems does not support MMIO handling. This issue is observed with SEV-ES/SNP guest kexec as kexec -c adds screen_info to the boot parameters passed to the kexec kernel, which causes console output to be dumped to both video and serial. As the decompressor output gets cleared really fast, it is preferable to get the console output only on serial, hence, skip accessing video RAM during decompressor stage to prevent guest termination. Serial console output during decompressor stage works as boot stage2 #VC handler already supports handling port I/O. Suggested-by: Thomas Lendacy Signed-off-by: Ashish Kalra Reviewed-by: Kuppuswamy Sathyanarayanan --- arch/x86/boot/compressed/misc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/mis= c.c index b70e4a21c15f..3b9f96b3dbcc 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -427,8 +427,10 @@ asmlinkage __visible void *extract_kernel(void *rmode,= unsigned char *output) vidport =3D 0x3d4; } =20 - lines =3D boot_params_ptr->screen_info.orig_video_lines; - cols =3D boot_params_ptr->screen_info.orig_video_cols; + if (!(sev_status & MSR_AMD64_SEV_ES_ENABLED)) { + lines =3D boot_params_ptr->screen_info.orig_video_lines; + cols =3D boot_params_ptr->screen_info.orig_video_cols; + } =20 init_default_io_ops(); =20 --=20 2.34.1 From nobody Sun May 19 19:10:14 2024 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2080.outbound.protection.outlook.com [40.107.243.80]) (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 C6CE82230C for ; Fri, 26 Apr 2024 16:35:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714149347; cv=fail; b=CaV4cGjmXzANIsAE2We23pg9PqWJahO+vmA/eQBPyToSP1Vdc2j4WmwEKDtJ2sGCj1LdFeaSSbfLDheG2S0XfD79jFOchS71ZgAJohU/pXJDwQHzh47pc7p/ckSL9ad14n5O16LJv6wdZFZVhggOaUdkC1XvE4yWhXXhYNvoCbY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714149347; c=relaxed/simple; bh=HjbyeEWVR+iLQgayYETXWRgclt/8PmcXMc2I08W0xCM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Faw25+34f15NfC4lGP4FuigaCk2q0DSYA1wDTWWVlh/B2bVhn0rWf2mtt0ETfDFGq5tDDqe+QNib2GA6EJs5dZB9AOd/Mlji8TtMbDSbP5S0n5zVTsU56yemLhRvvnOooVxNWJ5RWJkeVL+JF1n5wufKLeMVCvEUNHDwtpZXhBg= 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=G6myba9X; arc=fail smtp.client-ip=40.107.243.80 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="G6myba9X" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H1Wro/x8ezP1EG9QUJAetbHj6Tmi502CNIEkYD3UsNy5qPJSa3V1p0C9IL5FZVS+XS49G+9qY4pn6Wv2bcnuMy7PZ1BABjgFFCOK6KADFsOyh7bpEe2MCoduepmTdTsX0KNus4VJjZJRPb/p0t1bO+qJWfn48h6db57xJY7AA0aaYJLeAgvLWTdd5EyoZeHispIfv3cdw9mHr5HIyar3FYD/YjVhn9jI0uRVnOPIdjefl08mkJ0BrLOtCZXSHgHXqqNeGDHGBfYUTfR9d8dsD3aKSgHaBC8AUum1TMKzaDyknEAz0sjALNWBUVqzAjiN6ncJzsgwypqKfdS0iNCgkQ== 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=MGjacbaSG0E4Xrc1HaZgxSpSaWSCfPXy//14N/+XCX8=; b=la9rU3uCP1BdFCdNuKSCNK+W2zJP0wUHNdG5pLl5gIGkWQD+4pMCdDbPaIUz3Va0/LGd8Q+SYT5oua9txhN4kgwjh9N1Sky91TPdbTp2zOJQyFgjaZJtEcl/LmF/4pg1qyzpHGZ4z72Kq5wSgJk85ZyiXbZJVp5aE4BRlZt+u3E/OesMHodEBQ7oQ97TA7fj+uXbSJjHLhfFCorVJllmLqWA3zfI62rCubhReEBOFMiav17wiwrrQvhLIKABWuSyBODo9Iy16sOADQDyr2e3TnuLblzWYqCF6O38Pdgqa/J4LSCt17fyj5jCWUsusdrpLlDhd2y9zPAQijv5zulKrw== 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=MGjacbaSG0E4Xrc1HaZgxSpSaWSCfPXy//14N/+XCX8=; b=G6myba9XYjR47YJTmSZyUu4UNdt1BShhdWQpVkduJfb7zryDE4lW7w09U5DeMRSW5Q6g5e5jacQKgJaVQLSr1dC87rLQtzVO3jkm1A0MzggBR7wtvJyYSKYFKF2zsRUR34oTwgr8/+kVqef6jyzDfHVR9yGoiq+DMlgQF++AfaA= Received: from BLAPR03CA0148.namprd03.prod.outlook.com (2603:10b6:208:32e::33) by MW4PR12MB6952.namprd12.prod.outlook.com (2603:10b6:303:207::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22; Fri, 26 Apr 2024 16:35:42 +0000 Received: from BL02EPF00021F6D.namprd02.prod.outlook.com (2603:10b6:208:32e:cafe::bf) by BLAPR03CA0148.outlook.office365.com (2603:10b6:208:32e::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.25 via Frontend Transport; Fri, 26 Apr 2024 16:35:41 +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 BL02EPF00021F6D.mail.protection.outlook.com (10.167.249.9) 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 16:35:41 +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; Fri, 26 Apr 2024 11:35:35 -0500 From: Ashish Kalra To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v6 3/3] x86/snp: Convert shared memory back to private on kexec Date: Fri, 26 Apr 2024 16:35:17 +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: BL02EPF00021F6D:EE_|MW4PR12MB6952:EE_ X-MS-Office365-Filtering-Correlation-Id: 23fd2dd6-5f05-4eb1-9c79-08dc660ee9cf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|376005|82310400014|1800799015|36860700004; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?JqZmv55s7cWBXtg8cbYKHStZ4T+usyqYdzDzoM9maLrfoO2AfrCfoOiPqTv2?= =?us-ascii?Q?CpOkIiDl2p/xVV21+ioIN3eWtfbQkBczEgJYp1D0ILY0eWrUvZw2cNN8D+DX?= =?us-ascii?Q?qtyGlcHflmLFDpRU2dOt6PP6fRqdI8W4v6sKFjWSFG8vKaJYNDkk99yvjIMC?= =?us-ascii?Q?t/gp182cqQHJ8myWudoMOpJR84nCaxAYBhxUECWtf7k7WCZxXCHMfDaCdSku?= =?us-ascii?Q?9lSrsjYysREY0vd77cmm88d5mVjGQWuOiqW9ram05sHEIkUzlhBnJh2+Swep?= =?us-ascii?Q?SYqbbv6CSNcS/lSQFm/H9yd7syvEPH0B/2N1Xs+az4q8dIACdB3BIvuWT2Xg?= =?us-ascii?Q?GYsS9MGk3m6Z9ETsKVmFDGPxc4n+Do7BbWCF5qZasj9p3FSDMCZMf9JDDTwb?= =?us-ascii?Q?AlibKhLjvGZhPXcS9VMFCyESlsID9SNVtMOWNIo84ab6+G1+YxKoN0jFuzxe?= =?us-ascii?Q?5hXdMaaCXSOzUppXsksFKT54ylgCf2TW9cWXJ/tQF90u1jU0O8RcDcbtIOZs?= =?us-ascii?Q?qVi8KJ3+8ZboL46oC0qMY/9X+HOKw4JxunShWdp6WQZl1RwPDUAxE74mNen7?= =?us-ascii?Q?hObjeSYmHCadPLGyoObxfpk+x/XYSyVuabUK96QXXIegfM9m6BQ43h5HQ8tz?= =?us-ascii?Q?44frAB43JihQ6NQ/WsTLri1u26WuKKgYwYSOFex7IN34pNqUITgJ0JzXKzbO?= =?us-ascii?Q?MOExS5J+Zr3Hbeqst6bvaKcx+jpvCTLV22rQtxclTY1Xrw8Buysu1+jQgwSX?= =?us-ascii?Q?OuPXi8nwRmWP0mGNAwtcrkJ44vXLyShmLoCxEqG6R5vhFgfIGbrmi1Ozvmvn?= =?us-ascii?Q?m0mIxTQY9XkqK1DpxSUX1hivXr4exJd0AjU2ttreCDAsxcYXZzMgfKMMcOMk?= =?us-ascii?Q?fBHTd5kx9/MFHDc7XWqplSkgI9JtWmHpUtS0ieVy4NY/cbOqZ+H361idI/vl?= =?us-ascii?Q?UF+xsLZ46AsTdwdlntTX+MUlBB0TVLdK28mavF+vQcWURr1ihcCLfT2uhR55?= =?us-ascii?Q?xIKoogmUJVmU0WLIWXqdc3ReQdzA78OEXMuq8noQHNdSzJDnPKZNE8wG/w3z?= =?us-ascii?Q?Z4kUdvRSyj8twlPXEzI6jiaYXR+nuovAsQzltoriaMibprFZztTVdDuNhgVf?= =?us-ascii?Q?Ogc7WjP89oCGo3ssoiDVErxjtDVYH/ZJ+bfFuUvl9mgM4nzN1OXrFxxR2zLy?= =?us-ascii?Q?TXDIOX8njobrvspa4iSNCJPmX95JKwSTIq/qpZc8SwfjYxi8eToMSQyzopvQ?= =?us-ascii?Q?RwHByd/D+v65dIzssI7DpQVHB7Oiq7nqhjwQLCadHMAq/BNUKny509gRIByb?= =?us-ascii?Q?TsO29dYYv+BCpvTjraTD4o9yfIe7i1dahBk+CKUfkKqr2bKSzGr8+uW0XxG1?= =?us-ascii?Q?ezTQEZo=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)(7416005)(376005)(82310400014)(1800799015)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2024 16:35:41.6946 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 23fd2dd6-5f05-4eb1-9c79-08dc660ee9cf 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: BL02EPF00021F6D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6952 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra SNP guests allocate shared buffers to perform I/O. It is done by allocating pages normally from the buddy allocator and converting them to shared with set_memory_decrypted(). The second kernel has no idea what memory is converted this way. It only sees E820_TYPE_RAM. Accessing shared memory via private mapping will cause unrecoverable RMP page-faults. On kexec walk direct mapping and convert all shared memory back to private. It makes all RAM private again and second kernel may use it normally. Additionally for SNP guests convert all bss decrypted section pages back to private and switch back ROM regions to shared so that their revalidation does not fail during kexec kernel boot. The conversion occurs in two steps: stopping new conversions and unsharing all memory. In the case of normal kexec, the stopping of conversions takes place while scheduling is still functioning. This allows for waiting until any ongoing conversions are finished. The second step is carried out when all CPUs except one are inactive and interrupts are disabled. This prevents any conflicts with code that may access shared memory. Signed-off-by: Ashish Kalra --- arch/x86/include/asm/sev.h | 4 + arch/x86/kernel/sev.c | 161 ++++++++++++++++++++++++++++++++++ arch/x86/mm/mem_encrypt_amd.c | 3 + 3 files changed, 168 insertions(+) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 7f57382afee4..78d40d08d201 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -229,6 +229,8 @@ 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_kexec_unshare_mem(void); +void snp_kexec_stop_conversion(bool crash); #else static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } @@ -258,6 +260,8 @@ 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_kexec_unshare_mem(void) { } +static inline void snp_kexec_stop_conversion(bool crash) { } #endif =20 #ifdef CONFIG_KVM_AMD_SEV diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 995f94467101..891257fde810 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -42,6 +42,8 @@ #include #include #include +#include +#include =20 #define DR7_RESET_VALUE 0x400 =20 @@ -92,6 +94,9 @@ static struct ghcb *boot_ghcb __section(".data"); /* Bitmap of SEV features supported by the hypervisor */ static u64 sev_hv_features __ro_after_init; =20 +/* Last address to be switched to private during kexec */ +static unsigned long kexec_last_addr_to_make_private; + /* #VC handler runtime per-CPU data */ struct sev_es_runtime_data { struct ghcb ghcb_page; @@ -913,6 +918,162 @@ void snp_accept_memory(phys_addr_t start, phys_addr_t= end) set_pages_state(vaddr, npages, SNP_PAGE_STATE_PRIVATE); } =20 +static bool set_pte_enc(pte_t *kpte, int level, void *va) +{ + pte_t new_pte; + + if (pte_none(*kpte)) + return false; + + /* + * Change the physical page attribute from C=3D0 to C=3D1. Flush the + * caches to ensure that data gets accessed with the correct C-bit. + */ + if (pte_present(*kpte)) + clflush_cache_range(va, page_level_size(level)); + + new_pte =3D __pte(cc_mkenc(pte_val(*kpte))); + set_pte_atomic(kpte, new_pte); + + return true; +} + +static bool make_pte_private(pte_t *pte, unsigned long addr, int pages, in= t level) +{ + struct sev_es_runtime_data *data; + struct ghcb *ghcb; + + data =3D this_cpu_read(runtime_data); + ghcb =3D &data->ghcb_page; + + /* Check for GHCB for being part of a PMD range. */ + if ((unsigned long)ghcb >=3D addr && + (unsigned long)ghcb <=3D (addr + (pages * PAGE_SIZE))) { + /* + * Ensure that the current cpu's GHCB is made private + * at the end of unshared loop so that we continue to use the + * optimized GHCB protocol and not force the switch to + * MSR protocol till the very end. + */ + pr_debug("setting boot_ghcb to NULL for this cpu ghcb\n"); + kexec_last_addr_to_make_private =3D addr; + return true; + } + + if (!set_pte_enc(pte, level, (void *)addr)) + return false; + + snp_set_memory_private(addr, pages); + + return true; +} + +static void unshare_all_memory(void) +{ + unsigned long addr, end; + + /* + * Walk direct mapping and convert all shared memory back to private, + */ + + addr =3D PAGE_OFFSET; + end =3D PAGE_OFFSET + get_max_mapped(); + + while (addr < end) { + unsigned long size; + unsigned int level; + pte_t *pte; + + pte =3D lookup_address(addr, &level); + size =3D page_level_size(level); + + /* + * pte_none() check is required to skip physical memory holes in direct = mapped. + */ + if (pte && pte_decrypted(*pte) && !pte_none(*pte)) { + int pages =3D size / PAGE_SIZE; + + if (!make_pte_private(pte, addr, pages, level)) { + pr_err("Failed to unshare range %#lx-%#lx\n", + addr, addr + size); + } + + } + + addr +=3D size; + } + __flush_tlb_all(); + +} + +static void unshare_all_bss_decrypted_memory(void) +{ + unsigned long vaddr, vaddr_end; + unsigned int level; + unsigned int npages; + pte_t *pte; + + vaddr =3D (unsigned long)__start_bss_decrypted; + vaddr_end =3D (unsigned long)__start_bss_decrypted_unused; + npages =3D (vaddr_end - vaddr) >> PAGE_SHIFT; + for (; vaddr < vaddr_end; vaddr +=3D PAGE_SIZE) { + pte =3D lookup_address(vaddr, &level); + if (!pte || !pte_decrypted(*pte) || pte_none(*pte)) + continue; + + set_pte_enc(pte, level, (void *)vaddr); + } + vaddr =3D (unsigned long)__start_bss_decrypted; + snp_set_memory_private(vaddr, npages); +} + +/* Stop new private<->shared conversions */ +void snp_kexec_stop_conversion(bool crash) +{ + /* + * Crash kernel reaches here with interrupts disabled: can't wait for + * conversions to finish. + * + * If race happened, just report and proceed. + */ + bool wait_for_lock =3D !crash; + + if (!stop_memory_enc_conversion(wait_for_lock)) + pr_warn("Failed to finish shared<->private conversions\n"); +} + +void snp_kexec_unshare_mem(void) +{ + if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) + return; + + unshare_all_memory(); + + unshare_all_bss_decrypted_memory(); + + if (kexec_last_addr_to_make_private) { + unsigned long size; + unsigned int level; + pte_t *pte; + + /* + * Switch to using the MSR protocol to change this cpu's + * GHCB to private. + * All the per-cpu GHCBs have been switched back to private, + * so can't do any more GHCB calls to the hypervisor beyond + * this point till the kexec kernel starts running. + */ + boot_ghcb =3D NULL; + sev_cfg.ghcbs_initialized =3D false; + + pr_debug("boot ghcb 0x%lx\n", kexec_last_addr_to_make_private); + pte =3D lookup_address(kexec_last_addr_to_make_private, &level); + size =3D page_level_size(level); + set_pte_enc(pte, level, (void *)kexec_last_addr_to_make_private); + snp_set_memory_private(kexec_last_addr_to_make_private, (size / PAGE_SIZ= E)); + } +} + static int snp_set_vmsa(void *va, bool vmsa) { u64 attrs; diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index e7b67519ddb5..49c40c2ed809 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -468,6 +468,9 @@ void __init sme_early_init(void) x86_platform.guest.enc_tlb_flush_required =3D amd_enc_tlb_flush_requir= ed; x86_platform.guest.enc_cache_flush_required =3D amd_enc_cache_flush_requ= ired; =20 + x86_platform.guest.enc_kexec_stop_conversion =3D snp_kexec_stop_conversio= n; + x86_platform.guest.enc_kexec_unshare_mem =3D snp_kexec_unshare_mem; + /* * AMD-SEV-ES intercepts the RDMSR to read the X2APIC ID in the * parallel bringup low level code. That raises #VC which cannot be --=20 2.34.1