* [kvm-unit-tests PATCH v2 0/4] riscv: Extend CI
@ 2024-08-08 15:42 Andrew Jones
2024-08-08 15:42 ` [kvm-unit-tests PATCH v2 1/4] lib: Add limits.h Andrew Jones
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Andrew Jones @ 2024-08-08 15:42 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: pbonzini, thuth, atishp, cade.richard, jamestiotio
So far we were only building and testing 64-bit, non-efi in the CI for
riscv. I had mistakenly thought Fedora's riscv compiler could only build
64-bit, but it's multilib so we just need to add some CFLAGS to get it
to work. To preserve building with a 32-bit-only riscv compiler we need
to introduce limits.h to our tiny libc. And, while adding 32-bit builds
to CI we also add EFI builds so now we test 32-bit, 64-bit, and 64-bit
EFI. And, since Fedora has been udpated, bringing in a later QEMU, we
can now do the testing with the 'max' cpu type.
v2:
- *Actually* test out-of-tree builds in the rv32 CI (I was missing
a few important lines, like 'cd build'...
- Add another patch to fix out-of-tree builds for riscv
- Added some indentation in the new limits.h
Andrew Jones (4):
lib: Add limits.h
riscv: Build with explicit ABI
riscv: Fix out-of-tree builds
riscv: Extend gitlab CI
.gitlab-ci.yml | 36 +++++++++++++++++++++++++++++++-----
configure | 8 ++++++--
lib/limits.h | 43 +++++++++++++++++++++++++++++++++++++++++++
riscv/Makefile | 12 +++++++-----
4 files changed, 87 insertions(+), 12 deletions(-)
create mode 100644 lib/limits.h
--
2.45.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [kvm-unit-tests PATCH v2 1/4] lib: Add limits.h
2024-08-08 15:42 [kvm-unit-tests PATCH v2 0/4] riscv: Extend CI Andrew Jones
@ 2024-08-08 15:42 ` Andrew Jones
2024-08-08 15:42 ` [kvm-unit-tests PATCH v2 2/4] riscv: Build with explicit ABI Andrew Jones
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Jones @ 2024-08-08 15:42 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: pbonzini, thuth, atishp, cade.richard, jamestiotio
We already include limits.h from a couple places (libfdt and the
sbi test for riscv). We should provide our own limits.h rather than
depend on the build environment as some cross environments may not
support it (building riscv with a ilp32d toolchain fails, for
example).
We guard each definition to ensure we only provide them when the
sizes match our expectations. If something is strange then the
define won't be created, and either the includer won't notice since
it wasn't used or the build will break and limits.h can be extended.
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
lib/limits.h | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 lib/limits.h
diff --git a/lib/limits.h b/lib/limits.h
new file mode 100644
index 000000000000..650085c68e5d
--- /dev/null
+++ b/lib/limits.h
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _LIMITS_H_
+#define _LIMITS_H_
+
+#if __CHAR_BIT__ == 8
+# if __CHAR_UNSIGNED__
+# define CHAR_MIN 0
+# define CHAR_MAX __UINT8_MAX__
+# else
+# define CHAR_MAX __INT8_MAX__
+# define CHAR_MIN (-CHAR_MAX - 1)
+# endif
+#endif
+
+#if __SHRT_WIDTH__ == 16
+# define SHRT_MAX __INT16_MAX__
+# define SHRT_MIN (-SHRT_MAX - 1)
+# define USHRT_MAX __UINT16_MAX__
+#endif
+
+#if __INT_WIDTH__ == 32
+# define INT_MAX __INT32_MAX__
+# define INT_MIN (-INT_MAX - 1)
+# define UINT_MAX __UINT32_MAX__
+#endif
+
+#if __LONG_WIDTH__ == 64
+# define LONG_MAX __INT64_MAX__
+# define LONG_MIN (-LONG_MAX - 1)
+# define ULONG_MAX __UINT64_MAX__
+#elif __LONG_WIDTH__ == 32
+# define LONG_MAX __INT32_MAX__
+# define LONG_MIN (-LONG_MAX - 1)
+# define ULONG_MAX __UINT32_MAX__
+#endif
+
+#if __LONG_LONG_WIDTH__ == 64
+# define LLONG_MAX __INT64_MAX__
+# define LLONG_MIN (-LLONG_MAX - 1)
+# define ULLONG_MAX __UINT64_MAX__
+#endif
+
+#endif /* _LIMITS_H_ */
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [kvm-unit-tests PATCH v2 2/4] riscv: Build with explicit ABI
2024-08-08 15:42 [kvm-unit-tests PATCH v2 0/4] riscv: Extend CI Andrew Jones
2024-08-08 15:42 ` [kvm-unit-tests PATCH v2 1/4] lib: Add limits.h Andrew Jones
@ 2024-08-08 15:42 ` Andrew Jones
2024-08-08 15:42 ` [kvm-unit-tests PATCH v2 3/4] riscv: Fix out-of-tree builds Andrew Jones
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Jones @ 2024-08-08 15:42 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: pbonzini, thuth, atishp, cade.richard, jamestiotio
If we add -mabi to the command line then compilers that are built
to support multiple ABIs may be used for both rv32 and rv64 builds,
so add it for that reason. We also need the right linker flags, so
add those too and throw in a trimming of the ISA string (drop fd)
in order to keep it minimal.
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
riscv/Makefile | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/riscv/Makefile b/riscv/Makefile
index b0cd613fcd8c..7906cef7f199 100644
--- a/riscv/Makefile
+++ b/riscv/Makefile
@@ -64,13 +64,15 @@ define arch_elf_check =
$(error $(1) has unsupported reloc types))
endef
-ISA_COMMON = mafdc_zicsr_zifencei_zihintpause
+ISA_COMMON = imac_zicsr_zifencei_zihintpause
ifeq ($(ARCH),riscv64)
-CFLAGS += -march=rv64i$(ISA_COMMON)
-CFLAGS += -DCONFIG_64BIT
+CFLAGS += -DCONFIG_64BIT
+CFLAGS += -mabi=lp64 -march=rv64$(ISA_COMMON)
+LDFLAGS += -melf64lriscv
else ifeq ($(ARCH),riscv32)
-CFLAGS += -march=rv32i$(ISA_COMMON)
+CFLAGS += -mabi=ilp32 -march=rv32$(ISA_COMMON)
+LDFLAGS += -melf32lriscv
endif
CFLAGS += -DCONFIG_RELOC
CFLAGS += -mcmodel=medany
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [kvm-unit-tests PATCH v2 3/4] riscv: Fix out-of-tree builds
2024-08-08 15:42 [kvm-unit-tests PATCH v2 0/4] riscv: Extend CI Andrew Jones
2024-08-08 15:42 ` [kvm-unit-tests PATCH v2 1/4] lib: Add limits.h Andrew Jones
2024-08-08 15:42 ` [kvm-unit-tests PATCH v2 2/4] riscv: Build with explicit ABI Andrew Jones
@ 2024-08-08 15:42 ` Andrew Jones
2024-08-08 15:42 ` [kvm-unit-tests PATCH v2 4/4] riscv: Extend gitlab CI Andrew Jones
2024-08-12 13:53 ` [kvm-unit-tests PATCH v2 0/4] riscv: Extend CI Andrew Jones
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Jones @ 2024-08-08 15:42 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: pbonzini, thuth, atishp, cade.richard, jamestiotio
My riscv compiler doesn't seem to want to create directories as other
compilers are apparently doing. There's only a few of them, so let's
just manually create them in configure. And riscv also needed
'-I lib' in CFLAGS.
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
configure | 8 ++++++--
riscv/Makefile | 2 +-
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/configure b/configure
index db15e85d6ac7..27ae9cc89657 100755
--- a/configure
+++ b/configure
@@ -418,12 +418,16 @@ rm -f lib/asm
asm="asm-generic"
if [ -d "$srcdir/lib/$arch/asm" ]; then
asm="$srcdir/lib/$arch/asm"
+ mkdir -p "lib/$arch"
+elif [ -d "$srcdir/lib/$arch_libdir/asm" ]; then
+ asm="$srcdir/lib/$arch_libdir/asm"
+ mkdir -p "lib/$arch_libdir"
elif [ -d "$srcdir/lib/$testdir/asm" ]; then
asm="$srcdir/lib/$testdir/asm"
+ mkdir -p "lib/$testdir"
fi
-mkdir -p lib
ln -sf "$asm" lib/asm
-
+mkdir -p lib/generated lib/libfdt
# create the config
cat <<EOF > config.mak
diff --git a/riscv/Makefile b/riscv/Makefile
index 7906cef7f199..179a373dbacf 100644
--- a/riscv/Makefile
+++ b/riscv/Makefile
@@ -80,7 +80,7 @@ CFLAGS += -mstrict-align
CFLAGS += -std=gnu99
CFLAGS += -ffreestanding
CFLAGS += -O2
-CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt
+CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib
asm-offsets = lib/riscv/asm-offsets.h
include $(SRCDIR)/scripts/asm-offsets.mak
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [kvm-unit-tests PATCH v2 4/4] riscv: Extend gitlab CI
2024-08-08 15:42 [kvm-unit-tests PATCH v2 0/4] riscv: Extend CI Andrew Jones
` (2 preceding siblings ...)
2024-08-08 15:42 ` [kvm-unit-tests PATCH v2 3/4] riscv: Fix out-of-tree builds Andrew Jones
@ 2024-08-08 15:42 ` Andrew Jones
2024-08-12 13:53 ` [kvm-unit-tests PATCH v2 0/4] riscv: Extend CI Andrew Jones
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Jones @ 2024-08-08 15:42 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: pbonzini, thuth, atishp, cade.richard, jamestiotio
Fedora's riscv64 gcc supports ilp32 so enable 32-bit RISCV testing.
And use the out-of-tree template for the 32-bit build to get that
covered too. Also add EFI build testing and, since Fedora has been
updated which brings in a later QEMU, we can now use the 'max' cpu
type.
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
.gitlab-ci.yml | 36 +++++++++++++++++++++++++++++++-----
1 file changed, 31 insertions(+), 5 deletions(-)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e0eb85a94910..180ef6e78558 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -133,18 +133,44 @@ build-ppc64le:
| tee results.txt
- if grep -q FAIL results.txt ; then exit 1 ; fi
-# build-riscv32:
-# Fedora doesn't package a riscv32 compiler for QEMU. Oh, well.
+build-riscv32:
+ extends: .outoftree_template
+ script:
+ - dnf install -y qemu-system-riscv gcc-riscv64-linux-gnu
+ - mkdir build
+ - cd build
+ - ../configure --arch=riscv32 --cross-prefix=riscv64-linux-gnu-
+ - make -j2
+ - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\nMARCHID=0\nMIMPID=0\n" >test-env
+ - ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
+ selftest
+ sbi
+ | tee results.txt
+ - grep -q PASS results.txt && ! grep -q FAIL results.txt
-# Select 'rv64' with PROCESSOR_OVERRIDE in case QEMU is too old to have 'max'
build-riscv64:
extends: .intree_template
script:
- dnf install -y qemu-system-riscv gcc-riscv64-linux-gnu
- ./configure --arch=riscv64 --cross-prefix=riscv64-linux-gnu-
- make -j2
- - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\n" >test-env
- - PROCESSOR_OVERRIDE=rv64 ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
+ - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\nMARCHID=0\nMIMPID=0\n" >test-env
+ - ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
+ selftest
+ sbi
+ | tee results.txt
+ - grep -q PASS results.txt && ! grep -q FAIL results.txt
+
+build-riscv64-efi:
+ extends: .intree_template
+ script:
+ - dnf install -y edk2-riscv64 qemu-system-riscv gcc-riscv64-linux-gnu
+ - cp /usr/share/edk2/riscv/RISCV_VIRT_CODE.fd .
+ - truncate -s 32M RISCV_VIRT_CODE.fd
+ - ./configure --arch=riscv64 --cross-prefix=riscv64-linux-gnu- --enable-efi
+ - make -j2
+ - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\nMARCHID=0\nMIMPID=0\n" >test-env
+ - ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
selftest
sbi
| tee results.txt
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [kvm-unit-tests PATCH v2 0/4] riscv: Extend CI
2024-08-08 15:42 [kvm-unit-tests PATCH v2 0/4] riscv: Extend CI Andrew Jones
` (3 preceding siblings ...)
2024-08-08 15:42 ` [kvm-unit-tests PATCH v2 4/4] riscv: Extend gitlab CI Andrew Jones
@ 2024-08-12 13:53 ` Andrew Jones
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Jones @ 2024-08-12 13:53 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: pbonzini, thuth, atishp, cade.richard, jamestiotio
On Thu, Aug 08, 2024 at 05:42:24PM GMT, Andrew Jones wrote:
> So far we were only building and testing 64-bit, non-efi in the CI for
> riscv. I had mistakenly thought Fedora's riscv compiler could only build
> 64-bit, but it's multilib so we just need to add some CFLAGS to get it
> to work. To preserve building with a 32-bit-only riscv compiler we need
> to introduce limits.h to our tiny libc. And, while adding 32-bit builds
> to CI we also add EFI builds so now we test 32-bit, 64-bit, and 64-bit
> EFI. And, since Fedora has been udpated, bringing in a later QEMU, we
> can now do the testing with the 'max' cpu type.
>
> v2:
> - *Actually* test out-of-tree builds in the rv32 CI (I was missing
> a few important lines, like 'cd build'...
> - Add another patch to fix out-of-tree builds for riscv
> - Added some indentation in the new limits.h
>
> Andrew Jones (4):
> lib: Add limits.h
> riscv: Build with explicit ABI
> riscv: Fix out-of-tree builds
> riscv: Extend gitlab CI
>
> .gitlab-ci.yml | 36 +++++++++++++++++++++++++++++++-----
> configure | 8 ++++++--
> lib/limits.h | 43 +++++++++++++++++++++++++++++++++++++++++++
> riscv/Makefile | 12 +++++++-----
> 4 files changed, 87 insertions(+), 12 deletions(-)
> create mode 100644 lib/limits.h
>
> --
> 2.45.2
>
Queued on riscv/queue, https://gitlab.com/jones-drew/kvm-unit-tests/-/commits/riscv%2Fqueue
drew
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-08-12 13:54 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-08 15:42 [kvm-unit-tests PATCH v2 0/4] riscv: Extend CI Andrew Jones
2024-08-08 15:42 ` [kvm-unit-tests PATCH v2 1/4] lib: Add limits.h Andrew Jones
2024-08-08 15:42 ` [kvm-unit-tests PATCH v2 2/4] riscv: Build with explicit ABI Andrew Jones
2024-08-08 15:42 ` [kvm-unit-tests PATCH v2 3/4] riscv: Fix out-of-tree builds Andrew Jones
2024-08-08 15:42 ` [kvm-unit-tests PATCH v2 4/4] riscv: Extend gitlab CI Andrew Jones
2024-08-12 13:53 ` [kvm-unit-tests PATCH v2 0/4] riscv: Extend CI Andrew Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox