Skip to contentSkip to conversation

riscv: Ensure isa-ext static keys are writable

PATCH In review Andrew Jones 6 participants 10 messages Aug 16, 2022 – Aug 17, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: Ensure isa-ext static keys are writable

riscv_isa_ext_keys[] is an array of static keys used in the unified ISA extension framework. The keys added to this array may be used anywhere, including in modules. Ensure the keys remain writable by placing them in the data section.

The need to change riscv_isa_ext_keys[]'s section was found when the kvm module started failing to load. Commit 8eb060e10185 ("arch/riscv:
add Zihintpause support") adds a static branch check for a newly added isa-ext key to cpu_relax(), which kvm uses.

Fixes c360cbec3511 ("riscv: introduce unified static key mechanism for ISA extensions")
---
 arch/riscv/kernel/cpufeature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cpufeature.c +1 -1
index 553d755483ed..3b5583db9d80 100644
@@ -28,7 +28,7 @@ unsigned long elf_hwcap __read_mostly;
 /* Host ISA bitmap */
 static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
 
-__ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
+DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
 EXPORT_SYMBOL(riscv_isa_ext_keys);
 
 /**
Signature · 1 line
2.37.1
#1 lore raw
Quoted 11 lines · Andrew Jones

riscv_isa_ext_keys[] is an array of static keys used in the unified ISA extension framework. The keys added to this array may be used anywhere, including in modules. Ensure the keys remain writable by placing them in the data section.

The need to change riscv_isa_ext_keys[]'s section was found when the kvm module started failing to load. Commit 8eb060e10185 ("arch/riscv:
add Zihintpause support") adds a static branch check for a newly added isa-ext key to cpu_relax(), which kvm uses.

Fixes c360cbec3511 ("riscv: introduce unified static key mechanism for ISA extensions")

Hey Drew,
How about adding:

Thanks,
Conor.

Quoted 18 lines
---
 arch/riscv/kernel/cpufeature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cpufeature.c +1 -1
index 553d755483ed..3b5583db9d80 100644
@@ -28,7 +28,7 @@ unsigned long elf_hwcap __read_mostly;
 /* Host ISA bitmap */
 static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
 
-__ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
+DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
 EXPORT_SYMBOL(riscv_isa_ext_keys);
 
 /**
#2 lore raw
Quoted 11 lines · Conor.Dooley at microchip.com
Quoted 10 lines · Andrew Jones

riscv_isa_ext_keys[] is an array of static keys used in the unified ISA extension framework. The keys added to this array may be used anywhere, including in modules. Ensure the keys remain writable by placing them in the data section.

The need to change riscv_isa_ext_keys[]'s section was found when the kvm module started failing to load. Commit 8eb060e10185 ("arch/riscv:
add Zihintpause support") adds a static branch check for a newly added isa-ext key to cpu_relax(), which kvm uses.

Quoted 8 lines
Quoted 1 line
Fixes c360cbec3511 ("riscv: introduce unified static key mechanism for ISA extensions")

Hey Drew,
How about adding:

Sure, should I repost or can those be picked up when/if the patch is picked up?

Thanks,
drew

Quoted 22 lines

Thanks,
Conor.

Quoted 18 lines
---
 arch/riscv/kernel/cpufeature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cpufeature.c +1 -1
index 553d755483ed..3b5583db9d80 100644
@@ -28,7 +28,7 @@ unsigned long elf_hwcap __read_mostly;
 /* Host ISA bitmap */
 static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
 
-__ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
+DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
 EXPORT_SYMBOL(riscv_isa_ext_keys);
 
 /**
#3 lore raw
Quoted 17 lines · Andrew Jones
Quoted 16 lines · Conor.Dooley at microchip.com
Quoted 11 lines · Andrew Jones

riscv_isa_ext_keys[] is an array of static keys used in the unified ISA extension framework. The keys added to this array may be used anywhere, including in modules. Ensure the keys remain writable by placing them in the data section.

The need to change riscv_isa_ext_keys[]'s section was found when the kvm module started failing to load. Commit 8eb060e10185 ("arch/riscv:
add Zihintpause support") adds a static branch check for a newly added isa-ext key to cpu_relax(), which kvm uses.

Fixes c360cbec3511 ("riscv: introduce unified static key mechanism for ISA extensions")

Hey Drew,
How about adding:

Quoted 6 lines
Quoted 3 lines

Sure, should I repost or can those be picked up when/if the patch is picked up?

Oh god no, don't repost for that alone.
Sorry, should've specified.
Conor.

Quoted 31 lines

Thanks,
drew

Quoted 17 lines

Thanks,
Conor.

Quoted 13 lines
---
 arch/riscv/kernel/cpufeature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cpufeature.c +0 -0
index 553d755483ed..3b5583db9d80 100644
@@ -28,7 +28,7 @@ unsigned long elf_hwcap __read_mostly;
 /* Host ISA bitmap */
 static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
 
