Skip to contentSkip to conversation

riscv: hwprobe: simplify has_fpu() to check D extension only

PATCH In review Ivy Lopez 3 participants 3 messages Sep 1 RISC-V

lore
Share & tools
lore

Ivy Lopez

author
#0 lore raw

PATCH 1/1 riscv: hwprobe: simplify has_fpu() to check D extension only

The kernel never supports D without F, since D depends on F. The D-extension flag is cleared during devicetree/ACPI parsing whenever F is not present, so has_fpu() checking either extension with '||' never actually produces a different result than checking D alone - F without D cannot occur in practice, and there is no observable impact on RISCV_HWPROBE_IMA_FD or userspace.

Simplify has_fpu() to check D only, matching the expectations set elsewhere in the kernel for this dependency, rather than relying on a redundant OR condition.

sys_hwprobe.c already calls has_fpu() and needs no changes.

---
Changes in v4:
- Rewrite commit message: drop the "weakens semantics"/incorrect-report framing (Conor pointed out F-without-D cannot occur since the D flag is cleared during devicetree/ACPI parsing - confirmed in riscv_ext_f_validate(), arch/riscv/kernel/cpufeature.c - so there's no actual behavioral impact). Reframe as a simplification matching existing kernel conventions, not a correctness fix.
- Fix "F without D" -> "D without F" (Andreas).

Changes in v3:
- Drop the sys_hwprobe.c hunk entirely: it already calls has_fpu(), no change needed there since v1 was never merged.
- 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
index 0e71eb82f920..8186cda88e17 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Ivy Lopez

The kernel never supports D without F, since D depends on F. The D-extension flag is cleared during devicetree/ACPI parsing whenever F is not present, so has_fpu() checking either extension with '||' never actually produces a different result than checking D alone - F without D cannot occur in practice, and there is no observable impact on RISCV_HWPROBE_IMA_FD or userspace.

Simplify has_fpu() to check D only, matching the expectations set elsewhere in the kernel for this dependency, rather than relying on a redundant OR condition.

Quoted 6 lines

sys_hwprobe.c already calls has_fpu() and needs no changes.

Thanks,
Conor.

maintainer
#2 lore raw
In reply to Ivy Lopez
Quoted 11 lines · Ivy Lopez

The kernel never supports D without F, since D depends on F. The D-extension flag is cleared during devicetree/ACPI parsing whenever F is not present, so has_fpu() checking either extension with '||' never actually produces a different result than checking D alone - F without D cannot occur in practice, and there is no observable impact on RISCV_HWPROBE_IMA_FD or userspace.

Simplify has_fpu() to check D only, matching the expectations set elsewhere in the kernel for this dependency, rather than relying on a redundant OR condition.

Quoted 6 lines

sys_hwprobe.c already calls has_fpu() and needs no changes.

Thanks, updated to apply and queued for v7.3-rc.

- Paul