From nobody Mon Sep 28 19:23:02 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 238BC420475 for ; Tue, 18 Aug 2026 09:24:33 +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=1787045075; cv=none; b=HZKmoPzjvD/8ODSWMPn+2M+EVL1C/kcWaojMdKTnItVkhzkqX8A926W1Vgg0P/8FIXbyoWnVm529DfskTVr/nM4mfrgRCzGdlNG38oIME9twoY0jf6O+eavk28KHB/7es4YjjGxUIVQUgcWPEoMubnV1BXxvMgTeDORZLx8285k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045075; c=relaxed/simple; bh=AZW+JtHL/apWBr9muRBcy0BI7L3aVGKCtqBv1W/MCmY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lAv1gv5B6Xeo+xIJk7px3I9eVth0O4EKLT4zS1ouXtYBDLcMsU2tkBxPlyhDT9Hu9IquReDMkGND8NuN0Gbkj4+jfeq8pIP0wJBPb1X7sK46dtlN88asHGE4y7O8GM8Q+6ta6dg+s3tKrYZ+XS90vJDr9vw2v0TqLE7idPz9Q0Q= 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=byvUX5uq; 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="byvUX5uq" Received: by mail-pf1-f194.google.com with SMTP id d2e1a72fcca58-84e84a6c4bfso836827b3a.1 for ; Tue, 18 Aug 2026 02:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787045073; x=1787649873; 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:content-type; bh=edFBVCDZ8uahtaafghiqDdA2JkU9nFhvYVeD5bTaUSM=; b=byvUX5uqglOdLjj5+Ljn7KLUIABn+/ZCWa7ZYq5RKwULuPuazalYc4mLq2hUyu9wWz re7pticr6XXEbNJ7jUsPBINwryhDeKtMtJcvcjfAYkXwFKlccXDXYw18WvmJqZpODfZ8 AQChpsVx3dhCc8aQDWT36eGDRcNSqjHUvWWsgekQCtUhGE70+8oiDI1ljwt2c86qJr5C cX57xrTCy2zrIZt0IcC0yoSso+GKaHMl+JJZL+YXC1rzIZJebe2mOErcDsuqVMFv7L/E djwlxFswF4AduUTlXVEeDOfYetZVkl89n6PLLUCb8bTJcJz9uYQzmFO8MO/XP+5MCtt2 lBfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787045073; x=1787649873; 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:content-type; bh=edFBVCDZ8uahtaafghiqDdA2JkU9nFhvYVeD5bTaUSM=; b=JQu9ecQrSoM4CntJAGCRadhc6dsvN/KXoNhP+7TwxdRjvfvcsRdpeKcmLGy7oedyOe mM0fZUJzj4b8RMPfh+1K5ZIMJnND+hU2QCAH0ky/B9s1yRDBESedHgSZkdTmyrUo/5hC M7RGoLERZLjWdhURJADtHGcLoaH7AELj7U5+3hzPF7+1858WATtWn8z7CHQM8nCVCooM r/HGoTe0OwlkqzBe6ivHY/xoXOX36gB9OC0F6efZFHPgOb+3H3R1ICMcqsOfAvZeDz6r maM0PWEx63tFOYeSG2MU3NyEbfkzVu3b5Uk29KzmRneYeZKSCKXkQkf+Ieq1hRzQLT45 1Uiw== X-Forwarded-Encrypted: i=1; AHgh+RoAO/L3GxD6wiFsbsmLcaN00y94atLMGbucc/12rCoadyp7pRWtslzdEgt5qYMXaAWI8g/PP1wWqU/WqK0=@vger.kernel.org X-Gm-Message-State: AOJu0YxCq4Hlmkzz1vdPOUzMSzlo4c3T/OFxeuvBiqexT8P0OoMCZeCf enblt1GjJjARpRHhAPQQiuPXtnWkWC2LPbIYo+EcX5tRekh0ONxtAdfw X-Gm-Gg: AR+sD12X6t83wMw+BW9Ea+KTo0ZOg8TceL2+1LCWDPT4jXHrQZ1YTQbl/9LS67cdg/V Wt8Ylf6qEoaj+desBHOig87/Cez9wH1uEyg/wiQhKEepD7XoXXScLsH/0D0h+ZEdU+PVw37tggO HamF9EvN9JRHjkbY8WkENzinfiIyrnOeLH2whMl0rMyf5Ni882O3nNCNEYx0cAEwtOX9ZTcfK/O qIjdnKTqsDh2db4kwG8N2Ex8AeXuwvl2dj+PvLlKc5TqmBNUK+Bgno5AdaJR+Tu2Wm6EVhIt2vr aDzsVrjA9hMMWmARGx6UWvUpGwg6GrIeqCAbwkzlYmmhTaYazwzF8qfJA4xFzmkk/vPMau/LtzP VorVOWYnoJF9TX8Rp+NCiCKs/YrdBAmKfaba1gzLWPMitzzCXdsXYviJHMHMsSAd4fLb/gkzoUA 52azvwpsLdntpUS+ZH/qOTaj9aJAaYl4g0SlmR/4S5fwMMngp4ArTk3b0cN6PC+P8thrpBmnjm X-Received: by 2002:a05:6a00:3a13:b0:84e:ea49:8899 with SMTP id d2e1a72fcca58-851bc2cc6b9mr4442181b3a.6.1787045073210; Tue, 18 Aug 2026 02:24:33 -0700 (PDT) Received: from intel.company.local ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cc13c036c50sm1855975a12.26.2026.08.18.02.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 02:24:32 -0700 (PDT) From: Wandun Chen To: robh@kernel.org, saravanak@kernel.org, rppt@kernel.org, m.szyprowski@samsung.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: akpm@linux-foundation.org Subject: [PATCH v2 1/5] of: reserved_mem: skip init for regions whose early reservation failed Date: Tue, 18 Aug 2026 17:24:16 +0800 Message-ID: <20260818092420.2859026-2-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260818092420.2859026-1-chenwandun1@gmail.com> References: <20260818092420.2859026-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wandun Chen __reserved_mem_reserve_reg() discards the error from early_init_dt_reserve_memory() and returns 0 unconditionally, so the caller counts the node in total_reserved_mem_cnt and the late scan initializes it without checking whether the early reservation actually succeeded. A region whose reservation failed is then handed to a device assuming the memory is protected. Propagate the error so failed reservations are no longer counted, and record the failed nodes so fdt_scan_reserved_mem_late() can skip them. Recording the failed nodes explicitly is necessary because fdt_scan_reserved_mem_late() rescans the DT independently. It cannot tell from memblock whether early reservation succeeded. The failed-node array is bounded by MAX_RESERVED_REGIONS, the number of static regions is not bounded by it, so on overflow the extra nodes fall back to being initialized, which is the current behavior. Fixes: 8a6e02d0c00e ("of: reserved_mem: Restructure how the reserved memory= regions are processed") Signed-off-by: Wandun Chen --- drivers/of/of_reserved_mem.c | 65 ++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 8c9d6395d6a3..c6e73d710ee1 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -32,6 +32,30 @@ static struct reserved_mem *reserved_mem __refdata =3D r= eserved_mem_array; static int total_reserved_mem_cnt =3D MAX_RESERVED_REGIONS; static int reserved_mem_count; =20 +static int reserve_failed_nodes[MAX_RESERVED_REGIONS] __initdata; +static int reserve_failed_nodes_cnt __initdata; + +static bool __init reserved_mem_node_reserve_failed(int node) +{ + int i; + + for (i =3D 0; i < reserve_failed_nodes_cnt; i++) + if (reserve_failed_nodes[i] =3D=3D node) + return true; + return false; +} + +static bool __init record_reserve_failed_node(int node, const char *uname) +{ + if (reserve_failed_nodes_cnt =3D=3D MAX_RESERVED_REGIONS) { + pr_err("too many failed regions, '%s' reservation failed\n", uname); + return false; + } + + reserve_failed_nodes[reserve_failed_nodes_cnt++] =3D node; + return true; +} + static int __init early_init_dt_alloc_reserved_memory_arch(phys_addr_t siz= e, phys_addr_t align, phys_addr_t start, phys_addr_t end, bool nomap, phys_addr_t *res_base) @@ -141,7 +165,8 @@ static int __init early_init_dt_reserve_memory(phys_add= r_t base, * first entry in 'reg' property */ static int __init __reserved_mem_reserve_reg(unsigned long node, - const char *uname) + const char *uname, + bool *should_record_failed_node) { phys_addr_t base, size; int len, err; @@ -149,6 +174,8 @@ static int __init __reserved_mem_reserve_reg(unsigned l= ong node, bool nomap; u64 b, s; =20 + *should_record_failed_node =3D false; + prop =3D of_flat_dt_get_addr_size_prop(node, "reg", &len); if (!prop || !len) return -ENOENT; @@ -167,14 +194,20 @@ static int __init __reserved_mem_reserve_reg(unsigned= long node, base =3D b; size =3D s; =20 - if (size && early_init_dt_reserve_memory(base, size, nomap) =3D=3D 0) { - fdt_fixup_reserved_mem_node(node, base, size); - pr_debug("Reserved memory: reserved region for node '%s': base %pa, size= %lu MiB\n", - uname, &base, (unsigned long)(size / SZ_1M)); - } else { + if (!size) + return -EINVAL; + + err =3D early_init_dt_reserve_memory(base, size, nomap); + if (err) { + *should_record_failed_node =3D true; pr_err("Reserved memory: failed to reserve memory for node '%s': base %p= a, size %lu MiB\n", uname, &base, (unsigned long)(size / SZ_1M)); + return err; } + + fdt_fixup_reserved_mem_node(node, base, size); + pr_debug("Reserved memory: reserved region for node '%s': base %pa, size = %lu MiB\n", + uname, &base, (unsigned long)(size / SZ_1M)); return 0; } =20 @@ -306,10 +339,14 @@ void __init fdt_scan_reserved_mem_late(void) base =3D b; size =3D s; =20 - if (size) { - uname =3D fdt_get_name(fdt, child, NULL); - fdt_init_reserved_mem_node(child, uname, base, size); - } + if (!size) + continue; + + if (reserved_mem_node_reserve_failed(child)) + continue; + + uname =3D fdt_get_name(fdt, child, NULL); + fdt_init_reserved_mem_node(child, uname, base, size); } =20 /* check for overlapping reserved regions */ @@ -349,6 +386,7 @@ int __init fdt_scan_reserved_mem(void) =20 fdt_for_each_subnode(child, fdt, node) { const char *uname; + bool should_record_failed_node; int err; =20 if (!of_fdt_device_is_available(fdt, child)) @@ -356,9 +394,14 @@ int __init fdt_scan_reserved_mem(void) =20 uname =3D fdt_get_name(fdt, child, NULL); =20 - err =3D __reserved_mem_reserve_reg(child, uname); + err =3D __reserved_mem_reserve_reg(child, uname, + &should_record_failed_node); if (!err) count++; + else if (should_record_failed_node && + !record_reserve_failed_node(child, uname)) + /* Keep a slot for the untracked node's late initialization. */ + count++; =20 /* * Save the nodes for the dynamically-placed regions --=20 2.43.0 From nobody Mon Sep 28 19:23:02 2026 Received: from mail-pz2-f1.google.com (mail-pz2-f1.google.com [74.125.228.1]) (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 73D9D445ADD for ; Tue, 18 Aug 2026 09:24:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045079; cv=none; b=ZAHy0Cj/jAFYF/X7DN79qRBeLgzW5xivuOf2IO9KfYrGjYe3AM9iDJO12Up0AbmHh3NOJc/wnJDh1IShFJdVx0q0w7IADYW191K/90Xm4InYw4DdOVGzclRW9JCqj9sLM18WH2lOZel/rfz/z2tidNvaZasr4n3psb4lis2CVRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045079; c=relaxed/simple; bh=6o3jag8MYPkjyjui0T+mJJonk+syY88nEjjzZbh4dYA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tRcj0dhsz+G0gDceBmo2kbS1XKkv2/NpzWwuOTvvxrXKCAKqW5ga2ZBnXTDA9b/HJ5c1tkGIcnHctkNJPGIHhfUjgWPQEY96ogPnbQqtofq2uHvSfH0XP7qId60rE64w+qpL0v5Qzz0yBfnWTSsKLMFB1PKyUdu8c7QbPx8gIIU= 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=jXvLdx3Y; arc=none smtp.client-ip=74.125.228.1 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="jXvLdx3Y" Received: by mail-pz2-f1.google.com with SMTP id 41be03b00d2f7-cbb8ebaca74so1907730a12.1 for ; Tue, 18 Aug 2026 02:24:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787045078; x=1787649878; 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:content-type; bh=xWMBqkj73rVQAMFA4LqK7WvxQ0Lo75WvfMJxyxluc60=; b=jXvLdx3Ygy3gGuZct/hiTQ/9F1MI3uDnGLb2UTvVw4Y0uC369O3rggyVlp8z770ckZ tITK6ThRpO3u5SHA23aItcyvgnUzH0qyCJc/HBfjErOxOkTPQ691almA3LIwUp+RDyny X1ZMNfIAV72JdwxqFsbp4ltfxldSK29HxRVIX4OxZJtZugwJCEjft58qUB8clMTI0LM+ SnEUE6cxaScqxBHKQn5UWD06bIp106oa7oKNnt1hOd2cyvGwQkoD3gzsz1BVGUX7Zsqc sNJeIe2d3Z1eW+q1BcUw0SnpQ9wrS1XrRi/CIi4GKVpUPUnlXXyqtfXUkUC5JvIiIlxZ jW0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787045078; x=1787649878; 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:content-type; bh=xWMBqkj73rVQAMFA4LqK7WvxQ0Lo75WvfMJxyxluc60=; b=mKizM/72fLMywVurcMadgSlBYCGoRpohsSmcyyZ/Zv5Ld6vhoSOeb0exBHk33+1lsY /eFB2MwmBiAnadYK9FNMne4Qzu11gmKC9q0yDV55cvTD4GL48bCR9JwBFJz0OYkzDdi4 r2kNFlTc8uB8SIWn9PZe1bOc+hX6k7tkr9ywNsGK6TOsBJ5VZ0ahbTd4e1Md+jwjc3s/ zzpodDuueF55qnmq+tNIlpkNXp0PUj8Qyz/79yyg8Yyt8AvNfEb+dfPm22kOFJYYrQNl xgvjqTaBsqzINd7DZH4cLwikXjEbw+ExcjnU7WWOyezR+JRN3tcyAZOP6cs4zB5Bzs6G jgyQ== X-Forwarded-Encrypted: i=1; AHgh+RrSMSUhd/3DMhnHgWaOYPM7IVOOaxD5RekTePaLT7eyo1XK6YlREZMFUMTZPd8ddB3+LK70qLVjNsR7Mag=@vger.kernel.org X-Gm-Message-State: AOJu0Ywu0tiqshMGD/DQ6E/56l68SmGf/Slgh0TRAjfv8biTlg8HQ4Z1 j0nPgRHCwwP4CP1fR190PovpMysw/IvSl6N6GOJZn/9FLGs+hZQhVoLQ X-Gm-Gg: AR+sD12Lxyo8xqiPazIbZnREABScEXXp7tCAfG8a3c2N2YhAmZVfjcHLsfvs4jn0kZG y2yir1zzi6s3d972HN7N+qxk0MX2Fea+IpTnFNg3WB1lPJ0EgkNg9ZSDyJ8YUVLUJznA+fSzDR7 2CynYGPZB8Nik1JmQrbhOLkjfaSwsOsvRaNhCzfS5lfCPEYvup0fbtKdqVoMM2mSBZ5q6EciW30 qypyqt/GAyLatmygjJGvJty4Y3RvusXOj3BOwI0ONIM3YNvDy8UQaNb42iUlzOerCHmyMUDwLMU e4TqW2hm7j1VoRgJ9Wc20f6XF54cFZSEw91XY2vPSmQ0eS9bthuPFknFK/h4/R1cB82pYigAfOg q87xNwgLc5wIs0QTDyMNXuPCyqAtyTTUbuZQeLuKACEMFs4WHWZiP7PIEZC9dmSy6JBggPjjy0D Cde3dmcXi3BPM9kQUHa0YJWYMzaqM81s9LsNJ376Uh9+aF+2NltIOk6TObNCmGvm0C9NeDshTg X-Received: by 2002:a05:6a00:1149:b0:847:7ffd:ce35 with SMTP id d2e1a72fcca58-851b87eaa83mr7838506b3a.8.1787045077737; Tue, 18 Aug 2026 02:24:37 -0700 (PDT) Received: from intel.company.local ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cc13c036c50sm1855975a12.26.2026.08.18.02.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 02:24:37 -0700 (PDT) From: Wandun Chen To: robh@kernel.org, saravanak@kernel.org, rppt@kernel.org, m.szyprowski@samsung.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: akpm@linux-foundation.org Subject: [PATCH v2 2/5] of: reserved_mem: reject static regions overlapping no-map memory Date: Tue, 18 Aug 2026 17:24:17 +0800 Message-ID: <20260818092420.2859026-3-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260818092420.2859026-1-chenwandun1@gmail.com> References: <20260818092420.2859026-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wandun Chen Static no-map reserved-memory regions are marked in memblock.memory rather than memblock.reserved. So the reservation overlap check does not reject a static region that overlaps existing no-map memory. Both regions can then be initialized and hand the same physical memory to different reserved-memory drivers. So reject a static region that overlaps existing no-map memory. Sashiko found this issue in [1]. Fixes: 86588296acbf ("fdt: Properly handle "no-map" field in the memory reg= ion") Signed-off-by: Wandun Chen Link: https://sashiko.dev/#/message/20260814084718.29C341F000E9%40smtp.kern= el.org [1] Acked-by: Marek Szyprowski --- drivers/of/of_reserved_mem.c | 3 ++- include/linux/memblock.h | 1 + mm/memblock.c | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index c6e73d710ee1..9fb2e4c29443 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -152,7 +152,8 @@ static int __init early_init_dt_reserve_memory(phys_add= r_t base, * if the region isn't memory as it won't be mapped. */ if (memblock_overlaps_region(&memblock.memory, base, size) && - memblock_is_region_reserved(base, size)) + (memblock_is_region_reserved(base, size) || + memblock_overlaps_nomap(base, size))) return -EBUSY; =20 return memblock_mark_nomap(base, size); diff --git a/include/linux/memblock.h b/include/linux/memblock.h index d62db9e776cf..27d68fbb3157 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -148,6 +148,7 @@ int memblock_physmem_add(phys_addr_t base, phys_addr_t = size); void memblock_trim_memory(phys_addr_t align); unsigned long memblock_addrs_overlap(phys_addr_t base1, phys_addr_t size1, phys_addr_t base2, phys_addr_t size2); +bool memblock_overlaps_nomap(phys_addr_t base, phys_addr_t size); bool memblock_overlaps_region(struct memblock_type *type, phys_addr_t base, phys_addr_t size); bool memblock_validate_numa_coverage(unsigned long threshold_bytes); diff --git a/mm/memblock.c b/mm/memblock.c index 9ce86349a29f..4cabfe365ac4 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -202,6 +202,20 @@ memblock_addrs_overlap(phys_addr_t base1, phys_addr_t = size1, phys_addr_t base2, return ((base1 < (base2 + size2)) && (base2 < (base1 + size1))); } =20 +bool __init memblock_overlaps_nomap(phys_addr_t base, phys_addr_t size) +{ + struct memblock_region *region; + + memblock_cap_size(base, &size); + for_each_mem_region(region) { + if (memblock_is_nomap(region) && + memblock_addrs_overlap(base, size, region->base, region->size)) + return true; + } + + return false; +} + bool __init_memblock memblock_overlaps_region(struct memblock_type *type, phys_addr_t base, phys_addr_t size) { --=20 2.43.0 From nobody Mon Sep 28 19:23:02 2026 Received: from mail-pj2-f8.google.com (mail-pj2-f8.google.com [74.125.227.136]) (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 147A2445ADD for ; Tue, 18 Aug 2026 09:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.136 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045084; cv=none; b=t7qyv1dfFx7hVF8NODitUZNsKfcOM/S9MR6yHr0L3WpUIhXvtqtCXA83zInCpz4aMfI782+ZbZhkPtu9yEZ1+cxQ3454xiv/N3pnQe5G4fTvi5wPLU2m+ynIVDT9wvjVtDGaXaqasyBufzmzMr/dj6olI1yXsJ37w1t2Asy4z5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045084; c=relaxed/simple; bh=HFaffslyAq00MYKaOo8bzVRYd+um+ZFrtT7zrTOOu9U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rZe7/OVlTC8k05L3JiVz1Dp6PeedHlQsQz7ByAN90987EWUn2Nj69iKDJoHLKcP22lxkiIYeS9+OPUfdgyVohEEJEoILyjm4XkNi+a8qy3PIAHlX5Kbcvm2PhPdIv0ZkMqgnsmrQZP1FOms98FSsSpIKcaVYprhVtlY+aIhb7ic= 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=BIrbF8lR; arc=none smtp.client-ip=74.125.227.136 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="BIrbF8lR" Received: by mail-pj2-f8.google.com with SMTP id d9443c01a7336-2d313798bf8so29747045ad.0 for ; Tue, 18 Aug 2026 02:24:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787045082; x=1787649882; 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:content-type; bh=vgrzyPwZN4L7nqoNRJuB9G+jUytRArcpJTaiildA9bE=; b=BIrbF8lRamH1grc8/bNpXeeYnlJxpNeszUbFqHRk6JcRHV3S20AbFK5H0DqlY7QR3H 3vAFXf8WgRLUdPT4j1ZAPdufbilFhXm5/JCCRy5Rc6l+KytIycWC7/Pu07uKUlPJXkRx wJvpGf5OqIKGd0vrSN8hOJei7IvL4DXsssvJtoDxe6CssxffK9HflGzBxn5sVIJYx9bI yQnr0wWISMvg39bEPcAI/yp/amQ9Plh5KosgvBPZpYjHQjrc34R2k7LWYJckOqH9xTE7 dsRg/cErCZBfhRZUeg+RdAZrBIs4djaUcw1pb42rYeykvNRxmnp9f/Nk/bzk+zEcXFLt ubjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787045082; x=1787649882; 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:content-type; bh=vgrzyPwZN4L7nqoNRJuB9G+jUytRArcpJTaiildA9bE=; b=kDl8Nr9vg3GEq8QDDTnzF2JxwbY8nxr9MoCFw01lciEOo90o4kGXON0hX29eepg5e6 Lf8Ic0O1vHkHfHg00UaFHv//jS7BxaIUyg2+H5FlfxmIIoWhS8jUSpFo98QR1z7DD0C3 M2XB5FQjxnUiifiyM/j+c9CkaX7Ugm32jBbi1VCFHdUbZZ4xpo/8tqHFRYQE0llyty37 ThtUtCrgRV4tYNZO0euDMfrtTweF3DRR36wT1oYETj3aZZ8UrcthY+c5quLATiROFQFY 4mi0IBa7MPG3Odb+P1MC7hgon1n5+v3cijuqLQgYcTVZlrzunX9424OCMRTGFboGRDbe WG9Q== X-Forwarded-Encrypted: i=1; AHgh+RpfrP7rP9qtlpGR8f/6bZCKzaAn5sVLaJOaoy9MB38X6Jm0mC3CGpvuguvTI1V7Bi7X54UD5YWXaqWvQKI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2xoD3Dc6utJN5IV2noB6KnssF9uGi+paP5eEMprZqxuzDxHez h/vJlclvrpJTUjKHmZUPL9m3nPb4rqzfFHX0n2EPeNDdlqYSL2RBQYX1 X-Gm-Gg: AR+sD12BhtA95+f2cpMahyrYTxZrynB/pH8fQVvs2GNIxE0fHddWYped19HzdwvfSO8 hL47BfzQ2yKMWBbpFvmM1sjwpTa1cvdAsLTjFshwOcqc3I5q/lXMxlaRx88QBvfXhdGBd7f58cP Lf1lFdwx5V5TqcOvG2S8rRc4TGq8bEoE1C4vmUfKhF7BurniUMDp9xUM7irEZwM9ZGv32x8EDTs 7bbBLVT+D4kNJcCy4QbB3Lp3Yl6obYAaTK59cgLjUWS6Kaq7xriwTNvZ3DRK8Jkp23ydJ0DbgYd x3uagHTXEE+HK4z1qfO6hdId8Fz89MpjX4s7RiNt9kB9FeOrtNLze0h+aEUQPzC8OTNi7Li0vvn jSpCTUK/CnXEwa4YuZe1Wqx7vGXqp3wpcRh0xsNqvFfv+DOBZdRhE0GwQU8XzPDPh/Xp7VuNTr+ m6K4lCctK7t9CBgUp8DaOcK3R0P9bHXmfyqJGFRV6g43L2cV3UVJriR7BruC7/VRyiTQ7RIZX7 X-Received: by 2002:a05:6a20:4321:b0:398:7ed3:a001 with SMTP id adf61e73a8af0-3cc71af5f13mr34124324637.2.1787045082245; Tue, 18 Aug 2026 02:24:42 -0700 (PDT) Received: from intel.company.local ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cc13c036c50sm1855975a12.26.2026.08.18.02.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 02:24:41 -0700 (PDT) From: Wandun Chen To: robh@kernel.org, saravanak@kernel.org, rppt@kernel.org, m.szyprowski@samsung.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: akpm@linux-foundation.org Subject: [PATCH v2 3/5] of: reserved_mem: reject statically placed regions overlapping existing reservations Date: Tue, 18 Aug 2026 17:24:18 +0800 Message-ID: <20260818092420.2859026-4-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260818092420.2859026-1-chenwandun1@gmail.com> References: <20260818092420.2859026-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wandun Chen memblock_reserve() permits overlapping reservations, so a statically placed region whose 'reg' overlaps an existing one is accepted. When initialization of a statically placed reserved-memory region overlapping an existing reservation fails, memblock_phys_free() returns the overlap to the buddy allocator, corrupting that memory. Reject the overlap up front. Dynamically allocated regions are unaffected, as they are allocated from free memory and so cannot overlap an existing reservation. Sashiko found this issue in [1]. Fixes: d0b8ed47e83a ("of: reserved_mem: fix reserve memory leak") Signed-off-by: Wandun Chen Link: https://sashiko.dev/#/message/20260806100605.2C2C01F000E9%40smtp.kern= el.org [1] Acked-by: Marek Szyprowski --- drivers/of/of_reserved_mem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 9fb2e4c29443..767ef702392e 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -158,6 +158,11 @@ static int __init early_init_dt_reserve_memory(phys_ad= dr_t base, =20 return memblock_mark_nomap(base, size); } + + if (memblock_is_region_reserved(base, size) || + memblock_overlaps_nomap(base, size)) + return -EBUSY; + return memblock_reserve(base, size); } =20 --=20 2.43.0 From nobody Mon Sep 28 19:23:02 2026 Received: from mail-pz2-f0.google.com (mail-pz2-f0.google.com [74.125.228.0]) (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 651CB445ADD for ; Tue, 18 Aug 2026 09:24:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.0 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045088; cv=none; b=UTY9cq+939sRFVfZLtS86k9KeWCgQl1dRsl9XYfUKzesTJxN59Hmzc22wBu/AS2s/jtexx7f+nenpMeV5nJoQo7miQNiDiLoUC+vinnFaCbEYG0RAVuBKyriGPD6+fgQYGsRu/RKV82KidWneFrMd7NnIf58XcSrfzBgW6VHuQ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045088; c=relaxed/simple; bh=Nctdu3GRXgFPqdYGuio1jU8JKaStTeEWL2DxwYXyFUk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sVpKlU4l8qZdAHJVQJB8gfWJOFBXgOXS1cC+W46PCs+VEW3p5aHs5mzTcqic4K4uCIdTYLJp4eaipP+Bi5xlzht5MsfV75fjAYp3tWgJkQYhguy1dGtbJ0vuUEHTG5MAqrp9hmZKysvsTN5zsh36kL1fyrhwqsmeFhyMK9EHjkk= 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=doABhiRp; arc=none smtp.client-ip=74.125.228.0 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="doABhiRp" Received: by mail-pz2-f0.google.com with SMTP id 41be03b00d2f7-c96739a46acso2400999a12.1 for ; Tue, 18 Aug 2026 02:24:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787045087; x=1787649887; 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:content-type; bh=vXih3fn/TdgHOmckkY8kxI7AN967ZoqRDpC349A4Z68=; b=doABhiRpLQz7lEFbaJzHnclIWxz1RI+wF/JvjU2l/1HAjS9Tde/9zzuwX3Bok+CZgI czvrDkPN2q0PnM040X/98DdiD3DDfw2R/0q7zEZpuYSGxm7LPq4BLzyLHUBO1UrzoLC/ 50zW+bmyPXULpLorGvN9xwYVtlexbeMM+rX47ECWqIcntGhVu5x9gM7uHt284P5XXwU+ aqtofyJBB1BKbX+vkfxBrJ2ddQAhGpc9Jdcdz2yKJ6C/PrCwcG9JsZrsX4GKg+ZOovBu etUPI/iDLV7VohQOzp7P6ZM31a/7YISGDjPFlsKTdBNbv5rxYlpVwQAWOW9B3TeRk6gJ Kujg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787045087; x=1787649887; 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:content-type; bh=vXih3fn/TdgHOmckkY8kxI7AN967ZoqRDpC349A4Z68=; b=EvZACpJTgE5tXO9NomVGhbnUI2Mkva9/pMIMlMxykZfx0uVoYzCwBwQyklhDbKE/O9 ixtf9SjQ1D1THIkCPuVRzRi6APMTa5mSvemHvZ4soPwJvo4HGbcdZhEgP+7KHO+XvGP0 +W5tLWKq2pWxrLoM+ffbrKN9D8mRpSTs9uX+oF5pRjbItveymB+EyW24F7I6Kb6bncJF p5NgHZXmt5a6QGFIHr5PI7mcoBuGO0CWrqgQ9Aj/YnG+Px3mHbWkgs3MBFORZHjFcUdE YumZx+Mwl8EQLImYmYr3HMVvm6PL1NKKl2wKAl0be21Jv0gzyqMkXiFuPFdejkubcCQh Leow== X-Forwarded-Encrypted: i=1; AHgh+RrmH94N4IwaGuzY2ep++/33xffzCiXdZcKHoHr+I5OxigmCp2kq+2/mF80mjW2hoCqaw2UMsYe2o7rnRzM=@vger.kernel.org X-Gm-Message-State: AOJu0YweQYZqlWQKev1IObD9hN2Hpa1Rtp8HVec6V43YzlWZh3Sxy5BG 0txt+ofQIxsDoOEyCsz1PUy4+VNzCSS5aMXDuwVzn1LiUECxRmuTBS3e X-Gm-Gg: AR+sD10Eo4B1lni9DHkJ5mmTJ2J/IbDPLiClqJ07PNxACbG0wW/g4U3g8ImyJRgNKXL 6G28G23AVwh3w3P/6FFjuEFE7toq6a8yyI0j4JpMO8oeKBjpcA1HqjLClXcT13CLsRE2UAru+Km HmIF4mNoRnyHXet0pAt7/2Zm3QJWI4vGSwDig6wp+PxYo0Q0fZM+vwQFKSH3YUM1nTsZx+Xu8Bk Mxb7H+HvFQZmnyS98+grMIjCNympEiJPitLaSEJcVADYTCq6jsVkHYGB5zcQQ2jwmcBlbWZFNs0 PwXm1mmZ8ZxJ/vARpmErRsIqtcbz8xDEm4pCbGL+YXg/xJLyP4kd8y7kHNAw0uk9B/wGEq31CLZ VW17is9J45CrHCwTuFHIr7/V1qffhZQTY408e/V+RjzRoE2YFKLgprV29Z6zLypEBLHbWUszfpF C9JUfQQwu9jjMiUg6F+6cKCsZBHyTpTd6ehpSeyV9tPs9sO0pMKZ7ymA1uUBLfhYe3kDrKh8dQ X-Received: by 2002:a05:6a21:4685:b0:3c3:875d:705e with SMTP id adf61e73a8af0-3ccda96659cmr10292610637.19.1787045086651; Tue, 18 Aug 2026 02:24:46 -0700 (PDT) Received: from intel.company.local ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cc13c036c50sm1855975a12.26.2026.08.18.02.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 02:24:46 -0700 (PDT) From: Wandun Chen To: robh@kernel.org, saravanak@kernel.org, rppt@kernel.org, m.szyprowski@samsung.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: akpm@linux-foundation.org Subject: [PATCH v2 4/5] of: reserved_mem: release dynamically allocated no-map region on init failure Date: Tue, 18 Aug 2026 17:24:19 +0800 Message-ID: <20260818092420.2859026-5-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260818092420.2859026-1-chenwandun1@gmail.com> References: <20260818092420.2859026-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wandun Chen Dynamically reserved-memory regions are added to memblock.reserved by memblock_phys_alloc_range() during __reserved_mem_alloc_size(). When a reserved-memory region's driver initialization fails, fdt_init_reserved_mem_node() cleans up the reservation. For no-map regions it only calls memblock_clear_nomap(), leaving the range in memblock.reserved and unavailable for normal memory use. Fix it by freeing the region on init failure when it was dynamically allocated. Sashiko found this issue in [1]. Fixes: 7b25995f5319 ("of: of_reserved_mem: mark nomap memory instead of rem= oving") Signed-off-by: Wandun Chen Link: https://sashiko.dev/#/message/20260806100605.2C2C01F000E9%40smtp.kern= el.org [1] Acked-by: Marek Szyprowski --- drivers/of/of_reserved_mem.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 767ef702392e..ac5db19dcc93 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -136,7 +136,8 @@ static int __init alloc_reserved_mem_array(void) } =20 static void fdt_init_reserved_mem_node(unsigned long node, const char *una= me, - phys_addr_t base, phys_addr_t size); + phys_addr_t base, phys_addr_t size, + bool dynamic); static int fdt_validate_reserved_mem_node(unsigned long node, phys_addr_t *align); static int fdt_fixup_reserved_mem_node(unsigned long node, @@ -352,7 +353,7 @@ void __init fdt_scan_reserved_mem_late(void) continue; =20 uname =3D fdt_get_name(fdt, child, NULL); - fdt_init_reserved_mem_node(child, uname, base, size); + fdt_init_reserved_mem_node(child, uname, base, size, false); } =20 /* check for overlapping reserved regions */ @@ -567,7 +568,7 @@ static int __init __reserved_mem_alloc_size(unsigned lo= ng node, const char *unam } =20 fdt_fixup_reserved_mem_node(node, base, size); - fdt_init_reserved_mem_node(node, uname, base, size); + fdt_init_reserved_mem_node(node, uname, base, size, true); =20 return 0; } @@ -676,13 +677,15 @@ static int __init __reserved_mem_init_node(struct res= erved_mem *rmem, * @uname: name of the reserved memory node * @base: base address of the reserved memory region * @size: size of the reserved memory region + * @dynamic: whether the region was dynamically allocated * * This function calls the region-specific initialization function for a * reserved memory region and saves all region-specific data to the * reserved_mem array to allow of_reserved_mem_lookup() to find it. */ static void __init fdt_init_reserved_mem_node(unsigned long node, const ch= ar *uname, - phys_addr_t base, phys_addr_t size) + phys_addr_t base, phys_addr_t size, + bool dynamic) { int err =3D 0; bool nomap; @@ -708,7 +711,8 @@ static void __init fdt_init_reserved_mem_node(unsigned = long node, const char *un =20 if (nomap) memblock_clear_nomap(rmem->base, rmem->size); - else + + if (dynamic || !nomap) memblock_phys_free(rmem->base, rmem->size); return; } else { --=20 2.43.0 From nobody Mon Sep 28 19:23:02 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 BC30A448B8B for ; Tue, 18 Aug 2026 09:24:51 +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=1787045093; cv=none; b=K3fEfNMxlCgK7K0sb+CIFm1i4330vbJemkqNXPknEOZN1iuilpP3Ts2AH0ekY/MDr/FSmMJ508QkdpZXwPlNiUbxECTMp5u/a0tjw8GL/WtSRqXhPCY8QT7qajlh8289Gmu+X82ZlgTz+b/UEgh6fH4Z+PmiW+Z42ceQKTR0+kw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045093; c=relaxed/simple; bh=yd+K1Uo+/8kr+Dz5o7vzi3RnXV8sT8wqf8KMY1gJ5nE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cylhzf8MyXwDHGFdKXijKoc7XpLvw92OjbfipodJHfcv6d1Ohas3dWBcYj4sEVXpq4eF0mWplk1mJDytKh7Pi/CG+rKCRQYIE+Q3WQa3SyMPnusMw/EE5rwtzWlPpH8K4Ryd9bMvnYXZMTYuAs1QnykKER+pESYgqteEdoCk6y0= 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=kKNTPXat; 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="kKNTPXat" Received: by mail-pf1-f194.google.com with SMTP id d2e1a72fcca58-8486ac3f347so754880b3a.1 for ; Tue, 18 Aug 2026 02:24:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787045091; x=1787649891; 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:content-type; bh=9v55YoKHog4sYMlVLVJ4eD+dGmtcRqfX1CYvFqTElOI=; b=kKNTPXatPMA8T/u0DD8DNTVkGcHEZzvSw6MVrktfPdMWZDfgIVg9hG+zmf1pGN7fRV FH/12BLUlquHjFqKZ4tdo4CE2JWovuQLIUI2oy/xT77/tUbBaOTXgSnRKFx2p2f5rLdK h8ZO/KPvg2YhdX+XCgs/vnE0PBi2udPwpVX6xGiqCrsFfmb7XRv1SUtxtkq+y3ra4cDa 5s+wpcCqaw2+MIBMR08/vE0ANMUw4DG5fnejs5SKQVg5T0R+QIKpKHz8sc3bvMiDeT65 Tk7cnee7sb7mpDA206Q0IvQ85iJIjKU+34o3wuQkwQ1iEoSEeYlWqYY7tXF51zKYPITo wq1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787045091; x=1787649891; 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:content-type; bh=9v55YoKHog4sYMlVLVJ4eD+dGmtcRqfX1CYvFqTElOI=; b=lTuxTYSt0XyHa4nX5kA9Lk+P+T9gME5d5by0NJkHtSnddGkXiK4BYi2dASgXaTX+Cn f4q+OZXmJapm4az6ry33+vJoxM06q4v62tX3BEuVp/g2s4hoQTl/mN4//Y53Eg4ENpNI aPUlATAK83yisEqyLVNdvwbbAloWgUqaPkt58R2cIUkL1IHlena4Ti7E5lFTfDsmniKh ikQMYLgyJQfWg10kjCYif5Vnk9RVbB+AQQa7w8v/ay4sO/Uhv2Mi2NwEDAU9hvjoGA64 yiVng11BtBJ38dAGJt6FK1ObORDIJd+2kyWYJqmppZfiGiSHY2BQQGydINyB0LyOGdc0 kXSQ== X-Forwarded-Encrypted: i=1; AHgh+RrCUdPfjDvzXlC7LFEofaO2N3stQa3PbAp8XVlZ1xVTH5Ig1yfIIF0th65CfQhn+x/W4UKnG/Ix+ql2lMQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxgYAxcKXGVzuaaAPzpS9LDbjl+IMZVTK778Klzp+sf3Z1Dz838 JkhC5Vr/r7qUgKEbQr0bIilUxm0vLpio2xw9Ns2pi9QHMS3OmM05s5za X-Gm-Gg: AR+sD13wxuoqcI79Mf6KmQ7EvHBJdI4KOyYLTh2JKRLoYeeuOYkYXKp7ddi+ECzmBdn C8m2sWdB4y7Slb33Dqif6TP1VqgAAg5rt+0rFP8I+7OoJi2QorI7SFvgEDSKaxEHxnBfN7qSQxs mib6DzWPVx+ToCAqn70zlFD3qlXhP5elLiQZrbVAOBmGHaBGk6YIwFY7PpVirrjgg9d8X7xVZds klretezIfVm0jObvZLR7e9/jq20tSW/Q1Ydppl4lPufEGC0E44tmdGsMS2mHjDq1Q3nARDMN9bp b5aEsPSI0pH46Md8/aSqf+uQmMcI2P9wQFz78LM+WUv622zYBXGgGf7X809HuWfU3HYtH6MO9uj qvFtH8Mss/JynO5hR/3L4tWeDwVeljykq9i//UyP8URnlhOWF48IOwmLaT3wwe/ACX+0ImkTQ2e o25y7AQWS0CrE5aM9EZG4nL7aEfjFQn8Gabxmimf/GgTvJ5CVBEKnKBitaiNwgD6jJX9210AABb CxprArOQ5I= X-Received: by 2002:a05:6a00:1d96:b0:836:6f2e:bb6d with SMTP id d2e1a72fcca58-851bc3cce42mr4379051b3a.14.1787045091103; Tue, 18 Aug 2026 02:24:51 -0700 (PDT) Received: from intel.company.local ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cc13c036c50sm1855975a12.26.2026.08.18.02.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 02:24:50 -0700 (PDT) From: Wandun Chen To: robh@kernel.org, saravanak@kernel.org, rppt@kernel.org, m.szyprowski@samsung.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: akpm@linux-foundation.org Subject: [PATCH v2 5/5] of: reserved_mem: retain static no-map memory on init failure Date: Tue, 18 Aug 2026 17:24:20 +0800 Message-ID: <20260818092420.2859026-6-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260818092420.2859026-1-chenwandun1@gmail.com> References: <20260818092420.2859026-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wandun Chen Static no-map reserved-memory regions are initialized after paging_init(). If initialization fails, MEMBLOCK_NOMAP would be cleared, and the memory is available to the buddy allocator even though it was excluded from the kernel linear mapping. Clear MEMBLOCK_NOMAP only for dynamically allocated regions, which are initialized before paging_init() and can safely be made available to the kernel linear mapping. Sashiko found this issue in [1]. Fixes: 8a6e02d0c00e ("of: reserved_mem: Restructure how the reserved memory= regions are processed") Signed-off-by: Wandun Chen Link: https://sashiko.dev/#/message/20260814090305.4C8741F00A3D%40smtp.kern= el.org [1] Acked-by: Marek Szyprowski --- drivers/of/of_reserved_mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index ac5db19dcc93..0090fa86dd10 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -709,7 +709,7 @@ static void __init fdt_init_reserved_mem_node(unsigned = long node, const char *un pr_info("node %s compatible matching fail\n", rmem->name); rmem->name =3D NULL; =20 - if (nomap) + if (dynamic && nomap) memblock_clear_nomap(rmem->base, rmem->size); =20 if (dynamic || !nomap) --=20 2.43.0