Skip to contentSkip to conversation

Add RISC-V ISA extensions based on Linux-6.13

PATCH Applied Anup Patel 2 participants 10 messages Jan 27, 2025 – Feb 11, 2025

Subsystems (4)
lore
Share & tools
lore

Anup Patel

author
#0 lore raw

cover Add RISC-V ISA extensions based on Linux-6.13

This series adds support for new ISA extensions based on Linux-6.13
namely: Svade, Svadu, Smnpm, and Ssnpm.

These patches can also be found in the riscv_more_exts_round5_v1 branch
at: https://github.com/avpatel/kvmtool.git

Anup Patel (6):
Sync-up headers with Linux-6.13 kernel
Add __KERNEL_DIV_ROUND_UP() macro
riscv: Add Svade extension support
riscv: Add Svadu extension support
riscv: Add Smnpm extension support
riscv: Add Ssnpm extension support

 arm/aarch64/include/asm/kvm.h       |   6 ++
 include/linux/kernel.h              |   3 +
 include/linux/kvm.h                 |   8 ++
 include/linux/virtio_balloon.h      |  16 +++-
 include/linux/virtio_pci.h          | 131 ++++++++++++++++++++++++++++
 riscv/fdt.c                         |   4 +
 riscv/include/asm/kvm.h             |   4 +
 riscv/include/kvm/kvm-config-arch.h |  12 +++
 x86/include/asm/kvm.h               |   2 +
 9 files changed, 184 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/6 Sync-up headers with Linux-6.13 kernel

We sync-up Linux headers to get latest KVM RISC-V headers having newly added ISA extensions in ONE_REG interface.

---
 arm/aarch64/include/asm/kvm.h  |   6 ++
 include/linux/kvm.h            |   8 ++
 include/linux/virtio_balloon.h |  16 +++-
 include/linux/virtio_pci.h     | 131 +++++++++++++++++++++++++++++++++
 riscv/include/asm/kvm.h        |   4 +
 x86/include/asm/kvm.h          |   2 +
 6 files changed, 165 insertions(+), 2 deletions(-)
