Skip to contentSkip to conversation

riscv: Fix alternatives issues on for-next

PATCH Applied Samuel Holland 7 participants 13 messages Feb 12, 2023 – Feb 15, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

cover riscv: Fix alternatives issues on for-next

Several people have reported that D1 fails to boot on linux-next. Patch 1 fixes a bug where early alternative patching used the wrong address. Patch 2 fixes a separate issue where the Zbb alternatives are incorrectly applied based on the 'C' extension instead of Zbb.

Samuel Holland (2):
riscv: Fix early alternative patching
riscv: Fix Zbb alternative IDs

 arch/riscv/errata/thead/errata.c     | 4 +---
 arch/riscv/include/asm/errata_list.h | 5 -----
 arch/riscv/lib/strcmp.S              | 2 +-
 arch/riscv/lib/strlen.S              | 2 +-
 arch/riscv/lib/strncmp.S             | 2 +-
 5 files changed, 4 insertions(+), 11 deletions(-)
Signature · 1 line
2.37.4
#1 lore raw

PATCH 1/2 riscv: Fix early alternative patching

Now that the text to patch is located using a relative offset from the alternative entry, the text address should be computed without applying the kernel mapping offset, both before and after VM setup.

Fixes 8d23e94a4433 ("riscv: switch to relative alternative entries")

---

 arch/riscv/errata/thead/errata.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/riscv/errata/thead/errata.c +1 -3
index c0bea5c94128..1dd90a5f86f0 100644
@@ -102,9 +102,7 @@ void __init_or_module thead_errata_patch_func(struct alt_entry *begin, struct al
 
 			/* On vm-alternatives, the mmu isn't running yet */
 			if (stage == RISCV_ALTERNATIVES_EARLY_BOOT)
-				memcpy((void *)__pa_symbol(oldptr),
-				       (void *)__pa_symbol(altptr),
-				       alt->alt_len);
+				memcpy(oldptr, altptr, alt->alt_len);
 			else
 				patch_text_nosync(oldptr, altptr, alt->alt_len);
 		}
Signature · 1 line
2.37.4
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] riscv: Fix early alternative patching

Quoted 5 lines · Samuel Holland

Now that the text to patch is located using a relative offset from the alternative entry, the text address should be computed without applying the kernel mapping offset, both before and after VM setup.

Fixes 8d23e94a4433 ("riscv: switch to relative alternative entries")
Quoted 24 lines

---

 arch/riscv/errata/thead/errata.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/riscv/errata/thead/errata.c +1 -3
index c0bea5c94128..1dd90a5f86f0 100644
@@ -102,9 +102,7 @@ void __init_or_module thead_errata_patch_func(struct alt_entry *begin, struct al
 
 			/* On vm-alternatives, the mmu isn't running yet */
 			if (stage == RISCV_ALTERNATIVES_EARLY_BOOT)
-				memcpy((void *)__pa_symbol(oldptr),
-				       (void *)__pa_symbol(altptr),
-				       alt->alt_len);
+				memcpy(oldptr, altptr, alt->alt_len);
 			else
 				patch_text_nosync(oldptr, altptr, alt->alt_len);
 		}
Signature · 1 line
2.37.4
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] riscv: Fix early alternative patching

In reply to Samuel Holland
Quoted 28 lines · Samuel Holland

Now that the text to patch is located using a relative offset from the alternative entry, the text address should be computed without applying the kernel mapping offset, both before and after VM setup.

Fixes 8d23e94a4433 ("riscv: switch to relative alternative entries")

---

 arch/riscv/errata/thead/errata.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/riscv/errata/thead/errata.c +1 -4
index c0bea5c94128..1dd90a5f86f0 100644
@@ -102,9 +102,7 @@ void __init_or_module thead_errata_patch_func(struct alt_entry *begin, struct al
 
                        /* On vm-alternatives, the mmu isn't running yet */
                        if (stage == RISCV_ALTERNATIVES_EARLY_BOOT)
-                               memcpy((void *)__pa_symbol(oldptr),
-                                      (void *)__pa_symbol(altptr),
-                                      alt->alt_len);
+                               memcpy(oldptr, altptr, alt->alt_len);
                        else
                                patch_text_nosync(oldptr, altptr, alt->alt_len);
                }
--
Quoted 2 lines

2.37.4

Signature · 2 lines
Best Regards
 Guo Ren
Reviewed-by on v1 1/2
#4 lore raw

Re: [PATCH 1/2] riscv: Fix early alternative patching

In reply to Samuel Holland
Quoted 3 lines · Samuel Holland

Now that the text to patch is located using a relative offset from the alternative entry, the text address should be computed without applying the kernel mapping offset, both before and after VM setup.

Good catch!

Quoted 3 lines
Fixes 8d23e94a4433 ("riscv: switch to relative alternative entries")
Quoted 23 lines

---

 arch/riscv/errata/thead/errata.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/riscv/errata/thead/errata.c +1 -3
index c0bea5c94128..1dd90a5f86f0 100644
@@ -102,9 +102,7 @@ void __init_or_module thead_errata_patch_func(struct alt_entry *begin, struct al
 
 			/* On vm-alternatives, the mmu isn't running yet */
 			if (stage == RISCV_ALTERNATIVES_EARLY_BOOT)
-				memcpy((void *)__pa_symbol(oldptr),
-				       (void *)__pa_symbol(altptr),
-				       alt->alt_len);
+				memcpy(oldptr, altptr, alt->alt_len);
 			else
 				patch_text_nosync(oldptr, altptr, alt->alt_len);
 		}
Signature · 1 line
2.37.4

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#5 lore raw

PATCH 2/2 riscv: Fix Zbb alternative IDs

In reply to Samuel Holland

Commit 4bf8860760d9 ("riscv: cpufeature: extend riscv_cpufeature_patch_func to all ISA extensions") switched ISA extension alternatives to use the RISCV_ISA_EXT_* macros instead of CPUFEATURE_*. This was mismerged when applied on top of the Zbb series, so the Zbb alternatives referenced the wrong errata ID values.

Fixes 9daca9a5b9ac ("Merge patch series "riscv: improve boot time isa extensions handling"")

---

 arch/riscv/include/asm/errata_list.h | 5 -----
 arch/riscv/lib/strcmp.S              | 2 +-
 arch/riscv/lib/strlen.S              | 2 +-
 arch/riscv/lib/strncmp.S             | 2 +-
 4 files changed, 3 insertions(+), 8 deletions(-)
arch/riscv/include/asm/errata_list.h +0 -5
index e158439029ce..274c6f889602 100644
@@ -23,11 +23,6 @@
 #define	ERRATA_THEAD_NUMBER 3
 #endif
 
-#define	CPUFEATURE_SVPBMT 0
-#define	CPUFEATURE_ZICBOM 1
-#define	CPUFEATURE_ZBB 2
-#define	CPUFEATURE_NUMBER 3
-
 #ifdef __ASSEMBLY__
 
 #define ALT_INSN_FAULT(x)						\
arch/riscv/lib/strcmp.S +1 -1
index 8148b6418f61..986ab23fe787 100644
@@ -9,7 +9,7 @@
 /* int strcmp(const char *cs, const char *ct) */
 SYM_FUNC_START(strcmp)
 
