public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v2 0/4] Fix arm64 clang errors on fpu tests
@ 2024-10-23 15:26 Raghavendra Rao Ananta
  2024-10-23 15:26 ` [kvm-unit-tests PATCH v2 1/4] arm: Fix clang error in sve_vl() Raghavendra Rao Ananta
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Raghavendra Rao Ananta @ 2024-10-23 15:26 UTC (permalink / raw)
  To: Subhasish Ghosh, Joey Gouly, Andrew Jones
  Cc: Oliver Upton, Marc Zyngier, Raghavendra Rao Anata,
	linux-arm-kernel, kvmarm, linux-kernel, kvm

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/20241022004710.1888067-1-rananta@google.com/

- 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
-- 
2.47.0.105.g07ac214952-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [kvm-unit-tests PATCH v2 1/4] arm: Fix clang error in sve_vl()
  2024-10-23 15:26 [kvm-unit-tests PATCH v2 0/4] Fix arm64 clang errors on fpu tests Raghavendra Rao Ananta
@ 2024-10-23 15:26 ` Raghavendra Rao Ananta
  2024-10-23 15:26 ` [kvm-unit-tests PATCH v2 2/4] arm: fpu: Convert 'q' registers to 'v' to satisfy clang Raghavendra Rao Ananta
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Raghavendra Rao Ananta @ 2024-10-23 15:26 UTC (permalink / raw)
  To: Subhasish Ghosh, Joey Gouly, Andrew Jones
  Cc: Oliver Upton, Marc Zyngier, Raghavendra Rao Anata,
	linux-arm-kernel, kvmarm, linux-kernel, kvm

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"
                           ^~
                           %w0
1 error generated.

Fixes: d47d370c8f ("arm: Add test for FPU/SIMD context save/restore")
Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
---
 lib/arm64/asm/processor.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/arm64/asm/processor.h b/lib/arm64/asm/processor.h
index b28d41fd..e261e74d 100644
--- a/lib/arm64/asm/processor.h
+++ b/lib/arm64/asm/processor.h
@@ -159,7 +159,7 @@ static inline int sve_vl(void)
 	int vl;
 
 	asm volatile(".arch_extension sve\n"
-		     "rdvl %0, #8"
+		     "rdvl %w0, #8"
 		     : "=r" (vl));
 
 	return vl;
-- 
2.47.0.105.g07ac214952-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [kvm-unit-tests PATCH v2 2/4] arm: fpu: Convert 'q' registers to 'v' to satisfy clang
  2024-10-23 15:26 [kvm-unit-tests PATCH v2 0/4] Fix arm64 clang errors on fpu tests Raghavendra Rao Ananta
  2024-10-23 15:26 ` [kvm-unit-tests PATCH v2 1/4] arm: Fix clang error in sve_vl() Raghavendra Rao Ananta
@ 2024-10-23 15:26 ` Raghavendra Rao Ananta
  2024-10-23 15:26 ` [kvm-unit-tests PATCH v2 3/4] arm: fpu: Add '.arch_extension fp' to fpu macros Raghavendra Rao Ananta
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Raghavendra Rao Ananta @ 2024-10-23 15:26 UTC (permalink / raw)
  To: Subhasish Ghosh, Joey Gouly, Andrew Jones
  Cc: Oliver Upton, Marc Zyngier, Raghavendra Rao Anata,
	linux-arm-kernel, kvmarm, linux-kernel, kvm

Clang 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.

Fixes: d47d370c8f ("arm: Add test for FPU/SIMD context save/restore")
Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
---
 arm/fpu.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/arm/fpu.c b/arm/fpu.c
index edbd9a94..587b6ea3 100644
--- a/arm/fpu.c
+++ b/arm/fpu.c
@@ -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
-- 
2.47.0.105.g07ac214952-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [kvm-unit-tests PATCH v2 3/4] arm: fpu: Add '.arch_extension fp' to fpu macros
  2024-10-23 15:26 [kvm-unit-tests PATCH v2 0/4] Fix arm64 clang errors on fpu tests Raghavendra Rao Ananta
  2024-10-23 15:26 ` [kvm-unit-tests PATCH v2 1/4] arm: Fix clang error in sve_vl() Raghavendra Rao Ananta
  2024-10-23 15:26 ` [kvm-unit-tests PATCH v2 2/4] arm: fpu: Convert 'q' registers to 'v' to satisfy clang Raghavendra Rao Ananta
@ 2024-10-23 15:26 ` Raghavendra Rao Ananta
  2024-10-23 15:26 ` [kvm-unit-tests PATCH v2 4/4] arm: fpu: Fix the input/output args for inline asm in fpu.c Raghavendra Rao Ananta
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Raghavendra Rao Ananta @ 2024-10-23 15:26 UTC (permalink / raw)
  To: Subhasish Ghosh, Joey Gouly, Andrew Jones
  Cc: Oliver Upton, Marc Zyngier, Raghavendra Rao Anata,
	linux-arm-kernel, kvmarm, linux-kernel, kvm

Since 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.

Reported-by: Andrew Jones <andrew.jones@linux.dev>
Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
---
 arm/fpu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arm/fpu.c b/arm/fpu.c
