From nobody Thu Sep 24 20:36:52 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 C4E063EC802 for ; Sun, 20 Sep 2026 09:29:10 +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=1789896552; cv=none; b=KfRxNUUfanGKPPsaTroYA/CvQIzg4EEIc4CT4qp9vGxcV/HJI5zuel8Xsk0geuoNei4/1RQm6HsrkAtyYZN11FRMk0uxXr/59uPxuXXEL+eaSAirPPTR0EKHKVi5UN5b2C3in8+3JUxBJ8e/j7BDhoK9Mg+fcXfO2CYsIeoRwac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789896552; c=relaxed/simple; bh=HLAKvhJkzr2wMQTL4lMwFebMpdVfGJZuNPiX3c2LAO4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=svpjZhXTwK5oi/GDwIAj/XmHtq/0bbYAYT6UB9vh65jN5fD23g8oFN44AAj4UoC/U0J5nSALjOxn7zX+S3fJl5jU/PJ6/wtMfAFvlWnvz7TmsIzL5Q0tGdwbtwdcV3Ykel1QSGRcDRx8mrqPa02a4RrcS0v94pNvVHJDQL24tcM= 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=RwmiRQ3o; 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="RwmiRQ3o" Received: by mail-pj2-f8.google.com with SMTP id 98e67ed59e1d1-398b9f722abso1158477a91.0 for ; Sun, 20 Sep 2026 02:29:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789896550; x=1790501350; 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=Hr//weXOOHxuEsChSdCH6E1epplNkMkMoIIsD/MpGSM=; b=RwmiRQ3oS+nI+MC/PGwh2+OfOmGABNSPzqt4f6i+RlD9znKWwRMJhBlw3dR8KXm5w4 Yr0cPtrp1MOQVhF+qNIY3ajZzWKjjX+eUpGawvxpF26iTzb0zmDYKwHwaiuoQWvRbSVy xxMbmHteTL1u/ZAEVBaV1K8NtpfJWbJT5TZSHMnmaJDEyBU/t8RFyNPRUVIQFocKObhu T+ov6XhLivsJSpo8T5DwTt94/aZxEtEeDzcYx9CqifPzvwFzFxVa9n0Wq9QOV5tDbfVc noF5/tJ0Bi0tcd4oJwt/zajaRDQp2fHJjYZucOgPMlz8k9O+FIcH9CAO2ZOx6lJ8mPD3 uYXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789896550; x=1790501350; 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=Hr//weXOOHxuEsChSdCH6E1epplNkMkMoIIsD/MpGSM=; b=WBiEXrFd9YqDm6JVG1ueYNYIpo7tfSPKTEan34lUPUpCIfuGblVoqGpFrRWum0chZt fLxs2NvNNVbCKFO4c1CeaST1hNL9trR+NzfskgiGFLnDw6A9jqLwGpP7o5eHJJP4CQBf 9AYiZYZA92D7qQlWfHIWJqjYj5TFNFra3RdTUtQbiesCo6TRr5Qr+UOvE+9ohcwQNuy9 EbjCiNHQrZqyDkN0zUdN2UK21msUkwZRUBbguyhgSI8oS8/EyQy+IsppUd52TTNGDFfT I/hjqzEm8/NFTyU6pdzmj/HoLNwT54VOjTySbhjGAnvkgi9w77Mc31d4aapbwWQuFynL RNHQ== X-Forwarded-Encrypted: i=1; AKwUvBz87+oELqz5+q26EyrqQzZsDbKAOCsSu27i7IAqNyYHfh1UUYwqqoeOkh5k8S1rNvOP2J/cFKjxGNu3RgQ=@vger.kernel.org X-Gm-Message-State: AFuF++kTOIfC7uUK51IfBe+GqW6H54U6GUfUjE+cPYhqTfbgFR0k1cjp ICe/qfGGbVBrlxVEsDFznH4iNFxaFrWmQcBcnaJ476vV26PCa/zlyc88 X-Gm-Gg: AYBFou14KgDCOUt8yiIplw3Gta0tV6f3Fn1woWXQpX38zihCo/S1iGv2LNjF/u6ku8D gXLLmuPCwYdb+vl9Keml79v0bEoRCmDGMNz/Km0eQcPjftdwft/kOo2ka3+ImekvnYSgwHKhiED gquAeGDc0+mijtYS7NyfNtzF23g+Edh0oWeh9HrV7YfWkG+HOOmIkD+kYJh/rez4BI7WU9B7V4d wxtOhbEz1eG75NKu+vhQqUX1ZScMllBy+kkGdXaXxQX3wbMirRWTIGmCAObP6kC/uNgVOdbbe91 OOq4OsHAtCX4ESCXyJxNwtVK0+qjhthz3qGfF4UVIRsGSDxLuBheWszXCT4nDVPGIvONUQfVbyk JL5TEWNnaHa52s/Q2X++XzXpoeeo5Bp1QHU6d/ieUEX1SGwV8M1Q5NxO7lRH7+2tSfL1DF+BPUX oBckDxOIQf8/JhSqZONaxLPyjc04tNAItKu+BCDie16wSI5lDKa2/RuTf2xYjDgE+s6D0Sr2+ow eFPdmFnTC4= X-Received: by 2002:a17:90a:d648:b0:39e:6c6a:4b70 with SMTP id 98e67ed59e1d1-39e6c6a5518mr5665139a91.58.1789896549933; Sun, 20 Sep 2026 02:29:09 -0700 (PDT) Received: from intel.company.local ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39e6c37c64csm8154917a91.10.2026.09.20.02.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2026 02:29:09 -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 v3 1/5] of: reserved_mem: release dynamically allocated no-map region on init failure Date: Sun, 20 Sep 2026 17:28:48 +0800 Message-ID: <20260920092852.614973-2-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260920092852.614973-1-chenwandun1@gmail.com> References: <20260920092852.614973-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") Acked-by: Marek Szyprowski Signed-off-by: Wandun Chen Link: https://sashiko.dev/#/message/20260806100605.2C2C01F000E9%40smtp.kern= el.org [1] --- drivers/of/of_reserved_mem.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 8c9d6395d6a3..f55ed3b5aaa4 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -112,7 +112,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, @@ -308,7 +309,7 @@ void __init fdt_scan_reserved_mem_late(void) =20 if (size) { 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 @@ -518,7 +519,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; } @@ -627,13 +628,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; @@ -659,7 +662,7 @@ 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 Thu Sep 24 20:36:52 2026 Received: from mail-pj2-f6.google.com (mail-pj2-f6.google.com [74.125.227.134]) (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 E97143ED5DA for ; Sun, 20 Sep 2026 09:29:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789896559; cv=none; b=YYEsElw8NzhMEiROv6AF4dPn1uxamIUwmTJF3SoETVFXRbQGepcmdlPo4m6499t3ACcV+xzx/ePntGPFtr7MyjlkRduDeb8kyWP3BcttbPDf2VP76Rjr88ScYkzhVEmrPJcNfw7WbH2aBH7pyXwYGg+XSPwqZA2bIjwdI1Lhqn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789896559; c=relaxed/simple; bh=Lq1oWKwyKwiD4aqiQeQgicUxGO7xLFEAUi+XFe1Km0s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IvjglK8DRLnwo3e/isVx48qDTmVs2oYycOuA4EwHic8cn9yV83rrfolycYSm+m1/vJXb413GBwSkkSkPNgxf1T5V3a9Ioks+Vq/VxuAKTbLyjtSM6z/JI6q8g4Pdgtocs9tyveiHSS8G4e5L3yIpun8jWMkImE2ok09sVPAXb54= 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=hQv1Axiy; arc=none smtp.client-ip=74.125.227.134 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="hQv1Axiy" Received: by mail-pj2-f6.google.com with SMTP id d9443c01a7336-2d74bbdc61fso2286695ad.0 for ; Sun, 20 Sep 2026 02:29:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789896556; x=1790501356; 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=E32DKEy2LsQDqopReHm9os4YgHCG98q1Wgi6cD5WuWk=; b=hQv1Axiy+nQXVklIYJMAy+A++UVAIpYpErjViYR2rUsaHMy0E95xlcrwoBa2Vp5DwH pwwsZFKuCbCiHQY/RPifuXDllmshbsleXAWHDQ2u36Hrv1oDKa5+FLjqYEH/BewPBMDJ ato1vtJkvVCYE3aDPWu72sL9XQU2C/WtXlUKgWZtD+SUUIqZhNzCwRmTrm3rJqnt0rsY XJxo2nByVUzSJITpziesvKmlZtdKR6bIvpYRZcz59bPIFlbCOn9ZBvWvBf26FhAWnC+c ZD+f3lALLr/oTIPKMEETFwpDoV+VyJZc46+BQm7mjybAdT1GrHWxFBJP8JZ0fmIL0ekn xJYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789896556; x=1790501356; 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=E32DKEy2LsQDqopReHm9os4YgHCG98q1Wgi6cD5WuWk=; b=RoSpT/+A6xjt1JT9nMU35UDFYJGx3JvoeWcxramAS5uHE45mAi8cCli9Q7s2wMhyRF uCpXk4h+gY/QBZ00PqHtWMc6kQJ57QM4eeSOZUJLlSD/ih9pewiDCnUiLl+VhVulmvRB XbXuj56IWbK+qGBS94f+Rv5yA43bEu/wuT5bHhtaWK8INY6qZIN+h3d7LJEu4OHx/Jai 2MttGxUlKA9koMgRWY83TxxYkJhtmDW4MCUbL37X72jqV4hUR+CJDwpsUh7Tg9IYJqfk sQeByCRfCyNGNnYbifMhcE4BFkxzVYqngXz9QwFpjzL/dZu3vnjaJnLk7pYfJCmex6uD 0Veg== X-Forwarded-Encrypted: i=1; AKwUvBxjS3h7urFbnLw5uCUVao2oshb1OtLlt9iDZedYkdM26iuf158kGodoDNhmCk2ThOwl/DO/9jWbYuq0rDY=@vger.kernel.org X-Gm-Message-State: AFuF++mi9Y3lMzZP5hA39gk9Zdo17FFA4aebWCmwt03VjMSq45JnPVri 4elzESWWQTcDQGAmm9/92STon5aw/2LfnqLz5u45TknhjxEvMqrV6HF8 X-Gm-Gg: AYBFou0jhfnbPjanEOA62GI1FMxxQMOaghGrx/ZDlniv5NmcfB7WFWLDkU6cagSEvL/ udo8xw1/CP0Tv9bB084PRrLFkDy8eV9TfNCHrXjm9xbXePa34f2A5RPOKegxkrALPtMblqbjbBb 6kebA1neUcEFWIlZUxgWEC8Bqss2VGRz5S0Y4TG3ouo4xctWamIdzXPQQ6RZ0sl92AcwKvSMORW Qw96sdIs1Nb08g4b7p8dHLzspZjULp9n5kHcQp8FvlWacoEgBNIuoqTjA9Sv1FUlL5et8RHVvFS myogtfQclRfmj2GgbUgQUPoOTafA0o5/ZXlP6LQF9hvWWGS3j0cZekmCpEjqUtQydBDwLRf4W9F Mxo/Mwr51Q7230RmSwsPWHxmyiz9esf/EUa0yd4y58aY3omsRScIn1KaYqyCGeOGKj6WYYrYGFt 6HgLehYEJZ1T2r/Sqh+912h0cKNBZZRIt519qPluPhspXVSrFZ23LpjSZBit2dHkX9pi855Xwso 99BtHhCLEkSZFO3HSuhpFs= X-Received: by 2002:a17:90b:3885:b0:39e:4c7e:bc4 with SMTP id 98e67ed59e1d1-39e556f5d26mr7972845a91.18.1789896555881; Sun, 20 Sep 2026 02:29:15 -0700 (PDT) Received: from intel.company.local ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39e6c37c64csm8154917a91.10.2026.09.20.02.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2026 02:29:15 -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 v3 2/5] of: reserved_mem: retain static no-map memory on init failure Date: Sun, 20 Sep 2026 17:28:49 +0800 Message-ID: <20260920092852.614973-3-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260920092852.614973-1-chenwandun1@gmail.com> References: <20260920092852.614973-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") Acked-by: Marek Szyprowski Signed-off-by: Wandun Chen Link: https://sashiko.dev/#/message/20260814090305.4C8741F00A3D%40smtp.kern= el.org [1] --- 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 f55ed3b5aaa4..2c64d85cabc6 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -660,7 +660,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); if (dynamic || !nomap) memblock_phys_free(rmem->base, rmem->size); --=20 2.43.0 From nobody Thu Sep 24 20:36:52 2026 Received: from mail-pj2-f5.google.com (mail-pj2-f5.google.com [74.125.227.133]) (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 B9D453ED13F for ; Sun, 20 Sep 2026 09:29:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789896565; cv=none; b=Fdvpaj+z6CiZR5QbU08h3IN2YSXPNFN/K9czutnCwl9GYn+jcuEaH/1Y2lIRYTur6JcpDP54l5DS4CQ55ZOBMlYbXRSQ+N43y3iQ1ciLo/tMJ/zVI2WPToTqNyYrn6r6LAoIievxOY4iSg/v3fylaz7kjQyc2T3H60pDu4wDVCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789896565; c=relaxed/simple; bh=BubAOpyWa9dplLnoG7syB3zPhW4qUYlyZ3mH75IAhEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QPVervPvr8Wd3P9CKLkzbV6l0H46wzt0puT8UYsnP082Ib8n36uiP+ys1yGfua2HXiPZ+yOixTCr3PIJCQkDMUZx9bVdFqF9OkNy7Md3oIX5abeS/LA6YtKC1I5ogVtjPn34+LsrXp5iuXsmssKiq620ph9mlsu1LAb6BBdMhg8= 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=T23oQ3vK; arc=none smtp.client-ip=74.125.227.133 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="T23oQ3vK" Received: by mail-pj2-f5.google.com with SMTP id 98e67ed59e1d1-3965683e9e9so1587823a91.1 for ; Sun, 20 Sep 2026 02:29:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789896562; x=1790501362; 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=fqWx8mKAaudoHgwpRkE/5/zADaw3qTiUOzjXR8usL9g=; b=T23oQ3vKWxZqrWI4iMUF66JK2shJ/TH6eHC4LBkKeC2j5qaiuWduWqJLHP9tMWZN9A cyR1/67+abAUEh5B42uxj/DttasHeAVpjnqn9jcczT0T78uOeq2EC4G6yEuYpPHanjuf jV+sFTdZc6Br9SYb8woG/u1Rke0pSLRQ994Ttj3mUDXkhhACDyu3V2r/x+unc87HUKgs 8vfiXP5BZMKXz9H9loEzv0HtyWl3PhurSKdVG1MJkjZW+5Sco2DbY6Vt3CGYvYP+tLr+ +zTgrXFHaY76R9eSNSQ4I4X0Gp6RlYNoWvHZ1vwSLBmix2G4ks0Lu99749ch24/5KW0z 2bHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789896562; x=1790501362; 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=fqWx8mKAaudoHgwpRkE/5/zADaw3qTiUOzjXR8usL9g=; b=wPEeCv4xsSGLZb82aEC+nPNCXHqKZyO1zQqakxdOvppuEyeoK+feqxZ7qQ5Zlc7cyP j5otupiDlVUF0de+6F7+6jhl/NRhbIs6D+eflES4rj2TceluZ07LunTZQ05+9U0CI1uP 4jp8xZ8z9I1eX16h9OrcjbU/wHliYYt8InisaWTxFw4qVI/WfpFptPW3nUIoaYikP4yc gP5mpPsRMH+o6AQdt2o4OkxGvgW71Qb4CeGMWt1x6XAiZvcA1CjNShuePrgRgk7K9A92 kEp2ttyk3C8Vgrdz43BE3/RIF/PpetmPlX2G7kUo4koVnDLCJsjbpLe+DYsfRd6zgSTp H8aQ== X-Forwarded-Encrypted: i=1; AKwUvBzNYnjyHtkaR/8mkfuZHXSSuWcynJArmT43hQ0BrfzZ5wRdUYjvQHygT+ddtdGfqackSHGJ/tWkmToM6kg=@vger.kernel.org X-Gm-Message-State: AFuF++lpacvCXoHf4HIFMY3Oznolwa87JgDEoWkxCqJrPFzdHM2KpGej Ki9X0Ef4kcCd/Gl9I4V303sPMX7ximX2Vj05OsGOdYzjnjZWf3rJpsYk X-Gm-Gg: AYBFou1GKLkdA/PZTF5KodlxZcjX28wAB+EGJYDGFKqxsBN2iV+p8WgUraO0g0Du5QD lg/oc+OA08UVjABD3o4MZbOcSlN3R8+WhnyiBVD0Y8elRa0fqw/jOfxmG1ykKFZ55dUXpROGs/G yI9qHx6I6z7msmsa7cyd0U7Hv2jfKsy7AWLUjtdMmBN/33KE+SXZaOyHMc4rQ8Fg9G4FAH/+B0C AUlaNBLQC48yuagRbmOCDHxEt/mSiw67Z/AUPUYCvY9tZjTq0g6ehNj0UsYV0bMw3n2s2txYvhD mxWAKx9tp/ZZgTPxowS6p33pxoc+gghdQHJ/efmdsCw4bjGX9caTb27N7kfP9Y7IyW8Nc2a8kFk K1Opfu1Md0yLxO98ns7lipWwzd5dRSmxvhwSIG6HH1pS5goHyMU4DRaRZQBCElhViDhGWm+7TS/ deYRRSbpJ6/N1FTkLBeVYKozo8oLpolWKygu1gT7orVsSIkQMqeAJFZDUW5zv2+7monM5noQA33 A+8QfpqPo4= X-Received: by 2002:a17:90b:4b85:b0:3a0:42a9:9c73 with SMTP id 98e67ed59e1d1-3a042a99fd2mr465493a91.38.1789896561858; Sun, 20 Sep 2026 02:29:21 -0700 (PDT) Received: from intel.company.local ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39e6c37c64csm8154917a91.10.2026.09.20.02.29.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2026 02:29:21 -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 v3 3/5] of: reserved_mem: skip init for regions whose early reservation failed Date: Sun, 20 Sep 2026 17:28:50 +0800 Message-ID: <20260920092852.614973-4-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260920092852.614973-1-chenwandun1@gmail.com> References: <20260920092852.614973-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. Tag each region in memblock with MEMBLOCK_RSRV_RMEM when its early reservation succeeds, so the late scan can check whether the node's own reservation succeeded and skip those that failed. Fixes: 8a6e02d0c00e ("of: reserved_mem: Restructure how the reserved memory= regions are processed") Suggested-by: Marek Szyprowski Signed-off-by: Wandun Chen --- drivers/of/of_reserved_mem.c | 46 ++++++++++++++++++------ include/linux/memblock.h | 6 ++++ mm/memblock.c | 69 ++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 11 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 2c64d85cabc6..3a6c6dbfd7b1 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -122,6 +122,8 @@ static int fdt_fixup_reserved_mem_node(unsigned long no= de, static int __init early_init_dt_reserve_memory(phys_addr_t base, phys_addr_t size, bool nomap) { + int ret; + if (nomap) { /* * If the memory is already reserved (by another region), we @@ -132,9 +134,16 @@ static int __init early_init_dt_reserve_memory(phys_ad= dr_t base, memblock_is_region_reserved(base, size)) return -EBUSY; =20 - return memblock_mark_nomap(base, size); + ret =3D memblock_mark_nomap(base, size); + if (!ret) + memblock_mark_rsrv_rmem(base, size); + return ret; } - return memblock_reserve(base, size); + + ret =3D memblock_reserve(base, size); + if (!ret) + memblock_mark_rsrv_rmem(base, size); + return ret; } =20 /* @@ -168,14 +177,19 @@ 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) { 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 @@ -288,6 +302,7 @@ void __init fdt_scan_reserved_mem_late(void) fdt_for_each_subnode(child, fdt, node) { const __be32 *prop; const char *uname; + bool nomap; u64 b, s; int ret; int len; @@ -307,10 +322,15 @@ 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, false); - } + if (!size) + continue; + + nomap =3D of_get_flat_dt_prop(child, "no-map", NULL) !=3D NULL; + if (!memblock_is_region_rsrv_rmem(base, size, nomap)) + continue; + + uname =3D fdt_get_name(fdt, child, NULL); + fdt_init_reserved_mem_node(child, uname, base, size, false); } =20 /* check for overlapping reserved regions */ @@ -662,8 +682,12 @@ static void __init fdt_init_reserved_mem_node(unsigned= long node, const char *un =20 if (dynamic && nomap) memblock_clear_nomap(rmem->base, rmem->size); + if (dynamic || !nomap) memblock_phys_free(rmem->base, rmem->size); + + if (!dynamic) + memblock_clear_rsrv_rmem(rmem->base, rmem->size); return; } else { phys_addr_t end =3D rmem->base + rmem->size - 1; diff --git a/include/linux/memblock.h b/include/linux/memblock.h index aa845f488327..03613fa0c894 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -52,6 +52,7 @@ extern unsigned long long max_possible_pfn; * kernel that we know is good to use. It is the only memory that * allocations may happen from in this phase. * @MEMBLOCK_RSRV_HUGETLB: memory is reserved for hugetlb pages + * @MEMBLOCK_RSRV_RMEM: memory reserved by a static /reserved-memory node */ enum memblock_flags { MEMBLOCK_NONE =3D 0x0, /* No special request */ @@ -63,6 +64,7 @@ enum memblock_flags { MEMBLOCK_RSRV_KERN =3D 0x20, /* memory reserved for kernel use */ MEMBLOCK_KHO_SCRATCH =3D 0x40, /* scratch memory for kexec handover */ MEMBLOCK_RSRV_HUGETLB =3D 0x80, /* memory reserved for hugetlb pages */ + MEMBLOCK_RSRV_RMEM =3D 0x100, /* static /reserved-memory node */ }; =20 /** @@ -160,6 +162,10 @@ int memblock_reserved_mark_noinit(phys_addr_t base, ph= ys_addr_t size); int memblock_reserved_mark_kern(phys_addr_t base, phys_addr_t size); int memblock_mark_kho_scratch(phys_addr_t base, phys_addr_t size); int memblock_clear_kho_scratch(phys_addr_t base, phys_addr_t size); +int memblock_mark_rsrv_rmem(phys_addr_t base, phys_addr_t size); +int memblock_clear_rsrv_rmem(phys_addr_t base, phys_addr_t size); +bool memblock_is_region_rsrv_rmem(phys_addr_t base, phys_addr_t size, + bool nomap); =20 void memblock_free(void *ptr, size_t size); =20 diff --git a/mm/memblock.c b/mm/memblock.c index ea0de4b5f356..d88e926e2ea5 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1204,6 +1204,39 @@ __init int memblock_clear_kho_scratch(phys_addr_t ba= se, phys_addr_t size) MEMBLOCK_KHO_SCRATCH); } =20 +/** + * memblock_mark_rsrv_rmem - Mark a region reserved by a static /reserved-= memory node + * @base: the base phys addr of the region + * @size: the size of the region + * + * Only called for statically placed reserved-memory regions (those defined + * by a "reg" property), so the late scan can later tell such a region apa= rt + * from one reserved by unrelated code. + * + * Return: 0 on success, -errno on failure. + */ +int __init_memblock memblock_mark_rsrv_rmem(phys_addr_t base, phys_addr_t = size) +{ + return memblock_setclr_flag(&memblock.memory, base, size, 1, + MEMBLOCK_RSRV_RMEM); +} + +/** + * memblock_clear_rsrv_rmem - Clear the static /reserved-memory node tag + * @base: the base phys addr of the region + * @size: the size of the region + * + * Only called for statically placed reserved-memory regions whose late + * initialization failed, to undo the tag set by memblock_mark_rsrv_rmem(). + * + * Return: 0 on success, -errno on failure. + */ +int __init_memblock memblock_clear_rsrv_rmem(phys_addr_t base, phys_addr_t= size) +{ + return memblock_setclr_flag(&memblock.memory, base, size, 0, + MEMBLOCK_RSRV_RMEM); +} + static bool should_skip_region(struct memblock_type *type, struct memblock_region *m, int nid, int flags) @@ -2154,6 +2187,41 @@ bool __init_memblock memblock_is_region_reserved(phy= s_addr_t base, phys_addr_t s return memblock_overlaps_region(&memblock.reserved, base, size); } =20 +/** + * memblock_is_region_rsrv_rmem - check if a range is tagged by MEMBLOCK_R= SRV_RMEM + * @base: the base phys addr of the range + * @size: the size of the range + * @nomap: the expected no-map state of the range + * + * A range with no overlap in memblock.memory lies entirely outside + * declared system memory, where the tag could never be applied, so it is + * treated as reserved. Otherwise, every overlapping region must carry the + * %MEMBLOCK_RSRV_RMEM tag and match @nomap. + * + * Return: true if the range is reserved, false otherwise. + */ +bool __init_memblock memblock_is_region_rsrv_rmem(phys_addr_t base, + phys_addr_t size, bool nomap) +{ + phys_addr_t end =3D base + memblock_cap_size(base, &size); + unsigned long i; + + for (i =3D 0; i < memblock.memory.cnt; i++) { + struct memblock_region *r =3D &memblock.memory.regions[i]; + + if (r->base >=3D end) + break; + if (!memblock_addrs_overlap(base, size, r->base, r->size)) + continue; + if (!(r->flags & MEMBLOCK_RSRV_RMEM)) + return false; + if (memblock_is_nomap(r) !=3D nomap) + return false; + } + + return true; +} + void __init_memblock memblock_trim_memory(phys_addr_t align) { phys_addr_t start, end, orig_start, orig_end; @@ -2880,6 +2948,7 @@ static const char * const flagname[] =3D { [ilog2(MEMBLOCK_RSRV_KERN)] =3D "RSV_KERN", [ilog2(MEMBLOCK_KHO_SCRATCH)] =3D "KHO_SCRATCH", [ilog2(MEMBLOCK_RSRV_HUGETLB)] =3D "RSV_HUGETLB", + [ilog2(MEMBLOCK_RSRV_RMEM)] =3D "RSV_RMEM", }; =20 static int memblock_debug_show(struct seq_file *m, void *private) --=20 2.43.0 From nobody Thu Sep 24 20:36:52 2026 Received: from mail-pj2-f7.google.com (mail-pj2-f7.google.com [74.125.227.135]) (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 29D133ED5DA for ; Sun, 20 Sep 2026 09:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789896570; cv=none; b=aDd/83TSs9sE8NOVYZ8Nhmp9EpJ/RLZSKKE4oZbZKr+dikEXac6SKtZRXt6n9NhwKqL2kIahXigm84OVINv0w76S4qwqPy9bJA2zHX0E16gBnsx0cVsNIOoW6pK3rAduPtOfbGMZfsPiEWfBSiF4/z5gBdp35qXVjSd0/aSHpkw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789896570; c=relaxed/simple; bh=LNR32bo9MZbhwnB9ad4i4/2psJWZcEuINS4tvZdMbDE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=orqnmsFi0DNehd+ER4WI5qynC1pDl6es0ivPRFya5FO/AETBS491bUvkkTJfEi+MtDCvqr/cUcNtF5kIZQSMH+PDqxFKNK79FmeZWznRsP39VDzzSU2yW42sEW+Vy6xQN/ab9mll7srpQzU71UGonW0TacBgKsJkoWKTCPOpgqg= 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=iOs8j8z/; arc=none smtp.client-ip=74.125.227.135 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="iOs8j8z/" Received: by mail-pj2-f7.google.com with SMTP id 98e67ed59e1d1-398da2bdcb9so979627a91.0 for ; Sun, 20 Sep 2026 02:29:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789896568; x=1790501368; 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=SxtCD6SnNu1NDzEpQGETPXmjrPB6bmHGJKpCRbMz92Y=; b=iOs8j8z/8Vx9zaKQW/mh70/dn9Egh7k/D2YDhFH8oDrxtpONMNHZwFvdb8J44jcvTW HPymCGdpLkwF0kTRoqALzhGlGFsdDlUrjy9bR01RVA1t1NUOMS//WcRIYXysFqEiwv9f fe6keo+OyDuP+PORktbM0eQed7ykCv5l3/aYgkmXu9n8KhqO6aL6zWRyC/OMaSdjc+zy wyChcrbVEKpWyy55mI0WRVn1td9l4z/qVB0YZFXtrniaMP0558QGgvJhEluIAGLLiezF JaR2W83atZQPcnJy8l/q0Dwg943yLTcm7R7HpzIpTv04QvDWpISY/4QCLnhGoKVBdHPu 2uPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789896568; x=1790501368; 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=SxtCD6SnNu1NDzEpQGETPXmjrPB6bmHGJKpCRbMz92Y=; b=kZJYiTeoqZxALrX1xUJS1N39FZYYiipoUTGUENY0nM4IZbOaBbaXjPuEtkehHJhjhP NiGm18gHggfe8lS75VqxNEzy8Hn4CyrmsctvYKyCMNvtt0Lo4ZKrwbDp1wKs6iAorf7s 1Z4Dqvc+1EqAaX/VOvFCDMsgMT4fvYyI7Rg4K1fqL6eiHS5qWgx+5Oh+1yQASzIiCYaz ARPbO0sGHTcH36iApucKOLIv9DRKUnTHV7rubLPYvdw5lqpLK1tli+XoLnlEo1H+cDLk qKiO52qle4al4ATgcgDgjP/8C3b6N63Bx49PWK3Yg3hA4rF/TJbH/NV3UIvqHpYy5/xs ZZuw== X-Forwarded-Encrypted: i=1; AKwUvBwQNHh21AQ4dvBoDI68k8PQ9/joI7YQKa1QjyvSTlHGY6CscsJ3sfg/YeEtDgt4c0bdfxX/5WCuXk3ukyo=@vger.kernel.org X-Gm-Message-State: AFuF++lfSIW3fwacodG+3MZ58mNMPY6gZv1gR4pEBuzd5t1LvivbZ4wU AVBvHSTRMSa1akWp+zev6/cB1lAf16nFbx0zluDgtYyELMQE/nyoYYm+sabo2Nx6 X-Gm-Gg: AYBFou1mKW3HGP6Pl9vXvpsuv1IAihae3P0rQHND9zxO5nySfy60iE+GXaAILb/Fgg0 fx7atd6xNRWSY1nZFGQkhYEzP/0Jm5o1EIPae7FsGQiYNsFcPYwx0O2W52UGSk/KChQsBHTRBwZ +G1E5dVwKdb+yta4bTdu+QwzEKNkwsevKcT64zDVuZJP88/IIY//Y1Ui9M2oAslWDPptdlsRIOu Xb807/SmgUtsRQBn9kZLKLZw3wPf05Ler6FppLHhLjFoO247b0aK32gyeWUxW5KjxShg2WcoHmm TU5FGSsECO0GsVBnWB5n9YrLxwMIADq0iiYnPMvVhAeDz/9glccu49Ye+4/HAF0Iz3MIxm993Dm tJpux/yacpFPRNA+z/Nph+TBQir8kFEpVk9EUJUn0xh8KkwzASkPAib6ZRt0VC8Fv/zXDbl+XfA ipJFSNW2K561o8+J2Mt8TG5RB4NjheUSGPGtfwR+yF+N7+sJdzLgqJrdtZL4bOvGMwK3ncj7xnJ FpytTjhm/0= X-Received: by 2002:a17:90b:5787:b0:398:a145:5d3d with SMTP id 98e67ed59e1d1-39e54ce45c2mr19449286a91.6.1789896568224; Sun, 20 Sep 2026 02:29:28 -0700 (PDT) Received: from intel.company.local ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39e6c37c64csm8154917a91.10.2026.09.20.02.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2026 02:29:27 -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 v3 4/5] of: reserved_mem: reject static regions overlapping no-map memory Date: Sun, 20 Sep 2026 17:28:51 +0800 Message-ID: <20260920092852.614973-5-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260920092852.614973-1-chenwandun1@gmail.com> References: <20260920092852.614973-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 no-map region that overlaps existing reserved no-map memory, and skip a no-map region in the late scan that overlaps one already reserved. Sashiko found this issue in [1]. Fixes: 86588296acbf ("fdt: Properly handle "no-map" field in the memory reg= ion") Suggested-by: Marek Szyprowski Signed-off-by: Wandun Chen Link: https://sashiko.dev/#/message/20260814084718.29C341F000E9%40smtp.kern= el.org [1] --- drivers/of/of_reserved_mem.c | 23 +++++++++++++++++++++-- include/linux/memblock.h | 1 + mm/memblock.c | 26 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 3a6c6dbfd7b1..8d2057f2ac12 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -131,7 +131,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_region(base, size))) return -EBUSY; =20 ret =3D memblock_mark_nomap(base, size); @@ -266,6 +267,20 @@ static void __init __rmem_check_for_overlap(void) } } =20 +static bool __init rmem_overlaps_check(phys_addr_t base, phys_addr_t size, + int start) +{ + int i; + + for (i =3D start; i < reserved_mem_count; i++) { + struct reserved_mem *r =3D &reserved_mem[i]; + + if (memblock_addrs_overlap(base, size, r->base, r->size)) + return true; + } + return false; +} + /** * fdt_scan_reserved_mem_late() - Scan FDT and initialize remaining reserv= ed * memory regions. @@ -279,7 +294,7 @@ void __init fdt_scan_reserved_mem_late(void) { const void *fdt =3D initial_boot_params; phys_addr_t base, size; - int node, child; + int node, child, static_reserved_start; =20 if (!fdt) return; @@ -299,6 +314,8 @@ void __init fdt_scan_reserved_mem_late(void) return; } =20 + static_reserved_start =3D reserved_mem_count; + fdt_for_each_subnode(child, fdt, node) { const __be32 *prop; const char *uname; @@ -326,6 +343,8 @@ void __init fdt_scan_reserved_mem_late(void) continue; =20 nomap =3D of_get_flat_dt_prop(child, "no-map", NULL) !=3D NULL; + if (nomap && rmem_overlaps_check(base, size, static_reserved_start)) + continue; if (!memblock_is_region_rsrv_rmem(base, size, nomap)) continue; =20 diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 03613fa0c894..34a695542ab1 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -504,6 +504,7 @@ bool memblock_is_map_memory(phys_addr_t addr); bool memblock_is_region_memory(phys_addr_t base, phys_addr_t size); bool memblock_is_reserved(phys_addr_t addr); bool memblock_is_region_reserved(phys_addr_t base, phys_addr_t size); +bool memblock_overlaps_nomap_region(phys_addr_t base, phys_addr_t size); =20 void memblock_dump_all(void); =20 diff --git a/mm/memblock.c b/mm/memblock.c index d88e926e2ea5..58c9281e729e 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2222,6 +2222,32 @@ bool __init_memblock memblock_is_region_rsrv_rmem(ph= ys_addr_t base, return true; } =20 +/** + * memblock_overlaps_nomap_region - check if a region intersects no-map me= mory + * @base: base of region to check + * @size: size of region to check + * + * Check if the region [@base, @base + @size) intersects a memory block + * marked %MEMBLOCK_NOMAP. + * + * Return: + * True if they intersect, false if not. + */ +bool __init_memblock memblock_overlaps_nomap_region(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; +} + void __init_memblock memblock_trim_memory(phys_addr_t align) { phys_addr_t start, end, orig_start, orig_end; --=20 2.43.0 From nobody Thu Sep 24 20:36:52 2026 Received: from mail-pj2-f7.google.com (mail-pj2-f7.google.com [74.125.227.135]) (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 90AAA3ED5DA for ; Sun, 20 Sep 2026 09:29:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789896576; cv=none; b=tYH/Bv3KA7DIeNigaSfbiRSARzrdNJEnUOn8NBSjCnrp1PZ1YnCGncN+9PYgXzCc6Uc2D0fqemOrE/U6iPzsaOJ0DO5ejoXXSbvVSgqTyxiyl6vnhJbW86Iwet33w2d9+UL+kbqCiXiGZzpmT3l7kxRKMJyA0Lm/0uh7Dae64XQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789896576; c=relaxed/simple; bh=Tmu2iOBSum4sCidWBK+rRsYXL+/qGEiGufjpG+9emsE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t4P8KNYgX37QvII0v6fya8pGy+HLiwu/BNNL5wZIhK7GEDwTK9pL1E8sifwn3dGtR9wuomHXfzsilLyp6QPVVE60gzEwyMQpi/6jP/IAYBIM3URWThrGtT+VuK6W6WIaJPTZh2tHsOHDAflnMqBN2uv/d52BPxph7QaGuqEK35w= 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=P3qfrTqA; arc=none smtp.client-ip=74.125.227.135 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="P3qfrTqA" Received: by mail-pj2-f7.google.com with SMTP id 98e67ed59e1d1-39e37c430bbso985012a91.1 for ; Sun, 20 Sep 2026 02:29:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789896574; x=1790501374; 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=Sug+4f+tGLe8RFcRq2oeLrmDKsMlqAOb6R6Xgy7yp4w=; b=P3qfrTqAG+794yqsghTR0p3gYTcx5X8bV9zAVgONta9mNhauziPVQyYPNtQF/a7c27 adZnygAFRwQlp53RZpL2kWcTJPp1b/CRlUmCVLAlveRO2v0l3p7TTVvSovb7rYzlCjYr jloRKI2PoSsJ2Sh7tfqGAqTcYh524VfVGXnsl3Sc02y8hAIPmeFdgWUoHLEx+i5+sOpp R2egmo4OmGTgpITWKLEn/K7/7uyS+rfJJST3nHgUTfzHaXANe5go7PWHZJwl3rvCzzk3 hrg6n4ES76jgjiM1K2Q1V+6VxVBlckSZ6m9hxFA5At2dzUIeSqTwV/5lidlOXRYi+Bmu dq7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789896574; x=1790501374; 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=Sug+4f+tGLe8RFcRq2oeLrmDKsMlqAOb6R6Xgy7yp4w=; b=lTt8c6eiv7q3rj9YJwYo2BlYEp5Nxly8oMlZdZGs79hABfDHvKwel6PxTjSzW1VU6G oB5FcHG+i/D14kM77pXEN9Uc6BW8jx4T0OFa8csxtTLrVXwT4zE/1ZAEvpm69Yqa5YHA S/p059v1pMsmb98mDk85L8+cx7mqLnmA94+EwXHkjOMJ3Js9H5e30BzTPoGUkKhmIndC joFzua+wg3PBAmqb+nky444jKBWqB82UocyCTrae6FRmtkeLY8nTjWuct7Hi6XhWd/rN /ah0QiazyBl3wLX1kH3Sw1pdsFibGYwYVxddggHEvvr6rvnPE/CNSclXFUD5kkDKd6W3 r8oA== X-Forwarded-Encrypted: i=1; AKwUvByBwAn4i+2GQ4wjf26Y66MDkldcTQh0xV5jwMuxEmNJnwNeap5WhWWjhu7vCMfP2FItdsuha3V++1Hd0CI=@vger.kernel.org X-Gm-Message-State: AFuF++lNavTjHa8dNXxW7c/wT5hyxGiwP85URS1zYZbr8fH/+BWTjay2 lkOC3ahvxTCbTj+aih3Jcwv/6OwtlZMy0jZi4CcICAuh9prMBoa9m6TI X-Gm-Gg: AYBFou3YCY5CrFBuskVr6eArISx2b/Kp6dnX+RxuwvKKNrJ6KLB5YlXonEccCjdJ38A 87DD0XskI/VRlZ2sDxXDaI3wVvjbs8ZcDgYtmAUrTocm8ULiX6J908ExMqKY+mclXoHTO7VYo6A wtJU4PWEoVPysQ5OIQlYjBCRhddYMHXM3XfYdFAqeIgD35EXXpB/MPuiiPuROpWSmE4OSYKoTnL 1xGNGWkxzjI9VjBhD6JAyQ9RE8YccearWZ4CNwEtfRYoDROHEDkMb6SF4LOpXOV0aMegqkvSuR2 mNcZ35shmsex9khnh48CBMG3tuGjH4MgCv4nKzeNaa12eLU1gDSUilJWwYLlkG0xu5HJ9cIe5Ar bFkwFP9MypeCfPNZj/sfkBc+HHWlQZ6CmHrhwFSJsGNkmxb2X8v7luQWleW4jiiAKvwMb2DNoGx oyn/HKhSIGug9c7ip3fFjgrxkyHqFjiAztwOtayYO0+PoHefIeLLz5z9cc+lM8NK7CWnBv0KBLE uTJTqKHlX0= X-Received: by 2002:a17:90b:2d44:b0:39d:8794:5564 with SMTP id 98e67ed59e1d1-39e54ce36fdmr13649499a91.12.1789896573869; Sun, 20 Sep 2026 02:29:33 -0700 (PDT) Received: from intel.company.local ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39e6c37c64csm8154917a91.10.2026.09.20.02.29.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2026 02:29:31 -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 v3 5/5] of: reserved_mem: reject static mapped regions overlapping existing reservations Date: Sun, 20 Sep 2026 17:28:52 +0800 Message-ID: <20260920092852.614973-6-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260920092852.614973-1-chenwandun1@gmail.com> References: <20260920092852.614973-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") Suggested-by: Marek Szyprowski Signed-off-by: Wandun Chen Link: https://sashiko.dev/#/message/20260806100605.2C2C01F000E9%40smtp.kern= el.org [1] --- drivers/of/of_reserved_mem.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 8d2057f2ac12..2d1e01c0f886 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -141,6 +141,10 @@ static int __init early_init_dt_reserve_memory(phys_ad= dr_t base, return ret; } =20 + if (memblock_is_region_reserved(base, size) || + memblock_overlaps_nomap_region(base, size)) + return -EBUSY; + ret =3D memblock_reserve(base, size); if (!ret) memblock_mark_rsrv_rmem(base, size); @@ -343,7 +347,7 @@ void __init fdt_scan_reserved_mem_late(void) continue; =20 nomap =3D of_get_flat_dt_prop(child, "no-map", NULL) !=3D NULL; - if (nomap && rmem_overlaps_check(base, size, static_reserved_start)) + if (rmem_overlaps_check(base, size, static_reserved_start)) continue; if (!memblock_is_region_rsrv_rmem(base, size, nomap)) continue; --=20 2.43.0