Skip to contentSkip to conversation

Introduce /dev/mshv drivers

PATCH In review Nuno Das Neves 7 participants 49 messages Sep 29, 2023 – Nov 6, 2023

Subsystems (8)
Documentation x86 ACPI arm64 +4 more subsystems
lore
Share & tools
lore
#0 lore raw

v4 cover Introduce /dev/mshv drivers

This series introduces support for creating and running guest machines while running on the Microsoft Hypervisor. [0]
This is done via an IOCTL interface accessed through /dev/mshv, similar to /dev/kvm. Another series introducing this support was previously posted.
[1]

These interfaces support VMMs running in:
1. The root patition - provided in the mshv_root module, and
2. VTL 2 - provided in the mshv_vtl module [2]

Patches breakdown
-----------------
The first 7 patches are refactoring and adding some helper functions. They provide some benefit on their own and could be applied independently as cleanup patches.

Patches 8-12 just set things up for the driver code to come. These are very small. They come first so that the remaining patches are more self-contained.

The final 3 patches are the meat of the series:
- Patch 13 contains new header files used by the driver.
These are designed to mirror the ABI headers exported by Hyper-V. This is done to avoid polluting hyperv-tlfs.h and help track changes to the ABIs that are still unstable. (See FAQ below).
- Patch 14 conditionally includes these new header files into mshyperv.h and linux/hyperv.h, in order to be able to use these files in the new drivers while remaining independent from hyperv-tlfs.h.
- Patch 15 contains the new driver code located in drivers/hv. This is a large amount of code and new files, but it is mostly self-contained and all within drivers/hv - apart from the IOCTL interface itself in uapi.

Patch 15 is rather big and has bounced back from some mailing lists. If you did not get a copy in your inbox, you can view it here instead:
https://github.com/NunoDasNeves/linux/commit/3974fa9e586daf4be2580ca94d49c20a1f3f9b98

FAQ on include/uapi/hyperv/*.h
------------------------------
Q:
Why not just add these definitions to hyperv-tlfs.h?
A:
The intention of hyperv-tlfs.h is to contain stable definitions documented in the public TLFS document. These new definitions don't fit that criteria, so they should be separate.

Q:
The new headers redefine many things that are already in hyperv-tlfs.h - why? A:
Some definitions are extended compared to what is documented in the TLFS. In order to avoid adding undocumented or unstable definitions to hyperv-tlfs.h, the new headers must compile independently.
Therefore, the new headers must redefine many things in hyperv-tlfs.h in order to compile.

Q:
Why are these files named hvgdk.h, hvgdk_mini.h, hvhdk.h and hvhdk_mini.h? A:
The precise meaning of the names reflects conventions used internally at Microsoft.
Naming them this way makes it easy to find where particular Hyper-V definitions come from, and check their correctness.
It also facilitates the future work of automatically generating these files.

Q:
Why are they in uapi?
A:
In short, to keep things simple. There are many definitions needed in both the kernel and the VMM in userspace. Separating them doesn't serve much purpose, and makes it more laborious to import definitions from Hyper-V code.

--------------------------
[0] "Hyper-V" is more well-known, but it really refers to the whole stack including the hypervisor and other components that run in Windows kernel and userspace.
[1] Previous /dev/mshv patch series and discussion:

    https://lore.kernel.org/linux-hyperv/1632853875-20261-1-git-send-email-nunodasneves@linux.microsoft.com/

[2] Virtual Secure Mode (VSM) and Virtual Trust Levels (VTL):
https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/vsm
--------------------------

Changes since v3:
* Correct HyperV -> Hyper-V in patch 1 commit message
* Replace BUG()s in mshv_vtl_init() with return -ENODEV
* Remove some debug prints that leak kernel addresses
* Remove __func__ in most error printing where the error string is easily greppable, and in all uses of pr_debug()/dev_dbg()
* Pass mshv_dev->this_device to mshv_vtl and mshv_root, store it in vtl and partition structs
* Add a set of macros vp_*() and partition_*() which call the equivalent dev_*(), passing the device from the partition struct
* The new macros also print the partition and vp ids to aid debugging and reduce repeated code
* Use dev_*() (mostly via the new macros) instead of pr_*() *almost* everywhere - in interrupt context we can't always get the device struct
* Remove pr_*() logging from hv_call.c and mshv_root_hv_call.c
Changes since v2:
* Fix some commit message wrapping
* Fix many checkpatch.pl --strict style issues
* Replace uapi ints with __s32
* Replace uapi enums with __u32
* Replace uapi pointers with __u64
* Add explicit padding to uapi structures
* Initialize status in get/set registers hypercall helpers
* Add missing return on error in get_vp_signaled_count
* Remove select TRANSPARENT_HUGEPAGES for mshv_vtl
* Use __func__ prefix consistently in printks
* Use single generic cpuid() to get all 4 registers instead of 4 calls
* Change hv_proximity_domain_info from union to struct for clarity
Changes since v1:
* Clean up formatting, capitalization in commit messages
* Add detail to commit message for patch 15
* Remove errant lines in Makefile and Kconfig in patch 15
* Move a reference to CONFIG_MSHV_VTL from patch 9 to 15

Nuno Das Neves (15):
hyperv-tlfs: Change shared HV_REGISTER_* defines to HV_MSR_*
mshyperv: Introduce hv_get_hypervisor_version function
mshyperv: Introduce numa_node_to_proximity_domain_info asm-generic/mshyperv: Introduce hv_recommend_using_aeoi()
hyperv: Move hv_connection_id to hyperv-tlfs
hyperv-tlfs: Introduce hv_status_to_string and hv_status_to_errno
Drivers: hv: Move hv_call_deposit_pages and hv_call_create_vp to
common code
Drivers: hv: Introduce per-cpu event ring tail
Drivers: hv: Introduce hv_output_arg_exists in hv_common.c
x86: hyperv: Add mshv_handler irq handler and setup function
Drivers: hv: export vmbus_isr, hv_context and hv_post_message
Documentation: Reserve ioctl number for mshv driver
uapi: hyperv: Add mshv driver headers defining hypervisor ABIs
asm-generic: hyperv: Use new Hyper-V headers conditionally.
Drivers: hv: Add modules to expose /dev/mshv to VMMs running on
Hyper-V

 .../userspace-api/ioctl/ioctl-number.rst      |    2 +
 arch/arm64/hyperv/mshyperv.c                  |   23 +-
 arch/arm64/include/asm/hyperv-tlfs.h          |   25 +
 arch/arm64/include/asm/mshyperv.h             |    2 +-
 arch/x86/hyperv/hv_init.c                     |    2 +-
 arch/x86/hyperv/hv_proc.c                     |  166 +-
 arch/x86/include/asm/hyperv-tlfs.h            |  137 +-
 arch/x86/include/asm/mshyperv.h               |   12 +-
 arch/x86/kernel/cpu/mshyperv.c                |   67 +-
 drivers/acpi/numa/srat.c                      |    1 +
 drivers/clocksource/hyperv_timer.c            |   24 +-
 drivers/hv/Kconfig                            |   49 +
 drivers/hv/Makefile                           |   20 +
 drivers/hv/hv.c                               |   50 +-
 drivers/hv/hv_call.c                          |  103 +
 drivers/hv/hv_common.c                        |  223 +-
 drivers/hv/hyperv_vmbus.h                     |    2 +-
 drivers/hv/mshv.h                             |  125 ++
 drivers/hv/mshv_eventfd.c                     |  761 +++++++
 drivers/hv/mshv_eventfd.h                     |   80 +
 drivers/hv/mshv_main.c                        |  196 ++
 drivers/hv/mshv_msi.c                         |  129 ++
 drivers/hv/mshv_portid_table.c                |   84 +
 drivers/hv/mshv_root.h                        |  232 ++
 drivers/hv/mshv_root_hv_call.c                |  911 ++++++++
 drivers/hv/mshv_root_main.c                   | 1911 +++++++++++++++++
 drivers/hv/mshv_synic.c                       |  688 ++++++
 drivers/hv/mshv_vtl.h                         |   52 +
 drivers/hv/mshv_vtl_main.c                    | 1522 +++++++++++++
 drivers/hv/vmbus_drv.c                        |    3 +-
 drivers/hv/xfer_to_guest.c                    |   28 +
 include/asm-generic/hyperv-defs.h             |   26 +
 include/asm-generic/hyperv-tlfs.h             |   93 +-
 include/asm-generic/mshyperv.h                |   73 +-
 include/linux/hyperv.h                        |   11 +-
 include/uapi/hyperv/hvgdk.h                   |   41 +
 include/uapi/hyperv/hvgdk_mini.h              | 1076 ++++++++++
 include/uapi/hyperv/hvhdk.h                   | 1342 ++++++++++++
 include/uapi/hyperv/hvhdk_mini.h              |  160 ++
 include/uapi/linux/mshv.h                     |  306 +++
 40 files changed, 10394 insertions(+), 364 deletions(-)
 create mode 100644 drivers/hv/hv_call.c
 create mode 100644 drivers/hv/mshv.h
 create mode 100644 drivers/hv/mshv_eventfd.c
 create mode 100644 drivers/hv/mshv_eventfd.h
 create mode 100644 drivers/hv/mshv_main.c
 create mode 100644 drivers/hv/mshv_msi.c
 create mode 100644 drivers/hv/mshv_portid_table.c
 create mode 100644 drivers/hv/mshv_root.h
 create mode 100644 drivers/hv/mshv_root_hv_call.c
 create mode 100644 drivers/hv/mshv_root_main.c
 create mode 100644 drivers/hv/mshv_synic.c
 create mode 100644 drivers/hv/mshv_vtl.h
 create mode 100644 drivers/hv/mshv_vtl_main.c
 create mode 100644 drivers/hv/xfer_to_guest.c
 create mode 100644 include/asm-generic/hyperv-defs.h
 create mode 100644 include/uapi/hyperv/hvgdk.h
 create mode 100644 include/uapi/hyperv/hvgdk_mini.h
 create mode 100644 include/uapi/hyperv/hvhdk.h
 create mode 100644 include/uapi/hyperv/hvhdk_mini.h
 create mode 100644 include/uapi/linux/mshv.h
Signature · 1 line
2.25.1
#1 lore raw

PATCH v4 1/15 hyperv-tlfs: Change shared HV_REGISTER_* defines to HV_MSR_*

In x86 hyperv-tlfs, HV_REGISTER_ prefix is used to indicate MSRs accessed via rdmsrl/wrmsrl. But in ARM64, HV_REGISTER_ instead indicates VP registers accessed via get/set vp registers hypercall.

This is due to HV_REGISTER_* names being used by hv_set/get_register, with the arch-specific version delegating to the appropriate mechanism.

The problem is, using prefix HV_REGISTER_ for MSRs will conflict with VP registers when they are introduced for x86 in future.

This patch solves the issue by:

1. Defining all the x86 MSRs with a consistent prefix: HV_X64_MSR_. This is so HV_REGISTER_ can be reserved for VP registers.

2. Change the non-arch-specific alias used by hv_set/get_register to HV_MSR_. This is also happens to be the same name Hyper-V uses for this purpose.

---
 arch/arm64/include/asm/hyperv-tlfs.h |  25 +++++
 arch/x86/include/asm/hyperv-tlfs.h   | 137 +++++++++++++--------------
 arch/x86/include/asm/mshyperv.h      |   8 +-
 arch/x86/kernel/cpu/mshyperv.c       |  22 ++---
 drivers/clocksource/hyperv_timer.c   |  24 ++---
 drivers/hv/hv.c                      |  36 +++----
 drivers/hv/hv_common.c               |  18 ++--
 include/asm-generic/mshyperv.h       |   2 +-
 8 files changed, 148 insertions(+), 124 deletions(-)
arch/arm64/include/asm/hyperv-tlfs.h +25 -0
index bc6c7ac934a1..a6e852c2fc3a 100644
@@ -64,6 +64,31 @@
 #define HV_REGISTER_STIMER0_CONFIG	0x000B0000
 #define HV_REGISTER_STIMER0_COUNT	0x000B0001
 
+/*
+ * To support non-arch-specific code calling hv_set/get_register:
+ * - On x86, HV_MSR_ indicates an MSR accessed via rdmsrl/wrmsrl
+ * - On ARM, HV_MSR_ indicates a VP register accessed via hypercall
+ */
+#define HV_MSR_VP_INDEX		(HV_REGISTER_VP_INDEX)
+#define HV_MSR_TIME_REF_COUNT	(HV_REGISTER_TIME_REF_COUNT)
+#define HV_MSR_REFERENCE_TS	(HV_REGISTER_REFERENCE_TSC)
+
+#define HV_MSR_STIMER0_CONFIG	(HV_REGISTER_STIMER0_CONFIG)
+#define HV_MSR_STIMER0_COUNT	(HV_REGISTER_STIMER0_COUNT)
+
+#define HV_MSR_SCONTROL		(HV_REGISTER_SCONTROL)
+#define HV_MSR_SIEFP		(HV_REGISTER_SIEFP)
+#define HV_MSR_SIMP		(HV_REGISTER_SIMP)
+#define HV_MSR_EOM		(HV_REGISTER_EOM)
+#define HV_MSR_SINT0		(HV_REGISTER_SINT0)
+
+#define HV_MSR_CRASH_P0		(HV_REGISTER_CRASH_P0)
+#define HV_MSR_CRASH_P1		(HV_REGISTER_CRASH_P1)
+#define HV_MSR_CRASH_P2		(HV_REGISTER_CRASH_P2)
+#define HV_MSR_CRASH_P3		(HV_REGISTER_CRASH_P3)
+#define HV_MSR_CRASH_P4		(HV_REGISTER_CRASH_P4)
+#define HV_MSR_CRASH_CTL	(HV_REGISTER_CRASH_CTL)
+
 union hv_msi_entry {
 	u64 as_uint64[2];
 	struct {
arch/x86/include/asm/hyperv-tlfs.h +68 -69

177 lines not on this page · raw message

arch/x86/include/asm/mshyperv.h +4 -4
index 033b53f993c6..e918b4132de8 100644
@@ -295,14 +295,14 @@ static inline void hv_ivm_msr_read(u64 msr, u64 *value) {}
 
 static inline bool hv_is_synic_reg(unsigned int reg)
 {
-	return (reg >= HV_REGISTER_SCONTROL) &&
-	       (reg <= HV_REGISTER_SINT15);
+	return (reg >= HV_X64_MSR_SCONTROL) &&
+	       (reg <= HV_X64_MSR_SINT15);
 }
 
 static inline bool hv_is_sint_reg(unsigned int reg)
 {
-	return (reg >= HV_REGISTER_SINT0) &&
-	       (reg <= HV_REGISTER_SINT15);
+	return (reg >= HV_X64_MSR_SINT0) &&
+	       (reg <= HV_X64_MSR_SINT15);
 }
 
 u64 hv_get_register(unsigned int reg);
arch/x86/kernel/cpu/mshyperv.c +11 -11
index e6bba12c759c..d85a8e2a10c9 100644
@@ -48,19 +48,19 @@ EXPORT_SYMBOL_GPL(hyperv_paravisor_present);
 static inline unsigned int hv_get_nested_reg(unsigned int reg)
 {
 	if (hv_is_sint_reg(reg))
-		return reg - HV_REGISTER_SINT0 + HV_REGISTER_NESTED_SINT0;
+		return reg - HV_X64_MSR_SINT0 + HV_X64_MSR_NESTED_SINT0;
 
 	switch (reg) {
-	case HV_REGISTER_SIMP:
-		return HV_REGISTER_NESTED_SIMP;
-	case HV_REGISTER_SIEFP:
-		return HV_REGISTER_NESTED_SIEFP;
-	case HV_REGISTER_SVERSION:
-		return HV_REGISTER_NESTED_SVERSION;
-	case HV_REGISTER_SCONTROL:
-		return HV_REGISTER_NESTED_SCONTROL;
-	case HV_REGISTER_EOM:
-		return HV_REGISTER_NESTED_EOM;
+	case HV_X64_MSR_SIMP:
+		return HV_X64_MSR_NESTED_SIMP;
+	case HV_X64_MSR_SIEFP:
+		return HV_X64_MSR_NESTED_SIEFP;
+	case HV_X64_MSR_SVERSION:
+		return HV_X64_MSR_NESTED_SVERSION;
+	case HV_X64_MSR_SCONTROL:
+		return HV_X64_MSR_NESTED_SCONTROL;
+	case HV_X64_MSR_EOM:
+		return HV_X64_MSR_NESTED_EOM;
 	default:
 		return reg;
 	}
drivers/clocksource/hyperv_timer.c +12 -12
index 8ff7cd4e20bb..40832043dd21 100644
@@ -81,14 +81,14 @@ static int hv_ce_set_next_event(unsigned long delta,
 
 	current_tick = hv_read_reference_counter();
 	current_tick += delta;
-	hv_set_register(HV_REGISTER_STIMER0_COUNT, current_tick);
+	hv_set_register(HV_MSR_STIMER0_COUNT, current_tick);
 	return 0;
 }
 
 static int hv_ce_shutdown(struct clock_event_device *evt)
 {
-	hv_set_register(HV_REGISTER_STIMER0_COUNT, 0);
-	hv_set_register(HV_REGISTER_STIMER0_CONFIG, 0);
+	hv_set_register(HV_MSR_STIMER0_COUNT, 0);
+	hv_set_register(HV_MSR_STIMER0_CONFIG, 0);
 	if (direct_mode_enabled && stimer0_irq >= 0)
 		disable_percpu_irq(stimer0_irq);
 
@@ -119,7 +119,7 @@ static int hv_ce_set_oneshot(struct clock_event_device *evt)
 		timer_cfg.direct_mode = 0;
 		timer_cfg.sintx = stimer0_message_sint;
 	}
-	hv_set_register(HV_REGISTER_STIMER0_CONFIG, timer_cfg.as_uint64);
+	hv_set_register(HV_MSR_STIMER0_CONFIG, timer_cfg.as_uint64);
 	return 0;
 }
 
@@ -373,10 +373,10 @@ static __always_inline u64 read_hv_clock_msr(void)
 	 * nanosecond units.
 	 *
 	 * Use hv_raw_get_register() because this function is used from
-	 * noinstr. Notable; while HV_REGISTER_TIME_REF_COUNT is a synthetic
+	 * noinstr. Notable; while HV_MSR_TIME_REF_COUNT is a synthetic
 	 * register it doesn't need the GHCB path.
 	 */
-	return hv_raw_get_register(HV_REGISTER_TIME_REF_COUNT);
+	return hv_raw_get_register(HV_MSR_TIME_REF_COUNT);
 }
 
 /*
@@ -439,9 +439,9 @@ static void suspend_hv_clock_tsc(struct clocksource *arg)
 	union hv_reference_tsc_msr tsc_msr;
 
 	/* Disable the TSC page */
-	tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC);
+	tsc_msr.as_uint64 = hv_get_register(HV_MSR_REFERENCE_TSC);
 	tsc_msr.enable = 0;
-	hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64);
+	hv_set_register(HV_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
 }
 
 
@@ -450,10 +450,10 @@ static void resume_hv_clock_tsc(struct clocksource *arg)
 	union hv_reference_tsc_msr tsc_msr;
 
 	/* Re-enable the TSC page */
-	tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC);
+	tsc_msr.as_uint64 = hv_get_register(HV_MSR_REFERENCE_TSC);
 	tsc_msr.enable = 1;
 	tsc_msr.pfn = tsc_pfn;
-	hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64);
+	hv_set_register(HV_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
 }
 
 #ifdef HAVE_VDSO_CLOCKMODE_HVCLOCK
@@ -555,14 +555,14 @@ static void __init hv_init_tsc_clocksource(void)
 	 * thus TSC clocksource will work even without the real TSC page
 	 * mapped.
 	 */
-	tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC);
+	tsc_msr.as_uint64 = hv_get_register(HV_MSR_REFERENCE_TSC);
 	if (hv_root_partition)
 		tsc_pfn = tsc_msr.pfn;
 	else
 		tsc_pfn = HVPFN_DOWN(virt_to_phys(tsc_page));
 	tsc_msr.enable = 1;
 	tsc_msr.pfn = tsc_pfn;
-	hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64);
+	hv_set_register(HV_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
 
 	clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100);
 
drivers/hv/hv.c +18 -18
index 51e5018ac9b2..5ea104c61fa7 100644
@@ -270,7 +270,7 @@ void hv_synic_enable_regs(unsigned int cpu)
 	union hv_synic_scontrol sctrl;
 
 	/* Setup the Synic's message page */
-	simp.as_uint64 = hv_get_register(HV_REGISTER_SIMP);
+	simp.as_uint64 = hv_get_register(HV_MSR_SIMP);
 	simp.simp_enabled = 1;
 
 	if (ms_hyperv.paravisor_present || hv_root_partition) {
@@ -286,10 +286,10 @@ void hv_synic_enable_regs(unsigned int cpu)
 			>> HV_HYP_PAGE_SHIFT;
 	}
 
-	hv_set_register(HV_REGISTER_SIMP, simp.as_uint64);
+	hv_set_register(HV_MSR_SIMP, simp.as_uint64);
 
 	/* Setup the Synic's event page */
-	siefp.as_uint64 = hv_get_register(HV_REGISTER_SIEFP);
+	siefp.as_uint64 = hv_get_register(HV_MSR_SIEFP);
 	siefp.siefp_enabled = 1;
 
 	if (ms_hyperv.paravisor_present || hv_root_partition) {
@@ -305,12 +305,12 @@ void hv_synic_enable_regs(unsigned int cpu)
 			>> HV_HYP_PAGE_SHIFT;
 	}
 
-	hv_set_register(HV_REGISTER_SIEFP, siefp.as_uint64);
+	hv_set_register(HV_MSR_SIEFP, siefp.as_uint64);
 
 	/* Setup the shared SINT. */
 	if (vmbus_irq != -1)
 		enable_percpu_irq(vmbus_irq, 0);
-	shared_sint.as_uint64 = hv_get_register(HV_REGISTER_SINT0 +
+	shared_sint.as_uint64 = hv_get_register(HV_MSR_SINT0 +
 					VMBUS_MESSAGE_SINT);
 
 	shared_sint.vector = vmbus_interrupt;
@@ -326,14 +326,14 @@ void hv_synic_enable_regs(unsigned int cpu)
 #else
 	shared_sint.auto_eoi = 0;
 #endif
-	hv_set_register(HV_REGISTER_SINT0 + VMBUS_MESSAGE_SINT,
-				shared_sint.as_uint64);
+	hv_set_register(HV_MSR_SINT0 + VMBUS_MESSAGE_SINT,
+			shared_sint.as_uint64);
 
 	/* Enable the global synic bit */
-	sctrl.as_uint64 = hv_get_register(HV_REGISTER_SCONTROL);
+	sctrl.as_uint64 = hv_get_register(HV_MSR_SCONTROL);
 	sctrl.enable = 1;
 
-	hv_set_register(HV_REGISTER_SCONTROL, sctrl.as_uint64);
+	hv_set_register(HV_MSR_SCONTROL, sctrl.as_uint64);
 }
 
 int hv_synic_init(unsigned int cpu)
