RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support
Subsystems (5)
v3 cover RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support
The latest KVM in Linux-6.4 has support for:
1) Enabling/disabling SBI extensions from KVM user-space
2) Zbb ISA extension support
3) Zicboz ISA extension support
4) Ssaia ISA extension support
This series adds corresponding changes in KVMTOOL to use the above mentioned features for Guest/VM.
These patches can also be found in the riscv_sbi_zbb_zicboz_ssaia_v3 branch at: https://github.com/avpatel/kvmtool.git
Changes since v2:
- Rebased on commit 0b5e55fc032d1c6394b8ec7fe02d842813c903df
- Updated PATCH1 to sync-up header with released Linux-6.4
Changes since v1:
- Rebased on commit b17552ee6c9728c20c9d0bd037ef134277daaa40
- Fixed compile error for KVMTOOL x86 by adding __DECLARE_FLEX_ARRAY() in include/linux/stddef.h
Andrew Jones (1):
riscv: Add Zicboz extension support
Anup Patel (7):
Sync-up headers with Linux-6.4
riscv: Allow setting custom mvendorid, marchid, and mimpid
riscv: Allow disabling SBI extensions for Guest
riscv: Sort the ISA extension array alphabetically
riscv: Add zbb extension support
riscv: Add Ssaia extension support
riscv: Fix guest RAM alloc size computation for RV32
arm/aarch64/include/asm/kvm.h | 38 ++++++++++ include/linux/kvm.h | 57 +++++++++------ include/linux/virtio_blk.h | 105 ++++++++++++++++++++++++++++ include/linux/virtio_config.h | 6 ++ include/linux/virtio_net.h | 5 ++ riscv/fdt.c | 19 ++++- riscv/include/asm/kvm.h | 56 ++++++++++++++- riscv/include/kvm/kvm-config-arch.h | 51 +++++++++++++- riscv/include/kvm/kvm-cpu-arch.h | 19 +++-- riscv/kvm-cpu.c | 45 +++++++++++- riscv/kvm.c | 15 +++- x86/include/asm/kvm.h | 50 ++++++++++--- 12 files changed, 419 insertions(+), 47 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/8 Sync-up headers with Linux-6.4
We sync-up Linux headers to get latest KVM RISC-V headers having SBI extension enable/disable, Zbb, Zicboz, and Ssaia support.
--- arm/aarch64/include/asm/kvm.h | 38 ++++++++++++ include/linux/kvm.h | 57 +++++++++++------- include/linux/virtio_blk.h | 105 ++++++++++++++++++++++++++++++++++ include/linux/virtio_config.h | 6 ++ include/linux/virtio_net.h | 5 ++ riscv/include/asm/kvm.h | 56 +++++++++++++++++- x86/include/asm/kvm.h | 50 ++++++++++++---- 7 files changed, 286 insertions(+), 31 deletions(-)
arm/aarch64/include/asm/kvm.h +38 -0
@@ -43,6 +43,7 @@#define __KVM_HAVE_VCPU_EVENTS#define KVM_COALESCED_MMIO_PAGE_OFFSET 1 +#define KVM_DIRTY_LOG_PAGE_OFFSET 64#define KVM_REG_SIZE (id) \ (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
@@ -108,6 +109,7 @@ struct kvm_regs {#define KVM_ARM_VCPU_SVE 4/* enable SVE for this CPU */ #define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5/* VCPU uses address authentication */ #define KVM_ARM_VCPU_PTRAUTH_GENERIC 6/* VCPU uses generic authentication */ +#define KVM_ARM_VCPU_HAS_EL2 7/* Support nested virtualization */ struct kvm_vcpu_init {__u32 target;
@@ -196,6 +198,15 @@ struct kvm_arm_copy_mte_tags {__u64 reserved[2 ]; }; +/* +* Counter/Timer offset structure. Describe the virtual/physical offset. +* To be used with KVM_ARM_SET_COUNTER_OFFSET. +*/ +struct kvm_arm_counter_offset { +__u64 counter_offset; +__u64 reserved; +}; +#define KVM_ARM_TAGS_TO_GUEST 0#define KVM_ARM_TAGS_FROM_GUEST 1
@@ -370,6 +381,10 @@ enum {#endif }; +/* Device Control API on vm fd */ +#define KVM_ARM_VM_SMCCC_CTRL 0 +#define KVM_ARM_VM_SMCCC_FILTER 0 +/* Device Control API: ARM VGIC */ #define KVM_DEV_ARM_VGIC_GRP_ADDR 0#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1
@@ -409,6 +424,8 @@ enum {#define KVM_ARM_VCPU_TIMER_CTRL 1#define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0#define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1 +#define KVM_ARM_VCPU_TIMER_IRQ_HVTIMER 2 +#define KVM_ARM_VCPU_TIMER_IRQ_HPTIMER 3#define KVM_ARM_VCPU_PVTIME_CTRL 2#define KVM_ARM_VCPU_PVTIME_IPA 0
@@ -467,6 +484,27 @@ enum {/* run->fail_entry.hardware_entry_failure_reason codes. */ #define KVM_EXIT_FAIL_ENTRY_CPU_UNSUPPORTED (1ULL << 0) +enum kvm_smccc_filter_action { +KVM_SMCCC_FILTER_HANDLE =0 , +KVM_SMCCC_FILTER_DENY , +KVM_SMCCC_FILTER_FWD_TO_USER , + +#ifdef __KERNEL__ +NR_SMCCC_FILTER_ACTIONS +#endif +}; + +struct kvm_smccc_filter { +__u32 base; +__u32 nr_functions; +__u8 action; +__u8 pad[15 ]; +}; + +/* arm64-specific KVM_EXIT_HYPERCALL flags */ +#define KVM_HYPERCALL_EXIT_SMC (1U << 0) +#define KVM_HYPERCALL_EXIT_16BIT (1U << 1) +#endif #endif /* __ARM_KVM_H__ */
include/linux/kvm.h +37 -20
161 lines not on this page · raw message
include/linux/virtio_blk.h +105 -0
133 lines not on this page · raw message
include/linux/virtio_config.h +6 -0
@@ -99,6 +99,12 @@*/ #define VIRTIO_F_SR_IOV 37 +/* +* This feature indicates that the driver passes extra data (besides +* identifying the virtqueue) in its device notifications. +*/ +#define VIRTIO_F_NOTIFICATION_DATA 38 +/* * This feature indicates that the driver can reset a queue individually. */
include/linux/virtio_net.h +5 -0
@@ -57,7 +57,11 @@* Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23/* Set MAC address */ #define VIRTIO_NET_F_NOTF_COAL 53/* Device supports notifications coalescing */ +#define VIRTIO_NET_F_GUEST_USO4 54/* Guest can handle USOv4 in. */ +#define VIRTIO_NET_F_GUEST_USO6 55/* Guest can handle USOv6 in. */ +#define VIRTIO_NET_F_HOST_USO 56/* Host can handle USO in. */ #define VIRTIO_NET_F_HASH_REPORT 57/* Supports hash report */ +#define VIRTIO_NET_F_GUEST_HDRLEN 59/* Guest provides the exact hdr_len value. */ #define VIRTIO_NET_F_RSS 60/* Supports RSS RX steering */ #define VIRTIO_NET_F_RSC_EXT 61/* extended coalescing info */ #define VIRTIO_NET_F_STANDBY 62/* Act as standby for another device
@@ -130,6 +134,7 @@ struct virtio_net_hdr_v1 {#define VIRTIO_NET_HDR_GSO_TCPV4 1/* GSO frame, IPv4 TCP (TSO) */ #define VIRTIO_NET_HDR_GSO_UDP 3/* GSO frame, IPv4 UDP (UFO) */ #define VIRTIO_NET_HDR_GSO_TCPV6 4/* GSO frame, IPv6 TCP */ +#define VIRTIO_NET_HDR_GSO_UDP_L4 5/* GSO frame, IPv4& IPv6 UDP (USO) */ #define VIRTIO_NET_HDR_GSO_ECN 0x80/* TCP has ECN set */ __u8 gso_type;__virtio16 hdr_len;/* Ethernet + IP + tcp/udp hdrs */
riscv/include/asm/kvm.h +55 -1
109 lines not on this page · raw message
x86/include/asm/kvm.h +40 -10
90 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 2/8 riscv: Allow setting custom mvendorid, marchid, and mimpid
In reply to Anup PatelWe add command-line parameter to set custom mvendorid, marchid, and mimpid so that users can show fake CPU type to Guest/VM which does not match underlying Host CPU.
--- riscv/include/kvm/kvm-config-arch.h | 12 ++++++++++++ riscv/kvm-cpu.c | 26 +++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-)
riscv/include/kvm/kvm-config-arch.h +12 -0
@@ -5,6 +5,9 @@struct kvm_config_arch {const char *dump_dtb_filename; +u64 custom_mvendorid; +u64 custom_marchid; +u64 custom_mimpid;bool ext_disabled[KVM_RISCV_ISA_EXT_MAX ]; };
@@ -12,6 +15,15 @@ struct kvm_config_arch { pfx, \OPT_STRING ('\0' ,"dump-dtb" , &(cfg)->dump_dtb_filename, \".dtb file" ,"Dump generated .dtb to specified file" ),\ +OPT_U64 ('\0' ,"custom-mvendorid" , \ + &(cfg)->custom_mvendorid, \ +"Show custom mvendorid to Guest VCPU" ), \ +OPT_U64 ('\0' ,"custom-marchid" , \ + &(cfg)->custom_marchid, \ +"Show custom marchid to Guest VCPU" ), \ +OPT_U64 ('\0' ,"custom-mimpid" , \ + &(cfg)->custom_mimpid, \ +"Show custom mimpid to Guest VCPU" ), \OPT_BOOLEAN ('\0' ,"disable-sstc" , \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSTC ], \ "Disable Sstc Extension"), \
riscv/kvm-cpu.c +25 -1
@@ -22,7 +22,7 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) {struct kvm_cpu *vcpu;u64 timebase =0 ; -unsigned long isa =0 ; +unsigned long isa =0 , id =0 ;int coalesced_offset, mmap_size;struct kvm_one_reg reg;
@@ -64,6 +64,30 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)if (ioctl (vcpu->vcpu_fd,KVM_SET_ONE_REG , ®) <0 )die ("KVM_SET_ONE_REG failed (config.isa)" ); +if (kvm->cfg.arch.custom_mvendorid) { + id = kvm->cfg.arch.custom_mvendorid; + reg.id =RISCV_CONFIG_REG (mvendorid); + reg.addr = (unsigned long )&id; +if (ioctl (vcpu->vcpu_fd,KVM_SET_ONE_REG , ®) <0 ) +die ("KVM_SET_ONE_REG failed (config.mvendorid)" ); + } + +if (kvm->cfg.arch.custom_marchid) { + id = kvm->cfg.arch.custom_marchid; + reg.id =RISCV_CONFIG_REG (marchid); + reg.addr = (unsigned long )&id; +if (ioctl (vcpu->vcpu_fd,KVM_SET_ONE_REG , ®) <0 ) +die ("KVM_SET_ONE_REG failed (config.marchid)" ); + } + +if (kvm->cfg.arch.custom_mimpid) { + id = kvm->cfg.arch.custom_mimpid; + reg.id =RISCV_CONFIG_REG (mimpid); + reg.addr = (unsigned long )&id; +if (ioctl (vcpu->vcpu_fd,KVM_SET_ONE_REG , ®) <0 ) +die ("KVM_SET_ONE_REG failed (config.mimpid)" ); + } +/* Populate the vcpu structure. */ vcpu->kvm = kvm; vcpu->cpu_id = cpu_id;
Signature · 1 line
2.34.1
PATCH v3 3/8 riscv: Allow disabling SBI extensions for Guest
In reply to Anup PatelWe add "--disable-sbi-<xyz>" options to disable various SBI extensions visible to the Guest. This allows users to disable deprecated/redundant SBI extensions.
--- riscv/include/kvm/kvm-config-arch.h | 30 ++++++++++++++++++++++++++++- riscv/include/kvm/kvm-cpu-arch.h | 19 +++++++++++------- riscv/kvm-cpu.c | 19 +++++++++++++++++- 3 files changed, 59 insertions(+), 9 deletions(-)
riscv/include/kvm/kvm-config-arch.h +29 -1
@@ -9,6 +9,7 @@ struct kvm_config_arch {u64 custom_marchid;u64 custom_mimpid;bool ext_disabled[KVM_RISCV_ISA_EXT_MAX ]; +bool sbi_ext_disabled[KVM_RISCV_SBI_EXT_MAX ]; };#define OPT_ARCH_RUN (pfx, cfg) \
@@ -38,6 +39,33 @@ struct kvm_config_arch { "Disable Zicbom Extension"), \OPT_BOOLEAN ('\0' ,"disable-zihintpause" , \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZIHINTPAUSE ],\ - "Disable Zihintpause Extension"), +"Disable Zihintpause Extension" ), \ +OPT_BOOLEAN ('\0' ,"disable-sbi-legacy" , \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_V01 ], \ +"Disable SBI Legacy Extensions" ), \ +OPT_BOOLEAN ('\0' ,"disable-sbi-time" , \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_TIME ], \ +"Disable SBI Time Extension" ), \ +OPT_BOOLEAN ('\0' ,"disable-sbi-ipi" , \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_IPI ], \ +"Disable SBI IPI Extension" ), \ +OPT_BOOLEAN ('\0' ,"disable-sbi-rfence" , \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_RFENCE ], \ +"Disable SBI RFence Extension" ), \ +OPT_BOOLEAN ('\0' ,"disable-sbi-srst" , \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_SRST ], \ +"Disable SBI SRST Extension" ), \ +OPT_BOOLEAN ('\0' ,"disable-sbi-hsm" , \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_HSM ], \ +"Disable SBI HSM Extension" ), \ +OPT_BOOLEAN ('\0' ,"disable-sbi-pmu" , \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_PMU ], \ +"Disable SBI PMU Extension" ), \ +OPT_BOOLEAN ('\0' ,"disable-sbi-experimental" , \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_EXPERIMENTAL ],\ +"Disable SBI Experimental Extensions" ), \ +OPT_BOOLEAN ('\0' ,"disable-sbi-vendor" , \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_VENDOR ], \ + "Disable SBI Vendor Extensions"), #endif /* KVM__KVM_CONFIG_ARCH_H */
riscv/include/kvm/kvm-cpu-arch.h +12 -7
@@ -7,9 +7,10 @@#include "kvm/kvm.h" -static inline __u64 __kvm_reg_id (__u64 type,__u64 idx,__u64 size) +static inline __u64 __kvm_reg_id (__u64 type,__u64 subtype, +__u64 idx,__u64 size) { -return KVM_REG_RISCV | type | idx | size; +return KVM_REG_RISCV | type | subtype | idx | size; }#if __riscv_xlen ==64
@@ -18,25 +19,29 @@ static inline __u64 __kvm_reg_id(__u64 type, __u64 idx, __u64 size)#define KVM_REG_SIZE_ULONG KVM_REG_SIZE_U32#endif -#define RISCV_CONFIG_REG (name) __kvm_reg_id(KVM_REG_RISCV_CONFIG, \ +#define RISCV_CONFIG_REG (name) __kvm_reg_id(KVM_REG_RISCV_CONFIG, 0, \ KVM_REG_RISCV_CONFIG_REG(name), \ KVM_REG_SIZE_ULONG) -#define RISCV_ISA_EXT_REG (id) __kvm_reg_id(KVM_REG_RISCV_ISA_EXT, \ +#define RISCV_ISA_EXT_REG (id) __kvm_reg_id(KVM_REG_RISCV_ISA_EXT, 0, \ id, KVM_REG_SIZE_ULONG) -#define RISCV_CORE_REG (name) __kvm_reg_id(KVM_REG_RISCV_CORE, \ +#define RISCV_CORE_REG (name) __kvm_reg_id(KVM_REG_RISCV_CORE, 0, \ KVM_REG_RISCV_CORE_REG(name), \ KVM_REG_SIZE_ULONG) -#define RISCV_CSR_REG (name) __kvm_reg_id(KVM_REG_RISCV_CSR, \ +#define RISCV_CSR_REG (name) __kvm_reg_id(KVM_REG_RISCV_CSR, 0, \ KVM_REG_RISCV_CSR_REG(name), \ KVM_REG_SIZE_ULONG) -#define RISCV_TIMER_REG (name) __kvm_reg_id(KVM_REG_RISCV_TIMER, \ +#define RISCV_TIMER_REG (name) __kvm_reg_id(KVM_REG_RISCV_TIMER, 0, \ KVM_REG_RISCV_TIMER_REG(name), \ KVM_REG_SIZE_U64) +#define RISCV_SBI_EXT_REG (subtype, id) \ + __kvm_reg_id(KVM_REG_RISCV_SBI_EXT, subtype, \ + id, KVM_REG_SIZE_ULONG) +struct kvm_cpu {pthread_t thread;
riscv/kvm-cpu.c +18 -1
@@ -23,7 +23,8 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)struct kvm_cpu *vcpu;u64 timebase =0 ;unsigned long isa =0 , id =0 ; -int coalesced_offset, mmap_size; +unsigned long masks[KVM_REG_RISCV_SBI_MULTI_REG_LAST +1 ] = {0 }; +int i, coalesced_offset, mmap_size;struct kvm_one_reg reg; vcpu =calloc (1 ,sizeof (struct kvm_cpu ));
@@ -88,6 +89,22 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)die ("KVM_SET_ONE_REG failed (config.mimpid)" ); } +for (i =0 ; i <KVM_RISCV_SBI_EXT_MAX ; i++) { +if (!kvm->cfg.arch.sbi_ext_disabled[i]) +continue ; + masks[KVM_REG_RISCV_SBI_MULTI_REG (i)] |= +KVM_REG_RISCV_SBI_MULTI_MASK (i); + } +for (i =0 ; i <=KVM_REG_RISCV_SBI_MULTI_REG_LAST ; i++) { +if (!masks[i]) +continue ; + + reg.id =RISCV_SBI_EXT_REG (KVM_REG_RISCV_SBI_MULTI_DIS , i); + reg.addr = (unsigned long )&masks[i]; +if (ioctl (vcpu->vcpu_fd,KVM_SET_ONE_REG , ®) <0 ) +die ("KVM_SET_ONE_REG failed (sbi_ext %d)" , i); + } +/* Populate the vcpu structure. */ vcpu->kvm = kvm; vcpu->cpu_id = cpu_id;
Signature · 1 line
2.34.1
PATCH v3 4/8 riscv: Sort the ISA extension array alphabetically
In reply to Anup PatelLet us follow alphabetical order for listing ISA extensions in the isa_info_arr[] array.
--- riscv/fdt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
riscv/fdt.c +3 -2
@@ -15,11 +15,12 @@ struct isa_ext_info { };struct isa_ext_info isa_info_arr[] = { - {"svpbmt" ,KVM_RISCV_ISA_EXT_SVPBMT }, +/* sorted alphabetically */ {"sstc" ,KVM_RISCV_ISA_EXT_SSTC }, {"svinval" ,KVM_RISCV_ISA_EXT_SVINVAL }, - {"zihintpause" ,KVM_RISCV_ISA_EXT_ZIHINTPAUSE }, + {"svpbmt" ,KVM_RISCV_ISA_EXT_SVPBMT }, {"zicbom" ,KVM_RISCV_ISA_EXT_ZICBOM }, + {"zihintpause" ,KVM_RISCV_ISA_EXT_ZIHINTPAUSE }, };static void dump_fdt (const char *dtb_file,void *fdt)
Signature · 1 line
2.34.1
PATCH v3 5/8 riscv: Add zbb extension support
In reply to Anup PatelThe zbb extension allows software to use basic bitmanip instructions. Let us add the zbb extension to the Guest device tree whenever it is supported by the host.
--- riscv/fdt.c | 1 + riscv/include/kvm/kvm-config-arch.h | 3 +++ 2 files changed, 4 insertions(+)
riscv/fdt.c +1 -0
@@ -19,6 +19,7 @@ struct isa_ext_info isa_info_arr[] = { {"sstc", KVM_RISCV_ISA_EXT_SSTC}, {"svinval", KVM_RISCV_ISA_EXT_SVINVAL}, {"svpbmt", KVM_RISCV_ISA_EXT_SVPBMT}, + {"zbb", KVM_RISCV_ISA_EXT_ZBB}, {"zicbom", KVM_RISCV_ISA_EXT_ZICBOM}, {"zihintpause", KVM_RISCV_ISA_EXT_ZIHINTPAUSE}, };
riscv/include/kvm/kvm-config-arch.h +3 -0
@@ -34,6 +34,9 @@ struct kvm_config_arch {OPT_BOOLEAN ('\0' ,"disable-svpbmt" , \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SVPBMT ], \"Disable Svpbmt Extension" ), \ +OPT_BOOLEAN ('\0' ,"disable-zbb" , \ + &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZBB ], \ +"Disable Zbb Extension" ), \OPT_BOOLEAN ('\0' ,"disable-zicbom" , \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZICBOM ], \ "Disable Zicbom Extension"), \
Signature · 1 line
2.34.1
PATCH v3 6/8 riscv: Add Zicboz extension support
In reply to Anup PatelFrom: Andrew Jones <[email protected]>
When the Zicboz extension is available expose it to the guest. Also provide the guest the size of the cache block through DT.
--- riscv/fdt.c | 12 +++++++++++- riscv/include/kvm/kvm-config-arch.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-)
riscv/fdt.c +11 -1
@@ -21,6 +21,7 @@ struct isa_ext_info isa_info_arr[] = { {"svpbmt", KVM_RISCV_ISA_EXT_SVPBMT}, {"zbb", KVM_RISCV_ISA_EXT_ZBB}, {"zicbom", KVM_RISCV_ISA_EXT_ZICBOM}, + {"zicboz", KVM_RISCV_ISA_EXT_ZICBOZ}, {"zihintpause", KVM_RISCV_ISA_EXT_ZIHINTPAUSE}, };
@@ -47,7 +48,7 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)int cpu, pos, i, index, valid_isa_len;const char *valid_isa_order ="IEMAFDQCLBJTPVNSUHKORWXYZG" ;int arr_sz =ARRAY_SIZE (isa_info_arr); -unsigned long cbom_blksz =0 ; +unsigned long cbom_blksz =0 , cboz_blksz =0 ;_FDT (fdt_begin_node (fdt,"cpus" ));_FDT (fdt_property_cell (fdt,"#address-cells" ,0x1 ));
@@ -97,6 +98,13 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)die ("KVM_GET_ONE_REG failed (config.zicbom_block_size)" ); } +if (isa_info_arr[i].ext_id ==KVM_RISCV_ISA_EXT_ZICBOZ && !cboz_blksz) { + reg.id =RISCV_CONFIG_REG (zicboz_block_size); + reg.addr = (unsigned long )&cboz_blksz; +if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , ®) <0 ) +die ("KVM_GET_ONE_REG failed (config.zicboz_block_size)" ); + } +if ((strlen (isa_info_arr[i].name) + pos +1 ) >=CPU_ISA_MAX_LEN ) {pr_warning ("Insufficient space to append ISA exension\n" );break ;
@@ -118,6 +126,8 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)_FDT (fdt_property_string (fdt,"riscv,isa" , cpu_isa));if (cbom_blksz)_FDT (fdt_property_cell (fdt,"riscv,cbom-block-size" , cbom_blksz)); +if (cboz_blksz) +_FDT (fdt_property_cell (fdt,"riscv,cboz-block-size" , cboz_blksz));_FDT (fdt_property_cell (fdt,"reg" , cpu));_FDT (fdt_property_string (fdt,"status" ,"okay" ));
riscv/include/kvm/kvm-config-arch.h +3 -0
@@ -40,6 +40,9 @@ struct kvm_config_arch {OPT_BOOLEAN ('\0' ,"disable-zicbom" , \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZICBOM ], \"Disable Zicbom Extension" ), \ +OPT_BOOLEAN ('\0' ,"disable-zicboz" , \ + &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZICBOZ ], \ +"Disable Zicboz Extension" ), \OPT_BOOLEAN ('\0' ,"disable-zihintpause" , \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZIHINTPAUSE ],\ "Disable Zihintpause Extension"), \
Signature · 1 line
2.34.1
PATCH v3 7/8 riscv: Add Ssaia extension support
In reply to Anup PatelWhen the Ssaia extension is available expose it to the guest.
--- riscv/fdt.c | 1 + riscv/include/kvm/kvm-config-arch.h | 3 +++ 2 files changed, 4 insertions(+)
riscv/fdt.c +1 -0
@@ -16,6 +16,7 @@ struct isa_ext_info {struct isa_ext_info isa_info_arr[] = {/* sorted alphabetically */ + {"ssaia" ,KVM_RISCV_ISA_EXT_SSAIA }, {"sstc" ,KVM_RISCV_ISA_EXT_SSTC }, {"svinval" ,KVM_RISCV_ISA_EXT_SVINVAL }, {"svpbmt" ,KVM_RISCV_ISA_EXT_SVPBMT },
riscv/include/kvm/kvm-config-arch.h +3 -0
@@ -25,6 +25,9 @@ struct kvm_config_arch {OPT_U64 ('\0' ,"custom-mimpid" , \ &(cfg)->custom_mimpid, \"Show custom mimpid to Guest VCPU" ), \ +OPT_BOOLEAN ('\0' ,"disable-ssaia" , \ + &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSAIA ], \ +"Disable Ssaia Extension" ), \OPT_BOOLEAN ('\0' ,"disable-sstc" , \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSTC ], \ "Disable Sstc Extension"), \
Signature · 1 line
2.34.1
PATCH v3 8/8 riscv: Fix guest RAM alloc size computation for RV32
In reply to Anup PatelCurrently, we ensure that guest RAM alloc size is at least 2M for THP which works well for RV64 but breaks hugepage support for RV32. To fix this, we use 4M as hugepage size for RV32.
--- riscv/kvm.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
riscv/kvm.c +12 -3
@@ -61,16 +61,25 @@ void kvm__arch_set_cmdline(char *cmdline, bool video) { } +#if __riscv_xlen ==64 +#define HUGEPAGE_SIZE SZ_2M +#else +#define HUGEPAGE_SIZE SZ_4M +#endif +void kvm__arch_init (struct kvm *kvm) {/* * Allocate guest memory. We must align our buffer to 64K to * correlate with the maximum guest page size for virtio-mmio. -* If using THP, then our minimal alignment becomes 2M. -* 2M trumps 64K, so let's go with that. +* If using THP, then our minimal alignment becomes hugepage +* size. The hugepage size is always greater than 64K, so +* let's go with that. */ kvm->ram_size =min (kvm->cfg.ram_size, (u64 )RISCV_MAX_MEMORY (kvm)); - kvm->arch.ram_alloc_size = kvm->ram_size +SZ_2M ; + kvm->arch.ram_alloc_size = kvm->ram_size; +if (!kvm->cfg.hugetlbfs_path) + kvm->arch.ram_alloc_size +=HUGEPAGE_SIZE ; kvm->arch.ram_alloc_start =mmap_anon_or_hugetlbfs (kvm, kvm->cfg.hugetlbfs_path, kvm->arch.ram_alloc_size);
Signature · 1 line
2.34.1
Quoted 9 lines · Anup Patel
The latest KVM in Linux-6.4 has support for:
1) Enabling/disabling SBI extensions from KVM user-space
2) Zbb ISA extension support
3) Zicboz ISA extension support
4) Ssaia ISA extension supportThis series adds corresponding changes in KVMTOOL to use the above mentioned features for Guest/VM.
Quoted 6 lines
These patches can also be found in the
riscv_sbi_zbb_zicboz_ssaia_v3branch at: https://github.com/avpatel/kvmtool.gitChanges since v2:
- Rebased on commit0b5e55fc032d1c6394b8ec7fe02d842813c903df
- Updated PATCH1 to sync-up header with released Linux-6.4
Bah, now we're back to the __DECLARE_FLEX_ARRAY breakage :(
In file included from include/linux/kvm.h:15,
from x86/include/kvm/kvm-cpu-arch.h:6,
from include/kvm/kvm-cpu.h:4,
from include/kvm/ioport.h:4,
from hw/rtc.c:4:
x86/include/asm/kvm.h:511:17: error: expected specifier-qualifier-list before ?__DECLARE_FLEX_ARRAY?
511 | __DECLARE_FLEX_ARRAY(struct kvm_vmx_nested_state_data, vmx);
| ^~~~~~~~~~~~~~~~~~~~Will
Anup Patel
maintainerQuoted 20 lines · On Wed, Jul 12, 2023 at 9:41?PM Will Deacon <[email protected]> wrote:
Quoted 9 lines · Anup Patel
The latest KVM in Linux-6.4 has support for:
1) Enabling/disabling SBI extensions from KVM user-space
2) Zbb ISA extension support
3) Zicboz ISA extension support
4) Ssaia ISA extension supportThis series adds corresponding changes in KVMTOOL to use the above mentioned features for Guest/VM.
Quoted 6 lines
These patches can also be found in the
riscv_sbi_zbb_zicboz_ssaia_v3branch at: https://github.com/avpatel/kvmtool.gitChanges since v2:
- Rebased on commit0b5e55fc032d1c6394b8ec7fe02d842813c903df
- Updated PATCH1 to sync-up header with released Linux-6.4Bah, now we're back to the
__DECLARE_FLEX_ARRAYbreakage :(
Quoted 8 lines
In file included from
include/linux/kvm.h:15,from x86/include/kvm/kvm-cpu-arch.h:6, from include/kvm/kvm-cpu.h:4, from include/kvm/ioport.h:4, from hw/rtc.c:4: x86/include/asm/kvm.h:511:17: error: expected specifier-qualifier-list before ?__DECLARE_FLEX_ARRAY? 511 | __DECLARE_FLEX_ARRAY(struct kvm_vmx_nested_state_data, vmx); | ^~~~~~~~~~~~~~~~~~~~
My bad, the fix for this error was folded in the header sync patch of v2 which got accidently dropped in this version.
I will send v4 with the compile error fix as a separate patch.
Regards,
Anup