From nobody Tue Jun 16 20:38:23 2026 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC02639DBEE for ; Wed, 29 Apr 2026 06:58:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445936; cv=none; b=RkUZoJChi0uWsT6UxRcnrjWKRfiXRpWxZZFAbmsgMfhDIE0GKp6muFdFVfmwfnKriCnCfwyB20CACtviqHLDoTExUW9w+TlgioijEadSu8D7dSD36ORY4Mlxny4HWSItDgv4HXiwthOQIPwq2QZc+GkN48i+bQD4EQFvP6CkWrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445936; c=relaxed/simple; bh=3p0YBHSpmNNuRtsQDEIxkQcORCtiS252q1murO0b87Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tdmwZ7PrfUlXjOFxW3pAh5ZPmwwN/wyVgq8qmXQOFaB5BvPq9FYP/ZSsDJu6UIB0zf6oSKGGENyC0s3xNbFzVlKocPWPUe/im2qxIF+D57KmUCvHwJx5cd3JN37yTOP1Vtsnj0EA5vqUU2ssmcWxlgRdrYBB3BQaV4qD/DjxhOU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=sups5GrR; arc=none smtp.client-ip=209.85.210.194 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.b="sups5GrR" Received: by mail-pf1-f194.google.com with SMTP id d2e1a72fcca58-82f351ca23cso6291371b3a.2 for ; Tue, 28 Apr 2026 23:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777445934; x=1778050734; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y02uBvZORLsA6xImd4974JLfXXgs5mmuCn2J28MpgzI=; b=sups5GrRaVc2+j0pyqda6YOQ1TCNTO0Msnngq/uncykO9OIwxngAPv1gP7xO6pkN0G 5nrDClLzUvZZb3JPa3oRcDOpDRTx3oWRb4di/rxxOqRQqrk1V8fxD7zoia8U0/oo7eyX eU2WP0YxTdZqGeCjf9yqMkWBmqtGjpxEuTmbtdbWCDd7mM8Ih4fKT6IJFce5mcFI8lK9 NyYb9sogZMC2IdStNk7PzK4ILWYEDz2aBeORr51t9fwR54WQtLtK//5LEbi8KLBn4xaX rfrhpwOLCuZ0BoRw7buInJ36cSdsIn32dGO2b/UpiAU72vbfHC5kjWlxAJvfTYQydSBX KyXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777445934; x=1778050734; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=y02uBvZORLsA6xImd4974JLfXXgs5mmuCn2J28MpgzI=; b=JI5MfuT9WN0DobM4IRpjPojxFZCEAicIdHt6qCqobPaDt2HptN+jRhvVmZhv/4b5KF 0adNITmTPg8bgQ1mS24ojWXHPg4paQ+3hy4y4IFR0hPalont8kiYkivWJ6tLuk6vdgME SK5dmkEF3Lc/kDJQyZLzW8nXoeSCjwPyMoxkPnsjSgUtN7hLDqEHlFSrXWse8JOAbnBt s/tmTkvFgGIgqeU2Y5YuJSbzEppqqkdJyiSHS9+wJnE1Jtw4eNbXgZd6GVvSwh9yRE4J xl1hNhVhZsgFZY2M26z7l2EONbZDCOEZAaR/kpfz//MhYsNWb6TFsgPfEWyB16L5K9mj dXrg== X-Forwarded-Encrypted: i=1; AFNElJ97EU136H0kuLz/4xFGkoaTV1QVMLnYVkHZV7c4cCPvKTWBmLtCE/nEjSX/f5Cz6xBFkrOoz3GRZ/w9CLk=@vger.kernel.org X-Gm-Message-State: AOJu0YwwIHwip3I1OYMto4FsPcLPm/lS+8ZIaFBCD+Y4bNGH/lf2DrER qc7VuIAj18wuPe1yOCghVh/VADtZorBeHBFTRMNUf6oV9cA3tOx4lTZ3 X-Gm-Gg: AeBDieuG7pRqX6jXV3sNp5GD3EnEyORPF1rJ6kh9mUXH1ycHDsSdr19co0DhGE5Dkfn MTCru2sEyGgYU60xCMZoUFFe1YdboXoHvId3uDCw10y0B9pCrWVScwQ/EDZo8sk10di09SUaNFj RpR4r0T5RXENK7bIvbSAPsnv/bX/yci28rC4HgBjjW8NIg7DXxWrOhnQt1sM8pgcCzHCo9mAy0k Kz2LFQ3/sv+Ukc8UMv/F16SoBDAs9lfnJ+kRPgqYCPFZSS37CLv8b0r8/E2gKT5r+SknS6Zyj64 QzuwG6BvIwd8gFJard2drUXwBEfim1Xwqw/aPp99DhO2XBznbl/78ptWmxEH2vI6j5kV/xQbU3i b0+ZnecPOY10CVVKo9LYJlPXPoWFJmlxBysk245Aog/fx+7WTNTgb9trOb79cG3pyIz2PiRDJeN BhgzsO2fv/NyduMJv/lXhb2pwRDOomPLW3ryGjOzmqLNCmUJAI X-Received: by 2002:a05:6a00:2d85:b0:82c:dd31:b83d with SMTP id d2e1a72fcca58-834ddc5879cmr6667128b3a.38.1777445934284; Tue, 28 Apr 2026 23:58:54 -0700 (PDT) Received: from intel.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-834ed7eaf93sm1043146b3a.40.2026.04.28.23.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 23:58:53 -0700 (PDT) From: Chen Wandun X-Google-Original-From: Chen Wandun To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org Cc: akpm@linux-foundation.org, bhe@redhat.com, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, corbet@lwn.net, skhan@linuxfoundation.org, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, saravanak@kernel.org, chenwandun@lixiang.com, zhaomeijing@lixiang.com, everyzhao@126.com Subject: [PATCH 01/11] of: reserved_mem: fix region count for nodes with multiple reg entries Date: Wed, 29 Apr 2026 14:58:21 +0800 Message-ID: <20260429065831.1510858-2-chenwandun@lixiang.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260429065831.1510858-1-chenwandun@lixiang.com> References: <20260429065831.1510858-1-chenwandun@lixiang.com> 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 Content-Type: text/plain; charset="utf-8" When a reserved-memory node contains multiple reg entries (e.g., reg =3D , ), the count used for total_reserved_mem_cnt is wrong in two places: 1) __reserved_mem_reserve_reg() returns 0 on success regardless of how many regions it reserved in memblock. The caller in fdt_scan_reserved_mem() then increments count by just 1. 2) fdt_scan_reserved_mem_late() uses of_flat_dt_get_addr_size() which only reads the first reg entry. Subsequent entries are never initialized via fdt_init_reserved_mem_node(), so their metadata is lost. Fix both issues: - Make __reserved_mem_reserve_reg() return the actual number of regions successfully reserved. Update the caller to accumulate the returned count. - Rewrite fdt_scan_reserved_mem_late() to use of_flat_dt_get_addr_size_prop() and iterate all reg entries, initializing each one via fdt_init_reserved_mem_node(). Fixes: 8a6e02d0c00e ("of: reserved_mem: Restructure how the reserved memory= regions are processed") Fixes: 00c9a452a235 ("of: reserved_mem: Add code to dynamically allocate re= served_mem array") Signed-off-by: Chen Wandun Tested-by: Zhao Meijing --- drivers/of/of_reserved_mem.c | 37 +++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 8d5777cb5d1b..9d1b0193864c 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -129,6 +129,8 @@ static int __init early_init_dt_reserve_memory(phys_add= r_t base, =20 /* * __reserved_mem_reserve_reg() - reserve all memory described in 'reg' pr= operty + * + * Returns: number of regions successfully reserved, or negative error code */ static int __init __reserved_mem_reserve_reg(unsigned long node, const char *uname) @@ -137,6 +139,7 @@ static int __init __reserved_mem_reserve_reg(unsigned l= ong node, int i, len, err; const __be32 *prop; bool nomap; + int reserved_count =3D 0; =20 prop =3D of_flat_dt_get_addr_size_prop(node, "reg", &len); if (!prop) @@ -160,12 +163,13 @@ static int __init __reserved_mem_reserve_reg(unsigned= long node, fdt_fixup_reserved_mem_node(node, base, size); pr_debug("Reserved memory: reserved region for node '%s': base %pa, siz= e %lu MiB\n", uname, &base, (unsigned long)(size / SZ_1M)); + reserved_count++; } else { pr_err("Reserved memory: failed to reserve memory for node '%s': base %= pa, size %lu MiB\n", uname, &base, (unsigned long)(size / SZ_1M)); } } - return 0; + return reserved_count; } =20 /* @@ -275,25 +279,32 @@ void __init fdt_scan_reserved_mem_late(void) =20 fdt_for_each_subnode(child, fdt, node) { const char *uname; - u64 b, s; + int i, len; + const __be32 *prop; int ret; =20 if (!of_fdt_device_is_available(fdt, child)) continue; =20 - if (!of_flat_dt_get_addr_size(child, "reg", &b, &s)) + prop =3D of_flat_dt_get_addr_size_prop(child, "reg", &len); + if (!prop) continue; =20 ret =3D fdt_validate_reserved_mem_node(child, NULL); if (ret && ret !=3D -ENODEV) continue; =20 - base =3D b; - size =3D s; + uname =3D fdt_get_name(fdt, child, NULL); + for (i =3D 0; i < len; i++) { + u64 b, s; =20 - if (size) { - uname =3D fdt_get_name(fdt, child, NULL); - fdt_init_reserved_mem_node(child, uname, base, size); + of_flat_dt_read_addr_size(prop, i, &b, &s); + + base =3D b; + size =3D s; + + if (size) + fdt_init_reserved_mem_node(child, uname, base, size); } } =20 @@ -331,16 +342,16 @@ int __init fdt_scan_reserved_mem(void) =20 fdt_for_each_subnode(child, fdt, node) { const char *uname; - int err; + int ret; =20 if (!of_fdt_device_is_available(fdt, child)) continue; =20 uname =3D fdt_get_name(fdt, child, NULL); =20 - err =3D __reserved_mem_reserve_reg(child, uname); - if (!err) - count++; + ret =3D __reserved_mem_reserve_reg(child, uname); + if (ret > 0) + count +=3D ret; /* * Save the nodes for the dynamically-placed regions * into an array which will be used for allocation right @@ -348,7 +359,7 @@ int __init fdt_scan_reserved_mem(void) * or marked as no-map. This is done to avoid dynamically * allocating from one of the statically-placed regions. */ - if (err =3D=3D -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) { + if (ret =3D=3D -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) { dynamic_nodes[dynamic_nodes_cnt] =3D child; dynamic_nodes_cnt++; } --=20 2.43.0 From nobody Tue Jun 16 20:38:23 2026 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A67C139D6F9 for ; Wed, 29 Apr 2026 06:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445945; cv=none; b=uoZlLWQTBLXu+zgNHS0OEr0dvm5bhyv4fFswOBEEHHX2VejjkJdLtio76HwUk797TWvYSXL3jl+zLU/ddkeG1Thx0YJCwMxeMzrIO4Lji8B1ilBAWdoQt73MlDFUHj1w6aMMvnod/IEQvdwEcsbhxRPC8xLjx501T5KvknU04j4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445945; c=relaxed/simple; bh=4vP7N1zetgFgj1WqIi/8IydbnE6WqBVEmWVx1kRBdBA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D1lV+ktYwyUcj/EJkUFUUJ8QQphcKZkS1aaYYKcSJhYBDEp5nsR1+3fiepmUb1GaYUP/tmk5ruDCMBJf/qmvrEmjzSvgVAdzbOUtad5V4OwFHUFbxXKU9hChDyaSDLyqN0kL5OlB/YhD4XCwTe2U8DBhQowjFYi0axmckyttfNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=P9k3Bx5F; arc=none smtp.client-ip=209.85.210.194 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.b="P9k3Bx5F" Received: by mail-pf1-f194.google.com with SMTP id d2e1a72fcca58-82fbdd60b64so6908072b3a.3 for ; Tue, 28 Apr 2026 23:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777445944; x=1778050744; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X32YgoESRg0ywcKfjv7wOK1DWSx0V8m7oh8gezp47dw=; b=P9k3Bx5FnPEUJ9xsz9HaIP/KlmgWRKYrMOnNrcrwJZrPgP+1AnBkp4pMmSxdi9mbl9 8o2+L01Enwt+y66NaSpXSALAgWNOwy2hZeF5a7PjoRiKd9HQIvl00z8C+kcr1xHENr5E Yq/2EG0ogRfNJEOArkrsVRd1C600CLIhEBOa7/AM0IqNsIbGncyQtcEvchyUUVwzpGfs 3yYSnLAWbBVvWRE65jwgX0ToPPjDOx1Z/RmuFNAupcuWN347lc+tJYag6ahOwWahd0Te UfQZ6GWMUQuFE9vjJOPJe5hi7Nla6KLa70RHBHPof6uhkXPafnqhB8oFQli4RzdhrMRl AW7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777445944; x=1778050744; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=X32YgoESRg0ywcKfjv7wOK1DWSx0V8m7oh8gezp47dw=; b=ftFAhfWCYoaAzPdIFCeLlZXZsoLSKLrEQ2dd6Ho7RDkgy8pg3GuekpMZ6h2DfsuYVo jNRV68c8Hu1C28RQl2abt8NDtPY52/jASmf7xQn1A/mP0693MJh+mA8hntdPWAheKlRD hTHsAsgLFtCeMHa3z0mI+VHP1qSibNH2JHhXURRTN/yjSt8Fdl6bzh20x1mAJZgPPTwD VgGwKS0YC3LNHgsQ9o7ZTI8E9P0RjnK1SqfRJPGHPeAjkl+C2Z/UwjHRkkCqykrHdkdG Yn5mF+pIAX5YarR5ZH8PBD4rTyIdhjfL+5LZdgr9NHrcUj7lGIwSwjA8Zwd4jSd8eAGN gSXA== X-Forwarded-Encrypted: i=1; AFNElJ8bt32htev6c9+HoUZO0bG45xLipEQRpaO5e3pOb1cjYECVqEM0RRXcgzrQAL/Au+UsZs0wB9loLE9lyNg=@vger.kernel.org X-Gm-Message-State: AOJu0YyBjq5ZAYJgWNMexC7Tao1zCEGRREh+yH7wyDeWV/dMyZY4CoGX sHCqbe3o/qPZhfglZXvaUoF+M63w+jAtCkQtBzLnsPIlhk0GK69ZQYKu X-Gm-Gg: AeBDietTW/5bjP0e898OL5s05QQuk37CcneypuJHgwZQgXQ61j+4crUy1U1uqRRLfW4 55ZyfAJEZy27SqlJ/tTOGAYGmA9NMSM6biNsg5RM5Pynw4I8QTKLWY9P926ioqctdsToTKMUcE/ K/sC6CLfOPm7eYu8Jor8thD7LANX6OL05fFFxBJ0VwvfsccYVjS3QqpkzCsaXbhLqDrnhYpkAwF b2LY/Sucvbu6b0OVnb7ED0JxPHf11BwlTjt837vv+vj0MnJGJfj47hpb2hE/J4MTWfjY7m53bb7 h/GYPfus9FPiFS0JvZiRzqqbIlbYwDVRZfItVDUXM/Pt8juinoXwcsG85SBYTOe+Ymul3+goTc8 Sx9DFzK0OpL635jBTZ6B1bKtfraXAKJnXqfstUtu/8f4QDMSp4uBlI/ENzVuhRG8qiqrNrRyfnO 8d1SbnUyFpGvc16dHDZnWFXBbuhHYqKCYYH96v0DLPyn0TttA/nLAatDK/pbY= X-Received: by 2002:a05:6a00:17aa:b0:823:1c5f:1c43 with SMTP id d2e1a72fcca58-834ddc5725bmr6614944b3a.36.1777445944007; Tue, 28 Apr 2026 23:59:04 -0700 (PDT) Received: from intel.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-834ed7eaf93sm1043146b3a.40.2026.04.28.23.58.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 23:59:03 -0700 (PDT) From: Chen Wandun X-Google-Original-From: Chen Wandun To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org Cc: akpm@linux-foundation.org, bhe@redhat.com, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, corbet@lwn.net, skhan@linuxfoundation.org, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, saravanak@kernel.org, chenwandun@lixiang.com, zhaomeijing@lixiang.com, everyzhao@126.com Subject: [PATCH 02/11] of: reserved_mem: reject reserved memory outside physical address range Date: Wed, 29 Apr 2026 14:58:22 +0800 Message-ID: <20260429065831.1510858-3-chenwandun@lixiang.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260429065831.1510858-1-chenwandun@lixiang.com> References: <20260429065831.1510858-1-chenwandun@lixiang.com> 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 Content-Type: text/plain; charset="utf-8" early_init_dt_reserve_memory() does not validate whether the region falls within physical memory. If a device tree incorrectly specifies a reserved memory region outside the physical address range: - For the non-nomap path, memblock_reserve() blindly adds the region to memblock.reserved, creating a stale entry that refers to non-existent memory. - For the nomap path, memblock_mark_nomap() silently fails to match any region in memblock.memory, but still returns success. Add a memblock_overlaps_region() check at the entry of early_init_dt_reserve_memory() to reject such regions before any memblock operation takes place. This also simplifies the existing nomap guard: the original "overlaps && is_reserved" condition reduces to just "is_reserved", since the overlap with physical memory is already guaranteed by the new check. Signed-off-by: Chen Wandun Tested-by: Zhao Meijing --- drivers/of/of_reserved_mem.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 9d1b0193864c..03c676052dab 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -112,14 +112,21 @@ static int fdt_fixup_reserved_mem_node(unsigned long = node, static int __init early_init_dt_reserve_memory(phys_addr_t base, phys_addr_t size, bool nomap) { + if (!memblock_overlaps_region(&memblock.memory, base, size)) { + phys_addr_t end =3D base + size - 1; + + pr_warn("Reserved memory region %pa..%pa is outside of physical memory\n= ", + &base, &end); + return -EINVAL; + } + if (nomap) { /* * If the memory is already reserved (by another region), we - * should not allow it to be marked nomap, but don't worry - * if the region isn't memory as it won't be mapped. + * should not allow it to be marked nomap. The region being + * physical memory is guaranteed by the overlap check above. */ - if (memblock_overlaps_region(&memblock.memory, base, size) && - memblock_is_region_reserved(base, size)) + if (memblock_is_region_reserved(base, size)) return -EBUSY; =20 return memblock_mark_nomap(base, size); --=20 2.43.0 From nobody Tue Jun 16 20:38:23 2026 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67C8A39D6F8 for ; Wed, 29 Apr 2026 06:59:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.193 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445956; cv=none; b=sFzHvDlCTKCp4mq1rguKT+o9yqUcJ6Rs+Zew9xVcsTH7lc3XFFw1OpcupOqMYZDN9yKbmlj7rKhPJI+qZNLxRn//uJqHlwvLKQ1t3HJNiMjRRY88Che2Dy94y6e19iQUlRqN+0joW6Atv7LETQXN5gxWwf0dSrU5N1eg5y9ygUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445956; c=relaxed/simple; bh=cIkj0kxww8gxsjUOlEDL+11Vay4FMTzDgmzX/FxgbuI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F9+Adt+HP/M1bAsVq+wCmm1IE3XEauNcve/WQ5BOzcQC1NVZoosX4PAy4eN5CjuPW+82EQwqfCGOXcLp7BA3+88F0OJGIvKmVHCMDCTIS3lo+IB265d7d/y59wFWWqR5Xb8vJnmg9EjKixcmngSpP1OK+3gkP+J5YOlxgfMkjUo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NKZLuyw3; arc=none smtp.client-ip=209.85.210.193 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.b="NKZLuyw3" Received: by mail-pf1-f193.google.com with SMTP id d2e1a72fcca58-8318293f02bso296463b3a.0 for ; Tue, 28 Apr 2026 23:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777445954; x=1778050754; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p829QSKrb4/ZZPtJ47R2GmLE7Z7L3DGhl/Bc8vHjFYM=; b=NKZLuyw3YsXf/fwlXWzFiVmvonCJZf4r1bidu/xD/dnNdlHrerbXcxYoGYJXHlOzjd fYaeLTgU+M99MA0wOZWyvd7zPi0IDNjCwCeYlT8eivm8vAH5xT8q8U/O1v10Xlxkj1/r 7tsDgtbC+XqVS4BA0ME3JMNl5x9zgoeG1sv33+CLjJfkf2k0Z68G5ziDBjP7hWRpZeha ftIixrVaevFslXk8Vxk9mVEKFE+it41DONwcdZakaBU1DdOzrFzlc1xm/OdYwFOBrCJe 5UIlRu8dab9xD4dYu6mU63L3kvqXeabZ5GLu85eSZdGFZU/1xk00x2jYm2vD5mMQjGHr Nh8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777445954; x=1778050754; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=p829QSKrb4/ZZPtJ47R2GmLE7Z7L3DGhl/Bc8vHjFYM=; b=HW+rc/4ekyvTAMkxguSTCmNFO4C5TZYdwv0AbzMkvdj3mns9ZWVnpKRc5DjlbMnQhS Cqpk1J4LMmXLX8Y6R3kl5lmtpIb784//ir08MGigaWTaZ+PD9PKWsipj4B4R4j/ZZ/R7 M8OPHG5X3I7mkfic/YEQAF/N2JaqUjXIzZu6NOxIoPJcGUoo3sA0rgOyLo5Ed/AoFCxa u+HAH/TCBYJDlSJ+77iQSDXMjT/Cnrr3wS5S7hvaK6fxx4C6+Jr/YK60O9VTDC2voI2o 5SlM+dLxZiH6BGIM9/IPxZlKrG6+onzvXCECgcpgTxHD8Uz9b1ytiFwcwsRgwWjUI9Rz mKgA== X-Forwarded-Encrypted: i=1; AFNElJ8VLagRrZros8xp0jvRVYbfkZbcq4AainoQ/oH+YRXPjZ0OsR9R1e4g7YfESO1PTaFZvX9LM7Is5s3zHso=@vger.kernel.org X-Gm-Message-State: AOJu0YwVcUx+Db9lL3vdZrS+w3qThrr+G7spdt0jPYjAs+ez5yrLSDWc MeuInr8CENpz2p5J/UhjJloE5mI68RIzFTntRQcST6NipvFuoCi+9m+L X-Gm-Gg: AeBDietaMqdtAhpb/4bZyHkzBiWvsteNuszqDVqRJwxtxndgAC3MbqssTkWzg6mttCa Fzgp1nlkCB5ZeVnUBLOAGYM4QHFVn87M5tO/iUhR/uljMBGAsAU3bpyv87VOZhmfvWWsK8dHmif lh7kvPBy7z0F9SPOOEuucyWZ5jBo1gbWG662BsxkY3YgYFoSnH3xHsotZHLmkmOsfWbun5TRbsz 9MYlf4s5iN36SyScEI+HERy+bi6ncNqERM3h0LoF0eiKT51OjuMzzs9NIFwCs0FrAryY/nq+gz9 3KrX+Lm38OouBEd3or3C4rPkt4NhFcq0WTzZKXVtpXiHjb518abUz30b38rM/udk1ipj73QkFyW 3qCkygpbNsJc8Dt8J+bPHsnA2dXcCu1HQ8vPHUqMcq97GQp2DmpAih7++x80ZSfO2N6gnRiVl8g UTMf9/Hw5nKTit3Oux7ZbO/EyU0IZ/yyzjKEoY+EEmbZLZTGuhqxeyYt9+KFo= X-Received: by 2002:a05:6a00:94e8:b0:82f:65d:33ad with SMTP id d2e1a72fcca58-834ebb751bdmr1807155b3a.15.1777445953880; Tue, 28 Apr 2026 23:59:13 -0700 (PDT) Received: from intel.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-834ed7eaf93sm1043146b3a.40.2026.04.28.23.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 23:59:13 -0700 (PDT) From: Chen Wandun X-Google-Original-From: Chen Wandun To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org Cc: akpm@linux-foundation.org, bhe@redhat.com, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, corbet@lwn.net, skhan@linuxfoundation.org, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, saravanak@kernel.org, chenwandun@lixiang.com, zhaomeijing@lixiang.com, everyzhao@126.com Subject: [PATCH 03/11] of: reserved_mem: avoid unconditional save of reg entries in fdt_scan_reserved_mem_late() Date: Wed, 29 Apr 2026 14:58:23 +0800 Message-ID: <20260429065831.1510858-4-chenwandun@lixiang.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260429065831.1510858-1-chenwandun@lixiang.com> References: <20260429065831.1510858-1-chenwandun@lixiang.com> 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 Content-Type: text/plain; charset="utf-8" fdt_scan_reserved_mem_late() iterates all reg entries of every /reserved-memory child and unconditionally initialises each via fdt_init_reserved_mem_node(), while fdt_scan_reserved_mem() in the first pass may have rejected individual entries in early_init_dt_reserve_memory() (e.g. outside physical memory or, on the no-map path, overlapping an existing reservation). When a single node mixes failing and succeeding reg entries, the first-pass counter only accounts for the successful ones, and the second-pass save then overflows into the wrong slots: the failing entry may be written to reserved_mem[] while the succeeding one is dropped by the "not enough space" guard in fdt_init_reserved_mem_node(). The stored entry does not correspond to any real memblock reservation and misleads consumers such as of_reserved_mem_lookup(). Mirror early_init_dt_reserve_memory()'s preconditions in the per-reg-entry save loop: - skip the entry if it does not overlap memblock.memory; - for nomap entries, skip if the region is already reserved. This keeps reserved_mem[] strictly consistent with the regions that were actually reserved. Fixes: 8a6e02d0c00e ("of: reserved_mem: Restructure how the reserved memory= regions are processed") Signed-off-by: Chen Wandun Tested-by: Zhao Meijing --- drivers/of/of_reserved_mem.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 03c676052dab..807b222fce5f 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -288,6 +288,7 @@ void __init fdt_scan_reserved_mem_late(void) const char *uname; int i, len; const __be32 *prop; + bool nomap; int ret; =20 if (!of_fdt_device_is_available(fdt, child)) @@ -301,6 +302,7 @@ void __init fdt_scan_reserved_mem_late(void) if (ret && ret !=3D -ENODEV) continue; =20 + nomap =3D of_get_flat_dt_prop(child, "no-map", NULL) !=3D NULL; uname =3D fdt_get_name(fdt, child, NULL); for (i =3D 0; i < len; i++) { u64 b, s; @@ -310,8 +312,23 @@ void __init fdt_scan_reserved_mem_late(void) base =3D b; size =3D s; =20 - if (size) - fdt_init_reserved_mem_node(child, uname, base, size); + if (!size) + continue; + + /* + * Save only entries that were successfully reserved + * in the first pass. Mirrors the preconditions in + * early_init_dt_reserve_memory() so that a per-reg + * entry failure (outside RAM, or nomap rejected due + * to an existing reservation) does not leave a + * ghost slot in reserved_mem[]. + */ + if (!memblock_overlaps_region(&memblock.memory, base, size)) + continue; + if (nomap && memblock_is_region_reserved(base, size)) + continue; + + fdt_init_reserved_mem_node(child, uname, base, size); } } =20 --=20 2.43.0 From nobody Tue Jun 16 20:38:23 2026 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F12D39DBDB for ; Wed, 29 Apr 2026 06:59:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445965; cv=none; b=l1wL56J90DEyJJPVDmlaTKw/RC54fyPrm8yDEIUHlUgs8y6mrdZrouHoTv82UsWqIj5NteQZkHApUGnL/d4335ff2P3Lu2lyuJXJIB9KyeOYGjiGz3rp1iCeK3LG5jJ2VL9vFE+hk86lHREPqgOybUn9+W+lYwi/WM6mYHLAfNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445965; c=relaxed/simple; bh=AscXsVQdQtSzP4LlCGAz/Bs520rvB9Y/aAxkWx2lFak=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hyK+S/FOPnY3iv63n5qpj5A9UZw5A0xWmX7oF83fDjYu+VGKqoayx9qANMRW5vHulYVCkPsP+Mn6izaMSxp/qAU8MTjnA8+SK+dIpYYnLNNaO9dggyWUk4twB8PL/XJOOBdml/ajE7myUyBlDyVAHtgz2VWvLcCejzzyBTb+XAA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZnVoxcCo; arc=none smtp.client-ip=209.85.210.196 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.b="ZnVoxcCo" Received: by mail-pf1-f196.google.com with SMTP id d2e1a72fcca58-82d0b68837aso7235097b3a.2 for ; Tue, 28 Apr 2026 23:59:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777445964; x=1778050764; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OzSUcXeQbcSyOJLVmBDEIvlXQPXERsU2BOZ+obvdQ0o=; b=ZnVoxcCoAveJ4rIHsBQ12JxKf+R9lgl5AhXozPQpSLLiF8+wiBEHHW0LJyxlViKYy1 VAxJpIoy42UOkWXFdD+2e7ifiSW+OMwkY7HcsHMWb+sle2r8NJW7Lgz9QG4DxNI1NuXs jOIJ6IKwMpRE1SbURUdW72HbqFDVvYSKJNCvCuu19+bJ185LySuWdYFxCnz0xdHtiF7N cR35X9dLQPuQN/lQ4pP1zeteyWSQ+l2ZS0jBHoZ5y72PZ25GIu6ArWIhaf+YgJzDGHWp KNIorlgsSlCs0IeGDbqHW0ABCqFJwP2KSDBfKNomlFpyIjLtnAnBopCCi6+UePGsyPg2 nROA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777445964; x=1778050764; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=OzSUcXeQbcSyOJLVmBDEIvlXQPXERsU2BOZ+obvdQ0o=; b=MAQ5RpUoabTh/9w1L/cr0C5eEslVaGXPCa6i5E5+wkfXWmtRudzZbVd72g5J6lfCiM Dk1xYUtMhZNlyjktlYp2I4ayPaeXG4I2BAoX1AU3r+VhXSVbXflyKcryL0q04pwilxYn /gx7s9yeigqAhRHKBbSvyNVwKmXzXjRcboa9JNl16pW2SY8W5L7xr6hb0/LRG6O40d3A 8DI7ZkptMcdDHfRe6qPbMU+7aGxyriRpARZnxj4tBaVnusRLh5Spr2/D9JHi7l4oOHog ZONbl+hrGe6dHua12lutjxUflTCaHR3ySKevcCoe/4mP+yrp2kIszXlq2Ij9pzbuHjth X2vA== X-Forwarded-Encrypted: i=1; AFNElJ8XJlIsfsEewU+WZHYWzFzMB5EEH302pGg6KuA3XCVGGsO2Mf9Zmi2wdMEWIgYYGUU/vuyQSZlAr9gmojM=@vger.kernel.org X-Gm-Message-State: AOJu0YzcZM3xe4GgDe1QAM/V6j2OdjiwzD7fX6cLLoZj85++fHsWBzLY 1h7WcgcUJUIp+m67bvxCDc7RDh6OB5u3NJvSyW8SHavTl6da0+bOitv8 X-Gm-Gg: AeBDietwz1XKdWNEjyVcMhgUIwyt+35hf6M5L+ns8ypeX1MocO3AmASRGbqR+sUQXJu WTD1muOLXuIetH4Fw9gQc/Htp7MjAoH/h7GjDjrzlmgs1Y0FfDqw8O1ohG3isxkkK0Yh72BMcTi PynPScGgumtiEQflniKAatcq+SWIJLOoaxTkBnNVIPckGMpHb5zga9OzyXLcwMI2nkJous4NDyN 4gDCleF1lbihTPnpk8FuqgHTDUI+OejFRyetbXeL2ihxPF0wtaGEY4l4N5ssyFF7xJBCbcisygt wXLc/RgksqAXqvU4ZozT+TTwh56N6ENb6ZZ/BWAuj5xMeW+M6HQEk4jE3bIQa/wMJ+az/ZflBRk UwPiF8Xl2KsflWAZVPs+E3kGawNoaB8CnVUr4M4IIBH/w7jHxQ8zcOfX2Z6P0cc7ewDcZtwgM+h Irq4KLvoEKRpJTF/jiaBlAbwMsweuZ++vZ7OXxmxwI3hHgabN+ X-Received: by 2002:a05:6a00:1c8f:b0:82f:29fe:7239 with SMTP id d2e1a72fcca58-834ddc4bf7fmr5980744b3a.50.1777445963631; Tue, 28 Apr 2026 23:59:23 -0700 (PDT) Received: from intel.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-834ed7eaf93sm1043146b3a.40.2026.04.28.23.59.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 23:59:23 -0700 (PDT) From: Chen Wandun X-Google-Original-From: Chen Wandun To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org Cc: akpm@linux-foundation.org, bhe@redhat.com, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, corbet@lwn.net, skhan@linuxfoundation.org, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, saravanak@kernel.org, chenwandun@lixiang.com, zhaomeijing@lixiang.com, everyzhao@126.com Subject: [PATCH 04/11] of: reserved_mem: skip reserved_mem array allocation when there is nothing to save Date: Wed, 29 Apr 2026 14:58:24 +0800 Message-ID: <20260429065831.1510858-5-chenwandun@lixiang.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260429065831.1510858-1-chenwandun@lixiang.com> References: <20260429065831.1510858-1-chenwandun@lixiang.com> 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 Content-Type: text/plain; charset="utf-8" fdt_scan_reserved_mem_late() unconditionally calls alloc_reserved_mem_array() after confirming /reserved-memory exists. Two issues with that: - When __reserved_mem_check_root() subsequently fails, the call returns right away, leaving the freshly allocated array unused. - When /reserved-memory exists but fdt_scan_reserved_mem() found no entries to save (total_reserved_mem_cnt stays at its freshly-set value of zero, e.g. empty node or all children disabled), alloc_reserved_mem_array() ends up calling memblock_alloc() with zero size, which returns NULL and logs an "Failed to allocate memory for reserved_mem array" error even though nothing was expected to be allocated. Move alloc_reserved_mem_array() past the root-node check and gate it on total_reserved_mem_cnt, so the array is only allocated when there is at least one entry that needs a slot. Fixes: 00c9a452a235 ("of: reserved_mem: Add code to dynamically allocate re= served_mem array") Signed-off-by: Chen Wandun Tested-by: Zhao Meijing --- drivers/of/of_reserved_mem.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 807b222fce5f..93585af9f8a3 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -276,14 +276,22 @@ void __init fdt_scan_reserved_mem_late(void) return; } =20 - /* Attempt dynamic allocation of a new reserved_mem array */ - alloc_reserved_mem_array(); - if (__reserved_mem_check_root(node)) { pr_err("Reserved memory: unsupported node format, ignoring\n"); return; } =20 + /* + * fdt_scan_reserved_mem() sets total_reserved_mem_cnt to the + * number of entries that need a slot in reserved_mem[]. If it is + * zero there is nothing to allocate or save. + */ + if (!total_reserved_mem_cnt) + return; + + /* Attempt dynamic allocation of a new reserved_mem array */ + alloc_reserved_mem_array(); + fdt_for_each_subnode(child, fdt, node) { const char *uname; int i, len; --=20 2.43.0 From nobody Tue Jun 16 20:38:23 2026 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34F4839DBDB for ; Wed, 29 Apr 2026 06:59:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445975; cv=none; b=Mf8BAU2zcjxCCH4bEmKYimr4LDuc0uJyQIafnRQQa3EjkNZ27BuIfDV3VQIxb7vliaapVM1GqB38Xkojb593709upt61ifobP+kIjrDLV63jr2bPDQKFsPZcfg+ufbtIDP2eWmT3z3dChuT8KgJasSn3DDWKCOzRz1bIEij+Y7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445975; c=relaxed/simple; bh=njXek1mtACSOjC4Z95gnnxHimRa+XaiIE4tLKUU7iZ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pltaX+cArf4q9U+DXoU9AX8IMGc2vNgqkzqNU03mqYe1q1aq6xAyVlKbpxIDm4zi9zY4rIzV1P9gMe2vBmR39cHgcqGZ/RWG5U6FLN+MqCPCgWygx2bknRe78T46FueamktBlqBpoXzoIlcNzxGww6xBTeZ9EJP5vCLJYrL+oWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Y40p1EVH; arc=none smtp.client-ip=209.85.210.196 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.b="Y40p1EVH" Received: by mail-pf1-f196.google.com with SMTP id d2e1a72fcca58-82cebbdbdccso389080b3a.1 for ; Tue, 28 Apr 2026 23:59:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777445973; x=1778050773; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8ejmHsY9aPO4mjE6CDrxULTYgFgw7tdPgcMhiefmNm8=; b=Y40p1EVHlbNm6FIzq2x7jJEbhRHfZEj/l6wvnst5xi/4hOfjTuktEcgcEKtzFH908l UhtwWz507ztReMZcfOfcO3dUFaKSjiZVwZ82dnWA0/CrVdTzkja4Or0p+uwR8i+xpOUS k1Zu0xcj2UZ8bcg5uP7QYZBhlDGsdFOhZt8z9oWAZ8m7QCoxn1AXMCB3zVcfYc7gI0TR 8vLaI2YHDeuOxwJD/0hTX2Z9wZsaOkHjyj62HBfEfIygZNCvAJprn3gdTdKexHsFNeVf gnDnLoGNmjm/y3CZTjH0QItk5D6C53lkXXHrZAyJ+Y+KzAVB0lX/0/OZ2ZWcT2TNPcWY xU0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777445973; x=1778050773; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8ejmHsY9aPO4mjE6CDrxULTYgFgw7tdPgcMhiefmNm8=; b=oLzl2qAw1XUMROoHiYiB3yCSUMx+Pnv9br92Vrea2w/EadKx0Cv5vVFgP30b/o1IRE t9JwW4WxChrLenVLOMI+o1MOqeYEionGphICuxSHxskSRckJxcYLcvTrpZmCDGV5ZWqZ FBkqW6Pi6vcBXI4Rm/Fanfo62KWiMr7844KbiXbYZM6V2Pr2lSUgNf+ID4njvMwHPVTV 3OgFbKYGElVjmVpTsbmdMaKMjcWkUC8h3eA/tILFWxWcMJFHr7DgDw02M+1XF3RgQfaV +Tmo39igBHzS3BV/FhyLKcldLLmCRPnRv43oCCGHH/cl9cZkTRpdKWgP2kg7FkddGEZv c47Q== X-Forwarded-Encrypted: i=1; AFNElJ93eMN6mllq1fR21luxlEyfnD2smhAiGGd93CvEYR+pyHwufTYWaKlrQJCwX/GEuWlcEzievQTf7Xv8TX8=@vger.kernel.org X-Gm-Message-State: AOJu0YyqIuqJZSM6VGwdPdQFhmt/4tAzeLqU2XstVLSuEeEPSh4JlONp cZvrig6o3RpqfivHqeEPV0P4Afz6rMouezGJSQUlfDPH2B253U1pJNhq X-Gm-Gg: AeBDievA+FTvo4jVhSyhf7x5JuDzHnZ2/IjEaTK1sXqDsm9gHPJE44NtYbcRaoj7Zrz 2nKyRa8PdknNhdD9dtHoXXYLhx6oDzBiPGAnFcDd/fYdpAIx0IZUeFj/Aqep3A+02SoCj0jjuin MFp0orkzSi/Hx4R/QAlZYbXjUYhg3qvOrldLDj/J7wajE1rZbZckBIs+G/GVA/lR5nPV0up5Yxx wvmHBKJPwyVl0f8KHk4s26CD/5TQk+l9E6fnC5MnLTASbT6hLJMAAXQubj/dKeTcHjOblGeCtPx tI6aC5qp/4p0fwvfd6LT3rfk985QUMgORmd3hCVx+sri4vZGKGgyfitzlw8mlOXQhMoey252MLD PyuJXkJydJNzVCoN9TrzL1+WZ1z5UH6U0Masd+/I8F5xQBz++ksBtJa9/SIQsHZcgUDIPJh46X5 wkO6GjoX/la4tzkCszoEz+xPHhXyTqDvQDcxdEUfetmvASTEuJqRJGUb1Jw0E= X-Received: by 2002:a05:6a00:2e93:b0:82f:2d48:f8fc with SMTP id d2e1a72fcca58-834eb3e4d01mr1774850b3a.6.1777445973470; Tue, 28 Apr 2026 23:59:33 -0700 (PDT) Received: from intel.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-834ed7eaf93sm1043146b3a.40.2026.04.28.23.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 23:59:32 -0700 (PDT) From: Chen Wandun X-Google-Original-From: Chen Wandun To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org Cc: akpm@linux-foundation.org, bhe@redhat.com, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, corbet@lwn.net, skhan@linuxfoundation.org, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, saravanak@kernel.org, chenwandun@lixiang.com, zhaomeijing@lixiang.com, everyzhao@126.com Subject: [PATCH 05/11] of: reserved_mem: add linux,no-dump property support for reserved memory regions Date: Wed, 29 Apr 2026 14:58:25 +0800 Message-ID: <20260429065831.1510858-6-chenwandun@lixiang.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260429065831.1510858-1-chenwandun@lixiang.com> References: <20260429065831.1510858-1-chenwandun@lixiang.com> 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 Content-Type: text/plain; charset="utf-8" Add a 'no_dump' field to struct reserved_mem and parse the 'linux,no-dump' device tree property during reserved memory node initialization. This property allows device tree authors to mark specific reserved memory regions that should be excluded from kdump vmcore dumps. Reserved memory regions used by device firmware (e.g., GPU, DSP, modem) typically contain data that is not useful for kernel crash analysis and can significantly increase vmcore size. The 'linux,no-dump' property provides a declarative way to indicate these regions should be filtered out when constructing the elfcorehdr for kdump. The property is named with a 'linux,' prefix because kdump/vmcore is Linux-specific and the property is an OS hint rather than a hardware description, matching existing properties such as 'linux,cma-default' and 'linux,usable-memory-range'. The 'linux,no-dump' property is only effective when the region: - Does not have 'no-map': these regions are already excluded from vmcore since they are removed from the linear mapping (MEMBLOCK_NOMAP). - Does not have 'reusable': CMA reusable regions are actively used by the kernel for movable page allocations, and their contents are valuable for crash analysis. The no-dump status is also printed in the boot log alongside the existing nomap and reusable flags for diagnostic purposes. Corresponding dt-schema binding update: https://github.com/devicetree-org/dt-schema/pull/193 Signed-off-by: Chen Wandun Tested-by: Zhao Meijing --- drivers/of/of_reserved_mem.c | 13 ++++++++----- include/linux/of_reserved_mem.h | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 93585af9f8a3..ac3d8b837d61 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -654,6 +654,7 @@ static void __init fdt_init_reserved_mem_node(unsigned = long node, const char *un { int err =3D 0; bool nomap; + bool reusable; =20 struct reserved_mem *rmem =3D &reserved_mem[reserved_mem_count]; =20 @@ -662,11 +663,14 @@ static void __init fdt_init_reserved_mem_node(unsigne= d long node, const char *un return; } =20 + nomap =3D of_get_flat_dt_prop(node, "no-map", NULL) !=3D NULL; + reusable =3D of_get_flat_dt_prop(node, "reusable", NULL) !=3D NULL; + rmem->name =3D uname; rmem->base =3D base; rmem->size =3D size; - - nomap =3D of_get_flat_dt_prop(node, "no-map", NULL) !=3D NULL; + rmem->no_dump =3D !nomap && !reusable && + of_get_flat_dt_prop(node, "linux,no-dump", NULL) !=3D NULL; =20 err =3D __reserved_mem_init_node(rmem, node); if (err !=3D 0 && err !=3D -ENODEV) { @@ -680,13 +684,12 @@ static void __init fdt_init_reserved_mem_node(unsigne= d long node, const char *un return; } else { phys_addr_t end =3D rmem->base + rmem->size - 1; - bool reusable =3D - (of_get_flat_dt_prop(node, "reusable", NULL)) !=3D NULL; =20 - pr_info("%pa..%pa (%lu KiB) %s %s %s\n", + pr_info("%pa..%pa (%lu KiB) %s %s %s %s\n", &rmem->base, &end, (unsigned long)(rmem->size / SZ_1K), nomap ? "nomap" : "map", reusable ? "reusable" : "non-reusable", + rmem->no_dump ? "no-dump" : "dump", rmem->name ? rmem->name : "unknown"); } =20 diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_me= m.h index e8b20b29fa68..29674f572673 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -15,6 +15,7 @@ struct reserved_mem { phys_addr_t base; phys_addr_t size; void *priv; + bool no_dump; }; =20 struct reserved_mem_ops { --=20 2.43.0 From nobody Tue Jun 16 20:38:23 2026 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E244139DBE0 for ; Wed, 29 Apr 2026 06:59:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445985; cv=none; b=kqIpDd2EVeazowva3BTSvVfGutk82cM9qwhEXnS3WfmkHtRhqihQa0VYG4zagHvC4/R4zwX5zpJyPkk7ZCUaZRqHhNIL+YS4vHwWadDlVtQJl4BNGR7fyag5V+M5tDUsxUvema4CuisxZjRBthDH4m/HZ7RWPvkydnrQyUT4CzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445985; c=relaxed/simple; bh=qpJTPexygSurz5Uyf2L27E21lAO5pvcSgLBshfv01g4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G/xD5LSgVP1+UiFKJqeiERKiWy146wHfHRTtuPmEMooJ/8o0BKQURlgeCcrU8DFk0Rj+XzzPDH02phMs+OOYRsgwRnJcV6OinPaFy/EmnLPx3CDxbdLkdC2OUNjRyWDIp8fZBZfACal1pHvk7B26s+q1Du4uyFXPjzg4f7a1K/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=r1xbHHCI; arc=none smtp.client-ip=209.85.210.194 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.b="r1xbHHCI" Received: by mail-pf1-f194.google.com with SMTP id d2e1a72fcca58-82f351ca23cso6291632b3a.2 for ; Tue, 28 Apr 2026 23:59:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777445983; x=1778050783; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2q9dPj7TNisCrTMpZ3igJmznQK/scPvx1hraOs9ZEkA=; b=r1xbHHCIRVod2QEz3dDsT/QVb9bBgSVc+kk8m1OOyKJ3xI1QOdSy9TLjj15mc0kvUh 4vPuHmxgYfFY0PhNQYnC7b/eaBA5Z/imnXM+G5LF8Jb0uSSswUorB/K60p3+aziE6a+w ae14gXJgphdmNWUwpEjYGeE0rjo8hpIB4rli7+iLOiFNPSxTGYRlw1bNX2kOL3gum3zE w8AV8Ng+M8GvrQwNEhyzV3uGZCHmVEM8zBKzvU7zCIvXuvOwxKh+sELh4wZJYVM0Hpj4 +acRWGBhcRLCo1baJnvwqUZZdgPXHwVkxGkYlN7RANgLVdG/VitiF9JIc9lsY0ripr1A +dww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777445983; x=1778050783; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2q9dPj7TNisCrTMpZ3igJmznQK/scPvx1hraOs9ZEkA=; b=Wah7KF/hAJfg6yDMT/aVcuy8jiuiqpaCz0xRZqMpp23bOwXwKVJv4dsQ9xdSfalpSV AJWhRv+G90ZSUEEt8a4mo6773/rlezNtxJowgCO3E12YQd3wzxJrqUw+vsT5356KGYkR GOrh4S+S/gQqW97g1U8xG4sJ0Ge53rT1695xfEZgZjOWBbo0O2GW3dtI5nu5sxkif7Ok USqyiZXkzTJFnddWrJbNml63ZqHSMsKm+ydLJGSh8IXEt9L115ng5H0ZYBk6F8BgibTz aDADW/1lfaz2RUlLKGd3uT8fNYOuO1yRMr/zxf/wXcsAbgQEPwlucs5Cdggk8vwPFLhm xLAQ== X-Forwarded-Encrypted: i=1; AFNElJ/h+e2TnaLJpiUGPs5Q7vttzDTwJs8BJPDqsDtWRML6KniL0Xr3SFk9f8WzWXzMrJGi5V5rpjWIXrw7Taw=@vger.kernel.org X-Gm-Message-State: AOJu0YxdteOmsqzrFN9/5L6JhVy2rqSpMGXJ4O4ri91Ga3C5x8gBe+IQ +JFWdIqE5DKLRgd7NVd6ElhTWFTw9pgv7LS3/d4IP81CGbyY0+N5lV2V X-Gm-Gg: AeBDieu4Cf8MOIzVislseQa9u2RU81ZUXFjzMWJu1HuRi0uS6N83RIyQpRhFW9alfH5 HP/0uJFGmguFIzhByy4P0h634fUIurIqUrOL25asggjCeS1BnRjSIQdbcNv70kAdl7q/QkI2gfr exBaPB1tPFE2RppKBDnlfSEwBnoWqAK1Z8F0pVEJ95U0m9jDAZvlPVcsQmdsZUjBm/nV/KYPLKL 45eMvtrWCPa+rEwVvD+Bd1lt8fe3SA44cPLbGmtYSs0DgPXK4VpObHEPfU/72PnOe5AYwEHUvpO IcMGSgBhlSmWf5MIaPnjkpWFZRtCCZmX1bPC4tNSmm0DczHAnvsJcXQ2k9UTobJCE+YV/w7wcND 1Jkzoo42qL9f4LYOhFDjZT8fJhF1hVXr2eKvK7wwaeAVKXMk3hFdqepiFYLPrapUbI+NUrL6jei RM2MD5TClpgFuZh0gapWJUevMNoEXaQWT50yg2rdiIAxML6pcL X-Received: by 2002:a05:6a00:1802:b0:82f:bd8:70eb with SMTP id d2e1a72fcca58-834ddb5b988mr6406851b3a.21.1777445983273; Tue, 28 Apr 2026 23:59:43 -0700 (PDT) Received: from intel.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-834ed7eaf93sm1043146b3a.40.2026.04.28.23.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 23:59:42 -0700 (PDT) From: Chen Wandun X-Google-Original-From: Chen Wandun To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org Cc: akpm@linux-foundation.org, bhe@redhat.com, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, corbet@lwn.net, skhan@linuxfoundation.org, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, saravanak@kernel.org, chenwandun@lixiang.com, zhaomeijing@lixiang.com, everyzhao@126.com Subject: [PATCH 06/11] of: reserved_mem: save /memreserve/ entries into reserved_mem array Date: Wed, 29 Apr 2026 14:58:26 +0800 Message-ID: <20260429065831.1510858-7-chenwandun@lixiang.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260429065831.1510858-1-chenwandun@lixiang.com> References: <20260429065831.1510858-1-chenwandun@lixiang.com> 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 Content-Type: text/plain; charset="utf-8" Save /memreserve/ entries from the FDT header into the reserved_mem array so they can be consumed as vmcore filtering metadata by kdump. /memreserve/ regions hold firmware or bootloader state that is not useful for kernel crash analysis, so saved /memreserve/ entries default to no_dump=3Dtrue and are tagged with name=3D"memreserve" so consumers can distinguish them from /reserved-memory/ child nodes. Some DTBs declare the same or overlapping range in both /memreserve/ and a /reserved-memory/ child. Commit b41328187629 ("of: fdt: Scan /memreserve/ last") describes one such case on Khadas Vim3 where the range is in /memreserve/ and also in a /reserved-memory/ child carrying no-map. The /reserved-memory/ node's attributes (no-map, reusable, linux,no-dump) are the explicit declaration and must win over the firmware default, fdt_reserved_mem_save_memreserve() therefore inherits no_dump from the overlapping /reserved-memory/ entry rather than silently applying no_dump=3Dtrue. Signed-off-by: Chen Wandun Tested-by: Zhao Meijing --- drivers/of/of_reserved_mem.c | 107 +++++++++++++++++++++++++++++------ 1 file changed, 91 insertions(+), 16 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index ac3d8b837d61..4b80420da2d2 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -252,6 +252,49 @@ static void __init __rmem_check_for_overlap(void) } } =20 +/** + * fdt_reserved_mem_save_memreserve() - save a /memreserve/ entry + * @base: base address + * @size: size + * + * Save a /memreserve/ range into reserved_mem[] with no_dump=3Dtrue + * as the firmware default. If the range overlaps a /reserved-memory/ + * child already saved in this pass, inherit that entry's no_dump so + * node-level attributes (no-map, reusable, linux,no-dump) win over + * the firmware default. + */ +static void __init fdt_reserved_mem_save_memreserve(phys_addr_t base, + phys_addr_t size) +{ + struct reserved_mem *rmem; + phys_addr_t end =3D base + size; + bool no_dump =3D true; + int i; + + for (i =3D 0; i < reserved_mem_count; i++) { + phys_addr_t r_base =3D reserved_mem[i].base; + phys_addr_t r_end =3D r_base + reserved_mem[i].size; + + if (base < r_end && end > r_base) { + no_dump =3D reserved_mem[i].no_dump; + break; + } + } + + if (reserved_mem_count =3D=3D total_reserved_mem_cnt) { + pr_err("not enough space for all defined regions.\n"); + return; + } + + rmem =3D &reserved_mem[reserved_mem_count]; + rmem->name =3D "memreserve"; + rmem->base =3D base; + rmem->size =3D size; + rmem->no_dump =3D no_dump; + + reserved_mem_count++; +} + /** * fdt_scan_reserved_mem_late() - Scan FDT and initialize remaining reserv= ed * memory regions. @@ -260,6 +303,9 @@ static void __init __rmem_check_for_overlap(void) * "static" reserved memory regions, that are defined using the "reg" * property. Each such region is then initialized with its specific init * function and stored in the global reserved_mem array. + * + * In addition, /memreserve/ entries from the FDT header are saved into + * the reserved_mem array so they can be consumed as vmcore metadata. */ void __init fdt_scan_reserved_mem_late(void) { @@ -270,28 +316,32 @@ void __init fdt_scan_reserved_mem_late(void) if (!fdt) return; =20 + /* + * fdt_scan_reserved_mem() has set total_reserved_mem_cnt to the + * total number of entries to be saved (reg-based + /memreserve/). + * If it is zero there is nothing to allocate, save or check. + */ + if (!total_reserved_mem_cnt) + return; + + /* + * Allocate up front: /memreserve/ saves below may run on any + * path and must write into a memblock-backed array, not the + * __initdata reserved_mem_array which is freed at free_initmem(). + */ + alloc_reserved_mem_array(); + node =3D fdt_path_offset(fdt, "/reserved-memory"); if (node < 0) { pr_info("Reserved memory: No reserved-memory node in the DT\n"); - return; + goto memreserve; } =20 if (__reserved_mem_check_root(node)) { pr_err("Reserved memory: unsupported node format, ignoring\n"); - return; + goto memreserve; } =20 - /* - * fdt_scan_reserved_mem() sets total_reserved_mem_cnt to the - * number of entries that need a slot in reserved_mem[]. If it is - * zero there is nothing to allocate or save. - */ - if (!total_reserved_mem_cnt) - return; - - /* Attempt dynamic allocation of a new reserved_mem array */ - alloc_reserved_mem_array(); - fdt_for_each_subnode(child, fdt, node) { const char *uname; int i, len; @@ -342,6 +392,18 @@ void __init fdt_scan_reserved_mem_late(void) =20 /* check for overlapping reserved regions */ __rmem_check_for_overlap(); + +memreserve: + /* Save /memreserve/ entries (independent of /reserved-memory) */ + for (int i =3D 0; ; i++) { + u64 mbase, msize; + + if (fdt_get_mem_rsv(fdt, i, &mbase, &msize)) + break; + if (!msize) + break; + fdt_reserved_mem_save_memreserve(mbase, msize); + } } =20 static int __init __reserved_mem_alloc_size(unsigned long node, const char= *uname); @@ -365,11 +427,11 @@ int __init fdt_scan_reserved_mem(void) =20 node =3D fdt_path_offset(fdt, "/reserved-memory"); if (node < 0) - return -ENODEV; + goto memreserve; =20 if (__reserved_mem_check_root(node) !=3D 0) { pr_err("Reserved memory: unsupported node format, ignoring\n"); - return -EINVAL; + goto memreserve; } =20 fdt_for_each_subnode(child, fdt, node) { @@ -406,8 +468,21 @@ int __init fdt_scan_reserved_mem(void) if (!err) count++; } + +memreserve: + /* Count /memreserve/ entries (independent of /reserved-memory) */ + for (int i =3D 0; ; i++) { + u64 base, size; + + if (fdt_get_mem_rsv(fdt, i, &base, &size)) + break; + if (!size) + break; + count++; + } + total_reserved_mem_cnt =3D count; - return 0; + return count ? 0 : -ENODEV; } =20 /* --=20 2.43.0 From nobody Tue Jun 16 20:38:23 2026 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A79D939E18E for ; Wed, 29 Apr 2026 06:59:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445995; cv=none; b=Av5YGk6knjastxp+XSX29UGZAhPQm1r3Uq/H3b+6EuBK4B+K0K9UW2BG1ld8hHzxFBnY+/avwIOOrjQn1s2YELom56N/Si6wELa+ZiFhKZfBj/6t5X8ej+xHOpt+hu7VeBpcurSU8jSfOZdSl8PsvkjzdYhVRRSVRDbNj0Rnkj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445995; c=relaxed/simple; bh=18l+fhXsr0FIoD6ma0m0oV997W8UN5RJPyEXvUsYpxc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OVoJJDmzU664u2nprIxDZiR9rkoyvkB+kmvlz0K3sZEtRlqHGypfQgm/yeIgGXQ8AW705O2sgJnINH1YSPipjv4S0Zl+owUwHnLfD2Fobf+qYh5+RVNmBPKKR+vcF3+bKGMb9EYJvFw1eOx7rhrL6Wmbu+siYmJLu+nRzTtUv5E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=N0FUFLmU; arc=none smtp.client-ip=209.85.215.196 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.b="N0FUFLmU" Received: by mail-pg1-f196.google.com with SMTP id 41be03b00d2f7-c797d5ad36bso4224775a12.2 for ; Tue, 28 Apr 2026 23:59:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777445993; x=1778050793; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nuWPT+XdRkD5quZoMJ/j/U0upX+W05bC344BAJoReBo=; b=N0FUFLmUFq1724uZhXCIfajRaCrixLbi29yI1wn5jLbn+aZ4T2/OXRnyBE4JL50ni0 q3VDybrntBzyVRmB44N6+H49LDijQcDRFT4jBM9VItuXw0ilfdchHz0gGI3NSbp+UTHS DodNpJalJuckbvyYlI4G6NRtHSzHqlXeRd8UYuh2UlM7zZPjyWu0A7NREe9j6FtpeG56 zS/9G+HeokUYYu+T81wZWgFsVtFKh1l5INKQlzl2qg3KnQkFFQ7BZzKJHdXWRBz0sgWE UjwKjoRZwMJaKZLckgsnXa1uvYodIdZUGoXdj0QCslugcPHmPdcAC8gvuQ/CFuCa2Kpj 52Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777445993; x=1778050793; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nuWPT+XdRkD5quZoMJ/j/U0upX+W05bC344BAJoReBo=; b=a+hOdEC9PAT0IkU9mJQo5YPt9tABFrBGt+Fcga7b8Ri2zJIY8eYRIcG2625/1K4+kp 840zqcjNCGQq/RT8xi5ymnzYkSE2s0sbKtDbGloaLahu7qVAu4D3OEKzTD2LgycN1r2u QAPDxU3rHoIeEUCfh/3LeOTw+cR6yB3OHKTtYV4cj22EYZd7nNVYHBSC3yXW2c6dNi18 x782c/NmpUZLJHvAgR1jD6VrDLBJWNmRD2S0cnsN6kdtl954nGqhGZXkwGEisPxkCz0T H2Lagu0TDtDGRoesmK4cEDUoksNfVODO5C2ohli9jCv9AzoLAhJpUfvUk1QIpu51EJAi zOKg== X-Forwarded-Encrypted: i=1; AFNElJ9YHfgLO/PZH4sDZxRsLPy9jF8XQgimrGkM1IE+97jXLKBi8QuvRr3XWzx5j6TlsjIqgBYYpA0S0icga/s=@vger.kernel.org X-Gm-Message-State: AOJu0YxtOkVWSN18YviKKcU2t83Bby2iIip28L96utWDqu24YUjuurmk W8HlZFDi/XyB9kPCm6mG8NC2oDzgRsWReYrZ5JlP6LqgivOSAkaDHr0Wc/1hrHgSY1Jjew6g X-Gm-Gg: AeBDiesh5iqflnYpfHZzizrmGqpOj+8JCWFyVTG9MzHJaYmDAwgRASlyFCPD2SHTb2i yyBBIdEcM2og3C8hHNTKzDJRrxDy3FrsTbCJ7C0nOyddgRTfh5Cc+GR/5WDXmlRoTkOGAYcaci4 u99s6X40oXjLI3aJprtLMwMy1iwUA+JeAgbAL2pYmG/KN0qB9eyEgyBGiIVGkqzuwhSdMHLcpKI MowxeXFdbSmqi9tre1nAPJW4ZfVSpdT1DEpHMb/3sKEO64lHuqpPkHVc5xWDlUFmieB2+JKCJKH W6fwKwZShqPx0FuL2k4l/HZSV/drEbPDG9vUuo1X6+sosoa8iWVmqYfASNU7EYYi7gdt/PAPXeD UFPaJbel9hQSHBoEhOztBTDnHhtpCDjcy7f6Uc/+vWkT7jfs6EA/SxMHtpIi+VRBW1P0I6Kp9F3 gwXJEQl5Jhy4SwWvZ+Pnu9zEwnuJvGoxXFLuRh1O9/ZCNqeQDdYipnAZf2jcs= X-Received: by 2002:a05:6a21:33a7:b0:3a2:cc5f:2187 with SMTP id adf61e73a8af0-3a3af541a19mr3029899637.28.1777445993005; Tue, 28 Apr 2026 23:59:53 -0700 (PDT) Received: from intel.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-834ed7eaf93sm1043146b3a.40.2026.04.28.23.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 23:59:52 -0700 (PDT) From: Chen Wandun X-Google-Original-From: Chen Wandun To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org Cc: akpm@linux-foundation.org, bhe@redhat.com, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, corbet@lwn.net, skhan@linuxfoundation.org, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, saravanak@kernel.org, chenwandun@lixiang.com, zhaomeijing@lixiang.com, everyzhao@126.com Subject: [PATCH 07/11] of: reserved_mem: add no-dump crash_mem exclusion helpers Date: Wed, 29 Apr 2026 14:58:27 +0800 Message-ID: <20260429065831.1510858-8-chenwandun@lixiang.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260429065831.1510858-1-chenwandun@lixiang.com> References: <20260429065831.1510858-1-chenwandun@lixiang.com> 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 Content-Type: text/plain; charset="utf-8" Provide two kdump-oriented helpers so that arch kexec_file code does not have to open-code the no-dump filtering loop: - of_reserved_mem_no_dump_nr_ranges() returns the number of reserved regions flagged with linux,no-dump. Each exclusion may split one existing crash_mem range into two, so callers use this count to pre-size their crash_mem allocation. - of_reserved_mem_exclude_no_dump() walks the reserved_mem[] array and calls crash_exclude_mem_range() for each no-dump region. Both helpers are guarded by CONFIG_KEXEC_FILE; empty inline stubs are provided for the !KEXEC_FILE case so architecture code can call them unconditionally. The consumers are added in the following arm64, riscv and loongarch patches in this series. Signed-off-by: Chen Wandun Tested-by: Zhao Meijing --- drivers/of/of_reserved_mem.c | 54 +++++++++++++++++++++++++++++++++ include/linux/of_reserved_mem.h | 15 +++++++++ 2 files changed, 69 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 4b80420da2d2..038056a6408a 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -27,6 +27,10 @@ =20 #include "of_private.h" =20 +#ifdef CONFIG_KEXEC_FILE +#include +#endif + static struct reserved_mem reserved_mem_array[MAX_RESERVED_REGIONS] __init= data; static struct reserved_mem *reserved_mem __refdata =3D reserved_mem_array; static int total_reserved_mem_cnt =3D MAX_RESERVED_REGIONS; @@ -916,6 +920,56 @@ struct reserved_mem *of_reserved_mem_lookup(struct dev= ice_node *np) } EXPORT_SYMBOL_GPL(of_reserved_mem_lookup); =20 +#ifdef CONFIG_KEXEC_FILE +/** + * of_reserved_mem_no_dump_nr_ranges() - count reserved regions flagged + * with the linux,no-dump property. + * + * Each such region may split an existing crash_mem range into two when + * it is excluded, so callers can use this count to pre-size their + * crash_mem allocation. + */ +unsigned int of_reserved_mem_no_dump_nr_ranges(void) +{ + unsigned int i, n =3D 0; + + for (i =3D 0; i < reserved_mem_count; i++) + if (reserved_mem[i].no_dump) + n++; + return n; +} + +/** + * of_reserved_mem_exclude_no_dump() - exclude no-dump reserved regions + * from a crash_mem list. + * @cmem: crash memory list to modify + * + * Walks the reserved_mem[] array and calls crash_exclude_mem_range() for + * every region with no_dump set. Intended to be called from arch kdump + * code when constructing the elfcorehdr. + * + * Returns 0 on success, or a negative error returned by + * crash_exclude_mem_range() on the first failure. + */ +int of_reserved_mem_exclude_no_dump(struct crash_mem *cmem) +{ + unsigned int i; + int ret; + + for (i =3D 0; i < reserved_mem_count; i++) { + struct reserved_mem *r =3D &reserved_mem[i]; + + if (!r->no_dump || !r->size) + continue; + ret =3D crash_exclude_mem_range(cmem, r->base, + r->base + r->size - 1); + if (ret) + return ret; + } + return 0; +} +#endif /* CONFIG_KEXEC_FILE */ + /** * of_reserved_mem_region_to_resource() - Get a reserved memory region as = a resource * @np: node containing 'memory-region' property diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_me= m.h index 29674f572673..cd0f88f29579 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -8,6 +8,7 @@ struct of_phandle_args; struct reserved_mem_ops; struct resource; +struct crash_mem; =20 struct reserved_mem { const char *name; @@ -94,6 +95,20 @@ static inline int of_reserved_mem_region_count(const str= uct device_node *np) } #endif =20 +#if defined(CONFIG_OF_RESERVED_MEM) && defined(CONFIG_KEXEC_FILE) +unsigned int of_reserved_mem_no_dump_nr_ranges(void); +int of_reserved_mem_exclude_no_dump(struct crash_mem *cmem); +#else +static inline unsigned int of_reserved_mem_no_dump_nr_ranges(void) +{ + return 0; +} +static inline int of_reserved_mem_exclude_no_dump(struct crash_mem *cmem) +{ + return 0; +} +#endif + /** * of_reserved_mem_device_init() - assign reserved memory region to given = device * @dev: Pointer to the device to configure --=20 2.43.0 From nobody Tue Jun 16 20:38:23 2026 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50C8739EF1E for ; Wed, 29 Apr 2026 07:00:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777446012; cv=none; b=LFOeUjJg3Ztgh8+B+j2a4BkRNRE7h2TtqE5QzCW00i+4Ow/cg8xegdsmz7OWgDu/v+uB2DrAgDgy595f82e8NThN0KaI3G6Xvv74zIYwmkRb6lCd570s5ZIcvtucki+QumD622kN0ZcSKhP9SQR4Y3eMDr5a/jDaZAvrNRK23Xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777446012; c=relaxed/simple; bh=19ChOYuQhKdK9qw9JWxQ3u37AolQaWA1Yu0JwsfzieU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OosOhxFb7kXGGvPWKuXoYlW9WlBRthrpJikG3QzVXhVBIOWOsr6JHQqjjFXlKbXANtFx5rp+nLjPTqhuq+f1afGDP8EEIC5KSyy8J9aipc9ZtDYV79U/XTcgkZ8VSpxyroV7g0W+V2/gvL56YjQGm64g/tiF4s+Rb+pp+QbqOfE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kxezeEF2; arc=none smtp.client-ip=209.85.210.195 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.b="kxezeEF2" Received: by mail-pf1-f195.google.com with SMTP id d2e1a72fcca58-82f8bf96b46so5860949b3a.2 for ; Wed, 29 Apr 2026 00:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777446003; x=1778050803; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ngtzchp/6x72pHggoOfcu8l1aVao/9O/WyChqA+UT9g=; b=kxezeEF2Wcb16iDVIeF7jvx9Z0fFU+MgS5t34N+hQoDuE2Y1WQNVTXlR4u8ni7ndmn OfeF63M3uxLF3GvtdCBMNrEcfUQO5IB5jD53CeTC0GZANOUJ5MhWUwnXi0wErfWQT8CW 95/hbQWB6hwk4z6NrK7Bt6NmqipK0p6L22UIqiu57KMOftWY8uhGcdUyAPHyaORoSn1U 0CNWLV20BczBRSA8kLGzdN31dDH7FZmAE5qZfoBmxOTYipsFe/d431rHseYv47gKuev7 gLbz8TQvVp5Gdwdq5bR1B5AjcZA7L2h6pKgReAVP7n/WeKefTcEwmTnmtv8CeobAvps8 7lfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777446003; x=1778050803; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ngtzchp/6x72pHggoOfcu8l1aVao/9O/WyChqA+UT9g=; b=ln5fL6g+RlIbfbznakJ0j1V06ACPs8IvNTOWhpj9MEDYJAt1SJ6kqGTruvEUNyikt8 InwS18j4Z0bLBuoFEZLvZJ9DnsnNquk1XFX0JW6xjnxRm8z79qXbncHsJUBGRHUwKWlM X3DBC9wNz6pmP9iqjf+Mv0f2PosxYho4uHt769tJ6cRokSY6AUBzz4VflKEFMPVPMIwg bRaPDVSm+GAX+5haxM6+4z/s7jDOiYZccEWxYVfexY8bVT6ypsJc+k9VcA3L8wOYtFI/ FrMioC4wrP8+o4pNsD9+KsqkvUabyJPLTMmMsjVo/d8gLsWp9RoX7Ghqy6TfmwNC7t76 +XdQ== X-Forwarded-Encrypted: i=1; AFNElJ+Yaj5DYxzoaQJ8oOXJdcbCw5VXmCVt9fZvhQ/xyhjLAaStP6lVhc1kZ70b6sVHnkcDy3jrMcYWG7IfGrg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6nxTrbmNGo7cF+j5tPCaFdViYkTkceV2MHGydZkfCAe7SXDoh yEMU+bf1Ra9y5AxO7q9OMSXkSX/I/AxEl7q+urHry3XK/eunD4q6ZCP9 X-Gm-Gg: AeBDievUSEGKZgQUXeT/0UuCA2PsARuXScY/lnJ5zAV3CpeHzrlsFbjoqbRqHxkN1fi tQNy1y25hd1POx8JjsX97bh/lEeMOh1MWgylHVtUtFEcxHwHupWoDiWUd3+t5j9VfGr7028rPox Zj8U/OCy6cqFho4e6NHmlwprHcYi7VlaPEtHH8yp/I5PiNYkp3xkBCR0Gpz2RrBnw8cS7d8uN/8 bjVny9U0Bs7g67oOd8ytkqU5zA5d3+++3ZO2f9xf2678pH0QwJKXOZWRiXzNFfPsyjYakUVBlxa 8xOWAUpM+JzskzIi43aCtfcjSjnbJhOHCpMpLt8KdM20skPimelWbgbxhD6RGXqzdN6FgrG02Sk afrsBADNtR7Ug20RuF6GX09TxCMP49UucnXt/iPa6WPnizg8iNpY2KgYBD1oqtYzOcdkGXRBWil 4F+KS3nxrCmUBxgf/1mmVT33CxEw1qj7HuTURzkWxe6PvEg9AE+BfP0MErtUs= X-Received: by 2002:a05:6a00:338e:b0:82f:6e7:152d with SMTP id d2e1a72fcca58-834ea569f84mr2491372b3a.21.1777446002842; Wed, 29 Apr 2026 00:00:02 -0700 (PDT) Received: from intel.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-834ed7eaf93sm1043146b3a.40.2026.04.28.23.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2026 00:00:02 -0700 (PDT) From: Chen Wandun X-Google-Original-From: Chen Wandun To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org Cc: akpm@linux-foundation.org, bhe@redhat.com, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, corbet@lwn.net, skhan@linuxfoundation.org, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, saravanak@kernel.org, chenwandun@lixiang.com, zhaomeijing@lixiang.com, everyzhao@126.com Subject: [PATCH 08/11] arm64: kdump: exclude no-dump reserved memory regions from vmcore Date: Wed, 29 Apr 2026 14:58:28 +0800 Message-ID: <20260429065831.1510858-9-chenwandun@lixiang.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260429065831.1510858-1-chenwandun@lixiang.com> References: <20260429065831.1510858-1-chenwandun@lixiang.com> 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 Content-Type: text/plain; charset="utf-8" Exclude reserved memory regions marked with the linux,no-dump property from the elfcorehdr PT_LOAD segments when preparing kdump vmcore. Device firmware memory regions (e.g., GPU, DSP, modem) reserved via the device tree typically contain data that is not useful for kernel crash analysis and can significantly increase vmcore size. By honoring the no_dump flag in the reserved_mem array, these regions are filtered out from the crash dump, resulting in smaller and more focused vmcore files. Use the common of_reserved_mem_exclude_no_dump() helper to perform the exclusion, and pre-size the crash_mem array via of_reserved_mem_no_dump_nr_ranges(). Signed-off-by: Chen Wandun Tested-by: Zhao Meijing --- arch/arm64/kernel/machine_kexec_file.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/mac= hine_kexec_file.c index e31fabed378a..7c9c38096c60 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,7 @@ static int prepare_elf_headers(void **addr, unsigned long= *sz) nr_ranges =3D 2; /* for exclusion of crashkernel region */ for_each_mem_range(i, &start, &end) nr_ranges++; + nr_ranges +=3D of_reserved_mem_no_dump_nr_ranges(); =20 cmem =3D kmalloc_flex(*cmem, ranges, nr_ranges); if (!cmem) @@ -75,6 +77,10 @@ static int prepare_elf_headers(void **addr, unsigned lon= g *sz) goto out; } =20 + ret =3D of_reserved_mem_exclude_no_dump(cmem); + if (ret) + goto out; + ret =3D crash_prepare_elf64_headers(cmem, true, addr, sz); =20 out: --=20 2.43.0 From nobody Tue Jun 16 20:38:23 2026 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 803133264FD for ; Wed, 29 Apr 2026 07:00:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777446019; cv=none; b=coKlDFQtffYGJtImUfh5tlH6Ik1yS4QfEslnjuGcrSuO1OVsOUts1snA6tcd1oX9gsbx0Hk/OE0getMFRHx3pnPP9LS2gVSlrV7nDnpvM8ZkPhyHFgxTFW6EmI4VcPEPQR5VEtmbjrlK0La/czk+QRM4QRIiZQv1xwoEs5jTLBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777446019; c=relaxed/simple; bh=MCjZ4wIsMlFVxfNUvNxM58nyFA/FtDG5OZK4rUoOlR4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lf/xsmf4vzNSnwY8Z3sLs2Y1pqMEFWTarA70bmMgA6urWEM5PDedj15hw5/zM3Jedoj2vdj4dqUTXPJa4tlS1hJuzWdjsTFIxVTzvkoAD/Om6FnepcVIxfpX/LPLe4rMd1ZzQ7zo8PDxkf6XbTFovQUeLQXfvPrZPagazra+4Qg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YXBQxBe4; arc=none smtp.client-ip=209.85.210.195 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.b="YXBQxBe4" Received: by mail-pf1-f195.google.com with SMTP id d2e1a72fcca58-82cf636dac8so5271964b3a.3 for ; Wed, 29 Apr 2026 00:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777446013; x=1778050813; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2+aKzcozrfPvAHDOI307L3sGfueBolTmIlF5K5tQEKM=; b=YXBQxBe4i0BSZlLvLJ7W5t+4HxfUh47g6LNLJ6t0i/09tOwPFH8Chn+8lbolryPglQ LIsG41UDT+ZIKYJLGj2/dS8+ngnNMvVs1hcpas72AkwTgXYuyBU5RzWIAi/8/L5FLBtG 3iNMtIRIIziNV6wJ3WxNYIqqsmMc7xG1OTkwM/L+ONqKnwycvp0mw3k5pyGtGKkYhsce BZxlMLo+AJpesg3LJvLADElq1dNbixlAVbPFhlWuyx0Zl5MHvpJJfJRRSIl4o3Ys2QEW JzHfKwgigoJIy7dDBOrbo4jTD19YQUfu5/ImnKG0d49iAXAOJ/qjDNUtMyiXj8z38nUq G7Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777446013; x=1778050813; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2+aKzcozrfPvAHDOI307L3sGfueBolTmIlF5K5tQEKM=; b=PecIvpZNmyNygOBhTUPUqQTRhq1M3VwrfQggcgpLd1NjTvy3oxRObdJes/SKf3y7gO JkLIuUitjK9Mc3OyUrk8pgdCrm+SD1WIeXaC4oKlvfyzkNYFCCkjunCLBtLckZ2CZUm3 5Ll7xCxq4jXA6H0bVyEqbqafC6Fv2qdvLYNOUskUsuw0wqrTFciOnbHJxIOX5ewxsHHn BeEaJ/u+WFfQYjEqbOXvOS5H9MlVCZpfNvMSqwdrE6tp8B6g018dnpiKrz2u4zuCkNm7 /QPwL95eFX2p+gO/bG+VNhvpVC7NGEdSd7c9dAu3pDOZlpGKorPITh4uaO81oAGqHyyp HBgA== X-Forwarded-Encrypted: i=1; AFNElJ/EyxbnKvER7GJc6hSJkVj4i4JgzTYwg8Y1wjXdOUOfEsefMO7SklQMsjf2dRF8TrbHRxwzHDMovQE+agY=@vger.kernel.org X-Gm-Message-State: AOJu0YxlYAZ6Doy1Gk1vRjHvR/aFTHkC7KkEk1CZgo2KnGGBM+hz0G97 Ulgr4OT/bpZFZSC1ycSLeMguT8ljm97xWikg8kwjgJucrQhShV+TrhK1 X-Gm-Gg: AeBDiet5fmW13v69vuh1DDiTYlmMdLPRNzLXTWAseACpEzJmOKNivsbwv9CAUiEOiCA 957jJ796sN3jdCb0x3XBLiupBUWXuXCsWDj7piKMUkcXWFlhDNowupZ0mIjqEDNG/OxQtHiJAVt kUMGDpA5N0z2/PslQQY+jiMOzuUbytwd0C9No+GlWvLtEBcUzE0r489r2IuCRMXtpNZccMOweev WRNZ4aJwq8UdKlMEpGQrLnCM0NxN+qQn1qihzQrCOs0tUtuWru3Xnekut4TZuyepF1ZWhV4LQz7 ar1KKDDz/JXnL0aSIsi06Kbu29aSe5Inu2buoMqLACJX6K4dqgVQvjQt4NhQ61lwBvTB49qXVGz 8TcDN3Q7EISqculHzBYJj94jUUudzip3AkapqVTaJKGEwHxE6q0RPw1yRVI5pBBFHQ9kzPGRWCm g4y3A3k3L8jjVHlZQVPCU4BTKQc51o4KxViqqDKvC7+K+bQSgu X-Received: by 2002:a05:6a00:995:b0:82c:9fe1:aa4d with SMTP id d2e1a72fcca58-834ddb2d0d8mr6649550b3a.13.1777446012829; Wed, 29 Apr 2026 00:00:12 -0700 (PDT) Received: from intel.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-834ed7eaf93sm1043146b3a.40.2026.04.29.00.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2026 00:00:12 -0700 (PDT) From: Chen Wandun X-Google-Original-From: Chen Wandun To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org Cc: akpm@linux-foundation.org, bhe@redhat.com, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, corbet@lwn.net, skhan@linuxfoundation.org, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, saravanak@kernel.org, chenwandun@lixiang.com, zhaomeijing@lixiang.com, everyzhao@126.com Subject: [PATCH 09/11] riscv: kdump: exclude no-dump reserved memory regions from vmcore Date: Wed, 29 Apr 2026 14:58:29 +0800 Message-ID: <20260429065831.1510858-10-chenwandun@lixiang.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260429065831.1510858-1-chenwandun@lixiang.com> References: <20260429065831.1510858-1-chenwandun@lixiang.com> 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 Content-Type: text/plain; charset="utf-8" Apply the same no-dump reserved memory filtering to RISC-V kdump as was done for arm64. Use of_reserved_mem_exclude_no_dump() to drop flagged regions from the elfcorehdr PT_LOAD segments, and of_reserved_mem_no_dump_nr_ranges() to pre-size the crash_mem array. Signed-off-by: Chen Wandun --- arch/riscv/kernel/machine_kexec_file.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/mac= hine_kexec_file.c index 54e2d9552e93..012885ac9b79 100644 --- a/arch/riscv/kernel/machine_kexec_file.c +++ b/arch/riscv/kernel/machine_kexec_file.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,7 @@ static int prepare_elf_headers(void **addr, unsigned long= *sz) =20 nr_ranges =3D 1; /* For exclusion of crashkernel region */ walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback); + nr_ranges +=3D of_reserved_mem_no_dump_nr_ranges(); =20 cmem =3D kmalloc_flex(*cmem, ranges, nr_ranges); if (!cmem) @@ -76,6 +78,8 @@ static int prepare_elf_headers(void **addr, unsigned long= *sz) =20 /* Exclude crashkernel region */ ret =3D crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + if (!ret) + ret =3D of_reserved_mem_exclude_no_dump(cmem); if (!ret) ret =3D crash_prepare_elf64_headers(cmem, true, addr, sz); =20 --=20 2.43.0 From nobody Tue Jun 16 20:38:23 2026 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86C2139EF2E for ; Wed, 29 Apr 2026 07:00:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.193 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777446025; cv=none; b=lfT2d8v9e9AzZELwLLuJNTo00FRApS0rJUw5IxGnPr6otvQr4kI4soqb6605B103WIRD9VyYbdBePp0XUZW21zli5VkXSzYDvO8usI02CxzzJ2OQUrAwTe4XhOrHx6clc38cXikIkqYhrFWu+3zUrSzB2S4Gz8iVciL25ssbJyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777446025; c=relaxed/simple; bh=t/lgmsImXNg9vJwTMjsNuwxZoj6hoQlo/Fb9w/nVF60=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WtKBQfJoazEPV/pPu8sqAepsqLWRwLzSLjxbB+7OALt3waigV+efZdj6KPqqg49icMOsvlomGrJP6CjwLR5GifhVzd/Fcy3OYXaT0gm35OL6C89YA+Cs/nFN9muSHkg+hv53TERGtupwt+OtVcZxRXhcRBpR9gOvmDbftkL8sVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gG1T0NpL; arc=none smtp.client-ip=209.85.210.193 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.b="gG1T0NpL" Received: by mail-pf1-f193.google.com with SMTP id d2e1a72fcca58-82f8893bff3so5739616b3a.2 for ; Wed, 29 Apr 2026 00:00:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777446023; x=1778050823; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R4Zhc8gGgRynhB3pjFfj0bHF1QgAjZt+4XAvOQyKioc=; b=gG1T0NpLo+2VjRA41OTFcRWlSDtBOXdxKrw6R1vd78sXDkBvh4Bzi+tXYQPpwBO4+a x9+LMi1DemL9t9dOzoXyrSe8RUom4rL1kKlGEFRrsiBFtJPXYgVLqiFaroflwNcb8zKL C5X2WX1LElTfwPUrQ9ehb9cdlIV2h/oDn/9kwkn4kggaW7AirQAoWTlcL1YgjmrEYidz IHvRzBUKHH/c2M0RwnYqpz+wWXEH8+OZb/az1BOVO3ok4kSBkeJ2TlaYAoZWX16grR4l JteRpOZNuYYhTQn6CYLmfQGB4spbMFsaDihguBdk75xgIzdj7+v0xU8ZhCQ4U+g6DBOC zOaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777446023; x=1778050823; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=R4Zhc8gGgRynhB3pjFfj0bHF1QgAjZt+4XAvOQyKioc=; b=qX29yRgBjpgg5VcMHtK32PlAzOsPkdDOOkzZY+928U4YB4UJF/8NUNWjs1UobWI1Pa TXR+eJp57/xICAWiz9zvr7BE7a1PzyME1z/aAfV4gc1Ybsb1M7yQyoR8cTlTPUXsm3yJ BsT4WBrwyMBBBlnqsTgGRTE/bscP0o+sMO9tHu1obfam1Gb1LpQNig7uwVCcuvDgC3t7 omUlklD1XFu2qnmqyOdneeky1XLk+/mBV/XJeAiN9GYe+TZ/wZqKHulIx/b7bwa+uOTP UGl9YkX1b1Eis/TXqbn68sytJwssxgCizqPb4pmVlwz0OjE+FfjPG7sjp8iH5J3TDBkb T/eQ== X-Forwarded-Encrypted: i=1; AFNElJ8bILcX5A0oIURKrQIts7VtzdNeay32+8tHXSCWanW3CKsCZ0zJBI4qAVdZ+ACFXGSRbfdEUG3aQ1+0wXc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6DkIMm+UGtxJbNhLu3wH5FzPUH41obcgZzuajU4tQ4TGkOQfZ 0/QHbTh7XYqBeg5w56eGwxxRySEcA/Geg1DTmKAFu41f/HUBT7r/epv3 X-Gm-Gg: AeBDieu9n4mzII+QWERte3ukvuNgLOjY1oUhZnR8EAdYDMZJWkLmT8Qs8AbE5FAytEZ fb80fUpAAfmctI4legkJZ7p4M1A2b+2kobKbYd4XUaQ7mllB6agXeSjyXYUU1NCibvJLVqSolFC Ppb6zd1E0LVogsJcfYCql0WfKecJtkF23/XVEeKu6A7Ug2or9O+I6MsemMBkKcqqFcNgQnr9zap it2IlvKnjskpt53G6quU+7wMfRiIsKSdCcqJeLudFhgy83cOo6ExgKeIJ7eGLtQ5KkfogXT83uv diAYm6bRt6Wm3CMUXxC2jjDtgvhvQqyJ1CPqkFU7VNMd7qOvy/Auhd1kNQQDLoBhrd5zLrZ4EnO u+F2CFifdSxoIfa8R+aZzrCmSZ7wDX1pzylTQblgF6CRyjIPbdGg5WINexVSH59XImwrPlx9syc qReqw3sme067vTT10mPj2ouFUzntpD6Z9mP6rKpiy36qlxH+TH X-Received: by 2002:aa7:88c9:0:b0:82f:b519:a5cb with SMTP id d2e1a72fcca58-834ddc50c40mr6750211b3a.37.1777446022861; Wed, 29 Apr 2026 00:00:22 -0700 (PDT) Received: from intel.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-834ed7eaf93sm1043146b3a.40.2026.04.29.00.00.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2026 00:00:22 -0700 (PDT) From: Chen Wandun X-Google-Original-From: Chen Wandun To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org Cc: akpm@linux-foundation.org, bhe@redhat.com, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, corbet@lwn.net, skhan@linuxfoundation.org, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, saravanak@kernel.org, chenwandun@lixiang.com, zhaomeijing@lixiang.com, everyzhao@126.com Subject: [PATCH 10/11] loongarch: kdump: exclude no-dump reserved memory regions from vmcore Date: Wed, 29 Apr 2026 14:58:30 +0800 Message-ID: <20260429065831.1510858-11-chenwandun@lixiang.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260429065831.1510858-1-chenwandun@lixiang.com> References: <20260429065831.1510858-1-chenwandun@lixiang.com> 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 Content-Type: text/plain; charset="utf-8" Apply the same no-dump reserved memory filtering to LoongArch kdump as was done for arm64. Use of_reserved_mem_exclude_no_dump() to drop flagged regions from the elfcorehdr PT_LOAD segments, and of_reserved_mem_no_dump_nr_ranges() to pre-size the crash_mem array. Signed-off-by: Chen Wandun --- arch/loongarch/kernel/machine_kexec_file.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/ke= rnel/machine_kexec_file.c index 5584b798ba46..742fb9affcb9 100644 --- a/arch/loongarch/kernel/machine_kexec_file.c +++ b/arch/loongarch/kernel/machine_kexec_file.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -67,6 +68,7 @@ static int prepare_elf_headers(void **addr, unsigned long= *sz) nr_ranges =3D 2; /* for exclusion of crashkernel region */ for_each_mem_range(i, &start, &end) nr_ranges++; + nr_ranges +=3D of_reserved_mem_no_dump_nr_ranges(); =20 cmem =3D kmalloc_flex(*cmem, ranges, nr_ranges); if (!cmem) @@ -91,6 +93,10 @@ static int prepare_elf_headers(void **addr, unsigned lon= g *sz) goto out; } =20 + ret =3D of_reserved_mem_exclude_no_dump(cmem); + if (ret < 0) + goto out; + ret =3D crash_prepare_elf64_headers(cmem, true, addr, sz); =20 out: --=20 2.43.0 From nobody Tue Jun 16 20:38:23 2026 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55E191A9F9B for ; Wed, 29 Apr 2026 07:00:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777446036; cv=none; b=cYyQZhSzDKUg52xatSdCTe+VZLDFOvh+KQs74E5viqyB1EKDq90sG1OILIWqbJraprmc3t+vH4vJigxoMYxPIz8JaG3dNgEqRFu7u9itWcOz0haOFwIfV0p0Fn4DG8O19aKZwMLreID3hSSSzI0vLD80+dvJ1Kebazo/9qDS5b8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777446036; c=relaxed/simple; bh=GlzyRXhW7BOFU2J58m5FlsVsMQJSPP8T+AYIfqJL/UM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lrEUDZbu1MT1o6hJn/kIflT5bPdQY5A3eSwsnr02RJ7TTVs4CQSti80/OcoMVKzdvQJWq0FEib6ms+O66/UCIC/ag5c2qIbmoaVa6WLjxC2RKFLzD9T1S6YVVTJtsjTSuJFbGqqmhz1wQ4EdA/fHsb/ESAEUQi4IjMTilEEolp4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MteDqc+N; arc=none smtp.client-ip=209.85.210.195 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.b="MteDqc+N" Received: by mail-pf1-f195.google.com with SMTP id d2e1a72fcca58-82f33d28c1dso6760197b3a.3 for ; Wed, 29 Apr 2026 00:00:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777446033; x=1778050833; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZWH07l9RWm03Oah+cccPH78bmOCX+VwKmCZ1Y6ji5X8=; b=MteDqc+Nzc+Y+LXHt9TzYJ2mp5ZYiSxukpwu3QPoJO+o0S6b7Zc9OO+TCF5qiv35mj cFQxvOoNVVNf3ROdWdO/OsBhNoaIP8GsolwA2wziNfG+ahtDiha5Ma1xGCFPSE3WPZz0 zwVFryPwXIqe6PJu9JIyYB/gwrE6s8hBBM6etlW5egAh/mHpFMv54Lv9oSM7rJQa4t2f iSUmVZZZL/YTcD3FoPNHJlzyz8R59m2OeIE1xNr42ktveu4LEaX7q8/R+ri03p9oRfPX t/eRV+nVysY7hyjhsJd/4btqeS8vHJL3qvIRrAQ/y3mOZDIYfZb6gM8i8RP4/4pG8TFO 9oZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777446033; x=1778050833; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ZWH07l9RWm03Oah+cccPH78bmOCX+VwKmCZ1Y6ji5X8=; b=llNvumnCg1JcXi/fpnDxRJOwK8ETCPa9qE8vszMImOZ30Rd0I5VWSNLDhsLRTdIl9P gbUaNKwbg6svd0MToMQdDT4hkX0CzLEYaolJVHQA8ylcWvpo33lcQOMC0QKcLbVH3dah bZnvBTSuXcLBy5p9EqXTP09Nb2f/xUmqIq5s9dr4Vt6RbpQidvhcPmPujd1RS5Pqc6Lx vMAba0rH9Juvpg5GmN6pfVsO8//Wd0R4OOK9TioMADT3STaphScp04HqAdCqvcIDwCNI r4BzeKwQz4AQfqZP/40gO2+CnoQpY4YhIqBVi1bKb9573wHfmpisBuhvv+pwzX0Sqljd XgSw== X-Forwarded-Encrypted: i=1; AFNElJ/q5zJbfgkGQ8S2NUJbdHCaav12KWsJnDhJMOI1cD+yplQBkit1Khusf37H6dlblFbDP3kT7dl9vG2g2Sc=@vger.kernel.org X-Gm-Message-State: AOJu0YxMq8bhQ18LtCQXGKFvDn1KUjywjAvB8a0wT7tiJqWevUBCcQ/g a928KrxnYxvwBoEX708DIzSZLy+Xbg3gsEVnWTk/zki3Vf0mDR1a2kMc X-Gm-Gg: AeBDietSnCW1TH1YGxqqTTri7vPQDidoPOEbR8NlTIx9RlDMzA2jnjAkWRCxZ0siy7P mfwoRZtA1raJ12WZYAVh+m3LtOCj+5QDCploVBQiPqW2ov/8yloXCOEzt82i2CJ+W3Iq3rxBDHo BZWrMdU2owvvKotW7pJ3gGNSjqpmcc8BVEZiaCbsHWncfO8W9CEelxcCxd1QrhojvcBPSOndWrA CJHCmcnqPW5iHIZINxvohdAcqm/kIkc6ybVFFAkzOxY7HJlZbwLgYmVyMonku3UOIqeDgCAyPTy fTfpJ1Nw2hQwfQQ0fPGavZQukhxDH/MwRR+WIy4LsTAh1zWcM2dGiFptb7Wfgg9c5W4EvW8a3lX A62/f9gWTM6h5CBWfIK97b3l/assBQE2w7KTWKQ0gUONdp6Uijcft7Kgs+BuYJwLJ9VTGlnBOFI fW25kHsVK2o86wLgBevQyx7QUdrZM6OFs6tIMr9x6rxvGwscOS X-Received: by 2002:a05:6a00:a14:b0:82f:9985:d4a1 with SMTP id d2e1a72fcca58-834ddc14f4emr6920159b3a.24.1777446032715; Wed, 29 Apr 2026 00:00:32 -0700 (PDT) Received: from intel.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-834ed7eaf93sm1043146b3a.40.2026.04.29.00.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2026 00:00:32 -0700 (PDT) From: Chen Wandun X-Google-Original-From: Chen Wandun To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org Cc: akpm@linux-foundation.org, bhe@redhat.com, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, corbet@lwn.net, skhan@linuxfoundation.org, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, saravanak@kernel.org, chenwandun@lixiang.com, zhaomeijing@lixiang.com, everyzhao@126.com Subject: [PATCH 11/11] Documentation: admin-guide: kdump: document linux,no-dump DT property Date: Wed, 29 Apr 2026 14:58:31 +0800 Message-ID: <20260429065831.1510858-12-chenwandun@lixiang.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260429065831.1510858-1-chenwandun@lixiang.com> References: <20260429065831.1510858-1-chenwandun@lixiang.com> 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 Content-Type: text/plain; charset="utf-8" Describe the new 'linux,no-dump' reserved-memory device tree property and the automatic exclusion of /memreserve/ entries from the kdump vmcore. The section covers: - The two mechanisms that exclude reserved memory from the vmcore (firmware /memreserve/ entries and linux,no-dump child nodes). - Intended use cases (firmware-owned GPU, DSP and modem carveouts). - Interaction with the existing 'no-map' and 'reusable' flags, with the silent-ignore precedence implemented by the kernel. - Architectures honouring the hint (arm64, riscv, loongarch). - An illustrative reserved-memory DTS snippet. The DT binding for the property itself is maintained in dt-schema. Signed-off-by: Chen Wandun --- Documentation/admin-guide/kdump/kdump.rst | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/Documentation/admin-guide/kdump/kdump.rst b/Documentation/admi= n-guide/kdump/kdump.rst index 7587caadbae1..c2246888e84d 100644 --- a/Documentation/admin-guide/kdump/kdump.rst +++ b/Documentation/admin-guide/kdump/kdump.rst @@ -600,6 +600,65 @@ with /sys/kernel/config/crash_dm_crypt_keys for setup, 3. After the dump-capture kerne get booted, restore the keys to user keyri= ng echo yes > /sys/kernel/crash_dm_crypt_keys/restore =20 +Excluding reserved memory regions from the vmcore (device tree) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +On architectures that boot from a device tree and use kexec_file for +kdump (arm64, riscv, loongarch), specific reserved memory regions can +be excluded from the ELF PT_LOAD segments of the crash dump. + +Two mechanisms contribute to the exclusion: + +1) /memreserve/ entries from the FDT header. + + These are firmware-level memory reservations with no associated + device tree node and therefore no driver-level description. Their + contents are typically firmware scratch areas that carry no value + for kernel crash analysis, so they are excluded from the vmcore + automatically. + +2) Reserved-memory nodes carrying the 'linux,no-dump' property. + + Device tree authors can add this boolean hint to any + /reserved-memory child node to request that the kernel skip that + region when constructing the elfcorehdr. This is intended for + firmware-owned carveouts such as GPU, DSP and modem memory, whose + contents tend to significantly inflate the vmcore without aiding + kernel crash analysis. + + Example:: + + reserved-memory { + #address-cells =3D <2>; + #size-cells =3D <2>; + ranges; + + gpu_fw@a0000000 { + reg =3D <0x0 0xa0000000 0x0 0x01000000>; + no-map; + linux,no-dump; + }; + + modem_fw@b0000000 { + reg =3D <0x0 0xb0000000 0x0 0x02000000>; + linux,no-dump; + }; + }; + +Interaction with other reserved-memory flags: + +- 'no-map': the region is already absent from the kernel linear map, + so it does not appear in the vmcore to begin with. Combining + 'linux,no-dump' with 'no-map' is harmless but redundant. + +- 'reusable': the region is actively used by the kernel for movable + page allocations (CMA) and its contents are relevant to crash + analysis. 'linux,no-dump' is silently ignored on a reusable region. + +The property is an operating-system hint; DTBs that do not set it +retain the legacy behaviour (all memory is dumped). Architectures +that do not honour the hint simply ignore it. + Contact =3D=3D=3D=3D=3D=3D=3D =20 --=20 2.43.0