Quoted 5 lines

arch/riscv/kernel/cpufeature.c unsigned long elf_hwcap __read_mostly; · line 34

Quoted 5 lines
arch/riscv/kernel/cpufeature.c +1 -1
-__ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
+DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
 EXPORT_SYMBOL(riscv_isa_ext_keys);
 
 /**

_______________________________________________
linux-riscv mailing list
linux-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

Tested-by on v1 1/1
#4 lore raw
In reply to Andrew Jones
Quoted 7 lines · Andrew Jones

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

riscv_isa_ext_keys[] is an array of static keys used in the unified ISA extension framework. The keys added to this array may be used anywhere, including in modules. Ensure the keys remain writable by placing them in the data section.

Quoted 7 lines

The need to change riscv_isa_ext_keys[]'s section was found when the kvm module started failing to load. Commit 8eb060e10185 ("arch/riscv:
add Zihintpause support") adds a static branch check for a newly added isa-ext key to cpu_relax(), which kvm uses.

Fixes c360cbec3511 ("riscv: introduce unified static key mechanism for ISA extensions")

Thanks for the fix!

Still got issues booting mainline on my D1, but this is no longer one of them :)

Quoted 20 lines
---
 arch/riscv/kernel/cpufeature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cpufeature.c +1 -2
index 553d755483ed..3b5583db9d80 100644
@@ -28,7 +28,7 @@ unsigned long elf_hwcap __read_mostly;
 /* Host ISA bitmap */
 static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
 
-__ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
+DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
 EXPORT_SYMBOL(riscv_isa_ext_keys);
 
 /**
--

2.37.1

Tested-by on v1 1/1
#5 lore raw
In reply to Andrew Jones
Quoted 21 lines · Andrew Jones

riscv_isa_ext_keys[] is an array of static keys used in the unified ISA extension framework. The keys added to this array may be used anywhere, including in modules. Ensure the keys remain writable by placing them in the data section.

The need to change riscv_isa_ext_keys[]'s section was found when the kvm module started failing to load. Commit 8eb060e10185 ("arch/riscv:
add Zihintpause support") adds a static branch check for a newly added isa-ext key to cpu_relax(), which kvm uses.

Fixes c360cbec3511 ("riscv: introduce unified static key mechanism for ISA extensions")
---
  arch/riscv/kernel/cpufeature.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cpufeature.c +0 -0
index 553d755483ed..3b5583db9d80 100644

arch/riscv/kernel/cpufeature.c unsigned long elf_hwcap __read_mostly; · line 34

Quoted 8 lines
arch/riscv/kernel/cpufeature.c +1 -1
@@ -28,7 +28,7 @@ unsigned long elf_hwcap __read_mostly;
  /* Host ISA bitmap */
  static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
 
-__ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
+DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
  EXPORT_SYMBOL(riscv_isa_ext_keys);
 
  /**

Works good on HiFive Unmatched.

Tested-by on v1 1/1
#6 lore raw
In reply to Andrew Jones
Quoted 34 lines · Andrew Jones

riscv_isa_ext_keys[] is an array of static keys used in the unified ISA extension framework. The keys added to this array may be used anywhere, including in modules. Ensure the keys remain writable by placing them in the data section.

The need to change riscv_isa_ext_keys[]'s section was found when the kvm module started failing to load. Commit 8eb060e10185 ("arch/riscv:
add Zihintpause support") adds a static branch check for a newly added isa-ext key to cpu_relax(), which kvm uses.

Fixes c360cbec3511 ("riscv: introduce unified static key mechanism for ISA extensions")
---
 arch/riscv/kernel/cpufeature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cpufeature.c +1 -2
index 553d755483ed..3b5583db9d80 100644
@@ -28,7 +28,7 @@ unsigned long elf_hwcap __read_mostly;
 /* Host ISA bitmap */
 static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
 
-__ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
+DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
 EXPORT_SYMBOL(riscv_isa_ext_keys);
 
 /**
--

2.37.1

Quoted 4 lines

--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

Thanks for the quick fix. Tested with kvm guests booting in Qemu.

Signature · 2 lines
Regards,
Atish
maintainer
#7 lore raw
Quoted 35 lines · atishp at atishpatra.org
Quoted 34 lines · Andrew Jones

riscv_isa_ext_keys[] is an array of static keys used in the unified ISA extension framework. The keys added to this array may be used anywhere, including in modules. Ensure the keys remain writable by placing them in the data section.

The need to change riscv_isa_ext_keys[]'s section was found when the kvm module started failing to load. Commit 8eb060e10185 ("arch/riscv:
add Zihintpause support") adds a static branch check for a newly added isa-ext key to cpu_relax(), which kvm uses.

Fixes c360cbec3511 ("riscv: introduce unified static key mechanism for ISA extensions")
---
 arch/riscv/kernel/cpufeature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cpufeature.c +1 -2
index 553d755483ed..3b5583db9d80 100644
@@ -28,7 +28,7 @@ unsigned long elf_hwcap __read_mostly;
 /* Host ISA bitmap */
 static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
 
