Re: [PATCH] lib: sbi: sse: clear SPV for non-virtualized events

Zhanpeng Zhang <[email protected]>
Newsgroups org.infradead.lists.opensbi
Message-ID <CACnXVnfypnh+zD4+gu7=7PbiWrj0jv8sN_2JiRSdHx-q70fj4g@mail.gmail.com>
Hi Anup and Himanshu,

On 7/31/26 3:18 PM, Zhanpeng Zhang wrote:
> 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: c8cdf01d8f3a ("lib: sbi: Add support for Supervisor Software Events extension")
> Signed-off-by: Zhanpeng Zhang <[email protected]>
> ---
>   lib/sbi/sbi_sse.c | 11 +++--------
>   1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
> index 818afb87..68e4fab4 100644
> --- a/lib/sbi/sbi_sse.c
> +++ b/lib/sbi/sbi_sse.c
> @@ -563,15 +563,10 @@ static void sse_event_inject(struct sbi_sse_event *e,
>
>   	if (misa_extension('H')) {
>   		unsigned long hstatus = csr_read(CSR_HSTATUS);
> -
> -#if __riscv_xlen == 64
> -		if (regs->mstatus & MSTATUS_MPV)
> -#elif __riscv_xlen == 32
> -		if (regs->mstatusH & MSTATUSH_MPV)
> -#else
> -#error "Unexpected __riscv_xlen"
> -#endif
> +		if (sbi_regs_from_virt(regs))
>   			hstatus |= HSTATUS_SPV;
> +		else
> +			hstatus &= ~HSTATUS_SPV;
>
>   		hstatus &= ~HSTATUS_SPVP;
>   		if (hstatus & HSTATUS_SPV && regs->mstatus & SSTATUS_SPP)

A gentle ping on this SSE fix.

The SSE specification requires handler-entry hstatus.SPV to reflect the
interrupted virtualization state. The current code handles the
virtualized case, but can leave SPV stale when host execution is
interrupted.

This is also needed by the Linux PMU-SSE work to attribute host and
guest samples correctly. The patch only completes the existing
injection semantics and does not change the SSE ABI.

Any comments would be appreciated.

Thanks,
Zhanpeng

-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.