Skip to content

Commit 4622f15

Browse files
Merge patch series "RISC-V: Fixes for riscv_has_extension[un]likely()'s alternative dependency"
Conor Dooley <[email protected]> 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/[email protected]/T/#m21390d570997145d31dd8bb95002fd61f99c6573 [Palmer: merging in the fixes as a branch as there's some features that depend on it.] * 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/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
2 parents e89c2e8 + 1ee7fc3 commit 4622f15

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
lines changed

arch/riscv/Kconfig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ config RISCV
126126
select OF_IRQ
127127
select PCI_DOMAINS_GENERIC if PCI
128128
select PCI_MSI if PCI
129+
select RISCV_ALTERNATIVE if !XIP_KERNEL
129130
select RISCV_INTC
130131
select RISCV_TIMER if RISCV_SBI
131132
select SIFIVE_PLIC
@@ -401,9 +402,8 @@ config RISCV_ISA_C
401402
config RISCV_ISA_SVPBMT
402403
bool "SVPBMT extension support"
403404
depends on 64BIT && MMU
404-
depends on !XIP_KERNEL
405+
depends on RISCV_ALTERNATIVE
405406
default y
406-
select RISCV_ALTERNATIVE
407407
help
408408
Adds support to dynamically detect the presence of the SVPBMT
409409
ISA-extension (Supervisor-mode: page-based memory types) and
@@ -428,8 +428,8 @@ config TOOLCHAIN_HAS_ZBB
428428
config RISCV_ISA_ZBB
429429
bool "Zbb extension support for bit manipulation instructions"
430430
depends on TOOLCHAIN_HAS_ZBB
431-
depends on !XIP_KERNEL && MMU
432-
select RISCV_ALTERNATIVE
431+
depends on MMU
432+
depends on RISCV_ALTERNATIVE
433433
default y
434434
help
435435
Adds support to dynamically detect the presence of the ZBB
@@ -443,9 +443,9 @@ config RISCV_ISA_ZBB
443443

444444
config RISCV_ISA_ZICBOM
445445
bool "Zicbom extension support for non-coherent DMA operation"
446-
depends on !XIP_KERNEL && MMU
446+
depends on MMU
447+
depends on RISCV_ALTERNATIVE
447448
default y
448-
select RISCV_ALTERNATIVE
449449
select RISCV_DMA_NONCOHERENT
450450
help
451451
Adds support to dynamically detect the presence of the ZICBOM

arch/riscv/Kconfig.erratas

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
@@ -57,18 +57,31 @@ struct riscv_isa_ext_data {
5757
unsigned int isa_ext_id;
5858
};
5959

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

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

7386
return true;
7487
l_no:
@@ -81,26 +94,23 @@ riscv_has_extension_unlikely(const unsigned long ext)
8194
compiletime_assert(ext < RISCV_ISA_EXT_MAX,
8295
"ext must be < RISCV_ISA_EXT_MAX");
8396

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

91109
return false;
92110
l_yes:
93111
return true;
94112
}
95113

96-
unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap);
97-
98-
#define riscv_isa_extension_mask(ext) BIT_MASK(RISCV_ISA_EXT_##ext)
99-
100-
bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, int bit);
101-
#define riscv_isa_extension_available(isa_bitmap, ext) \
102-
__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_##ext)
103-
104114
#endif
105115

106116
#endif /* _ASM_RISCV_HWCAP_H */

0 commit comments

Comments
 (0)