Skip to contentSkip to conversation

i386/kvm/hyper-v: refactor and implement 'hv-stimer-direct' and 'hv-all' enlightenments

RFC PATCH Superseded Vitaly Kuznetsov 6 participants 21 messages Jan 25, 2019 – Feb 2, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover i386/kvm/hyper-v: refactor and implement 'hv-stimer-direct' and 'hv-all' enlightenments

The recently introduced Direct Mode for Hyper-V synthetic timers enlightenment is only exposed through KVM_GET_SUPPORTED_HV_CPUID ioctl. Take the opportunity and re-implement the way we handle Hyper-V enlightenments in QEMU, add support for hv-stimer-direct and 'hv-all' pass-through mode, add missing dependencies between enlightenments.

RFC: we could've been more conservative and only use KVM_GET_SUPPORTED_HV_CPUID for new enlightenments. I'd also like to know what you think about the 'pass-through' approach taken to implement 'hv-all' mode: we could've kept QEMU filling in signature, vendor,... but we take CPUIDs passed by KVM 'as-is'.

Vitaly Kuznetsov (8):
Update linux headers (5.0-rc2)
i386/kvm: add support for KVM_GET_SUPPORTED_HV_CPUID i386/kvm: move Hyper-V CPUID filling to hyperv_handle_properties() i386/kvm: Implement 'hv-all' pass-through mode i386/kvm: hv-evmcs requires hv-vapic
i386/kvm: hv-stimer requires hv-time and hv-synic i386/kvm: hv-tlbflush/ipi require hv-vpindex
i386/kvm: add support for Direct Mode for Hyper-V synthetic timers

 include/standard-headers/drm/drm_fourcc.h     |   63 +
 include/standard-headers/linux/ethtool.h      |   19 +-
 .../linux/input-event-codes.h                 |   19 +
 include/standard-headers/linux/pci_regs.h     |    1 +
 .../standard-headers/linux/virtio_balloon.h   |    8 +
 include/standard-headers/linux/virtio_blk.h   |   54 +
 .../standard-headers/linux/virtio_config.h    |    3 +
 include/standard-headers/linux/virtio_gpu.h   |   18 +
 include/standard-headers/linux/virtio_ring.h  |   52 +
 linux-headers/asm-arm/unistd-common.h         |    1 +
 linux-headers/asm-arm64/unistd.h              |    1 +
 linux-headers/asm-generic/unistd.h            |   10 +-
 linux-headers/asm-mips/sgidefs.h              |    8 -
 linux-headers/asm-mips/unistd.h               | 1074 +----------------
 linux-headers/asm-mips/unistd_n64.h           |  334 +++++
 linux-headers/asm-mips/unistd_o32.h           |  374 ++++++
 linux-headers/asm-powerpc/unistd.h            |  389 +-----
 linux-headers/asm-powerpc/unistd_32.h         |  381 ++++++
 linux-headers/asm-powerpc/unistd_64.h         |  372 ++++++
 linux-headers/linux/kvm.h                     |   29 +
 linux-headers/linux/vfio.h                    |   92 ++
 linux-headers/linux/vhost.h                   |  113 +-
 linux-headers/linux/vhost_types.h             |  128 ++
 scripts/update-linux-headers.sh               |   10 +-
 target/i386/cpu.c                             |    2 +
 target/i386/cpu.h                             |    2 +
 target/i386/hyperv-proto.h                    |    1 +
 target/i386/kvm.c                             |  749 +++++++++---
 28 files changed, 2533 insertions(+), 1774 deletions(-)
 create mode 100644 linux-headers/asm-mips/unistd_n64.h
 create mode 100644 linux-headers/asm-mips/unistd_o32.h
 create mode 100644 linux-headers/asm-powerpc/unistd_32.h
 create mode 100644 linux-headers/asm-powerpc/unistd_64.h
 create mode 100644 linux-headers/linux/vhost_types.h
Signature · 1 line
2.20.1
#1 lore raw

RFC PATCH 1/8 Update linux headers (5.0-rc2)

---
 include/standard-headers/drm/drm_fourcc.h     |   63 +
 include/standard-headers/linux/ethtool.h      |   19 +-
 .../linux/input-event-codes.h                 |   19 +
 include/standard-headers/linux/pci_regs.h     |    1 +
 .../standard-headers/linux/virtio_balloon.h   |    8 +
 include/standard-headers/linux/virtio_blk.h   |   54 +
 .../standard-headers/linux/virtio_config.h    |    3 +
 include/standard-headers/linux/virtio_gpu.h   |   18 +
 include/standard-headers/linux/virtio_ring.h  |   52 +
 linux-headers/asm-arm/unistd-common.h         |    1 +
 linux-headers/asm-arm64/unistd.h              |    1 +
 linux-headers/asm-generic/unistd.h            |   10 +-
 linux-headers/asm-mips/sgidefs.h              |    8 -
 linux-headers/asm-mips/unistd.h               | 1074 +----------------
 linux-headers/asm-mips/unistd_n64.h           |  334 +++++
 linux-headers/asm-mips/unistd_o32.h           |  374 ++++++
 linux-headers/asm-powerpc/unistd.h            |  389 +-----
 linux-headers/asm-powerpc/unistd_32.h         |  381 ++++++
 linux-headers/asm-powerpc/unistd_64.h         |  372 ++++++
 linux-headers/linux/kvm.h                     |   29 +
 linux-headers/linux/vfio.h                    |   92 ++
 linux-headers/linux/vhost.h                   |  113 +-
 linux-headers/linux/vhost_types.h             |  128 ++
 scripts/update-linux-headers.sh               |   10 +-
 24 files changed, 1963 insertions(+), 1590 deletions(-)
 create mode 100644 linux-headers/asm-mips/unistd_n64.h
 create mode 100644 linux-headers/asm-mips/unistd_o32.h
 create mode 100644 linux-headers/asm-powerpc/unistd_32.h
 create mode 100644 linux-headers/asm-powerpc/unistd_64.h
 create mode 100644 linux-headers/linux/vhost_types.h
