Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wandun Chen" <chenwandun1@gmail.com>,
	pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
	alex@ghiti.fr, robh@kernel.org, baoquan.he@linux.dev,
	rppt@kernel.org, m.szyprowski@samsung.com
Cc: catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com,
	chenhuacai@kernel.org, kernel@xen0n.name, tglx@kernel.org,
	mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	x86@kernel.org, hpa@zytor.com, saravanak@kernel.org,
	akpm@linux-foundation.org, pasha.tatashin@soleen.com,
	pratyush@kernel.org, ruirui.yang@linux.dev, robin.murphy@arm.com,
	ruanjinjie@huawei.com, devicetree@vger.kernel.org,
	kexec@lists.infradead.org, linux-mm@kvack.org,
	conor+dt@kernel.org
Subject: Re: [PATCH v10 7/8] of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP
Date: Sat, 28 Nov 2026 09:15:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-238578@kernel.org> (raw)
In-Reply-To: <20261127090723.741253-8-chenwandun1@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] of: reserved_mem: sub-page memblock split in
  fdt_mark_reserve_mem_nodump()
- [Medium] of: reserved_mem: early nodump split in
  unflatten_device_tree() before kasan
--

commit 47a5a6000f1f57782ed8a71e5ff4a13ee231c6bd
Author: Wandun Chen <chenwandun@lixiang.com>

of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP

This commit adds fdt_mark_reserve_mem_nodump() and calls it from
unflatten_device_tree() to mark page-clamped non-dumpable
/reserved-memory regions with MEMBLOCK_NODUMP.

Link: https://sashiko.dev/#/message/sashiko-outbox-181183@kernel.org [1]

> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index a58efdcbac7f1..f3a766310d119 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -1283,6 +1283,8 @@ void __init unflatten_device_tree(void)
>  {
>  	void *fdt = initial_boot_params;
>  
> +	fdt_mark_reserve_mem_nodump();
> +
>  	/* Populate an empty root node when bootloader doesn't provide one */
>  	if (!fdt) {
>  		fdt = (void *) __dtb_empty_root_begin;

[Severity: Medium]
Does calling fdt_mark_reserve_mem_nodump() in unflatten_device_tree()
split memblock.memory too early for kasan_init() and kvm_hyp_reserve()?

Mapped (!no-map) reserved-memory regions were previously only recorded in
memblock.reserved, keeping memblock.memory contiguous.  Splitting
memblock.memory with MEMBLOCK_NODUMP at PAGE_SIZE boundaries before the
rest of setup_arch() causes for_each_mem_range() and
for_each_mem_region() to iterate over the split ranges separately.

On arm64 and loongarch, when a mapped non-dumpable region boundary is
PAGE_SIZE-aligned but not aligned to PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT
(e.g. 32 KiB or 64 KiB on 4 KiB pages), the two adjacent regions share a
KASAN shadow page.  Because kasan_pte_populate() checks pte_none() only in
its do-while loop condition after the first iteration, the second region
allocates a duplicate shadow page, overwrites the PTE, and leaks the first
page:

arch/arm64/mm/kasan_init.c:kasan_pte_populate() {
    ...
	do {
		phys_addr_t page_phys = early ?
				__pa_symbol(kasan_early_shadow_page)
					: kasan_alloc_raw_page(node);
		if (!early)
			memset(__va(page_phys), KASAN_SHADOW_INIT, PAGE_SIZE);
		next = addr + PAGE_SIZE;
		__set_pte(ptep, pfn_pte(__phys_to_pfn(page_phys), PAGE_KERNEL));
	} while (ptep++, addr = next, addr != end && pte_none(__ptep_get(ptep)));
}

On riscv, splitting 16 MiB physical ranges before kasan_init() prevents
kasan_populate_pmd() from mapping a full 2 MiB shadow PMD, falling back to
4 KiB PTEs.  On arm64 with pKVM, splitting memblock.memory before
bootmem_init() -> kvm_hyp_reserve() consumes extra slots in the fixed
128-entry hyp_memory[] array and increases per-region hypervisor
page-table and vmemmap reservations.

[ ... ]

> diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
> index a5cd8c2fffc35..cef444d4c1a38 100644
> --- a/drivers/of/of_reserved_mem.c
> +++ b/drivers/of/of_reserved_mem.c
> @@ -610,6 +610,36 @@ static void __init fdt_init_reserved_mem_node(unsigned long node, const char *un
>  	reserved_mem_count++;
>  }
>  
> +void __init fdt_mark_reserve_mem_nodump(void)
> +{
> +	struct reserved_mem *rmem;
> +	int i;
> +
> +	if (!IS_ENABLED(CONFIG_CRASH_DUMP))
> +		return;
> +
> +	if (!IS_ENABLED(CONFIG_KEXEC_FILE) && !IS_ENABLED(CONFIG_CRASH_HOTPLUG))
> +		return;
> +
> +	if (reserved_mem_reserve_failed)
> +		return;
> +
> +	for (i = 0; i < reserved_mem_count; i++) {
> +		phys_addr_t base, end;
> +
> +		rmem = &reserved_mem[i];
> +		if (!rmem->size || rmem->dumpable)
> +			continue;
> +
> +		base = round_up(rmem->base, PAGE_SIZE);
> +		end = round_down(rmem->base + rmem->size, PAGE_SIZE);
> +		if (base >= end)
> +			continue;
> +
> +		memblock_mark_nodump(base, end - base);
> +	}
> +}

[Severity: High]
Can clamping each region to PAGE_SIZE here leave sub-page fragments in
memblock.memory when a no-map region or an adjacent region is not
page-aligned?

During fdt_scan_reserved_mem(), no-map regions are marked with
MEMBLOCK_NOMAP in memblock.memory at byte granularity (for example,
cont_splash_mem in arch/arm64/boot/dts/exynos/exynos2200-g0s.dts has size
0x9a3f80, and 4 KiB-aligned no-map regions are unaligned under 16 KiB or
64 KiB PAGE_SIZE).  Because fdt_mark_reserve_mem_nodump() does not skip
MEMBLOCK_NOMAP regions, calling memblock_mark_nodump(base, end - base) on
the page-clamped interior range gives [base, end) flags
MEMBLOCK_NOMAP | MEMBLOCK_NODUMP while leaving the unaligned head
[rmem->base, base) and tail [end, rmem->base + rmem->size) as sub-page
regions with only MEMBLOCK_NOMAP.

Similarly, if a mapped non-dumpable region abuts an unaligned no-map
region, clamping inward to PAGE_SIZE leaves a sub-page MEMBLOCK_NONE
fragment between the two regions; and if two adjacent non-dumpable regions
meet at a sub-page boundary, clamping each entry before coalescing leaves
their shared page unmarked.

On riscv, init_resources() converts every memblock.memory region
(including MEMBLOCK_NOMAP) using PFN_UP for start and PFN_DOWN - 1 for
end:

arch/riscv/kernel/setup.c:init_resources() {
    ...
	for_each_mem_region(region) {
		res = &mem_res[res_idx--];
		non_resv_res++;

		if (unlikely(memblock_is_nomap(region))) {
			res->name = "Reserved";
			res->flags = IORESOURCE_MEM | IORESOURCE_EXCLUSIVE;
		} else {
			res->name = "System RAM";
			res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
		}

		res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
		res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;

		ret = add_resource(&iomem_resource, res);
		if (ret < 0)
			goto error;
	}
    ...
}

Any sub-page fragment produces res->start > res->end, which fails
add_resource() and tears down iomem_resource.  On arm64 and loongarch, a
sub-page MEMBLOCK_NONE fragment likewise produces res->start > res->end in
request_standard_resources() / resource_init(), and an unaligned no-map
region split by MEMBLOCK_NODUMP is broken into multiple reserved entries
in /proc/iomem.

Since crash_should_skip_region() already skips MEMBLOCK_NOMAP regions,
skipping no-map entries and coalescing adjacent non-dumpable ranges before
clamping to page boundaries would avoid creating sub-page MEMBLOCK_NOMAP
splits and unmarked shared pages.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127090723.741253-1-chenwandun1@gmail.com?part=7

  reply	other threads:[~2026-11-28  9:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  9:07 [PATCH v10 0/8] kdump: reduce vmcore size and capture time Wandun Chen
2026-11-27  9:07 ` [PATCH v10 1/8] riscv: build crash_mem ranges from memblock instead of resource tree Wandun Chen
2026-11-27  9:07 ` [PATCH v10 2/8] crash_core: fold duplicated memblock arch hooks into the weak default Wandun Chen
2026-11-28  2:19   ` Jinjie Ruan
2026-11-27  9:07 ` [PATCH v10 3/8] crash_core: serialize crash header preparation against hotplug Wandun Chen
2026-11-28  2:03   ` Jinjie Ruan
2026-11-27  9:07 ` [PATCH v10 4/8] crash_core: replace for_each_mem_range() with for_each_mem_region() Wandun Chen
2026-11-28  2:58   ` Jinjie Ruan
2026-11-27  9:07 ` [PATCH v10 5/8] memblock: introduce MEMBLOCK_NODUMP flag Wandun Chen
2026-11-27  9:07 ` [PATCH v10 6/8] of: reserved_mem: add dumpable flag to opt-in vmcore Wandun Chen
2026-11-27  9:07 ` [PATCH v10 7/8] of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP Wandun Chen
2026-11-28  9:15   ` sashiko-bot [this message]
2026-11-27  9:07 ` [PATCH v10 8/8] crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF header Wandun Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-238578@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=baoquan.he@linux.dev \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=chenhuacai@kernel.org \
    --cc=chenwandun1@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hpa@zytor.com \
    --cc=kernel@xen0n.name \
    --cc=kexec@lists.infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=pjw@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=robh@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=rppt@kernel.org \
    --cc=ruanjinjie@huawei.com \
    --cc=ruirui.yang@linux.dev \
    --cc=saravanak@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tglx@kernel.org \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox