From: Jan Beulich <jbeulich@suse.com>
To: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Cc: "Alistair Francis" <alistair.francis@wdc.com>,
"Bob Eshleman" <bobbyeshleman@gmail.com>,
"Connor Davis" <connojdavis@gmail.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Michal Orzel" <michal.orzel@amd.com>,
"Julien Grall" <julien@xen.org>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v1 1/3] xen/riscv: introduce vSBI extension framework
Date: Mon, 8 Dec 2025 15:25:41 +0100 [thread overview]
Message-ID: <df316e2f-9eb0-4bb8-96cd-e5e0c42d123e@suse.com> (raw)
In-Reply-To: <3b67330dc4c1aa053eb15261a559e7b4eac3f493.1764582112.git.oleksii.kurochko@gmail.com>
On 01.12.2025 11:24, Oleksii Kurochko wrote:
> This commit introduces support for handling virtual SBI extensions in Xen.
>
> The changes include:
> - Added new vsbi.c and vsbi.h files to implement virtual SBI extension
> handling.
> - Modified traps.c to handle CAUSE_VIRTUAL_SUPERVISOR_ECALL by calling
> vsbi_handle_ecall() when the trap originates from VS-mode.
> - Updated xen.lds.S to include a new .vsbi.exts section for virtual SBI
> extension data.
> - Updated Makefile to include the new vsbi/ directory in the build.
> - Add hstatus register to struct cpu_user_regs as it is needed for
> a check that CAUSE_VIRTUAL_SUPERVISOR_ECALL happens from VS-mode.
I can spot the check, yes, but without the field ever being set how is one
to determine whether that check actually makes sense?
> The implementation allows for registration and handling of SBI
> extensions via a new vsbi_ext structure and ".vsbi.exts" section,
> enabling extensible virtual SBI support for RISC-V guests.
>
> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
> ---
> xen/arch/riscv/Makefile | 1 +
> xen/arch/riscv/include/asm/processor.h | 1 +
> xen/arch/riscv/include/asm/vsbi.h | 31 +++++++++++++++++
> xen/arch/riscv/traps.c | 8 +++++
> xen/arch/riscv/vsbi/Makefile | 1 +
> xen/arch/riscv/vsbi/vsbi.c | 46 ++++++++++++++++++++++++++
A file named identical to the directory it lives in raises the question of
why there is such a new sub-directory. Are you expecting moree files to
appear there? How's vsbi.c then be "special" compared to the others? Do
you perhaps mean someling like "core.c" or "common.c" here?
> --- /dev/null
> +++ b/xen/arch/riscv/include/asm/vsbi.h
> @@ -0,0 +1,31 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#ifndef ASM_RISCV_VSBI_H
> +#define ASM_RISCV_VSBI_H
> +
> +struct regs;
DYM struct cpu_user_regs?
> +struct vcpu;
> +
> +struct vsbi_ext {
> + const char *name;
> + unsigned long eid_start;
> + unsigned long eid_end;
> + int (*handle)(struct vcpu *vcpu, unsigned long eid,
> + unsigned long fid, struct cpu_user_regs *regs);
Nit: Maybe better "handler", as this isn't really a handle?
> +};
> +
> +#define VSBI_EXT_START(ext, extid_start, extid_end, extid_handle) \
The extid_ prefixes aren't adding much value here, are they?
> +static const struct vsbi_ext vsbi_ext_##ext __used \
> +__section(".vsbi.exts") = { \
> + .name = #ext, \
> + .eid_start = extid_start, \
> + .eid_end = extid_end, \
> + .handle = extid_handle,
> +
> +#define VSBI_EXT_END \
> +};
There's no use here, and peeking ahead at the other two patches shows
no use where this odd split of the macros would be necessary. What is
this about?
> --- a/xen/arch/riscv/traps.c
> +++ b/xen/arch/riscv/traps.c
> @@ -15,6 +15,7 @@
> #include <asm/processor.h>
> #include <asm/riscv_encoding.h>
> #include <asm/traps.h>
> +#include <asm/vsbi.h>
>
> /*
> * Initialize the trap handling.
> @@ -114,6 +115,13 @@ void do_trap(struct cpu_user_regs *cpu_regs)
>
> switch ( cause )
> {
> + case CAUSE_VIRTUAL_SUPERVISOR_ECALL:
> + if ( !(cpu_regs->hstatus & HSTATUS_SPV) )
> + panic("CAUSE_VIRTUAL_SUPERVISOR_ECALL came not from VS-mode\n");
This might more naturally want to be BUG_ON()? Assuming of course the value
in question is exclusively under hypervisor control. Otherwise panic() would
also be wrong to use here.
> --- /dev/null
> +++ b/xen/arch/riscv/vsbi/vsbi.c
> @@ -0,0 +1,46 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#include <xen/sched.h>
> +
> +#include <asm/processor.h>
> +#include <asm/sbi.h>
> +#include <asm/vsbi.h>
> +
> +extern const struct vsbi_ext _svsbi_exts[], _evsbi_exts[];
> +
> +const struct vsbi_ext *vsbi_find_extension(unsigned long ext_id)
static?
Also, again - is the ext_ prefix adding any value here?
> +{
> + const struct vsbi_ext *vsbi_ext;
> +
> + for ( vsbi_ext = _svsbi_exts; vsbi_ext != _evsbi_exts; vsbi_ext++ )
> + if ( ext_id >= vsbi_ext->eid_start &&
> + ext_id <= vsbi_ext->eid_end )
> + return vsbi_ext;
What if multiple entries have overlapping EID ranges?
Also at the macro definition site please clarify (by way of a comment)
that these ramnges are inclusive (especially at the upper end).
> +void vsbi_handle_ecall(struct vcpu *vcpu, struct cpu_user_regs *regs)
> +{
> + const unsigned long eid = regs->a7;
> + const unsigned long fid = regs->a6;
> + const struct vsbi_ext *ext = vsbi_find_extension(eid);
> + int ret;
> +
> + if ( ext && ext->handle )
> + ret = ext->handle(vcpu, eid, fid, regs);
Is a registration record NULL handler pointer actually legitimate / useful?
(If there was range overlap checking I could see a reason to permit such.)
> + else
> + {
> + printk("Unsupported Guest SBI EID #%#lx, FID #%lu\n", eid, regs->a1);
Are the #-es ahead of the %-s adding value here? Is printing an ID as
decimal going to be useful, when the value is pretty much arbitrary?
> + ret = SBI_ERR_NOT_SUPPORTED;
> + }
> +
> + /*
> + * The ecall instruction is not part of the RISC-V C extension (compressed
> + * instructions), so it is always 4 bytes long. Therefore, it is safe to
> + * use a fixed length of 4 bytes instead of reading guest memory to
> + * determine the instruction length.
> + */
And ECALL is also the sole possible cause of CAUSE_VIRTUAL_SUPERVISOR_ECALL?
> --- a/xen/arch/riscv/xen.lds.S
> +++ b/xen/arch/riscv/xen.lds.S
> @@ -91,6 +91,13 @@ SECTIONS
>
> DT_DEV_INFO /* Devicetree based device info */
>
> + . = ALIGN(POINTER_ALIGN);
> + DECL_SECTION(.vsbi.exts) {
> + _svsbi_exts = .;
> + *(.vsbi.exts)
> + _evsbi_exts = .;
> + } :text
Isn't this read-only data? In which case it wants to move up ahead of _erodata?
Jan
next prev parent reply other threads:[~2025-12-08 14:25 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-01 10:24 [PATCH v1 0/3] RISC-V: Introduce vSBI framework Oleksii Kurochko
2025-12-01 10:24 ` [PATCH v1 1/3] xen/riscv: introduce vSBI extension framework Oleksii Kurochko
2025-12-08 14:25 ` Jan Beulich [this message]
2025-12-10 17:03 ` Oleksii Kurochko
2025-12-11 9:23 ` Jan Beulich
2025-12-11 12:00 ` Oleksii Kurochko
2025-12-01 10:24 ` [PATCH v1 2/3] xen/riscv: add RISC-V legacy SBI extension support for guests Oleksii Kurochko
2025-12-08 15:05 ` Jan Beulich
2025-12-11 10:29 ` Oleksii Kurochko
2025-12-11 11:02 ` Jan Beulich
2025-12-11 12:52 ` Oleksii Kurochko
2025-12-11 13:36 ` Jan Beulich
2025-12-01 10:24 ` [PATCH v1 3/3] xen/riscv: add RISC-V virtual SBI base " Oleksii Kurochko
2025-12-08 15:15 ` Jan Beulich
2025-12-12 15:25 ` Oleksii Kurochko
2025-12-12 16:31 ` Oleksii Kurochko
2025-12-15 8:20 ` Jan Beulich
2025-12-15 10:39 ` Oleksii Kurochko
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=df316e2f-9eb0-4bb8-96cd-e5e0c42d123e@suse.com \
--to=jbeulich@suse.com \
--cc=alistair.francis@wdc.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=bobbyeshleman@gmail.com \
--cc=connojdavis@gmail.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=oleksii.kurochko@gmail.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.