public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6.1 v1] RISC-V: fix lock splat in riscv_cpufeature_patch_func()
@ 2023-05-09 21:36 Conor Dooley
  2023-05-11 23:39 ` Sasha Levin
  0 siblings, 1 reply; 4+ messages in thread
From: Conor Dooley @ 2023-05-09 21:36 UTC (permalink / raw)
  To: stable; +Cc: conor, Conor Dooley, palmer, Guenter Roeck

From: Conor Dooley <conor.dooley@microchip.com>

Guenter reported a lockdep splat that appears to have been present for a
while in v6.1.y & the backports of the riscv_patch_in_stop_machine dance
did nothing to help here, as the lock is not being taken when
patch_text_nosync() is called in riscv_cpufeature_patch_func().
Add the lock/unlock; elide the splat.

Fixes: c15ac4fd60d5 ("riscv/ftrace: Add dynamic function tracer support")
Reported-by: Guenter Roeck <linux@roeck-us.net>
cc: stable@vger.kernel.org
Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
---
 arch/riscv/kernel/cpufeature.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
index 694267d1fe81..fd1238df6149 100644
--- a/arch/riscv/kernel/cpufeature.c
+++ b/arch/riscv/kernel/cpufeature.c
@@ -9,6 +9,7 @@
 #include <linux/bitmap.h>
 #include <linux/ctype.h>
 #include <linux/libfdt.h>
+#include <linux/memory.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <asm/alternative.h>
@@ -316,8 +317,11 @@ void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin,
 		}
 
 		tmp = (1U << alt->errata_id);
-		if (cpu_req_feature & tmp)
+		if (cpu_req_feature & tmp) {
+			mutex_lock(&text_mutex);
 			patch_text_nosync(alt->old_ptr, alt->alt_ptr, alt->alt_len);
+			mutex_unlock(&text_mutex);
+		}
 	}
 }
 #endif
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 6.1 v1] RISC-V: fix lock splat in riscv_cpufeature_patch_func()
@ 2023-05-10 20:40 Guenter Roeck
  0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2023-05-10 20:40 UTC (permalink / raw)
  To: Conor Dooley; +Cc: stable, Conor Dooley, palmer

On Tue, May 09, 2023 at 10:36:42PM +0100, Conor Dooley wrote:
> From: Conor Dooley <conor.dooley@microchip.com>
> 
> Guenter reported a lockdep splat that appears to have been present for a
> while in v6.1.y & the backports of the riscv_patch_in_stop_machine dance
> did nothing to help here, as the lock is not being taken when
> patch_text_nosync() is called in riscv_cpufeature_patch_func().
> Add the lock/unlock; elide the splat.
> 
> Fixes: c15ac4fd60d5 ("riscv/ftrace: Add dynamic function tracer support")
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> cc: stable@vger.kernel.org
> Signed-off-by: Conor Dooley <conor.dooley@microchip.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

Guenter

> ---
>  arch/riscv/kernel/cpufeature.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
> index 694267d1fe81..fd1238df6149 100644
> --- a/arch/riscv/kernel/cpufeature.c
> +++ b/arch/riscv/kernel/cpufeature.c
> @@ -9,6 +9,7 @@
>  #include <linux/bitmap.h>
>  #include <linux/ctype.h>
>  #include <linux/libfdt.h>
> +#include <linux/memory.h>
>  #include <linux/module.h>
>  #include <linux/of.h>
>  #include <asm/alternative.h>
> @@ -316,8 +317,11 @@ void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin,
>  		}
>  
>  		tmp = (1U << alt->errata_id);
> -		if (cpu_req_feature & tmp)
> +		if (cpu_req_feature & tmp) {
> +			mutex_lock(&text_mutex);
>  			patch_text_nosync(alt->old_ptr, alt->alt_ptr, alt->alt_len);
> +			mutex_unlock(&text_mutex);
> +		}
>  	}
>  }
>  #endif
> -- 
> 2.39.2
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 6.1 v1] RISC-V: fix lock splat in riscv_cpufeature_patch_func()
  2023-05-09 21:36 [PATCH 6.1 v1] RISC-V: fix lock splat in riscv_cpufeature_patch_func() Conor Dooley
@ 2023-05-11 23:39 ` Sasha Levin
  2023-05-12  7:03   ` Conor Dooley
  0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2023-05-11 23:39 UTC (permalink / raw)
  To: Conor Dooley; +Cc: stable, Conor Dooley, palmer, Guenter Roeck

On Tue, May 09, 2023 at 10:36:42PM +0100, Conor Dooley wrote:
>From: Conor Dooley <conor.dooley@microchip.com>
>
>Guenter reported a lockdep splat that appears to have been present for a
>while in v6.1.y & the backports of the riscv_patch_in_stop_machine dance
>did nothing to help here, as the lock is not being taken when
>patch_text_nosync() is called in riscv_cpufeature_patch_func().
>Add the lock/unlock; elide the splat.

Is this not a problem upstream?

-- 
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 6.1 v1] RISC-V: fix lock splat in riscv_cpufeature_patch_func()
  2023-05-11 23:39 ` Sasha Levin
@ 2023-05-12  7:03   ` Conor Dooley
  0 siblings, 0 replies; 4+ messages in thread
From: Conor Dooley @ 2023-05-12  7:03 UTC (permalink / raw)
  To: Sasha Levin; +Cc: Conor Dooley, stable, palmer, Guenter Roeck

[-- Attachment #1: Type: text/plain, Size: 1409 bytes --]

On Thu, May 11, 2023 at 07:39:25PM -0400, Sasha Levin wrote:
> On Tue, May 09, 2023 at 10:36:42PM +0100, Conor Dooley wrote:
> > From: Conor Dooley <conor.dooley@microchip.com>
> > 
> > Guenter reported a lockdep splat that appears to have been present for a
> > while in v6.1.y & the backports of the riscv_patch_in_stop_machine dance
> > did nothing to help here, as the lock is not being taken when
> > patch_text_nosync() is called in riscv_cpufeature_patch_func().
> > Add the lock/unlock; elide the splat.
> 
> Is this not a problem upstream?

It is not. Nor is it a problem in 6.2 either.
In fact, looking at it at a time other than 22h30, I notice that this is
not a complete patch. Instead we need to backport commit 9493e6f3ce02
("RISC-V: take text_mutex during alternative patching") and bf89b7ee52af
("RISC-V: fix taking the text_mutex twice during sifive errata patching")
to 6.1. The automagic version failed:
https://lore.kernel.org/stable/a2a21e9c-41ec-46dd-b792-6314c5fa4241@spud/

And I was of the opinion that this was not needed for kernels without
commit 702e64550b12 ("riscv: fpu: switch has_fpu() to
riscv_has_extension_likely()").

I'll go send those now, I am surprised noone has complained about the
SiFive errata causing a splat, but I guess noone with that hardware is
testing stable. The T-HEAD errata has no functional users in 6.1.

Thanks,
Conor.

[-- 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:[~2023-05-12  7:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-09 21:36 [PATCH 6.1 v1] RISC-V: fix lock splat in riscv_cpufeature_patch_func() Conor Dooley
2023-05-11 23:39 ` Sasha Levin
2023-05-12  7:03   ` Conor Dooley
  -- strict thread matches above, loose matches on Subject: below --
2023-05-10 20:40 Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox