riscv: Move user-visible sbi ext ids to uapi
Subsystems (2)
PATCH 1/1 riscv: Move user-visible sbi ext ids to uapi
Move those sbi ext ids to uapi because they will be forwarded to user space by kvm.
--- arch/riscv/include/asm/sbi.h | 16 +----------- arch/riscv/include/uapi/asm/sbi.h | 43 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 arch/riscv/include/uapi/asm/sbi.h
arch/riscv/include/asm/sbi.h +1 -15
@@ -10,13 +10,12 @@#include <linux/types.h> #include <linux/cpumask.h> #include <linux/jump_label.h> +#include <uapi/asm/sbi.h> #ifdef CONFIG_RISCV_SBI enum sbi_ext_id { #ifdef CONFIG_RISCV_SBI_V01 SBI_EXT_0_1_SET_TIMER = 0x0, - SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1, - SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2, SBI_EXT_0_1_CLEAR_IPI = 0x3, SBI_EXT_0_1_SEND_IPI = 0x4, SBI_EXT_0_1_REMOTE_FENCE_I = 0x5,
@@ -37,13 +36,6 @@ enum sbi_ext_id {SBI_EXT_NACL =0x4E41434C , SBI_EXT_FWFT = 0x46574654, -/* Experimentals extensions must lie within this range */ -SBI_EXT_EXPERIMENTAL_START =0x08000000 , -SBI_EXT_EXPERIMENTAL_END =0x08FFFFFF , - -/* Vendor extensions must lie within this range */ -SBI_EXT_VENDOR_START =0x09000000 , - SBI_EXT_VENDOR_END = 0x09FFFFFF, }; enum sbi_ext_base_fid {
@@ -263,12 +255,6 @@ enum sbi_pmu_ctr_type {#define SBI_PMU_STOP_FLAG_RESET BIT(0)#define SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT BIT(1) -enum sbi_ext_dbcn_fid { -SBI_EXT_DBCN_CONSOLE_WRITE =0 , -SBI_EXT_DBCN_CONSOLE_READ =1 , -SBI_EXT_DBCN_CONSOLE_WRITE_BYTE =2 , -}; -/* SBI STA (steal-time accounting) extension */ enum sbi_ext_sta_fid {SBI_EXT_STA_STEAL_TIME_SET_SHMEM =0 ,
arch/riscv/include/uapi/asm/sbi.h new file +43 -0
44 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 2 lines · BillXiang
Move those sbi ext ids to uapi because they will be forwarded to user space by kvm.
We don't need to publish the IDs in UAPI since they are already known to userspace by reading the SBI spec. Indeed QEMU already defines all of these except for the experimental range.
What problem are you trying to solve?
Thanks,
drew
Quoted 106 lines
Signed-off-by BillXiang <[email protected]>--- arch/riscv/include/asm/sbi.h | 16 +----------- arch/riscv/include/uapi/asm/sbi.h | 43 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 arch/riscv/include/uapi/asm/sbi.harch/riscv/include/asm/sbi.h +1
-15@@ -10,13 +10,12 @@#include <linux/types.h> #include <linux/cpumask.h> #include <linux/jump_label.h> +#include <uapi/asm/sbi.h> #ifdef CONFIG_RISCV_SBI enum sbi_ext_id { #ifdef CONFIG_RISCV_SBI_V01 SBI_EXT_0_1_SET_TIMER = 0x0, - SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1, - SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2, SBI_EXT_0_1_CLEAR_IPI = 0x3, SBI_EXT_0_1_SEND_IPI = 0x4, SBI_EXT_0_1_REMOTE_FENCE_I = 0x5,@@ -37,13 +36,6 @@ enum sbi_ext_id {SBI_EXT_NACL =0x4E41434C , SBI_EXT_FWFT = 0x46574654, -/* Experimentals extensions must lie within this range */ -SBI_EXT_EXPERIMENTAL_START =0x08000000 , -SBI_EXT_EXPERIMENTAL_END =0x08FFFFFF , - -/* Vendor extensions must lie within this range */ -SBI_EXT_VENDOR_START =0x09000000 , - SBI_EXT_VENDOR_END = 0x09FFFFFF, }; enum sbi_ext_base_fid {@@ -263,12 +255,6 @@ enum sbi_pmu_ctr_type {#define SBI_PMU_STOP_FLAG_RESET BIT(0)#define SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT BIT(1) -enum sbi_ext_dbcn_fid { -SBI_EXT_DBCN_CONSOLE_WRITE =0 , -SBI_EXT_DBCN_CONSOLE_READ =1 , -SBI_EXT_DBCN_CONSOLE_WRITE_BYTE =2 , -}; -/* SBI STA (steal-time accounting) extension */ enum sbi_ext_sta_fid {SBI_EXT_STA_STEAL_TIME_SET_SHMEM =0 ,arch/riscv/include/uapi/asm/sbi.h new file +43
-0@@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright (C) 2025 Lanxincomputing Corporation or its affiliates. +* +* Authors: +* BillXiang <[email protected]> +*/ + +#ifndef _UAPI_ASM_RISCV_SBI_H +#define _UAPI_ASM_RISCV_SBI_H + + +enum SBI_EXT_ID { +/* +* The CONSOLE_GETCHAR/CONSOLE_PUTCHAR SBI calls cannot be +* handled in kernel so they will be forwarded to userspace by kvm. +*/ +SBI_EXT_0_1_CONSOLE_PUTCHAR =0x1 , +SBI_EXT_0_1_CONSOLE_GETCHAR =0x2 , +/* +* Both SBI experimental and vendor extensions are +* unconditionally forwarded to userspace by kvm. +*/ +/* Experimentals extensions must lie within this range */ +SBI_EXT_EXPERIMENTAL_START =0x08000000 , +SBI_EXT_EXPERIMENTAL_END =0x08FFFFFF , + +/* Vendor extensions must lie within this range */ +SBI_EXT_VENDOR_START =0x09000000 , +SBI_EXT_VENDOR_END =0x09FFFFFF , +}; + +/* +* The SBI debug console functions are unconditionally +* forwarded to the userspace by kvm. +*/ +enum sbi_ext_dbcn_fid { +SBI_EXT_DBCN_CONSOLE_WRITE =0 , +SBI_EXT_DBCN_CONSOLE_READ =1 , +SBI_EXT_DBCN_CONSOLE_WRITE_BYTE =2 , +}; + +#endif /* _UAPI_ASM_RISCV_SBI_H */ Signature · 1 line
2.43.0
Quoted 8 lines · Andrew Jones
Quoted 2 lines · BillXiang
Move those sbi ext ids to uapi because they will be forwarded to user space by kvm.
We don't need to publish the IDs in UAPI since they are already known to userspace by reading the SBI spec. Indeed QEMU already defines all of these except for the experimental range.>
What problem are you trying to solve?
I'm working on rust-vmm[1], which auto-generates the ID constants from uapi/kvm.h via bindgen[2]. Any ID that isn't exported there is invisible to us. I expect other VMMs besides QEMU will need these numbers as well, so let's keep one canonical definition in the UAPI headers for everyone to share.
[1] https://github.com/rust-vmm
[2] https://crates.io/crates/bindgen
Quoted 110 lines
Thanks,
drewQuoted 106 lines
Signed-off-by BillXiang <[email protected]>--- arch/riscv/include/asm/sbi.h | 16 +----------- arch/riscv/include/uapi/asm/sbi.h | 43 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 15 deletions(-)create mode 100644
arch/riscv/include/uapi/asm/sbi.harch/riscv/include/asm/sbi.h +1
-15@@ -10,13 +10,12 @@#include <linux/types.h> #include <linux/cpumask.h> #include <linux/jump_label.h> +#include <uapi/asm/sbi.h> #ifdef CONFIG_RISCV_SBI enum sbi_ext_id { #ifdef CONFIG_RISCV_SBI_V01 SBI_EXT_0_1_SET_TIMER = 0x0, - SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1, - SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2, SBI_EXT_0_1_CLEAR_IPI = 0x3, SBI_EXT_0_1_SEND_IPI = 0x4, SBI_EXT_0_1_REMOTE_FENCE_I = 0x5,@@ -37,13 +36,6 @@ enum sbi_ext_id {SBI_EXT_NACL =0x4E41434C , SBI_EXT_FWFT = 0x46574654, -/* Experimentals extensions must lie within this range */ -SBI_EXT_EXPERIMENTAL_START =0x08000000 , -SBI_EXT_EXPERIMENTAL_END =0x08FFFFFF , - -/* Vendor extensions must lie within this range */ -SBI_EXT_VENDOR_START =0x09000000 , - SBI_EXT_VENDOR_END = 0x09FFFFFF, }; enum sbi_ext_base_fid {@@ -263,12 +255,6 @@ enum sbi_pmu_ctr_type {#define SBI_PMU_STOP_FLAG_RESET BIT(0)#define SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT BIT(1) -enum sbi_ext_dbcn_fid { -SBI_EXT_DBCN_CONSOLE_WRITE =0 , -SBI_EXT_DBCN_CONSOLE_READ =1 , -SBI_EXT_DBCN_CONSOLE_WRITE_BYTE =2 , -}; -/* SBI STA (steal-time accounting) extension */ enum sbi_ext_sta_fid {SBI_EXT_STA_STEAL_TIME_SET_SHMEM =0 ,arch/riscv/include/uapi/asm/sbi.h new file +43
-0@@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright (C) 2025 Lanxincomputing Corporation or its affiliates. +* +* Authors: +* BillXiang <[email protected]> +*/ + +#ifndef _UAPI_ASM_RISCV_SBI_H +#define _UAPI_ASM_RISCV_SBI_H + + +enum SBI_EXT_ID { +/* +* The CONSOLE_GETCHAR/CONSOLE_PUTCHAR SBI calls cannot be +* handled in kernel so they will be forwarded to userspace by kvm. +*/ +SBI_EXT_0_1_CONSOLE_PUTCHAR =0x1 , +SBI_EXT_0_1_CONSOLE_GETCHAR =0x2 , +/* +* Both SBI experimental and vendor extensions are +* unconditionally forwarded to userspace by kvm. +*/ +/* Experimentals extensions must lie within this range */ +SBI_EXT_EXPERIMENTAL_START =0x08000000 , +SBI_EXT_EXPERIMENTAL_END =0x08FFFFFF , + +/* Vendor extensions must lie within this range */ +SBI_EXT_VENDOR_START =0x09000000 , +SBI_EXT_VENDOR_END =0x09FFFFFF , +}; + +/* +* The SBI debug console functions are unconditionally +* forwarded to the userspace by kvm. +*/ +enum sbi_ext_dbcn_fid { +SBI_EXT_DBCN_CONSOLE_WRITE =0 , +SBI_EXT_DBCN_CONSOLE_READ =1 , +SBI_EXT_DBCN_CONSOLE_WRITE_BYTE =2 , +}; + +#endif /* _UAPI_ASM_RISCV_SBI_H */ Signature · 1 line
2.43.0
Signature · 3 lines
kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
Quoted 11 lines · BillXiang
Quoted 8 lines · Andrew Jones
Quoted 2 lines · BillXiang
Move those sbi ext ids to uapi because they will be forwarded to user space by kvm.
We don't need to publish the IDs in UAPI since they are already known to userspace by reading the SBI spec. Indeed QEMU already defines all of these except for the experimental range.>
What problem are you trying to solve?
Quoted 5 lines
I'm working on rust-vmm[1], which auto-generates the ID constants from
uapi/kvm.hvia bindgen[2]. Any ID that isn't exported there is invisible to us. I expect other VMMs besides QEMU will need these numbers as well, so let's keep one canonical definition in the UAPI headers for everyone to share.
But KVM isn't the authority on these IDs, the spec is. KVM and its userspaces are just some implementations of SBI. M-mode software and other hypervisors also implements SBI.
For Rust you can use https://docs.rs/sbi-spec/latest/sbi_spec/ to get the constants you're looking for.
Thanks,
drew
Quoted 115 lines
[1] https://github.com/rust-vmm
[2] https://crates.io/crates/bindgenQuoted 110 lines
Thanks,
drewQuoted 106 lines
Signed-off-by BillXiang <[email protected]>--- arch/riscv/include/asm/sbi.h | 16 +----------- arch/riscv/include/uapi/asm/sbi.h | 43 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 15 deletions(-)create mode 100644
arch/riscv/include/uapi/asm/sbi.harch/riscv/include/asm/sbi.h +1
-15@@ -10,13 +10,12 @@#include <linux/types.h> #include <linux/cpumask.h> #include <linux/jump_label.h> +#include <uapi/asm/sbi.h> #ifdef CONFIG_RISCV_SBI enum sbi_ext_id { #ifdef CONFIG_RISCV_SBI_V01 SBI_EXT_0_1_SET_TIMER = 0x0, - SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1, - SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2, SBI_EXT_0_1_CLEAR_IPI = 0x3, SBI_EXT_0_1_SEND_IPI = 0x4, SBI_EXT_0_1_REMOTE_FENCE_I = 0x5,@@ -37,13 +36,6 @@ enum sbi_ext_id {SBI_EXT_NACL =0x4E41434C , SBI_EXT_FWFT = 0x46574654, -/* Experimentals extensions must lie within this range */ -SBI_EXT_EXPERIMENTAL_START =0x08000000 , -SBI_EXT_EXPERIMENTAL_END =0x08FFFFFF , - -/* Vendor extensions must lie within this range */ -SBI_EXT_VENDOR_START =0x09000000 , - SBI_EXT_VENDOR_END = 0x09FFFFFF, }; enum sbi_ext_base_fid {@@ -263,12 +255,6 @@ enum sbi_pmu_ctr_type {#define SBI_PMU_STOP_FLAG_RESET BIT(0)#define SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT BIT(1) -enum sbi_ext_dbcn_fid { -SBI_EXT_DBCN_CONSOLE_WRITE =0 , -SBI_EXT_DBCN_CONSOLE_READ =1 , -SBI_EXT_DBCN_CONSOLE_WRITE_BYTE =2 , -}; -/* SBI STA (steal-time accounting) extension */ enum sbi_ext_sta_fid {SBI_EXT_STA_STEAL_TIME_SET_SHMEM =0 ,arch/riscv/include/uapi/asm/sbi.h new file +43
-0@@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright (C) 2025 Lanxincomputing Corporation or its affiliates. +* +* Authors: +* BillXiang <[email protected]> +*/ + +#ifndef _UAPI_ASM_RISCV_SBI_H +#define _UAPI_ASM_RISCV_SBI_H + + +enum SBI_EXT_ID { +/* +* The CONSOLE_GETCHAR/CONSOLE_PUTCHAR SBI calls cannot be +* handled in kernel so they will be forwarded to userspace by kvm. +*/ +SBI_EXT_0_1_CONSOLE_PUTCHAR =0x1 , +SBI_EXT_0_1_CONSOLE_GETCHAR =0x2 , +/* +* Both SBI experimental and vendor extensions are +* unconditionally forwarded to userspace by kvm. +*/ +/* Experimentals extensions must lie within this range */ +SBI_EXT_EXPERIMENTAL_START =0x08000000 , +SBI_EXT_EXPERIMENTAL_END =0x08FFFFFF , + +/* Vendor extensions must lie within this range */ +SBI_EXT_VENDOR_START =0x09000000 , +SBI_EXT_VENDOR_END =0x09FFFFFF , +}; + +/* +* The SBI debug console functions are unconditionally +* forwarded to the userspace by kvm. +*/ +enum sbi_ext_dbcn_fid { +SBI_EXT_DBCN_CONSOLE_WRITE =0 , +SBI_EXT_DBCN_CONSOLE_READ =1 , +SBI_EXT_DBCN_CONSOLE_WRITE_BYTE =2 , +}; + +#endif /* _UAPI_ASM_RISCV_SBI_H */ Signature · 1 line
2.43.0
Quoted 18 lines · Andrew Jones
Quoted 11 lines · BillXiang
Quoted 8 lines · Andrew Jones
Quoted 2 lines · BillXiang
Move those sbi ext ids to uapi because they will be forwarded to user space by kvm.
We don't need to publish the IDs in UAPI since they are already known to userspace by reading the SBI spec. Indeed QEMU already defines all of these except for the experimental range.>
What problem are you trying to solve?Quoted 5 lines
I'm working on rust-vmm[1], which auto-generates the ID constants from
uapi/kvm.hvia bindgen[2]. Any ID that isn't exported there is invisible to us. I expect other VMMs besides QEMU will need these numbers as well, so let's keep one canonical definition in the UAPI headers for everyone to share.
Quoted 6 lines
But KVM isn't the authority on these IDs, the spec is. KVM and its userspaces are just some implementations of SBI. M-mode software and other hypervisors also implements SBI.
For Rust you can use https://docs.rs/sbi-spec/latest/sbi_spec/ to get the constants you're looking for.
This is a good idea. I'll try it.
Thanks,
bill
Quoted 119 lines
Thanks,
drewQuoted 115 lines
[1] https://github.com/rust-vmm
[2] https://crates.io/crates/bindgenQuoted 110 lines
Thanks,
drewQuoted 106 lines
Signed-off-by BillXiang <[email protected]>--- arch/riscv/include/asm/sbi.h | 16 +----------- arch/riscv/include/uapi/asm/sbi.h | 43 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 15 deletions(-)create mode 100644
arch/riscv/include/uapi/asm/sbi.harch/riscv/include/asm/sbi.h +1
-15@@ -10,13 +10,12 @@#include <linux/types.h> #include <linux/cpumask.h> #include <linux/jump_label.h> +#include <uapi/asm/sbi.h> #ifdef CONFIG_RISCV_SBI enum sbi_ext_id { #ifdef CONFIG_RISCV_SBI_V01 SBI_EXT_0_1_SET_TIMER = 0x0, - SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1, - SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2, SBI_EXT_0_1_CLEAR_IPI = 0x3, SBI_EXT_0_1_SEND_IPI = 0x4, SBI_EXT_0_1_REMOTE_FENCE_I = 0x5,@@ -37,13 +36,6 @@ enum sbi_ext_id {SBI_EXT_NACL =0x4E41434C , SBI_EXT_FWFT = 0x46574654, -/* Experimentals extensions must lie within this range */ -SBI_EXT_EXPERIMENTAL_START =0x08000000 , -SBI_EXT_EXPERIMENTAL_END =0x08FFFFFF , - -/* Vendor extensions must lie within this range */ -SBI_EXT_VENDOR_START =0x09000000 , - SBI_EXT_VENDOR_END = 0x09FFFFFF, }; enum sbi_ext_base_fid {@@ -263,12 +255,6 @@ enum sbi_pmu_ctr_type {#define SBI_PMU_STOP_FLAG_RESET BIT(0)#define SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT BIT(1) -enum sbi_ext_dbcn_fid { -SBI_EXT_DBCN_CONSOLE_WRITE =0 , -SBI_EXT_DBCN_CONSOLE_READ =1 , -SBI_EXT_DBCN_CONSOLE_WRITE_BYTE =2 , -}; -/* SBI STA (steal-time accounting) extension */ enum sbi_ext_sta_fid {SBI_EXT_STA_STEAL_TIME_SET_SHMEM =0 ,arch/riscv/include/uapi/asm/sbi.h new file +43
-0@@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright (C) 2025 Lanxincomputing Corporation or its affiliates. +* +* Authors: +* BillXiang <[email protected]> +*/ + +#ifndef _UAPI_ASM_RISCV_SBI_H +#define _UAPI_ASM_RISCV_SBI_H + + +enum SBI_EXT_ID { +/* +* The CONSOLE_GETCHAR/CONSOLE_PUTCHAR SBI calls cannot be +* handled in kernel so they will be forwarded to userspace by kvm. +*/ +SBI_EXT_0_1_CONSOLE_PUTCHAR =0x1 , +SBI_EXT_0_1_CONSOLE_GETCHAR =0x2 , +/* +* Both SBI experimental and vendor extensions are +* unconditionally forwarded to userspace by kvm. +*/ +/* Experimentals extensions must lie within this range */ +SBI_EXT_EXPERIMENTAL_START =0x08000000 , +SBI_EXT_EXPERIMENTAL_END =0x08FFFFFF , + +/* Vendor extensions must lie within this range */ +SBI_EXT_VENDOR_START =0x09000000 , +SBI_EXT_VENDOR_END =0x09FFFFFF , +}; + +/* +* The SBI debug console functions are unconditionally +* forwarded to the userspace by kvm. +*/ +enum sbi_ext_dbcn_fid { +SBI_EXT_DBCN_CONSOLE_WRITE =0 , +SBI_EXT_DBCN_CONSOLE_READ =1 , +SBI_EXT_DBCN_CONSOLE_WRITE_BYTE =2 , +}; + +#endif /* _UAPI_ASM_RISCV_SBI_H */ Signature · 1 line
2.43.0