Fix arm64 clang errors on fpu tests
v2 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 address these issues.
v2:
- Fix build errors for newer clang versions that push 'q' registers out of scope under '-mgeneral-regs-only'. (Andrew)
v1:
https://lore.kernel.org/all/[email protected]/
- Raghavendra
Raghavendra Rao Ananta (4):
arm: Fix clang error in sve_vl()
arm: fpu: Convert 'q' registers to 'v' to satisfy clang
arm: fpu: Add '.arch_extension fp' to fpu macros
arm: fpu: Fix the input/output args for inline asm in fpu.c
arm/fpu.c | 52 ++++++++++++++++++++------------------- lib/arm64/asm/processor.h | 2 +- 2 files changed, 28 insertions(+), 26 deletions(-)
base-commit: f246b16099478a916eab37b9bd1eb07c743a67d5
Signature · 1 line
2.47.0.105.g07ac214952-goog
PATCH v2 1/4 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 v2 2/4 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 v2 3/4 arm: fpu: Add '.arch_extension fp' to fpu macros
In reply to Raghavendra Rao AnantaSince the tests are built with '-mgeneral-regs-only', clang-18 tends to push 'q' registers out of the scope and hence, the following error is observed:
arm/fpu.c:281:3: error: instruction requires: fp-armv8
281 | fpu_reg_write(*indata);
| ^arm/fpu.c:74:15: note: expanded from macro 'fpu_reg_write'
74 | asm volatile("ldp q0, q1, [%0], #32\n\t" \
| ^
<inline asm>:1:2: note: instantiated into assembly here
1 | ldp q0, q1, [x8], #32
| ^Hence, explicitly add fp support where these registers are used.
--- arm/fpu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
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" \
Signature · 1 line
2.47.0.105.g07ac214952-goog
PATCH v2 4/4 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
@@ -55,7 +55,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", \
@@ -89,8 +89,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", \
@@ -140,8 +140,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
[kvm-unit-tests PATCH 5/4] arm64: gitlab-ci: Add clang build tests
In reply to Raghavendra Rao AnantaTest building aarch64 with clang both with and without --enable-efi. Use in-tree building for one and out-of-tree building for the other to get more coverage there too.
--- .gitlab-ci.yml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
.gitlab-ci.yml +46 -0
@@ -80,6 +80,52 @@ build-aarch64-efi-acpi: | tee results.txt - grep -q PASS results.txt && ! grep -q FAIL results.txt +build-aarch64-clang: + extends: .outoftree_template + script: + - dnf install -y qemu-system-aarch64 gcc-aarch64-linux-gnu clang + - mkdir build + - cd build + - ../configure --arch=arm64 --cc=clang --cflags='--target=aarch64' --cross-prefix=aarch64-linux-gnu- + - make -j2 + - ACCEL=tcg MAX_SMP=8 ./run_tests.sh + cache + debug-bp + debug-sstep + debug-wp + gicv2-active + gicv2-ipi + gicv2-mmio + gicv3-active + gicv3-ipi + its-introspection + its-trigger + pci-test + pmu-cycle-counter + pmu-event-counter-config + pmu-sw-incr + selftest-setup + selftest-smp + selftest-vectors-kernel + selftest-vectors-user + timer + | tee results.txt + - grep -q PASS results.txt && ! grep -q FAIL results.txt + +build-aarch64-clang-efi: + extends: .intree_template + script: + - dnf install -y edk2-aarch64 qemu-system-aarch64 gcc-aarch64-linux-gnu clang + - ./configure --arch=arm64 --cc=clang --cflags='--target=aarch64' --cross-prefix=aarch64-linux-gnu- --enable-efi --enable-efi-direct + - make -j2 + - ACCEL=tcg MAX_SMP=8 ./run_tests.sh + selftest-setup + selftest-smp + selftest-vectors-kernel + selftest-vectors-user + | tee results.txt + - grep -q PASS results.txt && ! grep -q FAIL results.txt + build-arm: extends: .outoftree_template script:
Signature · 1 line
2.47.0
Quoted 22 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 address these issues.
v2:
- Fix build errors for newer clang versions that push 'q' registers out of scope under '-mgeneral-regs-only'. (Andrew)v1:
https://lore.kernel.org/all/[email protected]/- Raghavendra
Raghavendra Rao Ananta (4):
arm: Fix clang error insve_vl()
arm: fpu: Convert 'q' registers to 'v' to satisfy clang
arm: fpu: Add '.arch_extension fp' to fpu macros
arm: fpu: Fix the input/output args for inline asm infpu.c
Quoted 9 lines
arm/fpu.c | 52 ++++++++++++++++++++------------------- lib/arm64/asm/processor.h | 2 +- 2 files changed, 28 insertions(+), 26 deletions(-)base-commit:
f246b16099478a916eab37b9bd1eb07c743a67d5Signature · 1 line
2.47.0.105.g07ac214952-goog
I've merged this along with the cross clang series and the 5/4 patch I tacked onto this series which adds aarch64 clang testing to gitlab CI.
Thanks,
drew