@@ -357,17 +357,17 @@ void hv_synic_disable_regs(unsigned int cpu)
 	union hv_synic_siefp siefp;
 	union hv_synic_scontrol sctrl;
 
-	shared_sint.as_uint64 = hv_get_register(HV_REGISTER_SINT0 +
+	shared_sint.as_uint64 = hv_get_register(HV_MSR_SINT0 +
 					VMBUS_MESSAGE_SINT);
 
 	shared_sint.masked = 1;
 
 	/* Need to correctly cleanup in the case of SMP!!! */
 	/* Disable the interrupt */
-	hv_set_register(HV_REGISTER_SINT0 + VMBUS_MESSAGE_SINT,
-				shared_sint.as_uint64);
+	hv_set_register(HV_MSR_SINT0 + VMBUS_MESSAGE_SINT,
+			shared_sint.as_uint64);
 
-	simp.as_uint64 = hv_get_register(HV_REGISTER_SIMP);
+	simp.as_uint64 = hv_get_register(HV_MSR_SIMP);
 	/*
 	 * In Isolation VM, sim and sief pages are allocated by
 	 * paravisor. These pages also will be used by kdump
@@ -382,9 +382,9 @@ void hv_synic_disable_regs(unsigned int cpu)
 		simp.base_simp_gpa = 0;
 	}
 
-	hv_set_register(HV_REGISTER_SIMP, simp.as_uint64);
+	hv_set_register(HV_MSR_SIMP, simp.as_uint64);
 
-	siefp.as_uint64 = hv_get_register(HV_REGISTER_SIEFP);
+	siefp.as_uint64 = hv_get_register(HV_MSR_SIEFP);
 	siefp.siefp_enabled = 0;
 
 	if (ms_hyperv.paravisor_present || hv_root_partition) {
@@ -394,12 +394,12 @@ void hv_synic_disable_regs(unsigned int cpu)
 		siefp.base_siefp_gpa = 0;
 	}
 
-	hv_set_register(HV_REGISTER_SIEFP, siefp.as_uint64);
+	hv_set_register(HV_MSR_SIEFP, siefp.as_uint64);
 
 	/* Disable the global synic bit */
-	sctrl.as_uint64 = hv_get_register(HV_REGISTER_SCONTROL);
+	sctrl.as_uint64 = hv_get_register(HV_MSR_SCONTROL);
 	sctrl.enable = 0;
-	hv_set_register(HV_REGISTER_SCONTROL, sctrl.as_uint64);
+	hv_set_register(HV_MSR_SCONTROL, sctrl.as_uint64);
 
 	if (vmbus_irq != -1)
 		disable_percpu_irq(vmbus_irq);
drivers/hv/hv_common.c +9 -9
index ccad7bca3fd3..0be3fbec52dd 100644
@@ -228,17 +228,17 @@ static void hv_kmsg_dump(struct kmsg_dumper *dumper,
 	 * contain the size of the panic data in that page. Rest of the
 	 * registers are no-op when the NOTIFY_MSG flag is set.
 	 */
-	hv_set_register(HV_REGISTER_CRASH_P0, 0);
-	hv_set_register(HV_REGISTER_CRASH_P1, 0);
-	hv_set_register(HV_REGISTER_CRASH_P2, 0);
-	hv_set_register(HV_REGISTER_CRASH_P3, virt_to_phys(hv_panic_page));
-	hv_set_register(HV_REGISTER_CRASH_P4, bytes_written);
+	hv_set_register(HV_MSR_CRASH_P0, 0);
+	hv_set_register(HV_MSR_CRASH_P1, 0);
+	hv_set_register(HV_MSR_CRASH_P2, 0);
+	hv_set_register(HV_MSR_CRASH_P3, virt_to_phys(hv_panic_page));
+	hv_set_register(HV_MSR_CRASH_P4, bytes_written);
 
 	/*
 	 * Let Hyper-V know there is crash data available along with
 	 * the panic message.
 	 */
-	hv_set_register(HV_REGISTER_CRASH_CTL,
+	hv_set_register(HV_MSR_CRASH_CTL,
 			(HV_CRASH_CTL_CRASH_NOTIFY |
 			 HV_CRASH_CTL_CRASH_NOTIFY_MSG));
 }
@@ -311,7 +311,7 @@ int __init hv_common_init(void)
 		 * Register for panic kmsg callback only if the right
 		 * capability is supported by the hypervisor.
 		 */
-		hyperv_crash_ctl = hv_get_register(HV_REGISTER_CRASH_CTL);
+		hyperv_crash_ctl = hv_get_register(HV_MSR_CRASH_CTL);
 		if (hyperv_crash_ctl & HV_CRASH_CTL_CRASH_NOTIFY_MSG)
 			hv_kmsg_dump_register();
 
@@ -410,7 +410,7 @@ int hv_common_cpu_init(unsigned int cpu)
 		*inputarg = mem;
 	}
 
-	msr_vp_index = hv_get_register(HV_REGISTER_VP_INDEX);
+	msr_vp_index = hv_get_register(HV_MSR_VP_INDEX);
 
 	hv_vp_index[cpu] = msr_vp_index;
 
@@ -507,7 +507,7 @@ EXPORT_SYMBOL_GPL(hv_is_hibernation_supported);
  */
 static u64 __hv_read_ref_counter(void)
 {
-	return hv_get_register(HV_REGISTER_TIME_REF_COUNT);
+	return hv_get_register(HV_MSR_TIME_REF_COUNT);
 }
 
 u64 (*hv_read_reference_counter)(void) = __hv_read_ref_counter;
include/asm-generic/mshyperv.h +1 -1
index cecd2b7bd033..56f4a447a178 100644
@@ -157,7 +157,7 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
 		 * possibly deliver another msg from the
 		 * hypervisor
 		 */
-		hv_set_register(HV_REGISTER_EOM, 0);
+		hv_set_register(HV_MSR_EOM, 0);
 	}
 }
 
Signature · 1 line
2.25.1
#2 lore raw

PATCH v4 2/15 mshyperv: Introduce hv_get_hypervisor_version function

In reply to Nuno Das Neves

x86_64 and arm64 implementations to get the hypervisor version information. Store these in hv_hypervisor_version_info structure to simplify parsing the fields.

Replace the existing parsing when printing the version numbers at boot.

---
 arch/arm64/hyperv/mshyperv.c      | 23 +++++++++++++-------
 arch/x86/kernel/cpu/mshyperv.c    | 36 +++++++++++++++++++------------
 include/asm-generic/hyperv-tlfs.h | 23 ++++++++++++++++++++
 include/asm-generic/mshyperv.h    |  2 ++
 4 files changed, 62 insertions(+), 22 deletions(-)
arch/arm64/hyperv/mshyperv.c +15 -8
index f1b8a04ee9f2..53bdd3bc81ac 100644
@@ -19,10 +19,19 @@
 
 static bool hyperv_initialized;
 
+int hv_get_hypervisor_version(union hv_hypervisor_version_info *info)
+{
+	hv_get_vpreg_128(HV_REGISTER_HYPERVISOR_VERSION,
+			 (struct hv_get_vp_registers_output *)info);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(hv_get_hypervisor_version);
+
 static int __init hyperv_init(void)
 {
-	struct hv_get_vp_registers_output	result;
-	u32	a, b, c, d;
+	struct hv_get_vp_registers_output result;
+	union hv_hypervisor_version_info version;
 	u64	guest_id;
 	int	ret;
 
@@ -55,13 +64,11 @@ static int __init hyperv_init(void)
 		ms_hyperv.misc_features);
 
 	/* Get information about the Hyper-V host version */
-	hv_get_vpreg_128(HV_REGISTER_HYPERVISOR_VERSION, &result);
-	a = result.as32.a;
-	b = result.as32.b;
-	c = result.as32.c;
-	d = result.as32.d;
+	hv_get_hypervisor_version(&version);
 	pr_info("Hyper-V: Host Build %d.%d.%d.%d-%d-%d\n",
-		b >> 16, b & 0xFFFF, a,	d & 0xFFFFFF, c, d >> 24);
+		version.major_version, version.minor_version,
+		version.build_number, version.service_number,
+		version.service_pack, version.service_branch);
 
 	ret = hv_common_init();
 	if (ret)
arch/x86/kernel/cpu/mshyperv.c +22 -14
index d85a8e2a10c9..9b898b65a013 100644
@@ -347,13 +347,26 @@ static void __init reduced_hw_init(void)
 	x86_init.irqs.pre_vector_init	= x86_init_noop;
 }
 
