riscv: add SBI SSE extension tests
Subsystems (3)
v9 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.
---
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 (6):
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
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 | 142 ++++- lib/riscv/sbi-sse-asm.S | 102 ++++ lib/riscv/asm-offsets.c | 9 + lib/riscv/sbi.c | 76 +++ riscv/sbi-tests.h | 1 + riscv/sbi-asm.S | 6 +- riscv/sbi-asm-offsets.c | 11 + riscv/sbi-sse.c | 1263 +++++++++++++++++++++++++++++++++++++++ riscv/sbi.c | 2 + riscv/.gitignore | 1 + 13 files changed, 1630 insertions(+), 11 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 v9 1/6 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 v9 2/6 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 v9 3/6 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
PATCH v9 4/6 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
@@ -30,6 +30,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 {
@@ -78,7 +79,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 ,
@@ -105,6 +105,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 v9 5/6 lib: riscv: Add SBI SSE support
In reply to Clément LégerAdd support for registering and handling SSE events. This will be used by sbi test 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
@@ -230,5 +230,41 @@ struct sbiret sbi_send_ipi_broadcast(void);struct sbiret sbi_set_timer (unsigned long stime_value);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 v9 6/6 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 | 1263 +++++++++++++++++++++++++++++++++++++++++++++ riscv/sbi.c | 2 + 4 files changed, 1267 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 +1263 -0
1,263 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 v9 6/6] riscv: sbi: Add SSE extension tests
On Fri, Mar 14, 2025 at 12:10:29PM +0100, Clément Léger wrote:
...
Quoted 36 lines
riscv/sbi-sse.c new file +36
-0+static void sse_test_inject_local (uint32_t event_id) +{ +int cpu; +uint64_t timeout; +struct sbiret ret; +struct sse_local_per_cpu *cpu_args, *cpu_arg; +struct sse_foreign_cpu_test_arg *handler_arg; + + cpu_args =calloc (NR_CPUS ,sizeof (struct sbi_sse_handler_arg )); + +report_prefix_push ("local_dispatch" ); +for_each_online_cpu (cpu) { + cpu_arg = &cpu_args[cpu]; + cpu_arg->handler_arg.event_id = event_id; + cpu_arg->args.stack =sse_alloc_stack (); + cpu_arg->args.handler = sse_foreign_cpu_handler; + cpu_arg->args.handler_data = (void *)&cpu_arg->handler_arg; + cpu_arg->state =SBI_SSE_STATE_UNUSED ; + } + +on_cpus (sse_register_enable_local, cpu_args); +for_each_online_cpu (cpu) { + cpu_arg = &cpu_args[cpu]; + ret = cpu_arg->ret; +if (ret.error) { +report_fail ("CPU failed to register/enable event: %ld" , ret.error); + goto cleanup; + } + + handler_arg = &cpu_arg->handler_arg; +WRITE_ONCE (handler_arg->expected_cpu, cpu); +/* For handler_arg content to be visible for other CPUs */ +smp_wmb (); + ret =sbi_sse_inject (event_id, cpus[cpu].hartid); +if (ret.error) { +report_fail ("CPU failed to inject event: %ld" , ret.error);
riscv/sbi-sse.c line 784
Quoted 10 lines
riscv/sbi-sse.c new file +10
-0+ goto cleanup; + } + } + +for_each_online_cpu (cpu) { + handler_arg = &cpu_args[cpu].handler_arg; +smp_rmb (); + + timeout =sse_event_get_complete_timeout (); +while (!READ_ONCE (handler_arg->done) ||timer_get_cycles () < timeout) {
I pointed this out in the last review, the || should be a &&. We don't want to keep waiting until we reach the timeout if we get the done signal earlier.
Quoted 42 lines
riscv/sbi-sse.c new file +42
-0+/* For handler_arg update to be visible */ +smp_rmb (); +cpu_relax (); + } +report (READ_ONCE (handler_arg->done),"Event handled" ); +WRITE_ONCE (handler_arg->done, false); + } + +cleanup: +on_cpus (sbi_sse_disable_unregister_local, cpu_args); +for_each_online_cpu (cpu) { + cpu_arg = &cpu_args[cpu]; + ret =READ_ONCE (cpu_arg->ret); +if (ret.error) +report_fail ("CPU failed to disable/unregister event: %ld" , ret.error); + } + +for_each_online_cpu (cpu) { + cpu_arg = &cpu_args[cpu]; +sse_free_stack (cpu_arg->args.stack); + } + +report_prefix_pop (); +} + +static void sse_test_inject_global_cpu (uint32_t event_id,unsigned int cpu, +struct sse_foreign_cpu_test_arg *test_arg) +{ +unsigned long value; +struct sbiret ret; +uint64_t timeout; +enum sbi_sse_state state; + +WRITE_ONCE (test_arg->expected_cpu, cpu); +/* For test_arg content to be visible for other CPUs */ +smp_wmb (); + value = cpu; + ret =sbi_sse_write_attrs (event_id,SBI_SSE_ATTR_PREFERRED_HART ,1 , &value); +if (!sbiret_report_error (&ret,SBI_SUCCESS ,"Set preferred hart" )) +return ; + + ret =sbi_sse_enable (event_id);
riscv/sbi-sse.c line 836
Quoted 10 lines
riscv/sbi-sse.c new file +10
-0+if (!sbiret_report_error (&ret,SBI_SUCCESS ,"Enable event" )) +return ; + + ret =sbi_sse_inject (event_id, cpu); +if (!sbiret_report_error (&ret,SBI_SUCCESS ,"Inject event" )) + goto disable; + +smp_rmb (); + timeout =sse_event_get_complete_timeout (); +while (!READ_ONCE (test_arg->done) ||timer_get_cycles () < timeout) {
same comment
Quoted 6 lines
riscv/sbi-sse.c new file +6
-0+/* For shared test_arg structure */ +smp_rmb (); +cpu_relax (); + } + +report (READ_ONCE (test_arg->done),"event handler called" );
riscv/sbi-sse.c line 852
Quoted 10 lines
riscv/sbi-sse.c new file +10
-0+WRITE_ONCE (test_arg->done, false); + + timeout =sse_event_get_complete_timeout (); +/* Wait for event to be back in ENABLED state */ +do { + ret =sse_event_get_state (event_id, &state); +if (ret.error) + goto disable; +cpu_relax (); + }while (state !=SBI_SSE_STATE_ENABLED ||timer_get_cycles () < timeout);
same comment
Otherwise,
Thanks,
drew
Re: [kvm-unit-tests PATCH v9 6/6] riscv: sbi: Add SSE extension tests
Quoted 44 lines · Andrew Jones
On Fri, Mar 14, 2025 at 12:10:29PM +0100, Clément Léger wrote:
...Quoted 42 lines
riscv/sbi-sse.c new file +42
-0+static void sse_test_inject_local (uint32_t event_id) +{ +int cpu; +uint64_t timeout; +struct sbiret ret; +struct sse_local_per_cpu *cpu_args, *cpu_arg; +struct sse_foreign_cpu_test_arg *handler_arg; + + cpu_args =calloc (NR_CPUS ,sizeof (struct sbi_sse_handler_arg )); + +report_prefix_push ("local_dispatch" ); +for_each_online_cpu (cpu) { + cpu_arg = &cpu_args[cpu]; + cpu_arg->handler_arg.event_id = event_id; + cpu_arg->args.stack =sse_alloc_stack (); + cpu_arg->args.handler = sse_foreign_cpu_handler; + cpu_arg->args.handler_data = (void *)&cpu_arg->handler_arg; + cpu_arg->state =SBI_SSE_STATE_UNUSED ; + } + +on_cpus (sse_register_enable_local, cpu_args); +for_each_online_cpu (cpu) { + cpu_arg = &cpu_args[cpu]; + ret = cpu_arg->ret; +if (ret.error) { +report_fail ("CPU failed to register/enable event: %ld" , ret.error); + goto cleanup; + } + + handler_arg = &cpu_arg->handler_arg; +WRITE_ONCE (handler_arg->expected_cpu, cpu); +/* For handler_arg content to be visible for other CPUs */ +smp_wmb (); + ret =sbi_sse_inject (event_id, cpus[cpu].hartid); +if (ret.error) { +report_fail ("CPU failed to inject event: %ld" , ret.error); + goto cleanup; + } + } + +for_each_online_cpu (cpu) { + handler_arg = &cpu_args[cpu].handler_arg;
Quoted 8 lines
riscv/sbi-sse.c line 784
Quoted 4 lines
riscv/sbi-sse.c new file +4
-0+smp_rmb (); + + timeout =sse_event_get_complete_timeout (); +while (!READ_ONCE (handler_arg->done) ||timer_get_cycles () < timeout) {I pointed this out in the last review, the || should be a &&. We don't want to keep waiting until we reach the timeout if we get the done signal earlier.
Missed it. I'll resend a V10 if you don't have any other comments.
Thanks,
Clément
Quoted 81 lines
Quoted 43 lines
riscv/sbi-sse.c new file +42
-0+/* For handler_arg update to be visible */ +smp_rmb (); +cpu_relax (); + } +report (READ_ONCE (handler_arg->done),"Event handled" ); +WRITE_ONCE (handler_arg->done, false); + } + +cleanup: +on_cpus (sbi_sse_disable_unregister_local, cpu_args); +for_each_online_cpu (cpu) { + cpu_arg = &cpu_args[cpu]; + ret =READ_ONCE (cpu_arg->ret); +if (ret.error) +report_fail ("CPU failed to disable/unregister event: %ld" , ret.error); + } + +for_each_online_cpu (cpu) { + cpu_arg = &cpu_args[cpu]; +sse_free_stack (cpu_arg->args.stack); + } + +report_prefix_pop (); +} + +static void sse_test_inject_global_cpu (uint32_t event_id,unsigned int cpu, +struct sse_foreign_cpu_test_arg *test_arg) +{ +unsigned long value; +struct sbiret ret; +uint64_t timeout; +enum sbi_sse_state state; + +WRITE_ONCE (test_arg->expected_cpu, cpu); +/* For test_arg content to be visible for other CPUs */ +smp_wmb (); + value = cpu; + ret =sbi_sse_write_attrs (event_id,SBI_SSE_ATTR_PREFERRED_HART ,1 , &value); +if (!sbiret_report_error (&ret,SBI_SUCCESS ,"Set preferred hart" )) +return ; + + ret =sbi_sse_enable (event_id);riscv/sbi-sse.c line 836
Quoted 10 lines
riscv/sbi-sse.c new file +10
-0+if (!sbiret_report_error (&ret,SBI_SUCCESS ,"Enable event" )) +return ; + + ret =sbi_sse_inject (event_id, cpu); +if (!sbiret_report_error (&ret,SBI_SUCCESS ,"Inject event" )) + goto disable; + +smp_rmb (); + timeout =sse_event_get_complete_timeout (); +while (!READ_ONCE (test_arg->done) ||timer_get_cycles () < timeout) {same comment
Quoted 6 lines
riscv/sbi-sse.c new file +6
-0+/* For shared test_arg structure */ +smp_rmb (); +cpu_relax (); + } + +report (READ_ONCE (test_arg->done),"event handler called" );riscv/sbi-sse.c line 852
Quoted 10 lines
riscv/sbi-sse.c new file +10
-0+WRITE_ONCE (test_arg->done, false); + + timeout =sse_event_get_complete_timeout (); +/* Wait for event to be back in ENABLED state */ +do { + ret =sse_event_get_state (event_id, &state); +if (ret.error) + goto disable; +cpu_relax (); + }while (state !=SBI_SSE_STATE_ENABLED ||timer_get_cycles () < timeout);same comment
Otherwise,
Reviewed-by Andrew Jones <[email protected]>Thanks,
drew
Re: [kvm-unit-tests PATCH v9 6/6] riscv: sbi: Add SSE extension tests
On Fri, Mar 14, 2025 at 03:13:07PM +0100, Clément Léger wrote:
...
Quoted 1 line
Missed it. I'll resend a V10 if you don't have any other comments.
Other comments are on the cover letter.
Thanks,
drew
Quoted 3 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.
Is there an opensbi branch I should be using to test this? There are currently 54 failures reported with opensbi's master branch, and, with opensbi v1.5.1, which is the version provided by qemu's master branch, I get a crash which leads to a recursive stack walk. The crash occurs in what I'm guessing is sbi_sse_inject() by the last successful output.
I can't merge this without it skipping/kfailing with qemu's opensbi, otherwise it'll fail CI. We could change CI to be more tolerant, but I'd rather use kfail instead, and of course not crash.
Thanks,
drew
Quoted 10 lines · Andrew Jones
Quoted 3 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.
Is there an opensbi branch I should be using to test this? There are currently 54 failures reported with opensbi's master branch, and, with opensbi v1.5.1, which is the version provided by qemu's master branch, I get a crash which leads to a recursive stack walk. The crash occurs in what I'm guessing is
sbi_sse_inject()by the last successful output.
Yeah that's due to a6/a7 being inverted at injection time.
Quoted 4 lines
I can't merge this without it skipping/kfailing with qemu's opensbi, otherwise it'll fail CI. We could change CI to be more tolerant, but I'd rather use kfail instead, and of course not crash.
Yes, the branch dev/cleger/sse on github can be used:
https://github.com/rivosinc/opensbi/tree/dev/cleger/sse
I'm waiting for the specification error changes to be merged before sending this one.
Thanks,
Clément
Quoted 3 lines
Thanks,
drew
Quoted 21 lines · Clément Léger
Quoted 10 lines · Andrew Jones
Quoted 3 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.
Is there an opensbi branch I should be using to test this? There are currently 54 failures reported with opensbi's master branch, and, with opensbi v1.5.1, which is the version provided by qemu's master branch, I get a crash which leads to a recursive stack walk. The crash occurs in what I'm guessing is
sbi_sse_inject()by the last successful output.Yeah that's due to a6/a7 being inverted at injection time.
Quoted 4 lines
I can't merge this without it skipping/kfailing with qemu's opensbi, otherwise it'll fail CI. We could change CI to be more tolerant, but I'd rather use kfail instead, and of course not crash.
Quoted 6 lines
Yes, the branch dev/cleger/sse on github can be used:
https://github.com/rivosinc/opensbi/tree/dev/cleger/sse
I'm waiting for the specification error changes to be merged before sending this one.
While ugly, I'm not opposed to doing an SBI implementation ID and version check at the entry of the SSE tests and then just SKIP when we detect opensbi and not a late enough version of it. If we go that route, then please create a separate patch that adds a couple functions in lib/riscv/sbi allowing all sbi unit tests to easily check for specific SBI implementations and versions. (We'll probably want to steal the kernel's sbi_mk_version and add an enum or defines for the SBI implementation IDs.)
Thanks,
drew
Quoted 29 lines · Andrew Jones
Quoted 21 lines · Clément Léger
Quoted 10 lines · Andrew Jones
Quoted 3 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.
Is there an opensbi branch I should be using to test this? There are currently 54 failures reported with opensbi's master branch, and, with opensbi v1.5.1, which is the version provided by qemu's master branch, I get a crash which leads to a recursive stack walk. The crash occurs in what I'm guessing is
sbi_sse_inject()by the last successful output.Yeah that's due to a6/a7 being inverted at injection time.
Quoted 4 lines
I can't merge this without it skipping/kfailing with qemu's opensbi, otherwise it'll fail CI. We could change CI to be more tolerant, but I'd rather use kfail instead, and of course not crash.
Quoted 6 lines
Yes, the branch dev/cleger/sse on github can be used:
https://github.com/rivosinc/opensbi/tree/dev/cleger/sse
I'm waiting for the specification error changes to be merged before sending this one.
Quoted 8 lines
While ugly, I'm not opposed to doing an SBI implementation ID and version check at the entry of the SSE tests and then just SKIP when we detect opensbi and not a late enough version of it. If we go that route, then please create a separate patch that adds a couple functions in
lib/riscv/sbiallowing all sbi unit tests to easily check for specific SBI implementations and versions. (We'll probably want to steal the kernel'ssbi_mk_versionand add an enum or defines for the SBI implementation IDs.)
Based on the fact that it actually crashes on earlier OpenSBI version, I feel like we are not going to cut it if we want it to be reliable on all OpenSBI versions. I'll take a look at what you propose.
Thanks,
Clément
Quoted 3 lines
Thanks,
drew