lib: sbi: sse: clear SPV for non-virtualized events

SSE injection sets hstatus.SPV to the virtualization state of the
interrupted context before entering the supervisor handler. This patch
completes that existing requirement and does not change the SSE ABI.

The existing code sets SPV when the interrupted context is virtualized,
but leaves it unchanged otherwise. A stale SPV value can therefore make
an event that interrupted host execution appear to have interrupted a
guest. Event completion can then resume with virtualization enabled.

Clear SPV when the interrupted context is not virtualized so the
handler-visible state matches the interrupted context. This also lets
supervisor software, such as the Linux PMU and perf code, reliably tell
whether an SSE interrupted host or virtualized execution.

Fixes: c8cdf01d8f ("lib: sbi: Add support for Supervisor Software Events extension")
Signed-off-by: Zhanpeng Zhang <zhangzhanpeng.jasper@bytedance.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260731071820.7318-1-zhangzhanpeng.jasper@bytedance.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Zhanpeng Zhang
2026-09-01 12:57:33 +05:30
committed by Anup Patel
parent 22a5f98b39
commit 35511bc6ee
+4 -9
View File
@@ -563,19 +563,14 @@ static void sse_event_inject(struct sbi_sse_event *e,
if (misa_extension('H')) { if (misa_extension('H')) {
unsigned long hstatus = csr_read(CSR_HSTATUS); unsigned long hstatus = csr_read(CSR_HSTATUS);
if (sbi_regs_from_virt(regs))
#if __riscv_xlen == 64
if (regs->mstatus & MSTATUS_MPV)
#elif __riscv_xlen == 32
if (regs->mstatusH & MSTATUSH_MPV)
#else
#error "Unexpected __riscv_xlen"
#endif
hstatus |= HSTATUS_SPV; hstatus |= HSTATUS_SPV;
else
hstatus &= ~HSTATUS_SPV;
hstatus &= ~HSTATUS_SPVP; hstatus &= ~HSTATUS_SPVP;
if (hstatus & HSTATUS_SPV && regs->mstatus & SSTATUS_SPP) if (hstatus & HSTATUS_SPV && regs->mstatus & SSTATUS_SPP)
hstatus |= HSTATUS_SPVP; hstatus |= HSTATUS_SPVP;
csr_write(CSR_HSTATUS, hstatus); csr_write(CSR_HSTATUS, hstatus);
} }