riscv: hwprobe: fix has_fpu() to require D extension only
PATCH v3 1/1 riscv: hwprobe: fix has_fpu() to require D extension only
The kernel never supports F without D, since D depends on F. As such, has_fpu() checking either extension with '||' is incorrect: it reports FPU support when only F is present, which is not sufficient for D-dependent state save/restore, and weakens RISCV_HWPROBE_IMA_FD semantics to "F or D" instead of "F and D".
Fix has_fpu() to check D only, which is equivalent to requiring both extensions given the dependency. sys_hwprobe.c already calls has_fpu() and needs no changes.
---
Changes in v3:
- Drop the sys_hwprobe.c hunk entirely: it already calls has_fpu(), no change needed there since v1 was never merged.
- This is a new thread per maintainer request, not a reply to v1/v2.
arch/riscv/include/asm/switch_to.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/include/asm/switch_to.h +2 -2
@@ -60,8 +60,8 @@ static inline void __switch_to_fpu(struct task_struct *prev, static __always_inline bool has_fpu(void) { -return riscv_has_extension_likely (RISCV_ISA_EXT_f) || -riscv_has_extension_likely (RISCV_ISA_EXT_d); +/* D extension depends on F, so checking D alone is sufficient. */ +return riscv_has_extension_likely (RISCV_ISA_EXT_d); }#else static __always_inline bool has_fpu(void) { return false; }
Signature · 1 line
2.55.0
Quoted 1 line · Ivy Lopez
The kernel never supports F without D, since D depends on F. As such,
D without F
Signature · 3 lines
Andreas Schwab, SUSE Labs, [email protected] GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."
Quoted 4 lines · Andreas Schwab
Quoted 1 line · Ivy Lopez
The kernel never supports F without D, since D depends on F. As such,
D without F
|The kernel never supports F without D, since D depends on F. As such, |has_fpu() checking either extension with '||' is incorrect: it |reports FPU support when only F is present, which is not sufficient |for D-dependent state save/restore, and weakens |RISCV_HWPROBE_IMA_FD semantics to "F or D" instead of "F and D".
Thinking about it, this whole thing really is not right.
Quoted 1 line
The kernel never supports F without D
This is actually correct, the kernel itself doesn't support doing this.
Quoted 1 line
since D depends on F
But this is not the rationale, the rationale is simplicity of implementation etc.
Quoted 3 lines
As such,
has_fpu()checking either extension with '||' is incorrect: it reports FPU support when only F is present, which is not sufficient
And this cannot happen, because the kernel will not enable F support if D is not present, it clears the relevant flag during devicetree/acpi parsing.
Quoted 2 lines
for D-dependent state save/restore, and weakens
RISCV_HWPROBE_IMA_FDsemantics to "F or D" instead of "F and D".
The reason I would cite for changing the is matching the expectations set elsewhere in the kernel, rather than impact on userspace or behaviour, since F without D is not possible so there's no potential impact here at all.
Cheers,
Conor.