From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9A39606A322 for ; Fri, 4 Dec 2026 11:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Eif0jse/ Received: by kanga.kvack.org (Postfix) id 1EB866B05B5; Fri, 4 Dec 2026 06:35:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C2AC6B05B6; Fri, 4 Dec 2026 06:35:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FFB06B05B8; Fri, 4 Dec 2026 06:35:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9FAB46B05B5 for ; Fri, 4 Dec 2026 06:35:15 -0500 (EST) Received: from smtpin30.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 34EF716034B for ; Fri, 4 Dec 2026 11:35:15 +0000 (UTC) X-FDA: 85506094590.30.8E239AD Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf09.hostedemail.com (Postfix) with ESMTP id 7534E140005 for ; Fri, 4 Dec 2026 11:35:13 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b="Eif0jse/"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796384113; b=T0MQhau1Q2NqokMQ2TPKLyN5X9rYlaWw/6W5dDNAzP4c6EHetTY4o29wHbMj9mML+0YBbT hQ0co9PVYLxwdVufbklWxzArVKTdK5u2cM2WNcb/VxewSJ3pLkP/HIlHeSI7ETP7hDOB/p r3LKDNzXksRuv51HUc2ycZSv41IuQjM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796384113; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Axn4WiWdpJXlReLVfgZO+Ek4h1Yk9eKQzzDjmNTHWWU=; b=zEMzkibupyaoOqQ/VY+iZn+1ElEuXlup4JqfZe1FGvRw8l0UEuH33ACCXlsZtzaih68pde pZUjakPVqiVC8GGFG4yY8LwQaDTpuSy3WjQjII/jBQroqPE5HwOduhxuJoZFtwPTFlgJ3E 2Jo6lYA/hWJXx0c8/eOst3qKaZRqa7I= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b="Eif0jse/"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id AB99F40561; Fri, 4 Dec 2026 11:35:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C5AC1F000C2; Fri, 4 Dec 2026 11:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796384112; bh=Axn4WiWdpJXlReLVfgZO+Ek4h1Yk9eKQzzDjmNTHWWU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Eif0jse/+2vXT577b57xLp4DY6voVB6op9LNhf570lbXDMsH/MkAJVWqihA+swgNM gF0soni07MkjRyd7MmizT2VQNgvlzBPTX4spfwUWCsahfbIiHDrtjbWFXkoDlx0XCv JCJHFfUyb5HaTs9H3t3688D48Nqu6EaLrzi+uMGELc04SedlGAWxkyuY4BGHSY2eO4 a09GFOiSOs9WvovMAW8A7xfYdmpQ+RlkesWnBEBzuy32OmaEFgukTL+NQ4YAiboMen anvQ/AG1deYBD7w3cYJ1iPJEzbJ6hjWa1fMTfKH4ofw01UMaZb28Qm3/cDmpClJ2LF cSr2ZauzwGqTA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] x86/unaccepted_memory: Do not accept ranges that are no longer E820 RAM Reply-To: sashiko-reviews@lists.linux.dev To: "Pankaj Gupta" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org, "Jonathan Corbet" , "Shuah Khan" , rdunlap@infradead.org Cc: "Arnd Bergmann" , "Dapeng Mi" , "Marco Elver" , "H . Peter Anvin" , "Tom Lendacky" , "Ard Biesheuvel" , "Kiryl Shutsemau" , "Ilias Apalodimas" , "Mike Rapoport" , linux-mm@kvack.org, linux-efi@vger.kernel.org, Pankaj.gupta.linux@gmail.com, "Ethan Nelson-Moore" , "Karl Mehltretter" In-Reply-To: <20261203113224.250498-1-pankaj.gupta@amd.com> References: <20261203113224.250498-1-pankaj.gupta@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 11:35:11 +0000 X-Stat-Signature: xoiwnyxe53nqdqzirhmux3ibk466kf6u X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 7534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Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] x86/unaccepted_memory: arch_clear_accepted() clears partial units in bitmap - [High] x86/unaccepted_memory: e820_table UAF race with free_initmem() - [Medium] efi/unaccepted: set hole bits break range_contains_unaccepted_memory() - [Medium] x86/unaccepted_memory: arch_accept_memory() skips hot-added non-E820-RAM - [Medium] x86/unaccepted_memory: 64-bit PAGE_ALIGN() wraparound in e820_ram_pages() - [Medium] efi: unaddressed maintainer objection to E820 filtering in accept_memory() -- commit 9fd60bf8e1c09dbddfc18def62b612b4e1e680e2 Author: Pankaj Gupta x86/unaccepted_memory: Do not accept ranges that are no longer E820 RAM This commit filters x86 memory acceptance in arch_accept_memory() to whole pages covered by E820_TYPE_RAM entries and adds arch_clear_accepted() so accept_memory() only clears bitmap bits for those E820 RAM subranges. > diff --git a/arch/x86/include/asm/unaccepted_memory.h b/arch/x86/include/= asm/unaccepted_memory.h > index f5937e9866ac1..9e27a9953dd83 100644 > --- a/arch/x86/include/asm/unaccepted_memory.h > +++ b/arch/x86/include/asm/unaccepted_memory.h [ ... ] > @@ -18,6 +19,47 @@ static inline void arch_accept_memory(phys_addr_t star= t, phys_addr_t end) > } > } > =20 > +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 !=3D E820_TYPE_RAM) > + return false; > + > + *s =3D PAGE_ALIGN(max_t(phys_addr_t, start, entry->addr)); > + *e =3D PAGE_ALIGN_DOWN(min_t(phys_addr_t, end, entry->addr + entry->siz= e)); > + return *s < *e; > +} [Severity: Medium] Can PAGE_ALIGN() wrap *s to zero for a non-overlapping E820_TYPE_RAM entry near U64_MAX? An entry such as memmap=3D0x7ff@0xfffffffffffff800 passes e820__update_tabl= e() because addr + size does not overflow. Calling PAGE_ALIGN() before checking overlap wraps *s to 0 while *e equals end, so *s < *e returns true. arch_accept_memory() then passes [0, end) to __arch_accept_memory(), panick= ing on TDX or faulting on SEV-SNP, and arch_clear_accepted() underflows (s - ba= se) and (last - first) when base is non-zero, writing out of bounds in bitmap_clear(). Checking overlap before calling PAGE_ALIGN() avoids this. > + > +static inline void arch_accept_memory(phys_addr_t start, phys_addr_t end) > +{ > + phys_addr_t s, e; > + u32 i; > + > + for (i =3D 0; i < e820_table->nr_entries; i++) { > + if (e820_ram_pages(&e820_table->entries[i], start, end, &s, &e)) > + __arch_accept_memory(s, e); > + } > +} [Severity: High] Can arch_accept_memory() and arch_clear_accepted() race with free_initmem() freeing e820_table_init? During SMP boot, lazy memory acceptance can run accept_memory() on one CPU while kernel_init() runs free_initmem() on another: CPU0 CPU1 kernel_init() accept_memory() free_initmem() arch_accept_memory() /* reads e820_table_init */ __arch_accept_memory(...) e820__reallocate_tables() e820_table =3D kmemdup(...) free_kernel_image_pages(...) /* poisons/unmaps initmem */ e820_table_init->nr_entries <-- use-after-free e820__reallocate_tables() swaps e820_table with a plain store and no grace period before free_kernel_image_pages() poisons or unmaps e820_table_init. On AMD systems with X86_FEATURE_INVLPGB, flush_tlb_all() broadcasts hardware invalidations rather than IPIs, so it does not wait for remote IRQ-disabled CPUs executing arch_accept_memory(). A concurrent reader can then observe POISON_FREE_INITMEM (0xcccccccc) as nr_entries or fault on an unmapped init page with interrupts disabled. [Severity: Medium] Does filtering on e820_table cause arch_accept_memory() to silently skip hot-added memory? e820_table is a static boot-time snapshot that arch_add_memory() never updates. If an EFI_UNACCEPTED_MEMORY range is reclassified to E820_TYPE_SOFT_RESERVED via memmap=3D and later hot-added by dax/kmem (dax_kmem_do_hotplug() -> arch_add_memory() -> online_pages() -> __free_pages_core() -> accept_memory()), e820_ram_pages() rejects it. __free_pages_core() and __accept_page() then expose the unaccepted pages to the buddy allocator via __free_pages_ok(), causing an unrecoverable EPT violation on TDX or RMP fault on SEV-SNP on first access. Checking direct-= map coverage (such as pfn_mapped[] / pfn_range_is_mapped()) instead of boot-time e820_table would cover hot-added memory while still avoiding unmapped holes. > + > +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 =3D 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 =3D (s - base) / unit_size; > + last =3D DIV_ROUND_UP(e - base, unit_size); > + bitmap_clear(bitmap, first, last - first); > + } > +} [Severity: High] Does rounding first down and last up corrupt the persistent unaccepted bitm= ap when a hole is smaller than or unaligned to unit_size (2 MiB)? Each bitmap bit tracks a full 2 MiB unit in EFI_ACPI_RECLAIM_MEMORY, which persists across kexec. With a sub-unit hole such as memmap=3D1M$0x1ffe0000= 0, accepting any E820_TYPE_RAM page in that 2 MiB unit clears the whole unit's bit even though the hole pages remain unaccepted in hardware. Because e820_table_kexec is snapshotted before parse_early_param() applies memmap=3D, a kexec'd kernel receives the hole as E820_TYPE_RAM with its bit= map bit already cleared and crashes when accessing it. Additionally, sanity_check_segment_list() in kernel/kexec_core.c calls accept_memory() on kexec segments chosen from e820_table_kexec, which arch_accept_memory() now silently skips if they lie in a memmap=3D-excluded range. [Severity: Medium] What happens in range_contains_unaccepted_memory() when a full unit_size ho= le leaves its bitmap bit permanently set? For a 2 MiB-aligned hole such as memmap=3D2M$0x1ffe00000, arch_clear_accept= ed() never clears the hole unit's bit. However, range_contains_unaccepted_memor= y() still extends any unit_size-aligned end by + unit_size for the load_unaligned_zeropad() guard page without consulting e820_table. As a result, pfn_is_unaccepted_memory() always returns true for the last 4 = KiB page of live, accepted RAM immediately preceding the hole, causing unaccepted_memory_vmcore_pfn_is_ram() to omit that page from /proc/vmcore a= nd /proc/kcore to zero it out. [ ... ] > diff --git a/drivers/firmware/efi/unaccepted_memory.c b/drivers/firmware/= efi/unaccepted_memory.c > index 4a8ec8d6a571e..b8a0c0d1d2891 100644 > --- a/drivers/firmware/efi/unaccepted_memory.c > +++ b/drivers/firmware/efi/unaccepted_memory.c [ ... ] > @@ -150,7 +149,8 @@ void accept_memory(phys_addr_t start, unsigned long s= ize) > arch_accept_memory(phys_start, phys_end); > =20 > 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); > } [Severity: Medium] As reported by Ard Biesheuvel on v1 [1], should memmap=3D instead be disall= owed in confidential VMs so the firmware and OS views of memory remain in sync? Rather than addressing that objection, this version extends the E820-filter= ing workaround into generic EFI code via arch_clear_accepted(), exposing the mismatch between page-granular memmap=3D holes and the 2 MiB unit_size EFI bitmap. [1] https://lore.kernel.org/r/bd56cfa0-6fdc-4e83-b571-f2abf647afa2@app.fast= mail.com --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203113224.2504= 98-1-pankaj.gupta@amd.com?part=3D1