Skip to content

Commit be693ef

Browse files
Merge patch series "RISC-V: Fixes for riscv_has_extension[un]likely()'s alternative dependency"
Conor Dooley <conor.dooley@microchip.com> says: Here's my attempt at fixing both the use of an FPU on XIP kernels and the issue that Jason ran into where CONFIG_FPU, which needs the alternatives frame work for has_fpu() checks, could be enabled without the alternatives actually being present. For the former, a "slow" fallback that does not use alternatives is added to riscv_has_extension_[un]likely() that can be used with XIP. Obviously, we want to make use of Jisheng's alternatives based approach where possible, so any users of riscv_has_extension_[un]likely() will want to make sure that they select RISCV_ALTERNATIVE. If they don't however, they'll hit the fallback path which (should, sparing a silly mistake from me!) behave in the same way, thus succeeding silently. Sounds like a To prevent "depends on !XIP_KERNEL; select RISCV_ALTERNATIVE" spreading like the plague through the various places that want to check for the presence of extensions, and sidestep the potential silent "success" mentioned above, all users RISCV_ALTERNATIVE are converted from selects to dependencies, with the option being selected for all !XIP_KERNEL builds. I know that the VDSO was a key place that Jisheng wanted to use the new helper rather than static branches, and I think the fallback path should not cause issues there. See the thread at [1] for the prior discussion. 1 - https://lore.kernel.org/linux-riscv/20230128172856.3814-1-jszhang@kernel.org/T/#m21390d570997145d31dd8bb95002fd61f99c6573 [Palmer: these were also merged into fixes, but there's a cleanup that depends on the merge so I'm taking it into for-next as well.] * b4-shazam-merge: RISC-V: always select RISCV_ALTERNATIVE for non-xip kernels RISC-V: add non-alternative fallback for riscv_has_extension_[un]likely() Link: https://lore.kernel.org/r/20230324100538.3514663-1-conor.dooley@microchip.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> * commit '1ee7fc3f4d0a93831a20d5566f203d5ad6d44de8': RISC-V: always select RISCV_ALTERNATIVE for non-xip kernels RISC-V: add non-alternative fallback for riscv_has_extension_[un]likely()
2 parents e97be4f + 1ee7fc3 commit be693ef

3 files changed

Lines changed: 38 additions & 30 deletions

File tree

arch/riscv/Kconfig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ config RISCV
127127
select OF_IRQ
128128
select PCI_DOMAINS_GENERIC if PCI
129129
select PCI_MSI if PCI
130+
select RISCV_ALTERNATIVE if !XIP_KERNEL
130131
select RISCV_INTC
131132
select RISCV_TIMER if RISCV_SBI
132133
select SIFIVE_PLIC
@@ -420,9 +421,8 @@ config RISCV_ISA_SVNAPOT
420421
config RISCV_ISA_SVPBMT
421422
bool "SVPBMT extension support"
422423
depends on 64BIT && MMU
423-
depends on !XIP_KERNEL
424+
depends on RISCV_ALTERNATIVE
424425
default y
425-
select RISCV_ALTERNATIVE
426426
help
427427
Adds support to dynamically detect the presence of the SVPBMT
428428
ISA-extension (Supervisor-mode: page-based memory types) and
@@ -447,8 +447,8 @@ config TOOLCHAIN_HAS_ZBB
447447
config RISCV_ISA_ZBB
448448
bool "Zbb extension support for bit manipulation instructions"
449449
depends on TOOLCHAIN_HAS_ZBB
450-
depends on !XIP_KERNEL && MMU
451-
select RISCV_ALTERNATIVE
450+
depends on MMU
451+
depends on RISCV_ALTERNATIVE
452452
default y
453453
help
454454
Adds support to dynamically detect the presence of the ZBB
@@ -462,9 +462,9 @@ config RISCV_ISA_ZBB
462462

