From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.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 E5E10383C88 for ; Wed, 27 May 2026 03:30:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779852628; cv=none; b=EbHpVTrQU3PyC2iE+8CkaMByhQOsBG+tQGJVoPoGJPFsR0di8H/6dLDmuYlbxXT/2IPdWi5Dkn9aURW/jUB0yU9KCA4SQ7E0FTk4QuUPMSOA/HnIz9btvcnlkOvyuMolwC+mjlKB1gmuiz45p00NDqZKxacByQdgpyqXSfS9Ry4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779852628; c=relaxed/simple; bh=7kxqwwsFAI12NVUnaU7kq1LIiiUSTsB+7iEGWDm4OPM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a+RgNGN6o1b+N0FuVZt1vqaOP398cS94seIb0hHIQr5jO+04PJAFK82xlrw1pyjIFv7rZkJebUuQv63O6luOLcsL0LJ1aGcL4WQkOMnesKkmDnUZhIfRh3N6adhYgj5oNfRsaDKsQtNCl0ASIjzSBcdFvuQhpFNoSTowk1thEFg= 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=CCs43JIu; arc=none smtp.client-ip=209.85.215.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="CCs43JIu" Received: by mail-pg1-f194.google.com with SMTP id 41be03b00d2f7-c80148ae949so4531220a12.2 for ; Tue, 26 May 2026 20:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779852625; x=1780457425; 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=DuujAuF8eXBWdShhG/kW229CX67XgkUB6V+YnX45VpI=; b=CCs43JIu/zzgWir7yga/+29+T9mgm7bHzC5JN8RCZp+jKgYRqPtE2Ew1VWaCKNb4mQ jNE+cxLLDZxxl44pkoNwdGuCd7q2hdGKIUffbo5lmaWdFeXSHXFKREZWZ6s/M5ppBzZT r+saj2cURBfPfz+wO+h84Fmvj8MnK5b0WaAkwb3FzHNpDaCGex2lc2jVQIe8XrErHqRy ha61Zm3nM1lczQT0wG20BK+JVakYkCktty2c3X3VsojSqO/Bi6yu1Baz9n7Hc5OuYwB1 yv2iWlKFkQ0k9AOQp1nRK+m1u3kmC7+6lnJQkAQoB2tARviXsTlZE1ZTZP/+yuQ/VaUD msBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779852625; x=1780457425; 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=DuujAuF8eXBWdShhG/kW229CX67XgkUB6V+YnX45VpI=; b=kSiv+hAsl0agdAhD3Olsf5T+VBFA7Tew6qNexb67+QVietN0POhjuWHp6/ihX6AZTp 0p7fivaCWL7xMVp5OcI8OxgyuaFSN9RPeGdrMe4vGfXI0q/NjtXg0SrrOejbhFVExTU5 VHZbt7Cf4BiyR2U+LF83kNNqlImlN1bBF+DyfjEeH/1T6l0oZ9VFkj7rYtKeViAXLi3G fJi0fasdp6Oyc8zc3XQuOYL1EuDAGKz9BqmoBd30cdDSi6hxa3b/6KnPn5xjVKJYXb3z e4jRWa6haCXoBAvov9FEKn05SVW2hSyX5grFA3TEr8p5C2XNAyA6NdETFyGK2LHXH964 xcOA== X-Forwarded-Encrypted: i=1; AFNElJ8hcNNXVfhUwBKYf+JZDUsmn2SQ7HoQJ4dNOx7p3B+Ccj0MEzG+Q3POXE9y5txY17KH9jmsAtX1Qwu3XqM=@vger.kernel.org X-Gm-Message-State: AOJu0YzQLV987x99gU9SXGJi1hwgRK6vHaB8/4cSxxIdxrmjCNbcsSm5 59roreFgrME1rUuedk3KNX8QZyp9BaaWUfPgRTcEjktc2XUTu7isKXzY X-Gm-Gg: Acq92OEbwvZYxEmgcCu8D9K4FfiSsKr8y6pp1KH14WkpNBpY+Rckaf0vOY/Xs4zIbar UDwxxwtPNhGIOsrIgSfzg7pSS72qEjow7o8wAMYdTTFxSELUUyhLT6LNJjLRN7kwz8Z2BygtPgx /Q+yFXwcgG/aeA+R0HMsQOZY0t39LEP8yO6IXumTGg5m/6girLVOp+E0T20ht56df6AEi2hEfVF jCivAbzcq7JDjjSX6VCEgwRrgK/JEbsgG0q06Eg85NZcgz7pfXTUl6FBRLioUmxOiWo5VUzwtmc yK+3Zzr8uAwIiBshB4uOspNanmay5kikAKDNZs1D+Y2g1MfJP7haiE1CykR9W8sLjyrHsWh6R+D iYicBwLjU2SZ2913B1go5vf1pH4jfDBypyAhJmISHeZdJG2v6gM1NOcfkIXgwwGa7+8aTZsXNw0 0G2yxxNhO24l7KR2yBKAS7q1fK3d/WhBr+g7+H X-Received: by 2002:a05:6a21:6d81:b0:3a3:17f8:bedd with SMTP id adf61e73a8af0-3b328cc257bmr21442620637.17.1779852624627; Tue, 26 May 2026 20:30:24 -0700 (PDT) Received: from intel.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-841d7307596sm749688b3a.59.2026.05.26.20.30.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 20:30:24 -0700 (PDT) From: Wandun Chen To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, kexec@lists.infradead.org, iommu@lists.linux.dev, zhaomeijing@lixiang.com Cc: catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, robh@kernel.org, saravanak@kernel.org, akpm@linux-foundation.org, bhe@redhat.com, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, m.szyprowski@samsung.com, robin.murphy@arm.com, quic_obabatun@quicinc.com Subject: [PATCH v3 05/11] of: reserved_mem: split alloc_reserved_mem_array() from fdt_scan_reserved_mem_late() Date: Wed, 27 May 2026 11:29:11 +0800 Message-ID: <20260527032917.3385849-6-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260527032917.3385849-1-chenwandun1@gmail.com> References: <20260527032917.3385849-1-chenwandun1@gmail.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 From: Wandun Chen Prepare for storing /memreserve/ entries in the reserved_mem array. alloc_reserved_mem_array is skipped if the device tree lacks a /reserved-memory node, pointer 'reserved_mem' continues to reference the reserved_mem_array which lives in __initdata, storing /memreserve/ entries into reserved_mem_array would result in metadata loss, and an out-of-bounds memory access will occur if the device tree contains more than MAX_RESERVED_REGIONS /memreserve/ entries. So split alloc_reserved_mem_array() from fdt_scan_reserved_mem_late(), and call alloc_reserved_mem_array() whether or not there is a /reserved-memory node. No functional change. The actual /memreserve/ population is added in a follow-up patch. Signed-off-by: Wandun Chen --- drivers/of/fdt.c | 7 +++++-- drivers/of/of_private.h | 1 + drivers/of/of_reserved_mem.c | 6 +----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 82f7327c59ea..83a2a474831e 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1284,8 +1284,11 @@ void __init unflatten_device_tree(void) { void *fdt = initial_boot_params; - /* Save the statically-placed regions in the reserved_mem array */ - fdt_scan_reserved_mem_late(); + /* Attempt dynamic allocation of a new reserved_mem array */ + if (fdt && alloc_reserved_mem_array()) { + /* Save the statically-placed regions in the reserved_mem array */ + fdt_scan_reserved_mem_late(); + } /* Populate an empty root node when bootloader doesn't provide one */ if (!fdt) { diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 0ae16da066e2..50e5a533e059 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -187,6 +187,7 @@ static inline struct device_node *__of_get_dma_parent(const struct device_node * int fdt_scan_reserved_mem(void); void __init fdt_scan_reserved_mem_late(void); +bool __init alloc_reserved_mem_array(void); bool of_fdt_device_is_available(const void *blob, unsigned long node); diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 05defc91e901..888dcb6bdce5 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -69,7 +69,7 @@ static int __init early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, * the initial static array is copied over to this new array and * the new array is used from this point on. */ -static bool __init alloc_reserved_mem_array(void) +bool __init alloc_reserved_mem_array(void) { struct reserved_mem *new_array; size_t alloc_size, copy_size, memset_size; @@ -272,10 +272,6 @@ void __init fdt_scan_reserved_mem_late(void) return; } - /* Attempt dynamic allocation of a new reserved_mem array */ - if (!alloc_reserved_mem_array()) - return; - if (__reserved_mem_check_root(node)) { pr_err("Reserved memory: unsupported node format, ignoring\n"); return; -- 2.43.0