-	ALTERNATIVE("nop", "j strcmp_zbb", 0, CPUFEATURE_ZBB, CONFIG_RISCV_ISA_ZBB)
+	ALTERNATIVE("nop", "j strcmp_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
 
 	/*
 	 * Returns
arch/riscv/lib/strlen.S +1 -1
index 0f9dbf93301a..8345ceeee3f6 100644
@@ -9,7 +9,7 @@
 /* int strlen(const char *s) */
 SYM_FUNC_START(strlen)
 
-	ALTERNATIVE("nop", "j strlen_zbb", 0, CPUFEATURE_ZBB, CONFIG_RISCV_ISA_ZBB)
+	ALTERNATIVE("nop", "j strlen_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
 
 	/*
 	 * Returns
arch/riscv/lib/strncmp.S +1 -1
index 7940ddab2d48..ee49595075be 100644
@@ -9,7 +9,7 @@
 /* int strncmp(const char *cs, const char *ct, size_t count) */
 SYM_FUNC_START(strncmp)
 
-	ALTERNATIVE("nop", "j strncmp_zbb", 0, CPUFEATURE_ZBB, CONFIG_RISCV_ISA_ZBB)
+	ALTERNATIVE("nop", "j strncmp_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
 
 	/*
 	 * Returns
Signature · 1 line
2.37.4
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] riscv: Fix Zbb alternative IDs

Quoted 7 lines · Samuel Holland

Commit 4bf8860760d9 ("riscv: cpufeature: extend riscv_cpufeature_patch_func to all ISA extensions") switched ISA extension alternatives to use the RISCV_ISA_EXT_* macros instead of CPUFEATURE_*. This was mismerged when applied on top of the Zbb series, so the Zbb alternatives referenced the wrong errata ID values.

Fixes 9daca9a5b9ac ("Merge patch series "riscv: improve boot time isa extensions handling"")

Re: your question on irc, I think you did the right thing here as Jisheng did remove them in his series:
https://lore.kernel.org/linux-riscv/[email protected]/

Quoted 67 lines

---

 arch/riscv/include/asm/errata_list.h | 5 -----
 arch/riscv/lib/strcmp.S              | 2 +-
 arch/riscv/lib/strlen.S              | 2 +-
 arch/riscv/lib/strncmp.S             | 2 +-
 4 files changed, 3 insertions(+), 8 deletions(-)
arch/riscv/include/asm/errata_list.h +0 -5
index e158439029ce..274c6f889602 100644
@@ -23,11 +23,6 @@
 #define	ERRATA_THEAD_NUMBER 3
 #endif
 
-#define	CPUFEATURE_SVPBMT 0
-#define	CPUFEATURE_ZICBOM 1
-#define	CPUFEATURE_ZBB 2
-#define	CPUFEATURE_NUMBER 3
-
 #ifdef __ASSEMBLY__
 
 #define ALT_INSN_FAULT(x)						\
arch/riscv/lib/strcmp.S +1 -1
index 8148b6418f61..986ab23fe787 100644
@@ -9,7 +9,7 @@
 /* int strcmp(const char *cs, const char *ct) */
 SYM_FUNC_START(strcmp)
 
-	ALTERNATIVE("nop", "j strcmp_zbb", 0, CPUFEATURE_ZBB, CONFIG_RISCV_ISA_ZBB)
+	ALTERNATIVE("nop", "j strcmp_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
 
 	/*
 	 * Returns
arch/riscv/lib/strlen.S +1 -1
index 0f9dbf93301a..8345ceeee3f6 100644
@@ -9,7 +9,7 @@
 /* int strlen(const char *s) */
 SYM_FUNC_START(strlen)
 
-	ALTERNATIVE("nop", "j strlen_zbb", 0, CPUFEATURE_ZBB, CONFIG_RISCV_ISA_ZBB)
+	ALTERNATIVE("nop", "j strlen_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
 
 	/*
 	 * Returns
arch/riscv/lib/strncmp.S +1 -1
index 7940ddab2d48..ee49595075be 100644
@@ -9,7 +9,7 @@
 /* int strncmp(const char *cs, const char *ct, size_t count) */
 SYM_FUNC_START(strncmp)
 
-	ALTERNATIVE("nop", "j strncmp_zbb", 0, CPUFEATURE_ZBB, CONFIG_RISCV_ISA_ZBB)
+	ALTERNATIVE("nop", "j strncmp_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
 
 	/*
 	 * Returns
Signature · 1 line
2.37.4
Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] riscv: Fix Zbb alternative IDs

In reply to Samuel Holland
Quoted 8 lines · Samuel Holland

Commit 4bf8860760d9 ("riscv: cpufeature: extend riscv_cpufeature_patch_func to all ISA extensions") switched ISA extension alternatives to use the RISCV_ISA_EXT_* macros instead of CPUFEATURE_*. This was mismerged when applied on top of the Zbb series, so the Zbb alternatives referenced the wrong errata ID values.

Fixes 9daca9a5b9ac ("Merge patch series "riscv: improve boot time isa extensions handling"")
Quoted 8 lines

---

 arch/riscv/include/asm/errata_list.h | 5 -----
 arch/riscv/lib/strcmp.S              | 2 +-
 arch/riscv/lib/strlen.S              | 2 +-
 arch/riscv/lib/strncmp.S             | 2 +-
 4 files changed, 3 insertions(+), 8 deletions(-)

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Reviewed-by on v1 2/2
#8 lore raw

Re: [PATCH 2/2] riscv: Fix Zbb alternative IDs

In reply to Samuel Holland
Quoted 75 lines · Samuel Holland

Commit 4bf8860760d9 ("riscv: cpufeature: extend riscv_cpufeature_patch_func to all ISA extensions") switched ISA extension alternatives to use the RISCV_ISA_EXT_* macros instead of CPUFEATURE_*. This was mismerged when applied on top of the Zbb series, so the Zbb alternatives referenced the wrong errata ID values.

Fixes 9daca9a5b9ac ("Merge patch series "riscv: improve boot time isa extensions handling"")

---

 arch/riscv/include/asm/errata_list.h | 5 -----
 arch/riscv/lib/strcmp.S              | 2 +-
 arch/riscv/lib/strlen.S              | 2 +-
 arch/riscv/lib/strncmp.S             | 2 +-
 4 files changed, 3 insertions(+), 8 deletions(-)
arch/riscv/include/asm/errata_list.h +0 -5
index e158439029ce..274c6f889602 100644
@@ -23,11 +23,6 @@
 #define        ERRATA_THEAD_NUMBER 3
 #endif
 
-#define        CPUFEATURE_SVPBMT 0
-#define        CPUFEATURE_ZICBOM 1
-#define        CPUFEATURE_ZBB 2
-#define        CPUFEATURE_NUMBER 3
-
 #ifdef __ASSEMBLY__
 
 #define ALT_INSN_FAULT(x)                                              \
arch/riscv/lib/strcmp.S +1 -1
index 8148b6418f61..986ab23fe787 100644
@@ -9,7 +9,7 @@
 /* int strcmp(const char *cs, const char *ct) */
 SYM_FUNC_START(strcmp)
 
-       ALTERNATIVE("nop", "j strcmp_zbb", 0, CPUFEATURE_ZBB, CONFIG_RISCV_ISA_ZBB)
+       ALTERNATIVE("nop", "j strcmp_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
 
        /*
         * Returns
arch/riscv/lib/strlen.S +1 -1
index 0f9dbf93301a..8345ceeee3f6 100644
@@ -9,7 +9,7 @@
 /* int strlen(const char *s) */
 SYM_FUNC_START(strlen)
 
-       ALTERNATIVE("nop", "j strlen_zbb", 0, CPUFEATURE_ZBB, CONFIG_RISCV_ISA_ZBB)
+       ALTERNATIVE("nop", "j strlen_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
 
        /*
         * Returns
arch/riscv/lib/strncmp.S +1 -2
index 7940ddab2d48..ee49595075be 100644
@@ -9,7 +9,7 @@
 /* int strncmp(const char *cs, const char *ct, size_t count) */
 SYM_FUNC_START(strncmp)
 
-       ALTERNATIVE("nop", "j strncmp_zbb", 0, CPUFEATURE_ZBB, CONFIG_RISCV_ISA_ZBB)
+       ALTERNATIVE("nop", "j strncmp_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
 
        /*
         * Returns
--

2.37.4

Signature · 2 lines
Best Regards
 Guo Ren
Tested-by on the v1 series
#9 lore raw
In reply to Samuel Holland

Hey Samuel,

Quoted 4 lines · Samuel Holland

Several people have reported that D1 fails to boot on linux-next. Patch 1 fixes a bug where early alternative patching used the wrong address. Patch 2 fixes a separate issue where the Zbb alternatives are incorrectly applied based on the 'C' extension instead of Zbb.

On Icicle, Nezha & VisionFive 2:

I was really curious why my CI didn't catch this, but I think boot on Icicle wasn't broken as the toolchains pre-date Zbb and therefore it isn't even compiled in.
And the VisionFive 2 doesn't care as it has Zbb.

Thanks for the fixes :)
Conor.

#10 lore raw
In reply to Samuel Holland
Quoted 5 lines · Samuel Holland

Several people have reported that D1 fails to boot on linux-next. Patch 1 fixes a bug where early alternative patching used the wrong address. Patch 2 fixes a separate issue where the Zbb alternatives are incorrectly applied based on the 'C' extension instead of Zbb.

Great Job! Thx for fixup.

Quoted 16 lines

Samuel Holland (2):
riscv: Fix early alternative patching
riscv: Fix Zbb alternative IDs

 arch/riscv/errata/thead/errata.c     | 4 +---
 arch/riscv/include/asm/errata_list.h | 5 -----
 arch/riscv/lib/strcmp.S              | 2 +-
 arch/riscv/lib/strlen.S              | 2 +-
 arch/riscv/lib/strncmp.S             | 2 +-
 5 files changed, 4 insertions(+), 11 deletions(-)

--
2.37.4

Signature · 2 lines
Best Regards
 Guo Ren
#11 lore raw
In reply to Samuel Holland
Quoted 11 lines · Samuel Holland

Several people have reported that D1 fails to boot on linux-next. Patch 1 fixes a bug where early alternative patching used the wrong address. Patch 2 fixes a separate issue where the Zbb alternatives are incorrectly applied based on the 'C' extension instead of Zbb.

Samuel Holland (2):
riscv: Fix early alternative patching
riscv: Fix Zbb alternative IDs

[...]

Applied, thanks!

[1/2] riscv: Fix early alternative patching

      https://git.kernel.org/palmer/c/bfd6fc5d8014
[2/2] riscv: Fix Zbb alternative IDs
      https://git.kernel.org/palmer/c/d5a7fab7859d

Best regards,

Signature · 6 lines
Palmer Dabbelt <[email protected]>

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#12 lore raw
In reply to Samuel Holland
This series was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Hello:

This series was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Quoted 11 lines · On Sat, 11 Feb 2023 20:15:31 -0600 you wrote:

Several people have reported that D1 fails to boot on linux-next. Patch 1 fixes a bug where early alternative patching used the wrong address. Patch 2 fixes a separate issue where the Zbb alternatives are incorrectly applied based on the 'C' extension instead of Zbb.

Samuel Holland (2):
riscv: Fix early alternative patching
riscv: Fix Zbb alternative IDs

[...]

Here is the summary with links:
- [1/2] riscv: Fix early alternative patching

    https://git.kernel.org/riscv/c/bfd6fc5d8014
  - [2/2] riscv: Fix Zbb alternative IDs
    https://git.kernel.org/riscv/c/d5a7fab7859d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html