riscv: sbi: sse: Fix some potential crashes
Subsystems (3)
cover riscv: sbi: sse: Fix some potential crashes
While validating another SBI, we encountered a few crashes and errors in the SSE tests. Fix SSE stack freeing as well as handler call checking. Also add READ_ONCE()/WRITE_ONCE() for some shared variable.
Clément Léger (3):
riscv: sbi: sse: Fix wrong sse stack initialization
riscv: sbi: sse: Add missing index for handler call check
riscv: sbi: sse: Use READ_ONCE()/WRITE_ONCE() for shared variables
riscv/sbi-sse.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
Signature · 1 line
2.50.0
PATCH 1/3 riscv: sbi: sse: Fix wrong sse stack initialization
The sse stack temporary storage wasn't correctly initialize to 0. Since this is used to know if stack needs to be deallocated at the end (in the error handling path), sse_stack_free() would crash if an error happened while registering the sse event for instance. Fix this by correctly initializing all the stacks entries.
--- riscv/sbi-sse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
riscv/sbi-sse.c +1 -1
@@ -957,8 +957,8 @@ static void sse_test_injection_priority_arg(struct priority_test_arg *in_args,continue ; args[args_size] = arg; + event_args[args_size].stack =0 ; args_size++; - event_args->stack =0 ; }if (!args_size) {
Signature · 1 line
2.50.0
PATCH 2/3 riscv: sbi: sse: Add missing index for handler call check
In reply to Clément LégerThe check for handler to be finished was actually missing the index, leading to a single handler call being checked.
--- riscv/sbi-sse.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
riscv/sbi-sse.c +4 -2
@@ -1017,8 +1017,10 @@ static void sse_test_injection_priority_arg(struct priority_test_arg *in_args,sbiret_report_error (&ret,SBI_SUCCESS ,"injection" );/* Check that all handlers have been called */ -for (i =0 ; i < args_size; i++) -report (arg->called,"Event %s handler called" ,sse_event_name (args[i]->event_id)); +for (i =0 ; i < args_size; i++) { + arg = args[i]; +report (arg->called,"Event %s handler called" ,sse_event_name (arg->event_id)); + } err:for (i =0 ; i < args_size; i++) {
Signature · 1 line
2.50.0
PATCH 3/3 riscv: sbi: sse: Use READ_ONCE()/WRITE_ONCE() for shared variables
In reply to Clément LégerUse READ_ONCE() and WRITE_ONCE() for variables that are shared between the SSE handler and the main process.
--- riscv/sbi-sse.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
riscv/sbi-sse.c +8 -6
@@ -918,15 +918,16 @@ static void sse_low_priority_test_handler(void *arg, struct pt_regs *regs, unsigned int hartid) {struct priority_test_arg *targ = arg; -struct priority_test_arg *next = targ->next_event_arg; +struct priority_test_arg *next =READ_ONCE (targ->next_event_arg); - targ->called = true; +WRITE_ONCE (targ->called, true);if (next) {sbi_sse_inject (next->event_id,current_thread_info ()->hartid);report (sse_event_pending (next->event_id),"Lower priority event is pending" ); -report (!next->called,"Lower priority event %s was not handled before %s" , +report (!READ_ONCE (next->called), +"Lower priority event %s was not handled before %s" ,sse_event_name (next->event_id),sse_event_name (targ->event_id)); } }
@@ -977,9 +978,9 @@ static void sse_test_injection_priority_arg(struct priority_test_arg *in_args, event_arg->stack = stack;if (i < (args_size -1 )) - arg->next_event_arg = args[i +1 ]; +WRITE_ONCE (arg->next_event_arg, args[i +1 ]);else - arg->next_event_arg =NULL ; +WRITE_ONCE (arg->next_event_arg,NULL );/* Be sure global events are targeting the current hart */ if (sbi_sse_event_is_global (event_id)) {
@@ -1019,7 +1020,8 @@ static void sse_test_injection_priority_arg(struct priority_test_arg *in_args,/* Check that all handlers have been called */ for (i =0 ; i < args_size; i++) { arg = args[i]; -report (arg->called,"Event %s handler called" ,sse_event_name (arg->event_id)); +report (READ_ONCE (arg->called),"Event %s handler called" , +sse_event_name (arg->event_id)); } err:
Signature · 1 line
2.50.0
Andrew Jones
AppliedQuoted 4 lines · Clément Léger
While validating another SBI, we encountered a few crashes and errors in the SSE tests. Fix SSE stack freeing as well as handler call checking. Also add READ_ONCE()/WRITE_ONCE() for some shared variable.
Quoted 11 lines
Clément Léger (3):
riscv: sbi: sse: Fix wrong sse stack initialization
riscv: sbi: sse: Add missing index for handler call check
riscv: sbi: sse: Use READ_ONCE()/WRITE_ONCE() for shared variablesriscv/sbi-sse.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)Signature · 1 line
2.50.0
Applied to riscv/sbi
https://gitlab.com/jones-drew/kvm-unit-tests/-/commits/riscv/sbi
Thanks,
drew
Quoted 4 lines · Clément Léger
While validating another SBI, we encountered a few crashes and errors in the SSE tests. Fix SSE stack freeing as well as handler call checking. Also add READ_ONCE()/WRITE_ONCE() for some shared variable.
Quoted 11 lines
Clément Léger (3):
riscv: sbi: sse: Fix wrong sse stack initialization
riscv: sbi: sse: Add missing index for handler call check
riscv: sbi: sse: Use READ_ONCE()/WRITE_ONCE() for shared variablesriscv/sbi-sse.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)Signature · 1 line
2.50.0
Merged. Thanks