From dc1c45b86cb0243f6a32840acbefa78f773e4105 Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Mon, 12 Oct 2026 22:03:58 -0700 Subject: [PATCH] fix(sdei): keep event 0 pending while the PE is masked When the SGI behind event 0 arrives at a PE that has SDEI events masked, handle_masked_trigger() returns without ending the interrupt. The SGI stays active at the SDEI priority, which keeps the running priority of that PE above every Non-secure interrupt. The PE then takes no Non-secure interrupt at all, and SDEI_PE_UNMASK does not undo it. sdei_signal() refuses a target PE that is masked, but it reads the target's state from another PE. The target can mask between that check and the arrival of the SGI, and a client masks its PE around every power-down state and on its way off, so a signal sent at the wrong moment is enough. The caller has been told SUCCESS by then. The specification wants a private event triggered on a masked PE to stay pending and be delivered after SDEI_PE_UNMASK. Do that for event 0: end the interrupt, remember the signal for the PE, and raise the SGI again when the PE unmasks. The SGI is raised again rather than left pending at the interrupt controller, because SGI pending state is not something every controller lets software set or clear. A PE powered on afresh drops a signal its previous power-on missed. Tested on QEMU virt (GICv3) with Linux, on v2.12 where sdei_signal() has no target check: a PE signalled while masked keeps taking IPIs and runs the event 0 handler right after it unmasks. Signed-off-by: Cong Wang Change-Id: Iada3da6b1ed4a6d58c6b8fc2daea79946032d1d3 --- diff --git a/services/std_svc/sdei/sdei_intr_mgmt.c b/services/std_svc/sdei/sdei_intr_mgmt.c index c2de835..50ca0ed 100644 --- a/services/std_svc/sdei/sdei_intr_mgmt.c +++ b/services/std_svc/sdei/sdei_intr_mgmt.c @@ -54,6 +54,8 @@ unsigned short stack_top; /* Empty ascending */ bool pe_masked; bool pending_enables; + /* Event 0 was signalled while this PE was masked */ + bool pending_signal; } sdei_cpu_state_t; /* SDEI state for each core in the system */ @@ -136,6 +138,19 @@ state->pending_enables = false; state->pe_masked = false; + + if (state->pending_signal) { + state->pending_signal = false; + map = find_event_map(SDEI_EVENT_0); + assert(map != NULL); + plat_ic_raise_el3_sgi((int) map->intr, read_mpidr_el1()); + } +} + +/* Drop an event 0 signal that a previous power-on of this PE missed */ +void sdei_pe_clear_signal(void) +{ + sdei_get_this_pe_state()->pending_signal = false; } /* Push a dispatch context to the dispatch stack */ @@ -331,9 +346,16 @@ uint64_t my_mpidr __unused = (read_mpidr_el1() & MPIDR_AFFINITY_MASK); bool disable = false; - /* Nothing to do for event 0 */ - if (map->ev_num == SDEI_EVENT_0) + /* + * Event 0 must stay pending until the PE unmasks, like any private + * event. Its SGI cannot portably be left pending at the interrupt + * controller, so end it and raise it again from sdei_pe_unmask(). + */ + if (map->ev_num == SDEI_EVENT_0) { + state->pending_signal = true; + plat_ic_end_of_interrupt(intr_raw); return; + } /* * For a private event, or for a shared event specifically routed to diff --git a/services/std_svc/sdei/sdei_main.c b/services/std_svc/sdei/sdei_main.c index 6791419..9389fc3 100644 --- a/services/std_svc/sdei/sdei_main.c +++ b/services/std_svc/sdei/sdei_main.c @@ -79,6 +79,7 @@ /* All PEs start with SDEI events masked */ (void) sdei_pe_mask(); + sdei_pe_clear_signal(); return NULL; } diff --git a/services/std_svc/sdei/sdei_private.h b/services/std_svc/sdei/sdei_private.h index 788e8db..d2859b0 100644 --- a/services/std_svc/sdei/sdei_private.h +++ b/services/std_svc/sdei/sdei_private.h @@ -241,6 +241,7 @@ bool sdei_is_target_pe_masked(uint64_t target_pe); int64_t sdei_pe_mask(void); void sdei_pe_unmask(void); +void sdei_pe_clear_signal(void); int sdei_intr_handler(uint32_t intr_raw, uint32_t flags, void *handle, void *cookie);