From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.52.14 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796297554; b=FJbQqf7Yxnn7oPdJmKhubhWeoXBOW2gCtRmsppVYJy13kTp7mdhUghxNbIY0umAClTVL a6FOvWktE4O8rPyvB8HLgFqagpyTl2D8zaHctH0tJ2QrWZnAwXCTPnMvsxgOKknJUE4ZL KbHfHxI7Kfr2HgKs81MB2Zl1bEgSFEjf5DCAftc3Dy7fFajpnyyHBpWMk2d+U0eUT8qsi 60pKRq9r8S8VuC3ui5Ro7aigeyf/2pdftzXusSwS8+6ZkW4N/xcHREFfg4ue2Gbn/bGdI PtE5Kl4cmyn08wbVy9gR0Kt5urYVzcYgaZEFSWSBAtAskVQBkp8s3H+1MD2aZZ/icMA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796297554; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:To:CC:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding:Content-Type:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=Fn0MxtUkrP78BGjsRvrORM/5qKcHjoQt4s8RCTWu6OA=; b=L76oYd4aHu78wH6vsDPS7nDu2wpVQBxhADeyDMovsZhKycP+xP8mNmfQT7BgEJJjbmiK lezx4SSEdVJtqei01NMXn6M6+WPC8hvTBctJkS3off8qXMUFhrp4o+5VEjTVIt5sCjZt/ kf+gIRwYSrlQdtk/6CIM4COrWBX5QJBHY62we+mJUBbBfFDUvtD+GSJ+JZJZMaz4k9M+c IT6fFofJ3Ps1TATw1gKDzYMN71cIE6ODtBVlAHqUppbEOnk12ypgQOzIHC2/ukub5UIm4 Rp1Tj1jq/X4gG9Hhmduh9yUVEaKMAzxi1HhkbF6UanvhUCKob+M7aHUqxG9ZmRaNMnA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=fvzqfYbf; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.52.14 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011014.outbound.protection.outlook.com [52.101.52.14]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0204606A322; Thu, 3 Dec 2026 11:32:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F0204606A322 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, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=fvzqfYbf ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cMcRHRbT91jl30EUW5uhHyuCe9phy3dpHCumlRN8vDu++75UZNogZHIFdRSTmg3u9ZIeIE+1i3splsiSCJ1QVAnO/PNhuoQjNAmTF5/pnRMJy2JmjtjY3RnVXt7GYMXpu2mbfmxnIdj5/OuQFsvMdX4wYUCA0bSkDYcyjL4BbFmiRWzDjdh2Srp8JIr2VfTmzDCpdic8pGUyKHFnV17sTmKqGZE8IhBKe6UgOsjuhu95jMIIaeP5ORQ9uB3HT8hzOT6vU6IegJsoQQ6rl1laRavKNsiYO7W6rOUlxns75eG9wzio4mux4fcIm+mjFuXqVgEcYSgHAttMRW1Vopv47A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Fn0MxtUkrP78BGjsRvrORM/5qKcHjoQt4s8RCTWu6OA=; b=sSfiPS/54idUZQD94IvPZPX9hcOwjhlMdVVNO7WrQEVJsnncgWRq27Ma/lwIzAqypIoVfa399k5eLSOmmPeV3udW7cLPjbbo6EfeNHhAU5JDMllhqjfVGluUXQ9y7B3ezP0nT9z8QxWgWp6+kVFTBGOtZpxciJk5Ioa8hWuzV+PPMHQ4DIFS6Hpdnx1eKliXZE6Z9/AZdheI0bIexjlzbI3wFo8kFWjiRNS01x1YzBN1Nbm66qgNy+pPZUTHJnNopcGrPRJ5UkhgxDmLdaCaUFkG1yIMu8w/zHCUxcBWQGRa6JQP1S4swNg+tcKsj0Tz6y4Q10bCcOXNZjiMrMFjFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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=Fn0MxtUkrP78BGjsRvrORM/5qKcHjoQt4s8RCTWu6OA=; b=fvzqfYbfA+FfCh8pCtcNyyMO6hTPxouzoY6hDyt2VY1TUeLqin1c4IV6KqVA/tav4Z27RoGSJraYItCRrA3sgj+3vHBup8pFb5NlVugW5o0x1kJT/j7CJJNnxR1fE1iziXqa2fe69BdGiceObV1rBz0DPz1u0OsU5FxlDzGQS4o= Received: from PH8P221CA0057.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:349::12) by CH3PR12MB9730.namprd12.prod.outlook.com (2603:10b6:610:253::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.11; Thu, 3 Dec 2026 11:32:29 +0000 Received: from CY7PEPF000000E9.namprd04.prod.outlook.com (2603:10b6:510:349:cafe::7b) by PH8P221CA0057.outlook.office365.com (2603:10b6:510:349::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.12 via Frontend Transport; Thu, 3 Dec 2026 11:32:29 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; 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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CY7PEPF000000E9.mail.protection.outlook.com (10.167.247.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.709.6 via Frontend Transport; Thu, 3 Dec 2026 11:32:29 +0000 Received: from satlexmb07.amd.com (10.181.42.216) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Thu, 3 Dec 2026 05:32:25 -0600 Received: from pankaj-M75q.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.57 via Frontend Transport; Thu, 3 Dec 2026 05:32:24 -0600 From: Pankaj Gupta To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , , Jonathan Corbet , Shuah Khan , , CC: Arnd Bergmann , Dapeng Mi , Marco Elver , "H . Peter Anvin" , "Tom Lendacky" , Ard Biesheuvel , "Kiryl Shutsemau" , Ilias Apalodimas , , Mike Rapoport , , , , Ethan Nelson-Moore , Karl Mehltretter , Pankaj Gupta , Subject: [PATCH v2] x86/unaccepted_memory: Do not accept ranges that are no longer E820 RAM Date: Thu, 3 Dec 2026 05:32:24 -0600 Message-ID: <20261203113224.250498-1-pankaj.gupta@amd.com> X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY7PEPF000000E9:EE_|CH3PR12MB9730:EE_ X-MS-Office365-Filtering-Correlation-Id: 4b355829-ad20-4e5a-60f5-08df51311cfb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|1800799024|23010399003|36860700016|11063799006|261009223027099003|18002099003|13003099007|10067099003|56012099006|261102123227099003|261028144727099003|261026140227099003|261026121527099003|261022105027099003|261021123027099003|261021121427099003; X-Microsoft-Antispam-Message-Info: TG5YFcz32O6BZpyldNOhokNTt5/KBGjyUhjnz8edK+vGnd3LKQRDhlwXtdnhyzlfGmaX9zHK7oziaH3DGXjCWQBEewAA4MUTWqJxFTJmFA6uz9PuZgyEUehibtYnbCIthiVVJlCL/ToG9PTrN9wn0KQSyLoxoH1FaNDX1tPhoFNsyRFEVGR9YIwptGdi3XnbWK5H+kOz75mBmEKwPEb0OLq1xX4GCDKwBVBz/t6afJOC9b1XNDOchG7BX3yLl9wgpjD6Ymq6fC5B3jMRB443Tyjw2BV1bME6TY0leLg+GVEChrwOoFSPuST+o5jt/5Dmq/kAvu2hpvSCw9IQcH7wKjPSZHJXJSZPvmTwxnGfeWpyV/niYGkA4tFqcwgWJsVthm1art26ZCqUE52m2W+KAodnBKY6artVM7zxk6iOKiuP0jlbenyYlv9BDpr4I/PyQgNAORNEiqGFdccWci99ByCrMeJ6f5g6tbXstQ0rrCaa154DHJBB+1pYaux5IUTCamERywgNXpxJDvfp5sVRbUJjYZrOU7PPgB1ThD2d2HJHMqff9jhApK4ZPq7XqZjjPb2dq8B2wDmLIgzACtBPJeAZOU3LhPAkm7346LCjxDmZa/4UqK0hm6IT+ZfYU044UigFiGgVhZYQX6x6dKmdtQieam2YrbxiryuMuzMl4Pw= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(1800799024)(23010399003)(36860700016)(11063799006)(261009223027099003)(18002099003)(13003099007)(10067099003)(56012099006)(261102123227099003)(261028144727099003)(261026140227099003)(261026121527099003)(261022105027099003)(261021123027099003)(261021121427099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 40bxj1VQ9qu+1UmMXadiv3Q02bmubgH7mduDC4lkf39mDWFqMoEr9HY6miKEpmG7hvlSo6o0olRw0Jd9NWaVFiZrJZVL+Pc5hdBOXqTIq13WZrhh5k1f/lk3qTfn4GTAgRi/vz6m+nmuE0OeVG7lAkrmwiZZLf5+/tQjPzJ2IwYUhQm28Y9NSQ8MryrSXQZG8+8GdttpTV04FZ8rvgLxKXq7LDLjLi+6Bq75Su8GFG2s2oDPLPeSkI5HTfKMCGvanQN9jPEc7iEI/2dKNgAw3Zo8d2ag5JgYaKUnNNCLaAP9Q8Ev0WYKehx3wgVFqbrO5AcFkD/MuRkpFzYwvlRMOiyCBrHNYf5qUCHDGUSvVQ8Nk+MhO865UPytrz33R8SvB0Dr3H3eWK/4cOR3ofsH4VVHxYYgJrjSsyt7nwxJSoE2Veag9ceP7JH/yXKCMFk2 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2026 11:32:29.0741 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b355829-ad20-4e5a-60f5-08df51311cfb 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY7PEPF000000E9.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9730 The EFI stub builds the unaccepted memory bitmap before the kernel parses its command line. Option memmap=$ removes RAM from the E820 map while its bits are still set in the bitmap. The removed range, such as a memmap=...$... hole, is then still treated as unaccepted RAM and accept_memory() tries to accept it. The hole is not mapped, so on SEV-SNP the PVALIDATE faults and the guest crashes early in the boot: BUG: unable to handle page fault for address: ffff8a14bfe00000 RIP: 0010:pvalidate_pages+0xc0/0x250 set_pages_state+0x41a/0x440 snp_accept_memory+0x3e/0x50 accept_memory+0x186/0x260 __free_pages_core+0xd2/0x240 memblock_free_pages+0x1b/0x30 memblock_free_all+0x275/0x2d0 This was seen with memmap=2M$0x1ffe00000, a 2 MiB hole in RAM, on a 19 GiB SNP guest with lazy acceptance. Accept only whole pages of E820 RAM, and clear the bitmap bits only for the units in which memory was accepted. Fixes: 2053bc57f367 ("efi: Add unaccepted memory support") Cc: stable@vger.kernel.org Signed-off-by: Pankaj Gupta --- v1 -> v2: - Clear the bitmap bits only for the accepted memory - Round E820 RAM range to page boundaries v1: https://lore.kernel.org/all/20261102113127.161823-1-pankaj.gupta@amd.com/ arch/x86/include/asm/unaccepted_memory.h | 44 +++++++++++++++++++++++- drivers/firmware/efi/unaccepted_memory.c | 4 +-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/unaccepted_memory.h b/arch/x86/include/asm/unaccepted_memory.h index f5937e9866ac..9e27a9953dd8 100644 --- a/arch/x86/include/asm/unaccepted_memory.h +++ b/arch/x86/include/asm/unaccepted_memory.h @@ -2,10 +2,11 @@ #define _ASM_X86_UNACCEPTED_MEMORY_H #include +#include #include #include -static inline void arch_accept_memory(phys_addr_t start, phys_addr_t end) +static inline void __arch_accept_memory(phys_addr_t start, phys_addr_t end) { /* Platform-specific memory-acceptance call goes here */ if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) { @@ -18,6 +19,47 @@ static inline void arch_accept_memory(phys_addr_t start, phys_addr_t end) } } +static inline bool e820_ram_pages(struct e820_entry *entry, phys_addr_t start, + phys_addr_t end, phys_addr_t *s, phys_addr_t *e) +{ + if (entry->type != E820_TYPE_RAM) + return false; + + *s = PAGE_ALIGN(max_t(phys_addr_t, start, entry->addr)); + *e = PAGE_ALIGN_DOWN(min_t(phys_addr_t, end, entry->addr + entry->size)); + return *s < *e; +} + +static inline void arch_accept_memory(phys_addr_t start, phys_addr_t end) +{ + phys_addr_t s, e; + u32 i; + + for (i = 0; i < e820_table->nr_entries; i++) { + if (e820_ram_pages(&e820_table->entries[i], start, end, &s, &e)) + __arch_accept_memory(s, e); + } +} + +static inline void arch_clear_accepted(unsigned long *bitmap, phys_addr_t base, + unsigned long unit_size, + phys_addr_t start, phys_addr_t end) +{ + phys_addr_t s, e; + u32 i; + + for (i = 0; i < e820_table->nr_entries; i++) { + unsigned long first, last; + + if (!e820_ram_pages(&e820_table->entries[i], start, end, &s, &e)) + continue; + + first = (s - base) / unit_size; + last = DIV_ROUND_UP(e - base, unit_size); + bitmap_clear(bitmap, first, last - first); + } +} + static inline struct efi_unaccepted_memory *efi_get_unaccepted_table(void) { if (efi.unaccepted == EFI_INVALID_TABLE_ADDR) diff --git a/drivers/firmware/efi/unaccepted_memory.c b/drivers/firmware/efi/unaccepted_memory.c index 4a8ec8d6a571..b8a0c0d1d289 100644 --- a/drivers/firmware/efi/unaccepted_memory.c +++ b/drivers/firmware/efi/unaccepted_memory.c @@ -130,7 +130,6 @@ void accept_memory(phys_addr_t start, unsigned long size) for_each_set_bitrange_from(range_start, range_end, unaccepted->bitmap, range.end) { unsigned long phys_start, phys_end; - unsigned long len = range_end - range_start; phys_start = range_start * unit_size + unaccepted->phys_base; phys_end = range_end * unit_size + unaccepted->phys_base; @@ -150,7 +149,8 @@ void accept_memory(phys_addr_t start, unsigned long size) arch_accept_memory(phys_start, phys_end); spin_lock(&unaccepted_memory_lock); - bitmap_clear(unaccepted->bitmap, range_start, len); + arch_clear_accepted(unaccepted->bitmap, unaccepted->phys_base, + unit_size, phys_start, phys_end); } list_del(&range.list); -- 2.34.1