+int hv_get_hypervisor_version(union hv_hypervisor_version_info *info)
+{
+	unsigned int hv_max_functions;
+
+	hv_max_functions = cpuid_eax(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS);
+	if (hv_max_functions < HYPERV_CPUID_VERSION) {
+		pr_err("%s: Could not detect Hyper-V version\n", __func__);
+		return -ENODEV;
+	}
+
+	cpuid(HYPERV_CPUID_VERSION, &info->eax, &info->ebx, &info->ecx, &info->edx);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(hv_get_hypervisor_version);
+
 static void __init ms_hyperv_init_platform(void)
 {
 	int hv_max_functions_eax;
-	int hv_host_info_eax;
-	int hv_host_info_ebx;
-	int hv_host_info_ecx;
-	int hv_host_info_edx;
+	union hv_hypervisor_version_info version;
 
 #ifdef CONFIG_PARAVIRT
 	pv_info.name = "Hyper-V";
@@ -407,16 +420,11 @@ static void __init ms_hyperv_init_platform(void)
 	/*
 	 * Extract host information.
 	 */
-	if (hv_max_functions_eax >= HYPERV_CPUID_VERSION) {
-		hv_host_info_eax = cpuid_eax(HYPERV_CPUID_VERSION);
-		hv_host_info_ebx = cpuid_ebx(HYPERV_CPUID_VERSION);
-		hv_host_info_ecx = cpuid_ecx(HYPERV_CPUID_VERSION);
-		hv_host_info_edx = cpuid_edx(HYPERV_CPUID_VERSION);
-
-		pr_info("Hyper-V: Host Build %d.%d.%d.%d-%d-%d\n",
-			hv_host_info_ebx >> 16, hv_host_info_ebx & 0xFFFF,
-			hv_host_info_eax, hv_host_info_edx & 0xFFFFFF,
-			hv_host_info_ecx, hv_host_info_edx >> 24);
+	if (hv_get_hypervisor_version(&version) == 0) {
+		pr_info("Hyper-V Host Build:%d-%d.%d-%d-%d.%d\n",
+			version.build_number, version.major_version,
+			version.minor_version, version.service_pack,
+			version.service_branch, version.service_number);
 	}
 
 	if (ms_hyperv.features & HV_ACCESS_FREQUENCY_MSRS &&
include/asm-generic/hyperv-tlfs.h +23 -0
index fdac4a1714ec..f63b3704d89e 100644
@@ -787,6 +787,29 @@ struct hv_input_unmap_device_interrupt {
 #define HV_SOURCE_SHADOW_NONE               0x0
 #define HV_SOURCE_SHADOW_BRIDGE_BUS_RANGE   0x1
 
+/*
+ * Version info reported by hypervisor
+ */
+union hv_hypervisor_version_info {
+	struct {
+		u32 build_number;
+
+		u32 minor_version : 16;
+		u32 major_version : 16;
+
+		u32 service_pack;
+
+		u32 service_number : 24;
+		u32 service_branch : 8;
+	};
+	struct {
+		u32 eax;
+		u32 ebx;
+		u32 ecx;
+		u32 edx;
+	};
+};
+
 /*
  * The whole argument should fit in a page to be able to pass to the hypervisor
  * in one hypercall.
include/asm-generic/mshyperv.h +2 -0
index 56f4a447a178..9f2c06c9d5d1 100644
@@ -161,6 +161,8 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
 	}
 }
 
+int hv_get_hypervisor_version(union hv_hypervisor_version_info *info);
+
 void hv_setup_vmbus_handler(void (*handler)(void));
 void hv_remove_vmbus_handler(void);
 void hv_setup_stimer0_handler(void (*handler)(void));
Signature · 1 line
2.25.1
#3 lore raw

PATCH v4 3/15 mshyperv: Introduce numa_node_to_proximity_domain_info

In reply to Nuno Das Neves

Factor out logic for converting numa node to proximity domain info into a helper function, and export it.

Change hv_proximity_domain_info to a struct to simplify the code.

---
 arch/x86/hyperv/hv_proc.c         |  8 ++------
 drivers/acpi/numa/srat.c          |  1 +
 include/asm-generic/hyperv-tlfs.h | 14 +++++---------
 include/asm-generic/mshyperv.h    | 15 +++++++++++++++
 4 files changed, 23 insertions(+), 15 deletions(-)
arch/x86/hyperv/hv_proc.c +2 -6
index 68a0843d4750..5ba5ca1b2089 100644
@@ -121,7 +121,6 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
 	u64 status;
 	unsigned long flags;
 	int ret = HV_STATUS_SUCCESS;
-	int pxm = node_to_pxm(node);
 
 	/*
 	 * When adding a logical processor, the hypervisor may return
@@ -137,11 +136,8 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
 
 		input->lp_index = lp_index;
 		input->apic_id = apic_id;
-		input->flags = 0;
-		input->proximity_domain_info.domain_id = pxm;
-		input->proximity_domain_info.flags.reserved = 0;
-		input->proximity_domain_info.flags.proximity_info_valid = 1;
-		input->proximity_domain_info.flags.proximity_preferred = 1;
+		input->proximity_domain_info =
+			numa_node_to_proximity_domain_info(node);
 		status = hv_do_hypercall(HVCALL_ADD_LOGICAL_PROCESSOR,
 					 input, output);
 		local_irq_restore(flags);
drivers/acpi/numa/srat.c +1 -0
index 1f4fc5f8a819..0cf9f0574495 100644
@@ -48,6 +48,7 @@ int node_to_pxm(int node)
 		return PXM_INVAL;
 	return node_to_pxm_map[node];
 }
+EXPORT_SYMBOL(node_to_pxm);
 
 static void __acpi_map_pxm_to_node(int pxm, int node)
 {
include/asm-generic/hyperv-tlfs.h +5 -9
index f63b3704d89e..a6dffb346bf2 100644
@@ -512,13 +512,9 @@ struct hv_proximity_domain_flags {
 	u32 proximity_info_valid : 1;
 } __packed;
 
-/* Not a union in windows but useful for zeroing */
-union hv_proximity_domain_info {
-	struct {
-		u32 domain_id;
-		struct hv_proximity_domain_flags flags;
-	};
-	u64 as_uint64;
+struct hv_proximity_domain_info {
+	u32 domain_id;
+	struct hv_proximity_domain_flags flags;
 } __packed;
 
 struct hv_lp_startup_status {
@@ -535,7 +531,7 @@ struct hv_lp_startup_status {
 struct hv_add_logical_processor_in {
 	u32 lp_index;
 	u32 apic_id;
-	union hv_proximity_domain_info proximity_domain_info;
+	struct hv_proximity_domain_info proximity_domain_info;
 	u64 flags;
 } __packed;
 
@@ -560,7 +556,7 @@ struct hv_create_vp {
 	u8 padding[3];
 	u8 subnode_type;
 	u64 subnode_id;
-	union hv_proximity_domain_info proximity_domain_info;
+	struct hv_proximity_domain_info proximity_domain_info;
 	u64 flags;
 } __packed;
 
include/asm-generic/mshyperv.h +15 -0
index 9f2c06c9d5d1..8cc7b0e316d7 100644
@@ -21,6 +21,7 @@
 #include <linux/types.h>
 #include <linux/atomic.h>
 #include <linux/bitops.h>
+#include <acpi/acpi_numa.h>
 #include <linux/cpumask.h>
 #include <linux/nmi.h>
 #include <asm/ptrace.h>
@@ -28,6 +29,20 @@
 
 #define VTPM_BASE_ADDRESS 0xfed40000
 
+static inline struct hv_proximity_domain_info
+numa_node_to_proximity_domain_info(int node)
+{
+	struct hv_proximity_domain_info proximity_domain_info = {};
+
+	if (node != NUMA_NO_NODE) {
+		proximity_domain_info.domain_id = node_to_pxm(node);
+		proximity_domain_info.flags.proximity_info_valid = 1;
+		proximity_domain_info.flags.proximity_preferred = 1;
+	}
+
+	return proximity_domain_info;
+}
+
 struct ms_hyperv_info {
 	u32 features;
 	u32 priv_high;
Signature · 1 line
2.25.1
#4 lore raw

PATCH v4 4/15 asm-generic/mshyperv: Introduce hv_recommend_using_aeoi()

In reply to Nuno Das Neves

Factor out logic for determining if we should set the auto eoi flag in SINT register.

---
 drivers/hv/hv.c                | 12 +-----------
 include/asm-generic/mshyperv.h | 13 +++++++++++++
 2 files changed, 14 insertions(+), 11 deletions(-)
drivers/hv/hv.c +1 -11
index 5ea104c61fa7..d7869205dcbe 100644
@@ -315,17 +315,7 @@ void hv_synic_enable_regs(unsigned int cpu)
 
 	shared_sint.vector = vmbus_interrupt;
 	shared_sint.masked = false;
-
-	/*
-	 * On architectures where Hyper-V doesn't support AEOI (e.g., ARM64),
-	 * it doesn't provide a recommendation flag and AEOI must be disabled.
-	 */
-#ifdef HV_DEPRECATING_AEOI_RECOMMENDED
-	shared_sint.auto_eoi =
-			!(ms_hyperv.hints & HV_DEPRECATING_AEOI_RECOMMENDED);
-#else
-	shared_sint.auto_eoi = 0;
-#endif
+	shared_sint.auto_eoi = hv_recommend_using_aeoi();
 	hv_set_register(HV_MSR_SINT0 + VMBUS_MESSAGE_SINT,
 			shared_sint.as_uint64);
 
include/asm-generic/mshyperv.h +13 -0
index 8cc7b0e316d7..3e715aa114da 100644
@@ -82,6 +82,19 @@ extern u64 hv_do_fast_hypercall8(u16 control, u64 input8);
 bool hv_isolation_type_snp(void);
 bool hv_isolation_type_tdx(void);
 
+/*
+ * On architectures where Hyper-V doesn't support AEOI (e.g., ARM64),
+ * it doesn't provide a recommendation flag and AEOI must be disabled.
+ */
+static inline bool hv_recommend_using_aeoi(void)
+{
+#ifdef HV_DEPRECATING_AEOI_RECOMMENDED
+	return !(ms_hyperv.hints & HV_DEPRECATING_AEOI_RECOMMENDED);
+#else
+	return false;
+#endif
+}
+
 /* Helper functions that provide a consistent pattern for checking Hyper-V hypercall status. */
 static inline int hv_result(u64 status)
 {
Signature · 1 line
2.25.1
#5 lore raw

PATCH v4 5/15 hyperv: Move hv_connection_id to hyperv-tlfs

In reply to Nuno Das Neves

The definition conflicts with one added in hvgdk.h as part of the mshv driver so must be moved to hyperv-tlfs.h.

This structure should be in hyperv-tlfs.h anyway, since it is part of the TLFS document.

---
 include/asm-generic/hyperv-tlfs.h | 9 +++++++++
 include/linux/hyperv.h            | 9 ---------
 2 files changed, 9 insertions(+), 9 deletions(-)
include/asm-generic/hyperv-tlfs.h +9 -0
index a6dffb346bf2..1316584983c1 100644
@@ -842,4 +842,13 @@ struct hv_mmio_write_input {
 	u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH];
 } __packed;
 
+/* Define connection identifier type. */
+union hv_connection_id {
+	u32 asu32;
+	struct {
+		u32 id:24;
+		u32 reserved:8;
+	} u;
+};
+
 #endif
include/linux/hyperv.h +0 -9
index 2b00faf98017..4d5a5e39d76c 100644
@@ -748,15 +748,6 @@ struct vmbus_close_msg {
 	struct vmbus_channel_close_channel msg;
 };
 
-/* Define connection identifier type. */
-union hv_connection_id {
-	u32 asu32;
-	struct {
-		u32 id:24;
-		u32 reserved:8;
-	} u;
-};
-
 enum vmbus_device_type {
 	HV_IDE = 0,
 	HV_SCSI,
Signature · 1 line
2.25.1
#6 lore raw

PATCH v4 6/15 hyperv-tlfs: Introduce hv_status_to_string and hv_status_to_errno

In reply to Nuno Das Neves

hv_status_to_errno translates hyperv statuses to linux error codes. This is useful for returning something linux-friendly from a hypercall helper function.

hv_status_to_string improves clarity of error messages.

---
 arch/x86/hyperv/hv_init.c         |  2 +-
 arch/x86/hyperv/hv_proc.c         |  6 ++--
 include/asm-generic/hyperv-tlfs.h | 47 ++++++++++++++++++++++---------
 include/asm-generic/mshyperv.h    | 33 ++++++++++++++++++++++
 4 files changed, 71 insertions(+), 17 deletions(-)
arch/x86/hyperv/hv_init.c +1 -1
index 783ed339f341..515ca168748d 100644
@@ -387,7 +387,7 @@ static void __init hv_get_partition_id(void)
 	status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output_page);
 	if (!hv_result_success(status)) {
 		/* No point in proceeding if this failed */
-		pr_err("Failed to get partition ID: %lld\n", status);
+		pr_err("Failed to get partition ID: %s\n", hv_status_to_string(status));
 		BUG();
 	}
 	hv_current_partition_id = output_page->partition_id;
arch/x86/hyperv/hv_proc.c +3 -3
index 5ba5ca1b2089..ed80da64649e 100644
@@ -144,9 +144,9 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
 
 		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
 			if (!hv_result_success(status)) {
-				pr_err("%s: cpu %u apic ID %u, %lld\n", __func__,
-				       lp_index, apic_id, status);
-				ret = hv_result(status);
+				pr_err("%s: cpu %u apic ID %u, %s\n", __func__,
+				       lp_index, apic_id, hv_status_to_string(status));
+				ret = hv_status_to_errno(status);
 			}
 			break;
 		}
include/asm-generic/hyperv-tlfs.h +34 -13

53 lines not on this page · raw message

include/asm-generic/mshyperv.h +33 -0
index 3e715aa114da..d6310a40fbde 100644
@@ -305,6 +305,39 @@ static inline int cpumask_to_vpset_skip(struct hv_vpset *vpset,
 	return __cpumask_to_vpset(vpset, cpus, func);
 }
 
+
+static inline int hv_status_to_errno(u64 hv_status)
+{
+	switch (hv_result(hv_status)) {
+	case HV_STATUS_SUCCESS:
+		return 0;
+	case HV_STATUS_INVALID_PARAMETER:
+	case HV_STATUS_UNKNOWN_PROPERTY:
+	case HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE:
+	case HV_STATUS_INVALID_VP_INDEX:
+	case HV_STATUS_INVALID_REGISTER_VALUE:
+	case HV_STATUS_INVALID_LP_INDEX:
+	case HV_STATUS_PROCESSOR_FEATURE_NOT_SUPPORTED:
+		return -EINVAL;
+	case HV_STATUS_ACCESS_DENIED:
+	case HV_STATUS_OPERATION_DENIED:
+		return -EACCES;
+	case HV_STATUS_NOT_ACKNOWLEDGED:
+	case HV_STATUS_INVALID_VP_STATE:
+	case HV_STATUS_INVALID_PARTITION_STATE:
+		return -EBADFD;
+	}
+	return -ENOTRECOVERABLE;
+}
+
+static inline const char *hv_status_to_string(u64 hv_status)
+{
+	switch (hv_result(hv_status)) {
+	__HV_STATUS_DEF(__HV_MAKE_HV_STATUS_CASE)
+	default : return "Unknown";
+	}
+}
+
 void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die);
 bool hv_is_hyperv_initialized(void);
 bool hv_is_hibernation_supported(void);
Signature · 1 line
2.25.1
#7 lore raw

PATCH v4 7/15 Drivers: hv: Move hv_call_deposit_pages and hv_call_create_vp to common code

In reply to Nuno Das Neves

These hypercalls are not arch-specific. Move them to common code.

---
 arch/x86/hyperv/hv_proc.c       | 152 --------------------------------
 arch/x86/include/asm/mshyperv.h |   1 -
 drivers/hv/hv_common.c          | 147 ++++++++++++++++++++++++++++++
 include/asm-generic/mshyperv.h  |   2 +
 4 files changed, 149 insertions(+), 153 deletions(-)
arch/x86/hyperv/hv_proc.c +0 -152
index ed80da64649e..0a35cb865427 100644
@@ -3,7 +3,6 @@
 #include <linux/vmalloc.h>
 #include <linux/mm.h>
 #include <linux/clockchips.h>
-#include <linux/acpi.h>
 #include <linux/hyperv.h>
 #include <linux/slab.h>
 #include <linux/cpuhotplug.h>
@@ -14,106 +13,6 @@
 
 #include <asm/trace/hyperv.h>
 
-/*
- * See struct hv_deposit_memory. The first u64 is partition ID, the rest
- * are GPAs.
- */
-#define HV_DEPOSIT_MAX (HV_HYP_PAGE_SIZE / sizeof(u64) - 1)
-
-/* Deposits exact number of pages. Must be called with interrupts enabled.  */
-int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
-{
-	struct page **pages, *page;
-	int *counts;
-	int num_allocations;
-	int i, j, page_count;
-	int order;
-	u64 status;
-	int ret;
-	u64 base_pfn;
-	struct hv_deposit_memory *input_page;
-	unsigned long flags;
-
-	if (num_pages > HV_DEPOSIT_MAX)
-		return -E2BIG;
-	if (!num_pages)
-		return 0;
-
-	/* One buffer for page pointers and counts */
-	page = alloc_page(GFP_KERNEL);
-	if (!page)
-		return -ENOMEM;
-	pages = page_address(page);
-
-	counts = kcalloc(HV_DEPOSIT_MAX, sizeof(int), GFP_KERNEL);
-	if (!counts) {
-		free_page((unsigned long)pages);
-		return -ENOMEM;
-	}
-
-	/* Allocate all the pages before disabling interrupts */
-	i = 0;
-
-	while (num_pages) {
-		/* Find highest order we can actually allocate */
-		order = 31 - __builtin_clz(num_pages);
-
-		while (1) {
-			pages[i] = alloc_pages_node(node, GFP_KERNEL, order);
-			if (pages[i])
-				break;
-			if (!order) {
-				ret = -ENOMEM;
-				num_allocations = i;
-				goto err_free_allocations;
-			}
-			--order;
-		}
-
-		split_page(pages[i], order);
-		counts[i] = 1 << order;
-		num_pages -= counts[i];
-		i++;
-	}
-	num_allocations = i;
-
-	local_irq_save(flags);
-
-	input_page = *this_cpu_ptr(hyperv_pcpu_input_arg);
-
-	input_page->partition_id = partition_id;
-
-	/* Populate gpa_page_list - these will fit on the input page */
-	for (i = 0, page_count = 0; i < num_allocations; ++i) {
-		base_pfn = page_to_pfn(pages[i]);
-		for (j = 0; j < counts[i]; ++j, ++page_count)
-			input_page->gpa_page_list[page_count] = base_pfn + j;
-	}
-	status = hv_do_rep_hypercall(HVCALL_DEPOSIT_MEMORY,
-				     page_count, 0, input_page, NULL);
-	local_irq_restore(flags);
-	if (!hv_result_success(status)) {
-		pr_err("Failed to deposit pages: %lld\n", status);
-		ret = hv_result(status);
-		goto err_free_allocations;
-	}
-
-	ret = 0;
-	goto free_buf;
-
-err_free_allocations:
-	for (i = 0; i < num_allocations; ++i) {
-		base_pfn = page_to_pfn(pages[i]);
-		for (j = 0; j < counts[i]; ++j)
-			__free_page(pfn_to_page(base_pfn + j));
-	}
-
-free_buf:
-	free_page((unsigned long)pages);
-	kfree(counts);
-	return ret;
-}
-
 int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
 {
 	struct hv_add_logical_processor_in *input;
@@ -156,54 +55,3 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
 	return ret;
 }
 
-int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
-{
-	struct hv_create_vp *input;
-	u64 status;
-	unsigned long irq_flags;
-	int ret = HV_STATUS_SUCCESS;
-	int pxm = node_to_pxm(node);
-
-	/* Root VPs don't seem to need pages deposited */
-	if (partition_id != hv_current_partition_id) {
-		/* The value 90 is empirically determined. It may change. */
-		ret = hv_call_deposit_pages(node, partition_id, 90);
-		if (ret)
-			return ret;
-	}
-
-	do {
-		local_irq_save(irq_flags);
-
-		input = *this_cpu_ptr(hyperv_pcpu_input_arg);
-
-		input->partition_id = partition_id;
-		input->vp_index = vp_index;
-		input->flags = flags;
-		input->subnode_type = HvSubnodeAny;
-		if (node != NUMA_NO_NODE) {
-			input->proximity_domain_info.domain_id = pxm;
-			input->proximity_domain_info.flags.reserved = 0;
-			input->proximity_domain_info.flags.proximity_info_valid = 1;
-			input->proximity_domain_info.flags.proximity_preferred = 1;
-		} else {
-			input->proximity_domain_info.as_uint64 = 0;
-		}
-		status = hv_do_hypercall(HVCALL_CREATE_VP, input, NULL);
-		local_irq_restore(irq_flags);
-
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
-			if (!hv_result_success(status)) {
-				pr_err("%s: vcpu %u, lp %u, %lld\n", __func__,
-				       vp_index, flags, status);
-				ret = hv_result(status);
-			}
-			break;
-		}
-		ret = hv_call_deposit_pages(node, partition_id, 1);
-
-	} while (!ret);
-
-	return ret;
-}
-
arch/x86/include/asm/mshyperv.h +0 -1
index e918b4132de8..e3768d787065 100644
@@ -62,7 +62,6 @@ u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2);
 
 int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
 int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
-int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
 
 /*
  * If the hypercall involves no input or output parameters, the hypervisor
drivers/hv/hv_common.c +147 -0

150 lines not on this page · raw message

include/asm-generic/mshyperv.h +2 -0
index d6310a40fbde..4f2bb6099063 100644
@@ -349,6 +349,8 @@ u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2);
 void hyperv_cleanup(void);
 bool hv_query_ext_cap(u64 cap_query);
 void hv_setup_dma_ops(struct device *dev, bool coherent);
+int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
+int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
 #else /* CONFIG_HYPERV */
 static inline bool hv_is_hyperv_initialized(void) { return false; }
 static inline bool hv_is_hibernation_supported(void) { return false; }
Signature · 1 line
2.25.1
#8 lore raw

Re: [PATCH v4 07/15] Drivers: hv: Move hv_call_deposit_pages and hv_call_create_vp to common code

kernel test robot noticed the following build errors:

Hi Nuno,

kernel test robot noticed the following build errors:

[auto build test ERROR on arnd-asm-generic/master]
[also build test ERROR on arm64/for-next/core linus/master v6.6-rc4 next-20230929] [cannot apply to tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nuno-Das-Neves/hyperv-tlfs-Change-shared-HV_REGISTER_-defines-to-HV_MSR_/20230930-041305
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git master
patch link:    https://lore.kernel.org/r/1696010501-24584-8-git-send-email-nunodasneves%40linux.microsoft.com
patch subject: [PATCH v4 07/15] Drivers: hv: Move hv_call_deposit_pages and hv_call_create_vp to common code
config: arm64-allyesconfig (https://download.01.org/0day-ci/archive/20231003/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231003/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/hv/hv_common.c: In function 'hv_call_create_vp':

>> drivers/hv/hv_common.c:596:29: error: 'hv_current_partition_id' undeclared (first use in this function); did you mean 'hv_get_partition_id'?
     596 |         if (partition_id != hv_current_partition_id) {
         |                             ^~~~~~~~~~~~~~~~~~~~~~~
         |                             hv_get_partition_id

drivers/hv/hv_common.c:596:29: note: each undeclared identifier is reported only once for each function it appears in

vim +596 drivers/hv/hv_common.c

587
588 int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
589 {
590 struct hv_create_vp *input;
591 u64 status;
592 unsigned long irq_flags;
593 int ret = HV_STATUS_SUCCESS;
594
595 /* Root VPs don't seem to need pages deposited */

 > 596		if (partition_id != hv_current_partition_id) {

597 /* The value 90 is empirically determined. It may change. */
598 ret = hv_call_deposit_pages(node, partition_id, 90);
599 if (ret)
600 return ret;
601 }
602
603 do {
604 local_irq_save(irq_flags);
605
606 input = *this_cpu_ptr(hyperv_pcpu_input_arg);
607
608 input->partition_id = partition_id;
609 input->vp_index = vp_index;
610 input->flags = flags;
611 input->subnode_type = HvSubnodeAny;
612 input->proximity_domain_info =
613 numa_node_to_proximity_domain_info(node);
614 status = hv_do_hypercall(HVCALL_CREATE_VP, input, NULL);
615 local_irq_restore(irq_flags);
616
617 if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
618 if (!hv_result_success(status)) {
619 pr_err("%s: vcpu %u, lp %u, %s\n", __func__,
620 vp_index, flags, hv_status_to_string(status));
621 ret = hv_status_to_errno(status);
622 }
623 break;
624 }
625 ret = hv_call_deposit_pages(node, partition_id, 1);
626
627 } while (!ret);
628
629 return ret;
630 }
631 EXPORT_SYMBOL_GPL(hv_call_create_vp);
632

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#9 lore raw

PATCH v4 8/15 Drivers: hv: Introduce per-cpu event ring tail

In reply to Nuno Das Neves

Add a pointer hv_synic_eventring_tail to track the tail pointer for the SynIC event ring buffer for each SINT.

This will be used by the mshv driver, but must be tracked independently since the driver module could be removed and re-inserted.

---
 drivers/hv/hv_common.c         | 28 ++++++++++++++++++++++++++--
 include/asm-generic/mshyperv.h |  2 ++
 2 files changed, 28 insertions(+), 2 deletions(-)
drivers/hv/hv_common.c +26 -2
index 9d9f6f90f99e..39077841d518 100644
@@ -62,6 +62,16 @@ static void hv_kmsg_dump_unregister(void);
 
 static struct ctl_table_header *hv_ctl_table_hdr;
 
+/*
+ * Per-cpu array holding the tail pointer for the SynIC event ring buffer
+ * for each SINT.
+ *
+ * We cannot maintain this in mshv driver because the tail pointer should
+ * persist even if the mshv driver is unloaded.
+ */
+u8 __percpu **hv_synic_eventring_tail;
+EXPORT_SYMBOL_GPL(hv_synic_eventring_tail);
+
 /*
  * Hyper-V specific initialization and shutdown code that is
  * common across all architectures.  Called from architecture
@@ -84,6 +94,9 @@ void __init hv_common_free(void)
 
 	free_percpu(hyperv_pcpu_input_arg);
 	hyperv_pcpu_input_arg = NULL;
+
+	free_percpu(hv_synic_eventring_tail);
+	hv_synic_eventring_tail = NULL;
 }
 
 /*
@@ -333,6 +346,8 @@ int __init hv_common_init(void)
 	if (hv_root_partition) {
 		hyperv_pcpu_output_arg = alloc_percpu(void *);
 		BUG_ON(!hyperv_pcpu_output_arg);
+		hv_synic_eventring_tail = alloc_percpu(u8 *);
+		BUG_ON(hv_synic_eventring_tail == NULL);
 	}
 
 	hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index),
@@ -357,6 +372,7 @@ int __init hv_common_init(void)
 int hv_common_cpu_init(unsigned int cpu)
 {
 	void **inputarg, **outputarg;
+	u8 **synic_eventring_tail;
 	u64 msr_vp_index;
 	gfp_t flags;
 	int pgcount = hv_root_partition ? 2 : 1;
@@ -369,8 +385,8 @@ int hv_common_cpu_init(unsigned int cpu)
 	inputarg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg);
 
 	/*
-	 * hyperv_pcpu_input_arg and hyperv_pcpu_output_arg memory is already
-	 * allocated if this CPU was previously online and then taken offline
+	 * The per-cpu memory is already allocated if this CPU was previously
+	 * online and then taken offline
 	 */
 	if (!*inputarg) {
 		mem = kmalloc(pgcount * HV_HYP_PAGE_SIZE, flags);
@@ -380,6 +396,14 @@ int hv_common_cpu_init(unsigned int cpu)
 		if (hv_root_partition) {
 			outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg);
 			*outputarg = (char *)mem + HV_HYP_PAGE_SIZE;
+			synic_eventring_tail = (u8 **)this_cpu_ptr(hv_synic_eventring_tail);
+			*synic_eventring_tail = kcalloc(HV_SYNIC_SINT_COUNT, sizeof(u8),
+							flags);
+
+			if (unlikely(!*synic_eventring_tail)) {
+				kfree(mem);
+				return -ENOMEM;
+			}
 		}
 
 		if (!ms_hyperv.paravisor_present &&
include/asm-generic/mshyperv.h +2 -0
index 4f2bb6099063..4e49fd662b2b 100644
@@ -77,6 +77,8 @@ extern bool hv_nested;
 extern void * __percpu *hyperv_pcpu_input_arg;
 extern void * __percpu *hyperv_pcpu_output_arg;
 
+extern u8 __percpu **hv_synic_eventring_tail;
+
 extern u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr);
 extern u64 hv_do_fast_hypercall8(u16 control, u64 input8);
 bool hv_isolation_type_snp(void);
Signature · 1 line
2.25.1
#10 lore raw

Re: [PATCH v4 08/15] Drivers: hv: Introduce per-cpu event ring tail

kernel test robot noticed the following build warnings:

Hi Nuno,

kernel test robot noticed the following build warnings:

[auto build test WARNING on arnd-asm-generic/master]
[also build test WARNING on arm64/for-next/core linus/master v6.6-rc3 next-20230929] [cannot apply to tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nuno-Das-Neves/hyperv-tlfs-Change-shared-HV_REGISTER_-defines-to-HV_MSR_/20230930-041305
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git master
patch link:    https://lore.kernel.org/r/1696010501-24584-9-git-send-email-nunodasneves%40linux.microsoft.com
patch subject: [PATCH v4 08/15] Drivers: hv: Introduce per-cpu event ring tail
config: x86_64-randconfig-123-20230930 (https://download.01.org/0day-ci/archive/20230930/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230930/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> drivers/hv/hv_common.c:98:21: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void [noderef] __percpu *__pdata @@     got unsigned char [noderef] [usertype] __percpu **extern [addressable] [toplevel] hv_synic_eventring_tail @@
   drivers/hv/hv_common.c:98:21: sparse:     expected void [noderef] __percpu *__pdata
   drivers/hv/hv_common.c:98:21: sparse:     got unsigned char [noderef] [usertype] __percpu **extern [addressable] [toplevel] hv_synic_eventring_tail
>> drivers/hv/hv_common.c:349:41: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected unsigned char [noderef] [usertype] __percpu **extern [addressable] [assigned] [toplevel] hv_synic_eventring_tail @@     got unsigned char [usertype] *[noderef] __percpu * @@
   drivers/hv/hv_common.c:349:41: sparse:     expected unsigned char [noderef] [usertype] __percpu **extern [addressable] [assigned] [toplevel] hv_synic_eventring_tail
   drivers/hv/hv_common.c:349:41: sparse:     got unsigned char [usertype] *[noderef] __percpu *
>> drivers/hv/hv_common.c:399:55: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void const [noderef] __percpu *__vpp_verify @@     got unsigned char [noderef] [usertype] __percpu ** @@

drivers/hv/hv_common.c:399:55: sparse: expected void const [noderef] __percpu *__vpp_verify
drivers/hv/hv_common.c:399:55: sparse: got unsigned char [noderef] [usertype] __percpu **

vim +98 drivers/hv/hv_common.c

    74	
    75	/*
    76	 * Hyper-V specific initialization and shutdown code that is
    77	 * common across all architectures.  Called from architecture
    78	 * specific initialization functions.
    79	 */
    80	
    81	void __init hv_common_free(void)
    82	{
    83		unregister_sysctl_table(hv_ctl_table_hdr);
    84		hv_ctl_table_hdr = NULL;
    85	
    86		if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE)
    87			hv_kmsg_dump_unregister();
    88	
    89		kfree(hv_vp_index);
    90		hv_vp_index = NULL;
    91	
    92		free_percpu(hyperv_pcpu_output_arg);
    93		hyperv_pcpu_output_arg = NULL;
    94	
    95		free_percpu(hyperv_pcpu_input_arg);
    96		hyperv_pcpu_input_arg = NULL;
    97	
  > 98		free_percpu(hv_synic_eventring_tail);
    99		hv_synic_eventring_tail = NULL;

100 }
101

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#11 lore raw

PATCH v4 9/15 Drivers: hv: Introduce hv_output_arg_exists in hv_common.c

In reply to Nuno Das Neves

This is a more flexible approach for determining whether to allocate the output page.

---
 drivers/hv/hv_common.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/hv/hv_common.c +17 -4
index 39077841d518..3f6f23e4c579 100644
@@ -58,6 +58,14 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg);
 void * __percpu *hyperv_pcpu_output_arg;
 EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg);
 
+/*
+ * Determine whether output arg is needed
+ */
+static inline bool hv_output_arg_exists(void)
+{
+	return hv_root_partition ? true : false;
+}
+
 static void hv_kmsg_dump_unregister(void);
 
 static struct ctl_table_header *hv_ctl_table_hdr;
@@ -342,10 +350,12 @@ int __init hv_common_init(void)
 	hyperv_pcpu_input_arg = alloc_percpu(void  *);
 	BUG_ON(!hyperv_pcpu_input_arg);
 
-	/* Allocate the per-CPU state for output arg for root */
-	if (hv_root_partition) {
+	if (hv_output_arg_exists()) {
 		hyperv_pcpu_output_arg = alloc_percpu(void *);
 		BUG_ON(!hyperv_pcpu_output_arg);
+	}
+
+	if (hv_root_partition) {
 		hv_synic_eventring_tail = alloc_percpu(u8 *);
 		BUG_ON(hv_synic_eventring_tail == NULL);
 	}
@@ -375,7 +385,7 @@ int hv_common_cpu_init(unsigned int cpu)
 	u8 **synic_eventring_tail;
 	u64 msr_vp_index;
 	gfp_t flags;
-	int pgcount = hv_root_partition ? 2 : 1;
+	int pgcount = hv_output_arg_exists() ? 2 : 1;
 	void *mem;
 	int ret;
 
@@ -393,9 +403,12 @@ int hv_common_cpu_init(unsigned int cpu)
 		if (!mem)
 			return -ENOMEM;
 
-		if (hv_root_partition) {
+		if (hv_output_arg_exists()) {
 			outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg);
 			*outputarg = (char *)mem + HV_HYP_PAGE_SIZE;
+		}
+
+		if (hv_root_partition) {
 			synic_eventring_tail = (u8 **)this_cpu_ptr(hv_synic_eventring_tail);
 			*synic_eventring_tail = kcalloc(HV_SYNIC_SINT_COUNT, sizeof(u8),
 							flags);
Signature · 1 line
2.25.1
#12 lore raw

Re: [PATCH v4 09/15] Drivers: hv: Introduce hv_output_arg_exists in hv_common.c

Hi Nuno,

Is it possible to simply change to always allocating the output page? For example, the output page could be needed in scenarios where Linux is not running as the root partition, since certain hypercalls that a guest can make will still require one (I realize that's not the case _today_, but I don't believe this optimization buys much).

Best regards,
Alex Ionescu

Best regards,
Alex Ionescu

Quoted 71 lines · Nuno Das Neves

This is a more flexible approach for determining whether to allocate the output page.

---
 drivers/hv/hv_common.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/hv/hv_common.c +17 -5
index 39077841d518..3f6f23e4c579 100644
@@ -58,6 +58,14 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg);
 void * __percpu *hyperv_pcpu_output_arg;
 EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg);
 
+/*
+ * Determine whether output arg is needed
+ */
+static inline bool hv_output_arg_exists(void)
+{
+       return hv_root_partition ? true : false;
+}
+
 static void hv_kmsg_dump_unregister(void);
 
 static struct ctl_table_header *hv_ctl_table_hdr;
@@ -342,10 +350,12 @@ int __init hv_common_init(void)
        hyperv_pcpu_input_arg = alloc_percpu(void  *);
        BUG_ON(!hyperv_pcpu_input_arg);
 
-       /* Allocate the per-CPU state for output arg for root */
-       if (hv_root_partition) {
+       if (hv_output_arg_exists()) {
                hyperv_pcpu_output_arg = alloc_percpu(void *);
                BUG_ON(!hyperv_pcpu_output_arg);
+       }
+
+       if (hv_root_partition) {
                hv_synic_eventring_tail = alloc_percpu(u8 *);
                BUG_ON(hv_synic_eventring_tail == NULL);
        }
@@ -375,7 +385,7 @@ int hv_common_cpu_init(unsigned int cpu)
        u8 **synic_eventring_tail;
        u64 msr_vp_index;
        gfp_t flags;
-       int pgcount = hv_root_partition ? 2 : 1;
+       int pgcount = hv_output_arg_exists() ? 2 : 1;
        void *mem;
        int ret;
 
@@ -393,9 +403,12 @@ int hv_common_cpu_init(unsigned int cpu)
                if (!mem)
                        return -ENOMEM;
 
-               if (hv_root_partition) {
+               if (hv_output_arg_exists()) {
                        outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg);
                        *outputarg = (char *)mem + HV_HYP_PAGE_SIZE;
+               }
+
+               if (hv_root_partition) {
                        synic_eventring_tail = (u8 **)this_cpu_ptr(hv_synic_eventring_tail);
                        *synic_eventring_tail = kcalloc(HV_SYNIC_SINT_COUNT, sizeof(u8),
                                                        flags);
--

2.25.1

#13 lore raw

Re: [PATCH v4 09/15] Drivers: hv: Introduce hv_output_arg_exists in hv_common.c

Quoted 7 lines · Alex Ionescu

Hi Nuno,

Is it possible to simply change to always allocating the output page? For example, the output page could be needed in scenarios where Linux is not running as the root partition, since certain hypercalls that a guest can make will still require one (I realize that's not the case _today_, but I don't believe this optimization buys much).

I agree - it would indeed simplify the code, and guests will probably make use of it sooner or later.

Happy to make that change if Hyper-V guest maintainers agree. Long, Dexuan, Michael, what do you think?

Thanks,
Nuno

Quoted 77 lines

Best regards,
Alex Ionescu

Quoted 71 lines · Nuno Das Neves

This is a more flexible approach for determining whether to allocate the output page.

---
  drivers/hv/hv_common.c | 21 +++++++++++++++++----
  1 file changed, 17 insertions(+), 4 deletions(-)
drivers/hv/hv_common.c +17 -5
index 39077841d518..3f6f23e4c579 100644
@@ -58,6 +58,14 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg);
  void * __percpu *hyperv_pcpu_output_arg;
  EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg);
 
+/*
+ * Determine whether output arg is needed
+ */
+static inline bool hv_output_arg_exists(void)
+{
+       return hv_root_partition ? true : false;
+}
+
  static void hv_kmsg_dump_unregister(void);
 
  static struct ctl_table_header *hv_ctl_table_hdr;
@@ -342,10 +350,12 @@ int __init hv_common_init(void)
         hyperv_pcpu_input_arg = alloc_percpu(void  *);
         BUG_ON(!hyperv_pcpu_input_arg);
 
-       /* Allocate the per-CPU state for output arg for root */
-       if (hv_root_partition) {
+       if (hv_output_arg_exists()) {
                 hyperv_pcpu_output_arg = alloc_percpu(void *);
                 BUG_ON(!hyperv_pcpu_output_arg);
+       }
+
+       if (hv_root_partition) {
                 hv_synic_eventring_tail = alloc_percpu(u8 *);
                 BUG_ON(hv_synic_eventring_tail == NULL);
         }
@@ -375,7 +385,7 @@ int hv_common_cpu_init(unsigned int cpu)
         u8 **synic_eventring_tail;
         u64 msr_vp_index;
         gfp_t flags;
-       int pgcount = hv_root_partition ? 2 : 1;
+       int pgcount = hv_output_arg_exists() ? 2 : 1;
         void *mem;
         int ret;
 
@@ -393,9 +403,12 @@ int hv_common_cpu_init(unsigned int cpu)
                 if (!mem)
                         return -ENOMEM;
 
-               if (hv_root_partition) {
+               if (hv_output_arg_exists()) {
                         outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg);
                         *outputarg = (char *)mem + HV_HYP_PAGE_SIZE;
+               }
+
+               if (hv_root_partition) {
                         synic_eventring_tail = (u8 **)this_cpu_ptr(hv_synic_eventring_tail);
                         *synic_eventring_tail = kcalloc(HV_SYNIC_SINT_COUNT, sizeof(u8),
                                                         flags);
--

2.25.1

#14 lore raw

RE: [PATCH v4 09/15] Drivers: hv: Introduce hv_output_arg_exists in hv_common.c

Quoted 12 lines

Subject: Re: [PATCH v4 09/15] Drivers: hv: Introduce hv_output_arg_exists in hv_common.c

Quoted 7 lines · Alex Ionescu

Hi Nuno,

Is it possible to simply change to always allocating the output page? For example, the output page could be needed in scenarios where Linux is not running as the root partition, since certain hypercalls that a guest can make will still require one (I realize that's not the case _today_, but I don't believe this optimization buys much).

Quoted 5 lines

I agree - it would indeed simplify the code, and guests will probably make use of it sooner or later.

Happy to make that change if Hyper-V guest maintainers agree. Long, Dexuan, Michael, what do you think?

There is no use case as of today for guest VMs. And it allocates extra memory that are never used when running as guest VMs.

I suggest keep this code unchanged as is.

Thanks,
Long

#15 lore raw

PATCH v4 10/15 x86: hyperv: Add mshv_handler irq handler and setup function

In reply to Nuno Das Neves

This will handle SYNIC interrupts such as intercepts, doorbells, and scheduling messages intended for the mshv driver.

---
 arch/x86/kernel/cpu/mshyperv.c | 9 +++++++++
 drivers/hv/hv_common.c         | 5 +++++
 include/asm-generic/mshyperv.h | 2 ++
 3 files changed, 16 insertions(+)
arch/x86/kernel/cpu/mshyperv.c +9 -0
index 9b898b65a013..06f79963add5 100644
@@ -110,6 +110,7 @@ void hv_set_register(unsigned int reg, u64 value)
 }
 EXPORT_SYMBOL_GPL(hv_set_register);
 
+static void (*mshv_handler)(void);
 static void (*vmbus_handler)(void);
 static void (*hv_stimer0_handler)(void);
 static void (*hv_kexec_handler)(void);
@@ -120,6 +121,9 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_hyperv_callback)
 	struct pt_regs *old_regs = set_irq_regs(regs);
 
 	inc_irq_stat(irq_hv_callback_count);
+	if (mshv_handler)
+		mshv_handler();
+
 	if (vmbus_handler)
 		vmbus_handler();
 
@@ -129,6 +133,11 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_hyperv_callback)
 	set_irq_regs(old_regs);
 }
 
+void hv_setup_mshv_irq(void (*handler)(void))
+{
+	mshv_handler = handler;
+}
+
 void hv_setup_vmbus_handler(void (*handler)(void))
 {
 	vmbus_handler = handler;
drivers/hv/hv_common.c +5 -0
index 3f6f23e4c579..6ec63502d83d 100644
@@ -585,6 +585,11 @@ void __weak hv_remove_vmbus_handler(void)
 }
 EXPORT_SYMBOL_GPL(hv_remove_vmbus_handler);
 
+void __weak hv_setup_mshv_irq(void (*handler)(void))
+{
+}
+EXPORT_SYMBOL_GPL(hv_setup_mshv_irq);
+
 void __weak hv_setup_kexec_handler(void (*handler)(void))
 {
 }
include/asm-generic/mshyperv.h +2 -0
index 4e49fd662b2b..d832852d0ee7 100644
@@ -198,6 +198,8 @@ void hv_remove_vmbus_handler(void);
 void hv_setup_stimer0_handler(void (*handler)(void));
 void hv_remove_stimer0_handler(void);
 
+void hv_setup_mshv_irq(void (*handler)(void));
+
 void hv_setup_kexec_handler(void (*handler)(void));
 void hv_remove_kexec_handler(void);
 void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs));
Signature · 1 line
2.25.1
#16 lore raw

PATCH v4 11/15 Drivers: hv: export vmbus_isr, hv_context and hv_post_message

In reply to Nuno Das Neves

These will be used by the mshv_vtl driver.

---
 drivers/hv/hv.c           | 2 ++
 drivers/hv/hyperv_vmbus.h | 1 +
 drivers/hv/vmbus_drv.c    | 3 ++-
 3 files changed, 5 insertions(+), 1 deletion(-)
drivers/hv/hv.c +2 -0
index d7869205dcbe..c60a4fb55f3c 100644
@@ -25,6 +25,7 @@
 
 /* The one and only */
 struct hv_context hv_context;
+EXPORT_SYMBOL_GPL(hv_context);
 
 /*
  * hv_init - Main initialization routine.
@@ -93,6 +94,7 @@ int hv_post_message(union hv_connection_id connection_id,
 
 	return hv_result(status);
 }
+EXPORT_SYMBOL_GPL(hv_post_message);
 
 int hv_synic_alloc(void)
 {
drivers/hv/hyperv_vmbus.h +1 -0
index f6b1e710f805..09792eb4ffed 100644
@@ -32,6 +32,7 @@
  */
 #define HV_UTIL_NEGO_TIMEOUT 55
 
+void vmbus_isr(void);
 
 /* Definitions for the monitored notification facility */
 union hv_monitor_trigger_group {
drivers/hv/vmbus_drv.c +2 -1
index edbb38f6956b..6d27597af8bf 100644
@@ -1286,7 +1286,7 @@ static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu)
 	}
 }
 
