RISC-V: Mask out the F extension on systems without D
PATCH 1/1 RISC-V: Mask out the F extension on systems without D
The RISC-V Linux port doesn't support systems that have the F extension but don't have the D extension -- we actually don't support systems without D either, but Alan's patch set is rectifying that soon. For now I think we can leave this in a semi-broken state and just wait for Alan's patch set to get merged for proper non-FPU support -- the patch set is starting to look good, so doing something in-between doesn't seem like it's worth the work.
I don't think it's worth fretting about support for systems with F but not D for now: our glibc ABIs are IMAC and IMAFDC so they probably won't end up being popular. We can always extend this in the future.
--- arch/riscv/kernel/cpufeature.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/riscv/kernel/cpufeature.c +7 -0
@@ -57,5 +57,12 @@ void riscv_fill_hwcap(void)for (i =0 ; i <strlen (isa); ++i) elf_hwcap |= isa2hwcap[(unsigned char )(isa[i])]; +/* We don't support systems with F but without D, so mask those out +* here. */ +if ((elf_hwcap &COMPAT_HWCAP_ISA_F ) && !(elf_hwcap &COMPAT_HWCAP_ISA_D )) { +pr_info ("This kernel does not support systems with F but not D" ); + elf_hwcap &= ~COMPAT_HWCAP_ISA_F ; + } +pr_info ("elf_hwcap is 0x%lx" , elf_hwcap); }
Signature · 1 line
2.16.4
Hi Palmer,
Quoted 23 lines · Palmer Dabbelt
The RISC-V Linux port doesn't support systems that have the F extension but don't have the D extension -- we actually don't support systems without D either, but Alan's patch set is rectifying that soon. For now I think we can leave this in a semi-broken state and just wait for Alan's patch set to get merged for proper non-FPU support -- the patch set is starting to look good, so doing something in-between doesn't seem like it's worth the work.
I don't think it's worth fretting about support for systems with F but not D for now: our glibc ABIs are IMAC and IMAFDC so they probably won't end up being popular. We can always extend this in the future.
CC Alan Kao <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>--- arch/riscv/kernel/cpufeature.c | 7 +++++++ 1 file changed, 7 insertions(+)arch/riscv/kernel/cpufeature.c +0
-0
arch/riscv/kernel/cpufeature.c void riscv_fill_hwcap(void) · line 66
Quoted 10 lines
arch/riscv/kernel/cpufeature.c +7
-0@@ -57,5 +57,12 @@ void riscv_fill_hwcap(void)for (i =0 ; i <strlen (isa); ++i) elf_hwcap |= isa2hwcap[(unsigned char )(isa[i])]; +/* We don't support systems with F but without D, so mask those out +* here. */ +if ((elf_hwcap &COMPAT_HWCAP_ISA_F ) && !(elf_hwcap &COMPAT_HWCAP_ISA_D )) { +pr_info ("This kernel does not support systems with F but not D" ); + elf_hwcap &= ~COMPAT_HWCAP_ISA_F ; + } +
The commit message does address the problem and this patch does provide checks and helpful information to users, but I wonder if we really need this patch, for two reasons:
* Just as you mentioned, current glibc ABI does not support such a thing as IMAFC, so probably no one has had trouble with this. To be honest, I suppose that anybody (RISC-V enthusiasts or vendors) who really need F-only support in kernel should get themself involved in the development by sending patches to improve.
* There are corner cases to let a F-only machine to pass the check in this patch. For instance, a vendor decides to name her extension ISA as doom, and supports single-precision FP only, so her ISA string would be
IMAFCXdoom.
The variable elf_hwcap is calculated at the loop in line 57,58, the 'd' from Xdoom would bypass the check, while the underlying machine does not support double-precision FP.
Quoted 5 lines
arch/riscv/kernel/cpufeature.c +0
-0pr_info ("elf_hwcap is 0x%lx" , elf_hwcap); }Signature · 1 line
2.16.4
I don't know if the reasons make sense to you, but anyway that's all I would like to say about this patch.
Alan
Quoted 51 lines · alankao at andestech.com
Hi Palmer,
Quoted 23 lines · Palmer Dabbelt
The RISC-V Linux port doesn't support systems that have the F extension but don't have the D extension -- we actually don't support systems without D either, but Alan's patch set is rectifying that soon. For now I think we can leave this in a semi-broken state and just wait for Alan's patch set to get merged for proper non-FPU support -- the patch set is starting to look good, so doing something in-between doesn't seem like it's worth the work.
I don't think it's worth fretting about support for systems with F but not D for now: our glibc ABIs are IMAC and IMAFDC so they probably won't end up being popular. We can always extend this in the future.
CC Alan Kao <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>--- arch/riscv/kernel/cpufeature.c | 7 +++++++ 1 file changed, 7 insertions(+)arch/riscv/kernel/cpufeature.c +0
-0arch/riscv/kernel/cpufeature.c void riscv_fill_hwcap(void) · line 66
Quoted 10 lines
arch/riscv/kernel/cpufeature.c +7
-0@@ -57,5 +57,12 @@ void riscv_fill_hwcap(void)for (i =0 ; i <strlen (isa); ++i) elf_hwcap |= isa2hwcap[(unsigned char )(isa[i])]; +/* We don't support systems with F but without D, so mask those out +* here. */ +if ((elf_hwcap &COMPAT_HWCAP_ISA_F ) && !(elf_hwcap &COMPAT_HWCAP_ISA_D )) { +pr_info ("This kernel does not support systems with F but not D" ); + elf_hwcap &= ~COMPAT_HWCAP_ISA_F ; + } +The commit message does address the problem and this patch does provide checks and helpful information to users, but I wonder if we really need this patch, for two reasons:
* Just as you mentioned, current glibc ABI does not support such a thing as IMAFC, so probably no one has had trouble with this. To be honest, I suppose that anybody (RISC-V enthusiasts or vendors) who really need F-only support in kernel should get themself involved in the development by sending patches to improve.
* There are corner cases to let a F-only machine to pass the check in this patch. For instance, a vendor decides to name her extension ISA as doom, and supports single-precision FP only, so her ISA string would be
Quoted 5 lines
IMAFCXdoom.
The variable
elf_hwcapis calculated at the loop in line 57,58, the 'd' from Xdoom would bypass the check, while the underlying machine does not support double-precision FP.
Ah, yes, that makes sense. I'd go the other way here and just be strict about parsing the ISA string: it's defined to be listed in a particular order, so we should really only be accepting legal ISA strings.
I'll submit a second patch to fix this behavior.
Quoted 11 lines
Quoted 6 lines
arch/riscv/kernel/cpufeature.c +0
-1pr_info ("elf_hwcap is 0x%lx" , elf_hwcap); } --2.16.4
I don't know if the reasons make sense to you, but anyway that's all I would like to say about this patch.
Alan