index 587b6ea3..f327a349 100644
--- a/arm/fpu.c
+++ b/arm/fpu.c
@@ -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"	\
-- 
2.47.0.105.g07ac214952-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [kvm-unit-tests PATCH v2 4/4] arm: fpu: Fix the input/output args for inline asm in fpu.c
  2024-10-23 15:26 [kvm-unit-tests PATCH v2 0/4] Fix arm64 clang errors on fpu tests Raghavendra Rao Ananta
                   ` (2 preceding siblings ...)
  2024-10-23 15:26 ` [kvm-unit-tests PATCH v2 3/4] arm: fpu: Add '.arch_extension fp' to fpu macros Raghavendra Rao Ananta
@ 2024-10-23 15:26 ` Raghavendra Rao Ananta
  2024-10-24  8:31 ` [kvm-unit-tests PATCH 5/4] arm64: gitlab-ci: Add clang build tests Andrew Jones
  2024-10-24  8:40 ` [kvm-unit-tests PATCH v2 0/4] Fix arm64 clang errors on fpu tests Andrew Jones
  5 siblings, 0 replies; 7+ messages in thread
From: Raghavendra Rao Ananta @ 2024-10-23 15:26 UTC (permalink / raw)
  To: Subhasish Ghosh, Joey Gouly, Andrew Jones
  Cc: Oliver Upton, Marc Zyngier, Raghavendra Rao Anata,
	linux-arm-kernel, kvmarm, linux-kernel, kvm

The 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.

Fixes: d47d370c8f ("arm: Add test for FPU/SIMD context save/restore")
Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
---
 arm/fpu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arm/fpu.c b/arm/fpu.c
index f327a349..f44ed82a 100644
--- a/arm/fpu.c
+++ b/arm/fpu.c
@@ -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",	\
-- 
2.47.0.105.g07ac214952-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [kvm-unit-tests PATCH 5/4] arm64: gitlab-ci: Add clang build tests
  2024-10-23 15:26 [kvm-unit-tests PATCH v2 0/4] Fix arm64 clang errors on fpu tests Raghavendra Rao Ananta
                   ` (3 preceding siblings ...)
  2024-10-23 15:26 ` [kvm-unit-tests PATCH v2 4/4] arm: fpu: Fix the input/output args for inline asm in fpu.c Raghavendra Rao Ananta
@ 2024-10-24  8:31 ` Andrew Jones
  2024-10-24  8:40 ` [kvm-unit-tests PATCH v2 0/4] Fix arm64 clang errors on fpu tests Andrew Jones
  5 siblings, 0 replies; 7+ messages in thread
From: Andrew Jones @ 2024-10-24  8:31 UTC (permalink / raw)
  To: kvm, kvmarm
  Cc: rananta, pbonzini, thuth, subhasish.ghosh, joey.gouly,
	oliver.upton, maz

Test 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.

Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
 .gitlab-ci.yml | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b7ad99870e5a..aa69ca594ba3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -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:
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [kvm-unit-tests PATCH v2 0/4] Fix arm64 clang errors on fpu tests
  2024-10-23 15:26 [kvm-unit-tests PATCH v2 0/4] Fix arm64 clang errors on fpu tests Raghavendra Rao Ananta
                   ` (4 preceding siblings ...)
  2024-10-24  8:31 ` [kvm-unit-tests PATCH 5/4] arm64: gitlab-ci: Add clang build tests Andrew Jones
@ 2024-10-24  8:40 ` Andrew Jones
  5 siblings, 0 replies; 7+ messages in thread
From: Andrew Jones @ 2024-10-24  8:40 UTC (permalink / raw)
  To: Raghavendra Rao Ananta
  Cc: Subhasish Ghosh, Joey Gouly, Oliver Upton, Marc Zyngier,
	linux-arm-kernel, kvmarm, linux-kernel, kvm

On Wed, Oct 23, 2024 at 03:26:34PM +0000, Raghavendra Rao Ananta wrote:
> 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/20241022004710.1888067-1-rananta@google.com/
> 
> - 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
> -- 
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-10-24  8:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-23 15:26 [kvm-unit-tests PATCH v2 0/4] Fix arm64 clang errors on fpu tests Raghavendra Rao Ananta
2024-10-23 15:26 ` [kvm-unit-tests PATCH v2 1/4] arm: Fix clang error in sve_vl() Raghavendra Rao Ananta
2024-10-23 15:26 ` [kvm-unit-tests PATCH v2 2/4] arm: fpu: Convert 'q' registers to 'v' to satisfy clang Raghavendra Rao Ananta
2024-10-23 15:26 ` [kvm-unit-tests PATCH v2 3/4] arm: fpu: Add '.arch_extension fp' to fpu macros Raghavendra Rao Ananta
2024-10-23 15:26 ` [kvm-unit-tests PATCH v2 4/4] arm: fpu: Fix the input/output args for inline asm in fpu.c Raghavendra Rao Ananta
2024-10-24  8:31 ` [kvm-unit-tests PATCH 5/4] arm64: gitlab-ci: Add clang build tests Andrew Jones
2024-10-24  8:40 ` [kvm-unit-tests PATCH v2 0/4] Fix arm64 clang errors on fpu tests Andrew Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox