From mboxrd@z Thu Jan 1 00:00:00 1970 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: 8bit 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; if (!of_fdt_device_is_available(fdt, child)) @@ -301,6 +302,7 @@ void __init fdt_scan_reserved_mem_late(void) if (ret && ret != -ENODEV) continue; + nomap = of_get_flat_dt_prop(child, "no-map", NULL) != NULL; uname = fdt_get_name(fdt, child, NULL); for (i = 0; i < len; i++) { u64 b, s; @@ -310,8 +312,23 @@ void __init fdt_scan_reserved_mem_late(void) base = b; size = s; - 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); } } -- 2.43.0