-__ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
+DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
 EXPORT_SYMBOL(riscv_isa_ext_keys);
 
 /**
--

2.37.1

Quoted 8 lines
Quoted 4 lines

--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

Thanks for the quick fix. Tested with kvm guests booting in Qemu.

Thanks, I hadn't realized how static keys work but looks like having them as __ro_after_init was always bogus. Sorry to break stuff, looks like I should be loading some module (probably KVM, as it's in the defconfig) during testing.

This is on fixes, I'm planning on sending it up later this week.

Reviewed-by
#8 lore raw
Quoted 36 lines · Palmer Dabbelt
Quoted 35 lines · atishp at atishpatra.org
Quoted 34 lines · Andrew Jones

riscv_isa_ext_keys[] is an array of static keys used in the unified ISA extension framework. The keys added to this array may be used anywhere, including in modules. Ensure the keys remain writable by placing them in the data section.

The need to change riscv_isa_ext_keys[]'s section was found when the kvm module started failing to load. Commit 8eb060e10185 ("arch/riscv:
add Zihintpause support") adds a static branch check for a newly added isa-ext key to cpu_relax(), which kvm uses.

Quoted 1 line
Quoted 1 line
Fixes c360cbec3511 ("riscv: introduce unified static key mechanism for ISA extensions")
Quoted 1 line
Quoted 1 line

---

 arch/riscv/kernel/cpufeature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cpufeature.c +1 -2
index 553d755483ed..3b5583db9d80 100644
@@ -28,7 +28,7 @@ unsigned long elf_hwcap __read_mostly;
 /* Host ISA bitmap */
 static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
 
-__ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
+DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
 EXPORT_SYMBOL(riscv_isa_ext_keys);
 
 /**
--

2.37.1

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

Thanks for the quick fix. Tested with kvm guests booting in Qemu.

Thanks for catching the bug in my code.

Quoted 3 lines

Thanks, I hadn't realized how static keys work but looks like having them as __ro_after_init was always bogus. Sorry to break stuff, looks like I should be

Sorry for breaking the static isa extension key usage in modules. It's a good idea to make them readonly, but need to cope with the usage in module properly. This may be a good improvement item.

Quoted 3 lines

loading some module (probably KVM, as it's in the defconfig) during testing.

This is on fixes, I'm planning on sending it up later this week.

#9 lore raw
Quoted 51 lines · Jisheng Zhang
Quoted 36 lines · Palmer Dabbelt
Quoted 35 lines · atishp at atishpatra.org
Quoted 34 lines · Andrew Jones

riscv_isa_ext_keys[] is an array of static keys used in the unified ISA extension framework. The keys added to this array may be used anywhere, including in modules. Ensure the keys remain writable by placing them in the data section.

The need to change riscv_isa_ext_keys[]'s section was found when the kvm module started failing to load. Commit 8eb060e10185 ("arch/riscv:
add Zihintpause support") adds a static branch check for a newly added isa-ext key to cpu_relax(), which kvm uses.

Quoted 1 line
Quoted 1 line
Fixes c360cbec3511 ("riscv: introduce unified static key mechanism for ISA extensions")
Quoted 1 line
Quoted 1 line

---

 arch/riscv/kernel/cpufeature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cpufeature.c +1 -2
index 553d755483ed..3b5583db9d80 100644
@@ -28,7 +28,7 @@ unsigned long elf_hwcap __read_mostly;
 /* Host ISA bitmap */
 static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
 
-__ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
+DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX);
 EXPORT_SYMBOL(riscv_isa_ext_keys);
 
 /**
--

2.37.1

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

Thanks for the quick fix. Tested with kvm guests booting in Qemu.

Thanks for catching the bug in my code.

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

Thanks, I hadn't realized how static keys work but looks like having them as __ro_after_init was always bogus. Sorry to break stuff, looks like I should be

Sorry for breaking the static isa extension key usage in modules. It's a good idea to make them readonly, but need to cope with the usage in module properly. This may be a good improvement item.

While some static keys do use __ro_after_init, they're almost all locally defined (static __ro_after_init). I see a few instances of __read_mostly global static key definitions, though. That may make sense for riscv_isa_ext_keys[] as well.

Thanks,
drew