From: Andrew Jones <ajones@ventanamicro.com>
To: Alistair Francis <alistair23@gmail.com>
Cc: Alexei Filippov <alexei.filippov@syntacore.com>,
alistair.francis@wdc.com, apatel@ventanamicro.com,
bin.meng@windriver.com, dbarboza@ventanamicro.com,
liwei1518@gmail.com, palmer@dabbelt.com, qemu-devel@nongnu.org,
qemu-riscv@nongnu.org, zhiwei_liu@linux.alibaba.com
Subject: Re: [PATCH v4] target/riscv/kvm/kvm-cpu.c: kvm_riscv_handle_sbi() fail with vendor-specific SBI
Date: Mon, 22 Apr 2024 10:12:10 +0200 [thread overview]
Message-ID: <20240422-e78b28f00a168518c5d4937a@orel> (raw)
In-Reply-To: <CAKmqyKN1ATWcSqNXXG-81shqRj_XPG0hSVPVtW3gjeOCgNNfuw@mail.gmail.com>
On Mon, Apr 22, 2024 at 01:55:31PM +1000, Alistair Francis wrote:
> On Sat, Apr 13, 2024 at 9:26 PM Alexei Filippov
> <alexei.filippov@syntacore.com> wrote:
> >
> > kvm_riscv_handle_sbi() may return not supported return code to not trigger
> > qemu abort with vendor-specific sbi.
> >
> > Added SBI related return code's defines.
> >
> > Signed-off-by: Alexei Filippov <alexei.filippov@syntacore.com>
> > Fixes: 4eb47125 ("target/riscv: Handle KVM_EXIT_RISCV_SBI exit")
> > ---
> >
> > Changes since v3:
> > -Clear Reviewed-by tags
> > target/riscv/kvm/kvm-cpu.c | 13 +++++--------
> > target/riscv/sbi_ecall_interface.h | 12 ++++++++++++
> > 2 files changed, 17 insertions(+), 8 deletions(-)
> >
> > diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
> > index 6a6c6cae80..844942d9ba 100644
> > --- a/target/riscv/kvm/kvm-cpu.c
> > +++ b/target/riscv/kvm/kvm-cpu.c
> > @@ -1392,7 +1392,6 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs)
> >
> > static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
> > {
> > - int ret = 0;
> > unsigned char ch;
> > switch (run->riscv_sbi.extension_id) {
> > case SBI_EXT_0_1_CONSOLE_PUTCHAR:
> > @@ -1400,22 +1399,20 @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
> > qemu_chr_fe_write(serial_hd(0)->be, &ch, sizeof(ch));
> > break;
> > case SBI_EXT_0_1_CONSOLE_GETCHAR:
> > - ret = qemu_chr_fe_read_all(serial_hd(0)->be, &ch, sizeof(ch));
> > - if (ret == sizeof(ch)) {
> > + if (qemu_chr_fe_read_all(serial_hd(0)->be, &ch, sizeof(ch)) == sizeof(ch)) {
> > run->riscv_sbi.ret[0] = ch;
> > } else {
> > - run->riscv_sbi.ret[0] = -1;
> > + run->riscv_sbi.ret[0] = SBI_ERR_FAILURE;
>
> I'm not sure I follow. This seems like a failure but we report success
> to the caller of this function?
>
> Can you expand the commit message to explain why we want this change
Looking at this again, I think it would be more clear, and more correct,
if we only do the SBI_ERR_FAILURE path for a return value of exactly zero.
...
ret = qemu_chr_fe_read_all(...);
if (ret == sizeof(ch)) {
run->riscv_sbi.ret[0] = ch;
ret = 0;
} else if (ret == 0) {
run->riscv_sbi.ret[0] = SBI_ERR_FAILURE;
}
break;
...
return ret;
Exactly zero just means we failed to read input, which can happen, so
telling the SBI caller we failed to read, but telling the caller of this
function that we successfully emulated the SBI call, is correct. However,
anything else, other than sizeof(ch), means something unexpected happened,
so we should indeed return an error from this function.
Thanks,
drew
>
> Alistair
>
> > }
> > - ret = 0;
> > break;
> > default:
> > qemu_log_mask(LOG_UNIMP,
> > - "%s: un-handled SBI EXIT, specific reasons is %lu\n",
> > + "%s: Unhandled SBI exit with extension-id %lu\n",
> > __func__, run->riscv_sbi.extension_id);
> > - ret = -1;
> > + run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED;
> > break;
> > }
> > - return ret;
> > + return 0;
> > }
> >
> > int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
> > diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h
> > index 43899d08f6..a2e21d9b8c 100644
> > --- a/target/riscv/sbi_ecall_interface.h
> > +++ b/target/riscv/sbi_ecall_interface.h
> > @@ -69,4 +69,16 @@
> > #define SBI_EXT_VENDOR_END 0x09FFFFFF
> > /* clang-format on */
> >
> > +/* SBI return error codes */
> > +#define SBI_SUCCESS 0
> > +#define SBI_ERR_FAILURE -1
> > +#define SBI_ERR_NOT_SUPPORTED -2
> > +#define SBI_ERR_INVALID_PARAM -3
> > +#define SBI_ERR_DENIED -4
> > +#define SBI_ERR_INVALID_ADDRESS -5
> > +#define SBI_ERR_ALREADY_AVAILABLE -6
> > +#define SBI_ERR_ALREADY_STARTED -7
> > +#define SBI_ERR_ALREADY_STOPPED -8
> > +#define SBI_ERR_NO_SHMEM -9
> > +
> > #endif
> > --
> > 2.34.1
> >
> >
next prev parent reply other threads:[~2024-04-22 8:12 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-25 10:14 [PATCH] target/riscv/kvm/kvm-cpu.c: kvm_riscv_handle_sbi() fail with vendor-specific SBI Alexei Filippov
2024-03-25 11:51 ` Daniel Henrique Barboza
2024-03-25 13:01 ` [PATCH v2] " Alexei Filippov
2024-03-26 4:54 ` Alistair Francis
2024-03-27 12:57 ` [PATCH v3] " Alexei Filippov
2024-03-26 9:50 ` [PATCH v2] " Andrew Jones
2024-04-13 11:25 ` [PATCH v4] " Alexei Filippov
2024-04-15 14:03 ` Andrew Jones
2024-04-22 3:55 ` Alistair Francis
2024-04-22 8:12 ` Andrew Jones [this message]
2024-04-22 11:24 ` [PATCH v5] target/riscv/kvm/kvm-cpu.c: kvm_riscv_handle_sbi() fail with vendor-specific sbi Alexei Filippov
2024-04-22 11:40 ` Aleksei Filippov
2024-04-22 11:42 ` [PATCH v6] target/riscv/kvm/kvm-cpu.c: kvm_riscv_handle_sbi() fail with vendor-specific SBI Alexei Filippov
2024-04-22 12:31 ` Andrew Jones
2024-04-25 9:21 ` Andrew Jones
2024-05-03 10:39 ` Aleksei Filippov
2024-05-03 11:55 ` Andrew Jones
2024-05-27 13:48 ` [PATCH v7] " Alexei Filippov
2024-05-27 15:03 ` Andrew Jones
2024-06-25 15:02 ` [PATCH v8] " Alexei Filippov
2024-06-26 15:18 ` Andrew Jones
2024-09-17 11:54 ` [PATCH v9] " Alexei Filippov
2024-09-17 12:29 ` Andrew Jones
2024-09-17 13:10 ` Andrew Jones
2024-09-18 13:37 ` Aleksei Filippov
2024-09-18 13:41 ` Andrew Jones
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=20240422-e78b28f00a168518c5d4937a@orel \
--to=ajones@ventanamicro.com \
--cc=alexei.filippov@syntacore.com \
--cc=alistair.francis@wdc.com \
--cc=alistair23@gmail.com \
--cc=apatel@ventanamicro.com \
--cc=bin.meng@windriver.com \
--cc=dbarboza@ventanamicro.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=zhiwei_liu@linux.alibaba.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).