463463
config RISCV_ISA_ZICBOM
464464
bool "Zicbom extension support for non-coherent DMA operation"
465-
depends on !XIP_KERNEL && MMU
465+
depends on MMU
466+
depends on RISCV_ALTERNATIVE
466467
default y
467-
select RISCV_ALTERNATIVE
468468
select RISCV_DMA_NONCOHERENT
469469
help
470470
Adds support to dynamically detect the presence of the ZICBOM

arch/riscv/Kconfig.errata

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ menu "CPU errata selection"
22

33
config ERRATA_SIFIVE
44
bool "SiFive errata"
5-
depends on !XIP_KERNEL
6-
select RISCV_ALTERNATIVE
5+
depends on RISCV_ALTERNATIVE
76
help
87
All SiFive errata Kconfig depend on this Kconfig. Disabling
98
this Kconfig will disable all SiFive errata. Please say "Y"
@@ -35,8 +34,7 @@ config ERRATA_SIFIVE_CIP_1200
3534

3635
config ERRATA_THEAD
3736
bool "T-HEAD errata"
38-
depends on !XIP_KERNEL
39-
select RISCV_ALTERNATIVE
37+
depends on RISCV_ALTERNATIVE
4038
help
4139
All T-HEAD errata Kconfig depend on this Kconfig. Disabling
4240
this Kconfig will disable all T-HEAD errata. Please say "Y"

arch/riscv/include/asm/hwcap.h

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,31 @@ struct riscv_isa_ext_data {
5959
unsigned int isa_ext_id;
6060
};
6161

62+
unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap);
63+
64+
#define riscv_isa_extension_mask(ext) BIT_MASK(RISCV_ISA_EXT_##ext)
65+
66+
bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, int bit);
67+
#define riscv_isa_extension_available(isa_bitmap, ext) \
68+
__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_##ext)
69+
6270
static __always_inline bool
6371
riscv_has_extension_likely(const unsigned long ext)
6472
{
6573
compiletime_assert(ext < RISCV_ISA_EXT_MAX,
6674
"ext must be < RISCV_ISA_EXT_MAX");
6775

68-
asm_volatile_goto(
69-
ALTERNATIVE("j %l[l_no]", "nop", 0, %[ext], 1)
70-
:
71-
: [ext] "i" (ext)
72-
:
73-
: l_no);
76+
if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) {
77+
asm_volatile_goto(
78+
ALTERNATIVE("j %l[l_no]", "nop", 0, %[ext], 1)
79+
:
80+
: [ext] "i" (ext)
81+
:
82+
: l_no);
83+
} else {
84+
if (!__riscv_isa_extension_available(NULL, ext))
85+
goto l_no;
86+
}
7487

7588
return true;
7689
l_no:
@@ -83,26 +96,23 @@ riscv_has_extension_unlikely(const unsigned long ext)
8396
compiletime_assert(ext < RISCV_ISA_EXT_MAX,
8497
"ext must be < RISCV_ISA_EXT_MAX");
8598

86-
asm_volatile_goto(
87-
ALTERNATIVE("nop", "j %l[l_yes]", 0, %[ext], 1)
88-
:
89-
: [ext] "i" (ext)
90-
:
91-
: l_yes);
99+
if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) {
100+
asm_volatile_goto(
101+
ALTERNATIVE("nop", "j %l[l_yes]", 0, %[ext], 1)
102+
:
103+
: [ext] "i" (ext)
104+
:
105+
: l_yes);
106+
} else {
107+
if (__riscv_isa_extension_available(NULL, ext))
108+
goto l_yes;
109+
}
92110

93111
return false;
94112
l_yes:
95113
return true;
96114
}
97115

98-
unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap);
99-
100-
#define riscv_isa_extension_mask(ext) BIT_MASK(RISCV_ISA_EXT_##ext)
101-
102-
bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, int bit);
103-
#define riscv_isa_extension_available(isa_bitmap, ext) \
104-
__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_##ext)
105-
106116
#endif
107117

108118
#endif /* _ASM_RISCV_HWCAP_H */

0 commit comments

Comments
 (0)