include/standard-headers/drm/drm_fourcc.h +63 -0
index b53f8d7c8c..44490607f9 100644
@@ -29,11 +29,50 @@
 extern "C" {
 #endif
 
+/**
+ * DOC: overview
+ *
+ * In the DRM subsystem, framebuffer pixel formats are described using the
+ * fourcc codes defined in `include/uapi/drm/drm_fourcc.h`. In addition to the
+ * fourcc code, a Format Modifier may optionally be provided, in order to
+ * further describe the buffer's format - for example tiling or compression.
+ *
+ * Format Modifiers
+ * ----------------
+ *
+ * Format modifiers are used in conjunction with a fourcc code, forming a
+ * unique fourcc:modifier pair. This format:modifier pair must fully define the
+ * format and data layout of the buffer, and should be the only way to describe
+ * that particular buffer.
+ *
+ * Having multiple fourcc:modifier pairs which describe the same layout should
+ * be avoided, as such aliases run the risk of different drivers exposing
+ * different names for the same data format, forcing userspace to understand
+ * that they are aliases.
+ *
+ * Format modifiers may change any property of the buffer, including the number
+ * of planes and/or the required allocation size. Format modifiers are
+ * vendor-namespaced, and as such the relationship between a fourcc code and a
+ * modifier is specific to the modifer being used. For example, some modifiers
+ * may preserve meaning - such as number of planes - from the fourcc code,
+ * whereas others may not.
+ *
+ * Vendors should document their modifier usage in as much detail as
+ * possible, to ensure maximum compatibility across devices, drivers and
+ * applications.
+ *
+ * The authoritative list of format modifier codes is found in
+ * `include/uapi/drm/drm_fourcc.h`
+ */
+
 #define fourcc_code(a, b, c, d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \
 				 ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
 
 #define DRM_FORMAT_BIG_ENDIAN (1<<31) /* format is big endian instead of little endian */
 
+/* Reserve 0 for the invalid format specifier */
+#define DRM_FORMAT_INVALID	0
+
 /* color index */
 #define DRM_FORMAT_C8		fourcc_code('C', '8', ' ', ' ') /* [7:0] C */
 
@@ -111,6 +150,21 @@ extern "C" {
 #define DRM_FORMAT_VYUY		fourcc_code('V', 'Y', 'U', 'Y') /* [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian */
 
 #define DRM_FORMAT_AYUV		fourcc_code('A', 'Y', 'U', 'V') /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */
+#define DRM_FORMAT_XYUV8888		fourcc_code('X', 'Y', 'U', 'V') /* [31:0] X:Y:Cb:Cr 8:8:8:8 little endian */
+
+/*
+ * packed YCbCr420 2x2 tiled formats
+ * first 64 bits will contain Y,Cb,Cr components for a 2x2 tile
+ */
+/* [63:0]   A3:A2:Y3:0:Cr0:0:Y2:0:A1:A0:Y1:0:Cb0:0:Y0:0  1:1:8:2:8:2:8:2:1:1:8:2:8:2:8:2 little endian */
+#define DRM_FORMAT_Y0L0		fourcc_code('Y', '0', 'L', '0')
+/* [63:0]   X3:X2:Y3:0:Cr0:0:Y2:0:X1:X0:Y1:0:Cb0:0:Y0:0  1:1:8:2:8:2:8:2:1:1:8:2:8:2:8:2 little endian */
+#define DRM_FORMAT_X0L0		fourcc_code('X', '0', 'L', '0')
+
+/* [63:0]   A3:A2:Y3:Cr0:Y2:A1:A0:Y1:Cb0:Y0  1:1:10:10:10:1:1:10:10:10 little endian */
+#define DRM_FORMAT_Y0L2		fourcc_code('Y', '0', 'L', '2')
+/* [63:0]   X3:X2:Y3:Cr0:Y2:X1:X0:Y1:Cb0:Y0  1:1:10:10:10:1:1:10:10:10 little endian */
+#define DRM_FORMAT_X0L2		fourcc_code('X', '0', 'L', '2')
 
 /*
  * 2 plane RGB + A
@@ -298,6 +352,15 @@ extern "C" {
  */
 #define DRM_FORMAT_MOD_SAMSUNG_64_32_TILE	fourcc_mod_code(SAMSUNG, 1)
 
+/*
+ * Tiled, 16 (pixels) x 16 (lines) - sized macroblocks
+ *
+ * This is a simple tiled layout using tiles of 16x16 pixels in a row-major
+ * layout. For YCbCr formats Cb/Cr components are taken in such a way that
+ * they correspond to their 16x16 luma block.
+ */
+#define DRM_FORMAT_MOD_SAMSUNG_16_16_TILE	fourcc_mod_code(SAMSUNG, 2)
+
 /*
  * Qualcomm Compressed Format
  *
include/standard-headers/linux/ethtool.h +5 -14
index 57ffcb5341..063c814278 100644
@@ -91,10 +91,6 @@
  * %ETHTOOL_GSET to get the current values before making specific
  * changes and then applying them with %ETHTOOL_SSET.
  *
- * Drivers that implement set_settings() should validate all fields
- * other than @cmd that are not described as read-only or deprecated,
- * and must ignore all fields described as read-only.
- *
  * Deprecated fields should be ignored by both users and drivers.
  */
 struct ethtool_cmd {
@@ -886,7 +882,7 @@ struct ethtool_rx_flow_spec {
 	uint32_t		location;
 };
 
-/* How rings are layed out when accessing virtual functions or
+/* How rings are laid out when accessing virtual functions or
  * offloaded queues is device specific. To allow users to do flow
  * steering and specify these queues the ring cookie is partitioned
  * into a 32bit queue index with an 8 bit virtual function id.
@@ -895,7 +891,7 @@ struct ethtool_rx_flow_spec {
  * devices start supporting PCIe w/ARI. However at the moment I
  * do not know of any devices that support this so I do not reserve
  * space for this at this time. If a future patch consumes the next
- * byte it should be aware of this possiblity.
+ * byte it should be aware of this possibility.
  */
 #define ETHTOOL_RX_FLOW_SPEC_RING	0x00000000FFFFFFFFLL
 #define ETHTOOL_RX_FLOW_SPEC_RING_VF	0x000000FF00000000LL
@@ -1800,14 +1796,9 @@ enum ethtool_reset_flags {
  * rejected.
  *
  * Deprecated %ethtool_cmd fields transceiver, maxtxpkt and maxrxpkt
- * are not available in %ethtool_link_settings. Until all drivers are
- * converted to ignore them or to the new %ethtool_link_settings API,
- * for both queries and changes, users should always try
- * %ETHTOOL_GLINKSETTINGS first, and if it fails with -ENOTSUPP stick
- * only to %ETHTOOL_GSET and %ETHTOOL_SSET consistently. If it
- * succeeds, then users should stick to %ETHTOOL_GLINKSETTINGS and
- * %ETHTOOL_SLINKSETTINGS (which would support drivers implementing
- * either %ethtool_cmd or %ethtool_link_settings).
+ * are not available in %ethtool_link_settings. These fields will be
+ * always set to zero in %ETHTOOL_GSET reply and %ETHTOOL_SSET will
+ * fail if any of them is set to non-zero value.
  *
  * Users should assume that all fields not marked read-only are
  * writable and subject to validation by the driver.  They should use
include/standard-headers/linux/input-event-codes.h +19 -0
index 9e6a8ba4ce..ff2e1ebcc9 100644
@@ -708,6 +708,16 @@
 #define REL_DIAL		0x07
 #define REL_WHEEL		0x08
 #define REL_MISC		0x09
+/*
+ * 0x0a is reserved and should not be used in input drivers.
+ * It was used by HID as REL_MISC+1 and userspace needs to detect if
+ * the next REL_* event is correct or is just REL_MISC + n.
+ * We define here REL_RESERVED so userspace can rely on it and detect
+ * the situation described above.
+ */
+#define REL_RESERVED		0x0a
+#define REL_WHEEL_HI_RES	0x0b
+#define REL_HWHEEL_HI_RES	0x0c
 #define REL_MAX			0x0f
 #define REL_CNT			(REL_MAX+1)
 
@@ -744,6 +754,15 @@
 
 #define ABS_MISC		0x28
 
+/*
+ * 0x2e is reserved and should not be used in input drivers.
+ * It was used by HID as ABS_MISC+6 and userspace needs to detect if
+ * the next ABS_* event is correct or is just ABS_MISC + n.
+ * We define here ABS_RESERVED so userspace can rely on it and detect
+ * the situation described above.
+ */
+#define ABS_RESERVED		0x2e
+
 #define ABS_MT_SLOT		0x2f	/* MT slot being modified */
 #define ABS_MT_TOUCH_MAJOR	0x30	/* Major axis of touching ellipse */
 #define ABS_MT_TOUCH_MINOR	0x31	/* Minor axis (omit if circular) */
include/standard-headers/linux/pci_regs.h +1 -0
index ee556ccc93..e1e9888c85 100644
@@ -52,6 +52,7 @@
 #define  PCI_COMMAND_INTX_DISABLE 0x400 /* INTx Emulation Disable */
 
 #define PCI_STATUS		0x06	/* 16 bits */
+#define  PCI_STATUS_IMM_READY	0x01	/* Immediate Readiness */
 #define  PCI_STATUS_INTERRUPT	0x08	/* Interrupt status */
 #define  PCI_STATUS_CAP_LIST	0x10	/* Support Capability List */
 #define  PCI_STATUS_66MHZ	0x20	/* Support 66 MHz PCI 2.1 bus */
include/standard-headers/linux/virtio_balloon.h +8 -0
index 4dbb7dc6c0..9375ca2a70 100644
@@ -34,15 +34,23 @@
 #define VIRTIO_BALLOON_F_MUST_TELL_HOST	0 /* Tell before reclaiming pages */
 #define VIRTIO_BALLOON_F_STATS_VQ	1 /* Memory Stats virtqueue */
 #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM	2 /* Deflate balloon on OOM */
+#define VIRTIO_BALLOON_F_FREE_PAGE_HINT	3 /* VQ to report free pages */
+#define VIRTIO_BALLOON_F_PAGE_POISON	4 /* Guest is using page poisoning */
 
 /* Size of a PFN in the balloon interface. */
 #define VIRTIO_BALLOON_PFN_SHIFT 12
 
+#define VIRTIO_BALLOON_CMD_ID_STOP	0
+#define VIRTIO_BALLOON_CMD_ID_DONE	1
 struct virtio_balloon_config {
 	/* Number of pages host wants Guest to give up. */
 	uint32_t num_pages;
 	/* Number of pages we've actually got in balloon. */
 	uint32_t actual;
+	/* Free page report command id, readonly by guest */
+	uint32_t free_page_report_cmd_id;
+	/* Stores PAGE_POISON if page poisoning is in use */
+	uint32_t poison_val;
 };
 
 #define VIRTIO_BALLOON_S_SWAP_IN  0   /* Amount of memory swapped in */
include/standard-headers/linux/virtio_blk.h +54 -0

78 lines not on this page · raw message

include/standard-headers/linux/virtio_config.h +3 -0
index 0b194365a0..24e30af5ec 100644
@@ -75,6 +75,9 @@
  */
 #define VIRTIO_F_IOMMU_PLATFORM		33
 
+/* This feature indicates support for the packed virtqueue layout. */
+#define VIRTIO_F_RING_PACKED		34
+
 /*
  * Does the device support Single Root I/O Virtualization?
  */
include/standard-headers/linux/virtio_gpu.h +18 -0
index 52a830dcf8..27bb5111f9 100644
@@ -41,6 +41,7 @@
 #include "standard-headers/linux/types.h"
 
 #define VIRTIO_GPU_F_VIRGL 0
+#define VIRTIO_GPU_F_EDID  1
 
 enum virtio_gpu_ctrl_type {
 	VIRTIO_GPU_UNDEFINED = 0,
@@ -56,6 +57,7 @@ enum virtio_gpu_ctrl_type {
 	VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING,
 	VIRTIO_GPU_CMD_GET_CAPSET_INFO,
 	VIRTIO_GPU_CMD_GET_CAPSET,
+	VIRTIO_GPU_CMD_GET_EDID,
 
 	/* 3d commands */
 	VIRTIO_GPU_CMD_CTX_CREATE = 0x0200,
@@ -76,6 +78,7 @@ enum virtio_gpu_ctrl_type {
 	VIRTIO_GPU_RESP_OK_DISPLAY_INFO,
 	VIRTIO_GPU_RESP_OK_CAPSET_INFO,
 	VIRTIO_GPU_RESP_OK_CAPSET,
+	VIRTIO_GPU_RESP_OK_EDID,
 
 	/* error responses */
 	VIRTIO_GPU_RESP_ERR_UNSPEC = 0x1200,
@@ -291,6 +294,21 @@ struct virtio_gpu_resp_capset {
 	uint8_t capset_data[];
 };
 
+/* VIRTIO_GPU_CMD_GET_EDID */
+struct virtio_gpu_cmd_get_edid {
+	struct virtio_gpu_ctrl_hdr hdr;
+	uint32_t scanout;
+	uint32_t padding;
+};
+
+/* VIRTIO_GPU_RESP_OK_EDID */
+struct virtio_gpu_resp_edid {
+	struct virtio_gpu_ctrl_hdr hdr;
+	uint32_t size;
+	uint32_t padding;
+	uint8_t edid[1024];
+};
+
 #define VIRTIO_GPU_EVENT_DISPLAY (1 << 0)
 
 struct virtio_gpu_config {
include/standard-headers/linux/virtio_ring.h +52 -0

68 lines not on this page · raw message

linux-headers/asm-arm/unistd-common.h +1 -0
index 60c2d931d0..8c84bcf10f 100644
@@ -355,5 +355,6 @@
 #define __NR_pkey_free (__NR_SYSCALL_BASE + 396)
 #define __NR_statx (__NR_SYSCALL_BASE + 397)
 #define __NR_rseq (__NR_SYSCALL_BASE + 398)
+#define __NR_io_pgetevents (__NR_SYSCALL_BASE + 399)
 
 #endif /* _ASM_ARM_UNISTD_COMMON_H */
linux-headers/asm-arm64/unistd.h +1 -0
index 5072cbd15c..dae1584cf0 100644
@@ -16,5 +16,6 @@
  */
 
 #define __ARCH_WANT_RENAMEAT
+#define __ARCH_WANT_NEW_STAT
 
 #include <asm-generic/unistd.h>
linux-headers/asm-generic/unistd.h +9 -1
index df4bedb9b0..d90127298f 100644
@@ -242,10 +242,12 @@ __SYSCALL(__NR_tee, sys_tee)
 /* fs/stat.c */
 #define __NR_readlinkat 78
 __SYSCALL(__NR_readlinkat, sys_readlinkat)
+#if defined(__ARCH_WANT_NEW_STAT) || defined(__ARCH_WANT_STAT64)
 #define __NR3264_fstatat 79
 __SC_3264(__NR3264_fstatat, sys_fstatat64, sys_newfstatat)
 #define __NR3264_fstat 80
 __SC_3264(__NR3264_fstat, sys_fstat64, sys_newfstat)
+#endif
 
 /* fs/sync.c */
 #define __NR_sync 81
@@ -736,9 +738,11 @@ __SYSCALL(__NR_statx,     sys_statx)
 __SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents)
 #define __NR_rseq 293
 __SYSCALL(__NR_rseq, sys_rseq)
+#define __NR_kexec_file_load 294
+__SYSCALL(__NR_kexec_file_load,     sys_kexec_file_load)
 
 #undef __NR_syscalls
-#define __NR_syscalls 294
+#define __NR_syscalls 295
 
 /*
  * 32 bit systems traditionally used different
@@ -758,8 +762,10 @@ __SYSCALL(__NR_rseq, sys_rseq)
 #define __NR_ftruncate __NR3264_ftruncate
 #define __NR_lseek __NR3264_lseek
 #define __NR_sendfile __NR3264_sendfile
+#if defined(__ARCH_WANT_NEW_STAT) || defined(__ARCH_WANT_STAT64)
 #define __NR_newfstatat __NR3264_fstatat
 #define __NR_fstat __NR3264_fstat
+#endif
 #define __NR_mmap __NR3264_mmap
 #define __NR_fadvise64 __NR3264_fadvise64
 #ifdef __NR3264_stat
@@ -774,8 +780,10 @@ __SYSCALL(__NR_rseq, sys_rseq)
 #define __NR_ftruncate64 __NR3264_ftruncate
 #define __NR_llseek __NR3264_lseek
 #define __NR_sendfile64 __NR3264_sendfile
+#if defined(__ARCH_WANT_NEW_STAT) || defined(__ARCH_WANT_STAT64)
 #define __NR_fstatat64 __NR3264_fstatat
 #define __NR_fstat64 __NR3264_fstat
+#endif
 #define __NR_mmap2 __NR3264_mmap
 #define __NR_fadvise64_64 __NR3264_fadvise64
 #ifdef __NR3264_stat
linux-headers/asm-mips/sgidefs.h +0 -8
index 26143e3b7c..69c3de90c5 100644
@@ -11,14 +11,6 @@
 #ifndef __ASM_SGIDEFS_H
 #define __ASM_SGIDEFS_H
 
-/*
- * Using a Linux compiler for building Linux seems logic but not to
- * everybody.
- */
-#ifndef __linux__
-#error Use a Linux compiler or give up.
-#endif
-
 /*
  * Definitions for the ISA levels
  *
linux-headers/asm-mips/unistd.h +6 -1068

1,091 lines not on this page · raw message

linux-headers/asm-mips/unistd_n64.h new file +334 -0

334 lines not on this page · raw message

linux-headers/asm-mips/unistd_o32.h new file +374 -0

374 lines not on this page · raw message

linux-headers/asm-powerpc/unistd.h +2 -387

397 lines not on this page · raw message

linux-headers/asm-powerpc/unistd_32.h new file +381 -0

347 lines not on this page · raw message

linux-headers/asm-powerpc/unistd_64.h new file +372 -0

372 lines not on this page · raw message

linux-headers/linux/kvm.h +29 -0
index f11a7eb49c..b53ee59748 100644

Lines of this file are not shown. View the raw message.

linux-headers/linux/vfio.h +92 -0

92 lines not on this page · raw message

linux-headers/linux/vhost.h +2 -111

113 lines not on this page · raw message

linux-headers/linux/vhost_types.h new file +128 -0

128 lines not on this page · raw message

scripts/update-linux-headers.sh +9 -1
index 0a964fe240..58b25d4a39 100755

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.20.1

Part of the diff is not shown here. View the raw message.

#2 lore raw

RFC PATCH 2/8 i386/kvm: add support for KVM_GET_SUPPORTED_HV_CPUID

In reply to Vitaly Kuznetsov

KVM now supports reporting supported Hyper-V features through CPUID (KVM_GET_SUPPORTED_HV_CPUID ioctl). Going forward, this is going to be the only way to announce new functionality and this has already happened with Direct Mode stimers.

While we could just support KVM_GET_SUPPORTED_HV_CPUID for new features, it seems to be beneficial to use it for all Hyper-V enlightenments when possible. This was we can implement 'hv-all' pass-through mode giving the guest all supported Hyper-V features even when QEMU knows nothing about them.

Implementation-wise we create a new kvm_hyperv_properties structure defining Hyper-V features, get_supported_hv_cpuid()/ get_supported_hv_cpuid_legacy() returning the supported CPUID set and a bit over-engineered hv_cpuid_check_and_set() which we will also be used to set cpu->hyperv_* properties for 'hv-all' mode.

---
 target/i386/kvm.c | 487 +++++++++++++++++++++++++++++++++++-----------
 1 file changed, 372 insertions(+), 115 deletions(-)
target/i386/kvm.c +372 -115
index 9af4542fb8..dc4574daff 100644
@@ -691,141 +691,360 @@ static bool tsc_is_stable_and_known(CPUX86State *env)
         || env->user_tsc_khz;
 }
 
-static int hyperv_handle_properties(CPUState *cs)
+static struct {
+    const char *name;
+    const char *desc;
+    struct {
+        uint32_t fw;
+        uint32_t bits;
+    } flags[2];
+} kvm_hyperv_properties[] = {
+    {
+        .name = "hv-relaxed",
+        .desc = "relaxed timing",
+        .flags = {
+            {.fw = FEAT_HYPERV_EAX,
+             .bits = HV_HYPERCALL_AVAILABLE},
+            {.fw = FEAT_HV_RECOMM_EAX,
+             .bits = HV_RELAXED_TIMING_RECOMMENDED}
+        }
+    },
+    {
+        .name = "hv-vapic",
+        .desc = "virtual APIC",
+        .flags = {
+            {.fw = FEAT_HYPERV_EAX,
+             .bits = HV_HYPERCALL_AVAILABLE | HV_APIC_ACCESS_AVAILABLE},
+            {.fw = FEAT_HV_RECOMM_EAX,
+             .bits = HV_APIC_ACCESS_RECOMMENDED}
+        }
+    },
+    {
+        .name = "hv-time",
+        .desc = "clocksources",
+        .flags = {
+            {.fw = FEAT_HYPERV_EAX,
+             .bits = HV_HYPERCALL_AVAILABLE | HV_TIME_REF_COUNT_AVAILABLE |
+             HV_REFERENCE_TSC_AVAILABLE},
+            {0}
+        }
+    },
+    {
+        .name = "hv-frequencies",
+        .desc = "frequency MSRs",
+        .flags = {
+            {.fw = FEAT_HYPERV_EAX,
+             .bits = HV_ACCESS_FREQUENCY_MSRS},
+            {.fw = FEAT_HYPERV_EDX,
+             .bits = HV_FREQUENCY_MSRS_AVAILABLE}
+        }
+    },
+    {
+        .name = "hv-crash",
+        .desc = "crash MSRs",
+        .flags = {
+            {.fw = FEAT_HYPERV_EDX,
+             .bits = HV_GUEST_CRASH_MSR_AVAILABLE},
+            {0}
+        }
+    },
+    {
+        .name = "hv-reenlightenment",
+        .desc = "Reenlightenment MSRs",
+        .flags = {
+            {.fw = FEAT_HYPERV_EAX,
+             .bits = HV_ACCESS_REENLIGHTENMENTS_CONTROL},
+            {0}
+        }
+    },
+    {
+        .name = "hv-reset",
+        .desc = "reset MSR",
+        .flags = {
+            {.fw = FEAT_HYPERV_EAX,
+             .bits = HV_RESET_AVAILABLE},
+            {0}
+        }
+    },
+    {
+        .name = "hv-vpindex",
+        .desc = "VP_INDEX MSR",
+        .flags = {
+            {.fw = FEAT_HYPERV_EAX,
+             .bits = HV_VP_INDEX_AVAILABLE},
+            {0}
+        }
+    },
+    {
+        .name = "hv-runtime",
+        .desc = "VP_RUNTIME MSR",
+        .flags = {
+            {.fw = FEAT_HYPERV_EAX,
+             .bits = HV_VP_RUNTIME_AVAILABLE},
+            {0}
+        }
+    },
+    {
+        .name = "hv-synic",
+        .desc = "SynIC",
+        .flags = {
+            {.fw = FEAT_HYPERV_EAX,
+             .bits = HV_SYNIC_AVAILABLE},
+            {0}
+        }
+    },
+    {
+        .name = "hv-stimer",
+        .desc = "timers",
+        .flags = {
+            {.fw = FEAT_HYPERV_EAX,
+             .bits = HV_SYNTIMERS_AVAILABLE},
+            {0}
+        }
+    },
+    {
+        .name = "hv-tlbflush",
+        .desc = "TLB flush support",
+        .flags = {
+            {.fw = FEAT_HV_RECOMM_EAX,
+             .bits = HV_REMOTE_TLB_FLUSH_RECOMMENDED |
+             HV_EX_PROCESSOR_MASKS_RECOMMENDED},
+            {0}
+        }
+    },
+    {
+        .name = "hv-ipi",
+        .desc = "IPI send support",
+        .flags = {
+            {.fw = FEAT_HV_RECOMM_EAX,
+             .bits = HV_CLUSTER_IPI_RECOMMENDED |
+             HV_EX_PROCESSOR_MASKS_RECOMMENDED},
+            {0}
+        }
+    },
+};
+
+static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max)
+{
+    struct kvm_cpuid2 *cpuid;
+    int r, size;
+
+    size = sizeof(*cpuid) + max * sizeof(*cpuid->entries);
+    cpuid = g_malloc0(size);
+    cpuid->nent = max;
+
+    r = kvm_vcpu_ioctl(cs, KVM_GET_SUPPORTED_HV_CPUID, cpuid);
+    if (r == 0 && cpuid->nent >= max) {
+        r = -E2BIG;
+    }
+    if (r < 0) {
+        if (r == -E2BIG) {
+            g_free(cpuid);
+            return NULL;
+        } else {
+            fprintf(stderr, "KVM_GET_SUPPORTED_HV_CPUID failed: %s\n",
+                    strerror(-r));
+            exit(1);
+        }
+    }
+    return cpuid;
+}
+
+/*
+ * Run KVM_GET_SUPPORTED_HV_CPUID ioctl(), allocating a buffer large enough
+ * for all entries.
+ */
+static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUState *cs)
+{
+    struct kvm_cpuid2 *cpuid;
+    int max = 7; /* 0x40000000..0x40000005, 0x4000000A */
+
+    while ((cpuid = try_get_hv_cpuid(cs, max)) == NULL) {
+        max++;
+    }
+    return cpuid;
+}
+
+/*
+ * When KVM_GET_SUPPORTED_HV_CPUID is not supported we fill CPUID feature
+ * leaves from KVM_CAP_HYPERV* and present MSRs data.
+ */
+static struct kvm_cpuid2 *get_supported_hv_cpuid_legacy(CPUState *cs)
 {
     X86CPU *cpu = X86_CPU(cs);
-    CPUX86State *env = &cpu->env;
+    struct kvm_cpuid2 *cpuid;
+    struct kvm_cpuid_entry2 *entry_feat, *entry_recomm;
+
+    /* HV_CPUID_FEATURES, HV_CPUID_ENLIGHTMENT_INFO */
+    cpuid = g_malloc0(sizeof(*cpuid) + 2 * sizeof(*cpuid->entries));
+    cpuid->nent = 2;
+
+    /* HV_CPUID_VENDOR_AND_MAX_FUNCTIONS */
+    entry_feat = &cpuid->entries[0];
+    entry_feat->function = HV_CPUID_FEATURES;
+
+    entry_recomm = &cpuid->entries[1];
+    entry_recomm->function = HV_CPUID_ENLIGHTMENT_INFO;
 
-    if (cpu->hyperv_relaxed_timing) {
-        env->features[FEAT_HYPERV_EAX] |= HV_HYPERCALL_AVAILABLE;
+    if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0) {
+        entry_feat->eax |= HV_HYPERCALL_AVAILABLE;
+        entry_feat->eax |= HV_APIC_ACCESS_AVAILABLE;
+        entry_feat->edx |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE;
+        entry_recomm->eax |= HV_RELAXED_TIMING_RECOMMENDED;
+        entry_recomm->eax |= HV_APIC_ACCESS_RECOMMENDED;
     }
-    if (cpu->hyperv_vapic) {
-        env->features[FEAT_HYPERV_EAX] |= HV_HYPERCALL_AVAILABLE;
-        env->features[FEAT_HYPERV_EAX] |= HV_APIC_ACCESS_AVAILABLE;
+
+    if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_TIME) > 0) {
+        entry_feat->eax |= HV_TIME_REF_COUNT_AVAILABLE;
+        entry_feat->eax |= HV_REFERENCE_TSC_AVAILABLE;
     }
-    if (cpu->hyperv_time) {
-        if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_TIME) <= 0) {
-            fprintf(stderr, "Hyper-V clocksources "
-                    "(requested by 'hv-time' cpu flag) "
-                    "are not supported by kernel\n");
-            return -ENOSYS;
-        }
-        env->features[FEAT_HYPERV_EAX] |= HV_HYPERCALL_AVAILABLE;
-        env->features[FEAT_HYPERV_EAX] |= HV_TIME_REF_COUNT_AVAILABLE;
-        env->features[FEAT_HYPERV_EAX] |= HV_REFERENCE_TSC_AVAILABLE;
+
+    if (has_msr_hv_frequencies) {
+        entry_feat->eax |= HV_ACCESS_FREQUENCY_MSRS;
+        entry_feat->edx |= HV_FREQUENCY_MSRS_AVAILABLE;
     }
-    if (cpu->hyperv_frequencies) {
-        if (!has_msr_hv_frequencies) {
-            fprintf(stderr, "Hyper-V frequency MSRs "
-                    "(requested by 'hv-frequencies' cpu flag) "
-                    "are not supported by kernel\n");
-            return -ENOSYS;
-        }
-        env->features[FEAT_HYPERV_EAX] |= HV_ACCESS_FREQUENCY_MSRS;
-        env->features[FEAT_HYPERV_EDX] |= HV_FREQUENCY_MSRS_AVAILABLE;
+
+    if (has_msr_hv_crash) {
+        entry_feat->edx |= HV_GUEST_CRASH_MSR_AVAILABLE;
     }
-    if (cpu->hyperv_crash) {
-        if (!has_msr_hv_crash) {
-            fprintf(stderr, "Hyper-V crash MSRs "
-                    "(requested by 'hv-crash' cpu flag) "
-                    "are not supported by kernel\n");
-            return -ENOSYS;
-        }
-        env->features[FEAT_HYPERV_EDX] |= HV_GUEST_CRASH_MSR_AVAILABLE;
+
+    if (has_msr_hv_reenlightenment) {
+        entry_feat->eax |= HV_ACCESS_REENLIGHTENMENTS_CONTROL;
     }
-    if (cpu->hyperv_reenlightenment) {
-        if (!has_msr_hv_reenlightenment) {
-            fprintf(stderr,
-                    "Hyper-V Reenlightenment MSRs "
-                    "(requested by 'hv-reenlightenment' cpu flag) "
-                    "are not supported by kernel\n");
-            return -ENOSYS;
-        }
-        env->features[FEAT_HYPERV_EAX] |= HV_ACCESS_REENLIGHTENMENTS_CONTROL;
+
+    if (has_msr_hv_reset) {
+        entry_feat->eax |= HV_RESET_AVAILABLE;
     }
-    env->features[FEAT_HYPERV_EDX] |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE;
-    if (cpu->hyperv_reset) {
-        if (!has_msr_hv_reset) {
-            fprintf(stderr, "Hyper-V reset MSR "
-                    "(requested by 'hv-reset' cpu flag) "
-                    "is not supported by kernel\n");
-            return -ENOSYS;
-        }
-        env->features[FEAT_HYPERV_EAX] |= HV_RESET_AVAILABLE;
+
+    if (has_msr_hv_vpindex) {
+        entry_feat->eax |= HV_VP_INDEX_AVAILABLE;
     }
-    if (cpu->hyperv_vpindex) {
-        if (!has_msr_hv_vpindex) {
-            fprintf(stderr, "Hyper-V VP_INDEX MSR "
-                    "(requested by 'hv-vpindex' cpu flag) "
-                    "is not supported by kernel\n");
-            return -ENOSYS;
-        }
-        env->features[FEAT_HYPERV_EAX] |= HV_VP_INDEX_AVAILABLE;
+
+    if (has_msr_hv_runtime) {
+        entry_feat->eax |= HV_VP_RUNTIME_AVAILABLE;
     }
-    if (cpu->hyperv_runtime) {
-        if (!has_msr_hv_runtime) {
-            fprintf(stderr, "Hyper-V VP_RUNTIME MSR "
-                    "(requested by 'hv-runtime' cpu flag) "
-                    "is not supported by kernel\n");
-            return -ENOSYS;
+
+    if (has_msr_hv_synic) {
+        unsigned int cap = cpu->hyperv_synic_kvm_only ?
+            KVM_CAP_HYPERV_SYNIC : KVM_CAP_HYPERV_SYNIC2;
+
+        if (kvm_check_extension(cs->kvm_state, cap) > 0) {
+            entry_feat->eax |= HV_SYNIC_AVAILABLE;
         }
-        env->features[FEAT_HYPERV_EAX] |= HV_VP_RUNTIME_AVAILABLE;
     }
-    if (cpu->hyperv_synic) {
-        unsigned int cap = KVM_CAP_HYPERV_SYNIC;
-        if (!cpu->hyperv_synic_kvm_only) {
-            if (!cpu->hyperv_vpindex) {
-                fprintf(stderr, "Hyper-V SynIC "
-                        "(requested by 'hv-synic' cpu flag) "
-                        "requires Hyper-V VP_INDEX ('hv-vpindex')\n");
-            return -ENOSYS;
-            }
-            cap = KVM_CAP_HYPERV_SYNIC2;
-        }
 
-        if (!has_msr_hv_synic || !kvm_check_extension(cs->kvm_state, cap)) {
-            fprintf(stderr, "Hyper-V SynIC (requested by 'hv-synic' cpu flag) "
-                    "is not supported by kernel\n");
-            return -ENOSYS;
-        }
+    if (has_msr_hv_stimer) {
+        entry_feat->eax |= HV_SYNTIMERS_AVAILABLE;
+    }
 
-        env->features[FEAT_HYPERV_EAX] |= HV_SYNIC_AVAILABLE;
+    if (kvm_check_extension(cs->kvm_state,
+                            KVM_CAP_HYPERV_TLBFLUSH) > 0) {
+        entry_recomm->eax |= HV_REMOTE_TLB_FLUSH_RECOMMENDED;
+        entry_recomm->eax |= HV_EX_PROCESSOR_MASKS_RECOMMENDED;
     }
-    if (cpu->hyperv_stimer) {
-        if (!has_msr_hv_stimer) {
-            fprintf(stderr, "Hyper-V timers aren't supported by kernel\n");
-            return -ENOSYS;
-        }
-        env->features[FEAT_HYPERV_EAX] |= HV_SYNTIMERS_AVAILABLE;
+
+    if (kvm_check_extension(cs->kvm_state,
+                            KVM_CAP_HYPERV_SEND_IPI) > 0) {
+        entry_recomm->eax |= HV_CLUSTER_IPI_RECOMMENDED;
+        entry_recomm->eax |= HV_EX_PROCESSOR_MASKS_RECOMMENDED;
     }
-    if (cpu->hyperv_relaxed_timing) {
-        env->features[FEAT_HV_RECOMM_EAX] |= HV_RELAXED_TIMING_RECOMMENDED;
+
+    return cpuid;
+}
+
+static int hv_cpuid_get_fw(struct kvm_cpuid2 *cpuid, int fw, uint32_t *r)
+{
+    struct kvm_cpuid_entry2 *entry;
+    uint32_t func;
+    int reg;
+
+    switch (fw) {
+    case FEAT_HYPERV_EAX:
+        reg = R_EAX;
+        func = HV_CPUID_FEATURES;
+        break;
+    case FEAT_HYPERV_EDX:
+        reg = R_EDX;
+        func = HV_CPUID_FEATURES;
+        break;
+    case FEAT_HV_RECOMM_EAX:
+        reg = R_EAX;
+        func = HV_CPUID_ENLIGHTMENT_INFO;
+        break;
+    default:
+        return -EINVAL;
     }
-    if (cpu->hyperv_vapic) {
-        env->features[FEAT_HV_RECOMM_EAX] |= HV_APIC_ACCESS_RECOMMENDED;
-    }
-    if (cpu->hyperv_tlbflush) {
-        if (kvm_check_extension(cs->kvm_state,
-                                KVM_CAP_HYPERV_TLBFLUSH) <= 0) {
-            fprintf(stderr, "Hyper-V TLB flush support "
-                    "(requested by 'hv-tlbflush' cpu flag) "
-                    " is not supported by kernel\n");
-            return -ENOSYS;
-        }
-        env->features[FEAT_HV_RECOMM_EAX] |= HV_REMOTE_TLB_FLUSH_RECOMMENDED;
-        env->features[FEAT_HV_RECOMM_EAX] |= HV_EX_PROCESSOR_MASKS_RECOMMENDED;
+
+    entry = cpuid_find_entry(cpuid, func, 0);
+    if (!entry) {
+        return -ENOENT;
     }
-    if (cpu->hyperv_ipi) {
-        if (kvm_check_extension(cs->kvm_state,
-                                KVM_CAP_HYPERV_SEND_IPI) <= 0) {
-            fprintf(stderr, "Hyper-V IPI send support "
-                    "(requested by 'hv-ipi' cpu flag) "
-                    " is not supported by kernel\n");
-            return -ENOSYS;
+
+    switch (reg) {
+    case R_EAX:
+        *r = entry->eax;
+        break;
+    case R_EDX:
+        *r = entry->edx;
+        break;
+    default:
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid,
+                                  const char *name, bool flag)
+{
+    X86CPU *cpu = X86_CPU(cs);
+    CPUX86State *env = &cpu->env;
+    uint32_t r, fw, bits;;
+    int i, j;
+
+    if (!flag) {
+        return 0;
+    }
+
+    for (i = 0; i < ARRAY_SIZE(kvm_hyperv_properties); i++) {
+        if (strcmp(kvm_hyperv_properties[i].name, name)) {
+            continue;
         }
-        env->features[FEAT_HV_RECOMM_EAX] |= HV_CLUSTER_IPI_RECOMMENDED;
-        env->features[FEAT_HV_RECOMM_EAX] |= HV_EX_PROCESSOR_MASKS_RECOMMENDED;
+
+        for (j = 0; j < ARRAY_SIZE(kvm_hyperv_properties[i].flags); j++) {
+            fw = kvm_hyperv_properties[i].flags[j].fw;
+            bits = kvm_hyperv_properties[i].flags[j].bits;
+
+            if (!fw) {
+                continue;
+            }
+
+            if (hv_cpuid_get_fw(cpuid, fw, &r) || (r & bits) != bits) {
+                fprintf(stderr,
+                        "Hyper-V %s (requested by '%s' cpu flag) "
+                        "is not supported by kernel\n",
+                        kvm_hyperv_properties[i].desc,
+                        kvm_hyperv_properties[i].name);
+                return 1;
+            }
+
+            env->features[fw] |= bits;
+        }
+
+        return 0;
     }
+
+    /* the requested feature is undefined in kvm_hyperv_properties */
+    return 1;
+}
+
+static int hyperv_handle_properties(CPUState *cs)
+{
+    X86CPU *cpu = X86_CPU(cs);
+    CPUX86State *env = &cpu->env;
+    struct kvm_cpuid2 *cpuid;
+    int r = 0;
+
     if (cpu->hyperv_evmcs) {
         uint16_t evmcs_version;
 
@@ -840,7 +1059,45 @@ static int hyperv_handle_properties(CPUState *cs)
         env->features[FEAT_HV_NESTED_EAX] = evmcs_version;
     }
 
-    return 0;
+    if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_CPUID) > 0) {
+        cpuid = get_supported_hv_cpuid(cs);
+    } else {
+        cpuid = get_supported_hv_cpuid_legacy(cs);
+    }
+
+    /* Features */
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-relaxed",
+                                cpu->hyperv_relaxed_timing);
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-vapic", cpu->hyperv_vapic);
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-time", cpu->hyperv_time);
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-frequencies",
+                                cpu->hyperv_frequencies);
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-crash", cpu->hyperv_crash);
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-reenlightenment",
+                                cpu->hyperv_reenlightenment);
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-reset", cpu->hyperv_reset);
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-vpindex", cpu->hyperv_vpindex);
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-runtime", cpu->hyperv_runtime);
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-synic", cpu->hyperv_synic);
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-stimer", cpu->hyperv_stimer);
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-tlbflush", cpu->hyperv_tlbflush);
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-ipi", cpu->hyperv_ipi);
+
+    /* Dependencies */
+    if (cpu->hyperv_synic && !cpu->hyperv_synic_kvm_only &&
+        !cpu->hyperv_vpindex) {
+        fprintf(stderr, "Hyper-V SynIC "
+                "(requested by 'hv-synic' cpu flag) "
+                "requires Hyper-V VP_INDEX ('hv-vpindex')\n");
+        r |= 1;
+    }
+
+    /* Not exposed by KVM but needed to make CPU hotplug in Windows work */
+    env->features[FEAT_HYPERV_EDX] |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE;
+
+    g_free(cpuid);
+
+    return r ? -ENOSYS : 0;
 }
 
 static int hyperv_init_vcpu(X86CPU *cpu)
Signature · 1 line
2.20.1
#3 lore raw

RFC PATCH 3/8 i386/kvm: move Hyper-V CPUID filling to hyperv_handle_properties()

In reply to Vitaly Kuznetsov

Let's consolidate Hyper-V features handling in hyperv_handle_properties(). The change is necessary to support pass-through 'hv-all' mode as we'll be just copying CPUIDs from KVM instead of filling them in.

---
 target/i386/kvm.c | 163 +++++++++++++++++++++++++---------------------
 1 file changed, 90 insertions(+), 73 deletions(-)
target/i386/kvm.c +90 -73
index dc4574daff..ed55040d9e 100644
@@ -1038,13 +1038,25 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid,
     return 1;
 }
 
-static int hyperv_handle_properties(CPUState *cs)
+/*
+ * Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_ent in
+ * case of success, errno < 0 in case of failure and 0 when no Hyper-V
+ * extentions are enabled.
+ */
+static int hyperv_handle_properties(CPUState *cs,
+                                    struct kvm_cpuid_entry2 *cpuid_ent)
 {
     X86CPU *cpu = X86_CPU(cs);
     CPUX86State *env = &cpu->env;
     struct kvm_cpuid2 *cpuid;
+    struct kvm_cpuid_entry2 *c;
+    uint32_t signature[3];
+    uint32_t cpuid_i = 0;
     int r = 0;
 
+    if (!hyperv_enabled(cpu))
+        return 0;
+
     if (cpu->hyperv_evmcs) {
         uint16_t evmcs_version;
 
@@ -1095,9 +1107,80 @@ static int hyperv_handle_properties(CPUState *cs)
     /* Not exposed by KVM but needed to make CPU hotplug in Windows work */
     env->features[FEAT_HYPERV_EDX] |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE;
 
+    if (r) {
+        r = -ENOSYS;
+        goto free;
+    }
+
+    c = &cpuid_ent[cpuid_i++];
+    c->function = HV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
+    if (!cpu->hyperv_vendor_id) {
+        memcpy(signature, "Microsoft Hv", 12);
+    } else {
+        size_t len = strlen(cpu->hyperv_vendor_id);
+
+        if (len > 12) {
+            error_report("hv-vendor-id truncated to 12 characters");
+            len = 12;
+        }
+        memset(signature, 0, 12);
+        memcpy(signature, cpu->hyperv_vendor_id, len);
+    }
+    c->eax = cpu->hyperv_evmcs ?
+        HV_CPUID_NESTED_FEATURES : HV_CPUID_IMPLEMENT_LIMITS;
+    c->ebx = signature[0];
+    c->ecx = signature[1];
+    c->edx = signature[2];
+
+    c = &cpuid_ent[cpuid_i++];
+    c->function = HV_CPUID_INTERFACE;
+    memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12);
+    c->eax = signature[0];
+    c->ebx = 0;
+    c->ecx = 0;
+    c->edx = 0;
+
+    c = &cpuid_ent[cpuid_i++];
+    c->function = HV_CPUID_VERSION;
+    c->eax = 0x00001bbc;
+    c->ebx = 0x00060001;
+
+    c = &cpuid_ent[cpuid_i++];
+    c->function = HV_CPUID_FEATURES;
+    c->eax = env->features[FEAT_HYPERV_EAX];
+    c->ebx = env->features[FEAT_HYPERV_EBX];
+    c->edx = env->features[FEAT_HYPERV_EDX];
+
+    c = &cpuid_ent[cpuid_i++];
+    c->function = HV_CPUID_ENLIGHTMENT_INFO;
+    c->eax = env->features[FEAT_HV_RECOMM_EAX];
+    c->ebx = cpu->hyperv_spinlock_attempts;
+
+    c = &cpuid_ent[cpuid_i++];
+    c->function = HV_CPUID_IMPLEMENT_LIMITS;
+    c->eax = cpu->hv_max_vps;
+    c->ebx = 0x40;
+
+    if (cpu->hyperv_evmcs) {
+        __u32 function;
+
+        /* Create zeroed 0x40000006..0x40000009 leaves */
+        for (function = HV_CPUID_IMPLEMENT_LIMITS + 1;
+             function < HV_CPUID_NESTED_FEATURES; function++) {
+            c = &cpuid_ent[cpuid_i++];
+            c->function = function;
+        }
+
+        c = &cpuid_ent[cpuid_i++];
+        c->function = HV_CPUID_NESTED_FEATURES;
+        c->eax = env->features[FEAT_HV_NESTED_EAX];
+    }
+    r = cpuid_i;
+
+free:
     g_free(cpuid);
 
-    return r ? -ENOSYS : 0;
+    return r;
 }
 
 static int hyperv_init_vcpu(X86CPU *cpu)
@@ -1206,79 +1289,13 @@ int kvm_arch_init_vcpu(CPUState *cs)
     }
 
     /* Paravirtualization CPUIDs */
-    if (hyperv_enabled(cpu)) {
-        c = &cpuid_data.entries[cpuid_i++];
-        c->function = HV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
-        if (!cpu->hyperv_vendor_id) {
-            memcpy(signature, "Microsoft Hv", 12);
-        } else {
-            size_t len = strlen(cpu->hyperv_vendor_id);
-
-            if (len > 12) {
-                error_report("hv-vendor-id truncated to 12 characters");
-                len = 12;
-            }
-            memset(signature, 0, 12);
-            memcpy(signature, cpu->hyperv_vendor_id, len);
-        }
-        c->eax = cpu->hyperv_evmcs ?
-            HV_CPUID_NESTED_FEATURES : HV_CPUID_IMPLEMENT_LIMITS;
-        c->ebx = signature[0];
-        c->ecx = signature[1];
-        c->edx = signature[2];
-
-        c = &cpuid_data.entries[cpuid_i++];
-        c->function = HV_CPUID_INTERFACE;
-        memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12);
-        c->eax = signature[0];
-        c->ebx = 0;
-        c->ecx = 0;
-        c->edx = 0;
-
-        c = &cpuid_data.entries[cpuid_i++];
-        c->function = HV_CPUID_VERSION;
-        c->eax = 0x00001bbc;
-        c->ebx = 0x00060001;
-
-        c = &cpuid_data.entries[cpuid_i++];
-        c->function = HV_CPUID_FEATURES;
-        r = hyperv_handle_properties(cs);
-        if (r) {
-            return r;
-        }
-        c->eax = env->features[FEAT_HYPERV_EAX];
-        c->ebx = env->features[FEAT_HYPERV_EBX];
-        c->edx = env->features[FEAT_HYPERV_EDX];
-
-        c = &cpuid_data.entries[cpuid_i++];
-        c->function = HV_CPUID_ENLIGHTMENT_INFO;
-
-        c->eax = env->features[FEAT_HV_RECOMM_EAX];
-        c->ebx = cpu->hyperv_spinlock_attempts;
-
-        c = &cpuid_data.entries[cpuid_i++];
-        c->function = HV_CPUID_IMPLEMENT_LIMITS;
-
-        c->eax = cpu->hv_max_vps;
-        c->ebx = 0x40;
-
+    r = hyperv_handle_properties(cs, cpuid_data.entries);
+    if (r < 0) {
+        return r;
+    } else if (r > 0) {
+        cpuid_i = r;
         kvm_base = KVM_CPUID_SIGNATURE_NEXT;
         has_msr_hv_hypercall = true;
-
-        if (cpu->hyperv_evmcs) {
-            __u32 function;
-
-            /* Create zeroed 0x40000006..0x40000009 leaves */
-            for (function = HV_CPUID_IMPLEMENT_LIMITS + 1;
-                 function < HV_CPUID_NESTED_FEATURES; function++) {
-                c = &cpuid_data.entries[cpuid_i++];
-                c->function = function;
-            }
-
-            c = &cpuid_data.entries[cpuid_i++];
-            c->function = HV_CPUID_NESTED_FEATURES;
-            c->eax = env->features[FEAT_HV_NESTED_EAX];
-        }
     }
 
     if (cpu->expose_kvm) {
Signature · 1 line
2.20.1
#4 lore raw

RFC PATCH 4/8 i386/kvm: Implement 'hv-all' pass-through mode

In reply to Vitaly Kuznetsov

In many case we just want to give Windows guests all currently supported Hyper-V enlightenments and that's where this new mode may come handy. We pass through what was returned by KVM_GET_SUPPORTED_HV_CPUID.

hv_cpuid_check_and_set() is modified to also set cpu->hyperv_* flags as we may want to check them later (and we actually do for hv_runtime, hv_synic,...).

---
 target/i386/cpu.c |   1 +
 target/i386/cpu.h |   1 +
 target/i386/kvm.c | 133 ++++++++++++++++++++++++++++++++++++----------
 3 files changed, 107 insertions(+), 28 deletions(-)
target/i386/cpu.c +1 -0
index 2f5412592d..b776be5223 100644
@@ -5771,6 +5771,7 @@ static Property x86_cpu_properties[] = {
     DEFINE_PROP_BOOL("hv-tlbflush", X86CPU, hyperv_tlbflush, false),
     DEFINE_PROP_BOOL("hv-evmcs", X86CPU, hyperv_evmcs, false),
     DEFINE_PROP_BOOL("hv-ipi", X86CPU, hyperv_ipi, false),
+    DEFINE_PROP_BOOL("hv-all", X86CPU, hyperv_all, false),
     DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true),
     DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false),
     DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true),
target/i386/cpu.h +1 -0
index 59656a70e6..9b5c2715cc 100644
@@ -1397,6 +1397,7 @@ struct X86CPU {
     bool hyperv_tlbflush;
     bool hyperv_evmcs;
     bool hyperv_ipi;
+    bool hyperv_all;
     bool check_cpuid;
     bool enforce_cpuid;
     bool expose_kvm;
target/i386/kvm.c +105 -28

193 lines not on this page · raw message

Signature · 1 line
2.20.1
#5 lore raw

Re: [Qemu-devel] [PATCH RFC 4/8] i386/kvm: Implement 'hv-all' pass-through mode

Quoted 3 lines · Vitaly Kuznetsov

In many case we just want to give Windows guests all currently supported Hyper-V enlightenments and that's where this new mode may come handy. We pass through what was returned by KVM_GET_SUPPORTED_HV_CPUID.

How is the compatibility ensured on migration between kernels reporting different feature sets?

Roman.

#6 lore raw

Re: [Qemu-devel] [PATCH RFC 4/8] i386/kvm: Implement 'hv-all' pass-through mode

Quoted 7 lines · Roman Kagan
Quoted 3 lines · Vitaly Kuznetsov

In many case we just want to give Windows guests all currently supported Hyper-V enlightenments and that's where this new mode may come handy. We pass through what was returned by KVM_GET_SUPPORTED_HV_CPUID.

How is the compatibility ensured on migration between kernels reporting different feature sets?

AFAIU we don't change anything in this regard (or, my intention was to not change anything): hv-all is converted to the individual hv-* properties (hv_cpuid_check_and_set()) actually sets cpu->hyperv_* flags according to what's supported by kernel so when we migrate we will require all these features supported.

I'll look to see that my expectations actually match the reallity, thanks for the reminder!

Signature · 1 line
Vitaly
#7 lore raw

Re: [Qemu-devel] [PATCH RFC 4/8] i386/kvm: Implement 'hv-all' pass-through mode

Quoted 7 lines · Vitaly Kuznetsov
Quoted 5 lines · Roman Kagan
Quoted 3 lines · Vitaly Kuznetsov

In many case we just want to give Windows guests all currently supported Hyper-V enlightenments and that's where this new mode may come handy. We pass through what was returned by KVM_GET_SUPPORTED_HV_CPUID.

Quoted 8 lines
Quoted 2 lines

How is the compatibility ensured on migration between kernels reporting different feature sets?

AFAIU we don't change anything in this regard (or, my intention was to not change anything): hv-all is converted to the individual hv-* properties (hv_cpuid_check_and_set()) actually sets cpu->hyperv_* flags according to what's supported by kernel so when we migrate we will require all these features supported.

Migration relies on the upper layer to run the destination QEMU with the identical command line (except for -incoming) as the source, and QEMU is then supposed to set up identical environment in the target VM as was in the source, or refuse to start if that's impossible. (If I'm misunderstanding this Dave (cc-d) may want to correct me.)

AFAICS this hv-all attribute will enable different feature sets depending on the kernel it's run on, so the migration between different kernels will appear to succeed, but the guest may suddenly encounter an incompatible change in the environment.

Roman.

#8 lore raw

Re: [Qemu-devel] [PATCH RFC 4/8] i386/kvm: Implement 'hv-all' pass-through mode

Quoted 23 lines · Roman Kagan
Quoted 7 lines · Vitaly Kuznetsov
Quoted 5 lines · Roman Kagan
Quoted 3 lines · Vitaly Kuznetsov

In many case we just want to give Windows guests all currently supported Hyper-V enlightenments and that's where this new mode may come handy. We pass through what was returned by KVM_GET_SUPPORTED_HV_CPUID.

Quoted 8 lines
Quoted 2 lines

How is the compatibility ensured on migration between kernels reporting different feature sets?

AFAIU we don't change anything in this regard (or, my intention was to not change anything): hv-all is converted to the individual hv-* properties (hv_cpuid_check_and_set()) actually sets cpu->hyperv_* flags according to what's supported by kernel so when we migrate we will require all these features supported.

Migration relies on the upper layer to run the destination QEMU with the identical command line (except for -incoming) as the source, and QEMU is then supposed to set up identical environment in the target VM as was in the source, or refuse to start if that's impossible. (If I'm misunderstanding this Dave (cc-d) may want to correct me.)

Quoted 4 lines

AFAICS this hv-all attribute will enable different feature sets depending on the kernel it's run on, so the migration between different kernels will appear to succeed, but the guest may suddenly encounter an incompatible change in the environment.

With 'hv-all' I'm trying to achieve behavior similar to '-cpu host' and AFAIK these VMs are migratable 'at your own risk' (if you do it directly from qemu). Libvirt (or whatever upper layer), however, would do CPU feature comparison and in case you have less features on the destination host than you had on the source code it will forbid the migration. I think if this also works for Hyper-V features than were fine.

Dave, feel free to tell me I'm completely wrong with my assumptions)

Signature · 1 line
Vitaly
#9 lore raw

Re: [Qemu-devel] [PATCH RFC 4/8] i386/kvm: Implement 'hv-all' pass-through mode

Quoted 30 lines · * Vitaly Kuznetsov ([email protected]) wrote:
Quoted 23 lines · Roman Kagan
Quoted 7 lines · Vitaly Kuznetsov
Quoted 5 lines · Roman Kagan
Quoted 3 lines · Vitaly Kuznetsov

In many case we just want to give Windows guests all currently supported Hyper-V enlightenments and that's where this new mode may come handy. We pass through what was returned by KVM_GET_SUPPORTED_HV_CPUID.

Quoted 8 lines
Quoted 2 lines

How is the compatibility ensured on migration between kernels reporting different feature sets?

AFAIU we don't change anything in this regard (or, my intention was to not change anything): hv-all is converted to the individual hv-* properties (hv_cpuid_check_and_set()) actually sets cpu->hyperv_* flags according to what's supported by kernel so when we migrate we will require all these features supported.

Migration relies on the upper layer to run the destination QEMU with the identical command line (except for -incoming) as the source, and QEMU is then supposed to set up identical environment in the target VM as was in the source, or refuse to start if that's impossible. (If I'm misunderstanding this Dave (cc-d) may want to correct me.)

Quoted 4 lines

AFAICS this hv-all attribute will enable different feature sets depending on the kernel it's run on, so the migration between different kernels will appear to succeed, but the guest may suddenly encounter an incompatible change in the environment.

Quoted 8 lines

With 'hv-all' I'm trying to achieve behavior similar to '-cpu host' and AFAIK these VMs are migratable 'at your own risk' (if you do it directly from qemu). Libvirt (or whatever upper layer), however, would do CPU feature comparison and in case you have less features on the destination host than you had on the source code it will forbid the migration. I think if this also works for Hyper-V features than were fine.

Dave, feel free to tell me I'm completely wrong with my assumptions)

It does sound like -cpu host, but -cpu host does come with a health warning and we often get subtle screwups where it doesn't quite behave the same on the two sides, also qemu now warns (and with 'enforce' enforces) a check at it's level rather than relying on libvirt.

So hmm, yes it sounds like -cpu host, but I'd generally say it's not a great thing to copy unless you're really really careful. For example, in the -cpu host world people might have two machines they think are the same - but then they find out one has HT disabled or nesting enabled and so they're not actually the same.

I'm not sure what the equivalent bear traps are in the Hyper-V world, but I'd be surprised if there weren't any; for example what happens when someone upgrades one of their hosts to some minor version that adds/removes a feature?

Also, how does libvirt figure out that the features are actually the same - does it need a bunch of detection code?

Dave

Quoted 2 lines
Signature · 1 line
Vitaly

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#10 lore raw

Re: [Qemu-devel] [PATCH RFC 4/8] i386/kvm: Implement 'hv-all' pass-through mode

Quoted 51 lines · Dr. David Alan Gilbert
Quoted 30 lines · * Vitaly Kuznetsov ([email protected]) wrote:
Quoted 23 lines · Roman Kagan
Quoted 7 lines · Vitaly Kuznetsov
Quoted 5 lines · Roman Kagan
Quoted 3 lines · Vitaly Kuznetsov

In many case we just want to give Windows guests all currently supported Hyper-V enlightenments and that's where this new mode may come handy. We pass through what was returned by KVM_GET_SUPPORTED_HV_CPUID.

Quoted 8 lines
Quoted 2 lines

How is the compatibility ensured on migration between kernels reporting different feature sets?

AFAIU we don't change anything in this regard (or, my intention was to not change anything): hv-all is converted to the individual hv-* properties (hv_cpuid_check_and_set()) actually sets cpu->hyperv_* flags according to what's supported by kernel so when we migrate we will require all these features supported.

Migration relies on the upper layer to run the destination QEMU with the identical command line (except for -incoming) as the source, and QEMU is then supposed to set up identical environment in the target VM as was in the source, or refuse to start if that's impossible. (If I'm misunderstanding this Dave (cc-d) may want to correct me.)

Quoted 4 lines

AFAICS this hv-all attribute will enable different feature sets depending on the kernel it's run on, so the migration between different kernels will appear to succeed, but the guest may suddenly encounter an incompatible change in the environment.

Quoted 8 lines

With 'hv-all' I'm trying to achieve behavior similar to '-cpu host' and AFAIK these VMs are migratable 'at your own risk' (if you do it directly from qemu). Libvirt (or whatever upper layer), however, would do CPU feature comparison and in case you have less features on the destination host than you had on the source code it will forbid the migration. I think if this also works for Hyper-V features than were fine.

Dave, feel free to tell me I'm completely wrong with my assumptions)

It does sound like -cpu host, but -cpu host does come with a health warning and we often get subtle screwups where it doesn't quite behave the same on the two sides, also qemu now warns (and with 'enforce' enforces) a check at it's level rather than relying on libvirt.

So hmm, yes it sounds like -cpu host, but I'd generally say it's not a great thing to copy unless you're really really careful. For example, in the -cpu host world people might have two machines they think are the same - but then they find out one has HT disabled or nesting enabled and so they're not actually the same.

Quoted 7 lines

I'm not sure what the equivalent bear traps are in the Hyper-V world, but I'd be surprised if there weren't any; for example what happens when someone upgrades one of their hosts to some minor version that adds/removes a feature?

Also, how does libvirt figure out that the features are actually the same - does it need a bunch of detection code?

If libvirt is involved, it's much simpler and safer to use something like <cpu mode="host-model">, which generates a migration-safe CPU configuration based on the current host. Live migration support with "-cpu host" is only useful for experiments and carefully controlled environments.

Is there a real need to make hv-all migratable? What would be the use case, exactly? If there's no clear use case, I would recommend making it a migration blocker.

Signature · 1 line
Eduardo
#11 lore raw

Re: [Qemu-devel] [PATCH RFC 4/8] i386/kvm: Implement 'hv-all' pass-through mode

Quoted 10 lines · Eduardo Habkost

If libvirt is involved, it's much simpler and safer to use something like <cpu mode="host-model">, which generates a migration-safe CPU configuration based on the current host. Live migration support with "-cpu host" is only useful for experiments and carefully controlled environments.

Is there a real need to make hv-all migratable? What would be the use case, exactly? If there's no clear use case, I would recommend making it a migration blocker.

There's no clear use-case; I noticed that we keep adding Hyper-V enlightenments and these make Windows' life on KVM easier so we recommend enabling them all (and, with an exception for hv-evmcs, which I also don't enable with hv-all, I'm unawere of cases which would require disabling certain Hyper-V enlightenments).

hv-all is mostly a convenience feature. I plan to take a look at 'host-model' to see if we can borrow some ideas from there (that would actually be ideal - build a set of 'hv-*' enlightenments based on capabilites of the current host) but I'm also not totally against keeping it the way it is and making it a migration blocker for the time being (and making it a 'developer-only' feature).

Signature · 1 line
Vitaly
#12 lore raw

Re: [Qemu-devel] [PATCH RFC 4/8] i386/kvm: Implement 'hv-all' pass-through mode

In reply to Dr. David Alan Gilbert
Quoted 4 lines · Dr. David Alan Gilbert

I'm not sure what the equivalent bear traps are in the Hyper-V world, but I'd be surprised if there weren't any; for example what happens when someone upgrades one of their hosts to some minor version that adds/removes a feature?

Here we're talking about Hyper-V emulation in KVM, features only get added there, but even if it gets removed it will be detected by libvirt ...

Quoted 3 lines

Also, how does libvirt figure out that the features are actually the same - does it need a bunch of detection code?

... as I *think* it compares Feature CPUID words (and all Hyper-V features which we enable with hv-all are there).

Signature · 1 line
Vitaly
#13 lore raw

Re: [Qemu-devel] [PATCH RFC 4/8] i386/kvm: Implement 'hv-all' pass-through mode

Quoted 9 lines · * Vitaly Kuznetsov ([email protected]) wrote:
Quoted 4 lines · Dr. David Alan Gilbert

I'm not sure what the equivalent bear traps are in the Hyper-V world, but I'd be surprised if there weren't any; for example what happens when someone upgrades one of their hosts to some minor version that adds/removes a feature?

Here we're talking about Hyper-V emulation in KVM, features only get added there, but even if it gets removed it will be detected by libvirt ...

OK, but then you do get the same behaviour; upgrade a host to a new kernel/qemu and get a new enlightenment, and you can't back migrate to the older one (possibly with no warning).

Quoted 6 lines
Quoted 3 lines

Also, how does libvirt figure out that the features are actually the same - does it need a bunch of detection code?

... as I *think* it compares Feature CPUID words (and all Hyper-V features which we enable with hv-all are there).

Not too bad if it does, but also look at the scary command lines we get generated full of -cpu ...+feature,+feature,-feature,....

Dave

Quoted 2 lines
Signature · 1 line
Vitaly

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#14 lore raw

Re: [Qemu-devel] [PATCH RFC 4/8] i386/kvm: Implement 'hv-all' pass-through mode

In reply to Dr. David Alan Gilbert
Quoted 51 lines · Dr. David Alan Gilbert
Quoted 30 lines · * Vitaly Kuznetsov ([email protected]) wrote:
Quoted 23 lines · Roman Kagan
Quoted 7 lines · Vitaly Kuznetsov
Quoted 5 lines · Roman Kagan
Quoted 3 lines · Vitaly Kuznetsov

In many case we just want to give Windows guests all currently supported Hyper-V enlightenments and that's where this new mode may come handy. We pass through what was returned by KVM_GET_SUPPORTED_HV_CPUID.

Quoted 8 lines
Quoted 2 lines

How is the compatibility ensured on migration between kernels reporting different feature sets?

AFAIU we don't change anything in this regard (or, my intention was to not change anything): hv-all is converted to the individual hv-* properties (hv_cpuid_check_and_set()) actually sets cpu->hyperv_* flags according to what's supported by kernel so when we migrate we will require all these features supported.

Migration relies on the upper layer to run the destination QEMU with the identical command line (except for -incoming) as the source, and QEMU is then supposed to set up identical environment in the target VM as was in the source, or refuse to start if that's impossible. (If I'm misunderstanding this Dave (cc-d) may want to correct me.)

Quoted 4 lines

AFAICS this hv-all attribute will enable different feature sets depending on the kernel it's run on, so the migration between different kernels will appear to succeed, but the guest may suddenly encounter an incompatible change in the environment.

Quoted 8 lines

With 'hv-all' I'm trying to achieve behavior similar to '-cpu host' and AFAIK these VMs are migratable 'at your own risk' (if you do it directly from qemu). Libvirt (or whatever upper layer), however, would do CPU feature comparison and in case you have less features on the destination host than you had on the source code it will forbid the migration. I think if this also works for Hyper-V features than were fine.

Dave, feel free to tell me I'm completely wrong with my assumptions)

It does sound like -cpu host, but -cpu host does come with a health warning and we often get subtle screwups where it doesn't quite behave the same on the two sides, also qemu now warns (and with 'enforce' enforces) a check at it's level rather than relying on libvirt.

So hmm, yes it sounds like -cpu host, but I'd generally say it's not a great thing to copy unless you're really really careful. For example, in the -cpu host world people might have two machines they think are the same - but then they find out one has HT disabled or nesting enabled and so they're not actually the same.

Quoted 7 lines

I'm not sure what the equivalent bear traps are in the Hyper-V world, but I'd be surprised if there weren't any; for example what happens when someone upgrades one of their hosts to some minor version that adds/removes a feature?

Also, how does libvirt figure out that the features are actually the same - does it need a bunch of detection code?

We support "-cpu host" with libvirt because there is a genuine functional reasont to want to use that, as you can't get precisely the same result any other way. This isn't the case with 'hv-all', as it doesn't offer any feature that you can't already achieve by listing all the hv-XXX features explicitly.

As such I don't expect libvirt to use 'hv-all' at all.

There's no reason why QEMU can't support it anyway though, for the simplicity of people launching QEMU manually. Just need to document that migration caveat - its only safe if QEMU versions match on both sides.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#15 lore raw

RFC PATCH 5/8 i386/kvm: hv-evmcs requires hv-vapic

In reply to Vitaly Kuznetsov

Enlightened VMCS is enabled by writing to a field in VP assist page and these require virtual APIC.

---
 target/i386/kvm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
target/i386/kvm.c +4 -1
index b373b4ac06..674c5dc185 100644
@@ -1074,7 +1074,7 @@ static int hv_report_missing_dep(X86CPU *cpu, const char *name,
         return 1;
     }
 
-    if (cpu->hyperv_all) {
+    if (cpu->hyperv_all && strcmp(name, "hv-evmcs")) {
         fprintf(stderr, "Hyper-V %s (requested by 'hv-all' cpu flag) "
                 "requires %s (is not supported by kernel)\n",
                 kvm_hyperv_properties[i].desc, kvm_hyperv_properties[j].desc);
@@ -1174,6 +1174,9 @@ static int hyperv_handle_properties(CPUState *cs,
     if (cpu->hyperv_synic && !cpu->hyperv_synic_kvm_only &&
         !cpu->hyperv_vpindex)
         r |= hv_report_missing_dep(cpu, "hv-synic", "hv-vpindex");
+    if (cpu->hyperv_evmcs && !cpu->hyperv_vapic) {
+        r |= hv_report_missing_dep(cpu, "hv-evmcs", "hv-vapic");
+    }
 
     /* Not exposed by KVM but needed to make CPU hotplug in Windows work */
     env->features[FEAT_HYPERV_EDX] |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE;
Signature · 1 line
2.20.1
#16 lore raw

RFC PATCH 6/8 i386/kvm: hv-stimer requires hv-time and hv-synic

In reply to Vitaly Kuznetsov

Synthetic timers operate in hv-time time and Windows won't use these without SynIC.

---
 target/i386/kvm.c | 6 ++++++
 1 file changed, 6 insertions(+)
target/i386/kvm.c +6 -0
index 674c5dc185..7461bf05dd 100644
@@ -1177,6 +1177,12 @@ static int hyperv_handle_properties(CPUState *cs,
     if (cpu->hyperv_evmcs && !cpu->hyperv_vapic) {
         r |= hv_report_missing_dep(cpu, "hv-evmcs", "hv-vapic");
     }
+    if (cpu->hyperv_stimer && !cpu->hyperv_synic) {
+        r |= hv_report_missing_dep(cpu, "hv-stimer", "hv-synic");
+    }
+    if (cpu->hyperv_stimer && !cpu->hyperv_time) {
+        r |= hv_report_missing_dep(cpu, "hv-stimer", "hv-time");
+    }
 
     /* Not exposed by KVM but needed to make CPU hotplug in Windows work */
     env->features[FEAT_HYPERV_EDX] |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE;
Signature · 1 line
2.20.1
#17 lore raw

RFC PATCH 7/8 i386/kvm: hv-tlbflush/ipi require hv-vpindex

In reply to Vitaly Kuznetsov

The corresponding hypercalls require using VP indexes.

---
 target/i386/kvm.c | 6 ++++++
 1 file changed, 6 insertions(+)
target/i386/kvm.c +6 -0
index 7461bf05dd..14d74ca9c7 100644
@@ -1183,6 +1183,12 @@ static int hyperv_handle_properties(CPUState *cs,
     if (cpu->hyperv_stimer && !cpu->hyperv_time) {
         r |= hv_report_missing_dep(cpu, "hv-stimer", "hv-time");
     }
+    if (cpu->hyperv_tlbflush && !cpu->hyperv_vpindex) {
+        r |= hv_report_missing_dep(cpu, "hv-tlbflush", "hv-vpindex");
+    }
+    if (cpu->hyperv_ipi && !cpu->hyperv_vpindex) {
+        r |= hv_report_missing_dep(cpu, "hv-ipi", "hv-vpindex");
+    }
 
     /* Not exposed by KVM but needed to make CPU hotplug in Windows work */
     env->features[FEAT_HYPERV_EDX] |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE;
Signature · 1 line
2.20.1
#18 lore raw

RFC PATCH 8/8 i386/kvm: add support for Direct Mode for Hyper-V synthetic timers

In reply to Vitaly Kuznetsov

Hyper-V on KVM can only use Synthetic timers with Direct Mode (opting for an interrupt instead of VMBus message). This new capability is only announced in KVM_GET_SUPPORTED_HV_CPUID.

---
 target/i386/cpu.c          |  1 +
 target/i386/cpu.h          |  1 +
 target/i386/hyperv-proto.h |  1 +
 target/i386/kvm.c          | 15 +++++++++++++++
 4 files changed, 18 insertions(+)
target/i386/cpu.c +1 -0
index b776be5223..986cbe88dd 100644
@@ -5771,6 +5771,7 @@ static Property x86_cpu_properties[] = {
     DEFINE_PROP_BOOL("hv-tlbflush", X86CPU, hyperv_tlbflush, false),
     DEFINE_PROP_BOOL("hv-evmcs", X86CPU, hyperv_evmcs, false),
     DEFINE_PROP_BOOL("hv-ipi", X86CPU, hyperv_ipi, false),
+    DEFINE_PROP_BOOL("hv-stimer-direct", X86CPU, hyperv_stimer_direct, false),
     DEFINE_PROP_BOOL("hv-all", X86CPU, hyperv_all, false),
     DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true),
     DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false),
target/i386/cpu.h +1 -0
index 9b5c2715cc..9716cd89d7 100644
@@ -1397,6 +1397,7 @@ struct X86CPU {
     bool hyperv_tlbflush;
     bool hyperv_evmcs;
     bool hyperv_ipi;
+    bool hyperv_stimer_direct;
     bool hyperv_all;
     bool check_cpuid;
     bool enforce_cpuid;
target/i386/hyperv-proto.h +1 -0
index c0272b3a01..cffac10b45 100644
@@ -49,6 +49,7 @@
 #define HV_GUEST_IDLE_STATE_AVAILABLE           (1u << 5)
 #define HV_FREQUENCY_MSRS_AVAILABLE             (1u << 8)
 #define HV_GUEST_CRASH_MSR_AVAILABLE            (1u << 10)
+#define HV_STIMER_DIRECT_MODE_AVAILABLE         (1u << 19)
 
 /*
  * HV_CPUID_ENLIGHTMENT_INFO.EAX bits
target/i386/kvm.c +15 -0
index 14d74ca9c7..e7d0f4d3fe 100644
@@ -648,6 +648,7 @@ static bool hyperv_enabled(X86CPU *cpu)
             cpu->hyperv_reenlightenment ||
             cpu->hyperv_tlbflush ||
             cpu->hyperv_ipi ||
+            cpu->hyperv_stimer_direct ||
             cpu->hyperv_all);
 }
 
@@ -823,6 +824,15 @@ static struct {
             {0}
         }
     },
+    {
+        .name = "hv-stimer-direct",
+        .desc = "direct mode timers",
+        .flags = {
+            {.fw = FEAT_HYPERV_EDX,
+             .bits = HV_STIMER_DIRECT_MODE_AVAILABLE},
+            {0}
+        }
+    },
 };
 
 static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max)
@@ -1169,6 +1179,8 @@ static int hyperv_handle_properties(CPUState *cs,
     r |= hv_cpuid_check_and_set(cs, cpuid, "hv-tlbflush",
                                 &cpu->hyperv_tlbflush);
     r |= hv_cpuid_check_and_set(cs, cpuid, "hv-ipi", &cpu->hyperv_ipi);
+    r |= hv_cpuid_check_and_set(cs, cpuid, "hv-stimer-direct",
+                                &cpu->hyperv_stimer_direct);
 
     /* Dependencies */
     if (cpu->hyperv_synic && !cpu->hyperv_synic_kvm_only &&
@@ -1189,6 +1201,9 @@ static int hyperv_handle_properties(CPUState *cs,
     if (cpu->hyperv_ipi && !cpu->hyperv_vpindex) {
         r |= hv_report_missing_dep(cpu, "hv-ipi", "hv-vpindex");
     }
+    if (cpu->hyperv_stimer_direct && !cpu->hyperv_stimer) {
+        r |= hv_report_missing_dep(cpu, "hv-stimer-direct", "hv-stimer");
+    }
 
     /* Not exposed by KVM but needed to make CPU hotplug in Windows work */
     env->features[FEAT_HYPERV_EDX] |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE;
Signature · 1 line
2.20.1
#19 lore raw
In reply to Vitaly Kuznetsov
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Subject: [Qemu-devel] [PATCH RFC 0/8] i386/kvm/hyper-v: refactor and implement 'hv-stimer-direct' and 'hv-all' enlightenments
Type: series
Message-id: [email protected]

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
dabb4951b0 i386/kvm: add support for Direct Mode for Hyper-V synthetic timers 223e993ccd i386/kvm: hv-tlbflush/ipi require hv-vpindex 3051f4d3de i386/kvm: hv-stimer requires hv-time and hv-synic 6ca6a10f0a i386/kvm: hv-evmcs requires hv-vapic
c8aeebcffd i386/kvm: Implement 'hv-all' pass-through mode 79a00f19c1 i386/kvm: move Hyper-V CPUID filling to hyperv_handle_properties() 69c92de59b i386/kvm: add support for KVM_GET_SUPPORTED_HV_CPUID 345a0718e2 Update linux headers (5.0-rc2)

=== OUTPUT BEGIN ===
1/8 Checking commit 345a0718e21e (Update linux headers (5.0-rc2))
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #1646:
new file mode 100644

ERROR: code indent should never use tabs
#3980: FILE: scripts/update-linux-headers.sh:126:
+^Icp "$tmpdir/include/asm/unistd_n64.h" "$output/linux-headers/asm-mips/"$

WARNING: line over 80 characters
#3983: FILE: scripts/update-linux-headers.sh:129:
+ cp "$tmpdir/include/asm/unistd_32.h" "$output/linux-headers/asm-powerpc/"

WARNING: line over 80 characters
#3984: FILE: scripts/update-linux-headers.sh:130:
+ cp "$tmpdir/include/asm/unistd_64.h" "$output/linux-headers/asm-powerpc/"

ERROR: code indent should never use tabs
#3984: FILE: scripts/update-linux-headers.sh:130:
+^Icp "$tmpdir/include/asm/unistd_64.h" "$output/linux-headers/asm-powerpc/"$

total: 2 errors, 3 warnings, 3838 lines checked

Patch 1/8 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

2/8 Checking commit 69c92de59b5d (i386/kvm: add support for KVM_GET_SUPPORTED_HV_CPUID) 3/8 Checking commit 79a00f19c1c4 (i386/kvm: move Hyper-V CPUID filling to hyperv_handle_properties()) 4/8 Checking commit c8aeebcffd5a (i386/kvm: Implement 'hv-all' pass-through mode)
5/8 Checking commit 6ca6a10f0a12 (i386/kvm: hv-evmcs requires hv-vapic)
6/8 Checking commit 3051f4d3de1e (i386/kvm: hv-stimer requires hv-time and hv-synic) 7/8 Checking commit 223e993ccd15 (i386/kvm: hv-tlbflush/ipi require hv-vpindex)
8/8 Checking commit dabb4951b005 (i386/kvm: add support for Direct Mode for Hyper-V synthetic timers) === OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#20 lore raw
Quoted 14 lines · [email protected] writes:

=== OUTPUT BEGIN ===
1/8 Checking commit 345a0718e21e (Update linux headers (5.0-rc2))
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #1646:
new file mode 100644

ERROR: code indent should never use tabs
#3980: FILE: scripts/update-linux-headers.sh:126:
+^Icp "$tmpdir/include/asm/unistd_n64.h" "$output/linux-headers/asm-mips/"$

WARNING: line over 80 characters
#3983: FILE: scripts/update-linux-headers.sh:129:
+ cp "$tmpdir/include/asm/unistd_32.h" "$output/linux-headers/asm-powerpc/"

Quoted 8 lines

WARNING: line over 80 characters
#3984: FILE: scripts/update-linux-headers.sh:130:
+ cp "$tmpdir/include/asm/unistd_64.h" "$output/linux-headers/asm-powerpc/"

ERROR: code indent should never use tabs
#3984: FILE: scripts/update-linux-headers.sh:130:
+^Icp "$tmpdir/include/asm/unistd_64.h" "$output/linux-headers/asm-powerpc/"$

I saw these before submitting, however, these are linux headers and we take them as-is with scripts/update-linux-headers.sh: I don't think it is worth it to modify these headers just to silence patchew.

Signature · 1 line
Vitaly