arm/aarch64/include/asm/kvm.h +6 -0
index 964df31..66736ff 100644
@@ -484,6 +484,12 @@ enum {
  */
 #define KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2	(1ULL << 0)
 
+/*
+ * Shutdown caused by a PSCI v1.3 SYSTEM_OFF2 call.
+ * Valid only when the system event has a type of KVM_SYSTEM_EVENT_SHUTDOWN.
+ */
+#define KVM_SYSTEM_EVENT_SHUTDOWN_FLAG_PSCI_OFF2	(1ULL << 0)
+
 /* run->fail_entry.hardware_entry_failure_reason codes. */
 #define KVM_EXIT_FAIL_ENTRY_CPU_UNSUPPORTED	(1ULL << 0)
 
include/linux/kvm.h +8 -0
index 637efc0..502ea63 100644
@@ -1158,7 +1158,15 @@ enum kvm_device_type {
 #define KVM_DEV_TYPE_ARM_PV_TIME	KVM_DEV_TYPE_ARM_PV_TIME
 	KVM_DEV_TYPE_RISCV_AIA,
 #define KVM_DEV_TYPE_RISCV_AIA		KVM_DEV_TYPE_RISCV_AIA
+	KVM_DEV_TYPE_LOONGARCH_IPI,
+#define KVM_DEV_TYPE_LOONGARCH_IPI	KVM_DEV_TYPE_LOONGARCH_IPI
+	KVM_DEV_TYPE_LOONGARCH_EIOINTC,
+#define KVM_DEV_TYPE_LOONGARCH_EIOINTC	KVM_DEV_TYPE_LOONGARCH_EIOINTC
+	KVM_DEV_TYPE_LOONGARCH_PCHPIC,
+#define KVM_DEV_TYPE_LOONGARCH_PCHPIC	KVM_DEV_TYPE_LOONGARCH_PCHPIC
+
 	KVM_DEV_TYPE_MAX,
+
 };
 
 struct kvm_vfio_spapr_tce {
include/linux/virtio_balloon.h +14 -2
index ddaa45e..ee35a37 100644
@@ -71,7 +71,13 @@ struct virtio_balloon_config {
 #define VIRTIO_BALLOON_S_CACHES   7   /* Disk caches */
 #define VIRTIO_BALLOON_S_HTLB_PGALLOC  8  /* Hugetlb page allocations */
 #define VIRTIO_BALLOON_S_HTLB_PGFAIL   9  /* Hugetlb page allocation failures */
-#define VIRTIO_BALLOON_S_NR       10
+#define VIRTIO_BALLOON_S_OOM_KILL      10 /* OOM killer invocations */
+#define VIRTIO_BALLOON_S_ALLOC_STALL   11 /* Stall count of memory allocatoin */
+#define VIRTIO_BALLOON_S_ASYNC_SCAN    12 /* Amount of memory scanned asynchronously */
+#define VIRTIO_BALLOON_S_DIRECT_SCAN   13 /* Amount of memory scanned directly */
+#define VIRTIO_BALLOON_S_ASYNC_RECLAIM 14 /* Amount of memory reclaimed asynchronously */
+#define VIRTIO_BALLOON_S_DIRECT_RECLAIM 15 /* Amount of memory reclaimed directly */
+#define VIRTIO_BALLOON_S_NR       16
 
 #define VIRTIO_BALLOON_S_NAMES_WITH_PREFIX(VIRTIO_BALLOON_S_NAMES_prefix) { \
 	VIRTIO_BALLOON_S_NAMES_prefix "swap-in", \
@@ -83,7 +89,13 @@ struct virtio_balloon_config {
 	VIRTIO_BALLOON_S_NAMES_prefix "available-memory", \
 	VIRTIO_BALLOON_S_NAMES_prefix "disk-caches", \
 	VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-allocations", \
-	VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-failures" \
+	VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-failures", \
+	VIRTIO_BALLOON_S_NAMES_prefix "oom-kills", \
+	VIRTIO_BALLOON_S_NAMES_prefix "alloc-stalls", \
+	VIRTIO_BALLOON_S_NAMES_prefix "async-scans", \
+	VIRTIO_BALLOON_S_NAMES_prefix "direct-scans", \
+	VIRTIO_BALLOON_S_NAMES_prefix "async-reclaims", \
+	VIRTIO_BALLOON_S_NAMES_prefix "direct-reclaims" \
 }
 
 #define VIRTIO_BALLOON_S_NAMES VIRTIO_BALLOON_S_NAMES_WITH_PREFIX("")
include/linux/virtio_pci.h +131 -0

147 lines not on this page · raw message

riscv/include/asm/kvm.h +4 -0
index e97db32..3482c9a 100644
@@ -175,6 +175,10 @@ enum KVM_RISCV_ISA_EXT_ID {
 	KVM_RISCV_ISA_EXT_ZCF,
 	KVM_RISCV_ISA_EXT_ZCMOP,
 	KVM_RISCV_ISA_EXT_ZAWRS,
+	KVM_RISCV_ISA_EXT_SMNPM,
+	KVM_RISCV_ISA_EXT_SSNPM,
+	KVM_RISCV_ISA_EXT_SVADE,
+	KVM_RISCV_ISA_EXT_SVADU,
 	KVM_RISCV_ISA_EXT_MAX,
 };
 
x86/include/asm/kvm.h +2 -0
index bf57a82..88585c1 100644
@@ -439,6 +439,8 @@ struct kvm_sync_regs {
 #define KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT	(1 << 4)
 #define KVM_X86_QUIRK_FIX_HYPERCALL_INSN	(1 << 5)
 #define KVM_X86_QUIRK_MWAIT_NEVER_UD_FAULTS	(1 << 6)
+#define KVM_X86_QUIRK_SLOT_ZAP_ALL		(1 << 7)
+#define KVM_X86_QUIRK_STUFF_FEATURE_MSRS	(1 << 8)
 
 #define KVM_STATE_NESTED_FORMAT_VMX	0
 #define KVM_STATE_NESTED_FORMAT_SVM	1
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 2/6 Add __KERNEL_DIV_ROUND_UP() macro

In reply to Anup Patel

The latest virtio_pci.h header from Linux-6.13 kernel requires __KERNEL_DIV_ROUND_UP() macro so define it conditionally in linux/kernel.h.

---
 include/linux/kernel.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/kernel.h +3 -0
index 6c22f1c..df42d63 100644
@@ -8,6 +8,9 @@
 #define round_down(x, y)	((x) & ~__round_mask(x, y))
 
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#ifndef __KERNEL_DIV_ROUND_UP
+#define __KERNEL_DIV_ROUND_UP(n,d)	DIV_ROUND_UP(n,d)
+#endif
 
 #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
 #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
Signature · 1 line
2.43.0
#3 lore raw

Re: [kvmtool PATCH 2/6] Add __KERNEL_DIV_ROUND_UP() macro

Quoted 14 lines · Anup Patel

The latest virtio_pci.h header from Linux-6.13 kernel requires __KERNEL_DIV_ROUND_UP() macro so define it conditionally in linux/kernel.h.

---
 include/linux/kernel.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/kernel.h +0 -0
index 6c22f1c..df42d63 100644

include/linux/kernel.h line 13

Quoted 6 lines
include/linux/kernel.h +3 -0
@@ -8,6 +8,9 @@
 #define round_down(x, y)	((x) & ~__round_mask(x, y))
 
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#ifndef __KERNEL_DIV_ROUND_UP
+#define __KERNEL_DIV_ROUND_UP(n,d)	DIV_ROUND_UP(n,d)
+#endif

I'm happy to take this for now, but perhaps we should be pulling in the uapi const.h header instead of rolling this ourselves? Ideally, kernel.h would disappear altogether.

Will

author
#4 lore raw

Re: [kvmtool PATCH 2/6] Add __KERNEL_DIV_ROUND_UP() macro

Quoted 18 lines · Will Deacon
Quoted 16 lines · Anup Patel

The latest virtio_pci.h header from Linux-6.13 kernel requires __KERNEL_DIV_ROUND_UP() macro so define it conditionally in linux/kernel.h.

---
 include/linux/kernel.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/kernel.h +0 -0
index 6c22f1c..df42d63 100644
@@ -8,6 +8,9 @@
 #define round_down(x, y)     ((x) & ~__round_mask(x, y))
 
Quoted 9 lines

include/linux/kernel.h line 13

Quoted 4 lines
include/linux/kernel.h +3 -0
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#ifndef __KERNEL_DIV_ROUND_UP
+#define __KERNEL_DIV_ROUND_UP(n,d)   DIV_ROUND_UP(n,d)
+#endif

I'm happy to take this for now, but perhaps we should be pulling in the uapi const.h header instead of rolling this ourselves? Ideally, kernel.h would disappear altogether.

Sure, next time I will try to pull the uapi const.h header into kvmtool.

Thanks,
Anup

author
#5 lore raw

PATCH 3/6 riscv: Add Svade extension support

In reply to Anup Patel

When the Svade extension is available expose it to the guest via device tree so that guest can use it.

---
 riscv/fdt.c                         | 1 +
 riscv/include/kvm/kvm-config-arch.h | 3 +++
 2 files changed, 4 insertions(+)
riscv/fdt.c +1 -0
index 85c8f95..cf0c036 100644
@@ -20,6 +20,7 @@ struct isa_ext_info isa_info_arr[] = {
 	{"ssaia", KVM_RISCV_ISA_EXT_SSAIA},
 	{"sscofpmf", KVM_RISCV_ISA_EXT_SSCOFPMF},
 	{"sstc", KVM_RISCV_ISA_EXT_SSTC},
+	{"svade", KVM_RISCV_ISA_EXT_SVADE},
 	{"svinval", KVM_RISCV_ISA_EXT_SVINVAL},
 	{"svnapot", KVM_RISCV_ISA_EXT_SVNAPOT},
 	{"svpbmt", KVM_RISCV_ISA_EXT_SVPBMT},
riscv/include/kvm/kvm-config-arch.h +3 -0
index 7a9ca60..5389dff 100644
@@ -37,6 +37,9 @@ struct kvm_config_arch {
 	OPT_BOOLEAN('\0', "disable-sstc",				\
 		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSTC],	\
 		    "Disable Sstc Extension"),				\
+	OPT_BOOLEAN('\0', "disable-svade",				\
+		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SVADE],	\
+		    "Disable Svade Extension"),				\
 	OPT_BOOLEAN('\0', "disable-svinval",				\
 		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SVINVAL],	\
 		    "Disable Svinval Extension"),			\
Signature · 1 line
2.43.0
author
#6 lore raw

PATCH 4/6 riscv: Add Svadu extension support

In reply to Anup Patel

When the Svadu extension is available expose it to the guest via device tree so that guest can use it.

---
 riscv/fdt.c                         | 1 +
 riscv/include/kvm/kvm-config-arch.h | 3 +++
 2 files changed, 4 insertions(+)
riscv/fdt.c +1 -0
index cf0c036..7f774f8 100644
@@ -21,6 +21,7 @@ struct isa_ext_info isa_info_arr[] = {
 	{"sscofpmf", KVM_RISCV_ISA_EXT_SSCOFPMF},
 	{"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},
riscv/include/kvm/kvm-config-arch.h +3 -0
index 5389dff..e3eeb84 100644
@@ -40,6 +40,9 @@ struct kvm_config_arch {
 	OPT_BOOLEAN('\0', "disable-svade",				\
 		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SVADE],	\
 		    "Disable Svade Extension"),				\
+	OPT_BOOLEAN('\0', "disable-svadu",				\
+		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SVADU],	\
+		    "Disable Svadu Extension"),				\
 	OPT_BOOLEAN('\0', "disable-svinval",				\
 		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SVINVAL],	\
 		    "Disable Svinval Extension"),			\
Signature · 1 line
2.43.0
author
#7 lore raw

PATCH 5/6 riscv: Add Smnpm extension support

In reply to Anup Patel

When the Smnpm extension is available expose it to the guest via device tree so that guest can use it.

---
 riscv/fdt.c                         | 1 +
 riscv/include/kvm/kvm-config-arch.h | 3 +++
 2 files changed, 4 insertions(+)
riscv/fdt.c +1 -0
index 7f774f8..4c9dbc1 100644
@@ -16,6 +16,7 @@ struct isa_ext_info {
 
 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},
riscv/include/kvm/kvm-config-arch.h +3 -0
index e3eeb84..5eccdd0 100644
@@ -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-smnpm",				\
+		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SMNPM],	\
+		    "Disable Smnpm Extension"),				\
 	OPT_BOOLEAN('\0', "disable-smstateen",				\
 		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SMSTATEEN],	\
 		    "Disable Smstateen Extension"),			\
Signature · 1 line
2.43.0
author
#8 lore raw

PATCH 6/6 riscv: Add Ssnpm extension support

In reply to Anup Patel

When the Ssnpm extension is available expose it to the guest via device tree so that guest can use it.

---
 riscv/fdt.c                         | 1 +
 riscv/include/kvm/kvm-config-arch.h | 3 +++
 2 files changed, 4 insertions(+)
riscv/fdt.c +1 -0
index 4c9dbc1..03113cc 100644
@@ -20,6 +20,7 @@ struct isa_ext_info isa_info_arr[] = {
 	{"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},
riscv/include/kvm/kvm-config-arch.h +3 -0
index 5eccdd0..e56610b 100644
@@ -37,6 +37,9 @@ struct kvm_config_arch {
 	OPT_BOOLEAN('\0', "disable-sscofpmf",				\
 		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSCOFPMF],	\
 		    "Disable Sscofpmf Extension"),			\
+	OPT_BOOLEAN('\0', "disable-ssnpm",				\
+		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSNPM],	\
+		    "Disable Ssnpm Extension"),				\
 	OPT_BOOLEAN('\0', "disable-sstc",				\
 		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSTC],	\
 		    "Disable Sstc Extension"),				\
Signature · 1 line
2.43.0
Applied
#9 lore raw
In reply to Anup Patel
Quoted 14 lines · Anup Patel

This series adds support for new ISA extensions based on Linux-6.13
namely: Svade, Svadu, Smnpm, and Ssnpm.

These patches can also be found in the riscv_more_exts_round5_v1 branch
at: https://github.com/avpatel/kvmtool.git

Anup Patel (6):
Sync-up headers with Linux-6.13 kernel
Add __KERNEL_DIV_ROUND_UP() macro
riscv: Add Svade extension support
riscv: Add Svadu extension support
riscv: Add Smnpm extension support
riscv: Add Ssnpm extension support

Quoted 1 line

[...]

Applied to kvmtool (master), thanks!

[1/6] Sync-up headers with Linux-6.13 kernel

      https://git.kernel.org/will/kvmtool/c/4b2cc0660ef3
[2/6] Add __KERNEL_DIV_ROUND_UP() macro
      https://git.kernel.org/will/kvmtool/c/66567918472f
[3/6] riscv: Add Svade extension support
      https://git.kernel.org/will/kvmtool/c/f8ed03217263
[4/6] riscv: Add Svadu extension support
      https://git.kernel.org/will/kvmtool/c/521b1b676e5c
[5/6] riscv: Add Smnpm extension support
      https://git.kernel.org/will/kvmtool/c/4489348c961b
[6/6] riscv: Add Ssnpm extension support
      https://git.kernel.org/will/kvmtool/c/e48563f5c4a4

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev