From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.227.203 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796200460; b=sQr7+YMrTFM2KSsDlgOM8ngO+q3W3s0HjZRjk/m6iXdAxlyCa1EdiTmW/SCFScE4+HJD OzdslCeiT0BS6HmFePhPo3SUsc5oZPE69Doq4gfz3y77T7uEt6Zs8kkgNfbQzY5/rcciv BMSbPxuDY//ukMqvaZ+2wrHcrh5/vATDktmUrsmMNVGPnIc0KfY3tLQJFn99q2VafD9Of nyEbJPAsnqwuN8Zj00srMx0s3FBRqO1p1d2yNro9/K1v5yK828574E0eVTfPMmR4gzNAC IGnijtd8N7eQsViGxv499AfJqQG21K0h9ZiKwMZbHPGO7xYjRAUZOldXi6pgDCdUsaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796200460; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=1IpYluGAPNKH+NZrwWEbTgwstlqUmj2L/Ys67fAlJjg=; b=RgF2wZsMLP/ZCcwhxCNZ7uIl15bxzpXxjzHm+cAkEhm7SzM1xGCD06j6/quf+jk7ufCG pGu8Zzw2YMGhUoUmaedXnFD++glKepJ6WK0FchOQUKrltiww/LnL2wjsUIErj+n9Zh2kg DmvmZnK6H7F2ApMdFrC/aQQct8bgmruzawbhPH3FqAqBV1g+XNHwNmmVRZA+Xowl4F0A3 3gzfMB9huC3ph3O4JKhpoj8hB6oH/BX1oP/3cvT4PF4/KaCnmi1ksZECRCZqJpQDv3HKe dmHB1nIN17gbqphGpv5Uly+VZeI2Ylba1TQ9XQk+zi6K1ozzj2zfzNPWNVG5bd9StbQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=PZNOEMED; arc=none smtp.remote-ip=74.125.227.203 Received: from mail-pi2-f11.google.com (mail-pi2-f11.google.com [74.125.227.203]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D5D8606A6A3 for ; Wed, 2 Dec 2026 08:34:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2D5D8606A6A3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=PZNOEMED Received: by mail-pi2-f11.google.com with SMTP id 41be03b00d2f7-cde795fea95so3549093a12.1 for ; Wed, 02 Dec 2026 00:34:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796200459; x=1796805259; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1IpYluGAPNKH+NZrwWEbTgwstlqUmj2L/Ys67fAlJjg=; b=PZNOEMEDNb53oo1PBty3JEIucmdfLQYWMfLVWV35BnHy2zVFPIFKJTtvZScbcLkjlz UFdqxNRnYw4iWI1ZDKnGxVLnR5G/0VfNcCv1wsAouLluX2IBbKrqcmqxuUU1/2NCwhyh OuDaAnHEQCdh/uOEcsZWfCX64ceNOcuInWOabHlrIzqZB0wSWcruBxogvc8Z2idbNTEc tTagH7jfqowerbseFLUyeLWZ+Bbyhyy9pTImVHFMhmOB8Y2Ao+0MI8y/hWjxKsQ40jY4 BK3ACqYuSriABs3VSrIbtq1sVacvOMP83DCwC0fTBAGWygpRcdoYPiL7jov3u32cL3iO ckUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796200459; x=1796805259; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1IpYluGAPNKH+NZrwWEbTgwstlqUmj2L/Ys67fAlJjg=; b=ZSrLIevmHcls/Yvsh8IHditm95Y5cpN8u+9tGo81npaNaehgTg297LG+/8oGHZstwR SC3iEJqGWk4RbD9WWOSLR1lzIt82NSD/FXQBTWHN/4U5zd5XT97L8wo2yHw44d1b8+i7 QKkyIw5jXwit3F7NwA1p7A2JDrobg4OrDosNwOlBjHHqtHH3m0GM90dVsZfRDBHQDqqe 4Q+QoE3USx/haLXdUy6Xcz0q4FAqkI58kxA7WuUb2FLMuNBNBv9mcVbVCc42mx23OotU PhR2PFIpvLFvxNeCQjDSSNX67lk370s7N6vR1JtkfWN8/8U7qqK0pfMR2wvM0dWHoYkp XZEQ== X-Forwarded-Encrypted: i=1; AL+hErF19NE5+0HsqD0TiBvS6mVqpssik5S0QUEsePuA1ln6QfxuY4tKJ3/HME3J4srv6S5+1mQuGOP4hzPs@vger.kernel.org X-Gm-Message-State: APuU4Z/zXOBSGoYoez1iwNmi5rRe+6FLgUesolT+XaIB14A4A9Zq4jA/ lgxQBY6K/MVOz1g/iIwqFBdhgXSTHhvR7VpwtZVkE5Tle6PqGNbP8+ZD X-Gm-Gg: AZFdTZcbradkXoZ4MN3HJ1s/5oLLvbEPhDxT3aC38oRYeYSVLfKGrZe967K74TMGGgk Sj/VZPcQA3SKpC1XId4g7uFcq9sWvb/4K3QEcGdnEj7fPpj8FzGfMyK99BML0lBrwseepV7vAYa pKFz9HLl7O0GPIa6v9MQ/eg//8jUR42t+naFAPmjxWzKcRB94nVlPDE1kNv/ByAQaqIUzj8ofPZ aZae8YbB7JbR2NJeEm3gxsH5PeifLEI/BNg1PSKlTRlEPmJy1dKVK5OOg8YW+55N09Hfc5di7k7 z3+FerXEf7pqXTGrag+jwHB2bLz8qYth0F+BYmiLqeKKB+9+ABTC7ORfS/InpMZo2aLuoJYtX6l wlxuEVAvQcxKXINvWx94bN8/UZe0OixTN6RYo1E8fytB8CcOCjSuYKDx/9B7/EZFJrvJ/3RkK0K iDpTWNqnNUAs+tEBw3U0ZZJnbyrnezOZhQP1DEzq6Ro/BTNMogURDIMFygDuSHZQuRz8L9U6DRh uZM8B67w6U50ErakhenEV/kL5fWkOeF62iNDj9uqjf3C1WXhh2mPTWfI8OER7cGlzpJmsP37PnO 7pk150luQWPchIUxMByBuVHkO3FvkgHOchc= X-Received: by 2002:a05:6a00:4518:b0:89e:f2d2:1eab with SMTP id d2e1a72fcca58-8c87cf2a12amr34923018b3a.42.1796200459233; Wed, 02 Dec 2026 00:34:19 -0800 (PST) Received: from [10.125.112.22] ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c87285c219sm21458569b3a.18.2026.12.02.00.34.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2026 00:34:18 -0800 (PST) Message-ID: Date: Wed, 2 Dec 2026 16:34:06 +0800 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v10 7/8] of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP To: sashiko-reviews@lists.linux.dev, 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 References: <20261127090723.741253-1-chenwandun1@gmail.com> <20261127090723.741253-8-chenwandun1@gmail.com> Content-Language: en-US From: Wandun In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/28/26 17:15, sashiko-bot@kernel.org wrote: > 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 > > 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: This leak is pre-existing: nomap markings already split memblock.memory the same way and trigger this today. This patch only adds one more source of split points. > > 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. Same here: nomap regions already cause this today. 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. Agreed, and to me this is the most serious of the three points. All three points introduced by this patch will be fixed in v11 by moving the call to an early_initcall. The marking is done from an early_initcall instead of from unflatten_device_tree(), so the boot-time memblock walkers (KASAN, pKVM on arm64) use the unsplit memblock ranges. The main reason to use early_initcall() instead of any other initcalls is that some driver initcalls can trigger updates to memblock.memory that may race with fdt_mark_reserve_mem_nodump(), which does not take a lock. For example, virtio_mem can queue work during probe to add guest memory to memblock.memory. Therefore, run fdt_mark_reserve_mem_nodump() as early as possible in the initcall sequence. > > [ ... ] > >> 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. > Same here, also a pre existing issue, and will also be fixed by moving fdt_mark_reserve_mem_nodump to early_initcall. For riscv, I have already sent a separate patch to fix it. https://lore.kernel.org/linux-riscv/20261130124221.2500317-1-chenwandun1@gmail.com/ Thanks, Wandun > 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. >