From: Andrew Jones <andrew.jones@linux.dev>
To: Jesse Taube <jesse@rivosinc.com>
Cc: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org,
linux-kselftest@vger.kernel.org,
"Clément Léger" <cleger@rivosinc.com>,
"Charlie Jenkins" <charlie@rivosinc.com>,
"James Raphael Tiovalen" <jamestiotio@gmail.com>,
"Sean Christopherson" <seanjc@google.com>,
"Cade Richard" <cade.richard@gmail.com>
Subject: Re: [kvm-unit-tests PATCH] riscv: lib: sbi_shutdown add exit code.
Date: Tue, 24 Jun 2025 10:41:37 +0200 [thread overview]
Message-ID: <20250624-9f7044f67c5054d0a948b94a@orel> (raw)
In-Reply-To: <CALSpo=YQun4owTSkCULpgSu386nHK4q8kuU--oif4Wtw2S_V1w@mail.gmail.com>
On Mon, Jun 23, 2025 at 03:46:31PM -0700, Jesse Taube wrote:
> On Mon, Jun 23, 2025 at 10:01 AM Andrew Jones <andrew.jones@linux.dev> wrote:
> >
> > On Fri, Jun 20, 2025 at 08:50:51AM -0700, Jesse Taube wrote:
> > > When exiting it may be useful for the sbi implementation to know the
> > > exit code.
> > > Add exit code to sbi_shutdown, and use it in exit().
> > >
> > > Signed-off-by: Jesse Taube <jesse@rivosinc.com>
> > > ---
> > > lib/riscv/asm/sbi.h | 2 +-
> > > lib/riscv/io.c | 2 +-
> > > lib/riscv/sbi.c | 4 ++--
> > > 3 files changed, 4 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h
> > > index a5738a5c..de11c109 100644
> > > --- a/lib/riscv/asm/sbi.h
> > > +++ b/lib/riscv/asm/sbi.h
> > > @@ -250,7 +250,7 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
> > > unsigned long arg3, unsigned long arg4,
> > > unsigned long arg5);
> > >
> > > -void sbi_shutdown(void);
> > > +void sbi_shutdown(unsigned int code);
> > > struct sbiret sbi_hart_start(unsigned long hartid, unsigned long entry, unsigned long sp);
> > > struct sbiret sbi_hart_stop(void);
> > > struct sbiret sbi_hart_get_status(unsigned long hartid);
> > > diff --git a/lib/riscv/io.c b/lib/riscv/io.c
> > > index fb40adb7..02231268 100644
> > > --- a/lib/riscv/io.c
> > > +++ b/lib/riscv/io.c
> > > @@ -150,7 +150,7 @@ void halt(int code);
> > > void exit(int code)
> > > {
> > > printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1);
> > > - sbi_shutdown();
> > > + sbi_shutdown(code & 1);
> > > halt(code);
> > > __builtin_unreachable();
> > > }
> > > diff --git a/lib/riscv/sbi.c b/lib/riscv/sbi.c
> > > index 2959378f..9dd11e9d 100644
> > > --- a/lib/riscv/sbi.c
> > > +++ b/lib/riscv/sbi.c
> > > @@ -107,9 +107,9 @@ struct sbiret sbi_sse_inject(unsigned long event_id, unsigned long hart_id)
> > > return sbi_ecall(SBI_EXT_SSE, SBI_EXT_SSE_INJECT, event_id, hart_id, 0, 0, 0, 0);
> > > }
> > >
> > > -void sbi_shutdown(void)
> > > +void sbi_shutdown(unsigned int code)
> > > {
> > > - sbi_ecall(SBI_EXT_SRST, 0, 0, 0, 0, 0, 0, 0);
> > > + sbi_ecall(SBI_EXT_SRST, 0, 0, code, 0, 0, 0, 0);
> >
> > We can't do this because a kvm-unit-tests exit code is not an
> > SRST::reset_reason[1]. This could result in the SBI implementation
> > returning an error, or doing something else, rather than shutting
> > down.
>
> Yes that's why there is:
> +sbi_shutdown(code & 1);
Ah, I overlooked that.
> Admittedly it should probably be:
> +sbi_shutdown(!!code);
Indeed, it would only work now because bit 0 is set in the abort
exit code.
>
> >
> > If this is a custom kvm-unit-tests-specific SBI implementation, then
> > we could pass in a reset_reason in the 0xE0000000 - 0xEFFFFFFF range.
>
> That still doesn't guarantee it to succeed.
> In the exit function we can add a fallback like `sbi_shutdown(0);`,
> but reason code 1 (System failure) should always work.
> If anyone wants to use it for SBI specific codes, that's fine,
> but I only added it for the No reason and System failure exit codes.
Yup, I see now that the intention is just to say success/failure, not
pass down the actual exit code. The commit message says exit code,
though, which is why I didn't read the patch closely.
Please send a v2 with the !! change and a change to the commit message.
Thanks,
drew
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
prev parent reply other threads:[~2025-06-24 8:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-20 15:50 [kvm-unit-tests PATCH] riscv: lib: sbi_shutdown add exit code Jesse Taube
2025-06-23 17:01 ` Andrew Jones
2025-06-23 22:46 ` Jesse Taube
2025-06-24 8:41 ` Andrew Jones [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250624-9f7044f67c5054d0a948b94a@orel \
--to=andrew.jones@linux.dev \
--cc=cade.richard@gmail.com \
--cc=charlie@rivosinc.com \
--cc=cleger@rivosinc.com \
--cc=jamestiotio@gmail.com \
--cc=jesse@rivosinc.com \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).