[PATCH v1 10/15] xen/riscv: implement SBI legacy SET_TIMER support for guests

Oleksii Kurochko posted 15 patches 1 month, 2 weeks ago
[PATCH v1 10/15] xen/riscv: implement SBI legacy SET_TIMER support for guests
Posted by Oleksii Kurochko 1 month, 2 weeks ago
Add handling of the SBI_EXT_0_1_SET_TIMER function ID to the legacy
extension ecall handler. The handler now programs the vCPU’s virtual
timer via vtimer_set_timer() and returns SBI_SUCCESS.

This enables guests using the legacy SBI timer interface to schedule
timer events correctly.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
---
 xen/arch/riscv/vsbi/legacy-extension.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/xen/arch/riscv/vsbi/legacy-extension.c b/xen/arch/riscv/vsbi/legacy-extension.c
index ca869942d693..7eb3a1f119d8 100644
--- a/xen/arch/riscv/vsbi/legacy-extension.c
+++ b/xen/arch/riscv/vsbi/legacy-extension.c
@@ -7,6 +7,7 @@
 
 #include <asm/processor.h>
 #include <asm/vsbi.h>
+#include <asm/vtimer.h>
 
 static void vsbi_print_char(char c)
 {
@@ -44,6 +45,11 @@ static int vsbi_legacy_ecall_handler(unsigned long eid, unsigned long fid,
         ret = SBI_ERR_NOT_SUPPORTED;
         break;
 
+    case SBI_EXT_0_1_SET_TIMER:
+        vtimer_set_timer(&current->arch.vtimer, regs->a0);
+        regs->a0 = SBI_SUCCESS;
+        break;
+
     default:
         /*
          * TODO: domain_crash() is acceptable here while things are still under
-- 
2.52.0


Re: [PATCH v1 10/15] xen/riscv: implement SBI legacy SET_TIMER support for guests
Posted by Jan Beulich 1 month ago
On 24.12.2025 18:03, Oleksii Kurochko wrote:
> Add handling of the SBI_EXT_0_1_SET_TIMER function ID to the legacy
> extension ecall handler. The handler now programs the vCPU’s virtual
> timer via vtimer_set_timer() and returns SBI_SUCCESS.
> 
> This enables guests using the legacy SBI timer interface to schedule
> timer events correctly.
> 
> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>

Acked-by: Jan Beulich <jbeulich@suse.com>

What about the more modern timer extension, though?

Jan

Re: [PATCH v1 10/15] xen/riscv: implement SBI legacy SET_TIMER support for guests
Posted by Oleksii Kurochko 3 weeks, 5 days ago
On 1/8/26 11:45 AM, Jan Beulich wrote:
> On 24.12.2025 18:03, Oleksii Kurochko wrote:
>> Add handling of the SBI_EXT_0_1_SET_TIMER function ID to the legacy
>> extension ecall handler. The handler now programs the vCPU’s virtual
>> timer via vtimer_set_timer() and returns SBI_SUCCESS.
>>
>> This enables guests using the legacy SBI timer interface to schedule
>> timer events correctly.
>>
>> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
> Acked-by: Jan Beulich <jbeulich@suse.com>

Thanks.

>
> What about the more modern timer extension, though?

Handling will be the same, as the API is identical:
   struct sbiret sbi_set_timer(uint64_t stime_value)

The only additional work needed is to add handling for the new extension
with EID|0x54494D45| (“TIME”), which was introduced in SBI v0.2.

Interestingly, we currently report to the guest that OpenSBI v0.2 is
available, so technically this modern timer extension should be usable.
However, the guest still tries to use the Legacy extension, as it has not
yet received an indication in Xen that the EID|0x54494D45| (“TIME”) isn't
implemented.

~ Oleksii