Fix arm64 clang errors on fpu tests
cover Fix arm64 clang errors on fpu tests
When compiled with clang for arm64, some build errors were observed along the fpu code. Moreover, data aborts were seen while running the arm/fpu test due to misconfigured input/output args in the inline assembly.
The series tries to addresses these issues.
- Raghavendra
Raghavendra Rao Ananta (3):
arm: Fix clang error in sve_vl()
arm: fpu: Convert 'q' registers to 'v' to satisfy clang
arm: fpu: Fix the input/output args for inline asm in fpu.c
arm/fpu.c | 46 +++++++++++++++++++-------------------- lib/arm64/asm/processor.h | 2 +- 2 files changed, 24 insertions(+), 24 deletions(-)
base-commit: f246b16099478a916eab37b9bd1eb07c743a67d5
Signature · 1 line
2.47.0.105.g07ac214952-goog
PATCH 1/3 arm: Fix clang error in sve_vl()
Fix the following clang error in sve_vl():
In file included from arm/selftest.c:16:kvm-unit-tests/lib/asm/processor.h:163:16:
error: value size does not match register size specified by the constraint and modifier [-Werror,-Wasm-operand-widths]
: "=r" (vl));
^
kvm-unit-tests/lib/asm/processor.h:162:14:
note: use constraint modifier "w"
"rdvl %0, #8"
^~
%w01 error generated.
--- lib/arm64/asm/processor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/arm64/asm/processor.h +1 -1
@@ -159,7 +159,7 @@ static inline int sve_vl(void)int vl; asmvolatile (".arch_extension sve\n" -"rdvl %0, #8" +"rdvl %w0, #8" :"=r" (vl));return vl;
Signature · 1 line
2.47.0.105.g07ac214952-goog
PATCH 2/3 arm: fpu: Convert 'q' registers to 'v' to satisfy clang
In reply to Raghavendra Rao AnantaClang doesn't seem to support 'q' register notation in the clobbered list, and hence throws the following error:
arm/fpu.c:235:3: error: unknown register name 'q0' in asm
fpu_reg_read(outdata);
^
arm/fpu.c:59:10: note: expanded from macro 'fpu_reg_read'
: "q0", "q1", "q2", "q3", \
^
arm/fpu.c:281:3: error: unknown register name 'q0' in asm
fpu_reg_write(*indata);
^
arm/fpu.c:92:10: note: expanded from macro 'fpu_reg_write'
: "q0", "q1", "q2", "q3", \
^2 errors generated.
Hence, replace 'q' with 'v' registers for the clobbered list.
--- arm/fpu.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
arm/fpu.c +20 -20
@@ -56,16 +56,16 @@ static inline bool arch_collect_entropy(uint64_t *random) "stp q30, q31, [%0], #32\n\t" \ : "=r" (__val) \: \ -: " q0", " q1", " q2", " q3", \ -" q4", " q5", " q6", " q7", \ -" q8", " q9", " q10", " q11", \ -" q12", " q13", " q14", \ -" q15", " q16", " q17", \ -" q18", " q19", " q20", \ -" q21", " q22", " q23", \ -" q24", " q25", " q26", \ -" q27", " q28", " q29", \ - "q30", "q31", "memory"); \ +: " v0", " v1", " v2", " v3", \ +" v4", " v5", " v6", " v7", \ +" v8", " v9", " v10", " v11", \ +" v12", " v13", " v14", \ +" v15", " v16", " v17", \ +" v18", " v19", " v20", \ +" v21", " v22", " v23", \ +" v24", " v25", " v26", \ +" v27", " v28", " v29", \ + "v30", "v31", "memory"); \ }) #define fpu_reg_write(val) \
@@ -89,16 +89,16 @@ do { \ "ldp q30, q31, [%0], #32\n\t" \ : \ : "r" (__val) \ -: " q0", " q1", " q2", " q3", \ -" q4", " q5", " q6", " q7", \ -" q8", " q9", " q10", " q11", \ -" q12", " q13", " q14", \ -" q15", " q16", " q17", \ -" q18", " q19", " q20", \ -" q21", " q22", " q23", \ -" q24", " q25", " q26", \ -" q27", " q28", " q29", \ - "q30", "q31", "memory"); \ +: " v0", " v1", " v2", " v3", \ +" v4", " v5", " v6", " v7", \ +" v8", " v9", " v10", " v11", \ +" v12", " v13", " v14", \ +" v15", " v16", " v17", \ +" v18", " v19", " v20", \ +" v21", " v22", " v23", \ +" v24", " v25", " v26", \ +" v27", " v28", " v29", \ + "v30", "v31", "memory"); \ } while (0) #ifdef CC_HAS_SVE
Signature · 1 line
2.47.0.105.g07ac214952-goog
PATCH 3/3 arm: fpu: Fix the input/output args for inline asm in fpu.c
In reply to Raghavendra Rao AnantaThe macros fpu_reg_{read,write} post-increment the '__val' pointer register as a part of 'stp' and 'ldp' instructions. As a result, mark it with "+r" for the compiler to treat it as read-write operand.
On the contrary, sve_reg_read() never updates the value of the pointer/register. Hence, mark this as "r" for the compiler to treat it as read-only operand.
Without these adjustments, the compiler can potentially perform optimizations over the registers holding the pointers that could lead to data aborts.
--- arm/fpu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arm/fpu.c +3 -3
@@ -54,7 +54,7 @@ static inline bool arch_collect_entropy(uint64_t *random)"stp q26, q27, [%0], #32\n\t" \"stp q28, q29, [%0], #32\n\t" \"stp q30, q31, [%0], #32\n\t" \ - : "=r" (__val) \ + : "+r" (__val) \: \ : " v0", " v1", " v2", " v3", \ " v4", " v5", " v6", " v7", \
@@ -87,8 +87,8 @@ do { \"ldp q26, q27, [%0], #32\n\t" \"ldp q28, q29, [%0], #32\n\t" \"ldp q30, q31, [%0], #32\n\t" \ + : "+r" (__val) \: \ - : "r" (__val) \: " v0", " v1", " v2", " v3", \ " v4", " v5", " v6", " v7", \ " v8", " v9", " v10", " v11", \
@@ -138,8 +138,8 @@ do { \ "str z29, [%0, #29, MUL VL]\n" \ "str z30, [%0, #30, MUL VL]\n" \ "str z31, [%0, #31, MUL VL]\n" \ - : "=r" (__val) \ : \ + : "r" (__val) \: " z0", " z1", " z2", " z3", \ " z4", " z5", " z6", " z7", \ " z8", " z9", " z10", " z11", \
Signature · 1 line
2.47.0.105.g07ac214952-goog
Quoted 14 lines · Raghavendra Rao Ananta
When compiled with clang for arm64, some build errors were observed along the fpu code. Moreover, data aborts were seen while running the arm/fpu test due to misconfigured input/output args in the inline assembly.
The series tries to addresses these issues.
- Raghavendra
Raghavendra Rao Ananta (3):
arm: Fix clang error insve_vl()
arm: fpu: Convert 'q' registers to 'v' to satisfy clang
arm: fpu: Fix the input/output args for inline asm infpu.c
Quoted 9 lines
arm/fpu.c | 46 +++++++++++++++++++-------------------- lib/arm64/asm/processor.h | 2 +- 2 files changed, 24 insertions(+), 24 deletions(-)base-commit:
f246b16099478a916eab37b9bd1eb07c743a67d5Signature · 1 line
2.47.0.105.g07ac214952-goog
Hi Raghavendra,
With clang 18.1.8 (Fedora 18.1.8-1.fc40) I get a bunch of errors like these
arm/fpu.c:281:3: error: instruction requires: fp-armv8
I used my cross-clang series[1] and configured with
./configure --arch=arm64 --cc=clang --cflags='--target=aarch64' --cross-prefix=aarch64-linux-gnu-
[1] https://lore.kernel.org/all/[email protected]/
Thanks,
drew
Hi Andrew,
Quoted 6 lines · Andrew Jones
With clang 18.1.8 (Fedora 18.1.8-1.fc40) I get a bunch of errors like these
arm/fpu.c:281:3: error: instruction requires: fp-armv8
Quoted 8 lines
I used my cross-clang series[1] and configured with
./configure --arch=arm64 --cc=clang --cflags='--target=aarch64' --cross-prefix=aarch64-linux-gnu-[1] https://lore.kernel.org/all/[email protected]/
Thanks,
drew
I was able to reproduce the errors by pointing to a newer clang (20) and applying your series.
I think we see the errors because llvm decided to disable loads and stores on FP registers with "-mgeneral-regs-only" [1]. Explicitly adding ".arch_extension fp" for the fp_reg_{read,write}() helped with the build:
arm/fpu.c +4 -2
@@ -38,7 +38,8 @@ static inline bool arch_collect_entropy(uint64_t *random)#define fpu_reg_read (val) \ ({ \ uint64_t *__val = (val); \ - asm volatile("stp q0, q1, [%0], #32\n\t" \ + asm volatile(".arch_extension fp\n" \ + "stp q0, q1, [%0], #32\n\t" \ "stp q2, q3, [%0], #32\n\t" \ "stp q4, q5, [%0], #32\n\t" \ "stp q6, q7, [%0], #32\n\t" \
@@ -71,7 +72,8 @@ static inline bool arch_collect_entropy(uint64_t *random)#define fpu_reg_write (val) \ do { \ uint64_t *__val = (val); \ - asm volatile("ldp q0, q1, [%0], #32\n\t" \ + asm volatile(".arch_extension fp\n" \ + "ldp q0, q1, [%0], #32\n\t" \ "ldp q2, q3, [%0], #32\n\t" \ "ldp q4, q5, [%0], #32\n\t" \ "ldp q6, q7, [%0], #32\n\t" \
If you are fine with this, I can push it as a separate patch in v2.
Thank you.
Raghavendra
Quoted 50 lines · Raghavendra Rao Ananta
Hi Andrew,
Quoted 9 lines
With clang 18.1.8 (Fedora 18.1.8-1.fc40) I get a bunch of errors like these
arm/fpu.c:281:3: error: instruction requires: fp-armv8I used my cross-clang series[1] and configured with
./configure --arch=arm64 --cc=clang --cflags='--target=aarch64'--cross-prefix=aarch64-linux-gnu-
Quoted 2 lines
[1]
https://lore.kernel.org/all/[email protected]/
Quoted 3 lines
Thanks,
drewI was able to reproduce the errors by pointing to a newer clang (20) and applying your series.
I think we see the errors because llvm decided to disable loads and stores on FP registers with "-mgeneral-regs-only" [1]. Explicitly adding ".arch_extension fp" for the fp_reg_{read,write}() helped with the build:arm/fpu.c +4
-2@@ -38,7 +38,8 @@ static inline bool arch_collect_entropy(uint64_t *random)#define fpu_reg_read (val) \ ({ \ uint64_t *__val = (val); \ - asm volatile("stp q0, q1, [%0], #32\n\t" \ + asm volatile(".arch_extension fp\n" \ + "stp q0, q1, [%0], #32\n\t" \ "stp q2, q3, [%0], #32\n\t" \ "stp q4, q5, [%0], #32\n\t" \ "stp q6, q7, [%0], #32\n\t" \@@ -71,7 +72,8 @@ static inline bool arch_collect_entropy(uint64_t *random)#define fpu_reg_write (val) \ do { \ uint64_t *__val = (val); \ - asm volatile("ldp q0, q1, [%0], #32\n\t" \ + asm volatile(".arch_extension fp\n" \ + "ldp q0, q1, [%0], #32\n\t" \ "ldp q2, q3, [%0], #32\n\t" \ "ldp q4, q5, [%0], #32\n\t" \ "ldp q6, q7, [%0], #32\n\t" \
Quoted 1 line
If you are fine with this, I can push it as a separate patch in v2.
The fix works for me too. Please post v2.
Thanks,
drew