[PATCH] of: Make the number of reserved memory regions configurable

Maxime Ripard posted 1 patch 3 months, 2 weeks ago
drivers/of/Kconfig      | 12 ++++++++++++
drivers/of/of_private.h |  2 +-
2 files changed, 13 insertions(+), 1 deletion(-)
[PATCH] of: Make the number of reserved memory regions configurable
Posted by Maxime Ripard 3 months, 2 weeks ago
Some platforms register more reserved memory regions than the current
hardcoded limit of 64.

Let's turn into a Kconfig option so we can easily tune it according to a
platform needs, while keeping the current value as a default.

Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
 drivers/of/Kconfig      | 12 ++++++++++++
 drivers/of/of_private.h |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 50697cc3b07ebeb24283e22299797ce4612db89c..721221ae73cef118f8bde8c64c6298aa5f1d106e 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -97,10 +97,22 @@ config OF_IRQ
 	depends on !SPARC && IRQ_DOMAIN
 
 config OF_RESERVED_MEM
 	def_bool OF_EARLY_FLATTREE
 
+config OF_RESERVED_MEM_AREAS
+	int "Maximum count of reserved memory areas"
+	depends on OF_RESERVED_MEM
+	default 64
+	help
+	  Platforms can create a number of reserved memory region
+	  to accomodate their firmware,	describe driver-specific
+	  memory regions, etc. This parameters sets the maximum
+	  number of reserved memory areas in the system.
+
+	  If unsure, leave to its default value 64.
+
 config OF_RESOLVE
 	bool
 
 config OF_OVERLAY
 	bool "Device Tree overlays"
diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
index df0bb00349e01145930fa85c195aefc0a7c32a06..af424ca876b4481c21563bfbac8691a74a42970b 100644
--- a/drivers/of/of_private.h
+++ b/drivers/of/of_private.h
@@ -7,11 +7,11 @@
  * Paul Mackerras	August 1996.
  * Copyright (C) 1996-2005 Paul Mackerras.
  */
 
 #define FDT_ALIGN_SIZE 8
-#define MAX_RESERVED_REGIONS    64
+#define MAX_RESERVED_REGIONS    CONFIG_OF_RESERVED_MEM_AREAS
 
 /**
  * struct alias_prop - Alias property in 'aliases' node
  * @link:	List node to link the structure in aliases_lookup list
  * @alias:	Alias property name

---
base-commit: efb26a23ed5f5dc3554886ab398f559dcb1de96b
change-id: 20251023-of-max-reserved-mem-a8e8d7db3afe

Best regards,
-- 
Maxime Ripard <mripard@kernel.org>
Re: [PATCH] of: Make the number of reserved memory regions configurable
Posted by Rob Herring 3 months, 2 weeks ago
On Thu, Oct 23, 2025 at 10:35 AM Maxime Ripard <mripard@kernel.org> wrote:
>
> Some platforms register more reserved memory regions than the current
> hardcoded limit of 64.

I've already NAKed a kconfig option for this before.

The limit is now 64 dynamic regions, not total. The static regions are
unlimited. What platform needs so many regions and to abuse
/reserved-memory like this?

Rob
Re: [PATCH] of: Make the number of reserved memory regions configurable
Posted by Maxime Ripard 3 months, 2 weeks ago
Hi Rob,

Thanks for your answer!

On Fri, Oct 24, 2025 at 07:57:06AM -0500, Rob Herring wrote:
> On Thu, Oct 23, 2025 at 10:35 AM Maxime Ripard <mripard@kernel.org> wrote:
> >
> > Some platforms register more reserved memory regions than the current
> > hardcoded limit of 64.
> 
> I've already NAKed a kconfig option for this before.
> 
> The limit is now 64 dynamic regions, not total. The static regions are
> unlimited. What platform needs so many regions and to abuse
> /reserved-memory like this?

I'm sorry, I totally missed both that you nacked it and that it got
fixed recently. We're still seeing the issue with 6.12, but it looks like

https://lore.kernel.org/all/20241008220624.551309-1-quic_obabatun@quicinc.com/

Is the series you were talking about?

Thanks,
Maxime
Re: [PATCH] of: Make the number of reserved memory regions configurable
Posted by Rob Herring 3 months, 2 weeks ago
On Mon, Oct 27, 2025 at 11:02:39AM +0100, Maxime Ripard wrote:
> Hi Rob,
> 
> Thanks for your answer!
> 
> On Fri, Oct 24, 2025 at 07:57:06AM -0500, Rob Herring wrote:
> > On Thu, Oct 23, 2025 at 10:35 AM Maxime Ripard <mripard@kernel.org> wrote:
> > >
> > > Some platforms register more reserved memory regions than the current
> > > hardcoded limit of 64.
> > 
> > I've already NAKed a kconfig option for this before.
> > 
> > The limit is now 64 dynamic regions, not total. The static regions are
> > unlimited. What platform needs so many regions and to abuse
> > /reserved-memory like this?
> 
> I'm sorry, I totally missed both that you nacked it and that it got
> fixed recently. We're still seeing the issue with 6.12, but it looks like
> 
> https://lore.kernel.org/all/20241008220624.551309-1-quic_obabatun@quicinc.com/
> 
> Is the series you were talking about?

Yes. Plus some fixes on top of that. Every time this code is touched, we 
break someone...

Rob