-static void vmbus_isr(void)
+void vmbus_isr(void)
 {
 	struct hv_per_cpu_context *hv_cpu
 		= this_cpu_ptr(hv_context.cpu_context);
@@ -1309,6 +1309,7 @@ static void vmbus_isr(void)
 
 	add_interrupt_randomness(vmbus_interrupt);
 }
+EXPORT_SYMBOL_GPL(vmbus_isr);
 
 static irqreturn_t vmbus_percpu_isr(int irq, void *dev_id)
 {
Signature · 1 line
2.25.1
#17 lore raw

PATCH v4 12/15 Documentation: Reserve ioctl number for mshv driver

In reply to Nuno Das Neves
---
 Documentation/userspace-api/ioctl/ioctl-number.rst | 2 ++
 1 file changed, 2 insertions(+)
Documentation/userspace-api/ioctl/ioctl-number.rst +2 -0
index 4ea5b837399a..71e6d23070ca 100644
@@ -355,6 +355,8 @@ Code  Seq#    Include File                                           Comments
 0xB6  all    linux/fpga-dfl.h
 0xB7  all    uapi/linux/remoteproc_cdev.h                            <mailto:[email protected]>
 0xB7  all    uapi/linux/nsfs.h                                       <mailto:Andrei Vagin <[email protected]>>
+0xB8  all    uapi/linux/mshv.h                                       Microsoft Hypervisor VM management APIs
+                                                                     <mailto:[email protected]>
 0xC0  00-0F  linux/usb/iowarrior.h
 0xCA  00-0F  uapi/misc/cxl.h
 0xCA  10-2F  uapi/misc/ocxl.h
Signature · 1 line
2.25.1
#18 lore raw

PATCH v4 13/15 uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

In reply to Nuno Das Neves

These must be in uapi because they will be used in the mshv ioctl API.

Version numbers for each file:
hvhdk.h 25212
hvhdk_mini.h 25294
hvgdk.h 25125
hvgdk_mini.h 25294

These are unstable interfaces and as such must be compiled independently from published interfaces found in hyperv-tlfs.h.

---
 include/uapi/hyperv/hvgdk.h      |   41 +
 include/uapi/hyperv/hvgdk_mini.h | 1076 ++++++++++++++++++++++++
 include/uapi/hyperv/hvhdk.h      | 1342 ++++++++++++++++++++++++++++++
 include/uapi/hyperv/hvhdk_mini.h |  160 ++++
 4 files changed, 2619 insertions(+)
 create mode 100644 include/uapi/hyperv/hvgdk.h
 create mode 100644 include/uapi/hyperv/hvgdk_mini.h
 create mode 100644 include/uapi/hyperv/hvhdk.h
 create mode 100644 include/uapi/hyperv/hvhdk_mini.h
include/uapi/hyperv/hvgdk.h new file +41 -0
new file mode 100644
index 000000000000..9bcbb7d902b2
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright (c) 2023, Microsoft Corporation.
+ *
+ * These files (hvhdk.h, hvhdk_mini.h, hvgdk.h, hvgdk_mini.h) define APIs for
+ * communicating with the Microsoft Hypervisor.
+ *
+ * These definitions are subject to change across hypervisor versions, and as
+ * such are separate and independent from hyperv-tlfs.h.
+ *
+ * The naming of these headers reflects conventions used in the Microsoft
+ * Hypervisor.
+ */
+#ifndef _UAPI_HV_HVGDK_H
+#define _UAPI_HV_HVGDK_H
+
+#include "hvgdk_mini.h"
+
+enum hv_unimplemented_msr_action {
+	HV_UNIMPLEMENTED_MSR_ACTION_FAULT = 0,
+	HV_UNIMPLEMENTED_MSR_ACTION_IGNORE_WRITE_READ_ZERO = 1,
+	HV_UNIMPLEMENTED_MSR_ACTION_COUNT = 2,
+};
+
+/* Define connection identifier type. */
+union hv_connection_id {
+	__u32 asu32;
+	struct {
+		__u32 id:24;
+		__u32 reserved:8;
+	} __packed u;
+};
+
+struct hv_input_unmap_gpa_pages {
+	__u64 target_partition_id;
+	__u64 target_gpa_base;
+	__u32 unmap_flags;
+	__u32 padding;
+} __packed;
+
+#endif /* #ifndef _UAPI_HV_HVGDK_H */
include/uapi/hyperv/hvgdk_mini.h new file +1076 -0

1,076 lines not on this page · raw message

include/uapi/hyperv/hvhdk.h new file +1342 -0

1,342 lines not on this page · raw message

include/uapi/hyperv/hvhdk_mini.h new file +160 -0

160 lines not on this page · raw message

Signature · 1 line
2.25.1
#19 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

Quoted 7 lines · Nuno Das Neves

These must be in uapi because they will be used in the mshv ioctl API.

Version numbers for each file:
hvhdk.h 25212
hvhdk_mini.h 25294
hvgdk.h 25125
hvgdk_mini.h 25294

what are version numbers?

Quoted 2 lines

These are unstable interfaces and as such must be compiled independently from published interfaces found in hyperv-tlfs.h.

uapi files can NOT be unstable, that's the opposite of an api :(

Quoted 19 lines
---
 include/uapi/hyperv/hvgdk.h      |   41 +
 include/uapi/hyperv/hvgdk_mini.h | 1076 ++++++++++++++++++++++++
 include/uapi/hyperv/hvhdk.h      | 1342 ++++++++++++++++++++++++++++++
 include/uapi/hyperv/hvhdk_mini.h |  160 ++++
 4 files changed, 2619 insertions(+)
 create mode 100644 include/uapi/hyperv/hvgdk.h
 create mode 100644 include/uapi/hyperv/hvgdk_mini.h
 create mode 100644 include/uapi/hyperv/hvhdk.h
 create mode 100644 include/uapi/hyperv/hvhdk_mini.h
include/uapi/hyperv/hvgdk.h new file +0 -0
new file mode 100644
index 000000000000..9bcbb7d902b2

include/uapi/hyperv/hvgdk.h line 1

Quoted 1 line
include/uapi/hyperv/hvgdk.h new file +1 -0
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: MIT */

That's usually not a good license for a new uapi .h file, why did you choose this one?

include/uapi/hyperv/hvgdk.h line 31

Quoted 7 lines
include/uapi/hyperv/hvgdk.h new file +7 -0
+/* Define connection identifier type. */
+union hv_connection_id {
+	__u32 asu32;
+	struct {
+		__u32 id:24;
+		__u32 reserved:8;
+	} __packed u;

bitfields will not work properly in uapi .h files, please never do that.

thanks,

greg k-h

maintainer
#20 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

Quoted 10 lines · Greg KH
Quoted 7 lines · Nuno Das Neves

These must be in uapi because they will be used in the mshv ioctl API.

Version numbers for each file:
hvhdk.h 25212
hvhdk_mini.h 25294
hvgdk.h 25125
hvgdk_mini.h 25294

what are version numbers?

These are internal version numbers for the hypervisor headers. We keep track of them so that we can detect if there are any breakages in the ABI, and thus either ask them to be fixed or we come up with ways to maintain compatibility. People outside of Microsoft don't need to worry about this. If you don't think this information belongs in the commit message, we can drop it.

Quoted 6 lines
Quoted 3 lines

These are unstable interfaces and as such must be compiled independently from published interfaces found in hyperv-tlfs.h.

uapi files can NOT be unstable, that's the opposite of an api :(

You made a few suggestions in the past. Nuno responded here:

https://lore.kernel.org/linux-hyperv/1692309711-5573-1-git-send-email-nunodasneves@linux.microsoft.com/T/#m3dd8035e381a1344acd7f570c3f5921b7415bedb

Quoted 13 lines
Quoted 13 lines
---
 include/uapi/hyperv/hvgdk.h      |   41 +
 include/uapi/hyperv/hvgdk_mini.h | 1076 ++++++++++++++++++++++++
 include/uapi/hyperv/hvhdk.h      | 1342 ++++++++++++++++++++++++++++++
 include/uapi/hyperv/hvhdk_mini.h |  160 ++++
 4 files changed, 2619 insertions(+)
 create mode 100644 include/uapi/hyperv/hvgdk.h
 create mode 100644 include/uapi/hyperv/hvgdk_mini.h
 create mode 100644 include/uapi/hyperv/hvhdk.h
 create mode 100644 include/uapi/hyperv/hvhdk_mini.h
Quoted 11 lines

include/uapi/hyperv/hvgdk.h line 1

Quoted 7 lines
include/uapi/hyperv/hvgdk.h new file +1 -0
new file mode 100644
index 000000000000..9bcbb7d902b2
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: MIT */

That's usually not a good license for a new uapi .h file, why did you choose this one?

This is chosen so that other Microsoft developers who don't normally work on Linux can review this code.

Quoted 9 lines

include/uapi/hyperv/hvgdk.h line 31

Quoted 7 lines
include/uapi/hyperv/hvgdk.h new file +7 -0
+/* Define connection identifier type. */
+union hv_connection_id {
+	__u32 asu32;
+	struct {
+		__u32 id:24;
+		__u32 reserved:8;
+	} __packed u;

bitfields will not work properly in uapi .h files, please never do that.

Can you clarify a bit more why it wouldn't work? Endianess? Alignment? Or something else?

Just by eyeballing the header files under include/uapi, there are a non-trivial number of files that use bitfields.

include/uapi/linux/cdrom.h
include/uapi/linux/hdreg.h
include/uapi/linux/if_pppox.h
include/uapi/linux/adfs_fs.h
include/uapi/linux/atm.h
include/uapi/linux/batadv_packet.h
include/uapi/linux/bpf.h
include/uapi/linux/cciss_defs.h
include/uapi/linux/dccp.h
include/uapi/linux/erspan.h
include/uapi/linux/i2o-dev.h
include/uapi/linux/icmp.h
include/uapi/linux/icmpv6.h
include/uapi/linux/idxd.h
include/uapi/linux/if_hippi.h
include/uapi/linux/igmp.h
include/uapi/linux/inet_diag.h
include/uapi/linux/ioam6.h
include/uapi/linux/ip.h
include/uapi/linux/netfilter/xt_policy.h
include/uapi/linux/perf_event.h
include/uapi/linux/rpl.h
include/uapi/linux/tcp.h
include/uapi/linux/usb/raw_gadget.h
include/uapi/linux/watch_queue.h
include/uapi/scsi/scsi_bsg_ufs.h
include/uapi/sound/asound.h
include/uapi/sound/skl-tplg-interface.h

Also under arch/x86/include/uapi/asm:

arch/x86/include/uapi/asm/kvm.h

Can you help us understand how we can make our code work like the others listed above? There must be a way since they are all in the tree. We're happy to make adjustments.

Thanks,
Wei.

Quoted 4 lines

thanks,

greg k-h

#21 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

Quoted 10 lines · Wei Liu
Quoted 9 lines · Greg KH
Quoted 7 lines · Nuno Das Neves

These must be in uapi because they will be used in the mshv ioctl API.

Version numbers for each file:
hvhdk.h 25212
hvhdk_mini.h 25294
hvgdk.h 25125
hvgdk_mini.h 25294

Quoted 8 lines
Quoted 1 line

what are version numbers?

These are internal version numbers for the hypervisor headers. We keep track of them so that we can detect if there are any breakages in the ABI, and thus either ask them to be fixed or we come up with ways to maintain compatibility. People outside of Microsoft don't need to worry about this. If you don't think this information belongs in the commit message, we can drop it.

Internal numbers to a single company that have no relevance to anyone else do not belong in a changelog comment. Would you want to see this in any other kernel changelog message for any other portion of the kernel?

Quoted 12 lines
Quoted 11 lines

include/uapi/hyperv/hvgdk.h line 1

Quoted 7 lines
include/uapi/hyperv/hvgdk.h new file +1 -0
new file mode 100644
index 000000000000..9bcbb7d902b2
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: MIT */

That's usually not a good license for a new uapi .h file, why did you choose this one?

Quoted 2 lines

This is chosen so that other Microsoft developers who don't normally work on Linux can review this code.

Sorry, but that's not how kernel development is done. Please fix your internal review processes and use the correct uapi header file license.

If your lawyers insist on this license, that's fine, but please have them provide a signed-off-by on the patch that adds it and have it documented why it is this license in the changelog AND in a comment in the file so we can understand what is going on with it.

Quoted 11 lines
Quoted 9 lines

include/uapi/hyperv/hvgdk.h line 31

Quoted 7 lines
include/uapi/hyperv/hvgdk.h new file +7 -0
+/* Define connection identifier type. */
+union hv_connection_id {
+	__u32 asu32;
+	struct {
+		__u32 id:24;
+		__u32 reserved:8;
+	} __packed u;

bitfields will not work properly in uapi .h files, please never do that.

Can you clarify a bit more why it wouldn't work? Endianess? Alignment?

Yes to both.

Did you all read the documentation for how to write a kernel api? If not, please do so. I think it mentions bitfields, but it not, it really should as of course, this will not work properly with different endian systems or many compilers.

thanks,

greg k-h

maintainer
#22 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

Quoted 20 lines · Greg KH
Quoted 10 lines · Wei Liu
Quoted 9 lines · Greg KH
Quoted 7 lines · Nuno Das Neves

These must be in uapi because they will be used in the mshv ioctl API.

Version numbers for each file:
hvhdk.h 25212
hvhdk_mini.h 25294
hvgdk.h 25125
hvgdk_mini.h 25294

Quoted 8 lines
Quoted 1 line

what are version numbers?

These are internal version numbers for the hypervisor headers. We keep track of them so that we can detect if there are any breakages in the ABI, and thus either ask them to be fixed or we come up with ways to maintain compatibility. People outside of Microsoft don't need to worry about this. If you don't think this information belongs in the commit message, we can drop it.

Quoted 5 lines

Internal numbers to a single company that have no relevance to anyone else do not belong in a changelog comment. Would you want to see this in any other kernel changelog message for any other portion of the kernel?

Okay. They shall be removed. I agree with you.

Quoted 15 lines
Quoted 12 lines
Quoted 11 lines

include/uapi/hyperv/hvgdk.h line 1

Quoted 7 lines
include/uapi/hyperv/hvgdk.h new file +1 -0
new file mode 100644
index 000000000000..9bcbb7d902b2
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: MIT */

That's usually not a good license for a new uapi .h file, why did you choose this one?

Quoted 2 lines

This is chosen so that other Microsoft developers who don't normally work on Linux can review this code.

Quoted 8 lines

Sorry, but that's not how kernel development is done. Please fix your internal review processes and use the correct uapi header file license.

If your lawyers insist on this license, that's fine, but please have them provide a signed-off-by on the patch that adds it and have it documented why it is this license in the changelog AND in a comment in the file so we can understand what is going on with it.

We went through an internal review with our legal counsel regarding the MIT license. We have an approval from them.

Let me ask if using something like "GPL-2.0 WITH Linux-syscall-note OR MIT" is possible.

Thanks,
Wei.

#23 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

Quoted 24 lines · Wei Liu
Quoted 15 lines
Quoted 12 lines
Quoted 11 lines

include/uapi/hyperv/hvgdk.h line 1

Quoted 7 lines
include/uapi/hyperv/hvgdk.h new file +1 -0
new file mode 100644
index 000000000000..9bcbb7d902b2
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: MIT */

That's usually not a good license for a new uapi .h file, why did you choose this one?

Quoted 2 lines

This is chosen so that other Microsoft developers who don't normally work on Linux can review this code.

Quoted 8 lines

Sorry, but that's not how kernel development is done. Please fix your internal review processes and use the correct uapi header file license.

If your lawyers insist on this license, that's fine, but please have them provide a signed-off-by on the patch that adds it and have it documented why it is this license in the changelog AND in a comment in the file so we can understand what is going on with it.

Quoted 5 lines

We went through an internal review with our legal counsel regarding the MIT license. We have an approval from them.

Let me ask if using something like "GPL-2.0 WITH Linux-syscall-note OR MIT" is possible.

That marking makes no sense from a legal point of view, please work with your lawyers as it seems they do not understand license descriptions very well :(

thanks,

greg k-h

maintainer
#24 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

Hi Greg

Quoted 28 lines · Greg KH
Quoted 27 lines · Wei Liu
Quoted 15 lines
Quoted 12 lines
Quoted 11 lines

include/uapi/hyperv/hvgdk.h line 1

Quoted 7 lines
include/uapi/hyperv/hvgdk.h new file +1 -0
new file mode 100644
index 000000000000..9bcbb7d902b2
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: MIT */

That's usually not a good license for a new uapi .h file, why did you choose this one?

Quoted 2 lines

This is chosen so that other Microsoft developers who don't normally work on Linux can review this code.

Quoted 8 lines

Sorry, but that's not how kernel development is done. Please fix your internal review processes and use the correct uapi header file license.

If your lawyers insist on this license, that's fine, but please have them provide a signed-off-by on the patch that adds it and have it documented why it is this license in the changelog AND in a comment in the file so we can understand what is going on with it.

We went through an internal review with our legal counsel regarding the MIT license. We have an approval from them.

Quoted 7 lines
Quoted 2 lines

Let me ask if using something like "GPL-2.0 WITH Linux-syscall-note OR MIT" is possible.

That marking makes no sense from a legal point of view, please work with your lawyers as it seems they do not understand license descriptions very well :(

Do you mean "GPL-2.0 WITH Linux-syscall-note OR MIT" doesn't make sense?

Why is that? I see that in various UAPI headers.

include/uapi/drm/lima_drm.h:1:/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */ include/uapi/linux/io_uring.h:1:/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */ include/uapi/linux/kfd_sysfs.h:1:/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */ include/uapi/linux/rkisp1-config.h:1:/* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR MIT) */ include/uapi/linux/wireguard.h:1:/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */ include/uapi/xen/evtchn.h:1:/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR MIT) */ include/uapi/xen/gntdev.h:1:/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR MIT) */ include/uapi/xen/privcmd.h:1:/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR MIT) */

Thanks,
Wei.

Quoted 3 lines

thanks,

greg k-h

maintainer
#25 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

In reply to Greg KH
Quoted 28 lines · Greg KH
Quoted 27 lines · Wei Liu
Quoted 15 lines
Quoted 12 lines
Quoted 11 lines

include/uapi/hyperv/hvgdk.h line 1

Quoted 7 lines
include/uapi/hyperv/hvgdk.h new file +1 -0
new file mode 100644
index 000000000000..9bcbb7d902b2
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: MIT */

That's usually not a good license for a new uapi .h file, why did you choose this one?

Quoted 2 lines

This is chosen so that other Microsoft developers who don't normally work on Linux can review this code.

Quoted 8 lines

Sorry, but that's not how kernel development is done. Please fix your internal review processes and use the correct uapi header file license.

If your lawyers insist on this license, that's fine, but please have them provide a signed-off-by on the patch that adds it and have it documented why it is this license in the changelog AND in a comment in the file so we can understand what is going on with it.

We went through an internal review with our legal counsel regarding the MIT license. We have an approval from them.

Quoted 6 lines
Quoted 2 lines

Let me ask if using something like "GPL-2.0 WITH Linux-syscall-note OR MIT" is possible.

That marking makes no sense from a legal point of view, please work with your lawyers as it seems they do not understand license descriptions very well :(

I've got the clearance to use "GPL-2.0 WITH Linux-syscall-note". We can close on this issue. Thank you for the review.

Thanks,
Wei.

Quoted 4 lines

thanks,

greg k-h

#26 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

In reply to Greg KH
Quoted 13 lines · Greg KH
Quoted 12 lines · Wei Liu
Quoted 10 lines · Greg KH

include/uapi/hyperv/hvgdk.h line 31

Quoted 7 lines · Nuno Das Neves
include/uapi/hyperv/hvgdk.h new file +7 -0
+/* Define connection identifier type. */
+union hv_connection_id {
+	__u32 asu32;
+	struct {
+		__u32 id:24;
+		__u32 reserved:8;
+	} __packed u;

bitfields will not work properly in uapi .h files, please never do that.

Quoted 8 lines
Quoted 1 line

Can you clarify a bit more why it wouldn't work? Endianess? Alignment?

Yes to both.

Did you all read the documentation for how to write a kernel api? If not, please do so. I think it mentions bitfields, but it not, it really should as of course, this will not work properly with different endian systems or many compilers.

Yes, in https://docs.kernel.org/driver-api/ioctl.html it says that it is "better to avoid" bitfields.

Unfortunately bitfields are used in the definition of the hypervisor ABI. We import these definitions directly from the hypervisor code.

In practice the hypervisor, linux, and VMM compilers all produce the same layout for bitfields on the architectures we support.

Thanks,
Nuno

Quoted 4 lines

thanks,

greg k-h

#27 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

Quoted 23 lines · Nuno Das Neves
Quoted 13 lines · Greg KH
Quoted 12 lines · Wei Liu
Quoted 10 lines · Greg KH

include/uapi/hyperv/hvgdk.h line 31

Quoted 7 lines · Nuno Das Neves
include/uapi/hyperv/hvgdk.h new file +7 -0
+/* Define connection identifier type. */
+union hv_connection_id {
+	__u32 asu32;
+	struct {
+		__u32 id:24;
+		__u32 reserved:8;
+	} __packed u;

bitfields will not work properly in uapi .h files, please never do that.

Quoted 8 lines
Quoted 1 line

Can you clarify a bit more why it wouldn't work? Endianess? Alignment?

Yes to both.

Did you all read the documentation for how to write a kernel api? If not, please do so. I think it mentions bitfields, but it not, it really should as of course, this will not work properly with different endian systems or many compilers.

Quoted 5 lines

Yes, in https://docs.kernel.org/driver-api/ioctl.html it says that it is "better to avoid" bitfields.

Unfortunately bitfields are used in the definition of the hypervisor ABI. We import these definitions directly from the hypervisor code.

So why do you feel you have to use this specific format for your user/kernel api? That is not what is going to the hypervisor.

Quoted 2 lines

In practice the hypervisor, linux, and VMM compilers all produce the same layout for bitfields on the architectures we support.

You are getting lucky, please do this properly, without a bitfield marking in the structure.

thanks,

greg k-h

maintainer
#28 lore raw

RE: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

Quoted 7 lines

From: Greg KH <[email protected]>
Sent: Tuesday, October 3, 2023 11:10 PM
[...]

Quoted 3 lines · Nuno Das Neves
Quoted 2 lines · Greg KH
Quoted 1 line · Wei Liu

On Sat, Sep 30, 2023 at 08:09:19AM +0200, Greg KH wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Nuno Das Neves

include/uapi/hyperv/hvgdk.h line 31

Quoted 7 lines
include/uapi/hyperv/hvgdk.h new file +7 -0
+/* Define connection identifier type. */
+union hv_connection_id {
+   __u32 asu32;
+   struct {
+           __u32 id:24;
+           __u32 reserved:8;
+   } __packed u;

IMO the "__packed" is unnecessary.

Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

bitfields will not work properly in uapi .h files, please never do that.

Can you clarify a bit more why it wouldn't work? Endianess? Alignment?

Quoted 8 lines
Quoted 6 lines

Yes to both.

Did you all read the documentation for how to write a kernel api? If not, please do so. I think it mentions bitfields, but it not, it really should as of course, this will not work properly with different endian systems or many compilers.

Yes, in

https://docs.k/
ernel.org%2Fdriver- api%2Fioctl.html&data=05%7C01%7Cdecui%40microsoft.com%7Ce404769e0f 85493f0aa108dbc4a08a27%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C 0%7C638319966071263290%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C% 7C%7C&sdata=RiLNA5DRviWBQK6XXhxC4m77raSDBb%2F0BB6BDpFPUJY%3D &reserved=0 it says that it is

Quoted 7 lines
Quoted 4 lines

"better to avoid" bitfields.

Unfortunately bitfields are used in the definition of the hypervisor ABI. We import these definitions directly from the hypervisor code.

So why do you feel you have to use this specific format for your user/kernel api? That is not what is going to the hypervisor.

If it's hard to avoid bitfield here, maybe we can refer to the definition of struct iphdr in include/uapi/linux/ip.h

Thanks,
Dexuan

#29 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

Quoted 40 lines · Dexuan Cui
Quoted 7 lines

From: Greg KH <[email protected]>
Sent: Tuesday, October 3, 2023 11:10 PM
[...]

Quoted 3 lines · Nuno Das Neves
Quoted 2 lines · Greg KH
Quoted 1 line · Wei Liu

On Sat, Sep 30, 2023 at 08:09:19AM +0200, Greg KH wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Nuno Das Neves

Review

Quoted 7 lines
(quoted diff) +7 -0
+/* Define connection identifier type. */
+union hv_connection_id {
+   __u32 asu32;
+   struct {
+           __u32 id:24;
+           __u32 reserved:8;
+   } __packed u;

IMO the "__packed" is unnecessary.

Quoted 22 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

bitfields will not work properly in uapi .h files, please never do that.

Can you clarify a bit more why it wouldn't work? Endianess? Alignment?

Quoted 8 lines
Quoted 6 lines

Yes to both.

Did you all read the documentation for how to write a kernel api? If not, please do so. I think it mentions bitfields, but it not, it really should as of course, this will not work properly with different endian systems or many compilers.

Yes, in

https://docs.k/
ernel.org%2Fdriver- api%2Fioctl.html&data=05%7C01%7Cdecui%40microsoft.com%7Ce404769e0f 85493f0aa108dbc4a08a27%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C 0%7C638319966071263290%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C% 7C%7C&sdata=RiLNA5DRviWBQK6XXhxC4m77raSDBb%2F0BB6BDpFPUJY%3D &reserved=0 it says that it is

Quoted 2 lines

"better to avoid" bitfields.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Unfortunately bitfields are used in the definition of the hypervisor ABI. We import these definitions directly from the hypervisor code.

So why do you feel you have to use this specific format for your user/kernel api? That is not what is going to the hypervisor.

If it's hard to avoid bitfield here, maybe we can refer to the definition of struct iphdr in include/uapi/linux/ip.h

It is not hard to avoid using bitfields, just use the proper definitions to make this portable for all compilers. And ick, ip.h is not a good thing to follow :)

thanks,

greg k-h

#30 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

Quoted 39 lines · Greg KH
Quoted 38 lines · Dexuan Cui
Quoted 7 lines

From: Greg KH <[email protected]>
Sent: Tuesday, October 3, 2023 11:10 PM
[...]

Quoted 3 lines · Nuno Das Neves
Quoted 2 lines · Greg KH
Quoted 1 line · Wei Liu

On Sat, Sep 30, 2023 at 08:09:19AM +0200, Greg KH wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Nuno Das Neves

Review

Quoted 7 lines
(quoted diff) +7 -0
+/* Define connection identifier type. */
+union hv_connection_id {
+   __u32 asu32;
+   struct {
+           __u32 id:24;
+           __u32 reserved:8;
+   } __packed u;

IMO the "__packed" is unnecessary.

Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

bitfields will not work properly in uapi .h files, please never do that.

Can you clarify a bit more why it wouldn't work? Endianess? Alignment?

Quoted 8 lines
Quoted 6 lines

Yes to both.

Did you all read the documentation for how to write a kernel api? If not, please do so. I think it mentions bitfields, but it not, it really should as of course, this will not work properly with different endian systems or many compilers.

Yes, in

https://docs.k/
ernel.org%2Fdriver- api%2Fioctl.html&data=05%7C01%7Cdecui%40microsoft.com%7Ce404769e0f 85493f0aa108dbc4a08a27%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C 0%7C638319966071263290%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C% 7C%7C&sdata=RiLNA5DRviWBQK6XXhxC4m77raSDBb%2F0BB6BDpFPUJY%3D &reserved=0 it says that it is

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

"better to avoid" bitfields.

Unfortunately bitfields are used in the definition of the hypervisor ABI. We import these definitions directly from the hypervisor code.

So why do you feel you have to use this specific format for your user/kernel api? That is not what is going to the hypervisor.

These *are* going to the hypervisor - we use these same definitions in our driver for the kernel/hypervisor API. This is so we don't have to maintain two separate definitions for user/kernel and kernel/hypervisor APIs.

Quoted 7 lines
Quoted 2 lines

If it's hard to avoid bitfield here, maybe we can refer to the definition of struct iphdr in include/uapi/linux/ip.h

It is not hard to avoid using bitfields, just use the proper definitions to make this portable for all compilers. And ick, ip.h is not a good thing to follow :)

Greg, there is nothing making us use bitfields. It just makes the work of porting the hypervisor definitions to Linux easier - aided by the fact that in practice, all the compilers in our stack produce the same code for these.

If that stops being true, or we need to support some other scenario, then I can see the value in changing it. Right now it just feels like pointless work.

Just a reminder - we are the only consumers of this code right now; no one else can meaningfully use this interface yet.

That all said, if you really insist on changing it, then please say so. And please point to an example of how it should be done so there is no confusion on the best path forward.

Thanks,
Nuno

Quoted 3 lines

thanks,

greg k-h

#31 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

Quoted 45 lines · Nuno Das Neves
Quoted 44 lines · Greg KH
Quoted 43 lines · Dexuan Cui
Quoted 7 lines

From: Greg KH <[email protected]>
Sent: Tuesday, October 3, 2023 11:10 PM
[...]

Quoted 3 lines · Nuno Das Neves
Quoted 2 lines · Greg KH
Quoted 1 line · Wei Liu

On Sat, Sep 30, 2023 at 08:09:19AM +0200, Greg KH wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Nuno Das Neves

Review

Quoted 7 lines
(quoted diff) +7 -0
+/* Define connection identifier type. */
+union hv_connection_id {
+   __u32 asu32;
+   struct {
+           __u32 id:24;
+           __u32 reserved:8;
+   } __packed u;

IMO the "__packed" is unnecessary.

Quoted 25 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

bitfields will not work properly in uapi .h files, please never do that.

Can you clarify a bit more why it wouldn't work? Endianess? Alignment?

Quoted 8 lines
Quoted 6 lines

Yes to both.

Did you all read the documentation for how to write a kernel api? If not, please do so. I think it mentions bitfields, but it not, it really should as of course, this will not work properly with different endian systems or many compilers.

Yes, in

https://docs.k/
ernel.org%2Fdriver- api%2Fioctl.html&data=05%7C01%7Cdecui%40microsoft.com%7Ce404769e0f 85493f0aa108dbc4a08a27%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C 0%7C638319966071263290%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C% 7C%7C&sdata=RiLNA5DRviWBQK6XXhxC4m77raSDBb%2F0BB6BDpFPUJY%3D &reserved=0 it says that it is

Quoted 4 lines

"better to avoid" bitfields.

Unfortunately bitfields are used in the definition of the hypervisor ABI. We import these definitions directly from the hypervisor code.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

So why do you feel you have to use this specific format for your user/kernel api? That is not what is going to the hypervisor.

These *are* going to the hypervisor - we use these same definitions in our driver for the kernel/hypervisor API. This is so we don't have to maintain two separate definitions for user/kernel and kernel/hypervisor APIs.

So these fields are just pass-through from userspace to the hypervisor and are not touched at all by the kernel? If so, I hope the hypervisor is doing some validation of the data :)

Quoted 11 lines
Quoted 7 lines
Quoted 2 lines

If it's hard to avoid bitfield here, maybe we can refer to the definition of struct iphdr in include/uapi/linux/ip.h

It is not hard to avoid using bitfields, just use the proper definitions to make this portable for all compilers. And ick, ip.h is not a good thing to follow :)

Greg, there is nothing making us use bitfields. It just makes the work of porting the hypervisor definitions to Linux easier - aided by the fact that in practice, all the compilers in our stack produce the same code for these.

"our stack" is not how Linux works, you have to write files that work for all compilers here.

Just use a normal variable and define the bits in them with proper bit shifts or masks and that will be portable everywhere. This isn't rocket science...

thanks,

greg k-h

#32 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

In reply to Nuno Das Neves
kernel test robot noticed the following build errors:

Hi Nuno,

kernel test robot noticed the following build errors:

[auto build test ERROR on arnd-asm-generic/master]
[also build test ERROR on arm64/for-next/core linus/master v6.6-rc3 next-20230929] [cannot apply to tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nuno-Das-Neves/hyperv-tlfs-Change-shared-HV_REGISTER_-defines-to-HV_MSR_/20230930-041305
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git master
patch link:    https://lore.kernel.org/r/1696010501-24584-14-git-send-email-nunodasneves%40linux.microsoft.com
patch subject: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs
config: i386-randconfig-013-20230930 (https://download.01.org/0day-ci/archive/20231001/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231001/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from ./usr/include/hyperv/hvgdk.h:17,
from <command-line>:

>> ./usr/include/hyperv/hvgdk_mini.h:18:9: error: unknown type name '__u64'
      18 |         __u64 low_part;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:19:9: error: unknown type name '__u64'
      19 |         __u64 high_part;
         |         ^~~~~
>> ./usr/include/hyperv/hvgdk_mini.h:170:17: error: unknown type name '__u32'
     170 |                 __u32 build_number;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:172:17: error: unknown type name '__u32'
     172 |                 __u32 minor_version : 16;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:173:17: error: unknown type name '__u32'
     173 |                 __u32 major_version : 16;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:175:17: error: unknown type name '__u32'
     175 |                 __u32 service_pack;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:177:17: error: unknown type name '__u32'
     177 |                 __u32 service_number : 24;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:178:17: error: unknown type name '__u32'
     178 |                 __u32 service_branch : 8;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:181:17: error: unknown type name '__u32'
     181 |                 __u32 eax;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:182:17: error: unknown type name '__u32'
     182 |                 __u32 ebx;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:183:17: error: unknown type name '__u32'
     183 |                 __u32 ecx;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:184:17: error: unknown type name '__u32'
     184 |                 __u32 edx;
         |                 ^~~~~
>> ./usr/include/hyperv/hvgdk_mini.h:266:9: error: unknown type name 'u64'
     266 |         u64 address_space;
         |         ^~~
   ./usr/include/hyperv/hvgdk_mini.h:268:17: error: unknown type name 'u64'
     268 |                 u64 additional_pages:11;
         |                 ^~~
   ./usr/include/hyperv/hvgdk_mini.h:269:17: error: unknown type name 'u64'
     269 |                 u64 largepage:1;
         |                 ^~~
   ./usr/include/hyperv/hvgdk_mini.h:270:17: error: unknown type name 'u64'
     270 |                 u64 basepfn:52;
         |                 ^~~
>> ./usr/include/hyperv/hvgdk_mini.h:270:21: error: width of 'basepfn' exceeds its type
     270 |                 u64 basepfn:52;
         |                     ^~~~~~~
   ./usr/include/hyperv/hvgdk_mini.h:273:17: error: unknown type name 'u64'
     273 |                 u64 reserved:12;
         |                 ^~~
   ./usr/include/hyperv/hvgdk_mini.h:274:17: error: unknown type name 'u64'
     274 |                 u64 page_size:1;
         |                 ^~~
   ./usr/include/hyperv/hvgdk_mini.h:275:17: error: unknown type name 'u64'
     275 |                 u64 reserved1:8;
         |                 ^~~
   ./usr/include/hyperv/hvgdk_mini.h:276:17: error: unknown type name 'u64'
     276 |                 u64 base_large_pfn:43;
         |                 ^~~
>> ./usr/include/hyperv/hvgdk_mini.h:276:21: error: width of 'base_large_pfn' exceeds its type
     276 |                 u64 base_large_pfn:43;
         |                     ^~~~~~~~~~~~~~
   ./usr/include/hyperv/hvgdk_mini.h:308:9: error: unknown type name '__u64'
     308 |         __u64 as_uint64;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:310:17: error: unknown type name '__u64'
     310 |                 __u64 vector : 8;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:311:17: error: unknown type name '__u64'
     311 |                 __u64 reserved1 : 8;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:312:17: error: unknown type name '__u64'
     312 |                 __u64 masked : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:313:17: error: unknown type name '__u64'
     313 |                 __u64 auto_eoi : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:314:17: error: unknown type name '__u64'
     314 |                 __u64 polling : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:315:17: error: unknown type name '__u64'
     315 |                 __u64 as_intercept : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:316:17: error: unknown type name '__u64'
     316 |                 __u64 proxy : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:317:17: error: unknown type name '__u64'
     317 |                 __u64 reserved2 : 43;
         |                 ^~~~~
>> ./usr/include/hyperv/hvgdk_mini.h:317:23: error: width of 'reserved2' exceeds its type
     317 |                 __u64 reserved2 : 43;
         |                       ^~~~~~~~~
   ./usr/include/hyperv/hvgdk_mini.h:322:9: error: unknown type name '__u64'
     322 |         __u64 as_uint64;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:324:17: error: unknown type name '__u32'
     324 |                 __u32 low_uint32;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:325:17: error: unknown type name '__u32'
     325 |                 __u32 high_uint32;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:328:17: error: unknown type name '__u64'
     328 |                 __u64 legacy_x87 : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:329:17: error: unknown type name '__u64'
     329 |                 __u64 legacy_sse : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:330:17: error: unknown type name '__u64'
     330 |                 __u64 avx : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:331:17: error: unknown type name '__u64'
     331 |                 __u64 mpx_bndreg : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:332:17: error: unknown type name '__u64'
     332 |                 __u64 mpx_bndcsr : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:333:17: error: unknown type name '__u64'
     333 |                 __u64 avx_512_op_mask : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:334:17: error: unknown type name '__u64'
     334 |                 __u64 avx_512_zmmhi : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:335:17: error: unknown type name '__u64'
     335 |                 __u64 avx_512_zmm16_31 : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:336:17: error: unknown type name '__u64'
     336 |                 __u64 rsvd8_9 : 2;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:337:17: error: unknown type name '__u64'
     337 |                 __u64 pasid : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:338:17: error: unknown type name '__u64'
     338 |                 __u64 cet_u : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:339:17: error: unknown type name '__u64'
     339 |                 __u64 cet_s : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:340:17: error: unknown type name '__u64'
     340 |                 __u64 rsvd13_16 : 4;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:341:17: error: unknown type name '__u64'
     341 |                 __u64 xtile_cfg : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:342:17: error: unknown type name '__u64'
     342 |                 __u64 xtile_data : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:343:17: error: unknown type name '__u64'
     343 |                 __u64 rsvd19_63 : 45;
         |                 ^~~~~
>> ./usr/include/hyperv/hvgdk_mini.h:343:23: error: width of 'rsvd19_63' exceeds its type
     343 |                 __u64 rsvd19_63 : 45;
         |                       ^~~~~~~~~
   ./usr/include/hyperv/hvgdk_mini.h:352:9: error: unknown type name '__u32'
     352 |         __u32 asu32;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:354:17: error: unknown type name '__u32'
     354 |                 __u32 id : 24;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:355:17: error: unknown type name '__u32'
     355 |                 __u32 reserved : 8;
         |                 ^~~~~
>> ./usr/include/hyperv/hvgdk_mini.h:356:38: error: C++ style comments are not allowed in ISO C90
     356 |         } __attribute__((packed)) u; // TODO remove this u
         |                                      ^
   ./usr/include/hyperv/hvgdk_mini.h:356:38: note: (this will be reported only once per input file)
   ./usr/include/hyperv/hvgdk_mini.h:418:9: error: unknown type name '__u64'
     418 |         __u64 as_uint64;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:420:17: error: unknown type name '__u64'
     420 |                 __u64 simp_enabled : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:421:17: error: unknown type name '__u64'
     421 |                 __u64 preserved : 11;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:422:17: error: unknown type name '__u64'
     422 |                 __u64 base_simp_gpa : 52;
         |                 ^~~~~
>> ./usr/include/hyperv/hvgdk_mini.h:422:23: error: width of 'base_simp_gpa' exceeds its type
     422 |                 __u64 base_simp_gpa : 52;
         |                       ^~~~~~~~~~~~~
>> ./usr/include/hyperv/hvgdk_mini.h:427:9: error: unknown type name '__u8'
     427 |         __u8 asu8;
         |         ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:429:17: error: unknown type name '__u8'
     429 |                 __u8 msg_pending : 1;
         |                 ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:430:17: error: unknown type name '__u8'
     430 |                 __u8 reserved : 7;
         |                 ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:435:9: error: unknown type name '__u32'
     435 |         __u32 message_type;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:436:9: error: unknown type name '__u8'
     436 |         __u8 payload_size;
         |         ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:438:9: error: unknown type name '__u8'
     438 |         __u8 reserved[2];
         |         ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:440:17: error: unknown type name '__u64'
     440 |                 __u64 sender;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:450:9: error: unknown type name '__u32'
     450 |         __u32 sint_index;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:456:17: error: unknown type name '__u64'
     456 |                 __u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:466:9: error: unknown type name '__u64'
     466 |         __u64 base;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:467:9: error: unknown type name '__u32'
     467 |         __u32 limit;
         |         ^~~~~
>> ./usr/include/hyperv/hvgdk_mini.h:468:9: error: unknown type name '__u16'
     468 |         __u16 selector;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:471:25: error: unknown type name '__u16'
     471 |                         __u16 segment_type : 4;
         |                         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:472:25: error: unknown type name '__u16'
     472 |                         __u16 non_system_segment : 1;
         |                         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:473:25: error: unknown type name '__u16'
     473 |                         __u16 descriptor_privilege_level : 2;
         |                         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:474:25: error: unknown type name '__u16'
     474 |                         __u16 present : 1;
         |                         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:475:25: error: unknown type name '__u16'
     475 |                         __u16 reserved : 4;
         |                         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:476:25: error: unknown type name '__u16'
     476 |                         __u16 available : 1;
         |                         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:477:25: error: unknown type name '__u16'
     477 |                         __u16 _long : 1;
         |                         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:478:25: error: unknown type name '__u16'
     478 |                         __u16 _default : 1;
         |                         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:479:25: error: unknown type name '__u16'
     479 |                         __u16 granularity : 1;
         |                         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:481:17: error: unknown type name '__u16'
     481 |                 __u16 attributes;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:486:9: error: unknown type name '__u16'
     486 |         __u16 pad[3];
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:487:9: error: unknown type name '__u16'
     487 |         __u16 limit;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:488:9: error: unknown type name '__u64'
     488 |         __u64 base;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:494:17: error: unknown type name '__u16'
     494 |                 __u16 fp_control;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:495:17: error: unknown type name '__u16'
     495 |                 __u16 fp_status;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:496:17: error: unknown type name '__u8'
     496 |                 __u8 fp_tag;
         |                 ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:497:17: error: unknown type name '__u8'
     497 |                 __u8 reserved;
         |                 ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:498:17: error: unknown type name '__u16'
     498 |                 __u16 last_fp_op;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:501:25: error: unknown type name '__u64'
     501 |                         __u64 last_fp_rip;
         |                         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:504:33: error: unknown type name '__u32'
     504 |                                 __u32 last_fp_eip;
         |                                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:505:33: error: unknown type name '__u16'
     505 |                                 __u16 last_fp_cs;
         |                                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:506:33: error: unknown type name '__u16'
     506 |                                 __u16 padding;
         |                                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:517:25: error: unknown type name '__u64'
     517 |                         __u64 last_fp_rdp;
         |                         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:520:33: error: unknown type name '__u32'
     520 |                                 __u32 last_fp_dp;
         |                                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:521:33: error: unknown type name '__u16'
     521 |                                 __u16 last_fp_ds;
         |                                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:522:33: error: unknown type name '__u16'
     522 |                                 __u16 padding;
         |                                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:525:17: error: unknown type name '__u32'
     525 |                 __u32 xmm_status_control;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:526:17: error: unknown type name '__u32'
     526 |                 __u32 xmm_status_control_mask;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:533:17: error: unknown type name '__u64'
     533 |                 __u64 mantissa;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:534:17: error: unknown type name '__u64'
     534 |                 __u64 biased_exponent : 15;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:535:17: error: unknown type name '__u64'
     535 |                 __u64 sign : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:536:17: error: unknown type name '__u64'
     536 |                 __u64 reserved : 48;
         |                 ^~~~~
>> ./usr/include/hyperv/hvgdk_mini.h:536:23: error: width of 'reserved' exceeds its type
     536 |                 __u64 reserved : 48;
         |                       ^~~~~~~~
   ./usr/include/hyperv/hvgdk_mini.h:541:9: error: unknown type name '__u64'
     541 |         __u64 as_uint64;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:547:17: error: unknown type name '__u64'
     547 |                 __u64 prevents_gdt : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:548:17: error: unknown type name '__u64'
     548 |                 __u64 prevents_idt : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:549:17: error: unknown type name '__u64'
     549 |                 __u64 prevents_ldt : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:550:17: error: unknown type name '__u64'
     550 |                 __u64 prevents_tr : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:553:17: error: unknown type name '__u64'
     553 |                 __u64 reserved : 60;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:553:23: error: width of 'reserved' exceeds its type
     553 |                 __u64 reserved : 60;
         |                       ^~~~~~~~
   ./usr/include/hyperv/hvgdk_mini.h:558:9: error: unknown type name '__u8'
     558 |         __u8 as_uint8;
         |         ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:560:17: error: unknown type name '__u8'
     560 |                 __u8 target_vtl : 4;
         |                 ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:561:17: error: unknown type name '__u8'
     561 |                 __u8 use_target_vtl : 1;
         |                 ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:562:17: error: unknown type name '__u8'
     562 |                 __u8 reserved_z : 3;
         |                 ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:570:9: error: unknown type name '__u64'
     570 |         __u64 as_u64;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:572:17: error: unknown type name '__u64'
     572 |                 __u64 enable_vtl_protection : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:573:17: error: unknown type name '__u64'
     573 |                 __u64 default_vtl_protection_mask : 4;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:574:17: error: unknown type name '__u64'
     574 |                 __u64 zero_memory_on_reset : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:575:17: error: unknown type name '__u64'
     575 |                 __u64 deny_lower_vtl_startup : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:576:17: error: unknown type name '__u64'
     576 |                 __u64 intercept_acceptance : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:577:17: error: unknown type name '__u64'
     577 |                 __u64 intercept_enable_vtl_protection : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:578:17: error: unknown type name '__u64'
     578 |                 __u64 intercept_vp_startup : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:579:17: error: unknown type name '__u64'
     579 |                 __u64 intercept_cpuid_unimplemented : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:580:17: error: unknown type name '__u64'
     580 |                 __u64 intercept_unrecoverable_exception : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:581:17: error: unknown type name '__u64'
     581 |                 __u64 intercept_page : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:582:17: error: unknown type name '__u64'
     582 |                 __u64 mbz : 51;
         |                 ^~~~~
>> ./usr/include/hyperv/hvgdk_mini.h:582:23: error: width of 'mbz' exceeds its type
     582 |                 __u64 mbz : 51;
         |                       ^~~
   ./usr/include/hyperv/hvgdk_mini.h:588:17: error: unknown type name '__u32'
     588 |                 __u32 directhypercall : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:589:17: error: unknown type name '__u32'
     589 |                 __u32 reserved : 31;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:592:17: error: unknown type name '__u32'
     592 |                 __u32 inter_partition_comm : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:593:17: error: unknown type name '__u32'
     593 |                 __u32 reserved : 31;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:599:9: error: unknown type name '__u32'
     599 |         __u32 apic_assist;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:600:9: error: unknown type name '__u32'
     600 |         __u32 reserved1;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:601:9: error: unknown type name '__u32'
     601 |         __u32 vtl_entry_reason;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:602:9: error: unknown type name '__u32'
     602 |         __u32 vtl_reserved;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:603:9: error: unknown type name '__u64'
     603 |         __u64 vtl_ret_x64rax;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:604:9: error: unknown type name '__u64'
     604 |         __u64 vtl_ret_x64rcx;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:606:9: error: unknown type name '__u8'
     606 |         __u8 enlighten_vmentry;
         |         ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:607:9: error: unknown type name '__u8'
     607 |         __u8 reserved2[7];
         |         ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:608:9: error: unknown type name '__u64'
     608 |         __u64 current_nested_vmcs;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:609:9: error: unknown type name '__u8'
     609 |         __u8 synthetic_time_unhalted_timer_expired;
         |         ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:610:9: error: unknown type name '__u8'
     610 |         __u8 reserved3[7];
         |         ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:611:9: error: unknown type name '__u8'
     611 |         __u8 virtualization_fault_information[40];
         |         ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:612:9: error: unknown type name '__u8'
     612 |         __u8 reserved4[8];
         |         ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:613:9: error: unknown type name '__u8'
     613 |         __u8 intercept_message[256];
         |         ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:614:9: error: unknown type name '__u8'
     614 |         __u8 vtl_ret_actions[256];
         |         ^~~~
   ./usr/include/hyperv/hvgdk_mini.h:847:9: error: unknown type name '__u64'
     847 |         __u64 as_uint64;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:849:17: error: unknown type name '__u64'
     849 |                 __u64 suspended : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:850:17: error: unknown type name '__u64'
     850 |                 __u64 reserved : 63;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:850:23: error: width of 'reserved' exceeds its type
     850 |                 __u64 reserved : 63;
         |                       ^~~~~~~~
   ./usr/include/hyperv/hvgdk_mini.h:855:9: error: unknown type name '__u64'
     855 |         __u64 as_uint64;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:857:17: error: unknown type name '__u64'
     857 |                 __u64 suspended : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:858:17: error: unknown type name '__u64'
     858 |                 __u64 reserved : 63;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:858:23: error: width of 'reserved' exceeds its type
     858 |                 __u64 reserved : 63;
         |                       ^~~~~~~~
   ./usr/include/hyperv/hvgdk_mini.h:863:9: error: unknown type name '__u64'
     863 |         __u64 as_uint64;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:865:17: error: unknown type name '__u64'
     865 |                 __u64 suspended : 1;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:866:17: error: unknown type name '__u64'
     866 |                 __u64 reserved : 63;
         |                 ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:866:23: error: width of 'reserved' exceeds its type
     866 |                 __u64 reserved : 63;
         |                       ^~~~~~~~
   ./usr/include/hyperv/hvgdk_mini.h:871:9: error: unknown type name '__u64'
     871 |         __u64 as_uint64;
         |         ^~~~~
   ./usr/include/hyperv/hvgdk_mini.h:873:17: error: unknown type name '__u64'
     873 |                 __u64 interrupt_shadow : 1;

..

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#33 lore raw

Re: [PATCH v4 13/15] uapi: hyperv: Add mshv driver headers defining hypervisor ABIs

In reply to Nuno Das Neves

include/uapi/hyperv/hvgdk.h line 30

Quoted 6 lines · Nuno Das Neves
include/uapi/hyperv/hvgdk.h new file +6 -0
+/* Define connection identifier type. */
+union hv_connection_id {
+	__u32 asu32;
+	struct {
+		__u32 id:24;
+		__u32 reserved:8;

Meta-commment, I don't see anywhere you are properly checking that all of the "reserved" areas of these structures are actually set to 0 when they are sent to you. If you don't do that, then they are not really reserved at all and can never be used in the future, so properly check them please.

thanks,

greg k-h

#34 lore raw

PATCH v4 14/15 asm-generic: hyperv: Use new Hyper-V headers conditionally.

In reply to Nuno Das Neves

Add asm-generic/hyperv-defs.h. It includes hyperv-tlfs.h or hvhdk.h depending on compile-time constant HV_HYPERV_DEFS which will be defined in the mshv driver.

This is needed to keep unstable Hyper-V interfaces independent of hyperv-tlfs.h. This ensures hvhdk.h replaces hyperv-tlfs.h in the mshv driver, even via indirect includes.

---
 arch/arm64/include/asm/mshyperv.h |  2 +-
 arch/x86/include/asm/mshyperv.h   |  3 +--
 drivers/hv/hyperv_vmbus.h         |  1 -
 include/asm-generic/hyperv-defs.h | 26 ++++++++++++++++++++++++++
 include/asm-generic/mshyperv.h    |  2 +-
 include/linux/hyperv.h            |  2 +-
 6 files changed, 30 insertions(+), 6 deletions(-)
 create mode 100644 include/asm-generic/hyperv-defs.h
arch/arm64/include/asm/mshyperv.h +1 -1
index 20070a847304..8ec14caf3d4f 100644
@@ -20,7 +20,7 @@
 
 #include <linux/types.h>
 #include <linux/arm-smccc.h>
-#include <asm/hyperv-tlfs.h>
+#include <asm-generic/hyperv-defs.h>
 
 /*
  * Declare calls to get and set Hyper-V VP register values on ARM64, which
arch/x86/include/asm/mshyperv.h +1 -2
index e3768d787065..bb1b97106cd3 100644
@@ -6,10 +6,9 @@
 #include <linux/nmi.h>
 #include <linux/msi.h>
 #include <linux/io.h>
-#include <asm/hyperv-tlfs.h>
 #include <asm/nospec-branch.h>
 #include <asm/paravirt.h>
-#include <asm/mshyperv.h>
+#include <asm-generic/hyperv-defs.h>
 
 /*
  * Hyper-V always provides a single IO-APIC at this MMIO address.
drivers/hv/hyperv_vmbus.h +0 -1
index 09792eb4ffed..0e4bc18a13fa 100644
@@ -15,7 +15,6 @@
 #include <linux/list.h>
 #include <linux/bitops.h>
 #include <asm/sync_bitops.h>
-#include <asm/hyperv-tlfs.h>
 #include <linux/atomic.h>
 #include <linux/hyperv.h>
 #include <linux/interrupt.h>
include/asm-generic/hyperv-defs.h new file +26 -0
new file mode 100644
index 000000000000..ac6fcba35c8c
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_GENERIC_HYPERV_DEFS_H
+#define _ASM_GENERIC_HYPERV_DEFS_H
+
+/*
+ * There are cases where Microsoft Hypervisor ABIs are needed which may not be
+ * stable or present in the Hyper-V TLFS document. E.g. the mshv_root driver.
+ *
+ * As these interfaces are unstable and may differ from hyperv-tlfs.h, they
+ * must be kept separate and independent.
+ *
+ * However, code from files that depend on hyperv-tlfs.h (such as mshyperv.h)
+ * is still needed, so work around the issue by conditionally including the
+ * correct definitions.
+ *
+ * Note: Since they are independent of each other, there are many definitions
+ * duplicated in both hyperv-tlfs.h and uapi/hyperv/hv*.h files.
+ */
+#ifdef HV_HYPERV_DEFS
+#include <uapi/hyperv/hvhdk.h>
+#else
+#include <asm/hyperv-tlfs.h>
+#endif
+
+#endif /* _ASM_GENERIC_HYPERV_DEFS_H */
+
include/asm-generic/mshyperv.h +1 -1
index d832852d0ee7..6bef0d59d1b7 100644
@@ -25,7 +25,7 @@
 #include <linux/cpumask.h>
 #include <linux/nmi.h>
 #include <asm/ptrace.h>
-#include <asm/hyperv-tlfs.h>
+#include <asm-generic/hyperv-defs.h>
 
 #define VTPM_BASE_ADDRESS 0xfed40000
 
include/linux/hyperv.h +1 -1
index 4d5a5e39d76c..722a8cf23d87 100644
@@ -24,7 +24,7 @@
 #include <linux/mod_devicetable.h>
 #include <linux/interrupt.h>
 #include <linux/reciprocal_div.h>
-#include <asm/hyperv-tlfs.h>
+#include <asm-generic/hyperv-defs.h>
 
 #define MAX_PAGE_BUFFER_COUNT				32
 #define MAX_MULTIPAGE_BUFFER_COUNT			32 /* 128K */
Signature · 1 line
2.25.1
#35 lore raw

Re: [PATCH v4 14/15] asm-generic: hyperv: Use new Hyper-V headers conditionally.

Hi Nuno,

I understand the requirement to have undocumented/non-standard/non-TLFS-published information in the HDK headers, however, the current state of this patch is that for any other code that's not in the kernel today, or in this upcoming driver, the hyperv-tlfs definitions are incomplete, because some *documented* TLFS fields are only in HDK headers. Similarly, it is also impossible to only use the HDK headers for other use cases, because some basic documented, standard defines only exist in hyperv-tlfs. So there is no "logical" relationship between the two -- HDK headers are not _just_ undocumented information, but also documented information, but also not complete documented information.

Would you consider:

1) Updating hyperv-tlfs with all newly documented TLFS fields that are in the HDK headers?
OR
2) Updating the new HDK headers you're adding here to also include previously-documented information from hyperv-tlfs? This way, someone can include the HDK headers and get everything they need
OR
3) Truly making hypertv-tlfs the "documented" header, and then removing any duplication from HDK so that it remains the "undocumented" header file. In this manner, one would include hyperv-tlfs to use the stable ABI, and they would include HDK (which would include hyperv-tlfs) to use the unstable+stable ABI.

Thank you for your consideration.

Best regards,
Alex Ionescu

Quoted 124 lines · Nuno Das Neves

Add asm-generic/hyperv-defs.h. It includes hyperv-tlfs.h or hvhdk.h depending on compile-time constant HV_HYPERV_DEFS which will be defined in the mshv driver.

This is needed to keep unstable Hyper-V interfaces independent of hyperv-tlfs.h. This ensures hvhdk.h replaces hyperv-tlfs.h in the mshv driver, even via indirect includes.

---
 arch/arm64/include/asm/mshyperv.h |  2 +-
 arch/x86/include/asm/mshyperv.h   |  3 +--
 drivers/hv/hyperv_vmbus.h         |  1 -
 include/asm-generic/hyperv-defs.h | 26 ++++++++++++++++++++++++++
 include/asm-generic/mshyperv.h    |  2 +-
 include/linux/hyperv.h            |  2 +-
 6 files changed, 30 insertions(+), 6 deletions(-)
 create mode 100644 include/asm-generic/hyperv-defs.h
arch/arm64/include/asm/mshyperv.h +1 -1
index 20070a847304..8ec14caf3d4f 100644
@@ -20,7 +20,7 @@
 
 #include <linux/types.h>
 #include <linux/arm-smccc.h>
-#include <asm/hyperv-tlfs.h>
+#include <asm-generic/hyperv-defs.h>
 
 /*
  * Declare calls to get and set Hyper-V VP register values on ARM64, which
arch/x86/include/asm/mshyperv.h +1 -2
index e3768d787065..bb1b97106cd3 100644
@@ -6,10 +6,9 @@
 #include <linux/nmi.h>
 #include <linux/msi.h>
 #include <linux/io.h>
-#include <asm/hyperv-tlfs.h>
 #include <asm/nospec-branch.h>
 #include <asm/paravirt.h>
-#include <asm/mshyperv.h>
+#include <asm-generic/hyperv-defs.h>
 
 /*
  * Hyper-V always provides a single IO-APIC at this MMIO address.
drivers/hv/hyperv_vmbus.h +0 -1
index 09792eb4ffed..0e4bc18a13fa 100644
@@ -15,7 +15,6 @@
 #include <linux/list.h>
 #include <linux/bitops.h>
 #include <asm/sync_bitops.h>
-#include <asm/hyperv-tlfs.h>
 #include <linux/atomic.h>
 #include <linux/hyperv.h>
 #include <linux/interrupt.h>
include/asm-generic/hyperv-defs.h new file +26 -0
new file mode 100644
index 000000000000..ac6fcba35c8c
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_GENERIC_HYPERV_DEFS_H
+#define _ASM_GENERIC_HYPERV_DEFS_H
+
+/*
+ * There are cases where Microsoft Hypervisor ABIs are needed which may not be
+ * stable or present in the Hyper-V TLFS document. E.g. the mshv_root driver.
+ *
+ * As these interfaces are unstable and may differ from hyperv-tlfs.h, they
+ * must be kept separate and independent.
+ *
+ * However, code from files that depend on hyperv-tlfs.h (such as mshyperv.h)
+ * is still needed, so work around the issue by conditionally including the
+ * correct definitions.
+ *
+ * Note: Since they are independent of each other, there are many definitions
+ * duplicated in both hyperv-tlfs.h and uapi/hyperv/hv*.h files.
+ */
+#ifdef HV_HYPERV_DEFS
+#include <uapi/hyperv/hvhdk.h>
+#else
+#include <asm/hyperv-tlfs.h>
+#endif
+
+#endif /* _ASM_GENERIC_HYPERV_DEFS_H */
+
include/asm-generic/mshyperv.h +1 -1
index d832852d0ee7..6bef0d59d1b7 100644
@@ -25,7 +25,7 @@
 #include <linux/cpumask.h>
 #include <linux/nmi.h>
 #include <asm/ptrace.h>
-#include <asm/hyperv-tlfs.h>
+#include <asm-generic/hyperv-defs.h>
 
 #define VTPM_BASE_ADDRESS 0xfed40000
 
include/linux/hyperv.h +1 -2
index 4d5a5e39d76c..722a8cf23d87 100644
@@ -24,7 +24,7 @@
 #include <linux/mod_devicetable.h>
 #include <linux/interrupt.h>
 #include <linux/reciprocal_div.h>
-#include <asm/hyperv-tlfs.h>
+#include <asm-generic/hyperv-defs.h>
 
 #define MAX_PAGE_BUFFER_COUNT                          32
 #define MAX_MULTIPAGE_BUFFER_COUNT                     32 /* 128K */
--

2.25.1

#36 lore raw

Re: [PATCH v4 14/15] asm-generic: hyperv: Use new Hyper-V headers conditionally.

Hi Alex,

Quoted 8 lines · Alex Ionescu

Hi Nuno,

I understand the requirement to have undocumented/non-standard/non-TLFS-published information in the HDK headers, however, the current state of this patch is that for any other code that's not in the kernel today, or in this upcoming driver, the hyperv-tlfs definitions are incomplete, because some *documented* TLFS fields are only in HDK headers. Similarly, it is also impossible

If I understand correctly, you are saying there are documented definitions (in the TLFS document), which are NOT in hyperv-tlfs.h, but ARE in these new HDK headers, correct?

If these are needed elsewhere in the kernel, they can just be added to hyperv-tlfs.h.

Quoted 5 lines

to only use the HDK headers for other use cases, because some basic documented, standard defines only exist in hyperv-tlfs. So there is no "logical" relationship between the two -- HDK headers are not _just_ undocumented information, but also documented information, but also not complete documented information.

That is correct - they are meant to be independently compileable. The new HDK headers only serve as a replacement *in our driver* when we need some definitions like do_hypercall() etc in mshyperv.h.

Quoted 5 lines

Would you consider:

1) Updating hyperv-tlfs with all newly documented TLFS fields that are in the HDK headers?

I think this can be done on an as-needed basis, as I outlined above.

Quoted 4 lines

OR
2) Updating the new HDK headers you're adding here to also include previously-documented information from hyperv-tlfs? This way, someone can include the HDK headers and get everything they need

The new HDK headers are only intended for the new mshv driver.

Quoted 5 lines

OR
3) Truly making hypertv-tlfs the "documented" header, and then > removing any duplication from HDK so that it remains the "undocumented" header file. In this manner, one would include
hyperv-tlfs to use the stable ABI, and they would include HDK (which
would include hyperv-tlfs) to use the unstable+stable ABI.

hyperv-tlfs.h is remaining the "documented" header.

But, we can't make the HDK header depend on hyperv-tlfs.h, for 2 primary
reasons:
1. We need to put the new HDK headers in uapi so that we can use them in our IOCTL interface. As a result, we can't include hyperv-tlfs.h (unless we put it in uapi as well).
2. The HDK headers not only duplicate, but also MODIFY some structures in hyperv-tlfs.h. e.g., The struct is in hyperv-tlfs.h, but a particular field or bitfield is not.

Thanks,
Nuno

Quoted 132 lines

Thank you for your consideration.

Best regards,
Alex Ionescu

Quoted 124 lines · Nuno Das Neves

Add asm-generic/hyperv-defs.h. It includes hyperv-tlfs.h or hvhdk.h depending on compile-time constant HV_HYPERV_DEFS which will be defined in the mshv driver.

This is needed to keep unstable Hyper-V interfaces independent of hyperv-tlfs.h. This ensures hvhdk.h replaces hyperv-tlfs.h in the mshv driver, even via indirect includes.

---
  arch/arm64/include/asm/mshyperv.h |  2 +-
  arch/x86/include/asm/mshyperv.h   |  3 +--
  drivers/hv/hyperv_vmbus.h         |  1 -
  include/asm-generic/hyperv-defs.h | 26 ++++++++++++++++++++++++++
  include/asm-generic/mshyperv.h    |  2 +-
  include/linux/hyperv.h            |  2 +-
  6 files changed, 30 insertions(+), 6 deletions(-)

create mode 100644 include/asm-generic/hyperv-defs.h

arch/arm64/include/asm/mshyperv.h +1 -1
index 20070a847304..8ec14caf3d4f 100644
@@ -20,7 +20,7 @@
 
  #include <linux/types.h>
  #include <linux/arm-smccc.h>
-#include <asm/hyperv-tlfs.h>
+#include <asm-generic/hyperv-defs.h>
 
  /*
   * Declare calls to get and set Hyper-V VP register values on ARM64, which
arch/x86/include/asm/mshyperv.h +1 -2
index e3768d787065..bb1b97106cd3 100644
@@ -6,10 +6,9 @@
  #include <linux/nmi.h>
  #include <linux/msi.h>
  #include <linux/io.h>
-#include <asm/hyperv-tlfs.h>
  #include <asm/nospec-branch.h>
  #include <asm/paravirt.h>
-#include <asm/mshyperv.h>
+#include <asm-generic/hyperv-defs.h>
 
  /*
   * Hyper-V always provides a single IO-APIC at this MMIO address.
drivers/hv/hyperv_vmbus.h +0 -1
index 09792eb4ffed..0e4bc18a13fa 100644
@@ -15,7 +15,6 @@
  #include <linux/list.h>
  #include <linux/bitops.h>
  #include <asm/sync_bitops.h>
-#include <asm/hyperv-tlfs.h>
  #include <linux/atomic.h>
  #include <linux/hyperv.h>
  #include <linux/interrupt.h>
include/asm-generic/hyperv-defs.h new file +26 -0
new file mode 100644
index 000000000000..ac6fcba35c8c
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_GENERIC_HYPERV_DEFS_H
+#define _ASM_GENERIC_HYPERV_DEFS_H
+
+/*
+ * There are cases where Microsoft Hypervisor ABIs are needed which may not be
+ * stable or present in the Hyper-V TLFS document. E.g. the mshv_root driver.
+ *
+ * As these interfaces are unstable and may differ from hyperv-tlfs.h, they
+ * must be kept separate and independent.
+ *
+ * However, code from files that depend on hyperv-tlfs.h (such as mshyperv.h)
+ * is still needed, so work around the issue by conditionally including the
+ * correct definitions.
+ *
+ * Note: Since they are independent of each other, there are many definitions
+ * duplicated in both hyperv-tlfs.h and uapi/hyperv/hv*.h files.
+ */
+#ifdef HV_HYPERV_DEFS
+#include <uapi/hyperv/hvhdk.h>
+#else
+#include <asm/hyperv-tlfs.h>
+#endif
+
+#endif /* _ASM_GENERIC_HYPERV_DEFS_H */
+
include/asm-generic/mshyperv.h +1 -1
index d832852d0ee7..6bef0d59d1b7 100644
@@ -25,7 +25,7 @@
  #include <linux/cpumask.h>
  #include <linux/nmi.h>
  #include <asm/ptrace.h>
-#include <asm/hyperv-tlfs.h>
+#include <asm-generic/hyperv-defs.h>
 
  #define VTPM_BASE_ADDRESS 0xfed40000
 
include/linux/hyperv.h +1 -2
index 4d5a5e39d76c..722a8cf23d87 100644
@@ -24,7 +24,7 @@
  #include <linux/mod_devicetable.h>
  #include <linux/interrupt.h>
  #include <linux/reciprocal_div.h>
-#include <asm/hyperv-tlfs.h>
+#include <asm-generic/hyperv-defs.h>
 
  #define MAX_PAGE_BUFFER_COUNT                          32
  #define MAX_MULTIPAGE_BUFFER_COUNT                     32 /* 128K */
--

2.25.1

#37 lore raw

Re: [PATCH v4 14/15] asm-generic: hyperv: Use new Hyper-V headers conditionally.

Hi Nuno,

Best regards,
Alex Ionescu

Quoted 13 lines · Nuno Das Neves

Hi Alex,

Quoted 8 lines · Alex Ionescu

Hi Nuno,

I understand the requirement to have undocumented/non-standard/non-TLFS-published information in the HDK headers, however, the current state of this patch is that for any other code that's not in the kernel today, or in this upcoming driver, the hyperv-tlfs definitions are incomplete, because some *documented* TLFS fields are only in HDK headers. Similarly, it is also impossible

Quoted 3 lines

If I understand correctly, you are saying there are documented definitions (in the TLFS document), which are NOT in hyperv-tlfs.h, but ARE in these new HDK headers, correct?

Correct.

Quoted 3 lines

If these are needed elsewhere in the kernel, they can just be added to hyperv-tlfs.h.

OK, great, As the need arises I will submit patches here to do so (and source the TLFS page/paragraph as needed to help provide they're in there). Thank you!

Quoted 10 lines
Quoted 6 lines

to only use the HDK headers for other use cases, because some basic documented, standard defines only exist in hyperv-tlfs. So there is no "logical" relationship between the two -- HDK headers are not _just_ undocumented information, but also documented information, but also not complete documented information.

That is correct - they are meant to be independently compileable. The new HDK headers only serve as a replacement *in our driver* when we need some definitions like do_hypercall() etc in mshyperv.h.

Understood.

Quoted 8 lines
Quoted 6 lines

Would you consider:

1) Updating hyperv-tlfs with all newly documented TLFS fields that are in the HDK headers?

I think this can be done on an as-needed basis, as I outlined above.

Sounds good.

Quoted 16 lines
Quoted 5 lines

OR
2) Updating the new HDK headers you're adding here to also include previously-documented information from hyperv-tlfs? This way, someone can include the HDK headers and get everything they need

The new HDK headers are only intended for the new mshv driver.

Quoted 5 lines

OR
3) Truly making hypertv-tlfs the "documented" header, and then > removing any duplication from HDK so that it remains the "undocumented" header file. In this manner, one would include
hyperv-tlfs to use the stable ABI, and they would include HDK (which
would include hyperv-tlfs) to use the unstable+stable ABI.

hyperv-tlfs.h is remaining the "documented" header.

Quoted 8 lines

But, we can't make the HDK header depend on hyperv-tlfs.h, for 2 primary reasons:
1. We need to put the new HDK headers in uapi so that we can use them in our IOCTL interface. As a result, we can't include hyperv-tlfs.h (unless we put it in uapi as well).
2. The HDK headers not only duplicate, but also MODIFY some structures in hyperv-tlfs.h. e.g., The struct is in hyperv-tlfs.h, but a particular field or bitfield is not.

#2 was something I was worried about. Do you know if the standards/docs team is planning on updating the TLFS at some point with updates on their end? At which point I'd assume you'd be OK with patches to add them to hyperv-tlfs.h

Thanks a lot!

--
Best regards,
Alex Ionescu

Quoted 137 lines

Thanks,
Nuno

Quoted 132 lines

Thank you for your consideration.

Best regards,
Alex Ionescu

Quoted 124 lines · Nuno Das Neves

Add asm-generic/hyperv-defs.h. It includes hyperv-tlfs.h or hvhdk.h depending on compile-time constant HV_HYPERV_DEFS which will be defined in the mshv driver.

This is needed to keep unstable Hyper-V interfaces independent of hyperv-tlfs.h. This ensures hvhdk.h replaces hyperv-tlfs.h in the mshv driver, even via indirect includes.

---
  arch/arm64/include/asm/mshyperv.h |  2 +-
  arch/x86/include/asm/mshyperv.h   |  3 +--
  drivers/hv/hyperv_vmbus.h         |  1 -
  include/asm-generic/hyperv-defs.h | 26 ++++++++++++++++++++++++++
  include/asm-generic/mshyperv.h    |  2 +-
  include/linux/hyperv.h            |  2 +-
  6 files changed, 30 insertions(+), 6 deletions(-)

create mode 100644 include/asm-generic/hyperv-defs.h

arch/arm64/include/asm/mshyperv.h +1 -1
index 20070a847304..8ec14caf3d4f 100644
@@ -20,7 +20,7 @@
 
  #include <linux/types.h>
  #include <linux/arm-smccc.h>
-#include <asm/hyperv-tlfs.h>
+#include <asm-generic/hyperv-defs.h>
 
  /*
   * Declare calls to get and set Hyper-V VP register values on ARM64, which
arch/x86/include/asm/mshyperv.h +1 -2
index e3768d787065..bb1b97106cd3 100644
@@ -6,10 +6,9 @@
  #include <linux/nmi.h>
  #include <linux/msi.h>
  #include <linux/io.h>
-#include <asm/hyperv-tlfs.h>
  #include <asm/nospec-branch.h>
  #include <asm/paravirt.h>
-#include <asm/mshyperv.h>
+#include <asm-generic/hyperv-defs.h>
 
  /*
   * Hyper-V always provides a single IO-APIC at this MMIO address.
drivers/hv/hyperv_vmbus.h +0 -1
index 09792eb4ffed..0e4bc18a13fa 100644
@@ -15,7 +15,6 @@
  #include <linux/list.h>
  #include <linux/bitops.h>
  #include <asm/sync_bitops.h>
-#include <asm/hyperv-tlfs.h>
  #include <linux/atomic.h>
  #include <linux/hyperv.h>
  #include <linux/interrupt.h>
include/asm-generic/hyperv-defs.h new file +26 -0
new file mode 100644
index 000000000000..ac6fcba35c8c
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_GENERIC_HYPERV_DEFS_H
+#define _ASM_GENERIC_HYPERV_DEFS_H
+
+/*
+ * There are cases where Microsoft Hypervisor ABIs are needed which may not be
+ * stable or present in the Hyper-V TLFS document. E.g. the mshv_root driver.
+ *
+ * As these interfaces are unstable and may differ from hyperv-tlfs.h, they
+ * must be kept separate and independent.
+ *
+ * However, code from files that depend on hyperv-tlfs.h (such as mshyperv.h)
+ * is still needed, so work around the issue by conditionally including the
+ * correct definitions.
+ *
+ * Note: Since they are independent of each other, there are many definitions
+ * duplicated in both hyperv-tlfs.h and uapi/hyperv/hv*.h files.
+ */
+#ifdef HV_HYPERV_DEFS
+#include <uapi/hyperv/hvhdk.h>
+#else
+#include <asm/hyperv-tlfs.h>
+#endif
+
+#endif /* _ASM_GENERIC_HYPERV_DEFS_H */
+
include/asm-generic/mshyperv.h +1 -1
index d832852d0ee7..6bef0d59d1b7 100644
@@ -25,7 +25,7 @@
  #include <linux/cpumask.h>
  #include <linux/nmi.h>
  #include <asm/ptrace.h>
-#include <asm/hyperv-tlfs.h>
+#include <asm-generic/hyperv-defs.h>
 
  #define VTPM_BASE_ADDRESS 0xfed40000
 
include/linux/hyperv.h +1 -2
index 4d5a5e39d76c..722a8cf23d87 100644
@@ -24,7 +24,7 @@
  #include <linux/mod_devicetable.h>
  #include <linux/interrupt.h>
  #include <linux/reciprocal_div.h>
-#include <asm/hyperv-tlfs.h>
+#include <asm-generic/hyperv-defs.h>
 
  #define MAX_PAGE_BUFFER_COUNT                          32
  #define MAX_MULTIPAGE_BUFFER_COUNT                     32 /* 128K */
--

2.25.1

#38 lore raw

Re: [PATCH v4 14/15] asm-generic: hyperv: Use new Hyper-V headers conditionally.

Quoted 16 lines · Alex Ionescu
Quoted 7 lines
Quoted 4 lines

3) Truly making hypertv-tlfs the "documented" header, and then > removing any duplication from HDK so that it remains the "undocumented" header file. In this manner, one would include
hyperv-tlfs to use the stable ABI, and they would include HDK (which
would include hyperv-tlfs) to use the unstable+stable ABI.

