* [kvmtool PATCH v3 01/10] Sync-up headers with Linux-6.14 kernel
2025-04-26 11:03 [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
@ 2025-04-26 11:03 ` Anup Patel
2025-04-26 11:03 ` [kvmtool PATCH v3 02/10] riscv: Add Svvptc extension support Anup Patel
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2025-04-26 11:03 UTC (permalink / raw)
To: Will Deacon, julien.thierry.kdev, maz
Cc: Paolo Bonzini, Atish Patra, Andrew Jones, Anup Patel, kvm,
kvm-riscv, Anup Patel
We sync-up Linux headers to get latest KVM RISC-V headers having
newly added ISA extensions in ONE_REG interface.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
arm64/include/asm/kvm.h | 3 ---
include/linux/kvm.h | 8 ++++----
include/linux/virtio_pci.h | 14 ++++++++++++++
riscv/include/asm/kvm.h | 7 ++++---
x86/include/asm/kvm.h | 1 +
5 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/arm64/include/asm/kvm.h b/arm64/include/asm/kvm.h
index 66736ff..568bf85 100644
--- a/arm64/include/asm/kvm.h
+++ b/arm64/include/asm/kvm.h
@@ -43,9 +43,6 @@
#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))
-
struct kvm_regs {
struct user_pt_regs regs; /* sp = sp_el0 */
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 502ea63..45e6d8f 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -617,10 +617,6 @@ struct kvm_ioeventfd {
#define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
#define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2)
#define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3)
-#define KVM_X86_DISABLE_VALID_EXITS (KVM_X86_DISABLE_EXITS_MWAIT | \
- KVM_X86_DISABLE_EXITS_HLT | \
- KVM_X86_DISABLE_EXITS_PAUSE | \
- KVM_X86_DISABLE_EXITS_CSTATE)
/* for KVM_ENABLE_CAP */
struct kvm_enable_cap {
@@ -1070,6 +1066,10 @@ struct kvm_dirty_tlb {
#define KVM_REG_SIZE_SHIFT 52
#define KVM_REG_SIZE_MASK 0x00f0000000000000ULL
+
+#define KVM_REG_SIZE(id) \
+ (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
+
#define KVM_REG_SIZE_U8 0x0000000000000000ULL
#define KVM_REG_SIZE_U16 0x0010000000000000ULL
#define KVM_REG_SIZE_U32 0x0020000000000000ULL
diff --git a/include/linux/virtio_pci.h b/include/linux/virtio_pci.h
index 1beb317..8549d45 100644
--- a/include/linux/virtio_pci.h
+++ b/include/linux/virtio_pci.h
@@ -116,6 +116,8 @@
#define VIRTIO_PCI_CAP_PCI_CFG 5
/* Additional shared memory capability */
#define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
+/* PCI vendor data configuration */
+#define VIRTIO_PCI_CAP_VENDOR_CFG 9
/* This is the PCI capability header: */
struct virtio_pci_cap {
@@ -130,6 +132,18 @@ struct virtio_pci_cap {
__le32 length; /* Length of the structure, in bytes. */
};
+/* This is the PCI vendor data capability header: */
+struct virtio_pci_vndr_data {
+ __u8 cap_vndr; /* Generic PCI field: PCI_CAP_ID_VNDR */
+ __u8 cap_next; /* Generic PCI field: next ptr. */
+ __u8 cap_len; /* Generic PCI field: capability length */
+ __u8 cfg_type; /* Identifies the structure. */
+ __u16 vendor_id; /* Identifies the vendor-specific format. */
+ /* For Vendor Definition */
+ /* Pads structure to a multiple of 4 bytes */
+ /* Reads must not have side effects */
+};
+
struct virtio_pci_cap64 {
struct virtio_pci_cap cap;
__le32 offset_hi; /* Most sig 32 bits of offset */
diff --git a/riscv/include/asm/kvm.h b/riscv/include/asm/kvm.h
index 3482c9a..f06bc5e 100644
--- a/riscv/include/asm/kvm.h
+++ b/riscv/include/asm/kvm.h
@@ -179,6 +179,9 @@ enum KVM_RISCV_ISA_EXT_ID {
KVM_RISCV_ISA_EXT_SSNPM,
KVM_RISCV_ISA_EXT_SVADE,
KVM_RISCV_ISA_EXT_SVADU,
+ KVM_RISCV_ISA_EXT_SVVPTC,
+ KVM_RISCV_ISA_EXT_ZABHA,
+ KVM_RISCV_ISA_EXT_ZICCRSE,
KVM_RISCV_ISA_EXT_MAX,
};
@@ -198,6 +201,7 @@ enum KVM_RISCV_SBI_EXT_ID {
KVM_RISCV_SBI_EXT_VENDOR,
KVM_RISCV_SBI_EXT_DBCN,
KVM_RISCV_SBI_EXT_STA,
+ KVM_RISCV_SBI_EXT_SUSP,
KVM_RISCV_SBI_EXT_MAX,
};
@@ -211,9 +215,6 @@ struct kvm_riscv_sbi_sta {
#define KVM_RISCV_TIMER_STATE_OFF 0
#define KVM_RISCV_TIMER_STATE_ON 1
-#define KVM_REG_SIZE(id) \
- (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
-
/* If you need to interpret the index values, here is the key: */
#define KVM_REG_RISCV_TYPE_MASK 0x00000000FF000000
#define KVM_REG_RISCV_TYPE_SHIFT 24
diff --git a/x86/include/asm/kvm.h b/x86/include/asm/kvm.h
index 88585c1..9e75da9 100644
--- a/x86/include/asm/kvm.h
+++ b/x86/include/asm/kvm.h
@@ -925,5 +925,6 @@ struct kvm_hyperv_eventfd {
#define KVM_X86_SEV_VM 2
#define KVM_X86_SEV_ES_VM 3
#define KVM_X86_SNP_VM 4
+#define KVM_X86_TDX_VM 5
#endif /* _ASM_X86_KVM_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [kvmtool PATCH v3 02/10] riscv: Add Svvptc extension support
2025-04-26 11:03 [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
2025-04-26 11:03 ` [kvmtool PATCH v3 01/10] Sync-up headers with Linux-6.14 kernel Anup Patel
@ 2025-04-26 11:03 ` Anup Patel
2025-04-26 11:03 ` [kvmtool PATCH v3 03/10] riscv: Add Zabha " Anup Patel
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2025-04-26 11:03 UTC (permalink / raw)
To: Will Deacon, julien.thierry.kdev, maz
Cc: Paolo Bonzini, Atish Patra, Andrew Jones, Anup Patel, kvm,
kvm-riscv, Anup Patel
When the Svvptc extension is available expose it to the guest
via device tree so that guest can use it.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
---
riscv/fdt.c | 1 +
riscv/include/kvm/kvm-config-arch.h | 3 +++
2 files changed, 4 insertions(+)
diff --git a/riscv/fdt.c b/riscv/fdt.c
index 03113cc..c1e688d 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -27,6 +27,7 @@ struct isa_ext_info isa_info_arr[] = {
{"svinval", KVM_RISCV_ISA_EXT_SVINVAL},
{"svnapot", KVM_RISCV_ISA_EXT_SVNAPOT},
{"svpbmt", KVM_RISCV_ISA_EXT_SVPBMT},
+ {"svvptc", KVM_RISCV_ISA_EXT_SVVPTC},
{"zacas", KVM_RISCV_ISA_EXT_ZACAS},
{"zawrs", KVM_RISCV_ISA_EXT_ZAWRS},
{"zba", KVM_RISCV_ISA_EXT_ZBA},
diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h
index e56610b..ae01e14 100644
--- a/riscv/include/kvm/kvm-config-arch.h
+++ b/riscv/include/kvm/kvm-config-arch.h
@@ -58,6 +58,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-svvptc", \
+ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SVVPTC], \
+ "Disable Svvptc Extension"), \
OPT_BOOLEAN('\0', "disable-zacas", \
&(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZACAS], \
"Disable Zacas Extension"), \
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [kvmtool PATCH v3 03/10] riscv: Add Zabha extension support
2025-04-26 11:03 [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
2025-04-26 11:03 ` [kvmtool PATCH v3 01/10] Sync-up headers with Linux-6.14 kernel Anup Patel
2025-04-26 11:03 ` [kvmtool PATCH v3 02/10] riscv: Add Svvptc extension support Anup Patel
@ 2025-04-26 11:03 ` Anup Patel
2025-04-26 11:03 ` [kvmtool PATCH v3 04/10] riscv: Add Ziccrse " Anup Patel
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2025-04-26 11:03 UTC (permalink / raw)
To: Will Deacon, julien.thierry.kdev, maz
Cc: Paolo Bonzini, Atish Patra, Andrew Jones, Anup Patel, kvm,
kvm-riscv, Anup Patel
When the Zabha extension is available expose it to the guest
via device tree so that guest can use it.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
---
riscv/fdt.c | 1 +
riscv/include/kvm/kvm-config-arch.h | 3 +++
2 files changed, 4 insertions(+)
diff --git a/riscv/fdt.c b/riscv/fdt.c
index c1e688d..ddd0b28 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -28,6 +28,7 @@ struct isa_ext_info isa_info_arr[] = {
{"svnapot", KVM_RISCV_ISA_EXT_SVNAPOT},
{"svpbmt", KVM_RISCV_ISA_EXT_SVPBMT},
{"svvptc", KVM_RISCV_ISA_EXT_SVVPTC},
+ {"zabha", KVM_RISCV_ISA_EXT_ZABHA},
{"zacas", KVM_RISCV_ISA_EXT_ZACAS},
{"zawrs", KVM_RISCV_ISA_EXT_ZAWRS},
{"zba", KVM_RISCV_ISA_EXT_ZBA},
diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h
index ae01e14..d86158d 100644
--- a/riscv/include/kvm/kvm-config-arch.h
+++ b/riscv/include/kvm/kvm-config-arch.h
@@ -61,6 +61,9 @@ struct kvm_config_arch {
OPT_BOOLEAN('\0', "disable-svvptc", \
&(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SVVPTC], \
"Disable Svvptc Extension"), \
+ OPT_BOOLEAN('\0', "disable-zabha", \
+ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZABHA], \
+ "Disable Zabha Extension"), \
OPT_BOOLEAN('\0', "disable-zacas", \
&(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZACAS], \
"Disable Zacas Extension"), \
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [kvmtool PATCH v3 04/10] riscv: Add Ziccrse extension support
2025-04-26 11:03 [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
` (2 preceding siblings ...)
2025-04-26 11:03 ` [kvmtool PATCH v3 03/10] riscv: Add Zabha " Anup Patel
@ 2025-04-26 11:03 ` Anup Patel
2025-04-26 11:03 ` [kvmtool PATCH v3 05/10] riscv: Add SBI system suspend support Anup Patel
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2025-04-26 11:03 UTC (permalink / raw)
To: Will Deacon, julien.thierry.kdev, maz
Cc: Paolo Bonzini, Atish Patra, Andrew Jones, Anup Patel, kvm,
kvm-riscv, Anup Patel
When the Ziccrse extension is available expose it to the guest
via device tree so that guest can use it.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
---
riscv/fdt.c | 1 +
riscv/include/kvm/kvm-config-arch.h | 3 +++
2 files changed, 4 insertions(+)
diff --git a/riscv/fdt.c b/riscv/fdt.c
index ddd0b28..3ee20a9 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -48,6 +48,7 @@ struct isa_ext_info isa_info_arr[] = {
{"zfhmin", KVM_RISCV_ISA_EXT_ZFHMIN},
{"zicbom", KVM_RISCV_ISA_EXT_ZICBOM},
{"zicboz", KVM_RISCV_ISA_EXT_ZICBOZ},
+ {"ziccrse", KVM_RISCV_ISA_EXT_ZICCRSE},
{"zicntr", KVM_RISCV_ISA_EXT_ZICNTR},
{"zicond", KVM_RISCV_ISA_EXT_ZICOND},
{"zicsr", KVM_RISCV_ISA_EXT_ZICSR},
diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h
index d86158d..5badb74 100644
--- a/riscv/include/kvm/kvm-config-arch.h
+++ b/riscv/include/kvm/kvm-config-arch.h
@@ -121,6 +121,9 @@ struct kvm_config_arch {
OPT_BOOLEAN('\0', "disable-zicboz", \
&(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZICBOZ], \
"Disable Zicboz Extension"), \
+ OPT_BOOLEAN('\0', "disable-ziccrse", \
+ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZICCRSE], \
+ "Disable Ziccrse Extension"), \
OPT_BOOLEAN('\0', "disable-zicntr", \
&(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZICNTR], \
"Disable Zicntr Extension"), \
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [kvmtool PATCH v3 05/10] riscv: Add SBI system suspend support
2025-04-26 11:03 [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
` (3 preceding siblings ...)
2025-04-26 11:03 ` [kvmtool PATCH v3 04/10] riscv: Add Ziccrse " Anup Patel
@ 2025-04-26 11:03 ` Anup Patel
2025-04-26 11:03 ` [kvmtool PATCH v3 06/10] riscv: Make system suspend time configurable Anup Patel
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2025-04-26 11:03 UTC (permalink / raw)
To: Will Deacon, julien.thierry.kdev, maz
Cc: Paolo Bonzini, Atish Patra, Andrew Jones, Anup Patel, kvm,
kvm-riscv, Anup Patel
From: Andrew Jones <ajones@ventanamicro.com>
Provide a handler for SBI system suspend requests forwarded to the
VMM by KVM and enable system suspend by default. This is just for
testing purposes, so the handler only sleeps 5 seconds before
resuming the guest. Resuming a system suspend only requires running
the system suspend invoking hart again, everything else is handled by
KVM.
Note, resuming after a suspend doesn't work with 9p used for the
guest's rootfs. Testing with a disk works though, e.g.
lkvm-static run --nodefaults -m 256 -c 2 -d rootfs.ext2 -k Image \
-p 'console=ttyS0 rootwait root=/dev/vda ro no_console_suspend'
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
riscv/include/kvm/kvm-config-arch.h | 3 +++
riscv/include/kvm/sbi.h | 9 ++++++++
riscv/kvm-cpu.c | 36 +++++++++++++++++++++++++++++
3 files changed, 48 insertions(+)
diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h
index 5badb74..0553004 100644
--- a/riscv/include/kvm/kvm-config-arch.h
+++ b/riscv/include/kvm/kvm-config-arch.h
@@ -238,6 +238,9 @@ struct kvm_config_arch {
OPT_BOOLEAN('\0', "disable-sbi-dbcn", \
&(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_DBCN], \
"Disable SBI DBCN Extension"), \
+ OPT_BOOLEAN('\0', "disable-sbi-susp", \
+ &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_SUSP], \
+ "Disable SBI SUSP Extension"), \
OPT_BOOLEAN('\0', "disable-sbi-sta", \
&(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_STA], \
"Disable SBI STA Extension"),
diff --git a/riscv/include/kvm/sbi.h b/riscv/include/kvm/sbi.h
index a0f2c70..10bbe1b 100644
--- a/riscv/include/kvm/sbi.h
+++ b/riscv/include/kvm/sbi.h
@@ -21,6 +21,7 @@ enum sbi_ext_id {
SBI_EXT_0_1_SHUTDOWN = 0x8,
SBI_EXT_BASE = 0x10,
SBI_EXT_DBCN = 0x4442434E,
+ SBI_EXT_SUSP = 0x53555350,
};
enum sbi_ext_base_fid {
@@ -39,6 +40,14 @@ enum sbi_ext_dbcn_fid {
SBI_EXT_DBCN_CONSOLE_WRITE_BYTE = 2,
};
+enum sbi_ext_susp_fid {
+ SBI_EXT_SUSP_SYSTEM_SUSPEND = 0,
+};
+
+enum sbi_ext_susp_sleep_type {
+ SBI_SUSP_SLEEP_TYPE_SUSPEND_TO_RAM = 0,
+};
+
#define SBI_SPEC_VERSION_DEFAULT 0x1
#define SBI_SPEC_VERSION_MAJOR_OFFSET 24
#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
diff --git a/riscv/kvm-cpu.c b/riscv/kvm-cpu.c
index 0c171da..ad68b58 100644
--- a/riscv/kvm-cpu.c
+++ b/riscv/kvm-cpu.c
@@ -1,3 +1,5 @@
+#include <unistd.h>
+
#include "kvm/csr.h"
#include "kvm/kvm-cpu.h"
#include "kvm/kvm.h"
@@ -117,6 +119,17 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)
KVM_RISCV_SBI_EXT_DBCN);
}
+ /* Force enable SBI system suspend if not disabled from command line */
+ if (!kvm->cfg.arch.sbi_ext_disabled[KVM_RISCV_SBI_EXT_SUSP]) {
+ id = 1;
+ reg.id = RISCV_SBI_EXT_REG(KVM_REG_RISCV_SBI_SINGLE,
+ KVM_RISCV_SBI_EXT_SUSP);
+ reg.addr = (unsigned long)&id;
+ if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0)
+ pr_warning("KVM_SET_ONE_REG failed (sbi_ext %d)",
+ KVM_RISCV_SBI_EXT_SUSP);
+ }
+
/* Populate the vcpu structure. */
vcpu->kvm = kvm;
vcpu->cpu_id = cpu_id;
@@ -203,6 +216,29 @@ static bool kvm_cpu_riscv_sbi(struct kvm_cpu *vcpu)
break;
}
break;
+ case SBI_EXT_SUSP:
+ {
+ unsigned long susp_type, ret = SBI_SUCCESS;
+
+ switch (vcpu->kvm_run->riscv_sbi.function_id) {
+ case SBI_EXT_SUSP_SYSTEM_SUSPEND:
+ susp_type = vcpu->kvm_run->riscv_sbi.args[0];
+ if (susp_type != SBI_SUSP_SLEEP_TYPE_SUSPEND_TO_RAM) {
+ ret = SBI_ERR_INVALID_PARAM;
+ break;
+ }
+
+ sleep(5);
+
+ break;
+ default:
+ ret = SBI_ERR_NOT_SUPPORTED;
+ break;
+ }
+
+ vcpu->kvm_run->riscv_sbi.ret[0] = ret;
+ break;
+ }
default:
dprintf(dfd, "Unhandled SBI call\n");
dprintf(dfd, "extension_id=0x%lx function_id=0x%lx\n",
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [kvmtool PATCH v3 06/10] riscv: Make system suspend time configurable
2025-04-26 11:03 [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
` (4 preceding siblings ...)
2025-04-26 11:03 ` [kvmtool PATCH v3 05/10] riscv: Add SBI system suspend support Anup Patel
@ 2025-04-26 11:03 ` Anup Patel
2025-04-26 11:03 ` [kvmtool PATCH v3 07/10] riscv: Fix no params with nodefault segfault Anup Patel
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2025-04-26 11:03 UTC (permalink / raw)
To: Will Deacon, julien.thierry.kdev, maz
Cc: Paolo Bonzini, Atish Patra, Andrew Jones, Anup Patel, kvm,
kvm-riscv, Anup Patel
From: Andrew Jones <ajones@ventanamicro.com>
If the default of 5 seconds for a system suspend test is too long or
too short, then feel free to change it.
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
riscv/include/kvm/kvm-config-arch.h | 4 ++++
riscv/kvm-cpu.c | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h
index 0553004..7e54d8a 100644
--- a/riscv/include/kvm/kvm-config-arch.h
+++ b/riscv/include/kvm/kvm-config-arch.h
@@ -5,6 +5,7 @@
struct kvm_config_arch {
const char *dump_dtb_filename;
+ u64 suspend_seconds;
u64 custom_mvendorid;
u64 custom_marchid;
u64 custom_mimpid;
@@ -16,6 +17,9 @@ 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', "suspend-seconds", \
+ &(cfg)->suspend_seconds, \
+ "Number of seconds to suspend for system suspend (default is 5)"), \
OPT_U64('\0', "custom-mvendorid", \
&(cfg)->custom_mvendorid, \
"Show custom mvendorid to Guest VCPU"), \
diff --git a/riscv/kvm-cpu.c b/riscv/kvm-cpu.c
index ad68b58..7a86d71 100644
--- a/riscv/kvm-cpu.c
+++ b/riscv/kvm-cpu.c
@@ -228,7 +228,7 @@ static bool kvm_cpu_riscv_sbi(struct kvm_cpu *vcpu)
break;
}
- sleep(5);
+ sleep(vcpu->kvm->cfg.arch.suspend_seconds ? : 5);
break;
default:
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [kvmtool PATCH v3 07/10] riscv: Fix no params with nodefault segfault
2025-04-26 11:03 [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
` (5 preceding siblings ...)
2025-04-26 11:03 ` [kvmtool PATCH v3 06/10] riscv: Make system suspend time configurable Anup Patel
@ 2025-04-26 11:03 ` Anup Patel
2025-04-26 11:03 ` [kvmtool PATCH v3 08/10] riscv: Include single-letter extensions in isa_info_arr[] Anup Patel
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2025-04-26 11:03 UTC (permalink / raw)
To: Will Deacon, julien.thierry.kdev, maz
Cc: Paolo Bonzini, Atish Patra, Andrew Jones, Anup Patel, kvm,
kvm-riscv, Alexandru Elisei, Anup Patel
From: Andrew Jones <ajones@ventanamicro.com>
Fix segfault received when using --nodefault without --params.
Fixes: 7c9aac003925 ("riscv: Generate FDT at runtime for Guest/VM")
Suggested-by: Alexandru Elisei <alexandru.elisei@arm.com>
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Alexandru Elisei <alexandru.elisei@arm.com>
Link: https://lore.kernel.org/r/20250123151339.185908-2-ajones@ventanamicro.com
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
riscv/fdt.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/riscv/fdt.c b/riscv/fdt.c
index 3ee20a9..251821e 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -263,9 +263,10 @@ static int setup_fdt(struct kvm *kvm)
if (kvm->cfg.kernel_cmdline)
_FDT(fdt_property_string(fdt, "bootargs",
kvm->cfg.kernel_cmdline));
- } else
+ } else if (kvm->cfg.real_cmdline) {
_FDT(fdt_property_string(fdt, "bootargs",
kvm->cfg.real_cmdline));
+ }
_FDT(fdt_property_string(fdt, "stdout-path", "serial0"));
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [kvmtool PATCH v3 08/10] riscv: Include single-letter extensions in isa_info_arr[]
2025-04-26 11:03 [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
` (6 preceding siblings ...)
2025-04-26 11:03 ` [kvmtool PATCH v3 07/10] riscv: Fix no params with nodefault segfault Anup Patel
@ 2025-04-26 11:03 ` Anup Patel
2025-04-26 11:03 ` [kvmtool PATCH v3 09/10] riscv: Add cpu-type command-line option Anup Patel
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2025-04-26 11:03 UTC (permalink / raw)
To: Will Deacon, julien.thierry.kdev, maz
Cc: Paolo Bonzini, Atish Patra, Andrew Jones, Anup Patel, kvm,
kvm-riscv, Anup Patel
Currently, the isa_info_arr[] only include multi-letter extensions but
the KVM ONE_REG interface covers both single-letter and multi-letter
extensions so extend isa_info_arr[] to include single-letter extensions.
This also allows combining two loops in the generate_cpu_nodes()
function into one loop.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
---
riscv/fdt.c | 148 +++++++++++++++++++++++++++-------------------------
1 file changed, 76 insertions(+), 72 deletions(-)
diff --git a/riscv/fdt.c b/riscv/fdt.c
index 251821e..c741fd8 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -12,71 +12,81 @@
struct isa_ext_info {
const char *name;
unsigned long ext_id;
+ bool single_letter;
};
struct isa_ext_info isa_info_arr[] = {
- /* sorted alphabetically */
- {"smnpm", KVM_RISCV_ISA_EXT_SMNPM},
- {"smstateen", KVM_RISCV_ISA_EXT_SMSTATEEN},
- {"ssaia", KVM_RISCV_ISA_EXT_SSAIA},
- {"sscofpmf", KVM_RISCV_ISA_EXT_SSCOFPMF},
- {"ssnpm", KVM_RISCV_ISA_EXT_SSNPM},
- {"sstc", KVM_RISCV_ISA_EXT_SSTC},
- {"svade", KVM_RISCV_ISA_EXT_SVADE},
- {"svadu", KVM_RISCV_ISA_EXT_SVADU},
- {"svinval", KVM_RISCV_ISA_EXT_SVINVAL},
- {"svnapot", KVM_RISCV_ISA_EXT_SVNAPOT},
- {"svpbmt", KVM_RISCV_ISA_EXT_SVPBMT},
- {"svvptc", KVM_RISCV_ISA_EXT_SVVPTC},
- {"zabha", KVM_RISCV_ISA_EXT_ZABHA},
- {"zacas", KVM_RISCV_ISA_EXT_ZACAS},
- {"zawrs", KVM_RISCV_ISA_EXT_ZAWRS},
- {"zba", KVM_RISCV_ISA_EXT_ZBA},
- {"zbb", KVM_RISCV_ISA_EXT_ZBB},
- {"zbc", KVM_RISCV_ISA_EXT_ZBC},
- {"zbkb", KVM_RISCV_ISA_EXT_ZBKB},
- {"zbkc", KVM_RISCV_ISA_EXT_ZBKC},
- {"zbkx", KVM_RISCV_ISA_EXT_ZBKX},
- {"zbs", KVM_RISCV_ISA_EXT_ZBS},
- {"zca", KVM_RISCV_ISA_EXT_ZCA},
- {"zcb", KVM_RISCV_ISA_EXT_ZCB},
- {"zcd", KVM_RISCV_ISA_EXT_ZCD},
- {"zcf", KVM_RISCV_ISA_EXT_ZCF},
- {"zcmop", KVM_RISCV_ISA_EXT_ZCMOP},
- {"zfa", KVM_RISCV_ISA_EXT_ZFA},
- {"zfh", KVM_RISCV_ISA_EXT_ZFH},
- {"zfhmin", KVM_RISCV_ISA_EXT_ZFHMIN},
- {"zicbom", KVM_RISCV_ISA_EXT_ZICBOM},
- {"zicboz", KVM_RISCV_ISA_EXT_ZICBOZ},
- {"ziccrse", KVM_RISCV_ISA_EXT_ZICCRSE},
- {"zicntr", KVM_RISCV_ISA_EXT_ZICNTR},
- {"zicond", KVM_RISCV_ISA_EXT_ZICOND},
- {"zicsr", KVM_RISCV_ISA_EXT_ZICSR},
- {"zifencei", KVM_RISCV_ISA_EXT_ZIFENCEI},
- {"zihintntl", KVM_RISCV_ISA_EXT_ZIHINTNTL},
- {"zihintpause", KVM_RISCV_ISA_EXT_ZIHINTPAUSE},
- {"zihpm", KVM_RISCV_ISA_EXT_ZIHPM},
- {"zimop", KVM_RISCV_ISA_EXT_ZIMOP},
- {"zknd", KVM_RISCV_ISA_EXT_ZKND},
- {"zkne", KVM_RISCV_ISA_EXT_ZKNE},
- {"zknh", KVM_RISCV_ISA_EXT_ZKNH},
- {"zkr", KVM_RISCV_ISA_EXT_ZKR},
- {"zksed", KVM_RISCV_ISA_EXT_ZKSED},
- {"zksh", KVM_RISCV_ISA_EXT_ZKSH},
- {"zkt", KVM_RISCV_ISA_EXT_ZKT},
- {"ztso", KVM_RISCV_ISA_EXT_ZTSO},
- {"zvbb", KVM_RISCV_ISA_EXT_ZVBB},
- {"zvbc", KVM_RISCV_ISA_EXT_ZVBC},
- {"zvfh", KVM_RISCV_ISA_EXT_ZVFH},
- {"zvfhmin", KVM_RISCV_ISA_EXT_ZVFHMIN},
- {"zvkb", KVM_RISCV_ISA_EXT_ZVKB},
- {"zvkg", KVM_RISCV_ISA_EXT_ZVKG},
- {"zvkned", KVM_RISCV_ISA_EXT_ZVKNED},
- {"zvknha", KVM_RISCV_ISA_EXT_ZVKNHA},
- {"zvknhb", KVM_RISCV_ISA_EXT_ZVKNHB},
- {"zvksed", KVM_RISCV_ISA_EXT_ZVKSED},
- {"zvksh", KVM_RISCV_ISA_EXT_ZVKSH},
- {"zvkt", KVM_RISCV_ISA_EXT_ZVKT},
+ /* single-letter ordered canonically as "IEMAFDQCLBJTPVNSUHKORWXYZG" */
+ {"i", KVM_RISCV_ISA_EXT_I, .single_letter = true},
+ {"m", KVM_RISCV_ISA_EXT_M, .single_letter = true},
+ {"a", KVM_RISCV_ISA_EXT_A, .single_letter = true},
+ {"f", KVM_RISCV_ISA_EXT_F, .single_letter = true},
+ {"d", KVM_RISCV_ISA_EXT_D, .single_letter = true},
+ {"c", KVM_RISCV_ISA_EXT_C, .single_letter = true},
+ {"v", KVM_RISCV_ISA_EXT_V, .single_letter = true},
+ {"h", KVM_RISCV_ISA_EXT_H, .single_letter = true},
+ /* multi-letter sorted alphabetically */
+ {"smnpm", KVM_RISCV_ISA_EXT_SMNPM},
+ {"smstateen", KVM_RISCV_ISA_EXT_SMSTATEEN},
+ {"ssaia", KVM_RISCV_ISA_EXT_SSAIA},
+ {"sscofpmf", KVM_RISCV_ISA_EXT_SSCOFPMF},
+ {"ssnpm", KVM_RISCV_ISA_EXT_SSNPM},
+ {"sstc", KVM_RISCV_ISA_EXT_SSTC},
+ {"svade", KVM_RISCV_ISA_EXT_SVADE},
+ {"svadu", KVM_RISCV_ISA_EXT_SVADU},
+ {"svinval", KVM_RISCV_ISA_EXT_SVINVAL},
+ {"svnapot", KVM_RISCV_ISA_EXT_SVNAPOT},
+ {"svpbmt", KVM_RISCV_ISA_EXT_SVPBMT},
+ {"svvptc", KVM_RISCV_ISA_EXT_SVVPTC},
+ {"zabha", KVM_RISCV_ISA_EXT_ZABHA},
+ {"zacas", KVM_RISCV_ISA_EXT_ZACAS},
+ {"zawrs", KVM_RISCV_ISA_EXT_ZAWRS},
+ {"zba", KVM_RISCV_ISA_EXT_ZBA},
+ {"zbb", KVM_RISCV_ISA_EXT_ZBB},
+ {"zbc", KVM_RISCV_ISA_EXT_ZBC},
+ {"zbkb", KVM_RISCV_ISA_EXT_ZBKB},
+ {"zbkc", KVM_RISCV_ISA_EXT_ZBKC},
+ {"zbkx", KVM_RISCV_ISA_EXT_ZBKX},
+ {"zbs", KVM_RISCV_ISA_EXT_ZBS},
+ {"zca", KVM_RISCV_ISA_EXT_ZCA},
+ {"zcb", KVM_RISCV_ISA_EXT_ZCB},
+ {"zcd", KVM_RISCV_ISA_EXT_ZCD},
+ {"zcf", KVM_RISCV_ISA_EXT_ZCF},
+ {"zcmop", KVM_RISCV_ISA_EXT_ZCMOP},
+ {"zfa", KVM_RISCV_ISA_EXT_ZFA},
+ {"zfh", KVM_RISCV_ISA_EXT_ZFH},
+ {"zfhmin", KVM_RISCV_ISA_EXT_ZFHMIN},
+ {"zicbom", KVM_RISCV_ISA_EXT_ZICBOM},
+ {"zicboz", KVM_RISCV_ISA_EXT_ZICBOZ},
+ {"ziccrse", KVM_RISCV_ISA_EXT_ZICCRSE},
+ {"zicntr", KVM_RISCV_ISA_EXT_ZICNTR},
+ {"zicond", KVM_RISCV_ISA_EXT_ZICOND},
+ {"zicsr", KVM_RISCV_ISA_EXT_ZICSR},
+ {"zifencei", KVM_RISCV_ISA_EXT_ZIFENCEI},
+ {"zihintntl", KVM_RISCV_ISA_EXT_ZIHINTNTL},
+ {"zihintpause", KVM_RISCV_ISA_EXT_ZIHINTPAUSE},
+ {"zihpm", KVM_RISCV_ISA_EXT_ZIHPM},
+ {"zimop", KVM_RISCV_ISA_EXT_ZIMOP},
+ {"zknd", KVM_RISCV_ISA_EXT_ZKND},
+ {"zkne", KVM_RISCV_ISA_EXT_ZKNE},
+ {"zknh", KVM_RISCV_ISA_EXT_ZKNH},
+ {"zkr", KVM_RISCV_ISA_EXT_ZKR},
+ {"zksed", KVM_RISCV_ISA_EXT_ZKSED},
+ {"zksh", KVM_RISCV_ISA_EXT_ZKSH},
+ {"zkt", KVM_RISCV_ISA_EXT_ZKT},
+ {"ztso", KVM_RISCV_ISA_EXT_ZTSO},
+ {"zvbb", KVM_RISCV_ISA_EXT_ZVBB},
+ {"zvbc", KVM_RISCV_ISA_EXT_ZVBC},
+ {"zvfh", KVM_RISCV_ISA_EXT_ZVFH},
+ {"zvfhmin", KVM_RISCV_ISA_EXT_ZVFHMIN},
+ {"zvkb", KVM_RISCV_ISA_EXT_ZVKB},
+ {"zvkg", KVM_RISCV_ISA_EXT_ZVKG},
+ {"zvkned", KVM_RISCV_ISA_EXT_ZVKNED},
+ {"zvknha", KVM_RISCV_ISA_EXT_ZVKNHA},
+ {"zvknhb", KVM_RISCV_ISA_EXT_ZVKNHB},
+ {"zvksed", KVM_RISCV_ISA_EXT_ZVKSED},
+ {"zvksh", KVM_RISCV_ISA_EXT_ZVKSH},
+ {"zvkt", KVM_RISCV_ISA_EXT_ZVKT},
};
static void dump_fdt(const char *dtb_file, void *fdt)
@@ -98,10 +108,8 @@ static void dump_fdt(const char *dtb_file, void *fdt)
#define CPU_NAME_MAX_LEN 15
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, cboz_blksz = 0, satp_mode = 0;
+ int i, cpu, pos, arr_sz = ARRAY_SIZE(isa_info_arr);
_FDT(fdt_begin_node(fdt, "cpus"));
_FDT(fdt_property_cell(fdt, "#address-cells", 0x1));
@@ -121,12 +129,6 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
snprintf(cpu_isa, CPU_ISA_MAX_LEN, "rv%ld", vcpu->riscv_xlen);
pos = strlen(cpu_isa);
- valid_isa_len = strlen(valid_isa_order);
- for (i = 0; i < valid_isa_len; i++) {
- index = valid_isa_order[i] - 'A';
- if (vcpu->riscv_isa & (1 << (index)))
- cpu_isa[pos++] = 'a' + index;
- }
for (i = 0; i < arr_sz; i++) {
reg.id = RISCV_ISA_EXT_REG(isa_info_arr[i].ext_id);
@@ -164,7 +166,9 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
isa_info_arr[i].name);
break;
}
- pos += snprintf(cpu_isa + pos, CPU_ISA_MAX_LEN - pos, "_%s",
+
+ pos += snprintf(cpu_isa + pos, CPU_ISA_MAX_LEN - pos, "%s%s",
+ isa_info_arr[i].single_letter ? "" : "_",
isa_info_arr[i].name);
}
cpu_isa[pos] = '\0';
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [kvmtool PATCH v3 09/10] riscv: Add cpu-type command-line option
2025-04-26 11:03 [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
` (7 preceding siblings ...)
2025-04-26 11:03 ` [kvmtool PATCH v3 08/10] riscv: Include single-letter extensions in isa_info_arr[] Anup Patel
@ 2025-04-26 11:03 ` Anup Patel
2025-04-26 11:03 ` [kvmtool PATCH v3 10/10] riscv: Allow including extensions in the min CPU type using command-line Anup Patel
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2025-04-26 11:03 UTC (permalink / raw)
To: Will Deacon, julien.thierry.kdev, maz
Cc: Paolo Bonzini, Atish Patra, Andrew Jones, Anup Patel, kvm,
kvm-riscv, Anup Patel
Currently, the KVMTOOL always creates a VM with all available
ISA extensions virtualized by the in-kernel KVM module.
For better flexibility, add cpu-type command-line option using
which users can select one of the available CPU types for VM.
There are two CPU types supported at the moment namely "min"
and "max". The "min" CPU type implies VCPU with rv[64|32]imafdc
ISA whereas the "max" CPU type implies VCPU with all available
ISA extensions.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
---
riscv/aia.c | 2 +-
riscv/fdt.c | 68 +++++++++++++++++++++++++----
riscv/include/kvm/kvm-arch.h | 2 +
riscv/include/kvm/kvm-config-arch.h | 10 +++++
4 files changed, 73 insertions(+), 9 deletions(-)
diff --git a/riscv/aia.c b/riscv/aia.c
index 21d9704..cad53d4 100644
--- a/riscv/aia.c
+++ b/riscv/aia.c
@@ -209,7 +209,7 @@ void aia__create(struct kvm *kvm)
.flags = 0,
};
- if (kvm->cfg.arch.ext_disabled[KVM_RISCV_ISA_EXT_SSAIA])
+ if (riscv__isa_extension_disabled(kvm, KVM_RISCV_ISA_EXT_SSAIA))
return;
err = ioctl(kvm->vm_fd, KVM_CREATE_DEVICE, &aia_device);
diff --git a/riscv/fdt.c b/riscv/fdt.c
index c741fd8..abb6557 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -13,16 +13,17 @@ struct isa_ext_info {
const char *name;
unsigned long ext_id;
bool single_letter;
+ bool min_enabled;
};
struct isa_ext_info isa_info_arr[] = {
/* single-letter ordered canonically as "IEMAFDQCLBJTPVNSUHKORWXYZG" */
- {"i", KVM_RISCV_ISA_EXT_I, .single_letter = true},
- {"m", KVM_RISCV_ISA_EXT_M, .single_letter = true},
- {"a", KVM_RISCV_ISA_EXT_A, .single_letter = true},
- {"f", KVM_RISCV_ISA_EXT_F, .single_letter = true},
- {"d", KVM_RISCV_ISA_EXT_D, .single_letter = true},
- {"c", KVM_RISCV_ISA_EXT_C, .single_letter = true},
+ {"i", KVM_RISCV_ISA_EXT_I, .single_letter = true, .min_enabled = true},
+ {"m", KVM_RISCV_ISA_EXT_M, .single_letter = true, .min_enabled = true},
+ {"a", KVM_RISCV_ISA_EXT_A, .single_letter = true, .min_enabled = true},
+ {"f", KVM_RISCV_ISA_EXT_F, .single_letter = true, .min_enabled = true},
+ {"d", KVM_RISCV_ISA_EXT_D, .single_letter = true, .min_enabled = true},
+ {"c", KVM_RISCV_ISA_EXT_C, .single_letter = true, .min_enabled = true},
{"v", KVM_RISCV_ISA_EXT_V, .single_letter = true},
{"h", KVM_RISCV_ISA_EXT_H, .single_letter = true},
/* multi-letter sorted alphabetically */
@@ -89,6 +90,56 @@ struct isa_ext_info isa_info_arr[] = {
{"zvkt", KVM_RISCV_ISA_EXT_ZVKT},
};
+static bool __isa_ext_disabled(struct kvm *kvm, struct isa_ext_info *info)
+{
+ if (kvm->cfg.arch.cpu_type == RISCV__CPU_TYPE_MIN &&
+ !info->min_enabled)
+ return true;
+
+ return kvm->cfg.arch.ext_disabled[info->ext_id];
+}
+
+static bool __isa_ext_warn_disable_failure(struct kvm *kvm, struct isa_ext_info *info)
+{
+ if (kvm->cfg.arch.cpu_type == RISCV__CPU_TYPE_MIN &&
+ !info->min_enabled)
+ return false;
+
+ return true;
+}
+
+bool riscv__isa_extension_disabled(struct kvm *kvm, unsigned long isa_ext_id)
+{
+ struct isa_ext_info *info = NULL;
+ unsigned long i;
+
+ for (i = 0; i < ARRAY_SIZE(isa_info_arr); i++) {
+ if (isa_info_arr[i].ext_id == isa_ext_id) {
+ info = &isa_info_arr[i];
+ break;
+ }
+ }
+ if (!info)
+ return true;
+
+ return __isa_ext_disabled(kvm, info);
+}
+
+int riscv__cpu_type_parser(const struct option *opt, const char *arg, int unset)
+{
+ struct kvm *kvm = opt->ptr;
+
+ if ((strncmp(arg, "min", 3) && strncmp(arg, "max", 3)) || strlen(arg) != 3)
+ die("Invalid CPU type %s\n", arg);
+
+ if (!strcmp(arg, "max"))
+ kvm->cfg.arch.cpu_type = RISCV__CPU_TYPE_MAX;
+ else
+ kvm->cfg.arch.cpu_type = RISCV__CPU_TYPE_MIN;
+
+ return 0;
+}
+
static void dump_fdt(const char *dtb_file, void *fdt)
{
int count, fd;
@@ -139,9 +190,10 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
/* This extension is not available in hardware */
continue;
- if (kvm->cfg.arch.ext_disabled[isa_info_arr[i].ext_id]) {
+ if (__isa_ext_disabled(kvm, &isa_info_arr[i])) {
isa_ext_out = 0;
- if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0)
+ if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0 &&
+ __isa_ext_warn_disable_failure(kvm, &isa_info_arr[i]))
pr_warning("Failed to disable %s ISA exension\n",
isa_info_arr[i].name);
continue;
diff --git a/riscv/include/kvm/kvm-arch.h b/riscv/include/kvm/kvm-arch.h
index f0f469f..1bb2d32 100644
--- a/riscv/include/kvm/kvm-arch.h
+++ b/riscv/include/kvm/kvm-arch.h
@@ -90,6 +90,8 @@ enum irqchip_type {
IRQCHIP_AIA
};
+bool riscv__isa_extension_disabled(struct kvm *kvm, unsigned long ext_id);
+
extern enum irqchip_type riscv_irqchip;
extern bool riscv_irqchip_inkernel;
extern void (*riscv_irqchip_trigger)(struct kvm *kvm, int irq,
diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h
index 7e54d8a..6d9a29a 100644
--- a/riscv/include/kvm/kvm-config-arch.h
+++ b/riscv/include/kvm/kvm-config-arch.h
@@ -3,7 +3,13 @@
#include "kvm/parse-options.h"
+enum riscv__cpu_type {
+ RISCV__CPU_TYPE_MAX = 0,
+ RISCV__CPU_TYPE_MIN
+};
+
struct kvm_config_arch {
+ enum riscv__cpu_type cpu_type;
const char *dump_dtb_filename;
u64 suspend_seconds;
u64 custom_mvendorid;
@@ -13,8 +19,12 @@ struct kvm_config_arch {
bool sbi_ext_disabled[KVM_RISCV_SBI_EXT_MAX];
};
+int riscv__cpu_type_parser(const struct option *opt, const char *arg, int unset);
+
#define OPT_ARCH_RUN(pfx, cfg) \
pfx, \
+ OPT_CALLBACK('\0', "cpu-type", NULL, "min or max", \
+ "Choose the cpu type (default is max).", riscv__cpu_type_parser, kvm),\
OPT_STRING('\0', "dump-dtb", &(cfg)->dump_dtb_filename, \
".dtb file", "Dump generated .dtb to specified file"),\
OPT_U64('\0', "suspend-seconds", \
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [kvmtool PATCH v3 10/10] riscv: Allow including extensions in the min CPU type using command-line
2025-04-26 11:03 [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
` (8 preceding siblings ...)
2025-04-26 11:03 ` [kvmtool PATCH v3 09/10] riscv: Add cpu-type command-line option Anup Patel
@ 2025-04-26 11:03 ` Anup Patel
2025-05-01 13:13 ` [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
2025-05-16 13:54 ` Will Deacon
11 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2025-04-26 11:03 UTC (permalink / raw)
To: Will Deacon, julien.thierry.kdev, maz
Cc: Paolo Bonzini, Atish Patra, Andrew Jones, Anup Patel, kvm,
kvm-riscv, Anup Patel
It is useful to allow including extensions in the min CPU type on need
basis via command-line. To achieve this, parse extension names as comma
separated values appended to the "min" CPU type using command-line.
For example, to include Sstc and Ssaia in the min CPU type use
"--cpu-type min,sstc,ssaia" command-line option.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
---
riscv/fdt.c | 42 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 39 insertions(+), 3 deletions(-)
diff --git a/riscv/fdt.c b/riscv/fdt.c
index abb6557..eba9387 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -108,6 +108,20 @@ static bool __isa_ext_warn_disable_failure(struct kvm *kvm, struct isa_ext_info
return true;
}
+static void __min_enable(const char *ext, size_t ext_len)
+{
+ struct isa_ext_info *info;
+ unsigned long i;
+
+ for (i = 0; i < ARRAY_SIZE(isa_info_arr); i++) {
+ info = &isa_info_arr[i];
+ if (strlen(info->name) != ext_len)
+ continue;
+ if (!strncmp(ext, info->name, ext_len))
+ info->min_enabled = true;
+ }
+}
+
bool riscv__isa_extension_disabled(struct kvm *kvm, unsigned long isa_ext_id)
{
struct isa_ext_info *info = NULL;
@@ -128,15 +142,37 @@ bool riscv__isa_extension_disabled(struct kvm *kvm, unsigned long isa_ext_id)
int riscv__cpu_type_parser(const struct option *opt, const char *arg, int unset)
{
struct kvm *kvm = opt->ptr;
+ const char *str, *nstr;
+ int len;
- if ((strncmp(arg, "min", 3) && strncmp(arg, "max", 3)) || strlen(arg) != 3)
+ if (strncmp(arg, "min", 3) && (strncmp(arg, "max", 3) || strlen(arg) != 3))
die("Invalid CPU type %s\n", arg);
- if (!strcmp(arg, "max"))
+ if (!strcmp(arg, "max")) {
kvm->cfg.arch.cpu_type = RISCV__CPU_TYPE_MAX;
- else
+ } else {
kvm->cfg.arch.cpu_type = RISCV__CPU_TYPE_MIN;
+ str = arg;
+ str += 3;
+ while (*str) {
+ if (*str == ',') {
+ str++;
+ continue;
+ }
+
+ nstr = strchr(str, ',');
+ if (!nstr)
+ nstr = str + strlen(str);
+
+ len = nstr - str;
+ if (len) {
+ __min_enable(str, len);
+ str += len;
+ }
+ }
+ }
+
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option
2025-04-26 11:03 [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
` (9 preceding siblings ...)
2025-04-26 11:03 ` [kvmtool PATCH v3 10/10] riscv: Allow including extensions in the min CPU type using command-line Anup Patel
@ 2025-05-01 13:13 ` Anup Patel
2025-05-16 13:54 ` Will Deacon
11 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2025-05-01 13:13 UTC (permalink / raw)
To: Will Deacon
Cc: julien.thierry.kdev, maz, Paolo Bonzini, Atish Patra,
Andrew Jones, kvm, kvm-riscv, Anup Patel
Hi Will,
On Sat, Apr 26, 2025 at 4:33 PM Anup Patel <apatel@ventanamicro.com> wrote:
>
> This series does the following improvements:
> 1) Add Svvptc, Zabha, and Ziccrse extension support (PATCH2 to PATCH3)
> 2) Add SBI system suspend support (PATCH5 to PATCH6)
> 3) Add "--cpu-type" command-line option supporting "min" and "max"
> CPU types where "max" is the default (PATCH8 to PATCH10)
>
> These patches can also be found in the riscv_more_exts_round6_v3 branch
> at: https://github.com/avpatel/kvmtool.git
>
> Changes since v2:
> - Addressed comments on PATCH10
>
> Changes since v1:
> - Rebased on latest KVMTOOL commit d410d9a16f91458ae2b912cc088015396f22dfad
> - Addressed comments on PATCH8, PATCH9, and PATCH10
>
> Andrew Jones (3):
> riscv: Add SBI system suspend support
> riscv: Make system suspend time configurable
> riscv: Fix no params with nodefault segfault
>
> Anup Patel (7):
> Sync-up headers with Linux-6.14 kernel
> riscv: Add Svvptc extension support
> riscv: Add Zabha extension support
> riscv: Add Ziccrse extension support
> riscv: Include single-letter extensions in isa_info_arr[]
> riscv: Add cpu-type command-line option
> riscv: Allow including extensions in the min CPU type using
> command-line
>
> arm64/include/asm/kvm.h | 3 -
> include/linux/kvm.h | 8 +-
> include/linux/virtio_pci.h | 14 ++
> riscv/aia.c | 2 +-
> riscv/fdt.c | 240 +++++++++++++++++++---------
> riscv/include/asm/kvm.h | 7 +-
> riscv/include/kvm/kvm-arch.h | 2 +
> riscv/include/kvm/kvm-config-arch.h | 26 +++
> riscv/include/kvm/sbi.h | 9 ++
> riscv/kvm-cpu.c | 36 +++++
> x86/include/asm/kvm.h | 1 +
> 11 files changed, 265 insertions(+), 83 deletions(-)
>
> --
> 2.43.0
>
Friendly ping ?
Regards,
Anup
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option
2025-04-26 11:03 [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
` (10 preceding siblings ...)
2025-05-01 13:13 ` [kvmtool PATCH v3 00/10] Add SBI system suspend and cpu-type option Anup Patel
@ 2025-05-16 13:54 ` Will Deacon
11 siblings, 0 replies; 13+ messages in thread
From: Will Deacon @ 2025-05-16 13:54 UTC (permalink / raw)
To: julien.thierry.kdev, maz, Anup Patel
Cc: catalin.marinas, kernel-team, Will Deacon, Paolo Bonzini,
Atish Patra, Andrew Jones, Anup Patel, kvm, kvm-riscv
On Sat, 26 Apr 2025 16:33:37 +0530, Anup Patel wrote:
> This series does the following improvements:
> 1) Add Svvptc, Zabha, and Ziccrse extension support (PATCH2 to PATCH3)
> 2) Add SBI system suspend support (PATCH5 to PATCH6)
> 3) Add "--cpu-type" command-line option supporting "min" and "max"
> CPU types where "max" is the default (PATCH8 to PATCH10)
>
> These patches can also be found in the riscv_more_exts_round6_v3 branch
> at: https://github.com/avpatel/kvmtool.git
>
> [...]
Applied to kvmtool (master), thanks!
(I updated the headers myself after fixing the script we have).
[02/10] riscv: Add Svvptc extension support
https://git.kernel.org/will/kvmtool/c/a9880860d781
[03/10] riscv: Add Zabha extension support
https://git.kernel.org/will/kvmtool/c/8be1c78896b4
[04/10] riscv: Add Ziccrse extension support
https://git.kernel.org/will/kvmtool/c/0641ed8c3763
[05/10] riscv: Add SBI system suspend support
https://git.kernel.org/will/kvmtool/c/fcc316016e9f
[06/10] riscv: Make system suspend time configurable
https://git.kernel.org/will/kvmtool/c/1132ace1c069
[07/10] riscv: Fix no params with nodefault segfault
https://git.kernel.org/will/kvmtool/c/b6e9f38b28c9
[08/10] riscv: Include single-letter extensions in isa_info_arr[]
https://git.kernel.org/will/kvmtool/c/d47ad017c404
[09/10] riscv: Add cpu-type command-line option
https://git.kernel.org/will/kvmtool/c/a50e8d888be8
[10/10] riscv: Allow including extensions in the min CPU type using command-line
https://git.kernel.org/will/kvmtool/c/1117dbc8ceb2
Cheers,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
^ permalink raw reply [flat|nested] 13+ messages in thread