* [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support
@ 2023-07-06 17:37 Anup Patel
2023-07-06 17:37 ` [kvmtool PATCH v3 1/8] Sync-up headers with Linux-6.4 Anup Patel
` (8 more replies)
0 siblings, 9 replies; 11+ messages in thread
From: Anup Patel @ 2023-07-06 17:37 UTC (permalink / raw)
To: Will Deacon, julien.thierry.kdev, maz
Cc: Paolo Bonzini, Atish Patra, Andrew Jones, Anup Patel, kvm,
kvm-riscv, 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 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(-)
--
2.34.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [kvmtool PATCH v3 1/8] Sync-up headers with Linux-6.4
2023-07-06 17:37 [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Anup Patel
@ 2023-07-06 17:37 ` Anup Patel
2023-07-06 17:37 ` [kvmtool PATCH v3 2/8] riscv: Allow setting custom mvendorid, marchid, and mimpid Anup Patel
` (7 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2023-07-06 17:37 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
SBI extension enable/disable, Zbb, Zicboz, and Ssaia support.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
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(-)
diff --git a/arm/aarch64/include/asm/kvm.h b/arm/aarch64/include/asm/kvm.h
index 316917b..f7ddd73 100644
--- a/arm/aarch64/include/asm/kvm.h
+++ b/arm/aarch64/include/asm/kvm.h
@@ -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__ */
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 0d5d441..737318b 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -86,14 +86,6 @@ struct kvm_debug_guest {
/* *** End of deprecated interfaces *** */
-/* for KVM_CREATE_MEMORY_REGION */
-struct kvm_memory_region {
- __u32 slot;
- __u32 flags;
- __u64 guest_phys_addr;
- __u64 memory_size; /* bytes */
-};
-
/* for KVM_SET_USER_MEMORY_REGION */
struct kvm_userspace_memory_region {
__u32 slot;
@@ -104,9 +96,9 @@ struct kvm_userspace_memory_region {
};
/*
- * The bit 0 ~ bit 15 of kvm_memory_region::flags are visible for userspace,
- * other bits are reserved for kvm internal use which are defined in
- * include/linux/kvm_host.h.
+ * The bit 0 ~ bit 15 of kvm_userspace_memory_region::flags are visible for
+ * userspace, other bits are reserved for kvm internal use which are defined
+ * in include/linux/kvm_host.h.
*/
#define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0)
#define KVM_MEM_READONLY (1UL << 1)
@@ -349,8 +341,13 @@ struct kvm_run {
__u64 nr;
__u64 args[6];
__u64 ret;
- __u32 longmode;
- __u32 pad;
+
+ union {
+#ifndef __KERNEL__
+ __u32 longmode;
+#endif
+ __u64 flags;
+ };
} hypercall;
/* KVM_EXIT_TPR_ACCESS */
struct {
@@ -485,6 +482,9 @@ struct kvm_run {
#define KVM_MSR_EXIT_REASON_INVAL (1 << 0)
#define KVM_MSR_EXIT_REASON_UNKNOWN (1 << 1)
#define KVM_MSR_EXIT_REASON_FILTER (1 << 2)
+#define KVM_MSR_EXIT_REASON_VALID_MASK (KVM_MSR_EXIT_REASON_INVAL | \
+ KVM_MSR_EXIT_REASON_UNKNOWN | \
+ KVM_MSR_EXIT_REASON_FILTER)
__u32 reason; /* kernel -> user */
__u32 index; /* kernel -> user */
__u64 data; /* kernel <-> user */
@@ -588,6 +588,8 @@ struct kvm_s390_mem_op {
struct {
__u8 ar; /* the access register number */
__u8 key; /* access key, ignored if flag unset */
+ __u8 pad1[6]; /* ignored */
+ __u64 old_addr; /* ignored if cmpxchg flag unset */
};
__u32 sida_offset; /* offset into the sida */
__u8 reserved[32]; /* ignored */
@@ -600,11 +602,17 @@ struct kvm_s390_mem_op {
#define KVM_S390_MEMOP_SIDA_WRITE 3
#define KVM_S390_MEMOP_ABSOLUTE_READ 4
#define KVM_S390_MEMOP_ABSOLUTE_WRITE 5
+#define KVM_S390_MEMOP_ABSOLUTE_CMPXCHG 6
+
/* flags for kvm_s390_mem_op->flags */
#define KVM_S390_MEMOP_F_CHECK_ONLY (1ULL << 0)
#define KVM_S390_MEMOP_F_INJECT_EXCEPTION (1ULL << 1)
#define KVM_S390_MEMOP_F_SKEY_PROTECTION (1ULL << 2)
+/* flags specifying extension support via KVM_CAP_S390_MEM_OP_EXTENSION */
+#define KVM_S390_MEMOP_EXTENSION_CAP_BASE (1 << 0)
+#define KVM_S390_MEMOP_EXTENSION_CAP_CMPXCHG (1 << 1)
+
/* for KVM_INTERRUPT */
struct kvm_interrupt {
/* in */
@@ -1178,6 +1186,10 @@ struct kvm_ppc_resize_hpt {
#define KVM_CAP_S390_ZPCI_OP 221
#define KVM_CAP_S390_CPU_TOPOLOGY 222
#define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223
+#define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224
+#define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225
+#define KVM_CAP_PMU_EVENT_MASKED_EVENTS 226
+#define KVM_CAP_COUNTER_OFFSET 227
#ifdef KVM_CAP_IRQ_ROUTING
@@ -1267,6 +1279,7 @@ struct kvm_x86_mce {
#define KVM_XEN_HVM_CONFIG_RUNSTATE (1 << 3)
#define KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL (1 << 4)
#define KVM_XEN_HVM_CONFIG_EVTCHN_SEND (1 << 5)
+#define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG (1 << 6)
struct kvm_xen_hvm_config {
__u32 flags;
@@ -1437,20 +1450,14 @@ struct kvm_vfio_spapr_tce {
__s32 tablefd;
};
-/*
- * ioctls for VM fds
- */
-#define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
/*
* KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
* a vcpu fd.
*/
#define KVM_CREATE_VCPU _IO(KVMIO, 0x41)
#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
-/* KVM_SET_MEMORY_ALIAS is obsolete: */
-#define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias)
#define KVM_SET_NR_MMU_PAGES _IO(KVMIO, 0x44)
-#define KVM_GET_NR_MMU_PAGES _IO(KVMIO, 0x45)
+#define KVM_GET_NR_MMU_PAGES _IO(KVMIO, 0x45) /* deprecated */
#define KVM_SET_USER_MEMORY_REGION _IOW(KVMIO, 0x46, \
struct kvm_userspace_memory_region)
#define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47)
@@ -1542,6 +1549,8 @@ struct kvm_s390_ucas_mapping {
#define KVM_SET_PMU_EVENT_FILTER _IOW(KVMIO, 0xb2, struct kvm_pmu_event_filter)
#define KVM_PPC_SVM_OFF _IO(KVMIO, 0xb3)
#define KVM_ARM_MTE_COPY_TAGS _IOR(KVMIO, 0xb4, struct kvm_arm_copy_mte_tags)
+/* Available with KVM_CAP_COUNTER_OFFSET */
+#define KVM_ARM_SET_COUNTER_OFFSET _IOW(KVMIO, 0xb5, struct kvm_arm_counter_offset)
/* ioctl for vm fd */
#define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device)
@@ -1740,6 +1749,8 @@ enum pv_cmd_id {
KVM_PV_UNSHARE_ALL,
KVM_PV_INFO,
KVM_PV_DUMP,
+ KVM_PV_ASYNC_CLEANUP_PREPARE,
+ KVM_PV_ASYNC_CLEANUP_PERFORM,
};
struct kvm_pv_cmd {
@@ -1770,8 +1781,10 @@ struct kvm_xen_hvm_attr {
union {
__u8 long_mode;
__u8 vector;
+ __u8 runstate_update_flag;
struct {
__u64 gfn;
+#define KVM_XEN_INVALID_GFN ((__u64)-1)
} shared_info;
struct {
__u32 send_port;
@@ -1803,6 +1816,7 @@ struct kvm_xen_hvm_attr {
} u;
};
+
/* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO */
#define KVM_XEN_ATTR_TYPE_LONG_MODE 0x0
#define KVM_XEN_ATTR_TYPE_SHARED_INFO 0x1
@@ -1810,6 +1824,8 @@ struct kvm_xen_hvm_attr {
/* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_EVTCHN_SEND */
#define KVM_XEN_ATTR_TYPE_EVTCHN 0x3
#define KVM_XEN_ATTR_TYPE_XEN_VERSION 0x4
+/* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG */
+#define KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG 0x5
/* Per-vCPU Xen attributes */
#define KVM_XEN_VCPU_GET_ATTR _IOWR(KVMIO, 0xca, struct kvm_xen_vcpu_attr)
@@ -1826,6 +1842,7 @@ struct kvm_xen_vcpu_attr {
__u16 pad[3];
union {
__u64 gpa;
+#define KVM_XEN_INVALID_GPA ((__u64)-1)
__u64 pad[8];
struct {
__u64 state;
diff --git a/include/linux/virtio_blk.h b/include/linux/virtio_blk.h
index 58e70b2..3744e4d 100644
--- a/include/linux/virtio_blk.h
+++ b/include/linux/virtio_blk.h
@@ -41,6 +41,7 @@
#define VIRTIO_BLK_F_DISCARD 13 /* DISCARD is supported */
#define VIRTIO_BLK_F_WRITE_ZEROES 14 /* WRITE ZEROES is supported */
#define VIRTIO_BLK_F_SECURE_ERASE 16 /* Secure Erase is supported */
+#define VIRTIO_BLK_F_ZONED 17 /* Zoned block device */
/* Legacy feature bits */
#ifndef VIRTIO_BLK_NO_LEGACY
@@ -137,6 +138,16 @@ struct virtio_blk_config {
/* Secure erase commands must be aligned to this number of sectors. */
__virtio32 secure_erase_sector_alignment;
+ /* Zoned block device characteristics (if VIRTIO_BLK_F_ZONED) */
+ struct virtio_blk_zoned_characteristics {
+ __virtio32 zone_sectors;
+ __virtio32 max_open_zones;
+ __virtio32 max_active_zones;
+ __virtio32 max_append_sectors;
+ __virtio32 write_granularity;
+ __u8 model;
+ __u8 unused2[3];
+ } zoned;
} __attribute__((packed));
/*
@@ -174,6 +185,27 @@ struct virtio_blk_config {
/* Secure erase command */
#define VIRTIO_BLK_T_SECURE_ERASE 14
+/* Zone append command */
+#define VIRTIO_BLK_T_ZONE_APPEND 15
+
+/* Report zones command */
+#define VIRTIO_BLK_T_ZONE_REPORT 16
+
+/* Open zone command */
+#define VIRTIO_BLK_T_ZONE_OPEN 18
+
+/* Close zone command */
+#define VIRTIO_BLK_T_ZONE_CLOSE 20
+
+/* Finish zone command */
+#define VIRTIO_BLK_T_ZONE_FINISH 22
+
+/* Reset zone command */
+#define VIRTIO_BLK_T_ZONE_RESET 24
+
+/* Reset All zones command */
+#define VIRTIO_BLK_T_ZONE_RESET_ALL 26
+
#ifndef VIRTIO_BLK_NO_LEGACY
/* Barrier before this op. */
#define VIRTIO_BLK_T_BARRIER 0x80000000
@@ -193,6 +225,72 @@ struct virtio_blk_outhdr {
__virtio64 sector;
};
+/*
+ * Supported zoned device models.
+ */
+
+/* Regular block device */
+#define VIRTIO_BLK_Z_NONE 0
+/* Host-managed zoned device */
+#define VIRTIO_BLK_Z_HM 1
+/* Host-aware zoned device */
+#define VIRTIO_BLK_Z_HA 2
+
+/*
+ * Zone descriptor. A part of VIRTIO_BLK_T_ZONE_REPORT command reply.
+ */
+struct virtio_blk_zone_descriptor {
+ /* Zone capacity */
+ __virtio64 z_cap;
+ /* The starting sector of the zone */
+ __virtio64 z_start;
+ /* Zone write pointer position in sectors */
+ __virtio64 z_wp;
+ /* Zone type */
+ __u8 z_type;
+ /* Zone state */
+ __u8 z_state;
+ __u8 reserved[38];
+};
+
+struct virtio_blk_zone_report {
+ __virtio64 nr_zones;
+ __u8 reserved[56];
+ struct virtio_blk_zone_descriptor zones[];
+};
+
+/*
+ * Supported zone types.
+ */
+
+/* Conventional zone */
+#define VIRTIO_BLK_ZT_CONV 1
+/* Sequential Write Required zone */
+#define VIRTIO_BLK_ZT_SWR 2
+/* Sequential Write Preferred zone */
+#define VIRTIO_BLK_ZT_SWP 3
+
+/*
+ * Zone states that are available for zones of all types.
+ */
+
+/* Not a write pointer (conventional zones only) */
+#define VIRTIO_BLK_ZS_NOT_WP 0
+/* Empty */
+#define VIRTIO_BLK_ZS_EMPTY 1
+/* Implicitly Open */
+#define VIRTIO_BLK_ZS_IOPEN 2
+/* Explicitly Open */
+#define VIRTIO_BLK_ZS_EOPEN 3
+/* Closed */
+#define VIRTIO_BLK_ZS_CLOSED 4
+/* Read-Only */
+#define VIRTIO_BLK_ZS_RDONLY 13
+/* Full */
+#define VIRTIO_BLK_ZS_FULL 14
+/* Offline */
+#define VIRTIO_BLK_ZS_OFFLINE 15
+
/* Unmap this range (only valid for write zeroes command) */
#define VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP 0x00000001
@@ -219,4 +317,11 @@ struct virtio_scsi_inhdr {
#define VIRTIO_BLK_S_OK 0
#define VIRTIO_BLK_S_IOERR 1
#define VIRTIO_BLK_S_UNSUPP 2
+
+/* Error codes that are specific to zoned block devices */
+#define VIRTIO_BLK_S_ZONE_INVALID_CMD 3
+#define VIRTIO_BLK_S_ZONE_UNALIGNED_WP 4
+#define VIRTIO_BLK_S_ZONE_OPEN_RESOURCE 5
+#define VIRTIO_BLK_S_ZONE_ACTIVE_RESOURCE 6
+
#endif /* _LINUX_VIRTIO_BLK_H */
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 3c05162..2c712c6 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -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.
*/
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 6cb842e..12c1c96 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -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 */
diff --git a/riscv/include/asm/kvm.h b/riscv/include/asm/kvm.h
index 8985ff2..f92790c 100644
--- a/riscv/include/asm/kvm.h
+++ b/riscv/include/asm/kvm.h
@@ -12,6 +12,7 @@
#ifndef __ASSEMBLY__
#include <linux/types.h>
+#include <asm/bitsperlong.h>
#include <asm/ptrace.h>
#define __KVM_HAVE_READONLY_MEM
@@ -49,6 +50,10 @@ struct kvm_sregs {
struct kvm_riscv_config {
unsigned long isa;
unsigned long zicbom_block_size;
+ unsigned long mvendorid;
+ unsigned long marchid;
+ unsigned long mimpid;
+ unsigned long zicboz_block_size;
};
/* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
@@ -61,7 +66,7 @@ struct kvm_riscv_core {
#define KVM_RISCV_MODE_S 1
#define KVM_RISCV_MODE_U 0
-/* CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
+/* General CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
struct kvm_riscv_csr {
unsigned long sstatus;
unsigned long sie;
@@ -75,6 +80,17 @@ struct kvm_riscv_csr {
unsigned long scounteren;
};
+/* AIA CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
+struct kvm_riscv_aia_csr {
+ unsigned long siselect;
+ unsigned long iprio1;
+ unsigned long iprio2;
+ unsigned long sieh;
+ unsigned long siph;
+ unsigned long iprio1h;
+ unsigned long iprio2h;
+};
+
/* TIMER registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
struct kvm_riscv_timer {
__u64 frequency;
@@ -102,9 +118,29 @@ enum KVM_RISCV_ISA_EXT_ID {
KVM_RISCV_ISA_EXT_SVINVAL,
KVM_RISCV_ISA_EXT_ZIHINTPAUSE,
KVM_RISCV_ISA_EXT_ZICBOM,
+ KVM_RISCV_ISA_EXT_ZICBOZ,
+ KVM_RISCV_ISA_EXT_ZBB,
+ KVM_RISCV_ISA_EXT_SSAIA,
KVM_RISCV_ISA_EXT_MAX,
};
+/*
+ * SBI extension IDs specific to KVM. This is not the same as the SBI
+ * extension IDs defined by the RISC-V SBI specification.
+ */
+enum KVM_RISCV_SBI_EXT_ID {
+ KVM_RISCV_SBI_EXT_V01 = 0,
+ KVM_RISCV_SBI_EXT_TIME,
+ KVM_RISCV_SBI_EXT_IPI,
+ KVM_RISCV_SBI_EXT_RFENCE,
+ KVM_RISCV_SBI_EXT_SRST,
+ KVM_RISCV_SBI_EXT_HSM,
+ KVM_RISCV_SBI_EXT_PMU,
+ KVM_RISCV_SBI_EXT_EXPERIMENTAL,
+ KVM_RISCV_SBI_EXT_VENDOR,
+ KVM_RISCV_SBI_EXT_MAX,
+};
+
/* Possible states for kvm_riscv_timer */
#define KVM_RISCV_TIMER_STATE_OFF 0
#define KVM_RISCV_TIMER_STATE_ON 1
@@ -115,6 +151,8 @@ enum KVM_RISCV_ISA_EXT_ID {
/* 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
+#define KVM_REG_RISCV_SUBTYPE_MASK 0x0000000000FF0000
+#define KVM_REG_RISCV_SUBTYPE_SHIFT 16
/* Config registers are mapped as type 1 */
#define KVM_REG_RISCV_CONFIG (0x01 << KVM_REG_RISCV_TYPE_SHIFT)
@@ -128,8 +166,12 @@ enum KVM_RISCV_ISA_EXT_ID {
/* Control and status registers are mapped as type 3 */
#define KVM_REG_RISCV_CSR (0x03 << KVM_REG_RISCV_TYPE_SHIFT)
+#define KVM_REG_RISCV_CSR_GENERAL (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT)
+#define KVM_REG_RISCV_CSR_AIA (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT)
#define KVM_REG_RISCV_CSR_REG(name) \
(offsetof(struct kvm_riscv_csr, name) / sizeof(unsigned long))
+#define KVM_REG_RISCV_CSR_AIA_REG(name) \
+ (offsetof(struct kvm_riscv_aia_csr, name) / sizeof(unsigned long))
/* Timer registers are mapped as type 4 */
#define KVM_REG_RISCV_TIMER (0x04 << KVM_REG_RISCV_TYPE_SHIFT)
@@ -149,6 +191,18 @@ enum KVM_RISCV_ISA_EXT_ID {
/* ISA Extension registers are mapped as type 7 */
#define KVM_REG_RISCV_ISA_EXT (0x07 << KVM_REG_RISCV_TYPE_SHIFT)
+/* SBI extension registers are mapped as type 8 */
+#define KVM_REG_RISCV_SBI_EXT (0x08 << KVM_REG_RISCV_TYPE_SHIFT)
+#define KVM_REG_RISCV_SBI_SINGLE (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT)
+#define KVM_REG_RISCV_SBI_MULTI_EN (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT)
+#define KVM_REG_RISCV_SBI_MULTI_DIS (0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT)
+#define KVM_REG_RISCV_SBI_MULTI_REG(__ext_id) \
+ ((__ext_id) / __BITS_PER_LONG)
+#define KVM_REG_RISCV_SBI_MULTI_MASK(__ext_id) \
+ (1UL << ((__ext_id) % __BITS_PER_LONG))
+#define KVM_REG_RISCV_SBI_MULTI_REG_LAST \
+ KVM_REG_RISCV_SBI_MULTI_REG(KVM_RISCV_SBI_EXT_MAX - 1)
+
#endif
#endif /* __LINUX_KVM_RISCV_H */
diff --git a/x86/include/asm/kvm.h b/x86/include/asm/kvm.h
index 46de10a..1a6a1f9 100644
--- a/x86/include/asm/kvm.h
+++ b/x86/include/asm/kvm.h
@@ -9,6 +9,7 @@
#include <linux/types.h>
#include <linux/ioctl.h>
+#include <linux/stddef.h>
#define KVM_PIO_PAGE_OFFSET 1
#define KVM_COALESCED_MMIO_PAGE_OFFSET 2
@@ -53,14 +54,6 @@
/* Architectural interrupt line count. */
#define KVM_NR_INTERRUPTS 256
-struct kvm_memory_alias {
- __u32 slot; /* this has a different namespace than memory slots */
- __u32 flags;
- __u64 guest_phys_addr;
- __u64 memory_size;
- __u64 target_phys_addr;
-};
-
/* for KVM_GET_IRQCHIP and KVM_SET_IRQCHIP */
struct kvm_pic_state {
__u8 last_irr; /* edge detection */
@@ -214,6 +207,8 @@ struct kvm_msr_list {
struct kvm_msr_filter_range {
#define KVM_MSR_FILTER_READ (1 << 0)
#define KVM_MSR_FILTER_WRITE (1 << 1)
+#define KVM_MSR_FILTER_RANGE_VALID_MASK (KVM_MSR_FILTER_READ | \
+ KVM_MSR_FILTER_WRITE)
__u32 flags;
__u32 nmsrs; /* number of msrs in bitmap */
__u32 base; /* MSR index the bitmap starts at */
@@ -222,8 +217,11 @@ struct kvm_msr_filter_range {
#define KVM_MSR_FILTER_MAX_RANGES 16
struct kvm_msr_filter {
+#ifndef __KERNEL__
#define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0)
+#endif
#define KVM_MSR_FILTER_DEFAULT_DENY (1 << 0)
+#define KVM_MSR_FILTER_VALID_MASK (KVM_MSR_FILTER_DEFAULT_DENY)
__u32 flags;
struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES];
};
@@ -510,8 +508,8 @@ struct kvm_nested_state {
* KVM_{GET,PUT}_NESTED_STATE ioctl values.
*/
union {
- struct kvm_vmx_nested_state_data vmx[0];
- struct kvm_svm_nested_state_data svm[0];
+ __DECLARE_FLEX_ARRAY(struct kvm_vmx_nested_state_data, vmx);
+ __DECLARE_FLEX_ARRAY(struct kvm_svm_nested_state_data, svm);
} data;
};
@@ -528,8 +526,40 @@ struct kvm_pmu_event_filter {
#define KVM_PMU_EVENT_ALLOW 0
#define KVM_PMU_EVENT_DENY 1
+#define KVM_PMU_EVENT_FLAG_MASKED_EVENTS BIT(0)
+#define KVM_PMU_EVENT_FLAGS_VALID_MASK (KVM_PMU_EVENT_FLAG_MASKED_EVENTS)
+
+/*
+ * Masked event layout.
+ * Bits Description
+ * ---- -----------
+ * 7:0 event select (low bits)
+ * 15:8 umask match
+ * 31:16 unused
+ * 35:32 event select (high bits)
+ * 36:54 unused
+ * 55 exclude bit
+ * 63:56 umask mask
+ */
+
+#define KVM_PMU_ENCODE_MASKED_ENTRY(event_select, mask, match, exclude) \
+ (((event_select) & 0xFFULL) | (((event_select) & 0XF00ULL) << 24) | \
+ (((mask) & 0xFFULL) << 56) | \
+ (((match) & 0xFFULL) << 8) | \
+ ((__u64)(!!(exclude)) << 55))
+
+#define KVM_PMU_MASKED_ENTRY_EVENT_SELECT \
+ (GENMASK_ULL(7, 0) | GENMASK_ULL(35, 32))
+#define KVM_PMU_MASKED_ENTRY_UMASK_MASK (GENMASK_ULL(63, 56))
+#define KVM_PMU_MASKED_ENTRY_UMASK_MATCH (GENMASK_ULL(15, 8))
+#define KVM_PMU_MASKED_ENTRY_EXCLUDE (BIT_ULL(55))
+#define KVM_PMU_MASKED_ENTRY_UMASK_MASK_SHIFT (56)
+
/* for KVM_{GET,SET,HAS}_DEVICE_ATTR */
#define KVM_VCPU_TSC_CTRL 0 /* control group for the timestamp counter (TSC) */
#define KVM_VCPU_TSC_OFFSET 0 /* attribute for the TSC offset */
+/* x86-specific KVM_EXIT_HYPERCALL flags. */
+#define KVM_EXIT_HYPERCALL_LONG_MODE BIT(0)
+
#endif /* _ASM_X86_KVM_H */
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [kvmtool PATCH v3 2/8] riscv: Allow setting custom mvendorid, marchid, and mimpid
2023-07-06 17:37 [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Anup Patel
2023-07-06 17:37 ` [kvmtool PATCH v3 1/8] Sync-up headers with Linux-6.4 Anup Patel
@ 2023-07-06 17:37 ` Anup Patel
2023-07-06 17:37 ` [kvmtool PATCH v3 3/8] riscv: Allow disabling SBI extensions for Guest Anup Patel
` (6 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2023-07-06 17:37 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 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.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
riscv/include/kvm/kvm-config-arch.h | 12 ++++++++++++
riscv/kvm-cpu.c | 26 +++++++++++++++++++++++++-
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h
index 188125c..e64e3ca 100644
--- a/riscv/include/kvm/kvm-config-arch.h
+++ b/riscv/include/kvm/kvm-config-arch.h
@@ -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"), \
diff --git a/riscv/kvm-cpu.c b/riscv/kvm-cpu.c
index f98bd7a..89122b4 100644
--- a/riscv/kvm-cpu.c
+++ b/riscv/kvm-cpu.c
@@ -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;
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [kvmtool PATCH v3 3/8] riscv: Allow disabling SBI extensions for Guest
2023-07-06 17:37 [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Anup Patel
2023-07-06 17:37 ` [kvmtool PATCH v3 1/8] Sync-up headers with Linux-6.4 Anup Patel
2023-07-06 17:37 ` [kvmtool PATCH v3 2/8] riscv: Allow setting custom mvendorid, marchid, and mimpid Anup Patel
@ 2023-07-06 17:37 ` Anup Patel
2023-07-06 17:38 ` [kvmtool PATCH v3 4/8] riscv: Sort the ISA extension array alphabetically Anup Patel
` (5 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2023-07-06 17:37 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 add "--disable-sbi-<xyz>" options to disable various SBI extensions
visible to the Guest. This allows users to disable deprecated/redundant
SBI extensions.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
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(-)
diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h
index e64e3ca..56676e3 100644
--- a/riscv/include/kvm/kvm-config-arch.h
+++ b/riscv/include/kvm/kvm-config-arch.h
@@ -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 */
diff --git a/riscv/include/kvm/kvm-cpu-arch.h b/riscv/include/kvm/kvm-cpu-arch.h
index e014839..1e9a7b0 100644
--- a/riscv/include/kvm/kvm-cpu-arch.h
+++ b/riscv/include/kvm/kvm-cpu-arch.h
@@ -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;
diff --git a/riscv/kvm-cpu.c b/riscv/kvm-cpu.c
index 89122b4..540baec 100644
--- a/riscv/kvm-cpu.c
+++ b/riscv/kvm-cpu.c
@@ -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;
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [kvmtool PATCH v3 4/8] riscv: Sort the ISA extension array alphabetically
2023-07-06 17:37 [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Anup Patel
` (2 preceding siblings ...)
2023-07-06 17:37 ` [kvmtool PATCH v3 3/8] riscv: Allow disabling SBI extensions for Guest Anup Patel
@ 2023-07-06 17:38 ` Anup Patel
2023-07-06 17:38 ` [kvmtool PATCH v3 5/8] riscv: Add zbb extension support Anup Patel
` (4 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2023-07-06 17:38 UTC (permalink / raw)
To: Will Deacon, julien.thierry.kdev, maz
Cc: Paolo Bonzini, Atish Patra, Andrew Jones, Anup Patel, kvm,
kvm-riscv, Anup Patel
Let us follow alphabetical order for listing ISA extensions in
the isa_info_arr[] array.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
riscv/fdt.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/riscv/fdt.c b/riscv/fdt.c
index 3cdb95c..977e962 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -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)
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [kvmtool PATCH v3 5/8] riscv: Add zbb extension support
2023-07-06 17:37 [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Anup Patel
` (3 preceding siblings ...)
2023-07-06 17:38 ` [kvmtool PATCH v3 4/8] riscv: Sort the ISA extension array alphabetically Anup Patel
@ 2023-07-06 17:38 ` Anup Patel
2023-07-06 17:38 ` [kvmtool PATCH v3 6/8] riscv: Add Zicboz " Anup Patel
` (3 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2023-07-06 17:38 UTC (permalink / raw)
To: Will Deacon, julien.thierry.kdev, maz
Cc: Paolo Bonzini, Atish Patra, Andrew Jones, Anup Patel, kvm,
kvm-riscv, Anup Patel
The 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.
Signed-off-by: Anup Patel <apatel@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 977e962..17d6757 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -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},
};
diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h
index 56676e3..8448b1a 100644
--- a/riscv/include/kvm/kvm-config-arch.h
+++ b/riscv/include/kvm/kvm-config-arch.h
@@ -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"), \
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [kvmtool PATCH v3 6/8] riscv: Add Zicboz extension support
2023-07-06 17:37 [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Anup Patel
` (4 preceding siblings ...)
2023-07-06 17:38 ` [kvmtool PATCH v3 5/8] riscv: Add zbb extension support Anup Patel
@ 2023-07-06 17:38 ` Anup Patel
2023-07-06 17:38 ` [kvmtool PATCH v3 7/8] riscv: Add Ssaia " Anup Patel
` (2 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2023-07-06 17:38 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>
When the Zicboz extension is available expose it to the guest.
Also provide the guest the size of the cache block through DT.
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
riscv/fdt.c | 12 +++++++++++-
riscv/include/kvm/kvm-config-arch.h | 3 +++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/riscv/fdt.c b/riscv/fdt.c
index 17d6757..a76dc37 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -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"));
diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h
index 8448b1a..b12605d 100644
--- a/riscv/include/kvm/kvm-config-arch.h
+++ b/riscv/include/kvm/kvm-config-arch.h
@@ -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"), \
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [kvmtool PATCH v3 7/8] riscv: Add Ssaia extension support
2023-07-06 17:37 [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Anup Patel
` (5 preceding siblings ...)
2023-07-06 17:38 ` [kvmtool PATCH v3 6/8] riscv: Add Zicboz " Anup Patel
@ 2023-07-06 17:38 ` Anup Patel
2023-07-06 17:38 ` [kvmtool PATCH v3 8/8] riscv: Fix guest RAM alloc size computation for RV32 Anup Patel
2023-07-12 16:10 ` [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Will Deacon
8 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2023-07-06 17:38 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 Ssaia extension is available expose it to the guest.
Signed-off-by: Anup Patel <apatel@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 a76dc37..df71ed4 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -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},
diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h
index b12605d..b0a7e25 100644
--- a/riscv/include/kvm/kvm-config-arch.h
+++ b/riscv/include/kvm/kvm-config-arch.h
@@ -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"), \
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [kvmtool PATCH v3 8/8] riscv: Fix guest RAM alloc size computation for RV32
2023-07-06 17:37 [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Anup Patel
` (6 preceding siblings ...)
2023-07-06 17:38 ` [kvmtool PATCH v3 7/8] riscv: Add Ssaia " Anup Patel
@ 2023-07-06 17:38 ` Anup Patel
2023-07-12 16:10 ` [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Will Deacon
8 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2023-07-06 17:38 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, 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.
Fixes: 867159a7963b ("riscv: Implement Guest/VM arch functions")
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
riscv/kvm.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/riscv/kvm.c b/riscv/kvm.c
index 4d6f5cb..8daad94 100644
--- a/riscv/kvm.c
+++ b/riscv/kvm.c
@@ -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);
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support
2023-07-06 17:37 [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Anup Patel
` (7 preceding siblings ...)
2023-07-06 17:38 ` [kvmtool PATCH v3 8/8] riscv: Fix guest RAM alloc size computation for RV32 Anup Patel
@ 2023-07-12 16:10 ` Will Deacon
2023-07-12 16:33 ` Anup Patel
8 siblings, 1 reply; 11+ messages in thread
From: Will Deacon @ 2023-07-12 16:10 UTC (permalink / raw)
To: Anup Patel
Cc: julien.thierry.kdev, maz, Paolo Bonzini, Atish Patra,
Andrew Jones, Anup Patel, kvm, kvm-riscv
On Thu, Jul 06, 2023 at 11:07:56PM +0530, Anup Patel wrote:
> 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
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support
2023-07-12 16:10 ` [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Will Deacon
@ 2023-07-12 16:33 ` Anup Patel
0 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2023-07-12 16:33 UTC (permalink / raw)
To: Will Deacon
Cc: Anup Patel, julien.thierry.kdev, maz, Paolo Bonzini, Atish Patra,
Andrew Jones, kvm, kvm-riscv
On Wed, Jul 12, 2023 at 9:41 PM Will Deacon <will@kernel.org> wrote:
>
> On Thu, Jul 06, 2023 at 11:07:56PM +0530, Anup Patel wrote:
> > 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
>
> 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);
> | ^~~~~~~~~~~~~~~~~~~~
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
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-07-12 16:34 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-06 17:37 [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Anup Patel
2023-07-06 17:37 ` [kvmtool PATCH v3 1/8] Sync-up headers with Linux-6.4 Anup Patel
2023-07-06 17:37 ` [kvmtool PATCH v3 2/8] riscv: Allow setting custom mvendorid, marchid, and mimpid Anup Patel
2023-07-06 17:37 ` [kvmtool PATCH v3 3/8] riscv: Allow disabling SBI extensions for Guest Anup Patel
2023-07-06 17:38 ` [kvmtool PATCH v3 4/8] riscv: Sort the ISA extension array alphabetically Anup Patel
2023-07-06 17:38 ` [kvmtool PATCH v3 5/8] riscv: Add zbb extension support Anup Patel
2023-07-06 17:38 ` [kvmtool PATCH v3 6/8] riscv: Add Zicboz " Anup Patel
2023-07-06 17:38 ` [kvmtool PATCH v3 7/8] riscv: Add Ssaia " Anup Patel
2023-07-06 17:38 ` [kvmtool PATCH v3 8/8] riscv: Fix guest RAM alloc size computation for RV32 Anup Patel
2023-07-12 16:10 ` [kvmtool PATCH v3 0/8] RISC-V SBI enable/disable, Zbb, Zicboz, and Ssaia support Will Deacon
2023-07-12 16:33 ` Anup Patel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).