hyperv-tlfs.h is remaining the "documented" header.

Quoted 8 lines

But, we can't make the HDK header depend on hyperv-tlfs.h, for 2 primary reasons:
1. We need to put the new HDK headers in uapi so that we can use them in our IOCTL interface. As a result, we can't include hyperv-tlfs.h (unless we put it in uapi as well).
2. The HDK headers not only duplicate, but also MODIFY some structures in hyperv-tlfs.h. e.g., The struct is in hyperv-tlfs.h, but a particular field or bitfield is not.

Quoted 5 lines

#2 was something I was worried about. Do you know if the standards/docs team is planning on updating the TLFS at some point with updates on their end? At which point I'd assume you'd be OK with patches to add them to hyperv-tlfs.h

I don't know the current plans for updating the TLFS. But yes, assuming a new TLFS doc has something that is needed in the kernel, hyperv-tlfs.h would be updated to support that.

Thanks,
Nuno

#39 lore raw

PATCH v4 15/15 Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V

In reply to Nuno Das Neves

Add mshv, mshv_root, and mshv_vtl modules:

Module mshv is the parent module to the other two. It provides /dev/mshv, plus some common hypercall helper code. When one of the child modules is loaded, it is registered with the mshv module, which then provides entry point(s) to the child module via the IOCTLs defined in uapi/linux/mshv.h.

