RISC-V: Introduce vSBI framework
PATCH v4 1/1 xen/riscv: add RISC-V virtual SBI base extension support for guests
In reply to Oleksii KurochkoAdd support of virtual SBI base extension calls for RISC-V guests, delegating hardware-specific queries to the underlying SBI and handling version and firmware ID queries directly.
The changes include:
1. Define new SBI base extension function IDs (SBI_EXT_BASE_GET_MVENDORID, SBI_EXT_BASE_GET_MARCHID, SBI_EXT_BASE_GET_MIMPID).
2. Introduce XEN_SBI_VER_MAJOR, XEN_SBI_VER_MINOR for imeplenataion of SBI_EXT_BASE_GET_SPEC_VERSION.
4. Introduce SBI_XEN_IMPID to implement SBI_EXT_BASE_GET_IMP_ID.
5. Implement handling of SBI base extension functions, including version, firmware ID, and machine-specific queries.
---
Changes in v4:
- Move definition of XEN_SBI_VER_{MAJOR, MINOR} to base-extension.c.
- Correct string format for FID: s/#%#lx/#%lu.
- Print first EID then FID (as vsbi/core.c code does).
---
Changes in v3:
- s/XEN_SBI_IMPID/SBI_XEN_IMPID
- Add ASSERT(eid == SBI_EXT_BASE) in vsbi_base_ecall_handler().
- Fix code style for switch/case.
- Use current instead of vcpu argument as it was dropped from vsbi_base_ecall_handler() prototype.
- Add comments for define-s XEN_SBI_VER_{MAJOR, MINOR} and SBI_XEN_IMPID.
---
Changes in v2:
- s/vsbi-base-extension.*/base-extension.*
- Introduce VCPU_SBI_IMPID, XEN_SBI_VER_MINOR and XEN_SBI_VER_MAJOR.
- Return VCPU_SBI_IMPID in the case of SBI_EXT_BASE_GET_IMP_ID.
- Return Xen version in the case of SBI_EXT_BASE_GET_IMP_VERSION.
- Use domain_crash() instead of panic() for default case.
- For SBI_EXT_BASE_GET_{MVENDORID,MARCHID,MIMPID} abd SBI_EXT_BASE_PROBE_EXT add handling of a domain is h/w or not.
--- xen/arch/riscv/include/asm/sbi.h | 6 ++ xen/arch/riscv/vsbi/Makefile | 1 + xen/arch/riscv/vsbi/base-extension.c | 82 ++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 xen/arch/riscv/vsbi/base-extension.c
xen/arch/riscv/include/asm/sbi.h +6 -0
@@ -14,6 +14,9 @@#include <xen/cpumask.h> +/* SBI-defined implementation ID */ +#define SBI_XEN_IMPID 7 +#define SBI_EXT_0_1_SET_TIMER 0x0#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1#define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2
@@ -32,6 +35,9 @@#define SBI_EXT_BASE_GET_IMP_ID 0x1#define SBI_EXT_BASE_GET_IMP_VERSION 0x2#define SBI_EXT_BASE_PROBE_EXT 0x3 +#define SBI_EXT_BASE_GET_MVENDORID 0x4 +#define SBI_EXT_BASE_GET_MARCHID 0x5 +#define SBI_EXT_BASE_GET_MIMPID 0x6/* SBI function IDs for RFENCE extension */ #define SBI_EXT_RFENCE_REMOTE_FENCE_I 0x0
xen/arch/riscv/vsbi/Makefile +1 -0
@@ -1,2 +1,3 @@ +obj-y += base-extension.o obj-y += core.o obj-y += legacy-extension.o
xen/arch/riscv/vsbi/base-extension.c new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.52.0
v4 cover RISC-V: Introduce vSBI framework
Introduce the vSBI framework to handle extension ecall instruction calls from a guest.
In this patch series, support is added for only a few extensions and FIDs, just enough to boot the first guest domains and obtain logs from them. This keeps the patch series independent from other ongoing work.
It was decided to start with support for the Legacy Extension, as it is still supported by Linux (so we may need it anyway), and because some of its FIDs require less functionality to implement at this stage compared to the more modern extensions.
CI tests: https://gitlab.com/xen-project/people/olkur/xen/-/pipelines/2238071752
---
Changes in v4:
- First to patches were merged to staging.
- Address comments for the last patch.
---
Changes in v3:
- Address a comments from v2.
---
Changes in v2:
- Address a comments from v1.
---
Oleksii Kurochko (1):
xen/riscv: add RISC-V virtual SBI base extension support for guests
xen/arch/riscv/include/asm/sbi.h | 6 ++ xen/arch/riscv/vsbi/Makefile | 1 + xen/arch/riscv/vsbi/base-extension.c | 82 ++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 xen/arch/riscv/vsbi/base-extension.c
Signature · 1 line
2.52.0
Re: [PATCH v4 1/1] xen/riscv: add RISC-V virtual SBI base extension support for guests
In reply to Oleksii KurochkoHello,
Le 30/12/2025 à 16:52, Oleksii Kurochko a écrit :
Quoted 146 lines
Add support of virtual SBI base extension calls for RISC-V guests, delegating hardware-specific queries to the underlying SBI and handling version and firmware ID queries directly.
The changes include:
1. Define new SBI base extension function IDs (SBI_EXT_BASE_GET_MVENDORID,SBI_EXT_BASE_GET_MARCHID,SBI_EXT_BASE_GET_MIMPID).
2. IntroduceXEN_SBI_VER_MAJOR,XEN_SBI_VER_MINORfor imeplenataion ofSBI_EXT_BASE_GET_SPEC_VERSION.
4. IntroduceSBI_XEN_IMPIDto implementSBI_EXT_BASE_GET_IMP_ID.
5. Implement handling of SBI base extension functions, including version, firmware ID, and machine-specific queries.Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in v4:
- Move definition of XEN_SBI_VER_{MAJOR, MINOR} tobase-extension.c.
- Correct string format for FID: s/#%#lx/#%lu.
- Print first EID then FID (asvsbi/core.ccode does).
---
Changes in v3:
- s/XEN_SBI_IMPID/SBI_XEN_IMPID
- AddASSERT(eid == SBI_EXT_BASE)invsbi_base_ecall_handler().
- Fix code style for switch/case.
- Use current instead ofvcpuargument as it was dropped fromvsbi_base_ecall_handler()prototype.
- Add comments for define-s XEN_SBI_VER_{MAJOR, MINOR} andSBI_XEN_IMPID.
---
Changes in v2:
- s/vsbi-base-extension.*/base-extension.*
- IntroduceVCPU_SBI_IMPID,XEN_SBI_VER_MINORandXEN_SBI_VER_MAJOR.
- ReturnVCPU_SBI_IMPIDin the case ofSBI_EXT_BASE_GET_IMP_ID.
- Return Xen version in the case ofSBI_EXT_BASE_GET_IMP_VERSION.
- Usedomain_crash()instead ofpanic()for default case.
- For SBI_EXT_BASE_GET_{MVENDORID,MARCHID,MIMPID} abdSBI_EXT_BASE_PROBE_EXTadd handling of a domain is h/w or not.--- xen/arch/riscv/include/asm/sbi.h | 6 ++ xen/arch/riscv/vsbi/Makefile | 1 + xen/arch/riscv/vsbi/base-extension.c | 82 ++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+)create mode 100644
xen/arch/riscv/vsbi/base-extension.cxen/arch/riscv/include/asm/sbi.h +6
-0@@ -14,6 +14,9 @@#include <xen/cpumask.h> +/* SBI-defined implementation ID */ +#define SBI_XEN_IMPID 7 +#define SBI_EXT_0_1_SET_TIMER 0x0#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1#define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2@@ -32,6 +35,9 @@#define SBI_EXT_BASE_GET_IMP_ID 0x1#define SBI_EXT_BASE_GET_IMP_VERSION 0x2#define SBI_EXT_BASE_PROBE_EXT 0x3 +#define SBI_EXT_BASE_GET_MVENDORID 0x4 +#define SBI_EXT_BASE_GET_MARCHID 0x5 +#define SBI_EXT_BASE_GET_MIMPID 0x6/* SBI function IDs for RFENCE extension */ #define SBI_EXT_RFENCE_REMOTE_FENCE_I 0x0xen/arch/riscv/vsbi/Makefile +1
-0@@ -1,2 +1,3 @@ +obj-y += base-extension.o obj-y += core.o obj-y += legacy-extension.oxen/arch/riscv/vsbi/base-extension.c new file +65
-0@@ -0,0 +1,82 @@ + +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/lib.h> +#include <xen/sched.h> +#include <xen/version.h> + +#include <asm/processor.h> +#include <asm/sbi.h> +#include <asm/vsbi.h> + +/* Xen-controlled SBI version reported to guests */ +#define XEN_SBI_VER_MAJOR 0 +#define XEN_SBI_VER_MINOR 2 + +static int vsbi_base_ecall_handler (unsigned long eid,unsigned long fid, +struct cpu_user_regs *regs) +{ +int ret =0 ; +struct sbiret sbi_ret; + +ASSERT (eid ==SBI_EXT_BASE ); + +switch ( fid ) + { +case SBI_EXT_BASE_GET_SPEC_VERSION : + regs->a1 =MASK_INSR (XEN_SBI_VER_MAJOR ,SBI_SPEC_VERSION_MAJOR_MASK ) | +XEN_SBI_VER_MINOR ; +break ; + +case SBI_EXT_BASE_GET_IMP_ID : + regs->a1 =SBI_XEN_IMPID ; +break ; + +case SBI_EXT_BASE_GET_IMP_VERSION : + regs->a1 = (xen_major_version () <<16 ) |xen_minor_version (); +break ; + +case SBI_EXT_BASE_GET_MVENDORID : +case SBI_EXT_BASE_GET_MARCHID : +case SBI_EXT_BASE_GET_MIMPID : +if (is_hardware_domain (current->domain) ) + { + sbi_ret =sbi_ecall (SBI_EXT_BASE , fid,0 ,0 ,0 ,0 ,0 ,0 ); + ret = sbi_ret.error; + regs->a1 = sbi_ret.value; + } +else +/* +* vSBI should present a consistent, virtualized view to guests. +* In particular, DomU-visible data must remain stable across +* migration and must not expose hardware-specific details. +* +* These register(s) must be readable in any implementation, +* but a value of 0 can be returned to indicate the field +* is not implemented. +*/ + regs->a1 =0 ; + +break ; + +case SBI_EXT_BASE_PROBE_EXT : + regs->a1 =vsbi_find_extension (regs->a0) ?1 :0 ; +break ; +
xen/arch/riscv/vsbi/base-extension.c line 75
Quoted 10 lines
xen/arch/riscv/vsbi/base-extension.c new file +10
-0+default : +/* +* TODO: domain_crash() is acceptable here while things are still under +* development. +* It shouldn't stay like this in the end though: guests should not +* be punished like this for something Xen hasn't implemented. +*/ +domain_crash (current->domain, +"%s: Unsupported ecall: EID: #%#lx FID: #%lu\n" , + __func__, eid, fid);
I think we should rather report "SBI_ERR_NOT_SUPPORTED" (-2) instead (eventually logging a warning in Xen) ?
xen/arch/riscv/vsbi/base-extension.c line 82
Quoted 7 lines
xen/arch/riscv/vsbi/base-extension.c new file +7
-0+break ; + } + +return ret; +} + +VSBI_EXT (base,SBI_EXT_BASE ,SBI_EXT_BASE , vsbi_base_ecall_handler)
Teddy
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH v4 1/1] xen/riscv: add RISC-V virtual SBI base extension support for guests
Hello Teddy,
Quoted 151 lines · Teddy Astie
Le 30/12/2025 à 16:52, Oleksii Kurochko a écrit :
Quoted 150 lines
Add support of virtual SBI base extension calls for RISC-V guests, delegating hardware-specific queries to the underlying SBI and handling version and firmware ID queries directly.
The changes include:
1. Define new SBI base extension function IDs (SBI_EXT_BASE_GET_MVENDORID,SBI_EXT_BASE_GET_MARCHID,SBI_EXT_BASE_GET_MIMPID).
2. IntroduceXEN_SBI_VER_MAJOR,XEN_SBI_VER_MINORfor imeplenataion ofSBI_EXT_BASE_GET_SPEC_VERSION.
4. IntroduceSBI_XEN_IMPIDto implementSBI_EXT_BASE_GET_IMP_ID.
5. Implement handling of SBI base extension functions, including version, firmware ID, and machine-specific queries.Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in v4:
- Move definition of XEN_SBI_VER_{MAJOR, MINOR} tobase-extension.c.
- Correct string format for FID: s/#%#lx/#%lu.
- Print first EID then FID (asvsbi/core.ccode does).
---
Changes in v3:
- s/XEN_SBI_IMPID/SBI_XEN_IMPID
- AddASSERT(eid == SBI_EXT_BASE)invsbi_base_ecall_handler().
- Fix code style for switch/case.
- Use current instead ofvcpuargument as it was dropped fromvsbi_base_ecall_handler()prototype.
- Add comments for define-s XEN_SBI_VER_{MAJOR, MINOR} andSBI_XEN_IMPID.
---
Changes in v2:
- s/vsbi-base-extension.*/base-extension.*
- IntroduceVCPU_SBI_IMPID,XEN_SBI_VER_MINORandXEN_SBI_VER_MAJOR.
- ReturnVCPU_SBI_IMPIDin the case ofSBI_EXT_BASE_GET_IMP_ID.
- Return Xen version in the case ofSBI_EXT_BASE_GET_IMP_VERSION.
- Usedomain_crash()instead ofpanic()for default case.
- For SBI_EXT_BASE_GET_{MVENDORID,MARCHID,MIMPID} abdSBI_EXT_BASE_PROBE_EXTadd handling of a domain is h/w or not.--- xen/arch/riscv/include/asm/sbi.h | 6 ++ xen/arch/riscv/vsbi/Makefile | 1 + xen/arch/riscv/vsbi/base-extension.c | 82 ++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+)create mode 100644
xen/arch/riscv/vsbi/base-extension.cxen/arch/riscv/include/asm/sbi.h +6
-0@@ -14,6 +14,9 @@#include <xen/cpumask.h> +/* SBI-defined implementation ID */ +#define SBI_XEN_IMPID 7 +#define SBI_EXT_0_1_SET_TIMER 0x0#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1#define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2@@ -32,6 +35,9 @@#define SBI_EXT_BASE_GET_IMP_ID 0x1#define SBI_EXT_BASE_GET_IMP_VERSION 0x2#define SBI_EXT_BASE_PROBE_EXT 0x3 +#define SBI_EXT_BASE_GET_MVENDORID 0x4 +#define SBI_EXT_BASE_GET_MARCHID 0x5 +#define SBI_EXT_BASE_GET_MIMPID 0x6/* SBI function IDs for RFENCE extension */ #define SBI_EXT_RFENCE_REMOTE_FENCE_I 0x0xen/arch/riscv/vsbi/Makefile +1
-0@@ -1,2 +1,3 @@ +obj-y += base-extension.o obj-y += core.o obj-y += legacy-extension.oxen/arch/riscv/vsbi/base-extension.c new file +69
-0@@ -0,0 +1,82 @@ + +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/lib.h> +#include <xen/sched.h> +#include <xen/version.h> + +#include <asm/processor.h> +#include <asm/sbi.h> +#include <asm/vsbi.h> + +/* Xen-controlled SBI version reported to guests */ +#define XEN_SBI_VER_MAJOR 0 +#define XEN_SBI_VER_MINOR 2 + +static int vsbi_base_ecall_handler (unsigned long eid,unsigned long fid, +struct cpu_user_regs *regs) +{ +int ret =0 ; +struct sbiret sbi_ret; + +ASSERT (eid ==SBI_EXT_BASE ); + +switch ( fid ) + { +case SBI_EXT_BASE_GET_SPEC_VERSION : + regs->a1 =MASK_INSR (XEN_SBI_VER_MAJOR ,SBI_SPEC_VERSION_MAJOR_MASK ) | +XEN_SBI_VER_MINOR ; +break ; + +case SBI_EXT_BASE_GET_IMP_ID : + regs->a1 =SBI_XEN_IMPID ; +break ; + +case SBI_EXT_BASE_GET_IMP_VERSION : + regs->a1 = (xen_major_version () <<16 ) |xen_minor_version (); +break ; + +case SBI_EXT_BASE_GET_MVENDORID : +case SBI_EXT_BASE_GET_MARCHID : +case SBI_EXT_BASE_GET_MIMPID : +if (is_hardware_domain (current->domain) ) + { + sbi_ret =sbi_ecall (SBI_EXT_BASE , fid,0 ,0 ,0 ,0 ,0 ,0 ); + ret = sbi_ret.error; + regs->a1 = sbi_ret.value; + } +else +/* +* vSBI should present a consistent, virtualized view to guests. +* In particular, DomU-visible data must remain stable across +* migration and must not expose hardware-specific details. +* +* These register(s) must be readable in any implementation, +* but a value of 0 can be returned to indicate the field +* is not implemented. +*/ + regs->a1 =0 ; + +break ; + +case SBI_EXT_BASE_PROBE_EXT : + regs->a1 =vsbi_find_extension (regs->a0) ?1 :0 ; +break ; + +default : +/* +* TODO: domain_crash() is acceptable here while things are still under +* development.
Quoted 8 lines
xen/arch/riscv/vsbi/base-extension.c line 75
Quoted 6 lines
xen/arch/riscv/vsbi/base-extension.c new file +6
-0+* It shouldn't stay like this in the end though: guests should not +* be punished like this for something Xen hasn't implemented. +*/ +domain_crash (current->domain, +"%s: Unsupported ecall: EID: #%#lx FID: #%lu\n" , + __func__, eid, fid);I think we should rather report "
SBI_ERR_NOT_SUPPORTED" (-2) instead (eventually logging a warning in Xen) ?
The final goal is to return|SBI_ERR_NOT_SUPPORTED|.|domain_crash()| is used only temporarily and will be kept until a usable alternative (lets say fully supported dom0less) is available.
~ Oleksii
Quoted 20 lines
xen/arch/riscv/vsbi/base-extension.c line 82
Quoted 8 lines
xen/arch/riscv/vsbi/base-extension.c new file +7
-0+break ; + } + +return ret; +} + +VSBI_EXT (base,SBI_EXT_BASE ,SBI_EXT_BASE , vsbi_base_ecall_handler)Teddy
--
Teddy Astie | Vates XCP-ng DeveloperXCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH v4 1/1] xen/riscv: add RISC-V virtual SBI base extension support for guests
In reply to Oleksii KurochkoQuoted 13 lines · Oleksii Kurochko
Add support of virtual SBI base extension calls for RISC-V guests, delegating hardware-specific queries to the underlying SBI and handling version and firmware ID queries directly.
The changes include:
1. Define new SBI base extension function IDs (SBI_EXT_BASE_GET_MVENDORID,SBI_EXT_BASE_GET_MARCHID,SBI_EXT_BASE_GET_MIMPID).
2. IntroduceXEN_SBI_VER_MAJOR,XEN_SBI_VER_MINORfor imeplenataion ofSBI_EXT_BASE_GET_SPEC_VERSION.
4. IntroduceSBI_XEN_IMPIDto implementSBI_EXT_BASE_GET_IMP_ID.
5. Implement handling of SBI base extension functions, including version, firmware ID, and machine-specific queries.
Quoted 1 line
Signed-off-by Oleksii Kurochko <[email protected]>
Albeit with a question:
Quoted 7 lines
xen/arch/riscv/vsbi/base-extension.c new file +4
-0@@ -0,0 +1,82 @@ + +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/lib.h>
xen/arch/riscv/vsbi/base-extension.c line 14
Quoted 10 lines
xen/arch/riscv/vsbi/base-extension.c new file +10
-0+#include <xen/sched.h> +#include <xen/version.h> + +#include <asm/processor.h> +#include <asm/sbi.h> +#include <asm/vsbi.h> + +/* Xen-controlled SBI version reported to guests */ +#define XEN_SBI_VER_MAJOR 0 +#define XEN_SBI_VER_MINOR 2
Is it clear from whatever spec it is that is ...
Quoted 4 lines
xen/arch/riscv/vsbi/base-extension.c new file +4
-0+static int vsbi_base_ecall_handler (unsigned long eid,unsigned long fid, +struct cpu_user_regs *regs) +{ +int ret =0 ;
xen/arch/riscv/vsbi/base-extension.c line 29
Quoted 10 lines
xen/arch/riscv/vsbi/base-extension.c new file +10
-0+struct sbiret sbi_ret; + +ASSERT (eid ==SBI_EXT_BASE ); + +switch ( fid ) + { +case SBI_EXT_BASE_GET_SPEC_VERSION : + regs->a1 =MASK_INSR (XEN_SBI_VER_MAJOR ,SBI_SPEC_VERSION_MAJOR_MASK ) | +XEN_SBI_VER_MINOR ; +break ;
... implied here (it's ..._SPEC_VERSION after all) under what conditions the version would need bumping and what effects this would have on existing (e.g. migrating-in) guests? Recall that ...
Quoted 12 lines
xen/arch/riscv/vsbi/base-extension.c new file +12
-0+case SBI_EXT_BASE_GET_IMP_ID : + regs->a1 =SBI_XEN_IMPID ; +break ; + +case SBI_EXT_BASE_GET_IMP_VERSION : + regs->a1 = (xen_major_version () <<16 ) |xen_minor_version (); +break ; + +case SBI_EXT_BASE_GET_MVENDORID : +case SBI_EXT_BASE_GET_MARCHID : +case SBI_EXT_BASE_GET_MIMPID : +if (is_hardware_domain (current->domain) )
xen/arch/riscv/vsbi/base-extension.c line 52
Quoted 10 lines
xen/arch/riscv/vsbi/base-extension.c new file +10
-0+ { + sbi_ret =sbi_ecall (SBI_EXT_BASE , fid,0 ,0 ,0 ,0 ,0 ,0 ); + ret = sbi_ret.error; + regs->a1 = sbi_ret.value; + } + else +/* +* vSBI should present a consistent, virtualized view to guests. +* In particular, DomU-visible data must remain stable across +* migration and must not expose hardware-specific details.
... what is being said here applies to other sub-functions as well. IOW it looks to me as if the version reported needs to be a per-guest property.
Jan
Re: [PATCH v4 1/1] xen/riscv: add RISC-V virtual SBI base extension support for guests
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
Add support of virtual SBI base extension calls for RISC-V guests, delegating hardware-specific queries to the underlying SBI and handling version and firmware ID queries directly.
The changes include:
1. Define new SBI base extension function IDs (SBI_EXT_BASE_GET_MVENDORID,SBI_EXT_BASE_GET_MARCHID,SBI_EXT_BASE_GET_MIMPID).
2. IntroduceXEN_SBI_VER_MAJOR,XEN_SBI_VER_MINORfor imeplenataion ofSBI_EXT_BASE_GET_SPEC_VERSION.
4. IntroduceSBI_XEN_IMPIDto implementSBI_EXT_BASE_GET_IMP_ID.
5. Implement handling of SBI base extension functions, including version, firmware ID, and machine-specific queries.
Quoted 2 lines
Quoted 1 line
Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>
Thanks.
Quoted 31 lines
Albeit with a question:
Quoted 7 lines
xen/arch/riscv/vsbi/base-extension.c new file +4
-0@@ -0,0 +1,82 @@ + +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/lib.h> xen/arch/riscv/vsbi/base-extension.c line 14
Quoted 10 lines
xen/arch/riscv/vsbi/base-extension.c new file +10
-0+#include <xen/sched.h> +#include <xen/version.h> + +#include <asm/processor.h> +#include <asm/sbi.h> +#include <asm/vsbi.h> + +/* Xen-controlled SBI version reported to guests */ +#define XEN_SBI_VER_MAJOR 0 +#define XEN_SBI_VER_MINOR 2Is it clear from whatever spec it is that is ...
Quoted 9 lines
xen/arch/riscv/vsbi/base-extension.c new file +9
-0+static int vsbi_base_ecall_handler (unsigned long eid,unsigned long fid, +struct cpu_user_regs *regs) +{ +int ret =0 ; +struct sbiret sbi_ret; + +ASSERT (eid ==SBI_EXT_BASE ); + + switch ( fid )
Quoted 8 lines
xen/arch/riscv/vsbi/base-extension.c line 29
Quoted 5 lines
xen/arch/riscv/vsbi/base-extension.c new file +5
-0+ { +case SBI_EXT_BASE_GET_SPEC_VERSION : + regs->a1 =MASK_INSR (XEN_SBI_VER_MAJOR ,SBI_SPEC_VERSION_MAJOR_MASK ) | +XEN_SBI_VER_MINOR ; +break ;... implied here (it's ..._SPEC_VERSION after all) under what conditions the version would need bumping and what effects this would have on existing (e.g. migrating-in) guests? Recall that ...
For example, sooner or later we will want to use the SBI DBCN (Debug Console Extension) for early debug output for guests, as it provides an API to work with strings instead of single characters. This will require bumping the SBI version to 2.0.
I don’t think this should cause any migration issues. If a guest was fully booted and running with Xen SBI version 0.2, it would continue to use the legacy extension for early console output (or for hvc console which is using SBI calls in Linux for the moment). If the guest was still in the initialization stage (before SBI extensions were probed), it would simply use the newer SBI DBCN extension instead of the Legacy one.
~ Oleksii
Quoted 27 lines
Quoted 13 lines
xen/arch/riscv/vsbi/base-extension.c new file +12
-0+case SBI_EXT_BASE_GET_IMP_ID : + regs->a1 =SBI_XEN_IMPID ; +break ; + +case SBI_EXT_BASE_GET_IMP_VERSION : + regs->a1 = (xen_major_version () <<16 ) |xen_minor_version (); +break ; + +case SBI_EXT_BASE_GET_MVENDORID : +case SBI_EXT_BASE_GET_MARCHID : +case SBI_EXT_BASE_GET_MIMPID : +if (is_hardware_domain (current->domain) )xen/arch/riscv/vsbi/base-extension.c line 52
Quoted 10 lines
xen/arch/riscv/vsbi/base-extension.c new file +10
-0+ { + sbi_ret =sbi_ecall (SBI_EXT_BASE , fid,0 ,0 ,0 ,0 ,0 ,0 ); + ret = sbi_ret.error; + regs->a1 = sbi_ret.value; + } + else +/* +* vSBI should present a consistent, virtualized view to guests. +* In particular, DomU-visible data must remain stable across +* migration and must not expose hardware-specific details. ... what is being said here applies to other sub-functions as well. IOW it looks to me as if the version reported needs to be a per-guest property.
Jan
Re: [PATCH v4 1/1] xen/riscv: add RISC-V virtual SBI base extension support for guests
Quoted 59 lines · Oleksii Kurochko
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
Add support of virtual SBI base extension calls for RISC-V guests, delegating hardware-specific queries to the underlying SBI and handling version and firmware ID queries directly.
The changes include:
1. Define new SBI base extension function IDs (SBI_EXT_BASE_GET_MVENDORID,SBI_EXT_BASE_GET_MARCHID,SBI_EXT_BASE_GET_MIMPID).
2. IntroduceXEN_SBI_VER_MAJOR,XEN_SBI_VER_MINORfor imeplenataion ofSBI_EXT_BASE_GET_SPEC_VERSION.
4. IntroduceSBI_XEN_IMPIDto implementSBI_EXT_BASE_GET_IMP_ID.
5. Implement handling of SBI base extension functions, including version, firmware ID, and machine-specific queries.Quoted 2 lines
Quoted 1 line
Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>Thanks.
Quoted 30 lines
Albeit with a question:
Quoted 7 lines
xen/arch/riscv/vsbi/base-extension.c new file +4
-0@@ -0,0 +1,82 @@ + +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/lib.h> xen/arch/riscv/vsbi/base-extension.c line 14
Quoted 10 lines
xen/arch/riscv/vsbi/base-extension.c new file +10
-0+#include <xen/sched.h> +#include <xen/version.h> + +#include <asm/processor.h> +#include <asm/sbi.h> +#include <asm/vsbi.h> + +/* Xen-controlled SBI version reported to guests */ +#define XEN_SBI_VER_MAJOR 0 +#define XEN_SBI_VER_MINOR 2Is it clear from whatever spec it is that is ...
Quoted 9 lines
xen/arch/riscv/vsbi/base-extension.c new file +9
-0+static int vsbi_base_ecall_handler (unsigned long eid,unsigned long fid, +struct cpu_user_regs *regs) +{ +int ret =0 ; +struct sbiret sbi_ret; + +ASSERT (eid ==SBI_EXT_BASE ); + + switch ( fid )Quoted 8 lines
xen/arch/riscv/vsbi/base-extension.c line 29
Quoted 5 lines
xen/arch/riscv/vsbi/base-extension.c new file +5
-0+ { +case SBI_EXT_BASE_GET_SPEC_VERSION : + regs->a1 =MASK_INSR (XEN_SBI_VER_MAJOR ,SBI_SPEC_VERSION_MAJOR_MASK ) | +XEN_SBI_VER_MINOR ; +break ;... implied here (it's ..._SPEC_VERSION after all) under what conditions the version would need bumping and what effects this would have on existing (e.g. migrating-in) guests? Recall that ...
Quoted 4 lines
For example, sooner or later we will want to use the SBI DBCN (Debug Console Extension) for early debug output for guests, as it provides an API to work with strings instead of single characters. This will require bumping the SBI version to 2.0.
I fear there's a misunderstanding here, likely on my side: Why would it be 2.0? Didn't you say the version is Xen controlled? If so, why not 0.3 or 1.0?
Contrary to what you said previously, it now looks to me as if the version wasn't "Xen-controlled", but instead what we pick reflects functionality required by a particular spec version of a spec we do not control. That's "SBI version implemented by Xen" to me though, not really a "Xen-controlled" version.
Jan
Quoted 36 lines
I don’t think this should cause any migration issues. If a guest was fully booted and running with Xen SBI version 0.2, it would continue to use the legacy extension for early console output (or for hvc console which is using SBI calls in Linux for the moment). If the guest was still in the initialization stage (before SBI extensions were probed), it would simply use the newer SBI DBCN extension instead of the Legacy one.
~ Oleksii
Quoted 27 lines
Quoted 13 lines
xen/arch/riscv/vsbi/base-extension.c new file +12
-0+case SBI_EXT_BASE_GET_IMP_ID : + regs->a1 =SBI_XEN_IMPID ; +break ; + +case SBI_EXT_BASE_GET_IMP_VERSION : + regs->a1 = (xen_major_version () <<16 ) |xen_minor_version (); +break ; + +case SBI_EXT_BASE_GET_MVENDORID : +case SBI_EXT_BASE_GET_MARCHID : +case SBI_EXT_BASE_GET_MIMPID : +if (is_hardware_domain (current->domain) )xen/arch/riscv/vsbi/base-extension.c line 52
Quoted 10 lines
xen/arch/riscv/vsbi/base-extension.c new file +10
-0+ { + sbi_ret =sbi_ecall (SBI_EXT_BASE , fid,0 ,0 ,0 ,0 ,0 ,0 ); + ret = sbi_ret.error; + regs->a1 = sbi_ret.value; + } + else +/* +* vSBI should present a consistent, virtualized view to guests. +* In particular, DomU-visible data must remain stable across +* migration and must not expose hardware-specific details. ... what is being said here applies to other sub-functions as well. IOW it looks to me as if the version reported needs to be a per-guest property.
Jan
Re: [PATCH v4 1/1] xen/riscv: add RISC-V virtual SBI base extension support for guests
Quoted 58 lines · Jan Beulich
Quoted 57 lines · Oleksii Kurochko
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
Add support of virtual SBI base extension calls for RISC-V guests, delegating hardware-specific queries to the underlying SBI and handling version and firmware ID queries directly.
The changes include:
1. Define new SBI base extension function IDs (SBI_EXT_BASE_GET_MVENDORID,SBI_EXT_BASE_GET_MARCHID,SBI_EXT_BASE_GET_MIMPID).
2. IntroduceXEN_SBI_VER_MAJOR,XEN_SBI_VER_MINORfor imeplenataion ofSBI_EXT_BASE_GET_SPEC_VERSION.
4. IntroduceSBI_XEN_IMPIDto implementSBI_EXT_BASE_GET_IMP_ID.
5. Implement handling of SBI base extension functions, including version, firmware ID, and machine-specific queries.Quoted 2 lines
Quoted 1 line
Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>Thanks.
Quoted 38 lines
Albeit with a question:
Quoted 7 lines
xen/arch/riscv/vsbi/base-extension.c new file +4
-0@@ -0,0 +1,82 @@ + +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/lib.h> xen/arch/riscv/vsbi/base-extension.c line 14
Quoted 10 lines
xen/arch/riscv/vsbi/base-extension.c new file +10
-0+#include <xen/sched.h> +#include <xen/version.h> + +#include <asm/processor.h> +#include <asm/sbi.h> +#include <asm/vsbi.h> + +/* Xen-controlled SBI version reported to guests */ +#define XEN_SBI_VER_MAJOR 0 +#define XEN_SBI_VER_MINOR 2Is it clear from whatever spec it is that is ...
Quoted 4 lines
xen/arch/riscv/vsbi/base-extension.c new file +4
-0+static int vsbi_base_ecall_handler (unsigned long eid,unsigned long fid, +struct cpu_user_regs *regs) +{ +int ret =0 ;xen/arch/riscv/vsbi/base-extension.c line 29
Quoted 10 lines
xen/arch/riscv/vsbi/base-extension.c new file +10
-0+struct sbiret sbi_ret; + +ASSERT (eid ==SBI_EXT_BASE ); + +switch ( fid ) + { +case SBI_EXT_BASE_GET_SPEC_VERSION : + regs->a1 =MASK_INSR (XEN_SBI_VER_MAJOR ,SBI_SPEC_VERSION_MAJOR_MASK ) | +XEN_SBI_VER_MINOR ; +break ;... implied here (it's ..._SPEC_VERSION after all) under what conditions the version would need bumping and what effects this would have on existing (e.g. migrating-in) guests? Recall that ...
Quoted 6 lines
Quoted 4 lines
For example, sooner or later we will want to use the SBI DBCN (Debug Console Extension) for early debug output for guests, as it provides an API to work with strings instead of single characters. This will require bumping the SBI version to 2.0.
I fear there's a misunderstanding here, likely on my side: Why would it be 2.0? Didn't you say the version is Xen controlled? If so, why not 0.3 or 1.0?
I mentioned 2.0 because SBI DBCN support starts in SBI version 2.0 (2.0-rc2, to be more precise). If we use 0.3 or 1.0 instead, the guest won’t know [1][2] that it can use the SBI DBCN extension instead of the legacy extension.
[1] https://elixir.bootlin.com/linux/v6.18.3/source/arch/riscv/kernel/sbi.c#L692
[2] https://elixir.bootlin.com/linux/v6.18.3/source/drivers/tty/hvc/hvc_riscv_sbi.c#L67
Quoted 6 lines
Contrary to what you said previously, it now looks to me as if the version wasn't "Xen-controlled", but instead what we pick reflects functionality required by a particular spec version of a spec we do not control. That's "SBI version implemented by Xen" to me though, not really a "Xen-controlled" version.
I will update the comment above definitions of XEN_SBI_VER_MAJOR and XEN_SBI_VER_MINOR to:
/* SBI version implemented by Xen and reported to guests */
~ Oleksii
Quoted 35 lines
Quoted 35 lines
I don’t think this should cause any migration issues. If a guest was fully booted and running with Xen SBI version 0.2, it would continue to use the legacy extension for early console output (or for hvc console which is using SBI calls in Linux for the moment). If the guest was still in the initialization stage (before SBI extensions were probed), it would simply use the newer SBI DBCN extension instead of the Legacy one.
~ Oleksii
Quoted 26 lines
Quoted 12 lines
xen/arch/riscv/vsbi/base-extension.c new file +12
-0+case SBI_EXT_BASE_GET_IMP_ID : + regs->a1 =SBI_XEN_IMPID ; +break ; + +case SBI_EXT_BASE_GET_IMP_VERSION : + regs->a1 = (xen_major_version () <<16 ) |xen_minor_version (); +break ; + +case SBI_EXT_BASE_GET_MVENDORID : +case SBI_EXT_BASE_GET_MARCHID : +case SBI_EXT_BASE_GET_MIMPID : +if (is_hardware_domain (current->domain) )xen/arch/riscv/vsbi/base-extension.c line 52
Quoted 10 lines
xen/arch/riscv/vsbi/base-extension.c new file +10
-0+ { + sbi_ret =sbi_ecall (SBI_EXT_BASE , fid,0 ,0 ,0 ,0 ,0 ,0 ); + ret = sbi_ret.error; + regs->a1 = sbi_ret.value; + } + else +/* +* vSBI should present a consistent, virtualized view to guests. +* In particular, DomU-visible data must remain stable across +* migration and must not expose hardware-specific details. ... what is being said here applies to other sub-functions as well. IOW it looks to me as if the version reported needs to be a per-guest property.
Jan