riscv: add SBI SSE extension tests
Subsystems (3)
v11 cover riscv: add SBI SSE extension tests
This series adds tests for SBI SSE extension as well as needed infrastructure for SSE support. It also adds test specific asm-offsets generation to use custom OFFSET and DEFINE from the test directory.
These tests can be run using an OpenSBI version that implements latest specifications modification [1]
---
V11:
- Use mask inside sbi_impl_opensbi_mk_version()
- Mask the SBI version with a new mask
- Use assert inside sbi_get_impl_id/version()
- Remove sbi_check_impl()
- Increase completion timeout as events failed completing under 1000 micros when system is loaded.
V10:
- Use && instead of || for timeout handling
- Add SBI patches which introduce function to get implementer ID and version as well as implementer ID defines.
- Skip injection tests in OpenSBI < v1.6
V9:
- Use __ASSEMBLER__ instead of __ASSEMBLY__
- Remove extra spaces
- Use assert to check global event in sse_global_event_set_current_hart()
- Tabulate SSE events names table
- Use sbi_sse_register() instead of sbi_sse_register_raw() in error testing
- Move a report_pass() out of error path
- Rework all injection tests with better error handling
- Use an env var for sse event completion timeout
- Add timeout for some potentially infinite while() loops
V8:
- Short circuit current event tests if failure happens
- Remove SSE from all report strings
- Indent .prio field
- Add cpu_relax()/smp_rmb() where needed
- Add timeout for global event ENABLED state check
- Added BIT(32) aliases tests for attribute/event_id.
V7:
- Test ids/attributes/attributes count > 32 bits
- Rename all SSE function to sbi_sse_*
- Use event_id instead of event/evt
- Factorize read/write test
- Use virt_to_phys() for attributes read/write.
- Extensively use sbiret_report_error()
- Change check function return values to bool.
- Added assert for stack size to be below or equal to PAGE_SIZE
- Use en env variable for the maximum hart ID
- Check that individual read from attributes matches the multiple attributes read.
- Added multiple attributes write at once
- Used READ_ONCE/WRITE_ONCE
- Inject all local event at once rather than looping fopr each core.
- Split test_arg for local_dispatch test so that all CPUs can run at once.
- Move SSE entry and generic code to lib/riscv for other tests
- Fix unmask/mask state checking
V6:
- Add missing $(generated-file) dependencies for "-deps" objects
- Split SSE entry from sbi-asm.S to sse-asm.S and all SSE core functions since it will be useful for other tests as well (dbltrp).
V5:
- Update event ranges based on latest spec
- Rename asm-offset-test.c to sbi-asm-offset.c
V4:
- Fix typo sbi_ext_ss_fid -> sbi_ext_sse_fid
- Add proper asm-offset generation for tests
- Move SSE specific file from lib/riscv to riscv/
V3:
- Add -deps variable for test specific dependencies
- Fix formatting errors/typo in sbi.h
- Add missing double trap event
- Alphabetize sbi-sse.c includes
- Fix a6 content after unmasking event
- Add SSE HART_MASK/UNMASK test
- Use mv instead of move
- move sbi_check_sse() definition in sbi.c
- Remove sbi_sse test from unitests.cfg
V2:
- Rebased on origin/master and integrate it into sbi.c tests
Clément Léger (8):
kbuild: Allow multiple asm-offsets file to be generated
riscv: Set .aux.o files as .PRECIOUS
riscv: Use asm-offsets to generate SBI_EXT_HSM values
lib: riscv: Add functions for version checking
lib: riscv: Add functions to get implementer ID and version
riscv: lib: Add SBI SSE extension definitions
lib: riscv: Add SBI SSE support
riscv: sbi: Add SSE extension tests
scripts/asm-offsets.mak | 22 +- riscv/Makefile | 5 +- lib/riscv/asm/csr.h | 1 + lib/riscv/asm/sbi.h | 177 +++++- lib/riscv/sbi-sse-asm.S | 102 ++++ lib/riscv/asm-offsets.c | 9 + lib/riscv/sbi.c | 105 +++- riscv/sbi-tests.h | 1 + riscv/sbi-asm.S | 6 +- riscv/sbi-asm-offsets.c | 11 + riscv/sbi-sse.c | 1278 +++++++++++++++++++++++++++++++++++++++ riscv/sbi.c | 2 + riscv/.gitignore | 1 + 13 files changed, 1707 insertions(+), 13 deletions(-) create mode 100644 lib/riscv/sbi-sse-asm.S create mode 100644 riscv/sbi-asm-offsets.c create mode 100644 riscv/sbi-sse.c create mode 100644 riscv/.gitignore
Signature · 1 line
2.47.2
PATCH v11 1/8 kbuild: Allow multiple asm-offsets file to be generated
In order to allow multiple asm-offsets files to generated the include guard need to be different between these file. Add a asm_offset_name makefile macro to obtain an uppercase name matching the original asm offsets file.
--- scripts/asm-offsets.mak | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
scripts/asm-offsets.mak +15 -7
@@ -15,10 +15,14 @@ define sed-y s:->::; p;}' endef +define asm_offset_name + $(shell echo $(notdir $(1)) | tr [:lower:]- [:upper:]_) +endef + define make_asm_offsets (set -e; \ - echo "#ifndef __ASM_OFFSETS_H__"; \ - echo "#define __ASM_OFFSETS_H__"; \ + echo "#ifndef __$(strip $(asm_offset_name))_H__"; \ + echo "#define __$(strip $(asm_offset_name))_H__"; \ echo "/*"; \ echo " * Generated file. DO NOT MODIFY."; \ echo " *"; \
@@ -29,12 +33,16 @@ define make_asm_offsets echo "#endif" ) > $@ endef -$(asm-offsets:.h=.s): $(asm-offsets:.h=.c) - $(CC) $(CFLAGS) -fverbose-asm -S -o $@ $< +define gen_asm_offsets_rules +$(1).s: $(1).c + $(CC) $(CFLAGS) -fverbose-asm -S -o $$@ $$< + +$(1).h: $(1).s + $$(call make_asm_offsets,$(1)) + cp -f $$@ lib/generated/ +endef -$(asm-offsets): $(asm-offsets:.h=.s) - $(call make_asm_offsets) - cp -f $(asm-offsets) lib/generated/ +$(foreach o,$(asm-offsets),$(eval $(call gen_asm_offsets_rules, $(o:.h=)))) OBJDIRS += lib/generated
Signature · 1 line
2.47.2
PATCH v11 2/8 riscv: Set .aux.o files as .PRECIOUS
In reply to Clément LégerWhen compiling, we need to keep .aux.o file or they will be removed after the compilation which leads to dependent files to be recompiled. Set these files as .PRECIOUS to keep them.
--- riscv/Makefile | 1 + 1 file changed, 1 insertion(+)
riscv/Makefile +1 -0
@@ -90,6 +90,7 @@ CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib -I $(SRCDIR)/riscv asm-offsets = lib/riscv/asm-offsets.h include $(SRCDIR)/scripts/asm-offsets.mak +.PRECIOUS: %.aux.o %.aux.o: $(SRCDIR)/lib/auxinfo.c $(CC) $(CFLAGS) -c -o $@ $< \ -DPROGNAME=\"$(notdir $(@:.aux.o=.$(exe)))\" -DAUXFLAGS=$(AUXFLAGS)
Signature · 1 line
2.47.2
PATCH v11 3/8 riscv: Use asm-offsets to generate SBI_EXT_HSM values
In reply to Clément LégerReplace hardcoded values with generated ones using sbi-asm-offset. This allows to directly use ASM_SBI_EXT_HSM and ASM_SBI_EXT_HSM_STOP in assembly.
--- riscv/Makefile | 2 +- riscv/sbi-asm.S | 6 ++++-- riscv/sbi-asm-offsets.c | 11 +++++++++++ riscv/.gitignore | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 riscv/sbi-asm-offsets.c create mode 100644 riscv/.gitignore
riscv/Makefile +1 -1
@@ -87,7 +87,7 @@ CFLAGS += -ffreestanding CFLAGS += -O2 CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib -I $(SRCDIR)/riscv -asm-offsets = lib/riscv/asm-offsets.h +asm-offsets = lib/riscv/asm-offsets.h riscv/sbi-asm-offsets.h include $(SRCDIR)/scripts/asm-offsets.mak .PRECIOUS: %.aux.o
riscv/sbi-asm.S +4 -2
@@ -6,6 +6,8 @@ */ #include <asm/asm.h> #include <asm/csr.h> +#include <asm/asm-offsets.h> +#include <generated/sbi-asm-offsets.h> #include "sbi-tests.h"
@@ -57,8 +59,8 @@ sbi_hsm_check: 7: lb t0, 0(t1) pause beqz t0, 7b - li a7, 0x48534d /* SBI_EXT_HSM */ - li a6, 1 /* SBI_EXT_HSM_HART_STOP */ + li a7, ASM_SBI_EXT_HSM + li a6, ASM_SBI_EXT_HSM_HART_STOP ecall 8: pause j 8b
riscv/sbi-asm-offsets.c new file +11 -0
@@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include <kbuild.h> +#include <asm/sbi.h> + +int main (void ) +{ +DEFINE (ASM_SBI_EXT_HSM ,SBI_EXT_HSM ); +DEFINE (ASM_SBI_EXT_HSM_HART_STOP ,SBI_EXT_HSM_HART_STOP ); + +return 0 ; +}
riscv/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/*-asm-offsets.[hs]
Signature · 1 line
2.47.2
Re: [kvm-unit-tests PATCH v11 3/8] riscv: Use asm-offsets to generate SBI_EXT_HSM values
Quoted 33 lines · Clément Léger
Replace hardcoded values with generated ones using sbi-asm-offset. This allows to directly use
ASM_SBI_EXT_HSMandASM_SBI_EXT_HSM_STOPin assembly.Signed-off-by Clément Léger <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- riscv/Makefile | 2 +- riscv/sbi-asm.S | 6 ++++-- riscv/sbi-asm-offsets.c | 11 +++++++++++ riscv/.gitignore | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 riscv/sbi-asm-offsets.c create mode 100644 riscv/.gitignoreriscv/Makefile +1
-1@@ -87,7 +87,7 @@ CFLAGS += -ffreestanding CFLAGS += -O2 CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib -I $(SRCDIR)/riscv -asm-offsets = lib/riscv/asm-offsets.h +asm-offsets = lib/riscv/asm-offsets.h riscv/sbi-asm-offsets.h include $(SRCDIR)/scripts/asm-offsets.mak .PRECIOUS: %.aux.oriscv/sbi-asm.S +0
-0
riscv/sbi-asm.S line 10
Quoted 5 lines
riscv/sbi-asm.S +2
-0@@ -6,6 +6,8 @@ */ #include <asm/asm.h> #include <asm/csr.h> +#include <asm/asm-offsets.h> +#include <generated/sbi-asm-offsets.h>
Doing this causes sbi-asm.o to depend on generated files, so I had to add the change below to the Makefile in order for 'make -j' to work.
Thanks,
drew
riscv/Makefile +3 -1
@@ -19,6 +19,8 @@ all: $(tests) $(TEST_DIR)/sbi-deps = $(TEST_DIR)/sbi-asm.o $(TEST_DIR)/sbi-fwft.o +all_deps += $($(TEST_DIR)/sbi-deps) + # When built for EFI sieve needs extra memory, run with e.g. '-m 256' on QEMU $(TEST_DIR)/sieve.$(exe): AUXFLAGS = 0x1
@@ -134,7 +136,7 @@ else endif generated-files = $(asm-offsets) -$(tests:.$(exe)=.o) $(cstart.o) $(cflatobjs): $(generated-files) +$(tests:.$(exe)=.o) $(cstart.o) $(cflatobjs) $(all_deps): $(generated-files) arch_clean: asm_offsets_clean $(RM) $(TEST_DIR)/*.{o,flat,elf,so,efi,debug} \
Quoted 41 lines
riscv/sbi-asm.S +2
-2#include "sbi-tests.h"@@ -57,8 +59,8 @@ sbi_hsm_check: 7: lb t0, 0(t1) pause beqz t0, 7b - li a7, 0x48534d /* SBI_EXT_HSM */ - li a6, 1 /* SBI_EXT_HSM_HART_STOP */ + li a7, ASM_SBI_EXT_HSM + li a6, ASM_SBI_EXT_HSM_HART_STOP ecall 8: pause j 8briscv/sbi-asm-offsets.c new file +11
-0@@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include <kbuild.h> +#include <asm/sbi.h> + +int main (void ) +{ +DEFINE (ASM_SBI_EXT_HSM ,SBI_EXT_HSM ); +DEFINE (ASM_SBI_EXT_HSM_HART_STOP ,SBI_EXT_HSM_HART_STOP ); + +return 0 ; +}riscv/.gitignore new file +1
-0@@ -0,0 +1 @@ +/*-asm-offsets.[hs]Signature · 1 line
2.47.2
PATCH v11 4/8 lib: riscv: Add functions for version checking
In reply to Clément LégerVersion checking was done using some custom hardcoded values, backport a few SBI function and defines from Linux to do that cleanly.
--- lib/riscv/asm/sbi.h | 15 +++++++++++++++ lib/riscv/sbi.c | 9 +++++++-- 2 files changed, 22 insertions(+), 2 deletions(-)
lib/riscv/asm/sbi.h +15 -0
@@ -18,6 +18,13 @@#define SBI_ERR_IO -13#define SBI_ERR_DENIED_LOCKED -14 +/* SBI spec version fields */ +#define SBI_SPEC_VERSION_MAJOR_SHIFT 24 +#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f +#define SBI_SPEC_VERSION_MINOR_MASK 0xffffff +#define SBI_SPEC_VERSION_MASK ((SBI_SPEC_VERSION_MAJOR_MASK << SBI_SPEC_VERSION_MAJOR_SHIFT) | \ + SBI_SPEC_VERSION_MINOR_MASK) +#ifndef __ASSEMBLER__#include <cpumask.h>
@@ -110,6 +117,13 @@ struct sbiret {long value; }; +/* Make SBI version */ +static inline unsigned long sbi_mk_version (unsigned long major,unsigned long minor) +{ +return ((major &SBI_SPEC_VERSION_MAJOR_MASK ) <<SBI_SPEC_VERSION_MAJOR_SHIFT ) + | (minor &SBI_SPEC_VERSION_MINOR_MASK ); +} + struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4,
@@ -124,6 +138,7 @@ struct sbiret sbi_send_ipi_cpu(int cpu);struct sbiret sbi_send_ipi_cpumask (const cpumask_t *mask);struct sbiret sbi_send_ipi_broadcast (void );struct sbiret sbi_set_timer (unsigned long stime_value); +struct sbiret sbi_get_spec_version (void );long sbi_probe (int ext);#endif /* !__ASSEMBLER__ */
lib/riscv/sbi.c +7 -2
@@ -107,12 +107,17 @@ struct sbiret sbi_set_timer(unsigned long stime_value)return sbi_ecall (SBI_EXT_TIME ,SBI_EXT_TIME_SET_TIMER , stime_value,0 ,0 ,0 ,0 ,0 ); } +struct sbiret sbi_get_spec_version (void ) +{ +return sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_GET_SPEC_VERSION ,0 ,0 ,0 ,0 ,0 ,0 ); +} +long sbi_probe (int ext) {struct sbiret ret; - ret =sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_GET_SPEC_VERSION ,0 ,0 ,0 ,0 ,0 ,0 ); -assert (!ret.error && (ret.value &0x7ffffffful ) >=2 ); + ret =sbi_get_spec_version (); +assert (!ret.error && (ret.value &SBI_SPEC_VERSION_MASK ) >=sbi_mk_version (0 ,2 )); ret =sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_PROBE_EXT , ext,0 ,0 ,0 ,0 ,0 );assert (!ret.error);
Signature · 1 line
2.47.2
Re: [kvm-unit-tests PATCH v11 4/8] lib: riscv: Add functions for version checking
Quoted 14 lines · Clément Léger
Version checking was done using some custom hardcoded values, backport a few SBI function and defines from Linux to do that cleanly.
Signed-off-by Clément Léger <[email protected]>--- lib/riscv/asm/sbi.h | 15 +++++++++++++++ lib/riscv/sbi.c | 9 +++++++-- 2 files changed, 22 insertions(+), 2 deletions(-)lib/riscv/asm/sbi.h +0
-0
lib/riscv/asm/sbi.h line 26
Quoted 9 lines
lib/riscv/asm/sbi.h +6
-0@@ -18,6 +18,13 @@#define SBI_ERR_IO -13#define SBI_ERR_DENIED_LOCKED -14 +/* SBI spec version fields */ +#define SBI_SPEC_VERSION_MAJOR_SHIFT 24 +#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f +#define SBI_SPEC_VERSION_MINOR_MASK 0xffffff +#define SBI_SPEC_VERSION_MASK ((SBI_SPEC_VERSION_MAJOR_MASK << SBI_SPEC_VERSION_MAJOR_SHIFT) | \ + SBI_SPEC_VERSION_MINOR_MASK)
^ needs one more space
lib/riscv/asm/sbi.h struct sbiret { · line 120
Quoted 9 lines
lib/riscv/asm/sbi.h +2
-0+#ifndef __ASSEMBLER__#include <cpumask.h> @@ -110,6 +117,13 @@ struct sbiret {long value; }; +/* Make SBI version */
Unnecessary comment, it's the same as the function name.
Quoted 44 lines
lib/riscv/asm/sbi.h +7
-0+static inline unsigned long sbi_mk_version (unsigned long major,unsigned long minor) +{ +return ((major &SBI_SPEC_VERSION_MAJOR_MASK ) <<SBI_SPEC_VERSION_MAJOR_SHIFT ) + | (minor &SBI_SPEC_VERSION_MINOR_MASK ); +} + struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4,@@ -124,6 +138,7 @@ struct sbiret sbi_send_ipi_cpu(int cpu);struct sbiret sbi_send_ipi_cpumask (const cpumask_t *mask);struct sbiret sbi_send_ipi_broadcast (void );struct sbiret sbi_set_timer (unsigned long stime_value); +struct sbiret sbi_get_spec_version (void );long sbi_probe (int ext);#endif /* !__ASSEMBLER__ */ lib/riscv/sbi.c +7
-2@@ -107,12 +107,17 @@ struct sbiret sbi_set_timer(unsigned long stime_value)return sbi_ecall (SBI_EXT_TIME ,SBI_EXT_TIME_SET_TIMER , stime_value,0 ,0 ,0 ,0 ,0 ); } +struct sbiret sbi_get_spec_version (void ) +{ +return sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_GET_SPEC_VERSION ,0 ,0 ,0 ,0 ,0 ,0 ); +} +long sbi_probe (int ext) {struct sbiret ret; - ret =sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_GET_SPEC_VERSION ,0 ,0 ,0 ,0 ,0 ,0 ); -assert (!ret.error && (ret.value &0x7ffffffful ) >=2 ); + ret =sbi_get_spec_version (); +assert (!ret.error && (ret.value &SBI_SPEC_VERSION_MASK ) >=sbi_mk_version (0 ,2 )); ret =sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_PROBE_EXT , ext,0 ,0 ,0 ,0 ,0 );assert (!ret.error);Signature · 1 line
2.47.2
I fixed those two things up while applying.
Thanks,
drew
Re: [kvm-unit-tests PATCH v11 4/8] lib: riscv: Add functions for version checking
Quoted 29 lines · Andrew Jones
Quoted 14 lines · Clément Léger
Version checking was done using some custom hardcoded values, backport a few SBI function and defines from Linux to do that cleanly.
Signed-off-by Clément Léger <[email protected]>--- lib/riscv/asm/sbi.h | 15 +++++++++++++++ lib/riscv/sbi.c | 9 +++++++-- 2 files changed, 22 insertions(+), 2 deletions(-)lib/riscv/asm/sbi.h +0
-0lib/riscv/asm/sbi.h line 26
Quoted 9 lines
lib/riscv/asm/sbi.h +6
-0@@ -18,6 +18,13 @@#define SBI_ERR_IO -13#define SBI_ERR_DENIED_LOCKED -14 +/* SBI spec version fields */ +#define SBI_SPEC_VERSION_MAJOR_SHIFT 24 +#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f +#define SBI_SPEC_VERSION_MINOR_MASK 0xffffff +#define SBI_SPEC_VERSION_MASK ((SBI_SPEC_VERSION_MAJOR_MASK << SBI_SPEC_VERSION_MAJOR_SHIFT) | \ + SBI_SPEC_VERSION_MINOR_MASK)^ needs one more space
Quoted 4 lines
lib/riscv/asm/sbi.h +1
-0+#ifndef __ASSEMBLER__#include <cpumask.h>
Quoted 7 lines
lib/riscv/asm/sbi.h struct sbiret { · line 120
Quoted 5 lines
lib/riscv/asm/sbi.h +1
-0@@ -110,6 +117,13 @@ struct sbiret {long value; }; +/* Make SBI version */ Unnecessary comment, it's the same as the function name.
Yeah that's a copy/paste from Linux, didn't cleanup.
Quoted 40 lines
Quoted 40 lines
lib/riscv/asm/sbi.h +7
-0+static inline unsigned long sbi_mk_version (unsigned long major,unsigned long minor) +{ +return ((major &SBI_SPEC_VERSION_MAJOR_MASK ) <<SBI_SPEC_VERSION_MAJOR_SHIFT ) + | (minor &SBI_SPEC_VERSION_MINOR_MASK ); +} + struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4,@@ -124,6 +138,7 @@ struct sbiret sbi_send_ipi_cpu(int cpu);struct sbiret sbi_send_ipi_cpumask (const cpumask_t *mask);struct sbiret sbi_send_ipi_broadcast (void );struct sbiret sbi_set_timer (unsigned long stime_value); +struct sbiret sbi_get_spec_version (void );long sbi_probe (int ext);#endif /* !__ASSEMBLER__ */ lib/riscv/sbi.c +7
-2@@ -107,12 +107,17 @@ struct sbiret sbi_set_timer(unsigned long stime_value)return sbi_ecall (SBI_EXT_TIME ,SBI_EXT_TIME_SET_TIMER , stime_value,0 ,0 ,0 ,0 ,0 ); } +struct sbiret sbi_get_spec_version (void ) +{ +return sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_GET_SPEC_VERSION ,0 ,0 ,0 ,0 ,0 ,0 ); +} +long sbi_probe (int ext) {struct sbiret ret; - ret =sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_GET_SPEC_VERSION ,0 ,0 ,0 ,0 ,0 ,0 ); -assert (!ret.error && (ret.value &0x7ffffffful ) >=2 ); + ret =sbi_get_spec_version (); +assert (!ret.error && (ret.value &SBI_SPEC_VERSION_MASK ) >=sbi_mk_version (0 ,2 ));
Quoted 7 lines
Quoted 5 lines
lib/riscv/sbi.c +0
-0ret =sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_PROBE_EXT , ext,0 ,0 ,0 ,0 ,0 );assert (!ret.error);Signature · 1 line
2.47.2I fixed those two things up while applying.
Thanks Andrew,
Clément
Quoted 3 lines
Thanks,
drew
PATCH v11 5/8 lib: riscv: Add functions to get implementer ID and version
In reply to Clément LégerThese functions will be used by SSE tests to check for a specific OpenSBI version.
--- lib/riscv/asm/sbi.h | 20 ++++++++++++++++++++ lib/riscv/sbi.c | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+)
lib/riscv/asm/sbi.h +20 -0
@@ -18,6 +18,19 @@#define SBI_ERR_IO -13#define SBI_ERR_DENIED_LOCKED -14 +#define SBI_IMPL_BBL 0 +#define SBI_IMPL_OPENSBI 1 +#define SBI_IMPL_XVISOR 2 +#define SBI_IMPL_KVM 3 +#define SBI_IMPL_RUSTSBI 4 +#define SBI_IMPL_DIOSIX 5 +#define SBI_IMPL_COFFER 6 +#define SBI_IMPL_XEN 7 +#define SBI_IMPL_POLARFIRE_HSS 8 +#define SBI_IMPL_COREBOOT 9 +#define SBI_IMPL_OREBOOT 10 +#define SBI_IMPL_BHYVE 11 +/* SBI spec version fields */ #define SBI_SPEC_VERSION_MAJOR_SHIFT 24#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
@@ -124,6 +137,11 @@ static inline unsigned long sbi_mk_version(unsigned long major, unsigned long mi | (minor & SBI_SPEC_VERSION_MINOR_MASK); } +static inline unsigned long sbi_impl_opensbi_mk_version (unsigned long major,unsigned long minor) +{ +return (((major &0xffff ) <<16 ) | (minor &0xffff )); +} + struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4,
@@ -139,6 +157,8 @@ struct sbiret sbi_send_ipi_cpumask(const cpumask_t *mask);struct sbiret sbi_send_ipi_broadcast (void );struct sbiret sbi_set_timer (unsigned long stime_value);struct sbiret sbi_get_spec_version (void ); +unsigned long sbi_get_imp_version (void ); +unsigned long sbi_get_imp_id (void );long sbi_probe (int ext);#endif /* !__ASSEMBLER__ */
lib/riscv/sbi.c +20 -0
@@ -107,6 +107,26 @@ struct sbiret sbi_set_timer(unsigned long stime_value)return sbi_ecall (SBI_EXT_TIME ,SBI_EXT_TIME_SET_TIMER , stime_value,0 ,0 ,0 ,0 ,0 ); } +unsigned long sbi_get_imp_version (void ) +{ +struct sbiret ret; + + ret =sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_GET_IMP_VERSION ,0 ,0 ,0 ,0 ,0 ,0 ); +assert (!ret.error); + +return ret.value; +} + +unsigned long sbi_get_imp_id (void ) +{ +struct sbiret ret; + + ret =sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_GET_IMP_ID ,0 ,0 ,0 ,0 ,0 ,0 ); +assert (!ret.error); + +return ret.value; +} +struct sbiret sbi_get_spec_version (void ) {return sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_GET_SPEC_VERSION ,0 ,0 ,0 ,0 ,0 ,0 );
Signature · 1 line
2.47.2
Re: [kvm-unit-tests PATCH v11 5/8] lib: riscv: Add functions to get implementer ID and version
Quoted 88 lines · Clément Léger
These functions will be used by SSE tests to check for a specific OpenSBI version.
Signed-off-by Clément Léger <[email protected]>--- lib/riscv/asm/sbi.h | 20 ++++++++++++++++++++ lib/riscv/sbi.c | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+)lib/riscv/asm/sbi.h +20
-0@@ -18,6 +18,19 @@#define SBI_ERR_IO -13#define SBI_ERR_DENIED_LOCKED -14 +#define SBI_IMPL_BBL 0 +#define SBI_IMPL_OPENSBI 1 +#define SBI_IMPL_XVISOR 2 +#define SBI_IMPL_KVM 3 +#define SBI_IMPL_RUSTSBI 4 +#define SBI_IMPL_DIOSIX 5 +#define SBI_IMPL_COFFER 6 +#define SBI_IMPL_XEN 7 +#define SBI_IMPL_POLARFIRE_HSS 8 +#define SBI_IMPL_COREBOOT 9 +#define SBI_IMPL_OREBOOT 10 +#define SBI_IMPL_BHYVE 11 +/* SBI spec version fields */ #define SBI_SPEC_VERSION_MAJOR_SHIFT 24#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f@@ -124,6 +137,11 @@ static inline unsigned long sbi_mk_version(unsigned long major, unsigned long mi | (minor & SBI_SPEC_VERSION_MINOR_MASK); } +static inline unsigned long sbi_impl_opensbi_mk_version (unsigned long major,unsigned long minor) +{ +return (((major &0xffff ) <<16 ) | (minor &0xffff )); +} + struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4,@@ -139,6 +157,8 @@ struct sbiret sbi_send_ipi_cpumask(const cpumask_t *mask);struct sbiret sbi_send_ipi_broadcast (void );struct sbiret sbi_set_timer (unsigned long stime_value);struct sbiret sbi_get_spec_version (void ); +unsigned long sbi_get_imp_version (void ); +unsigned long sbi_get_imp_id (void );long sbi_probe (int ext);#endif /* !__ASSEMBLER__ */ lib/riscv/sbi.c +20
-0@@ -107,6 +107,26 @@ struct sbiret sbi_set_timer(unsigned long stime_value)return sbi_ecall (SBI_EXT_TIME ,SBI_EXT_TIME_SET_TIMER , stime_value,0 ,0 ,0 ,0 ,0 ); } +unsigned long sbi_get_imp_version (void ) +{ +struct sbiret ret; + + ret =sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_GET_IMP_VERSION ,0 ,0 ,0 ,0 ,0 ,0 ); +assert (!ret.error); + +return ret.value; +} + +unsigned long sbi_get_imp_id (void ) +{ +struct sbiret ret; + + ret =sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_GET_IMP_ID ,0 ,0 ,0 ,0 ,0 ,0 ); +assert (!ret.error); + +return ret.value; +} +struct sbiret sbi_get_spec_version (void ) {return sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_GET_SPEC_VERSION ,0 ,0 ,0 ,0 ,0 ,0 );Signature · 1 line
2.47.2
LGTM
Thanks,
drew
PATCH v11 6/8 riscv: lib: Add SBI SSE extension definitions
In reply to Clément LégerAdd SBI SSE extension definitions in sbi.h
--- lib/riscv/asm/sbi.h | 106 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-)
lib/riscv/asm/sbi.h +105 -1
@@ -50,6 +50,7 @@ enum sbi_ext_id {SBI_EXT_DBCN =0x4442434E ,SBI_EXT_SUSP =0x53555350 ,SBI_EXT_FWFT =0x46574654 , + SBI_EXT_SSE = 0x535345, }; enum sbi_ext_base_fid {
@@ -98,7 +99,6 @@ enum sbi_ext_dbcn_fid { SBI_EXT_DBCN_CONSOLE_WRITE_BYTE, }; -enum sbi_ext_fwft_fid {SBI_EXT_FWFT_SET =0 ,SBI_EXT_FWFT_GET ,
@@ -125,6 +125,110 @@ enum sbi_ext_fwft_fid {#define SBI_FWFT_SET_FLAG_LOCK BIT(0) +enum sbi_ext_sse_fid { +SBI_EXT_SSE_READ_ATTRS =0 , +SBI_EXT_SSE_WRITE_ATTRS , +SBI_EXT_SSE_REGISTER , +SBI_EXT_SSE_UNREGISTER , +SBI_EXT_SSE_ENABLE , +SBI_EXT_SSE_DISABLE , +SBI_EXT_SSE_COMPLETE , +SBI_EXT_SSE_INJECT , +SBI_EXT_SSE_HART_UNMASK , +SBI_EXT_SSE_HART_MASK , +}; + +/* SBI SSE Event Attributes. */ +enum sbi_sse_attr_id { +SBI_SSE_ATTR_STATUS =0x00000000 , +SBI_SSE_ATTR_PRIORITY =0x00000001 , +SBI_SSE_ATTR_CONFIG =0x00000002 , +SBI_SSE_ATTR_PREFERRED_HART =0x00000003 , +SBI_SSE_ATTR_ENTRY_PC =0x00000004 , +SBI_SSE_ATTR_ENTRY_ARG =0x00000005 , +SBI_SSE_ATTR_INTERRUPTED_SEPC =0x00000006 , +SBI_SSE_ATTR_INTERRUPTED_FLAGS =0x00000007 , +SBI_SSE_ATTR_INTERRUPTED_A6 =0x00000008 , +SBI_SSE_ATTR_INTERRUPTED_A7 =0x00000009 , +}; + +#define SBI_SSE_ATTR_STATUS_STATE_OFFSET 0 +#define SBI_SSE_ATTR_STATUS_STATE_MASK 0x3 +#define SBI_SSE_ATTR_STATUS_PENDING_OFFSET 2 +#define SBI_SSE_ATTR_STATUS_INJECT_OFFSET 3 + +#define SBI_SSE_ATTR_CONFIG_ONESHOT BIT(0) + +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP BIT(0) +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE BIT(1) +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV BIT(2) +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP BIT(3) +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP BIT(4) +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT BIT(5) + +enum sbi_sse_state { +SBI_SSE_STATE_UNUSED =0 , +SBI_SSE_STATE_REGISTERED =1 , +SBI_SSE_STATE_ENABLED =2 , +SBI_SSE_STATE_RUNNING =3 , +}; + +/* SBI SSE Event IDs. */ +/* Range 0x00000000 - 0x0000ffff */ +#define SBI_SSE_EVENT_LOCAL_HIGH_PRIO_RAS 0x00000000 +#define SBI_SSE_EVENT_LOCAL_DOUBLE_TRAP 0x00000001 +#define SBI_SSE_EVENT_LOCAL_RESERVED_0_START 0x00000002 +#define SBI_SSE_EVENT_LOCAL_RESERVED_0_END 0x00003fff +#define SBI_SSE_EVENT_LOCAL_PLAT_0_START 0x00004000 +#define SBI_SSE_EVENT_LOCAL_PLAT_0_END 0x00007fff + +#define SBI_SSE_EVENT_GLOBAL_HIGH_PRIO_RAS 0x00008000 +#define SBI_SSE_EVENT_GLOBAL_RESERVED_0_START 0x00008001 +#define SBI_SSE_EVENT_GLOBAL_RESERVED_0_END 0x0000bfff +#define SBI_SSE_EVENT_GLOBAL_PLAT_0_START 0x0000c000 +#define SBI_SSE_EVENT_GLOBAL_PLAT_0_END 0x0000ffff + +/* Range 0x00010000 - 0x0001ffff */ +#define SBI_SSE_EVENT_LOCAL_PMU_OVERFLOW 0x00010000 +#define SBI_SSE_EVENT_LOCAL_RESERVED_1_START 0x00010001 +#define SBI_SSE_EVENT_LOCAL_RESERVED_1_END 0x00013fff +#define SBI_SSE_EVENT_LOCAL_PLAT_1_START 0x00014000 +#define SBI_SSE_EVENT_LOCAL_PLAT_1_END 0x00017fff + +#define SBI_SSE_EVENT_GLOBAL_RESERVED_1_START 0x00018000 +#define SBI_SSE_EVENT_GLOBAL_RESERVED_1_END 0x0001bfff +#define SBI_SSE_EVENT_GLOBAL_PLAT_1_START 0x0001c000 +#define SBI_SSE_EVENT_GLOBAL_PLAT_1_END 0x0001ffff + +/* Range 0x00100000 - 0x0010ffff */ +#define SBI_SSE_EVENT_LOCAL_LOW_PRIO_RAS 0x00100000 +#define SBI_SSE_EVENT_LOCAL_RESERVED_2_START 0x00100001 +#define SBI_SSE_EVENT_LOCAL_RESERVED_2_END 0x00103fff +#define SBI_SSE_EVENT_LOCAL_PLAT_2_START 0x00104000 +#define SBI_SSE_EVENT_LOCAL_PLAT_2_END 0x00107fff + +#define SBI_SSE_EVENT_GLOBAL_LOW_PRIO_RAS 0x00108000 +#define SBI_SSE_EVENT_GLOBAL_RESERVED_2_START 0x00108001 +#define SBI_SSE_EVENT_GLOBAL_RESERVED_2_END 0x0010bfff +#define SBI_SSE_EVENT_GLOBAL_PLAT_2_START 0x0010c000 +#define SBI_SSE_EVENT_GLOBAL_PLAT_2_END 0x0010ffff + +/* Range 0xffff0000 - 0xffffffff */ +#define SBI_SSE_EVENT_LOCAL_SOFTWARE 0xffff0000 +#define SBI_SSE_EVENT_LOCAL_RESERVED_3_START 0xffff0001 +#define SBI_SSE_EVENT_LOCAL_RESERVED_3_END 0xffff3fff +#define SBI_SSE_EVENT_LOCAL_PLAT_3_START 0xffff4000 +#define SBI_SSE_EVENT_LOCAL_PLAT_3_END 0xffff7fff + +#define SBI_SSE_EVENT_GLOBAL_SOFTWARE 0xffff8000 +#define SBI_SSE_EVENT_GLOBAL_RESERVED_3_START 0xffff8001 +#define SBI_SSE_EVENT_GLOBAL_RESERVED_3_END 0xffffbfff +#define SBI_SSE_EVENT_GLOBAL_PLAT_3_START 0xffffc000 +#define SBI_SSE_EVENT_GLOBAL_PLAT_3_END 0xffffffff + +#define SBI_SSE_EVENT_PLATFORM_BIT BIT(14) +#define SBI_SSE_EVENT_GLOBAL_BIT BIT(15) +struct sbiret {long error;long value;
Signature · 1 line
2.47.2
PATCH v11 7/8 lib: riscv: Add SBI SSE support
In reply to Clément LégerAdd support for registering and handling SSE events. This will be used for sbi tests as well as upcoming double trap tests.
--- riscv/Makefile | 1 + lib/riscv/asm/csr.h | 1 + lib/riscv/asm/sbi.h | 36 ++++++++++++++ lib/riscv/sbi-sse-asm.S | 102 ++++++++++++++++++++++++++++++++++++++++ lib/riscv/asm-offsets.c | 9 ++++ lib/riscv/sbi.c | 76 ++++++++++++++++++++++++++++++ 6 files changed, 225 insertions(+) create mode 100644 lib/riscv/sbi-sse-asm.S
riscv/Makefile +1 -0
@@ -43,6 +43,7 @@ cflatobjs += lib/riscv/setup.o cflatobjs += lib/riscv/smp.o cflatobjs += lib/riscv/stack.o cflatobjs += lib/riscv/timer.o +cflatobjs += lib/riscv/sbi-sse-asm.o ifeq ($(ARCH),riscv32) cflatobjs += lib/ldiv32.o endif
lib/riscv/asm/csr.h +1 -0
@@ -17,6 +17,7 @@#define CSR_TIME 0xc01#define SR_SIE _AC(0x00000002, UL) +#define SR_SPP _AC(0x00000100, UL)/* Exception cause high bit - is an interrupt if set */ #define CAUSE_IRQ_FLAG (_AC(1, UL) << (__riscv_xlen - 1))
lib/riscv/asm/sbi.h +36 -0
@@ -265,5 +265,41 @@ unsigned long sbi_get_imp_version(void);unsigned long sbi_get_imp_id (void );long sbi_probe (int ext); +typedef void (*sbi_sse_handler_fn )(void *data,struct pt_regs *regs,unsigned int hartid); + +struct sbi_sse_handler_arg { +unsigned long reg_tmp; +sbi_sse_handler_fn handler; +void *handler_data; +void *stack; +}; + +extern void sbi_sse_entry (void ); + +static inline bool sbi_sse_event_is_global (uint32_t event_id) +{ +return !!(event_id &SBI_SSE_EVENT_GLOBAL_BIT ); +} + +struct sbiret sbi_sse_read_attrs_raw (unsigned long event_id,unsigned long base_attr_id, +unsigned long attr_count,unsigned long phys_lo, +unsigned long phys_hi); +struct sbiret sbi_sse_read_attrs (unsigned long event_id,unsigned long base_attr_id, +unsigned long attr_count,unsigned long *values); +struct sbiret sbi_sse_write_attrs_raw (unsigned long event_id,unsigned long base_attr_id, +unsigned long attr_count,unsigned long phys_lo, +unsigned long phys_hi); +struct sbiret sbi_sse_write_attrs (unsigned long event_id,unsigned long base_attr_id, +unsigned long attr_count,unsigned long *values); +struct sbiret sbi_sse_register_raw (unsigned long event_id,unsigned long entry_pc, +unsigned long entry_arg); +struct sbiret sbi_sse_register (unsigned long event_id,struct sbi_sse_handler_arg *arg); +struct sbiret sbi_sse_unregister (unsigned long event_id); +struct sbiret sbi_sse_enable (unsigned long event_id); +struct sbiret sbi_sse_disable (unsigned long event_id); +struct sbiret sbi_sse_hart_mask (void ); +struct sbiret sbi_sse_hart_unmask (void ); +struct sbiret sbi_sse_inject (unsigned long event_id,unsigned long hart_id); +#endif /* !__ASSEMBLER__ */ #endif /* _ASMRISCV_SBI_H_ */
lib/riscv/sbi-sse-asm.S new file +102 -0
102 lines not on this page · raw message
lib/riscv/asm-offsets.c +9 -0
@@ -3,6 +3,7 @@#include <elf.h> #include <asm/processor.h> #include <asm/ptrace.h> +#include <asm/sbi.h> #include <asm/smp.h> int main (void )
@@ -63,5 +64,13 @@ int main(void)OFFSET (THREAD_INFO_HARTID , thread_info, hartid);DEFINE (THREAD_INFO_SIZE ,sizeof (struct thread_info )); +DEFINE (ASM_SBI_EXT_SSE ,SBI_EXT_SSE ); +DEFINE (ASM_SBI_EXT_SSE_COMPLETE ,SBI_EXT_SSE_COMPLETE ); + +OFFSET (SBI_SSE_REG_TMP , sbi_sse_handler_arg, reg_tmp); +OFFSET (SBI_SSE_HANDLER , sbi_sse_handler_arg, handler); +OFFSET (SBI_SSE_HANDLER_DATA , sbi_sse_handler_arg, handler_data); +OFFSET (SBI_SSE_HANDLER_STACK , sbi_sse_handler_arg, stack); +return 0 ; }
lib/riscv/sbi.c +76 -0
88 lines not on this page · raw message
Signature · 1 line
2.47.2
PATCH v11 8/8 riscv: sbi: Add SSE extension tests
In reply to Clément LégerAdd SBI SSE extension tests for the following features:
- Test attributes errors (invalid values, RO, etc)
- Registration errors
- Simple events (register, enable, inject)
- Events with different priorities
- Global events dispatch on different harts
- Local events on all harts
- Hart mask/unmask events
--- riscv/Makefile | 1 + riscv/sbi-tests.h | 1 + riscv/sbi-sse.c | 1278 +++++++++++++++++++++++++++++++++++++++++++++ riscv/sbi.c | 2 + 4 files changed, 1282 insertions(+) create mode 100644 riscv/sbi-sse.c
riscv/Makefile +1 -0
@@ -18,6 +18,7 @@ tests += $(TEST_DIR)/sieve.$(exe) all: $(tests) $(TEST_DIR)/sbi-deps = $(TEST_DIR)/sbi-asm.o $(TEST_DIR)/sbi-fwft.o +$(TEST_DIR)/sbi-deps += $(TEST_DIR)/sbi-sse.o # When built for EFI sieve needs extra memory, run with e.g. '-m 256' on QEMU $(TEST_DIR)/sieve.$(exe): AUXFLAGS = 0x1
riscv/sbi-tests.h +1 -0
@@ -71,6 +71,7 @@ sbiret_report(ret, expected_error, expected_value, "check sbi.error and sbi.value")void sbi_bad_fid (int ext); +void check_sse (void );#endif /* __ASSEMBLER__ */ #endif /* _RISCV_SBI_TESTS_H_ */
riscv/sbi-sse.c new file +1278 -0
1,278 lines not on this page · raw message
riscv/sbi.c +2 -0
@@ -32,6 +32,7 @@#define HIGH_ADDR_BOUNDARY ((phys_addr_t)1 << 32) +void check_sse (void );void check_fwft (void );static long __labs (long a)
@@ -1567,6 +1568,7 @@ int main(int argc, char **argv)check_hsm ();check_dbcn ();check_susp (); +check_sse ();check_fwft ();return report_summary ();
Signature · 1 line
2.47.2
Re: [kvm-unit-tests PATCH v11 8/8] riscv: sbi: Add SSE extension tests
On Mon, Mar 17, 2025 at 05:46:53PM +0100, Clément Léger wrote:
...
Quoted 12 lines
(quoted diff) +12
-0+ /* Test all flags allowed for SBI_SSE_ATTR_INTERRUPTED_FLAGS */ + attr = SBI_SSE_ATTR_INTERRUPTED_FLAGS; + ret = sbi_sse_read_attrs(event_id, attr, 1, &prev_value); + sbiret_report_error(&ret, SBI_SUCCESS, "Save interrupted flags"); + + for (i = 0; i < ARRAY_SIZE(interrupted_flags); i++) { + flags = interrupted_flags[i]; + ret = sbi_sse_write_attrs(event_id, attr, 1, &flags); + sbiret_report_error(&ret, SBI_SUCCESS, + "Set interrupted flags bit 0x%lx value", flags); + ret = sbi_sse_read_attrs(event_id, attr, 1, &value); + sbiret_report_error(&ret, SBI_SUCCESS, "Get interrupted flags after set");
Review
Quoted 10 lines
(quoted diff) +10
-0+ report(value == flags, "interrupted flags modified value: 0x%lx", value); + } + + /* Write invalid bit in flag register */ + flags = SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT << 1; + ret = sbi_sse_write_attrs(event_id, attr, 1, &flags); + sbiret_report_error(&ret, SBI_ERR_INVALID_PARAM, "Set invalid flags bit 0x%lx value error", + flags); + + flags = BIT(SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT + 1);
This broke compiling for rv32, but just changing it to BIT_ULL wouldn't be right either since SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT is a BIT(). I think the test just above this one is what this test was aiming to do, making it redundant. Instead of removing it, I changed it as below to get more coverage, at least on rv64.
Thanks,
drew
riscv/sbi-sse.c +3 -1
@@ -495,10 +495,12 @@ static void sse_simple_handler(void *data, struct pt_regs *regs, unsigned int hasbiret_report_error (&ret,SBI_ERR_INVALID_PARAM ,"Set invalid flags bit 0x%lx value error" , flags); - flags =BIT (SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT +1 ); +#if __riscv_xlen >32 + flags =BIT (32 ); ret =sbi_sse_write_attrs (event_id, attr,1 , &flags);sbiret_report_error (&ret,SBI_ERR_INVALID_PARAM ,"Set invalid flags bit 0x%lx value error" , flags); +#endif ret =sbi_sse_write_attrs (event_id, attr,1 , &prev_value);sbiret_report_error (&ret,SBI_SUCCESS ,"Restore interrupted flags" );
Re: [kvm-unit-tests PATCH v11 8/8] riscv: sbi: Add SSE extension tests
Quoted 22 lines · Andrew Jones
On Mon, Mar 17, 2025 at 05:46:53PM +0100, Clément Léger wrote:
...Quoted 20 lines
(quoted diff) +20
-0+ /* Test all flags allowed for SBI_SSE_ATTR_INTERRUPTED_FLAGS */ + attr = SBI_SSE_ATTR_INTERRUPTED_FLAGS; + ret = sbi_sse_read_attrs(event_id, attr, 1, &prev_value); + sbiret_report_error(&ret, SBI_SUCCESS, "Save interrupted flags"); + + for (i = 0; i < ARRAY_SIZE(interrupted_flags); i++) { + flags = interrupted_flags[i]; + ret = sbi_sse_write_attrs(event_id, attr, 1, &flags); + sbiret_report_error(&ret, SBI_SUCCESS, + "Set interrupted flags bit 0x%lx value", flags); + ret = sbi_sse_read_attrs(event_id, attr, 1, &value); + sbiret_report_error(&ret, SBI_SUCCESS, "Get interrupted flags after set"); + report(value == flags, "interrupted flags modified value: 0x%lx", value); + } + + /* Write invalid bit in flag register */ + flags = SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT << 1; + ret = sbi_sse_write_attrs(event_id, attr, 1, &flags); + sbiret_report_error(&ret, SBI_ERR_INVALID_PARAM, "Set invalid flags bit 0x%lx value error", + flags);
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + flags = BIT(SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT + 1);This broke compiling for rv32, but just changing it to
BIT_ULLwouldn't be right either sinceSBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDTis aBIT(). I think the test just above this one is what this test was aiming to do, making it redundant. Instead of removing it, I changed it as below to get more coverage, at least on rv64.
Hum yeah indeed, that wasn't what was intended to be done. You fix is correct.
Thanks,
Clément
Quoted 22 lines
Thanks,
drewriscv/sbi-sse.c +3
-1@@ -495,10 +495,12 @@ static void sse_simple_handler(void *data, struct pt_regs *regs, unsigned int hasbiret_report_error (&ret,SBI_ERR_INVALID_PARAM ,"Set invalid flags bit 0x%lx value error" , flags); - flags =BIT (SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT +1 ); +#if __riscv_xlen >32 + flags =BIT (32 ); ret =sbi_sse_write_attrs (event_id, attr,1 , &flags);sbiret_report_error (&ret,SBI_ERR_INVALID_PARAM ,"Set invalid flags bit 0x%lx value error" , flags); +#endif ret =sbi_sse_write_attrs (event_id, attr,1 , &prev_value);sbiret_report_error (&ret,SBI_SUCCESS ,"Restore interrupted flags" );
Re: [kvm-unit-tests PATCH v11 8/8] riscv: sbi: Add SSE extension tests
In reply to Clément Léger...
riscv/sbi-sse.c line 648
Quoted 13 lines
riscv/sbi-sse.c new file +13
-0+cleanup: +switch (state) { +case SBI_SSE_STATE_ENABLED : + ret =sbi_sse_disable (event_id); +if (ret.error) { +sbiret_report_error (&ret,SBI_SUCCESS ,"disable event 0x%x" , event_id); +break ; + } +case SBI_SSE_STATE_REGISTERED : +sbi_sse_unregister (event_id); +if (ret.error) +sbiret_report_error (&ret,SBI_SUCCESS ,"unregister event 0x%x" , event_id); +default :
I had to add break here to make clang happy (and same for the other two defaults without statements).
Thanks,
drew
Re: [kvm-unit-tests PATCH v11 8/8] riscv: sbi: Add SSE extension tests
Quoted 17 lines · Andrew Jones
...
riscv/sbi-sse.c line 648
Quoted 13 lines
riscv/sbi-sse.c new file +13
-0+cleanup: +switch (state) { +case SBI_SSE_STATE_ENABLED : + ret =sbi_sse_disable (event_id); +if (ret.error) { +sbiret_report_error (&ret,SBI_SUCCESS ,"disable event 0x%x" , event_id); +break ; + } +case SBI_SSE_STATE_REGISTERED : +sbi_sse_unregister (event_id); +if (ret.error) +sbiret_report_error (&ret,SBI_SUCCESS ,"unregister event 0x%x" , event_id); +default :I had to add break here to make clang happy (and same for the other two defaults without statements).
Ok. Not directly related but I could/should have added "/* passthrough */" comments on the two cases above though.
Thanks,
Clément
Quoted 3 lines
Thanks,
drew
Hi Clément,
I'd like to merge this, but we still have 50 failures with the latest opensbi and over 30 with the opensbi QEMU provides. Testing with [1] and bumping the timeout to 6000 allowed me to avoid failures, however we can't count on that for CI.
[1] https://lists.infradead.org/pipermail/opensbi/2025-March/008190.html
I'm thinking about just doing the following. What do you think?
Thanks,
drew
riscv/sbi-sse.c +9 -17
@@ -1217,7 +1217,6 @@ void check_sse(void) {struct sse_event_info *info;unsigned long i, event_id; -bool sbi_skip_inject = false;bool supported;report_prefix_push ("sse" );
@@ -1228,6 +1227,13 @@ void check_sse(void)return ; } +if (sbi_get_imp_id () ==SBI_IMPL_OPENSBI && +sbi_get_imp_version () <sbi_impl_opensbi_mk_version (1 ,7 )) { +report_skip ("OpenSBI < v1.7 detected, skipping tests" ); +report_prefix_pop (); +return ; + } +sse_check_mask ();/*
@@ -1237,18 +1243,6 @@ void check_sse(void)*/ on_cpus (sse_secondary_boot_and_unmask,NULL ); -/* Check for OpenSBI to support injection */ -if (sbi_get_imp_id () ==SBI_IMPL_OPENSBI ) { -if (sbi_get_imp_version () <sbi_impl_opensbi_mk_version (1 ,6 )) { -/* -* OpenSBI < v1.6 crashes kvm-unit-tests upon injection since injection -* arguments (a6/a7) were reversed. Skip injection tests. -*/ -report_skip ("OpenSBI < v1.6 detected, skipping injection tests" ); - sbi_skip_inject = true; - } - } -sse_test_invalid_event_id ();for (i =0 ; i <ARRAY_SIZE (sse_event_infos); i++) {
@@ -1265,14 +1259,12 @@ void check_sse(void)sse_test_attrs (event_id);sse_test_register_error (event_id); -if (!sbi_skip_inject) -run_inject_test (info); +run_inject_test (info);report_prefix_pop (); } -if (!sbi_skip_inject) -sse_test_injection_priority (); +sse_test_injection_priority ();report_prefix_pop (); }
Quoted 126 lines · Clément Léger
This series adds tests for SBI SSE extension as well as needed infrastructure for SSE support. It also adds test specific asm-offsets generation to use custom OFFSET and DEFINE from the test directory.
These tests can be run using an OpenSBI version that implements latest specifications modification [1]
---
V11:
- Use mask insidesbi_impl_opensbi_mk_version()
- Mask the SBI version with a new mask
- Use assert inside sbi_get_impl_id/version()
- Removesbi_check_impl()
- Increase completion timeout as events failed completing under 1000 micros when system is loaded.V10:
- Use && instead of || for timeout handling
- Add SBI patches which introduce function to get implementer ID and version as well as implementer ID defines.
- Skip injection tests in OpenSBI < v1.6V9:
- Use__ASSEMBLER__instead of__ASSEMBLY__
- Remove extra spaces
- Use assert to check global event insse_global_event_set_current_hart()
- Tabulate SSE events names table
- Usesbi_sse_register()instead ofsbi_sse_register_raw()in error testing
- Move areport_pass()out of error path
- Rework all injection tests with better error handling
- Use an env var for sse event completion timeout
- Add timeout for some potentially infinitewhile()loopsV8:
- Short circuit current event tests if failure happens
- Remove SSE from all report strings
- Indent .prio field
- Add cpu_relax()/smp_rmb() where needed
- Add timeout for global event ENABLED state check
- Added BIT(32) aliases tests for attribute/event_id.V7:
- Test ids/attributes/attributes count > 32 bits
- Rename all SSE function to sbi_sse_*
- Useevent_idinstead of event/evt
- Factorize read/write test
- Usevirt_to_phys()for attributes read/write.
- Extensively usesbiret_report_error()
- Change check function return values to bool.
- Added assert for stack size to be below or equal toPAGE_SIZE
- Use en env variable for the maximum hart ID
- Check that individual read from attributes matches the multiple attributes read.
- Added multiple attributes write at once
- Used READ_ONCE/WRITE_ONCE
- Inject all local event at once rather than looping fopr each core.
- Splittest_argforlocal_dispatchtest so that all CPUs can run at once.
- Move SSE entry and generic code to lib/riscv for other tests
- Fix unmask/mask state checkingV6:
- Add missing $(generated-file) dependencies for "-deps" objects
- Split SSE entry fromsbi-asm.Stosse-asm.Sand all SSE core functions since it will be useful for other tests as well (dbltrp).V5:
- Update event ranges based on latest spec
- Renameasm-offset-test.ctosbi-asm-offset.cV4:
- Fix typosbi_ext_ss_fid->sbi_ext_sse_fid
- Add proper asm-offset generation for tests
- Move SSE specific file from lib/riscv to riscv/V3:
- Add -deps variable for test specific dependencies
- Fix formatting errors/typo insbi.h
- Add missing double trap event
- Alphabetizesbi-sse.cincludes
- Fix a6 content after unmasking event
- Add SSE HART_MASK/UNMASK test
- Use mv instead of move
- movesbi_check_sse()definition insbi.c
- Removesbi_ssetest from unitests.cfgV2:
- Rebased on origin/master and integrate it intosbi.ctestsClément Léger (8):
kbuild: Allow multiple asm-offsets file to be generated
riscv: Set .aux.o files as .PRECIOUS
riscv: Use asm-offsets to generateSBI_EXT_HSMvalues
lib: riscv: Add functions for version checking
lib: riscv: Add functions to get implementer ID and version
riscv: lib: Add SBI SSE extension definitions
lib: riscv: Add SBI SSE support
riscv: sbi: Add SSE extension testsscripts/asm-offsets.mak | 22 +- riscv/Makefile | 5 +- lib/riscv/asm/csr.h | 1 + lib/riscv/asm/sbi.h | 177 +++++- lib/riscv/sbi-sse-asm.S | 102 ++++ lib/riscv/asm-offsets.c | 9 + lib/riscv/sbi.c | 105 +++- riscv/sbi-tests.h | 1 + riscv/sbi-asm.S | 6 +- riscv/sbi-asm-offsets.c | 11 + riscv/sbi-sse.c | 1278 +++++++++++++++++++++++++++++++++++++++ riscv/sbi.c | 2 + riscv/.gitignore | 1 + 13 files changed, 1707 insertions(+), 13 deletions(-) create mode 100644 lib/riscv/sbi-sse-asm.S create mode 100644 riscv/sbi-asm-offsets.c create mode 100644 riscv/sbi-sse.c create mode 100644 riscv/.gitignoreSignature · 1 line
2.47.2
Clément Léger
Reviewed-byQuoted 10 lines · Andrew Jones
Hi Clément,
I'd like to merge this, but we still have 50 failures with the latest opensbi and over 30 with the opensbi QEMU provides. Testing with [1] and bumping the timeout to 6000 allowed me to avoid failures, however we can't count on that for CI.
[1] https://lists.infradead.org/pipermail/opensbi/2025-March/008190.html
I'm thinking about just doing the following. What do you think?
Hi Andrew,
Since the spec isn't even ratified, does it even make sense to test a version that does not implement the ratified SBI V3.0 spec ? IOW, should we simply test for SBI version to be >= 3.0 ? This will be correct for all SBI implementation.
However, If you want that series to be integrated ASAP, I'm ok with your patch , it seems unlikely that the SSE specification will change in the upcoming weeks.
Thanks,
Clément
Quoted 194 lines
Thanks,
drewriscv/sbi-sse.c +9
-17@@ -1217,7 +1217,6 @@ void check_sse(void) {struct sse_event_info *info;unsigned long i, event_id; -bool sbi_skip_inject = false;bool supported;report_prefix_push ("sse" );@@ -1228,6 +1227,13 @@ void check_sse(void)return ; } +if (sbi_get_imp_id () ==SBI_IMPL_OPENSBI && +sbi_get_imp_version () <sbi_impl_opensbi_mk_version (1 ,7 )) { +report_skip ("OpenSBI < v1.7 detected, skipping tests" ); +report_prefix_pop (); +return ; + } +sse_check_mask ();/* @@ -1237,18 +1243,6 @@ void check_sse(void)*/ on_cpus (sse_secondary_boot_and_unmask,NULL ); -/* Check for OpenSBI to support injection */ -if (sbi_get_imp_id () ==SBI_IMPL_OPENSBI ) { -if (sbi_get_imp_version () <sbi_impl_opensbi_mk_version (1 ,6 )) { -/* -* OpenSBI < v1.6 crashes kvm-unit-tests upon injection since injection -* arguments (a6/a7) were reversed. Skip injection tests. -*/ -report_skip ("OpenSBI < v1.6 detected, skipping injection tests" ); - sbi_skip_inject = true; - } - } -sse_test_invalid_event_id ();for (i =0 ; i <ARRAY_SIZE (sse_event_infos); i++) {@@ -1265,14 +1259,12 @@ void check_sse(void)sse_test_attrs (event_id);sse_test_register_error (event_id); -if (!sbi_skip_inject) -run_inject_test (info); +run_inject_test (info);report_prefix_pop (); } -if (!sbi_skip_inject) -sse_test_injection_priority (); +sse_test_injection_priority ();report_prefix_pop (); }Quoted 126 lines · Clément Léger
This series adds tests for SBI SSE extension as well as needed infrastructure for SSE support. It also adds test specific asm-offsets generation to use custom OFFSET and DEFINE from the test directory.
These tests can be run using an OpenSBI version that implements latest specifications modification [1]
---
V11:
- Use mask insidesbi_impl_opensbi_mk_version()
- Mask the SBI version with a new mask
- Use assert inside sbi_get_impl_id/version()
- Removesbi_check_impl()
- Increase completion timeout as events failed completing under 1000 micros when system is loaded.V10:
- Use && instead of || for timeout handling
- Add SBI patches which introduce function to get implementer ID and version as well as implementer ID defines.
- Skip injection tests in OpenSBI < v1.6V9:
- Use__ASSEMBLER__instead of__ASSEMBLY__
- Remove extra spaces
- Use assert to check global event insse_global_event_set_current_hart()
- Tabulate SSE events names table
- Usesbi_sse_register()instead ofsbi_sse_register_raw()in error testing
- Move areport_pass()out of error path
- Rework all injection tests with better error handling
- Use an env var for sse event completion timeout
- Add timeout for some potentially infinitewhile()loopsV8:
- Short circuit current event tests if failure happens
- Remove SSE from all report strings
- Indent .prio field
- Add cpu_relax()/smp_rmb() where needed
- Add timeout for global event ENABLED state check
- Added BIT(32) aliases tests for attribute/event_id.V7:
- Test ids/attributes/attributes count > 32 bits
- Rename all SSE function to sbi_sse_*
- Useevent_idinstead of event/evt
- Factorize read/write test
- Usevirt_to_phys()for attributes read/write.
- Extensively usesbiret_report_error()
- Change check function return values to bool.
- Added assert for stack size to be below or equal toPAGE_SIZE
- Use en env variable for the maximum hart ID
- Check that individual read from attributes matches the multiple attributes read.
- Added multiple attributes write at once
- Used READ_ONCE/WRITE_ONCE
- Inject all local event at once rather than looping fopr each core.
- Splittest_argforlocal_dispatchtest so that all CPUs can run at once.
- Move SSE entry and generic code to lib/riscv for other tests
- Fix unmask/mask state checkingV6:
- Add missing $(generated-file) dependencies for "-deps" objects
- Split SSE entry fromsbi-asm.Stosse-asm.Sand all SSE core functions since it will be useful for other tests as well (dbltrp).V5:
- Update event ranges based on latest spec
- Renameasm-offset-test.ctosbi-asm-offset.cV4:
- Fix typosbi_ext_ss_fid->sbi_ext_sse_fid
- Add proper asm-offset generation for tests
- Move SSE specific file from lib/riscv to riscv/V3:
- Add -deps variable for test specific dependencies
- Fix formatting errors/typo insbi.h
- Add missing double trap event
- Alphabetizesbi-sse.cincludes
- Fix a6 content after unmasking event
- Add SSE HART_MASK/UNMASK test
- Use mv instead of move
- movesbi_check_sse()definition insbi.c
- Removesbi_ssetest from unitests.cfgV2:
- Rebased on origin/master and integrate it intosbi.ctestsClément Léger (8):
kbuild: Allow multiple asm-offsets file to be generated
riscv: Set .aux.o files as .PRECIOUS
riscv: Use asm-offsets to generateSBI_EXT_HSMvalues
lib: riscv: Add functions for version checking
lib: riscv: Add functions to get implementer ID and version
riscv: lib: Add SBI SSE extension definitions
lib: riscv: Add SBI SSE support
riscv: sbi: Add SSE extension testsscripts/asm-offsets.mak | 22 +- riscv/Makefile | 5 +- lib/riscv/asm/csr.h | 1 + lib/riscv/asm/sbi.h | 177 +++++- lib/riscv/sbi-sse-asm.S | 102 ++++ lib/riscv/asm-offsets.c | 9 + lib/riscv/sbi.c | 105 +++- riscv/sbi-tests.h | 1 + riscv/sbi-asm.S | 6 +- riscv/sbi-asm-offsets.c | 11 + riscv/sbi-sse.c | 1278 +++++++++++++++++++++++++++++++++++++++ riscv/sbi.c | 2 + riscv/.gitignore | 1 + 13 files changed, 1707 insertions(+), 13 deletions(-) create mode 100644 lib/riscv/sbi-sse-asm.S create mode 100644 riscv/sbi-asm-offsets.c create mode 100644 riscv/sbi-sse.c create mode 100644 riscv/.gitignoreSignature · 1 line
2.47.2
Andrew Jones
AppliedQuoted 8 lines · Clément Léger
This series adds tests for SBI SSE extension as well as needed infrastructure for SSE support. It also adds test specific asm-offsets generation to use custom OFFSET and DEFINE from the test directory.
These tests can be run using an OpenSBI version that implements latest specifications modification [1]
Applied to riscv/sbi with the fixups pointed out.
https://gitlab.com/jones-drew/kvm-unit-tests/-/commits/riscv/sbi
Thanks,
drew
Quoted 118 lines
---
V11:
- Use mask insidesbi_impl_opensbi_mk_version()
- Mask the SBI version with a new mask
- Use assert inside sbi_get_impl_id/version()
- Removesbi_check_impl()
- Increase completion timeout as events failed completing under 1000 micros when system is loaded.V10:
- Use && instead of || for timeout handling
- Add SBI patches which introduce function to get implementer ID and version as well as implementer ID defines.
- Skip injection tests in OpenSBI < v1.6V9:
- Use__ASSEMBLER__instead of__ASSEMBLY__
- Remove extra spaces
- Use assert to check global event insse_global_event_set_current_hart()
- Tabulate SSE events names table
- Usesbi_sse_register()instead ofsbi_sse_register_raw()in error testing
- Move areport_pass()out of error path
- Rework all injection tests with better error handling
- Use an env var for sse event completion timeout
- Add timeout for some potentially infinitewhile()loopsV8:
- Short circuit current event tests if failure happens
- Remove SSE from all report strings
- Indent .prio field
- Add cpu_relax()/smp_rmb() where needed
- Add timeout for global event ENABLED state check
- Added BIT(32) aliases tests for attribute/event_id.V7:
- Test ids/attributes/attributes count > 32 bits
- Rename all SSE function to sbi_sse_*
- Useevent_idinstead of event/evt
- Factorize read/write test
- Usevirt_to_phys()for attributes read/write.
- Extensively usesbiret_report_error()
- Change check function return values to bool.
- Added assert for stack size to be below or equal toPAGE_SIZE
- Use en env variable for the maximum hart ID
- Check that individual read from attributes matches the multiple attributes read.
- Added multiple attributes write at once
- Used READ_ONCE/WRITE_ONCE
- Inject all local event at once rather than looping fopr each core.
- Splittest_argforlocal_dispatchtest so that all CPUs can run at once.
- Move SSE entry and generic code to lib/riscv for other tests
- Fix unmask/mask state checkingV6:
- Add missing $(generated-file) dependencies for "-deps" objects
- Split SSE entry fromsbi-asm.Stosse-asm.Sand all SSE core functions since it will be useful for other tests as well (dbltrp).V5:
- Update event ranges based on latest spec
- Renameasm-offset-test.ctosbi-asm-offset.cV4:
- Fix typosbi_ext_ss_fid->sbi_ext_sse_fid
- Add proper asm-offset generation for tests
- Move SSE specific file from lib/riscv to riscv/V3:
- Add -deps variable for test specific dependencies
- Fix formatting errors/typo insbi.h
- Add missing double trap event
- Alphabetizesbi-sse.cincludes
- Fix a6 content after unmasking event
- Add SSE HART_MASK/UNMASK test
- Use mv instead of move
- movesbi_check_sse()definition insbi.c
- Removesbi_ssetest from unitests.cfgV2:
- Rebased on origin/master and integrate it intosbi.ctestsClément Léger (8):
kbuild: Allow multiple asm-offsets file to be generated
riscv: Set .aux.o files as .PRECIOUS
riscv: Use asm-offsets to generateSBI_EXT_HSMvalues
lib: riscv: Add functions for version checking
lib: riscv: Add functions to get implementer ID and version
riscv: lib: Add SBI SSE extension definitions
lib: riscv: Add SBI SSE support
riscv: sbi: Add SSE extension testsscripts/asm-offsets.mak | 22 +- riscv/Makefile | 5 +- lib/riscv/asm/csr.h | 1 + lib/riscv/asm/sbi.h | 177 +++++- lib/riscv/sbi-sse-asm.S | 102 ++++ lib/riscv/asm-offsets.c | 9 + lib/riscv/sbi.c | 105 +++- riscv/sbi-tests.h | 1 + riscv/sbi-asm.S | 6 +- riscv/sbi-asm-offsets.c | 11 + riscv/sbi-sse.c | 1278 +++++++++++++++++++++++++++++++++++++++ riscv/sbi.c | 2 + riscv/.gitignore | 1 + 13 files changed, 1707 insertions(+), 13 deletions(-) create mode 100644 lib/riscv/sbi-sse-asm.S create mode 100644 riscv/sbi-asm-offsets.c create mode 100644 riscv/sbi-sse.c create mode 100644 riscv/.gitignoreSignature · 1 line
2.47.2
Quoted 8 lines · Clément Léger
This series adds tests for SBI SSE extension as well as needed infrastructure for SSE support. It also adds test specific asm-offsets generation to use custom OFFSET and DEFINE from the test directory.
These tests can be run using an OpenSBI version that implements latest specifications modification [1]
Merged.
Thanks,
drew