E.g. When the mshv_root module is loaded, it registers itself, and the MSHV_CREATE_PARTITION IOCTL becomes available in /dev/mshv. That is used to get a partition fd managed by mshv_root.

Similarly for mshv_vtl module, there is MSHV_CREATE_VTL, which creates an fd representing the lower vtl, managed by mshv_vtl.

Module mshv_root provides APIs for creating and managing child partitions. It defines abstractions for partitions (vms), vps (vcpus), and other things related to running a guest. It exposes the userspace interfaces for a VMM to manage the guest.

Module mshv_vtl provides VTL (Virtual Trust Level) support for VMMs. In this scenario, the host kernel and VMM run in a higher trust level than the guest, but within the same partition. This provides better isolation and performance.

---
 drivers/hv/Kconfig             |   49 +
 drivers/hv/Makefile            |   20 +
 drivers/hv/hv_call.c           |  103 ++
 drivers/hv/hv_common.c         |    4 +
 drivers/hv/mshv.h              |  125 +++
 drivers/hv/mshv_eventfd.c      |  761 +++++++++++++
 drivers/hv/mshv_eventfd.h      |   80 ++
 drivers/hv/mshv_main.c         |  196 ++++
 drivers/hv/mshv_msi.c          |  129 +++
 drivers/hv/mshv_portid_table.c |   84 ++
 drivers/hv/mshv_root.h         |  232 ++++
 drivers/hv/mshv_root_hv_call.c |  911 +++++++++++++++
 drivers/hv/mshv_root_main.c    | 1911 ++++++++++++++++++++++++++++++++
 drivers/hv/mshv_synic.c        |  688 ++++++++++++
 drivers/hv/mshv_vtl.h          |   52 +
 drivers/hv/mshv_vtl_main.c     | 1522 +++++++++++++++++++++++++
 drivers/hv/xfer_to_guest.c     |   28 +
 include/uapi/linux/mshv.h      |  306 +++++
 18 files changed, 7201 insertions(+)
 create mode 100644 drivers/hv/hv_call.c
 create mode 100644 drivers/hv/mshv.h
 create mode 100644 drivers/hv/mshv_eventfd.c
 create mode 100644 drivers/hv/mshv_eventfd.h
 create mode 100644 drivers/hv/mshv_main.c
 create mode 100644 drivers/hv/mshv_msi.c
 create mode 100644 drivers/hv/mshv_portid_table.c
 create mode 100644 drivers/hv/mshv_root.h
 create mode 100644 drivers/hv/mshv_root_hv_call.c
 create mode 100644 drivers/hv/mshv_root_main.c
 create mode 100644 drivers/hv/mshv_synic.c
 create mode 100644 drivers/hv/mshv_vtl.h
 create mode 100644 drivers/hv/mshv_vtl_main.c
 create mode 100644 drivers/hv/xfer_to_guest.c
 create mode 100644 include/uapi/linux/mshv.h
