* [PATCH] xen/riscv: vsbi: add SBI TIME extension @ 2026-11-19 11:59 Hiago De Franco 2026-11-19 13:52 ` Oleksii Kurochko 2026-11-19 16:32 ` Baptiste Le Duc 0 siblings, 2 replies; 6+ messages in thread From: Hiago De Franco @ 2026-11-19 11:59 UTC (permalink / raw) To: xen-devel Cc: Alistair Francis, Baptiste Le Duc, Connor Davis, Oleksii Kurochko, Ronaldo Nunez, Andrew Cooper, Anthony PERARD, Michal Orzel, Jan Beulich, Julien Grall, Roger Pau Monné, Stefano Stabellini Xen reports SBI v0.2 but does not implement the TIME extension, so the guest probe fails and Linux falls back to the legacy SBI v0.1 SET_TIMER call. The fallback is deprecated and only available when the guest is built with CONFIG_RISCV_SBI_V01, so a guest built without it never arms the timer. Implement the TIME extension and handle SET_TIMER() by programming the vCPU virtual timer through vtimer_set_timer(). With the extension registered, SBI_EXT_BASE_PROBE_EXT reports TIME as available and Linux selects the v0.2 path. Assisted-by: DeepSeek:v4.1-flash Signed-off-by: Hiago De Franco <hfranco@baylibre.com> --- Hello, This is a prerequisite for removing the legacy v0.1 from the guest configuration. Tested by booting dom0less Linux guest, which prints "SBI TIME extension detected". To test this, I used the fork from Oleksii [1] (branch riscv-next-upstreaming) to boot linux guest with dom0less. Since this is an isolated patch and applies to the xen master branch, I decided to send the patch. Please let me know if this is not correct. [1] https://gitlab.com/xen-project/people/olkur/xen --- xen/arch/riscv/vsbi/Makefile | 1 + xen/arch/riscv/vsbi/time-extension.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/xen/arch/riscv/vsbi/Makefile b/xen/arch/riscv/vsbi/Makefile index 8ce470f787c5b04f985dfb76d076025b49ddef19..31ff8e86d1a20500b9321c826c1e48c0f84cde84 100644 --- a/xen/arch/riscv/vsbi/Makefile +++ b/xen/arch/riscv/vsbi/Makefile @@ -1,3 +1,4 @@ obj-y += base-extension.o obj-y += core.o obj-y += legacy-extension.o +obj-y += time-extension.o diff --git a/xen/arch/riscv/vsbi/time-extension.c b/xen/arch/riscv/vsbi/time-extension.c new file mode 100644 index 0000000000000000000000000000000000000000..6bf23f5708d45d2f671bb15f423f209fb250525a --- /dev/null +++ b/xen/arch/riscv/vsbi/time-extension.c @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/lib.h> +#include <xen/sched.h> + +#include <asm/current.h> +#include <asm/processor.h> +#include <asm/sbi.h> +#include <asm/vsbi.h> +#include <asm/vtimer.h> + +static int vsbi_time_ecall_handler(unsigned long eid, unsigned long fid, + struct cpu_user_regs *regs) +{ + ASSERT(eid == SBI_EXT_TIME); + + if ( fid != SBI_EXT_TIME_SET_TIMER ) + return SBI_ERR_NOT_SUPPORTED; + + vtimer_set_timer(¤t->arch.vtimer, regs->a0); + + return SBI_SUCCESS; +} + +VSBI_EXT(time, SBI_EXT_TIME, SBI_EXT_TIME, vsbi_time_ecall_handler); --- base-commit: ab77da87e9b38022341eb6a54593e681485d203a change-id: 20261117-riscv-vsbi-time-ext-20ad33685b05 Best regards, -- Hiago ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] xen/riscv: vsbi: add SBI TIME extension 2026-11-19 11:59 [PATCH] xen/riscv: vsbi: add SBI TIME extension Hiago De Franco @ 2026-11-19 13:52 ` Oleksii Kurochko [not found] ` <bkmmgcqrbq47i7gxn3nt64xrypt2l2hrhlbip7rv7cfo7p6dqs@lssohgkujou5> 2026-11-19 16:32 ` Baptiste Le Duc 1 sibling, 1 reply; 6+ messages in thread From: Oleksii Kurochko @ 2026-11-19 13:52 UTC (permalink / raw) To: Hiago De Franco, xen-devel Cc: Alistair Francis, Baptiste Le Duc, Connor Davis, Ronaldo Nunez, Andrew Cooper, Anthony PERARD, Michal Orzel, Jan Beulich, Julien Grall, Roger Pau Monné, Stefano Stabellini On 11/19/26 12:59 PM, Hiago De Franco wrote: > Xen reports SBI v0.2 but does not implement the TIME extension, so the > guest probe fails and Linux falls back to the legacy SBI v0.1 SET_TIMER > call. Nit: the probe itself doesn't fail, it reports the extension as unavailable. Maybe something like: "Xen reports SBI v0.2 but does not implement the TIME extension, so SBI_EXT_BASE_PROBE_EXT reports TIME as unavailable and Linux falls back to the legacy SBI v0.1 SET_TIMER call." > > The fallback is deprecated and only available when the guest is built > with CONFIG_RISCV_SBI_V01, so a guest built without it never arms the > timer. > > Implement the TIME extension and handle SET_TIMER() by programming the > vCPU virtual timer through vtimer_set_timer(). With the extension > registered, SBI_EXT_BASE_PROBE_EXT reports TIME as available and Linux > selects the v0.2 path. > > Assisted-by: DeepSeek:v4.1-flash > Signed-off-by: Hiago De Franco <hfranco@baylibre.com> > --- > Hello, > > This is a prerequisite for removing the legacy v0.1 from the guest > configuration. I don't think removing legacy v0.1 is the best idea, as there could still be guests that only support v0.1 or, for some reason, prefer to use it. Therefore, both functionalities should remain available and be configurable in one way or another. > > Tested by booting dom0less Linux guest, which prints "SBI TIME > extension detected". To test this, I used the fork from Oleksii [1] > (branch riscv-next-upstreaming) to boot linux guest with dom0less. > > Since this is an isolated patch and applies to the xen master branch, I Please note, though, that development happens on the staging branch; master lags behind it, so patches should be based on staging. This one applies to staging as is. > decided to send the patch. Please let me know if this is not correct. Generally speaking, I can't say whether this is right or wrong. IMO, we should have a policy that we all agree on. If I'm not mistaken, Bruno invited you to our weekly Xen RISC-V meetings, and we have one today. It would be great if you could join us so we could discuss these things. At this point, the patch does look independent and ready to go. However, another option would be to take the patch to the riscv-next-upstreaming branch, apply it there, and verify that it works. That said, this might not be the best general approach. The patch is currently targeting upstream/staging, which cannot boot any guests. Strictly speaking, it is therefore difficult to verify how the patch works without fetching [1], switching to the mentioned branch, and applying the patch there. In this sense, the fact that staging cannot currently boot a guest creates a kind of "logical dependency". So, technically, we could proceed with this patch as it is. However, if you could join today's meeting, it would be good to discuss how we should handle similar situations with future patches and agree on a general upstreaming policy. > > [1] https://gitlab.com/xen-project/people/olkur/xen > --- > xen/arch/riscv/vsbi/Makefile | 1 + > xen/arch/riscv/vsbi/time-extension.c | 25 +++++++++++++++++++++++++ > 2 files changed, 26 insertions(+) > > diff --git a/xen/arch/riscv/vsbi/Makefile b/xen/arch/riscv/vsbi/Makefile > index 8ce470f787c5b04f985dfb76d076025b49ddef19..31ff8e86d1a20500b9321c826c1e48c0f84cde84 100644 > --- a/xen/arch/riscv/vsbi/Makefile > +++ b/xen/arch/riscv/vsbi/Makefile > @@ -1,3 +1,4 @@ > obj-y += base-extension.o > obj-y += core.o > obj-y += legacy-extension.o > +obj-y += time-extension.o > diff --git a/xen/arch/riscv/vsbi/time-extension.c b/xen/arch/riscv/vsbi/time-extension.c > new file mode 100644 > index 0000000000000000000000000000000000000000..6bf23f5708d45d2f671bb15f423f209fb250525a > --- /dev/null > +++ b/xen/arch/riscv/vsbi/time-extension.c > @@ -0,0 +1,25 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <xen/lib.h> > +#include <xen/sched.h> > + > +#include <asm/current.h> > +#include <asm/processor.h> > +#include <asm/sbi.h> > +#include <asm/vsbi.h> > +#include <asm/vtimer.h> > + > +static int vsbi_time_ecall_handler(unsigned long eid, unsigned long fid, > + struct cpu_user_regs *regs) > +{ > + ASSERT(eid == SBI_EXT_TIME); > + > + if ( fid != SBI_EXT_TIME_SET_TIMER ) > + return SBI_ERR_NOT_SUPPORTED; > + > + vtimer_set_timer(¤t->arch.vtimer, regs->a0); > + > + return SBI_SUCCESS; > +} > + > +VSBI_EXT(time, SBI_EXT_TIME, SBI_EXT_TIME, vsbi_time_ecall_handler); Nit: VSBI_EXT() already expands to a definition ending in "};", so the trailing ';' produces an empty declaration at file scope. base-extension.c doesn't have it; I'd drop it here too. With Nits fixed: Reviewed-by: Oleksii Kurochko <oleksii.kurochko@gmail.com> Thanks. ~ Oleksii ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <bkmmgcqrbq47i7gxn3nt64xrypt2l2hrhlbip7rv7cfo7p6dqs@lssohgkujou5>]
* Re: [PATCH] xen/riscv: vsbi: add SBI TIME extension [not found] ` <bkmmgcqrbq47i7gxn3nt64xrypt2l2hrhlbip7rv7cfo7p6dqs@lssohgkujou5> @ 2026-11-20 8:42 ` Oleksii Kurochko 0 siblings, 0 replies; 6+ messages in thread From: Oleksii Kurochko @ 2026-11-20 8:42 UTC (permalink / raw) To: Hiago De Franco, xen-devel Cc: Alistair Francis, Baptiste Le Duc, Connor Davis, Ronaldo Nunez, Andrew Cooper, Anthony PERARD, Michal Orzel, Jan Beulich, Julien Grall, Roger Pau Monné, Stefano Stabellini On 11/19/26 10:34 PM, Hiago De Franco wrote: > On Thu, Nov 19, 2026 at 02:52:46PM +0100, Oleksii Kurochko wrote: >> >> >> On 11/19/26 12:59 PM, Hiago De Franco wrote: [...] >> >>> >>> Tested by booting dom0less Linux guest, which prints "SBI TIME >>> extension detected". To test this, I used the fork from Oleksii [1] >>> (branch riscv-next-upstreaming) to boot linux guest with dom0less. >>> >>> Since this is an isolated patch and applies to the xen master branch, I >> >> Please note, though, that development happens on the staging branch; master >> lags behind it, so patches should be based on staging. This one applies to >> staging as is. > > Noted, I was basing it on master. I will fix that. > >> >>> decided to send the patch. Please let me know if this is not correct. >> >> Generally speaking, I can't say whether this is right or wrong. IMO, we >> should have a policy that we all agree on. If I'm not mistaken, Bruno >> invited you to our weekly Xen RISC-V meetings, and we have one today. It >> would be great if you could join us so we could discuss these things. >> >> At this point, the patch does look independent and ready to go. However, >> another option would be to take the patch to the riscv-next-upstreaming >> branch, apply it there, and verify that it works. That said, this might not >> be the best general approach. >> >> The patch is currently targeting upstream/staging, which cannot boot any >> guests. Strictly speaking, it is therefore difficult to verify how the patch >> works without fetching [1], switching to the mentioned branch, and applying >> the patch there. In this sense, the fact that staging cannot currently boot >> a guest creates a kind of "logical dependency". >> >> So, technically, we could proceed with this patch as it is. However, if you >> could join today's meeting, it would be good to discuss how we should handle >> similar situations with future patches and agree on a general upstreaming >> policy. > > Got it, since we had the call today I will prefer to proceed as the > following: > > I will open a MR on https://gitlab.com/xen-project/people/olkur/xen > staging branch, we do the testing and reviews there and once we have > more work done upstream, I will resbumit or submit a v2. That way we add > code upstream that is really capable of being tested. Just a small remark. We don't push changes directly to staging, as it is a protected branch. Of course, force-pushing is technically possible, but that would put us out of sync with upstream Xen's staging branch, meaning we'd probably have to force-push all the time, which could lead to other issues as well. What isn't good. Usually, changes are brought to downstream staging only after they have been merged into upstream staging. So, basically, we just need to run git pull upstream staging. Therefore, if you want to proceed with an MR, it would be better to target riscv-next-upstream. Feel free to suggest a better approach if you have one in mind. I'm pretty open to suggestions. Thanks. ~ Oleksii ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] xen/riscv: vsbi: add SBI TIME extension 2026-11-19 11:59 [PATCH] xen/riscv: vsbi: add SBI TIME extension Hiago De Franco 2026-11-19 13:52 ` Oleksii Kurochko @ 2026-11-19 16:32 ` Baptiste Le Duc 2026-11-19 21:38 ` Hiago De Franco 2026-11-20 8:31 ` Oleksii Kurochko 1 sibling, 2 replies; 6+ messages in thread From: Baptiste Le Duc @ 2026-11-19 16:32 UTC (permalink / raw) To: Hiago De Franco Cc: xen-devel, Alistair Francis, Baptiste Le Duc, Connor Davis, Oleksii Kurochko, Ronaldo Nunez, Andrew Cooper, Anthony PERARD, Michal Orzel, Jan Beulich, Julien Grall, Roger Pau Monné, Stefano Stabellini The commit's name is kind of weird with this two `:` next to each other. Here is suggestion based on previous patches (xen/riscv: implement SBI legacy SET_TIMER support for guests (647542cdf1)...) ``` xen/riscv: implement SBI TIME extension for guests ``` > [ ... 8 lines skipped ... ] > Implement the TIME extension and handle SET_TIMER() by programming the > vCPU virtual timer through vtimer_set_timer(). With the extension > registered, SBI_EXT_BASE_PROBE_EXT reports TIME as available and Linux > selects the v0.2 path. > > Assisted-by: DeepSeek:v4.1-flash Uncommon to see DeepSeek model used :) > [ ... 46 lines skipped ... ] > +static int vsbi_time_ecall_handler(unsigned long eid, unsigned long fid, > + struct cpu_user_regs *regs) > +{ > + ASSERT(eid == SBI_EXT_TIME); > + > + if ( fid != SBI_EXT_TIME_SET_TIMER ) > + return SBI_ERR_NOT_SUPPORTED; > + > + vtimer_set_timer(¤t->arch.vtimer, regs->a0); > Nit: this assumes VSXLEN == 64, i.e. that stime_value fits in a0. The SBI spec (binary-encoding.adoc) says: Parameters that are 2×XLEN bits wide are passed in a pair of argument registers, with the low-order XLEN bits in the lower-numbered register and the high-order XLEN bits in the higher-numbered register. and sbi_set_timer() takes a uint64_t stime_value, so an RV32 guest passes it in a0 (low) and a1 (high). That's fine today, as both Xen and its guests are RV64 only, and the legacy SET_TIMER path makes the same assumption. But nothing in the tree enforces it for guests, so it might be worth stating it somewhere. Oleksii, any opinion on that point? > + > + return SBI_SUCCESS; > +} > + > +VSBI_EXT(time, SBI_EXT_TIME, SBI_EXT_TIME, vsbi_time_ecall_handler); With Nits fixed, it lgtm. Thanks for your contribution! Reviewed-by: Baptiste Le Duc <baptiste.le-duc@vates.tech> -- Baptiste Le Duc <baptiste.le-duc@vates.tech> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] xen/riscv: vsbi: add SBI TIME extension 2026-11-19 16:32 ` Baptiste Le Duc @ 2026-11-19 21:38 ` Hiago De Franco 2026-11-20 8:31 ` Oleksii Kurochko 1 sibling, 0 replies; 6+ messages in thread From: Hiago De Franco @ 2026-11-19 21:38 UTC (permalink / raw) To: Baptiste Le Duc, xen-devel; +Cc: Oleksii Kurochko, Ronaldo Nunez, Andrew Cooper On Thu, Nov 19, 2026 at 05:32:48PM +0100, Baptiste Le Duc wrote: > The commit's name is kind of weird with this two `:` next to each other. > Here is suggestion based on previous patches (xen/riscv: implement SBI legacy SET_TIMER support for guests (647542cdf1)...) > ``` > xen/riscv: implement SBI TIME extension for guests > ``` > Noted, I will fix that. > > [ ... 8 lines skipped ... ] > > Implement the TIME extension and handle SET_TIMER() by programming the > > vCPU virtual timer through vtimer_set_timer(). With the extension > > registered, SBI_EXT_BASE_PROBE_EXT reports TIME as available and Linux > > selects the v0.2 path. > > > > Assisted-by: DeepSeek:v4.1-flash > Uncommon to see DeepSeek model used :) I was using Claude before, but now I switched and have been testing it for a couple of weeks :) Let's see how it goes... > > [ ... 46 lines skipped ... ] > > +static int vsbi_time_ecall_handler(unsigned long eid, unsigned long fid, > > + struct cpu_user_regs *regs) > > +{ > > + ASSERT(eid == SBI_EXT_TIME); > > + > > + if ( fid != SBI_EXT_TIME_SET_TIMER ) > > + return SBI_ERR_NOT_SUPPORTED; > > + > > + vtimer_set_timer(¤t->arch.vtimer, regs->a0); > > > Nit: this assumes VSXLEN == 64, i.e. that stime_value fits in a0. The > SBI spec (binary-encoding.adoc) says: > > Parameters that are 2×XLEN bits wide are passed in a pair of > argument registers, with the low-order XLEN bits in the > lower-numbered register and the high-order XLEN bits in the > higher-numbered register. > > and sbi_set_timer() takes a uint64_t stime_value, so an RV32 guest > passes it in a0 (low) and a1 (high). > > That's fine today, as both Xen and its guests are RV64 only, and the > legacy SET_TIMER path makes the same assumption. But nothing in the > tree enforces it for guests, so it might be worth stating it somewhere. Got it, thanks, I will think about a fix for that. > > Oleksii, any opinion on that point? > > > > + > > + return SBI_SUCCESS; > > +} > > + > > +VSBI_EXT(time, SBI_EXT_TIME, SBI_EXT_TIME, vsbi_time_ecall_handler); > With Nits fixed, it lgtm. > Thanks for your contribution! > > Reviewed-by: Baptiste Le Duc <baptiste.le-duc@vates.tech> Thanks, as I mentioned on the other email, I will add those to the MR. > > -- > Baptiste Le Duc <baptiste.le-duc@vates.tech> Best regards, -- Hiago ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] xen/riscv: vsbi: add SBI TIME extension 2026-11-19 16:32 ` Baptiste Le Duc 2026-11-19 21:38 ` Hiago De Franco @ 2026-11-20 8:31 ` Oleksii Kurochko 1 sibling, 0 replies; 6+ messages in thread From: Oleksii Kurochko @ 2026-11-20 8:31 UTC (permalink / raw) To: Baptiste Le Duc, Hiago De Franco Cc: xen-devel, Alistair Francis, Connor Davis, Ronaldo Nunez, Andrew Cooper, Anthony PERARD, Michal Orzel, Jan Beulich, Julien Grall, Roger Pau Monné, Stefano Stabellini On 11/19/26 5:32 PM, Baptiste Le Duc wrote: > The commit's name is kind of weird with this two `:` next to each other. > Here is suggestion based on previous patches (xen/riscv: implement SBI legacy SET_TIMER support for guests (647542cdf1)...) > ``` > xen/riscv: implement SBI TIME extension for guests > ``` > >> [ ... 8 lines skipped ... ] >> Implement the TIME extension and handle SET_TIMER() by programming the >> vCPU virtual timer through vtimer_set_timer(). With the extension >> registered, SBI_EXT_BASE_PROBE_EXT reports TIME as available and Linux >> selects the v0.2 path. >> >> Assisted-by: DeepSeek:v4.1-flash > Uncommon to see DeepSeek model used :) >> [ ... 46 lines skipped ... ] >> +static int vsbi_time_ecall_handler(unsigned long eid, unsigned long fid, >> + struct cpu_user_regs *regs) >> +{ >> + ASSERT(eid == SBI_EXT_TIME); >> + >> + if ( fid != SBI_EXT_TIME_SET_TIMER ) >> + return SBI_ERR_NOT_SUPPORTED; >> + >> + vtimer_set_timer(¤t->arch.vtimer, regs->a0); >> > Nit: this assumes VSXLEN == 64, i.e. that stime_value fits in a0. The > SBI spec (binary-encoding.adoc) says: > > Parameters that are 2×XLEN bits wide are passed in a pair of > argument registers, with the low-order XLEN bits in the > lower-numbered register and the high-order XLEN bits in the > higher-numbered register. > > and sbi_set_timer() takes a uint64_t stime_value, so an RV32 guest > passes it in a0 (low) and a1 (high). > > That's fine today, as both Xen and its guests are RV64 only, and the > legacy SET_TIMER path makes the same assumption. But nothing in the > tree enforces it for guests, so it might be worth stating it somewhere. > > Oleksii, any opinion on that point? I thought about that too, but decided not to mention it since, as you noted, only RV64 guests are possible at the moment. Another reason is that it isn't specific to this handler: every vSBI handler takes guest arguments as full-width registers, so other SBI extensions have the same issue. To me, this should be addressed together with RV32 guest support. If we want the assumption stated explicitly until then, I think it should be done once, in a separate patch, e.g. with a comment in asm/vsbi.h or an ASSERT(is_64bit_domain(current->domain)) in vsbi_handle_ecall(), rather than per extension. ~ Oleksii ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-20 8:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 11:59 [PATCH] xen/riscv: vsbi: add SBI TIME extension Hiago De Franco
2026-11-19 13:52 ` Oleksii Kurochko
[not found] ` <bkmmgcqrbq47i7gxn3nt64xrypt2l2hrhlbip7rv7cfo7p6dqs@lssohgkujou5>
2026-11-20 8:42 ` Oleksii Kurochko
2026-11-19 16:32 ` Baptiste Le Duc
2026-11-19 21:38 ` Hiago De Franco
2026-11-20 8:31 ` Oleksii Kurochko
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.