* [PATCH] cache: sifive_ccache: skip disabled device tree nodes
@ 2026-10-28 13:19 Avi Weiss
2026-11-05 18:24 ` Conor Dooley
0 siblings, 1 reply; 4+ messages in thread
From: Avi Weiss @ 2026-10-28 13:19 UTC (permalink / raw)
To: Conor Dooley
Cc: Jonathan Cameron, Paul Walmsley, Samuel Holland, linux-riscv,
linux-kernel, Avi Weiss
sifive_ccache_init() uses of_find_matching_node_and_match(), which also
returns nodes marked as disabled. The initializer can therefore map and
access a cache controller that the device tree marks unavailable.
Select the first available matching node before accessing its registers.
This also handles a disabled node preceding an enabled one.
Fixes: a967a289f169 ("RISC-V: sifive_l2_cache: Add L2 cache controller driver for SiFive SoCs")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
drivers/cache/sifive_ccache.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/cache/sifive_ccache.c b/drivers/cache/sifive_ccache.c
index 71d3f94987fa..02878d54381d 100644
--- a/drivers/cache/sifive_ccache.c
+++ b/drivers/cache/sifive_ccache.c
@@ -297,7 +297,9 @@ static int __init sifive_ccache_init(void)
unsigned long quirks __maybe_unused;
int rc;
- np = of_find_matching_node_and_match(NULL, sifive_ccache_ids, &match);
+ for_each_matching_node_and_match(np, sifive_ccache_ids, &match)
+ if (of_device_is_available(np))
+ break;
if (!np)
return -ENODEV;
base-commit: 65ba8f34ec886ec72b2c07ddc8cf3d815c32869d
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] cache: sifive_ccache: skip disabled device tree nodes
2026-10-28 13:19 [PATCH] cache: sifive_ccache: skip disabled device tree nodes Avi Weiss
@ 2026-11-05 18:24 ` Conor Dooley
2026-11-14 17:40 ` Avi
0 siblings, 1 reply; 4+ messages in thread
From: Conor Dooley @ 2026-11-05 18:24 UTC (permalink / raw)
To: Avi Weiss
Cc: Jonathan Cameron, Paul Walmsley, Samuel Holland, linux-riscv,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1428 bytes --]
On Wed, Oct 28, 2026 at 03:19:40PM +0200, Avi Weiss wrote:
> sifive_ccache_init() uses of_find_matching_node_and_match(), which also
> returns nodes marked as disabled. The initializer can therefore map and
> access a cache controller that the device tree marks unavailable.
>
> Select the first available matching node before accessing its registers.
> This also handles a disabled node preceding an enabled one.
>
> Fixes: a967a289f169 ("RISC-V: sifive_l2_cache: Add L2 cache controller driver for SiFive SoCs")
> Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
> ---
> drivers/cache/sifive_ccache.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cache/sifive_ccache.c b/drivers/cache/sifive_ccache.c
> index 71d3f94987fa..02878d54381d 100644
> --- a/drivers/cache/sifive_ccache.c
> +++ b/drivers/cache/sifive_ccache.c
> @@ -297,7 +297,9 @@ static int __init sifive_ccache_init(void)
> unsigned long quirks __maybe_unused;
> int rc;
>
> - np = of_find_matching_node_and_match(NULL, sifive_ccache_ids, &match);
> + for_each_matching_node_and_match(np, sifive_ccache_ids, &match)
> + if (of_device_is_available(np))
Are there any devices where this is actually possible? IOW, where there
are 2 ccache instances.
> + break;
> if (!np)
> return -ENODEV;
>
>
> base-commit: 65ba8f34ec886ec72b2c07ddc8cf3d815c32869d
> --
> 2.43.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] cache: sifive_ccache: skip disabled device tree nodes
2026-11-05 18:24 ` Conor Dooley
@ 2026-11-14 17:40 ` Avi
2026-11-16 17:20 ` Conor Dooley
0 siblings, 1 reply; 4+ messages in thread
From: Avi @ 2026-11-14 17:40 UTC (permalink / raw)
Cc: linux-riscv, linux-kernel
It's more of a defensive thing. The 2 ccache instance was an example -
the issue is also relevant for one disabled ccache node no?
Since of_find_matching_node_and_match() doesn't check whether a node
is enabled, it can return a disabled one.
sifive_ccache_init() then goes ahead and maps and accesses its
registers, even though the device tree marks it as disabled and normal
OF platform-device creation would skip it.
On Thu, Nov 5, 2026 at 8:24 PM Conor Dooley <conor@kernel.org> wrote:
>
> On Wed, Oct 28, 2026 at 03:19:40PM +0200, Avi Weiss wrote:
> > sifive_ccache_init() uses of_find_matching_node_and_match(), which also
> > returns nodes marked as disabled. The initializer can therefore map and
> > access a cache controller that the device tree marks unavailable.
> >
> > Select the first available matching node before accessing its registers.
> > This also handles a disabled node preceding an enabled one.
> >
> > Fixes: a967a289f169 ("RISC-V: sifive_l2_cache: Add L2 cache controller driver for SiFive SoCs")
> > Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
> > ---
> > drivers/cache/sifive_ccache.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/cache/sifive_ccache.c b/drivers/cache/sifive_ccache.c
> > index 71d3f94987fa..02878d54381d 100644
> > --- a/drivers/cache/sifive_ccache.c
> > +++ b/drivers/cache/sifive_ccache.c
> > @@ -297,7 +297,9 @@ static int __init sifive_ccache_init(void)
> > unsigned long quirks __maybe_unused;
> > int rc;
> >
> > - np = of_find_matching_node_and_match(NULL, sifive_ccache_ids, &match);
> > + for_each_matching_node_and_match(np, sifive_ccache_ids, &match)
> > + if (of_device_is_available(np))
>
> Are there any devices where this is actually possible? IOW, where there
> are 2 ccache instances.
>
> > + break;
> > if (!np)
> > return -ENODEV;
> >
> >
> > base-commit: 65ba8f34ec886ec72b2c07ddc8cf3d815c32869d
> > --
> > 2.43.0
> >
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] cache: sifive_ccache: skip disabled device tree nodes
2026-11-14 17:40 ` Avi
@ 2026-11-16 17:20 ` Conor Dooley
0 siblings, 0 replies; 4+ messages in thread
From: Conor Dooley @ 2026-11-16 17:20 UTC (permalink / raw)
To: Avi; +Cc: linux-riscv, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2771 bytes --]
On Sat, Nov 14, 2026 at 07:40:42PM +0200, Avi wrote:
> On Thu, Nov 5, 2026 at 8:24 PM Conor Dooley <conor@kernel.org> wrote:
> >
> > On Wed, Oct 28, 2026 at 03:19:40PM +0200, Avi Weiss wrote:
> > > sifive_ccache_init() uses of_find_matching_node_and_match(), which also
> > > returns nodes marked as disabled. The initializer can therefore map and
> > > access a cache controller that the device tree marks unavailable.
> > >
> > > Select the first available matching node before accessing its registers.
> > > This also handles a disabled node preceding an enabled one.
> > >
> > > Fixes: a967a289f169 ("RISC-V: sifive_l2_cache: Add L2 cache controller driver for SiFive SoCs")
> > > Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
> > > ---
> > > drivers/cache/sifive_ccache.c | 4 +++-
> > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/cache/sifive_ccache.c b/drivers/cache/sifive_ccache.c
> > > index 71d3f94987fa..02878d54381d 100644
> > > --- a/drivers/cache/sifive_ccache.c
> > > +++ b/drivers/cache/sifive_ccache.c
> > > @@ -297,7 +297,9 @@ static int __init sifive_ccache_init(void)
> > > unsigned long quirks __maybe_unused;
> > > int rc;
> > >
> > > - np = of_find_matching_node_and_match(NULL, sifive_ccache_ids, &match);
> > > + for_each_matching_node_and_match(np, sifive_ccache_ids, &match)
> > > + if (of_device_is_available(np))
> >
> > Are there any devices where this is actually possible? IOW, where there
> > are 2 ccache instances.
> It's more of a defensive thing. The 2 ccache instance was an example -
> the issue is also relevant for one disabled ccache node no?
That is true.
And on the two node front, the driver doesn't support that anyway either
before or after the patch. Consider what the new code does if there are
two nodes, both enabled.
But I don't think the ccache or llc-cache successor are intended for
that kind of situation anyway.
> Since of_find_matching_node_and_match() doesn't check whether a node
> is enabled, it can return a disabled one.
>
> sifive_ccache_init() then goes ahead and maps and accesses its
> registers, even though the device tree marks it as disabled and normal
> OF platform-device creation would skip it.
Could we instead drop the loop and just check for availability, while
retaining of_find_matching_node_and_match()? I kinda feel like the loop
gives the impression that the driver supports multiple nodes, when it
realistically does not.
Cheers,
Conor.
>
> >
> > > + break;
> > > if (!np)
> > > return -ENODEV;
> > >
> > >
> > > base-commit: 65ba8f34ec886ec72b2c07ddc8cf3d815c32869d
> > > --
> > > 2.43.0
> > >
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-16 17:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-28 13:19 [PATCH] cache: sifive_ccache: skip disabled device tree nodes Avi Weiss
2026-11-05 18:24 ` Conor Dooley
2026-11-14 17:40 ` Avi
2026-11-16 17:20 ` Conor Dooley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®