drivers/hv/Kconfig +49 -0
index 00242107d62e..f9d9b8883ba4 100644
@@ -54,4 +54,53 @@ config HYPERV_BALLOON
 	help
 	  Select this option to enable Hyper-V Balloon driver.
 
+config MSHV
+	tristate "Microsoft Hypervisor root partition interfaces: /dev/mshv"
+	depends on X86_64 && HYPERV
+	select EVENTFD
+	select MSHV_XFER_TO_GUEST_WORK
+	help
+	  Select this option to enable core functionality for managing guest
+	  virtual machines running under the Microsoft Hypervisor.
+
+	  The interfaces are provided via a device named /dev/mshv.
+
+	  To compile this as a module, choose M here.
+
+	  If unsure, say N.
+
+config MSHV_ROOT
+	tristate "Microsoft Hyper-V root partition APIs driver"
+	depends on MSHV
+	help
+	  Select this option to provide /dev/mshv interfaces specific to
+	  running as the root partition on Microsoft Hypervisor.
+
+	  To compile this as a module, choose M here.
+
+	  If unsure, say N.
+
+config MSHV_VTL
+	tristate "Microsoft Hyper-V VTL driver"
+	depends on MSHV
+	select HYPERV_VTL_MODE
+	help
+	  Select this option to enable Hyper-V VTL driver.
+	  Virtual Secure Mode (VSM) is a set of hypervisor capabilities and
+	  enlightenments offered to host and guest partitions which enables
+	  the creation and management of new security boundaries within
+	  operating system software.
+
+	  VSM achieves and maintains isolation through Virtual Trust Levels
+	  (VTLs). Virtual Trust Levels are hierarchical, with higher levels
+	  being more privileged than lower levels. VTL0 is the least privileged
+	  level, and currently only other level supported is VTL2.
+
+	  To compile this as a module, choose M here.
+
+	  If unsure, say N.
+
+config MSHV_XFER_TO_GUEST_WORK
+	bool
+
 endmenu
drivers/hv/Makefile +20 -0
index d76df5c8c2a9..da7aa7542b05 100644
@@ -2,10 +2,30 @@
 obj-$(CONFIG_HYPERV)		+= hv_vmbus.o
 obj-$(CONFIG_HYPERV_UTILS)	+= hv_utils.o
 obj-$(CONFIG_HYPERV_BALLOON)	+= hv_balloon.o
+obj-$(CONFIG_MSHV)			+= mshv.o
+obj-$(CONFIG_MSHV_VTL)		+= mshv_vtl.o
+obj-$(CONFIG_MSHV_ROOT)		+= mshv_root.o
 
 CFLAGS_hv_trace.o = -I$(src)
 CFLAGS_hv_balloon.o = -I$(src)
 
+CFLAGS_mshv_main.o			= -DHV_HYPERV_DEFS
+CFLAGS_hv_call.o			= -DHV_HYPERV_DEFS
+CFLAGS_mshv_root_main.o		= -DHV_HYPERV_DEFS
+CFLAGS_mshv_root_hv_call.o	= -DHV_HYPERV_DEFS
+CFLAGS_mshv_synic.o			= -DHV_HYPERV_DEFS
+CFLAGS_mshv_portid_table.o	= -DHV_HYPERV_DEFS
+CFLAGS_mshv_eventfd.o		= -DHV_HYPERV_DEFS
+CFLAGS_mshv_msi.o			= -DHV_HYPERV_DEFS
+CFLAGS_mshv_vtl_main.o		= -DHV_HYPERV_DEFS
+
+mshv-y				+= mshv_main.o
+mshv_root-y			:= mshv_root_main.o mshv_synic.o mshv_portid_table.o \
+						mshv_eventfd.o mshv_msi.o mshv_root_hv_call.o hv_call.o
+mshv_vtl-y			:= mshv_vtl_main.o hv_call.o
+
+obj-$(CONFIG_MSHV_XFER_TO_GUEST_WORK) += xfer_to_guest.o
+
 hv_vmbus-y := vmbus_drv.o \
 		 hv.o connection.o channel.o \
 		 channel_mgmt.o ring_buffer.o hv_trace.o
drivers/hv/hv_call.c new file +103 -0

103 lines not on this page · raw message

drivers/hv/hv_common.c +4 -0
index 6ec63502d83d..b30122cb5862 100644
@@ -63,7 +63,11 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg);
  */
 static inline bool hv_output_arg_exists(void)
 {
+#ifdef CONFIG_MSHV_VTL
+	return true;
+#else
 	return hv_root_partition ? true : false;
+#endif
 }
 
 static void hv_kmsg_dump_unregister(void);
drivers/hv/mshv.h new file +125 -0

125 lines not on this page · raw message

drivers/hv/mshv_eventfd.c new file +761 -0

761 lines not on this page · raw message

drivers/hv/mshv_eventfd.h new file +80 -0

80 lines not on this page · raw message

drivers/hv/mshv_main.c new file +196 -0

196 lines not on this page · raw message

drivers/hv/mshv_msi.c new file +129 -0

129 lines not on this page · raw message

drivers/hv/mshv_portid_table.c new file +84 -0

84 lines not on this page · raw message

drivers/hv/mshv_root.h new file +232 -0

232 lines not on this page · raw message

drivers/hv/mshv_root_hv_call.c new file +911 -0

911 lines not on this page · raw message

drivers/hv/mshv_root_main.c new file +1911 -0

285 lines not on this page · raw message

drivers/hv/mshv_synic.c new file +688 -0

688 lines not on this page · raw message

drivers/hv/mshv_vtl.h new file +52 -0

52 lines not on this page · raw message

drivers/hv/mshv_vtl_main.c new file +1522 -0

1,522 lines not on this page · raw message

drivers/hv/xfer_to_guest.c new file +28 -0
new file mode 100644
index 000000000000..4a3901d44209

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

include/uapi/linux/mshv.h new file +306 -0

306 lines not on this page · raw message

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

Signature · 1 line
2.25.1

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

#40 lore raw

Re: [PATCH v4 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V

kernel test robot noticed the following build warnings:

Hi Nuno,

kernel test robot noticed the following build warnings:

[auto build test WARNING on arnd-asm-generic/master]
[also build test WARNING on arm64/for-next/core linus/master v6.6-rc3 next-20230929] [cannot apply to tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nuno-Das-Neves/hyperv-tlfs-Change-shared-HV_REGISTER_-defines-to-HV_MSR_/20230930-041305
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git master
patch link:    https://lore.kernel.org/r/1696010501-24584-16-git-send-email-nunodasneves%40linux.microsoft.com
patch subject: [PATCH v4 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
reproduce: (https://download.01.org/0day-ci/archive/20230930/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

versioncheck warnings: (new ones prefixed by >>)
INFO PATH=/opt/cross/clang/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/usr/bin/timeout -k 100 3h /usr/bin/make W=1 --keep-going HOSTCC=gcc-12 CC=gcc-12 -j32 KBUILD_MODPOST_WARN=1 ARCH=x86_64 versioncheck find ./* \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS -o -name .pc -o -name .hg -o -name .git \) -prune -o \
-name '*.[hcS]' -type f -print | sort \
| xargs perl -w ./scripts/checkversion.pl
./drivers/accessibility/speakup/genmap.c: 13 linux/version.h not needed. ./drivers/accessibility/speakup/makemapdata.c: 13 linux/version.h not needed.

>> ./drivers/hv/mshv_portid_table.c: 3 linux/version.h not needed.

./drivers/staging/media/atomisp/include/linux/atomisp.h: 23 linux/version.h not needed. ./samples/bpf/spintest.bpf.c: 8 linux/version.h not needed. ./samples/trace_events/trace_custom_sched.c: 11 linux/version.h not needed. ./sound/soc/codecs/cs42l42.c: 14 linux/version.h not needed. ./tools/lib/bpf/bpf_helpers.h: 402: need linux/version.h ./tools/testing/selftests/bpf/progs/dev_cgroup.c: 9 linux/version.h not needed. ./tools/testing/selftests/bpf/progs/netcnt_prog.c: 3 linux/version.h not needed. ./tools/testing/selftests/bpf/progs/test_map_lock.c: 4 linux/version.h not needed. ./tools/testing/selftests/bpf/progs/test_send_signal_kern.c: 4 linux/version.h not needed. ./tools/testing/selftests/bpf/progs/test_spin_lock.c: 4 linux/version.h not needed. ./tools/testing/selftests/bpf/progs/test_tcp_estats.c: 37 linux/version.h not needed. ./tools/testing/selftests/wireguard/qemu/init.c: 27 linux/version.h not needed.

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#41 lore raw

Re: [PATCH v4 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V

In reply to Nuno Das Neves

include/uapi/linux/mshv.h line 1

Quoted 4 lines · Nuno Das Neves
include/uapi/linux/mshv.h new file +1 -0
@@ -0,0 +1,306 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

Much better.

include/uapi/linux/mshv.h line 8

Quoted 7 lines
include/uapi/linux/mshv.h new file +7 -0
+#ifndef _UAPI_LINUX_MSHV_H
+#define _UAPI_LINUX_MSHV_H
+
+/*
+ * Userspace interface for /dev/mshv
+ * Microsoft Hypervisor root partition APIs
+ * NOTE: This API is not yet stable!

Sorry, that will not work for obvious reasons.

greg k-h

maintainer
#42 lore raw

Re: [PATCH v4 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V

Quoted 8 lines · Greg KH

include/uapi/linux/mshv.h line 1

Quoted 4 lines · Nuno Das Neves
include/uapi/linux/mshv.h new file +1 -0
@@ -0,0 +1,306 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

Much better.

Quoted 9 lines

include/uapi/linux/mshv.h line 8

Quoted 7 lines
include/uapi/linux/mshv.h new file +7 -0
+#ifndef _UAPI_LINUX_MSHV_H
+#define _UAPI_LINUX_MSHV_H
+
+/*
+ * Userspace interface for /dev/mshv
+ * Microsoft Hypervisor root partition APIs
+ * NOTE: This API is not yet stable!

Sorry, that will not work for obvious reasons.

This can be removed. For practical purposes, the API has been stable for the past three years.

Thanks,
Wei.

Quoted 2 lines

greg k-h

#43 lore raw

Re: [PATCH v4 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V

Quoted 19 lines · Wei Liu
Quoted 8 lines · Greg KH

include/uapi/linux/mshv.h line 1

Quoted 4 lines · Nuno Das Neves
include/uapi/linux/mshv.h new file +1 -0
@@ -0,0 +1,306 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

Much better.

Quoted 9 lines

include/uapi/linux/mshv.h line 8

Quoted 7 lines
include/uapi/linux/mshv.h new file +7 -0
+#ifndef _UAPI_LINUX_MSHV_H
+#define _UAPI_LINUX_MSHV_H
+
+/*
+ * Userspace interface for /dev/mshv
+ * Microsoft Hypervisor root partition APIs
+ * NOTE: This API is not yet stable!

Sorry, that will not work for obvious reasons.

Quoted 2 lines

This can be removed. For practical purposes, the API has been stable for the past three years.

Then who wrote this text?

confused,

greg k-h

maintainer
#44 lore raw

Re: [PATCH v4 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V

Quoted 20 lines · Greg KH
Quoted 19 lines · Wei Liu
Quoted 17 lines · Greg KH

include/uapi/linux/mshv.h line 1

Quoted 4 lines · Nuno Das Neves
include/uapi/linux/mshv.h new file +1 -0
@@ -0,0 +1,306 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

Much better.

include/uapi/linux/mshv.h line 8

Quoted 7 lines
include/uapi/linux/mshv.h new file +7 -0
+#ifndef _UAPI_LINUX_MSHV_H
+#define _UAPI_LINUX_MSHV_H
+
+/*
+ * Userspace interface for /dev/mshv
+ * Microsoft Hypervisor root partition APIs
+ * NOTE: This API is not yet stable!

Sorry, that will not work for obvious reasons.

Quoted 4 lines
Quoted 2 lines

This can be removed. For practical purposes, the API has been stable for the past three years.

Then who wrote this text?

I don't think this matter, does it? This patch series had been rewritten so many times internally to conform to upstream standard it is very difficult to track down who wrote this and when.

If you have concrete concerns about removing the text, please let me know.

Thanks,
Wei.

Quoted 4 lines

confused,

greg k-h

#45 lore raw

Re: [PATCH v4 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V

Quoted 21 lines · Wei Liu
Quoted 20 lines · Greg KH
Quoted 19 lines · Wei Liu
Quoted 17 lines · Greg KH

include/uapi/linux/mshv.h line 1

Quoted 4 lines · Nuno Das Neves
include/uapi/linux/mshv.h new file +1 -0
@@ -0,0 +1,306 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

Much better.

include/uapi/linux/mshv.h line 8

Quoted 7 lines
include/uapi/linux/mshv.h new file +7 -0
+#ifndef _UAPI_LINUX_MSHV_H
+#define _UAPI_LINUX_MSHV_H
+
+/*
+ * Userspace interface for /dev/mshv
+ * Microsoft Hypervisor root partition APIs
+ * NOTE: This API is not yet stable!

Sorry, that will not work for obvious reasons.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

This can be removed. For practical purposes, the API has been stable for the past three years.

Then who wrote this text?

I don't think this matter, does it? This patch series had been rewritten so many times internally to conform to upstream standard it is very difficult to track down who wrote this and when.

The point is someone wrote this for a good reason so figuring out why that was done would be good for you all to do as maybe it is true!

Quoted 2 lines

If you have concrete concerns about removing the text, please let me know.

You need to verify that the comment is not true before removing it, otherwise you all will have a very hard time in the future when things change...

thanks,

greg k-h

maintainer
#46 lore raw

Re: [PATCH v4 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V

Quoted 34 lines · Greg KH
Quoted 21 lines · Wei Liu
Quoted 20 lines · Greg KH
Quoted 19 lines · Wei Liu
Quoted 17 lines · Greg KH

include/uapi/linux/mshv.h line 1

Quoted 4 lines · Nuno Das Neves
include/uapi/linux/mshv.h new file +1 -0
@@ -0,0 +1,306 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

Much better.

include/uapi/linux/mshv.h line 8

Quoted 7 lines
include/uapi/linux/mshv.h new file +7 -0
+#ifndef _UAPI_LINUX_MSHV_H
+#define _UAPI_LINUX_MSHV_H
+
+/*
+ * Userspace interface for /dev/mshv
+ * Microsoft Hypervisor root partition APIs
+ * NOTE: This API is not yet stable!

Sorry, that will not work for obvious reasons.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

This can be removed. For practical purposes, the API has been stable for the past three years.

Then who wrote this text?

I don't think this matter, does it? This patch series had been rewritten so many times internally to conform to upstream standard it is very difficult to track down who wrote this and when.

The point is someone wrote this for a good reason so figuring out why that was done would be good for you all to do as maybe it is true!

Quoted 6 lines
Quoted 2 lines

If you have concrete concerns about removing the text, please let me know.

You need to verify that the comment is not true before removing it, otherwise you all will have a very hard time in the future when things change...

I understand your point. Thanks, I will make sure to do that. :-)

Thanks,
Wei.

Quoted 4 lines

thanks,

greg k-h

#47 lore raw

Re: [PATCH v4 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V

In reply to Nuno Das Neves
kernel test robot noticed the following build warnings:

Hi Nuno,

kernel test robot noticed the following build warnings:

[auto build test WARNING on arnd-asm-generic/master]
[also build test WARNING on tip/x86/core arm64/for-next/core linus/master v6.6 next-20231103] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nuno-Das-Neves/hyperv-tlfs-Change-shared-HV_REGISTER_-defines-to-HV_MSR_/20230930-041305
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git master
patch link:    https://lore.kernel.org/r/1696010501-24584-16-git-send-email-nunodasneves%40linux.microsoft.com
patch subject: [PATCH v4 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20231106/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231106/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/hv/hv_call.c:21:5: warning: no previous prototype for 'hv_call_get_vp_registers' [-Wmissing-prototypes]
      21 | int hv_call_get_vp_registers(u32 vp_index, u64 partition_id, u16 count,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/hv_call.c:65:5: warning: no previous prototype for 'hv_call_set_vp_registers' [-Wmissing-prototypes]
      65 | int hv_call_set_vp_registers(u32 vp_index, u64 partition_id, u16 count,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~
--
>> drivers/hv/mshv_root_main.c:1816:12: warning: no previous prototype for 'mshv_root_init' [-Wmissing-prototypes]
    1816 | int __init mshv_root_init(void)
         |            ^~~~~~~~~~~~~~
>> drivers/hv/mshv_root_main.c:1896:13: warning: no previous prototype for 'mshv_root_exit' [-Wmissing-prototypes]
    1896 | void __exit mshv_root_exit(void)
         |             ^~~~~~~~~~~~~~
--
>> drivers/hv/mshv_synic.c:27:1: warning: no previous prototype for 'synic_event_ring_get_queued_port' [-Wmissing-prototypes]
      27 | synic_event_ring_get_queued_port(u32 sint_index)
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
>> drivers/hv/mshv_root_hv_call.c:46:5: warning: no previous prototype for 'hv_call_withdraw_memory' [-Wmissing-prototypes]
      46 | int hv_call_withdraw_memory(u64 count, int node, u64 partition_id)
         |     ^~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:94:5: warning: no previous prototype for 'hv_call_create_partition' [-Wmissing-prototypes]
      94 | int hv_call_create_partition(u64 flags,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:139:5: warning: no previous prototype for 'hv_call_initialize_partition' [-Wmissing-prototypes]
     139 | int hv_call_initialize_partition(u64 partition_id)
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:166:5: warning: no previous prototype for 'hv_call_finalize_partition' [-Wmissing-prototypes]
     166 | int hv_call_finalize_partition(u64 partition_id)
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:177:5: warning: no previous prototype for 'hv_call_delete_partition' [-Wmissing-prototypes]
     177 | int hv_call_delete_partition(u64 partition_id)
         |     ^~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:188:5: warning: no previous prototype for 'hv_call_map_gpa_pages' [-Wmissing-prototypes]
     188 | int hv_call_map_gpa_pages(u64 partition_id, u64 gpa_target, u64 page_count,
         |     ^~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:241:5: warning: no previous prototype for 'hv_call_unmap_gpa_pages' [-Wmissing-prototypes]
     241 | int hv_call_unmap_gpa_pages(u64 partition_id, u64 gpa_target, u64 page_count,
         |     ^~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:277:5: warning: no previous prototype for 'hv_call_get_gpa_access_states' [-Wmissing-prototypes]
     277 | int hv_call_get_gpa_access_states(u64 partition_id, u32 count,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:320:5: warning: no previous prototype for 'hv_call_install_intercept' [-Wmissing-prototypes]
     320 | int hv_call_install_intercept(u64 partition_id, u32 access_type,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:350:5: warning: no previous prototype for 'hv_call_assert_virtual_interrupt' [-Wmissing-prototypes]
     350 | int hv_call_assert_virtual_interrupt(u64 partition_id, u32 vector, u64 dest_addr,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:372:5: warning: no previous prototype for 'hv_call_get_vp_state' [-Wmissing-prototypes]
     372 | int hv_call_get_vp_state(u32 vp_index, u64 partition_id,
         |     ^~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:429:5: warning: no previous prototype for 'hv_call_set_vp_state' [-Wmissing-prototypes]
     429 | int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
         |     ^~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:494:5: warning: no previous prototype for 'hv_call_map_vp_state_page' [-Wmissing-prototypes]
     494 | int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:531:5: warning: no previous prototype for 'hv_call_unmap_vp_state_page' [-Wmissing-prototypes]
     531 | int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type)
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:554:5: warning: no previous prototype for 'hv_call_get_partition_property' [-Wmissing-prototypes]
     554 | int hv_call_get_partition_property(u64 partition_id, u64 property_code,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:581:5: warning: no previous prototype for 'hv_call_set_partition_property' [-Wmissing-prototypes]
     581 | int hv_call_set_partition_property(u64 partition_id, u64 property_code,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:609:5: warning: no previous prototype for 'hv_call_translate_virtual_address' [-Wmissing-prototypes]
     609 | int hv_call_translate_virtual_address(u32 vp_index, u64 partition_id, u64 flags,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:648:1: warning: no previous prototype for 'hv_call_clear_virtual_interrupt' [-Wmissing-prototypes]
     648 | hv_call_clear_virtual_interrupt(u64 partition_id)
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:662:1: warning: no previous prototype for 'hv_call_create_port' [-Wmissing-prototypes]
     662 | hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
         | ^~~~~~~~~~~~~~~~~~~
>> drivers/hv/mshv_root_hv_call.c:703:1: warning: no previous prototype for 'hv_call_delete_port' [-Wmissing-prototypes]
     703 | hv_call_delete_port(u64 port_partition_id, union hv_port_id port_id)
         | ^~~~~~~~~~~~~~~~~~~
   drivers/hv/mshv_root_hv_call.c:721:1: warning: no previous prototype for 'hv_call_connect_port' [-Wmissing-prototypes]
     721 | hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
         | ^~~~~~~~~~~~~~~~~~~~
   drivers/hv/mshv_root_hv_call.c:761:1: warning: no previous prototype for 'hv_call_disconnect_port' [-Wmissing-prototypes]
     761 | hv_call_disconnect_port(u64 connection_partition_id,
         | ^~~~~~~~~~~~~~~~~~~~~~~
   drivers/hv/mshv_root_hv_call.c:781:1: warning: no previous prototype for 'hv_call_notify_port_ring_empty' [-Wmissing-prototypes]
     781 | hv_call_notify_port_ring_empty(u32 sint_index)
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/hv/mshv_root_hv_call.c:798:5: warning: no previous prototype for 'hv_call_register_intercept_result' [-Wmissing-prototypes]
     798 | int hv_call_register_intercept_result(u32 vp_index, u64 partition_id,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/hv/mshv_root_hv_call.c:834:5: warning: no previous prototype for 'hv_call_signal_event_direct' [-Wmissing-prototypes]
     834 | int hv_call_signal_event_direct(u32 vp_index, u64 partition_id, u8 vtl,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/hv/mshv_root_hv_call.c:861:5: warning: no previous prototype for 'hv_call_post_message_direct' [-Wmissing-prototypes]
     861 | int hv_call_post_message_direct(u32 vp_index, u64 partition_id, u8 vtl,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/hv/mshv_root_hv_call.c:883:5: warning: no previous prototype for 'hv_call_get_vp_cpuid_values' [-Wmissing-prototypes]
     883 | int hv_call_get_vp_cpuid_values(u32 vp_index, u64 partition_id,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
--
>> drivers/hv/xfer_to_guest.c:15:5: warning: no previous prototype for 'mshv_xfer_to_guest_mode_handle_work' [-Wmissing-prototypes]

15 | int mshv_xfer_to_guest_mode_handle_work(unsigned long ti_work)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +/hv_call_get_vp_registers +21 drivers/hv/hv_call.c

    14	
    15	#define HV_GET_REGISTER_BATCH_SIZE	\
    16		(HV_HYP_PAGE_SIZE / sizeof(union hv_register_value))
    17	#define HV_SET_REGISTER_BATCH_SIZE	\
    18		((HV_HYP_PAGE_SIZE - sizeof(struct hv_input_set_vp_registers)) \
    19			/ sizeof(struct hv_register_assoc))
    20	
  > 21	int hv_call_get_vp_registers(u32 vp_index, u64 partition_id, u16 count,
    22				     union hv_input_vtl input_vtl,
    23				     struct hv_register_assoc *registers)
    24	{
    25		struct hv_input_get_vp_registers *input_page;
    26		union hv_register_value *output_page;
    27		u16 completed = 0;
    28		unsigned long remaining = count;
    29		int rep_count, i;
    30		u64 status = HV_STATUS_SUCCESS;
    31		unsigned long flags;
    32	
    33		local_irq_save(flags);
    34	
    35		input_page = *this_cpu_ptr(hyperv_pcpu_input_arg);
    36		output_page = *this_cpu_ptr(hyperv_pcpu_output_arg);
    37	
    38		input_page->partition_id = partition_id;
    39		input_page->vp_index = vp_index;
    40		input_page->input_vtl.as_uint8 = input_vtl.as_uint8;
    41		input_page->rsvd_z8 = 0;
    42		input_page->rsvd_z16 = 0;
    43	
    44		while (remaining) {
    45			rep_count = min(remaining, HV_GET_REGISTER_BATCH_SIZE);
    46			for (i = 0; i < rep_count; ++i)
    47				input_page->names[i] = registers[i].name;
    48	
    49			status = hv_do_rep_hypercall(HVCALL_GET_VP_REGISTERS, rep_count,
    50						     0, input_page, output_page);
    51			if (!hv_result_success(status))
    52				break;
    53			completed = hv_repcomp(status);
    54			for (i = 0; i < completed; ++i)
    55				registers[i].value = output_page[i];
    56	
    57			registers += completed;
    58			remaining -= completed;
    59		}
    60		local_irq_restore(flags);
    61	
    62		return hv_status_to_errno(status);
    63	}
    64	
  > 65	int hv_call_set_vp_registers(u32 vp_index, u64 partition_id, u16 count,
    66				     union hv_input_vtl input_vtl,
    67				     struct hv_register_assoc *registers)
    68	{
    69		struct hv_input_set_vp_registers *input_page;
    70		u16 completed = 0;
    71		unsigned long remaining = count;
    72		int rep_count;
    73		u64 status = HV_STATUS_SUCCESS;
    74		unsigned long flags;
    75	
    76		local_irq_save(flags);
    77		input_page = *this_cpu_ptr(hyperv_pcpu_input_arg);
    78	
    79		input_page->partition_id = partition_id;
    80		input_page->vp_index = vp_index;
    81		input_page->input_vtl.as_uint8 = input_vtl.as_uint8;
    82		input_page->rsvd_z8 = 0;
    83		input_page->rsvd_z16 = 0;
    84	
    85		while (remaining) {
    86			rep_count = min(remaining, HV_SET_REGISTER_BATCH_SIZE);
    87			memcpy(input_page->elements, registers,
    88			       sizeof(struct hv_register_assoc) * rep_count);
    89	
    90			status = hv_do_rep_hypercall(HVCALL_SET_VP_REGISTERS, rep_count,
    91						     0, input_page, NULL);
    92			if (!hv_result_success(status))
    93				break;
    94			completed = hv_repcomp(status);
    95			registers += completed;
    96			remaining -= completed;
    97		}
    98	
    99		local_irq_restore(flags);

100
101 return hv_status_to_errno(status);
102 }
103

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#48 lore raw

Re: [PATCH v4 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V

In reply to Nuno Das Neves
kernel test robot noticed the following build errors:

Hi Nuno,

kernel test robot noticed the following build errors:

[auto build test ERROR on arnd-asm-generic/master]
[also build test ERROR on tip/x86/core arm64/for-next/core linus/master v6.6 next-20231106] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nuno-Das-Neves/hyperv-tlfs-Change-shared-HV_REGISTER_-defines-to-HV_MSR_/20230930-041305
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git master
patch link:    https://lore.kernel.org/r/1696010501-24584-16-git-send-email-nunodasneves%40linux.microsoft.com
patch subject: [PATCH v4 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20231106/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231106/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/hv/mshv_vtl_main.c:25:10: fatal error: ../../../kernel/fpu/legacy.h: No such file or directory
      25 | #include "../../../kernel/fpu/legacy.h"
         |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.

vim +25 drivers/hv/mshv_vtl_main.c

    24	
  > 25	#include "../../../kernel/fpu/legacy.h"
    26	#include "mshv.h"
    27	#include "mshv_vtl.h"
    28	#include "hyperv_vmbus.h"
    29	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki