Re: [PATCH v2 04/11] RISC-V: KVM: Modify SBI extension handler to return SBI error code

From: Andrew Jones
Date: Fri Jan 13 2023 - 02:42:47 EST


On Thu, Jan 12, 2023 at 10:47:13AM -0800, Atish Kumar Patra wrote:
> On Thu, Jan 12, 2023 at 3:04 AM Andrew Jones <ajones@xxxxxxxxxxxxxxxx> wrote:
> >
> > On Thu, Dec 15, 2022 at 09:00:39AM -0800, Atish Patra wrote:
...
> > > + * and forwards the error to the userspace.
> > > + */
> > > + if (ret < 0) {
> > > + next_sepc = false;
> > > + goto ecall_done;
> > > + }
> >
> > Shouldn't this ret < 0 check go above the "Handle special error cases..."
> > block?
> >
>
> Why ? I thought if an extension handler has both utrap updated and
> returns an error,
> user space redirection should take precedence. Let me know if it is wrong.

My thinking was that utrap cannot be trusted if the handler returned an
error. The handler may not even have had a chance to set it before hitting
the error condition. IOW, we should check 'ret' right after the handler
call. If it's < 0, then from the caller's perspective the handler didn't
execute due to a KVM failure and it should be reported to userspace.

Thanks,
drew