* [PATCH 0/5] Add new headers for Hyper-V Dom0
@ 2024-10-03 19:50 Nuno Das Neves
2024-10-03 19:51 ` [PATCH 1/5] hyperv: Move hv_connection_id to hyperv-tlfs.h Nuno Das Neves
` (7 more replies)
0 siblings, 8 replies; 27+ messages in thread
From: Nuno Das Neves @ 2024-10-03 19:50 UTC (permalink / raw)
To: linux-hyperv, linux-arm-kernel, linux-kernel, kvm, iommu, netdev,
linux-pci, linux-arch, virtualization
Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, luto, tglx,
mingo, bp, dave.hansen, x86, hpa, seanjc, pbonzini, peterz,
daniel.lezcano, joro, robin.murphy, davem, edumazet, kuba, pabeni,
lpieralisi, kw, robh, bhelgaas, arnd, sgarzare, jinankjain,
muminulrussell, skinsburskii, mukeshrathor
To support Hyper-V Dom0 (aka Linux as root partition), many new
definitions are required.
The plan going forward is to directly import headers from
Hyper-V. This is a more maintainable way to import definitions
rather than via the TLFS doc. This patch series introduces
new headers (hvhdk.h, hvgdk.h, etc, see patch #3) directly
derived from Hyper-V code.
This patch series replaces hyperv-tlfs.h with hvhdk.h, but only
in Microsoft-maintained Hyper-V code where they are needed. This
leaves the existing hyperv-tlfs.h in use elsewhere - notably for
Hyper-V enlightenments on KVM guests.
An intermediary header "hv_defs.h" is introduced to conditionally
include either hyperv-tlfs.h or hvhdk.h. This is required because
several headers which today include hyperv-tlfs.h, are shared
between Hyper-V and KVM code (e.g. mshyperv.h).
Summary:
Patch 1-2: Cleanup patches
Patch 3: Add the new headers (hvhdk.h, etc..) in include/hyperv/
Patch 4: Add hv_defs.h and use it in mshyperv.h, svm.h,
hyperv_timer.h
Patch 5: Switch to the new headers, only in Hyper-V code
Nuno Das Neves (5):
hyperv: Move hv_connection_id to hyperv-tlfs.h
hyperv: Remove unnecessary #includes
hyperv: Add new Hyper-V headers
hyperv: Add hv_defs.h to conditionally include hyperv-tlfs.h or
hvhdk.h
hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
arch/arm64/hyperv/hv_core.c | 3 +-
arch/arm64/hyperv/mshyperv.c | 1 +
arch/arm64/include/asm/mshyperv.h | 2 +-
arch/x86/entry/vdso/vma.c | 1 +
arch/x86/hyperv/hv_apic.c | 2 +-
arch/x86/hyperv/hv_init.c | 3 +-
arch/x86/hyperv/hv_proc.c | 4 +-
arch/x86/hyperv/hv_spinlock.c | 1 +
arch/x86/hyperv/hv_vtl.c | 1 +
arch/x86/hyperv/irqdomain.c | 1 +
arch/x86/hyperv/ivm.c | 2 +-
arch/x86/hyperv/mmu.c | 2 +-
arch/x86/hyperv/nested.c | 2 +-
arch/x86/include/asm/kvm_host.h | 1 -
arch/x86/include/asm/mshyperv.h | 3 +-
arch/x86/include/asm/svm.h | 2 +-
arch/x86/include/asm/vdso/gettimeofday.h | 1 +
arch/x86/kernel/cpu/mshyperv.c | 2 +-
arch/x86/kernel/cpu/mtrr/generic.c | 1 +
arch/x86/kvm/vmx/vmx_onhyperv.h | 1 -
arch/x86/mm/pat/set_memory.c | 2 -
drivers/clocksource/hyperv_timer.c | 2 +-
drivers/hv/channel.c | 1 +
drivers/hv/channel_mgmt.c | 1 +
drivers/hv/connection.c | 1 +
drivers/hv/hv.c | 1 +
drivers/hv/hv_balloon.c | 5 +-
drivers/hv/hv_common.c | 2 +-
drivers/hv/hv_kvp.c | 1 -
drivers/hv/hv_snapshot.c | 1 -
drivers/hv/hv_util.c | 1 +
drivers/hv/hyperv_vmbus.h | 1 -
drivers/hv/ring_buffer.c | 1 +
drivers/hv/vmbus_drv.c | 1 +
drivers/iommu/hyperv-iommu.c | 1 +
drivers/net/hyperv/netvsc.c | 1 +
drivers/pci/controller/pci-hyperv.c | 1 +
include/asm-generic/hyperv-tlfs.h | 9 +
include/asm-generic/mshyperv.h | 2 +-
include/clocksource/hyperv_timer.h | 2 +-
include/hyperv/hv_defs.h | 29 +
include/hyperv/hvgdk.h | 66 ++
include/hyperv/hvgdk_ext.h | 46 +
include/hyperv/hvgdk_mini.h | 1212 ++++++++++++++++++++++
include/hyperv/hvhdk.h | 733 +++++++++++++
include/hyperv/hvhdk_mini.h | 310 ++++++
include/linux/hyperv.h | 12 +-
net/vmw_vsock/hyperv_transport.c | 1 -
48 files changed, 2442 insertions(+), 40 deletions(-)
create mode 100644 include/hyperv/hv_defs.h
create mode 100644 include/hyperv/hvgdk.h
create mode 100644 include/hyperv/hvgdk_ext.h
create mode 100644 include/hyperv/hvgdk_mini.h
create mode 100644 include/hyperv/hvhdk.h
create mode 100644 include/hyperv/hvhdk_mini.h
--
2.34.1
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 1/5] hyperv: Move hv_connection_id to hyperv-tlfs.h
2024-10-03 19:50 [PATCH 0/5] Add new headers for Hyper-V Dom0 Nuno Das Neves
@ 2024-10-03 19:51 ` Nuno Das Neves
2024-10-07 16:24 ` Wei Liu
2024-10-03 19:51 ` [PATCH 2/5] hyperv: Remove unnecessary #includes Nuno Das Neves
` (6 subsequent siblings)
7 siblings, 1 reply; 27+ messages in thread
From: Nuno Das Neves @ 2024-10-03 19:51 UTC (permalink / raw)
To: linux-hyperv, linux-arm-kernel, linux-kernel, kvm, iommu, netdev,
linux-pci, linux-arch, virtualization
Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, luto, tglx,
mingo, bp, dave.hansen, x86, hpa, seanjc, pbonzini, peterz,
daniel.lezcano, joro, robin.murphy, davem, edumazet, kuba, pabeni,
lpieralisi, kw, robh, bhelgaas, arnd, sgarzare, jinankjain,
muminulrussell, skinsburskii, mukeshrathor
This definition is in the wrong file; it is part of the TLFS doc.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
include/asm-generic/hyperv-tlfs.h | 9 +++++++++
include/linux/hyperv.h | 9 ---------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h
index 814207e7c37f..52274c9aefef 100644
--- a/include/asm-generic/hyperv-tlfs.h
+++ b/include/asm-generic/hyperv-tlfs.h
@@ -871,4 +871,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
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 22c22fb91042..d0893ec488ae 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -768,15 +768,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,
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 2/5] hyperv: Remove unnecessary #includes
2024-10-03 19:50 [PATCH 0/5] Add new headers for Hyper-V Dom0 Nuno Das Neves
2024-10-03 19:51 ` [PATCH 1/5] hyperv: Move hv_connection_id to hyperv-tlfs.h Nuno Das Neves
@ 2024-10-03 19:51 ` Nuno Das Neves
2024-10-07 16:24 ` Wei Liu
2024-10-10 18:21 ` Michael Kelley
2024-10-03 19:51 ` [PATCH 3/5] hyperv: Add new Hyper-V headers Nuno Das Neves
` (5 subsequent siblings)
7 siblings, 2 replies; 27+ messages in thread
From: Nuno Das Neves @ 2024-10-03 19:51 UTC (permalink / raw)
To: linux-hyperv, linux-arm-kernel, linux-kernel, kvm, iommu, netdev,
linux-pci, linux-arch, virtualization
Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, luto, tglx,
mingo, bp, dave.hansen, x86, hpa, seanjc, pbonzini, peterz,
daniel.lezcano, joro, robin.murphy, davem, edumazet, kuba, pabeni,
lpieralisi, kw, robh, bhelgaas, arnd, sgarzare, jinankjain,
muminulrussell, skinsburskii, mukeshrathor
asm/hyperv-tlfs.h is already included implicitly wherever mshyperv.h
or linux/hyperv.h is included. Remove those redundancies.
Remove includes of linux/hyperv.h and mshyperv.h where they are not
needed.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
arch/arm64/hyperv/hv_core.c | 2 --
arch/x86/hyperv/hv_apic.c | 1 -
arch/x86/hyperv/hv_init.c | 2 --
arch/x86/hyperv/hv_proc.c | 1 -
arch/x86/hyperv/ivm.c | 1 -
arch/x86/hyperv/mmu.c | 1 -
arch/x86/hyperv/nested.c | 1 -
arch/x86/include/asm/kvm_host.h | 1 -
arch/x86/include/asm/mshyperv.h | 1 -
arch/x86/kernel/cpu/mshyperv.c | 1 -
arch/x86/kvm/vmx/vmx_onhyperv.h | 1 -
arch/x86/mm/pat/set_memory.c | 2 --
drivers/clocksource/hyperv_timer.c | 1 -
drivers/hv/hv_balloon.c | 2 --
drivers/hv/hv_common.c | 1 -
drivers/hv/hv_kvp.c | 1 -
drivers/hv/hv_snapshot.c | 1 -
drivers/hv/hyperv_vmbus.h | 1 -
net/vmw_vsock/hyperv_transport.c | 1 -
19 files changed, 23 deletions(-)
diff --git a/arch/arm64/hyperv/hv_core.c b/arch/arm64/hyperv/hv_core.c
index f1ebc025e1df..9d1969b875e9 100644
--- a/arch/arm64/hyperv/hv_core.c
+++ b/arch/arm64/hyperv/hv_core.c
@@ -11,11 +11,9 @@
#include <linux/types.h>
#include <linux/export.h>
#include <linux/mm.h>
-#include <linux/hyperv.h>
#include <linux/arm-smccc.h>
#include <linux/module.h>
#include <asm-generic/bug.h>
-#include <asm/hyperv-tlfs.h>
#include <asm/mshyperv.h>
/*
diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
index 0569f579338b..f022d5f64fb6 100644
--- a/arch/x86/hyperv/hv_apic.c
+++ b/arch/x86/hyperv/hv_apic.c
@@ -23,7 +23,6 @@
#include <linux/vmalloc.h>
#include <linux/mm.h>
#include <linux/clockchips.h>
-#include <linux/hyperv.h>
#include <linux/slab.h>
#include <linux/cpuhotplug.h>
#include <asm/hypervisor.h>
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index 17a71e92a343..fc3c3d76c181 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -19,7 +19,6 @@
#include <asm/sev.h>
#include <asm/ibt.h>
#include <asm/hypervisor.h>
-#include <asm/hyperv-tlfs.h>
#include <asm/mshyperv.h>
#include <asm/idtentry.h>
#include <asm/set_memory.h>
@@ -27,7 +26,6 @@
#include <linux/version.h>
#include <linux/vmalloc.h>
#include <linux/mm.h>
-#include <linux/hyperv.h>
#include <linux/slab.h>
#include <linux/kernel.h>
#include <linux/cpuhotplug.h>
diff --git a/arch/x86/hyperv/hv_proc.c b/arch/x86/hyperv/hv_proc.c
index 3fa1f2ee7b0d..b74c06c04ff1 100644
--- a/arch/x86/hyperv/hv_proc.c
+++ b/arch/x86/hyperv/hv_proc.c
@@ -3,7 +3,6 @@
#include <linux/vmalloc.h>
#include <linux/mm.h>
#include <linux/clockchips.h>
-#include <linux/hyperv.h>
#include <linux/slab.h>
#include <linux/cpuhotplug.h>
#include <linux/minmax.h>
diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
index 60fc3ed72830..b56d70612734 100644
--- a/arch/x86/hyperv/ivm.c
+++ b/arch/x86/hyperv/ivm.c
@@ -7,7 +7,6 @@
*/
#include <linux/bitfield.h>
-#include <linux/hyperv.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <asm/svm.h>
diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c
index 1cc113200ff5..cc8c3bd0e7c2 100644
--- a/arch/x86/hyperv/mmu.c
+++ b/arch/x86/hyperv/mmu.c
@@ -1,6 +1,5 @@
#define pr_fmt(fmt) "Hyper-V: " fmt
-#include <linux/hyperv.h>
#include <linux/log2.h>
#include <linux/slab.h>
#include <linux/types.h>
diff --git a/arch/x86/hyperv/nested.c b/arch/x86/hyperv/nested.c
index 9dc259fa322e..ee06d0315c24 100644
--- a/arch/x86/hyperv/nested.c
+++ b/arch/x86/hyperv/nested.c
@@ -11,7 +11,6 @@
#include <linux/types.h>
-#include <asm/hyperv-tlfs.h>
#include <asm/mshyperv.h>
#include <asm/tlbflush.h>
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 4a68cb3eba78..3627eab994a3 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -24,7 +24,6 @@
#include <linux/pvclock_gtod.h>
#include <linux/clocksource.h>
#include <linux/irqbypass.h>
-#include <linux/hyperv.h>
#include <linux/kfifo.h>
#include <asm/apic.h>
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 390c4d13956d..47ca48062547 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -9,7 +9,6 @@
#include <asm/hyperv-tlfs.h>
#include <asm/nospec-branch.h>
#include <asm/paravirt.h>
-#include <asm/mshyperv.h>
/*
* Hyper-V always provides a single IO-APIC at this MMIO address.
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index e0fd57a8ba84..8e8fd23b1439 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -20,7 +20,6 @@
#include <linux/random.h>
#include <asm/processor.h>
#include <asm/hypervisor.h>
-#include <asm/hyperv-tlfs.h>
#include <asm/mshyperv.h>
#include <asm/desc.h>
#include <asm/idtentry.h>
diff --git a/arch/x86/kvm/vmx/vmx_onhyperv.h b/arch/x86/kvm/vmx/vmx_onhyperv.h
index eb48153bfd73..f4b081eb6521 100644
--- a/arch/x86/kvm/vmx/vmx_onhyperv.h
+++ b/arch/x86/kvm/vmx/vmx_onhyperv.h
@@ -3,7 +3,6 @@
#ifndef __ARCH_X86_KVM_VMX_ONHYPERV_H__
#define __ARCH_X86_KVM_VMX_ONHYPERV_H__
-#include <asm/hyperv-tlfs.h>
#include <asm/mshyperv.h>
#include <linux/jump_label.h>
diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index 44f7b2ea6a07..85fa0d4509f0 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -32,8 +32,6 @@
#include <asm/pgalloc.h>
#include <asm/proto.h>
#include <asm/memtype.h>
-#include <asm/hyperv-tlfs.h>
-#include <asm/mshyperv.h>
#include "../mm_internal.h"
diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
index b2a080647e41..1b7de45a7185 100644
--- a/drivers/clocksource/hyperv_timer.c
+++ b/drivers/clocksource/hyperv_timer.c
@@ -23,7 +23,6 @@
#include <linux/acpi.h>
#include <linux/hyperv.h>
#include <clocksource/hyperv_timer.h>
-#include <asm/hyperv-tlfs.h>
#include <asm/mshyperv.h>
static struct clock_event_device __percpu *hv_clock_event;
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index c38dcdfcb914..a120e9b80ded 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -28,8 +28,6 @@
#include <linux/sizes.h>
#include <linux/hyperv.h>
-#include <asm/hyperv-tlfs.h>
-
#include <asm/mshyperv.h>
#define CREATE_TRACE_POINTS
diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index 9c452bfbd571..a5217f837237 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -28,7 +28,6 @@
#include <linux/slab.h>
#include <linux/dma-map-ops.h>
#include <linux/set_memory.h>
-#include <asm/hyperv-tlfs.h>
#include <asm/mshyperv.h>
/*
diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c
index d35b60c06114..68e73ec7ab28 100644
--- a/drivers/hv/hv_kvp.c
+++ b/drivers/hv/hv_kvp.c
@@ -27,7 +27,6 @@
#include <linux/connector.h>
#include <linux/workqueue.h>
#include <linux/hyperv.h>
-#include <asm/hyperv-tlfs.h>
#include "hyperv_vmbus.h"
#include "hv_utils_transport.h"
diff --git a/drivers/hv/hv_snapshot.c b/drivers/hv/hv_snapshot.c
index 0d2184be1691..90fc935e89bd 100644
--- a/drivers/hv/hv_snapshot.c
+++ b/drivers/hv/hv_snapshot.c
@@ -12,7 +12,6 @@
#include <linux/connector.h>
#include <linux/workqueue.h>
#include <linux/hyperv.h>
-#include <asm/hyperv-tlfs.h>
#include "hyperv_vmbus.h"
#include "hv_utils_transport.h"
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 76ac5185a01a..321770d7ce25 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -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>
diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c
index e2157e387217..f77f0ea1ddad 100644
--- a/net/vmw_vsock/hyperv_transport.c
+++ b/net/vmw_vsock/hyperv_transport.c
@@ -13,7 +13,6 @@
#include <linux/hyperv.h>
#include <net/sock.h>
#include <net/af_vsock.h>
-#include <asm/hyperv-tlfs.h>
/* Older (VMBUS version 'VERSION_WIN10' or before) Windows hosts have some
* stricter requirements on the hv_sock ring buffer size of six 4K pages.
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 3/5] hyperv: Add new Hyper-V headers
2024-10-03 19:50 [PATCH 0/5] Add new headers for Hyper-V Dom0 Nuno Das Neves
2024-10-03 19:51 ` [PATCH 1/5] hyperv: Move hv_connection_id to hyperv-tlfs.h Nuno Das Neves
2024-10-03 19:51 ` [PATCH 2/5] hyperv: Remove unnecessary #includes Nuno Das Neves
@ 2024-10-03 19:51 ` Nuno Das Neves
2024-10-10 18:21 ` Michael Kelley
2024-10-03 19:51 ` [PATCH 4/5] hyperv: Add hv_defs.h to conditionally include hyperv-tlfs.h or hvhdk.h Nuno Das Neves
` (4 subsequent siblings)
7 siblings, 1 reply; 27+ messages in thread
From: Nuno Das Neves @ 2024-10-03 19:51 UTC (permalink / raw)
To: linux-hyperv, linux-arm-kernel, linux-kernel, kvm, iommu, netdev,
linux-pci, linux-arch, virtualization
Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, luto, tglx,
mingo, bp, dave.hansen, x86, hpa, seanjc, pbonzini, peterz,
daniel.lezcano, joro, robin.murphy, davem, edumazet, kuba, pabeni,
lpieralisi, kw, robh, bhelgaas, arnd, sgarzare, jinankjain,
muminulrussell, skinsburskii, mukeshrathor
Add definitions needed for privileged Hyper-V partitions.
These files are derived from headers exported from the hypervisor code.
This is a step toward importing headers directly, similar to Xen public
files in include/xen/interface/.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
include/hyperv/hvgdk.h | 66 ++
include/hyperv/hvgdk_ext.h | 46 ++
include/hyperv/hvgdk_mini.h | 1212 +++++++++++++++++++++++++++++++++++
include/hyperv/hvhdk.h | 733 +++++++++++++++++++++
include/hyperv/hvhdk_mini.h | 310 +++++++++
5 files changed, 2367 insertions(+)
create mode 100644 include/hyperv/hvgdk.h
create mode 100644 include/hyperv/hvgdk_ext.h
create mode 100644 include/hyperv/hvgdk_mini.h
create mode 100644 include/hyperv/hvhdk.h
create mode 100644 include/hyperv/hvhdk_mini.h
diff --git a/include/hyperv/hvgdk.h b/include/hyperv/hvgdk.h
new file mode 100644
index 000000000000..af44e8034090
--- /dev/null
+++ b/include/hyperv/hvgdk.h
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Type definitions for the Microsoft Hypervisor.
+ */
+#ifndef _HV_HVGDK_H
+#define _HV_HVGDK_H
+
+#include "hvgdk_mini.h"
+#include "hvgdk_ext.h"
+
+/*
+ * The guest OS needs to register the guest ID with the hypervisor.
+ * The guest ID is a 64 bit entity and the structure of this ID is
+ * specified in the Hyper-V TLFS specification.
+ *
+ * While the current guideline does not specify how Linux guest ID(s)
+ * need to be generated, our plan is to publish the guidelines for
+ * Linux and other guest operating systems that currently are hosted
+ * on Hyper-V. The implementation here conforms to this yet
+ * unpublished guidelines.
+ *
+ * Bit(s)
+ * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
+ * 62:56 - Os Type; Linux is 0x100
+ * 55:48 - Distro specific identification
+ * 47:16 - Linux kernel version number
+ * 15:0 - Distro specific identification
+ */
+
+#define HV_LINUX_VENDOR_ID 0x8100
+
+/*
+ * Hyper-V uses the software reserved 32 bytes in VMCB control area to expose
+ * SVM enlightenments to guests. This is documented in the TLFS doc.
+ * HV_VMX_ENLIGHTENED_VMCS or SVM_NESTED_ENLIGHTENED_VMCB_FIELDS
+ */
+struct hv_vmcb_enlightenments {
+ struct __packed hv_enlightenments_control {
+ u32 nested_flush_hypercall : 1;
+ u32 msr_bitmap : 1;
+ u32 enlightened_npt_tlb: 1;
+ u32 reserved : 29;
+ } __packed hv_enlightenments_control;
+ u32 hv_vp_id;
+ u64 hv_vm_id;
+ u64 partition_assist_page;
+ u64 reserved;
+} __packed;
+
+/* 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 _HV_HVGDK_H */
diff --git a/include/hyperv/hvgdk_ext.h b/include/hyperv/hvgdk_ext.h
new file mode 100644
index 000000000000..641b591ee61f
--- /dev/null
+++ b/include/hyperv/hvgdk_ext.h
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Type definitions for the Microsoft Hypervisor.
+ */
+#ifndef _HV_HVGDK_EXT_H
+#define _HV_HVGDK_EXT_H
+
+#include "hvgdk_mini.h"
+
+/* Extended hypercalls */
+#define HV_EXT_CALL_QUERY_CAPABILITIES 0x8001
+#define HV_EXT_CALL_MEMORY_HEAT_HINT 0x8003
+
+/* Extended hypercalls */
+enum { /* HV_EXT_CALL */
+ HV_EXTCALL_QUERY_CAPABILITIES = 0x8001,
+ HV_EXTCALL_MEMORY_HEAT_HINT = 0x8003,
+};
+
+/* HV_EXT_OUTPUT_QUERY_CAPABILITIES */
+#define HV_EXT_CAPABILITY_MEMORY_COLD_DISCARD_HINT BIT(8)
+
+enum { /* HV_EXT_MEMORY_HEAT_HINT_TYPE */
+ HV_EXTMEM_HEAT_HINT_COLD = 0,
+ HV_EXTMEM_HEAT_HINT_HOT = 1,
+ HV_EXTMEM_HEAT_HINT_COLD_DISCARD = 2,
+ HV_EXTMEM_HEAT_HINT_MAX
+};
+
+/*
+ * The whole argument should fit in a page to be able to pass to the hypervisor
+ * in one hypercall.
+ */
+#define HV_MEMORY_HINT_MAX_GPA_PAGE_RANGES \
+ ((HV_HYP_PAGE_SIZE - sizeof(struct hv_memory_hint)) / \
+ sizeof(union hv_gpa_page_range))
+
+/* HvExtCallMemoryHeatHint hypercall */
+#define HV_EXT_MEMORY_HEAT_HINT_TYPE_COLD_DISCARD 2
+struct hv_memory_hint { /* HV_EXT_INPUT_MEMORY_HEAT_HINT */
+ u64 heat_type : 2; /* HV_EXTMEM_HEAT_HINT_* */
+ u64 reserved : 62;
+ union hv_gpa_page_range ranges[];
+} __packed;
+
+#endif /* _HV_HVGDK_EXT_H */
diff --git a/include/hyperv/hvgdk_mini.h b/include/hyperv/hvgdk_mini.h
new file mode 100644
index 000000000000..b7dd22784c96
--- /dev/null
+++ b/include/hyperv/hvgdk_mini.h
@@ -0,0 +1,1212 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Type definitions for the Microsoft hypervisor.
+ */
+#ifndef _HV_HVGDK_MINI_H
+#define _HV_HVGDK_MINI_H
+
+#include <linux/types.h>
+#include <linux/bits.h>
+
+struct hv_u128 {
+ u64 low_part;
+ u64 high_part;
+} __packed;
+
+/* NOTE: when adding below, update hv_status_to_string() */
+#define HV_STATUS_SUCCESS 0x0
+#define HV_STATUS_INVALID_HYPERCALL_CODE 0x2
+#define HV_STATUS_INVALID_HYPERCALL_INPUT 0x3
+#define HV_STATUS_INVALID_ALIGNMENT 0x4
+#define HV_STATUS_INVALID_PARAMETER 0x5
+#define HV_STATUS_ACCESS_DENIED 0x6
+#define HV_STATUS_INVALID_PARTITION_STATE 0x7
+#define HV_STATUS_OPERATION_DENIED 0x8
+#define HV_STATUS_UNKNOWN_PROPERTY 0x9
+#define HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE 0xA
+#define HV_STATUS_INSUFFICIENT_MEMORY 0xB
+#define HV_STATUS_INVALID_PARTITION_ID 0xD
+#define HV_STATUS_INVALID_VP_INDEX 0xE
+#define HV_STATUS_NOT_FOUND 0x10
+#define HV_STATUS_INVALID_PORT_ID 0x11
+#define HV_STATUS_INVALID_CONNECTION_ID 0x12
+#define HV_STATUS_INSUFFICIENT_BUFFERS 0x13
+#define HV_STATUS_NOT_ACKNOWLEDGED 0x14
+#define HV_STATUS_INVALID_VP_STATE 0x15
+#define HV_STATUS_NO_RESOURCES 0x1D
+#define HV_STATUS_PROCESSOR_FEATURE_NOT_SUPPORTED 0x20
+#define HV_STATUS_INVALID_LP_INDEX 0x41
+#define HV_STATUS_INVALID_REGISTER_VALUE 0x50
+#define HV_STATUS_OPERATION_FAILED 0x71
+#define HV_STATUS_TIME_OUT 0x78
+#define HV_STATUS_CALL_PENDING 0x79
+#define HV_STATUS_VTL_ALREADY_ENABLED 0x86
+
+/*
+ * The Hyper-V TimeRefCount register and the TSC
+ * page provide a guest VM clock with 100ns tick rate
+ */
+#define HV_CLOCK_HZ (NSEC_PER_SEC / 100)
+
+#define HV_HYP_PAGE_SHIFT 12
+#define HV_HYP_PAGE_SIZE BIT(HV_HYP_PAGE_SHIFT)
+#define HV_HYP_PAGE_MASK (~(HV_HYP_PAGE_SIZE - 1))
+
+#define HV_PARTITION_ID_INVALID ((u64)0)
+#define HV_PARTITION_ID_SELF ((u64)-1)
+
+/* Hyper-V specific model specific registers (MSRs) */
+
+#if defined(CONFIG_X86)
+/* HV_X64_SYNTHETIC_MSR */
+#define HV_X64_MSR_GUEST_OS_ID 0x40000000
+#define HV_X64_MSR_HYPERCALL 0x40000001
+#define HV_X64_MSR_VP_INDEX 0x40000002
+#define HV_X64_MSR_RESET 0x40000003
+#define HV_X64_MSR_VP_RUNTIME 0x40000010
+#define HV_X64_MSR_TIME_REF_COUNT 0x40000020
+#define HV_X64_MSR_REFERENCE_TSC 0x40000021
+#define HV_X64_MSR_TSC_FREQUENCY 0x40000022
+#define HV_X64_MSR_APIC_FREQUENCY 0x40000023
+
+/* Define the virtual APIC registers */
+#define HV_X64_MSR_EOI 0x40000070
+#define HV_X64_MSR_ICR 0x40000071
+#define HV_X64_MSR_TPR 0x40000072
+#define HV_X64_MSR_VP_ASSIST_PAGE 0x40000073
+
+/* Note: derived, not in hvgdk_mini.h */
+#define HV_X64_MSR_VP_ASSIST_PAGE_ENABLE 0x00000001
+#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT 12
+#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_MASK \
+ (~((1ull << HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT) - 1))
+
+/* Define synthetic interrupt controller model specific registers. */
+#define HV_X64_MSR_SCONTROL 0x40000080
+#define HV_X64_MSR_SVERSION 0x40000081
+#define HV_X64_MSR_SIEFP 0x40000082
+#define HV_X64_MSR_SIMP 0x40000083
+#define HV_X64_MSR_EOM 0x40000084
+#define HV_X64_MSR_SIRBP 0x40000085
+#define HV_X64_MSR_SINT0 0x40000090
+#define HV_X64_MSR_SINT1 0x40000091
+#define HV_X64_MSR_SINT2 0x40000092
+#define HV_X64_MSR_SINT3 0x40000093
+#define HV_X64_MSR_SINT4 0x40000094
+#define HV_X64_MSR_SINT5 0x40000095
+#define HV_X64_MSR_SINT6 0x40000096
+#define HV_X64_MSR_SINT7 0x40000097
+#define HV_X64_MSR_SINT8 0x40000098
+#define HV_X64_MSR_SINT9 0x40000099
+#define HV_X64_MSR_SINT10 0x4000009A
+#define HV_X64_MSR_SINT11 0x4000009B
+#define HV_X64_MSR_SINT12 0x4000009C
+#define HV_X64_MSR_SINT13 0x4000009D
+#define HV_X64_MSR_SINT14 0x4000009E
+#define HV_X64_MSR_SINT15 0x4000009F
+
+/* Define synthetic interrupt controller model specific registers for nested hypervisor */
+#define HV_X64_MSR_NESTED_SCONTROL 0x40001080
+#define HV_X64_MSR_NESTED_SVERSION 0x40001081
+#define HV_X64_MSR_NESTED_SIEFP 0x40001082
+#define HV_X64_MSR_NESTED_SIMP 0x40001083
+#define HV_X64_MSR_NESTED_EOM 0x40001084
+#define HV_X64_MSR_NESTED_SINT0 0x40001090
+
+/*
+ * Synthetic Timer MSRs. Four timers per vcpu.
+ */
+#define HV_X64_MSR_STIMER0_CONFIG 0x400000B0
+#define HV_X64_MSR_STIMER0_COUNT 0x400000B1
+#define HV_X64_MSR_STIMER1_CONFIG 0x400000B2
+#define HV_X64_MSR_STIMER1_COUNT 0x400000B3
+#define HV_X64_MSR_STIMER2_CONFIG 0x400000B4
+#define HV_X64_MSR_STIMER2_COUNT 0x400000B5
+#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6
+#define HV_X64_MSR_STIMER3_COUNT 0x400000B7
+
+/* Hyper-V guest idle MSR */
+#define HV_X64_MSR_GUEST_IDLE 0x400000F0
+
+/* Hyper-V guest crash notification MSR's */
+#define HV_X64_MSR_CRASH_P0 0x40000100
+#define HV_X64_MSR_CRASH_P1 0x40000101
+#define HV_X64_MSR_CRASH_P2 0x40000102
+#define HV_X64_MSR_CRASH_P3 0x40000103
+#define HV_X64_MSR_CRASH_P4 0x40000104
+#define HV_X64_MSR_CRASH_CTL 0x40000105
+
+/* NOTE: derived, not in hvgdk_mini.h */
+#define HV_X64_MSR_CRASH_PARAMS \
+ (1 + (HV_X64_MSR_CRASH_P4 - HV_X64_MSR_CRASH_P0))
+
+#define HV_IPI_LOW_VECTOR 0x10
+#define HV_IPI_HIGH_VECTOR 0xff
+
+struct hv_reenlightenment_control {
+ u64 vector : 8;
+ u64 reserved1 : 8;
+ u64 enabled : 1;
+ u64 reserved2 : 15;
+ u64 target_vp : 32;
+} __packed;
+
+struct hv_tsc_emulation_status { /* HV_TSC_EMULATION_STATUS */
+ u64 inprogress : 1;
+ u64 reserved : 63;
+} __packed;
+
+struct hv_tsc_emulation_control { /* HV_TSC_INVARIANT_CONTROL */
+ u64 enabled : 1;
+ u64 reserved : 63;
+} __packed;
+
+/* TSC emulation after migration */
+#define HV_X64_MSR_REENLIGHTENMENT_CONTROL 0x40000106
+#define HV_X64_MSR_TSC_EMULATION_CONTROL 0x40000107
+#define HV_X64_MSR_TSC_EMULATION_STATUS 0x40000108
+#define HV_X64_MSR_TSC_INVARIANT_CONTROL 0x40000118
+#define HV_EXPOSE_INVARIANT_TSC BIT_ULL(0)
+
+#endif /* CONFIG_X86 */
+
+struct hv_get_partition_id { /* HV_OUTPUT_GET_PARTITION_ID */
+ u64 partition_id;
+} __packed;
+
+/* HV_CRASH_CTL_REG_CONTENTS */
+#define HV_CRASH_CTL_CRASH_NOTIFY_MSG BIT_ULL(62)
+#define HV_CRASH_CTL_CRASH_NOTIFY BIT_ULL(63)
+
+union hv_reference_tsc_msr {
+ u64 as_uint64;
+ struct {
+ u64 enable : 1;
+ u64 reserved : 11;
+ u64 pfn : 52;
+ } __packed;
+};
+
+/* The maximum number of sparse vCPU banks which can be encoded by 'struct hv_vpset' */
+#define HV_MAX_SPARSE_VCPU_BANKS (64)
+/* The number of vCPUs in one sparse bank */
+#define HV_VCPUS_PER_SPARSE_BANK (64)
+
+/* Some of Hyper-V structs do not use hv_vpset where linux uses them */
+struct hv_vpset { /* HV_VP_SET */
+ u64 format;
+ u64 valid_bank_mask;
+ u64 bank_contents[];
+} __packed;
+
+/*
+ * Version info reported by hypervisor
+ * Changed to a union for convenience
+ */
+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;
+ };
+};
+
+/* HV_CPUID_FUNCTION */
+#define HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS 0x40000000
+#define HYPERV_CPUID_INTERFACE 0x40000001
+#define HYPERV_CPUID_VERSION 0x40000002
+#define HYPERV_CPUID_FEATURES 0x40000003
+#define HYPERV_CPUID_ENLIGHTMENT_INFO 0x40000004
+#define HYPERV_CPUID_IMPLEMENT_LIMITS 0x40000005
+#define HYPERV_CPUID_CPU_MANAGEMENT_FEATURES 0x40000007
+#define HYPERV_CPUID_NESTED_FEATURES 0x4000000A
+#define HYPERV_CPUID_ISOLATION_CONFIG 0x4000000C
+
+#define HYPERV_CPUID_VIRT_STACK_INTERFACE 0x40000081
+#define HYPERV_VS_INTERFACE_EAX_SIGNATURE 0x31235356 /* "VS#1" */
+
+#define HYPERV_CPUID_VIRT_STACK_PROPERTIES 0x40000082
+/* Support for the extended IOAPIC RTE format */
+#define HYPERV_VS_PROPERTIES_EAX_EXTENDED_IOAPIC_RTE BIT(2)
+
+#define HYPERV_HYPERVISOR_PRESENT_BIT 0x80000000
+#define HYPERV_CPUID_MIN 0x40000005
+#define HYPERV_CPUID_MAX 0x4000ffff
+
+/* HV_PARTITION_PRIVILEGE_MASK */
+#define HV_MSR_VP_RUNTIME_AVAILABLE BIT(0)
+#define HV_MSR_TIME_REF_COUNT_AVAILABLE BIT(1)
+#define HV_MSR_SYNIC_AVAILABLE BIT(2)
+#define HV_MSR_SYNTIMER_AVAILABLE BIT(3)
+#define HV_MSR_APIC_ACCESS_AVAILABLE BIT(4)
+#define HV_MSR_HYPERCALL_AVAILABLE BIT(5)
+#define HV_MSR_VP_INDEX_AVAILABLE BIT(6)
+#define HV_MSR_RESET_AVAILABLE BIT(7)
+#define HV_MSR_STAT_PAGES_AVAILABLE BIT(8)
+#define HV_MSR_REFERENCE_TSC_AVAILABLE BIT(9)
+#define HV_MSR_GUEST_IDLE_AVAILABLE BIT(10)
+#define HV_ACCESS_FREQUENCY_MSRS BIT(11)
+#define HV_ACCESS_REENLIGHTENMENT BIT(13)
+#define HV_ACCESS_TSC_INVARIANT BIT(15)
+
+/* HV_PARTITION_PRIVILEGE_MASK */
+#define HV_CREATE_PARTITIONS BIT(0)
+#define HV_ACCESS_PARTITION_ID BIT(1)
+#define HV_ACCESS_MEMORY_POOL BIT(2)
+#define HV_ADJUST_MESSAGE_BUFFERS BIT(3)
+#define HV_POST_MESSAGES BIT(4)
+#define HV_SIGNAL_EVENTS BIT(5)
+#define HV_CREATE_PORT BIT(6)
+#define HV_CONNECT_PORT BIT(7)
+#define HV_ACCESS_STATS BIT(8)
+#define HV_DEBUGGING BIT(11)
+#define HV_CPU_MANAGEMENT BIT(12)
+#define HV_ENABLE_EXTENDED_HYPERCALLS BIT(20)
+#define HV_ISOLATION BIT(22)
+
+#if defined(CONFIG_X86)
+/* HV_X64_HYPERVISOR_FEATURES (EDX) */
+#define HV_X64_MWAIT_AVAILABLE BIT(0)
+#define HV_X64_GUEST_DEBUGGING_AVAILABLE BIT(1)
+#define HV_X64_PERF_MONITOR_AVAILABLE BIT(2)
+#define HV_X64_CPU_DYNAMIC_PARTITIONING_AVAILABLE BIT(3)
+#define HV_X64_HYPERCALL_XMM_INPUT_AVAILABLE BIT(4)
+#define HV_X64_GUEST_IDLE_STATE_AVAILABLE BIT(5)
+#define HV_FEATURE_FREQUENCY_MSRS_AVAILABLE BIT(8)
+#define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE BIT(10)
+#define HV_FEATURE_DEBUG_MSRS_AVAILABLE BIT(11)
+/*
+ * Support for returning hypercall output block via XMM
+ * registers is available
+ */
+#define HV_X64_HYPERCALL_XMM_OUTPUT_AVAILABLE BIT(15)
+/* stimer Direct Mode is available */
+#define HV_STIMER_DIRECT_MODE_AVAILABLE BIT(19)
+
+/* HV_X64_ENLIGHTENMENT_INFORMATION */
+#define HV_X64_AS_SWITCH_RECOMMENDED BIT(0)
+#define HV_X64_LOCAL_TLB_FLUSH_RECOMMENDED BIT(1)
+#define HV_X64_REMOTE_TLB_FLUSH_RECOMMENDED BIT(2)
+#define HV_X64_APIC_ACCESS_RECOMMENDED BIT(3)
+#define HV_X64_SYSTEM_RESET_RECOMMENDED BIT(4)
+#define HV_X64_RELAXED_TIMING_RECOMMENDED BIT(5)
+#define HV_DEPRECATING_AEOI_RECOMMENDED BIT(9)
+#define HV_X64_CLUSTER_IPI_RECOMMENDED BIT(10)
+#define HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED BIT(11)
+#define HV_X64_HYPERV_NESTED BIT(12)
+#define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED BIT(14)
+#define HV_X64_USE_MMIO_HYPERCALLS BIT(21)
+
+/* HYPERV_CPUID_ISOLATION_CONFIG.EBX bits. */
+#define HV_ISOLATION_TYPE GENMASK(3, 0)
+#define HV_SHARED_GPA_BOUNDARY_ACTIVE BIT(5)
+#define HV_SHARED_GPA_BOUNDARY_BITS GENMASK(11, 6)
+
+/* HYPERV_CPUID_FEATURES.ECX bits. */
+#define HV_VP_DISPATCH_INTERRUPT_INJECTION_AVAILABLE BIT(9)
+#define HV_VP_GHCB_ROOT_MAPPING_AVAILABLE BIT(10)
+
+enum hv_isolation_type {
+ HV_ISOLATION_TYPE_NONE = 0, /* HV_PARTITION_ISOLATION_TYPE_NONE */
+ HV_ISOLATION_TYPE_VBS = 1,
+ HV_ISOLATION_TYPE_SNP = 2,
+ HV_ISOLATION_TYPE_TDX = 3
+};
+
+union hv_x64_msr_hypercall_contents {
+ u64 as_uint64;
+ struct {
+ u64 enable : 1;
+ u64 reserved : 11;
+ u64 guest_physical_address : 52;
+ } __packed;
+};
+#endif /* CONFIG_X86 */
+
+#if defined(CONFIG_ARM64)
+#define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE BIT(8)
+#define HV_STIMER_DIRECT_MODE_AVAILABLE BIT(13)
+#endif /* CONFIG_ARM64 */
+
+#if defined(CONFIG_X86)
+#define HV_MAXIMUM_PROCESSORS 2048
+#elif defined(CONFIG_ARM64) /* CONFIG_X86 */
+#define HV_MAXIMUM_PROCESSORS 320
+#endif /* CONFIG_ARM64 */
+
+#define HV_MAX_VP_INDEX (HV_MAXIMUM_PROCESSORS - 1)
+#define HV_VP_INDEX_SELF ((u32)-2)
+#define HV_ANY_VP ((u32)-1)
+
+union hv_vp_assist_msr_contents { /* HV_REGISTER_VP_ASSIST_PAGE */
+ u64 as_uint64;
+ struct {
+ u64 enable : 1;
+ u64 reserved : 11;
+ u64 pfn : 52;
+ } __packed;
+};
+
+/* Declare the various hypercall operations. */
+/* HV_CALL_CODE */
+#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE 0x0002
+#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST 0x0003
+#define HVCALL_NOTIFY_LONG_SPIN_WAIT 0x0008
+#define HVCALL_SEND_IPI 0x000b
+#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013
+#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX 0x0014
+#define HVCALL_SEND_IPI_EX 0x0015
+#define HVCALL_CREATE_PARTITION 0x0040
+#define HVCALL_INITIALIZE_PARTITION 0x0041
+#define HVCALL_FINALIZE_PARTITION 0x0042
+#define HVCALL_DELETE_PARTITION 0x0043
+#define HVCALL_GET_PARTITION_PROPERTY 0x0044
+#define HVCALL_SET_PARTITION_PROPERTY 0x0045
+#define HVCALL_GET_PARTITION_ID 0x0046
+#define HVCALL_DEPOSIT_MEMORY 0x0048
+#define HVCALL_WITHDRAW_MEMORY 0x0049
+#define HVCALL_MAP_GPA_PAGES 0x004b
+#define HVCALL_UNMAP_GPA_PAGES 0x004c
+#define HVCALL_CREATE_VP 0x004e
+#define HVCALL_DELETE_VP 0x004f
+#define HVCALL_GET_VP_REGISTERS 0x0050
+#define HVCALL_SET_VP_REGISTERS 0x0051
+#define HVCALL_DELETE_PORT 0x0058
+#define HVCALL_DISCONNECT_PORT 0x005b
+#define HVCALL_POST_MESSAGE 0x005c
+#define HVCALL_SIGNAL_EVENT 0x005d
+#define HVCALL_POST_DEBUG_DATA 0x0069
+#define HVCALL_RETRIEVE_DEBUG_DATA 0x006a
+#define HVCALL_RESET_DEBUG_SESSION 0x006b
+#define HVCALL_ADD_LOGICAL_PROCESSOR 0x0076
+#define HVCALL_GET_SYSTEM_PROPERTY 0x007b
+#define HVCALL_MAP_DEVICE_INTERRUPT 0x007c
+#define HVCALL_UNMAP_DEVICE_INTERRUPT 0x007d
+#define HVCALL_RETARGET_INTERRUPT 0x007e
+#define HVCALL_NOTIFY_PORT_RING_EMPTY 0x008b
+#define HVCALL_ASSERT_VIRTUAL_INTERRUPT 0x0094
+#define HVCALL_CREATE_PORT 0x0095
+#define HVCALL_CONNECT_PORT 0x0096
+#define HVCALL_START_VP 0x0099
+#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af
+#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0
+#define HVCALL_DISPATCH_VP 0x00c2
+#define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db
+#define HVCALL_MAP_VP_STATE_PAGE 0x00e1
+#define HVCALL_UNMAP_VP_STATE_PAGE 0x00e2
+#define HVCALL_GET_VP_STATE 0x00e3
+#define HVCALL_SET_VP_STATE 0x00e4
+#define HVCALL_MMIO_READ 0x0106
+#define HVCALL_MMIO_WRITE 0x0107
+
+/* HV_HYPERCALL_INPUT */
+#define HV_HYPERCALL_RESULT_MASK GENMASK_ULL(15, 0)
+#define HV_HYPERCALL_FAST_BIT BIT(16)
+#define HV_HYPERCALL_VARHEAD_OFFSET 17
+#define HV_HYPERCALL_NESTED BIT(31)
+#define HV_HYPERCALL_REP_COMP_OFFSET 32
+#define HV_HYPERCALL_REP_COMP_1 BIT_ULL(32)
+#define HV_HYPERCALL_REP_COMP_MASK GENMASK_ULL(43, 32)
+#define HV_HYPERCALL_REP_START_OFFSET 48
+#define HV_HYPERCALL_REP_START_MASK GENMASK_ULL(59, 48)
+
+/* HvFlushGuestPhysicalAddressSpace hypercalls */
+struct hv_guest_mapping_flush {
+ u64 address_space;
+ u64 flags;
+} __packed;
+
+/*
+ * HV_MAX_FLUSH_PAGES = "additional_pages" + 1. It's limited
+ * by the bitwidth of "additional_pages" in union hv_gpa_page_range.
+ */
+#define HV_MAX_FLUSH_PAGES (2048)
+#define HV_GPA_PAGE_RANGE_PAGE_SIZE_2MB 0
+#define HV_GPA_PAGE_RANGE_PAGE_SIZE_1GB 1
+
+#define HV_FLUSH_ALL_PROCESSORS BIT(0)
+#define HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES BIT(1)
+#define HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY BIT(2)
+#define HV_FLUSH_USE_EXTENDED_RANGE_FORMAT BIT(3)
+
+/* HvFlushGuestPhysicalAddressList, HvExtCallMemoryHeatHint hypercall */
+union hv_gpa_page_range {
+ u64 address_space;
+ struct {
+ u64 additional_pages : 11;
+ u64 largepage : 1;
+ u64 basepfn : 52;
+ } page;
+ struct {
+ u64 reserved : 12;
+ u64 page_size : 1;
+ u64 reserved1 : 8;
+ u64 base_large_pfn : 43;
+ };
+};
+
+/*
+ * All input flush parameters should be in single page. The max flush
+ * count is equal with how many entries of union hv_gpa_page_range can
+ * be populated into the input parameter page.
+ */
+#define HV_MAX_FLUSH_REP_COUNT ((HV_HYP_PAGE_SIZE - 2 * sizeof(u64)) / \
+ sizeof(union hv_gpa_page_range))
+
+struct hv_guest_mapping_flush_list {
+ u64 address_space;
+ u64 flags;
+ union hv_gpa_page_range gpa_list[HV_MAX_FLUSH_REP_COUNT];
+};
+
+struct hv_tlb_flush { /* HV_INPUT_FLUSH_VIRTUAL_ADDRESS_LIST */
+ u64 address_space;
+ u64 flags;
+ u64 processor_mask;
+ u64 gva_list[];
+} __packed;
+
+/* HvFlushVirtualAddressSpaceEx, HvFlushVirtualAddressListEx hypercalls */
+struct hv_tlb_flush_ex {
+ u64 address_space;
+ u64 flags;
+ struct hv_vpset hv_vp_set;
+ u64 gva_list[];
+} __packed;
+
+struct ms_hyperv_tsc_page { /* HV_REFERENCE_TSC_PAGE */
+ volatile u32 tsc_sequence;
+ u32 reserved1;
+ volatile u64 tsc_scale;
+ volatile s64 tsc_offset;
+} __packed;
+
+/* Define the number of synthetic interrupt sources. */
+#define HV_SYNIC_SINT_COUNT (16)
+
+/* Hyper-V defined statically assigned SINTs */
+#define HV_SYNIC_INTERCEPTION_SINT_INDEX 0x00000000
+#define HV_SYNIC_IOMMU_FAULT_SINT_INDEX 0x00000001
+#define HV_SYNIC_VMBUS_SINT_INDEX 0x00000002
+#define HV_SYNIC_FIRST_UNUSED_SINT_INDEX 0x00000005
+
+/* mshv assigned SINT for doorbell */
+#define HV_SYNIC_DOORBELL_SINT_INDEX HV_SYNIC_FIRST_UNUSED_SINT_INDEX
+
+enum hv_interrupt_type {
+ HV_X64_INTERRUPT_TYPE_FIXED = 0x0000,
+ HV_X64_INTERRUPT_TYPE_LOWESTPRIORITY = 0x0001,
+ HV_X64_INTERRUPT_TYPE_SMI = 0x0002,
+ HV_X64_INTERRUPT_TYPE_REMOTEREAD = 0x0003,
+ HV_X64_INTERRUPT_TYPE_NMI = 0x0004,
+ HV_X64_INTERRUPT_TYPE_INIT = 0x0005,
+ HV_X64_INTERRUPT_TYPE_SIPI = 0x0006,
+ HV_X64_INTERRUPT_TYPE_EXTINT = 0x0007,
+ HV_X64_INTERRUPT_TYPE_LOCALINT0 = 0x0008,
+ HV_X64_INTERRUPT_TYPE_LOCALINT1 = 0x0009,
+ HV_X64_INTERRUPT_TYPE_MAXIMUM = 0x000A,
+};
+
+/* Define synthetic interrupt source. */
+union hv_synic_sint {
+ u64 as_uint64;
+ struct {
+ u64 vector : 8;
+ u64 reserved1 : 8;
+ u64 masked : 1;
+ u64 auto_eoi : 1;
+ u64 polling : 1;
+ u64 as_intercept : 1;
+ u64 proxy : 1;
+ u64 reserved2 : 43;
+ } __packed;
+};
+
+union hv_x64_xsave_xfem_register {
+ u64 as_uint64;
+ struct {
+ u32 low_uint32;
+ u32 high_uint32;
+ } __packed;
+ struct {
+ u64 legacy_x87 : 1;
+ u64 legacy_sse : 1;
+ u64 avx : 1;
+ u64 mpx_bndreg : 1;
+ u64 mpx_bndcsr : 1;
+ u64 avx_512_op_mask : 1;
+ u64 avx_512_zmmhi : 1;
+ u64 avx_512_zmm16_31 : 1;
+ u64 rsvd8_9 : 2;
+ u64 pasid : 1;
+ u64 cet_u : 1;
+ u64 cet_s : 1;
+ u64 rsvd13_16 : 4;
+ u64 xtile_cfg : 1;
+ u64 xtile_data : 1;
+ u64 rsvd19_63 : 45;
+ } __packed;
+};
+
+/* Synthetic timer configuration */
+union hv_stimer_config { /* HV_X64_MSR_STIMER_CONFIG_CONTENTS */
+ u64 as_uint64;
+ struct {
+ u64 enable : 1;
+ u64 periodic : 1;
+ u64 lazy : 1;
+ u64 auto_enable : 1;
+ u64 apic_vector : 8;
+ u64 direct_mode : 1;
+ u64 reserved_z0 : 3;
+ u64 sintx : 4;
+ u64 reserved_z1 : 44;
+ } __packed;
+};
+
+/* Define the number of synthetic timers */
+#define HV_SYNIC_STIMER_COUNT (4)
+
+/* Define port identifier type. */
+union hv_port_id {
+ u32 asu32;
+ struct {
+ u32 id : 24;
+ u32 reserved : 8;
+ } __packed u;
+};
+
+#define HV_MESSAGE_SIZE (256)
+#define HV_MESSAGE_PAYLOAD_BYTE_COUNT (240)
+#define HV_MESSAGE_PAYLOAD_QWORD_COUNT (30)
+
+/* Define hypervisor message types. */
+enum hv_message_type {
+ HVMSG_NONE = 0x00000000,
+
+ /* Memory access messages. */
+ HVMSG_UNMAPPED_GPA = 0x80000000,
+ HVMSG_GPA_INTERCEPT = 0x80000001,
+
+ /* Timer notification messages. */
+ HVMSG_TIMER_EXPIRED = 0x80000010,
+
+ /* Error messages. */
+ HVMSG_INVALID_VP_REGISTER_VALUE = 0x80000020,
+ HVMSG_UNRECOVERABLE_EXCEPTION = 0x80000021,
+ HVMSG_UNSUPPORTED_FEATURE = 0x80000022,
+
+ /*
+ * Opaque intercept message. The original intercept message is only
+ * accessible from the mapped intercept message page.
+ */
+ HVMSG_OPAQUE_INTERCEPT = 0x8000003F,
+
+ /* Trace buffer complete messages. */
+ HVMSG_EVENTLOG_BUFFERCOMPLETE = 0x80000040,
+
+ /* Hypercall intercept */
+ HVMSG_HYPERCALL_INTERCEPT = 0x80000050,
+
+ /* SynIC intercepts */
+ HVMSG_SYNIC_EVENT_INTERCEPT = 0x80000060,
+ HVMSG_SYNIC_SINT_INTERCEPT = 0x80000061,
+ HVMSG_SYNIC_SINT_DELIVERABLE = 0x80000062,
+
+ /* Async call completion intercept */
+ HVMSG_ASYNC_CALL_COMPLETION = 0x80000070,
+
+ /* Root scheduler messages */
+ HVMSG_SCHEDULER_VP_SIGNAL_BITSET = 0x80000100,
+ HVMSG_SCHEDULER_VP_SIGNAL_PAIR = 0x80000101,
+
+ /* Platform-specific processor intercept messages. */
+ HVMSG_X64_IO_PORT_INTERCEPT = 0x80010000,
+ HVMSG_X64_MSR_INTERCEPT = 0x80010001,
+ HVMSG_X64_CPUID_INTERCEPT = 0x80010002,
+ HVMSG_X64_EXCEPTION_INTERCEPT = 0x80010003,
+ HVMSG_X64_APIC_EOI = 0x80010004,
+ HVMSG_X64_LEGACY_FP_ERROR = 0x80010005,
+ HVMSG_X64_IOMMU_PRQ = 0x80010006,
+ HVMSG_X64_HALT = 0x80010007,
+ HVMSG_X64_INTERRUPTION_DELIVERABLE = 0x80010008,
+ HVMSG_X64_SIPI_INTERCEPT = 0x80010009,
+};
+
+/* Define the format of the SIMP register */
+union hv_synic_simp {
+ u64 as_uint64;
+ struct {
+ u64 simp_enabled : 1;
+ u64 preserved : 11;
+ u64 base_simp_gpa : 52;
+ } __packed;
+};
+
+union hv_message_flags {
+ u8 asu8;
+ struct {
+ u8 msg_pending : 1;
+ u8 reserved : 7;
+ } __packed;
+};
+
+struct hv_message_header {
+ u32 message_type;
+ u8 payload_size;
+ union hv_message_flags message_flags;
+ u8 reserved[2];
+ union {
+ u64 sender;
+ union hv_port_id port;
+ };
+} __packed;
+
+/*
+ * Message format for notifications delivered via
+ * intercept message(as_intercept=1)
+ */
+struct hv_notification_message_payload {
+ u32 sint_index;
+} __packed;
+
+struct hv_message {
+ struct hv_message_header header;
+ union {
+ u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
+ } u;
+} __packed;
+
+/* Define the synthetic interrupt message page layout. */
+struct hv_message_page {
+ struct hv_message sint_message[HV_SYNIC_SINT_COUNT];
+} __packed;
+
+struct hv_x64_segment_register {
+ u64 base;
+ u32 limit;
+ u16 selector;
+ union {
+ struct {
+ u16 segment_type : 4;
+ u16 non_system_segment : 1;
+ u16 descriptor_privilege_level : 2;
+ u16 present : 1;
+ u16 reserved : 4;
+ u16 available : 1;
+ u16 _long : 1;
+ u16 _default : 1;
+ u16 granularity : 1;
+ } __packed;
+ u16 attributes;
+ };
+} __packed;
+
+struct hv_x64_table_register {
+ u16 pad[3];
+ u16 limit;
+ u64 base;
+} __packed;
+
+union hv_input_vtl {
+ u8 as_uint8;
+ struct {
+ u8 target_vtl : 4;
+ u8 use_target_vtl : 1;
+ u8 reserved_z : 3;
+ };
+} __packed;
+
+struct hv_init_vp_context {
+ u64 rip;
+ u64 rsp;
+ u64 rflags;
+
+ struct hv_x64_segment_register cs;
+ struct hv_x64_segment_register ds;
+ struct hv_x64_segment_register es;
+ struct hv_x64_segment_register fs;
+ struct hv_x64_segment_register gs;
+ struct hv_x64_segment_register ss;
+ struct hv_x64_segment_register tr;
+ struct hv_x64_segment_register ldtr;
+
+ struct hv_x64_table_register idtr;
+ struct hv_x64_table_register gdtr;
+
+ u64 efer;
+ u64 cr0;
+ u64 cr3;
+ u64 cr4;
+ u64 msr_cr_pat;
+} __packed;
+
+struct hv_enable_vp_vtl {
+ u64 partition_id;
+ u32 vp_index;
+ union hv_input_vtl target_vtl;
+ u8 mbz0;
+ u16 mbz1;
+ struct hv_init_vp_context vp_context;
+} __packed;
+
+struct hv_nested_enlightenments_control {
+ struct {
+ u32 directhypercall : 1;
+ u32 reserved : 31;
+ } __packed features;
+ struct {
+ u32 inter_partition_comm : 1;
+ u32 reserved : 31;
+ } __packed hypercall_controls;
+} __packed;
+
+/* Define virtual processor assist page structure. */
+struct hv_vp_assist_page {
+ u32 apic_assist;
+ u32 reserved1;
+ u32 vtl_entry_reason;
+ u32 vtl_reserved;
+ u64 vtl_ret_x64rax;
+ u64 vtl_ret_x64rcx;
+ struct hv_nested_enlightenments_control nested_control;
+ u8 enlighten_vmentry;
+ u8 reserved2[7];
+ u64 current_nested_vmcs;
+ u8 synthetic_time_unhalted_timer_expired;
+ u8 reserved3[7];
+ u8 virtualization_fault_information[40];
+ u8 reserved4[8];
+ u8 intercept_message[256];
+ u8 vtl_ret_actions[256];
+} __packed;
+
+enum hv_register_name {
+ /* Suspend Registers */
+ HV_REGISTER_EXPLICIT_SUSPEND = 0x00000000,
+ HV_REGISTER_INTERCEPT_SUSPEND = 0x00000001,
+ HV_REGISTER_DISPATCH_SUSPEND = 0x00000003,
+
+ /* Version - 128-bit result same as CPUID 0x40000002 */
+ HV_REGISTER_HYPERVISOR_VERSION = 0x00000100,
+
+ /* Feature Access (registers are 128 bits) - same as CPUID 0x40000003 - 0x4000000B */
+ HV_REGISTER_PRIVILEGES_AND_FEATURES_INFO = 0x00000200,
+ HV_REGISTER_FEATURES_INFO = 0x00000201,
+ HV_REGISTER_IMPLEMENTATION_LIMITS_INFO = 0x00000202,
+ HV_REGISTER_HARDWARE_FEATURES_INFO = 0x00000203,
+ HV_REGISTER_CPU_MANAGEMENT_FEATURES_INFO = 0x00000204,
+ HV_REGISTER_SVM_FEATURES_INFO = 0x00000205,
+ HV_REGISTER_SKIP_LEVEL_FEATURES_INFO = 0x00000206,
+ HV_REGISTER_NESTED_VIRT_FEATURES_INFO = 0x00000207,
+ HV_REGISTER_IPT_FEATURES_INFO = 0x00000208,
+
+ /* Guest Crash Registers */
+ HV_REGISTER_GUEST_CRASH_P0 = 0x00000210,
+ HV_REGISTER_GUEST_CRASH_P1 = 0x00000211,
+ HV_REGISTER_GUEST_CRASH_P2 = 0x00000212,
+ HV_REGISTER_GUEST_CRASH_P3 = 0x00000213,
+ HV_REGISTER_GUEST_CRASH_P4 = 0x00000214,
+ HV_REGISTER_GUEST_CRASH_CTL = 0x00000215,
+
+ /* Misc */
+ HV_REGISTER_VP_RUNTIME = 0x00090000,
+ HV_REGISTER_GUEST_OS_ID = 0x00090002,
+ HV_REGISTER_VP_INDEX = 0x00090003,
+ HV_REGISTER_TIME_REF_COUNT = 0x00090004,
+ HV_REGISTER_CPU_MANAGEMENT_VERSION = 0x00090007,
+ HV_REGISTER_VP_ASSIST_PAGE = 0x00090013,
+ HV_REGISTER_VP_ROOT_SIGNAL_COUNT = 0x00090014,
+ HV_REGISTER_REFERENCE_TSC = 0x00090017,
+
+ /* Hypervisor-defined Registers (Synic) */
+ HV_REGISTER_SINT0 = 0x000A0000,
+ HV_REGISTER_SINT1 = 0x000A0001,
+ HV_REGISTER_SINT2 = 0x000A0002,
+ HV_REGISTER_SINT3 = 0x000A0003,
+ HV_REGISTER_SINT4 = 0x000A0004,
+ HV_REGISTER_SINT5 = 0x000A0005,
+ HV_REGISTER_SINT6 = 0x000A0006,
+ HV_REGISTER_SINT7 = 0x000A0007,
+ HV_REGISTER_SINT8 = 0x000A0008,
+ HV_REGISTER_SINT9 = 0x000A0009,
+ HV_REGISTER_SINT10 = 0x000A000A,
+ HV_REGISTER_SINT11 = 0x000A000B,
+ HV_REGISTER_SINT12 = 0x000A000C,
+ HV_REGISTER_SINT13 = 0x000A000D,
+ HV_REGISTER_SINT14 = 0x000A000E,
+ HV_REGISTER_SINT15 = 0x000A000F,
+ HV_REGISTER_SCONTROL = 0x000A0010,
+ HV_REGISTER_SVERSION = 0x000A0011,
+ HV_REGISTER_SIEFP = 0x000A0012,
+ HV_REGISTER_SIMP = 0x000A0013,
+ HV_REGISTER_EOM = 0x000A0014,
+ HV_REGISTER_SIRBP = 0x000A0015,
+
+ HV_REGISTER_NESTED_SINT0 = 0x000A1000,
+ HV_REGISTER_NESTED_SINT1 = 0x000A1001,
+ HV_REGISTER_NESTED_SINT2 = 0x000A1002,
+ HV_REGISTER_NESTED_SINT3 = 0x000A1003,
+ HV_REGISTER_NESTED_SINT4 = 0x000A1004,
+ HV_REGISTER_NESTED_SINT5 = 0x000A1005,
+ HV_REGISTER_NESTED_SINT6 = 0x000A1006,
+ HV_REGISTER_NESTED_SINT7 = 0x000A1007,
+ HV_REGISTER_NESTED_SINT8 = 0x000A1008,
+ HV_REGISTER_NESTED_SINT9 = 0x000A1009,
+ HV_REGISTER_NESTED_SINT10 = 0x000A100A,
+ HV_REGISTER_NESTED_SINT11 = 0x000A100B,
+ HV_REGISTER_NESTED_SINT12 = 0x000A100C,
+ HV_REGISTER_NESTED_SINT13 = 0x000A100D,
+ HV_REGISTER_NESTED_SINT14 = 0x000A100E,
+ HV_REGISTER_NESTED_SINT15 = 0x000A100F,
+ HV_REGISTER_NESTED_SCONTROL = 0x000A1010,
+ HV_REGISTER_NESTED_SVERSION = 0x000A1011,
+ HV_REGISTER_NESTED_SIFP = 0x000A1012,
+ HV_REGISTER_NESTED_SIPP = 0x000A1013,
+ HV_REGISTER_NESTED_EOM = 0x000A1014,
+ HV_REGISTER_NESTED_SIRBP = 0x000a1015,
+
+ /* Hypervisor-defined Registers (Synthetic Timers) */
+ HV_REGISTER_STIMER0_CONFIG = 0x000B0000,
+ HV_REGISTER_STIMER0_COUNT = 0x000B0001,
+
+ /* VSM */
+ HV_X64_REGISTER_VSM_VP_STATUS = 0x000D0003,
+};
+
+/*
+ * Arch compatibility regs for use with hv_set/get_register
+ */
+#if defined(CONFIG_X86)
+
+/*
+ * To support arch-generic 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_CRASH_P0 (HV_X64_MSR_CRASH_P0)
+#define HV_MSR_CRASH_P1 (HV_X64_MSR_CRASH_P1)
+#define HV_MSR_CRASH_P2 (HV_X64_MSR_CRASH_P2)
+#define HV_MSR_CRASH_P3 (HV_X64_MSR_CRASH_P3)
+#define HV_MSR_CRASH_P4 (HV_X64_MSR_CRASH_P4)
+#define HV_MSR_CRASH_CTL (HV_X64_MSR_CRASH_CTL)
+
+#define HV_MSR_VP_INDEX (HV_X64_MSR_VP_INDEX)
+#define HV_MSR_TIME_REF_COUNT (HV_X64_MSR_TIME_REF_COUNT)
+#define HV_MSR_REFERENCE_TSC (HV_X64_MSR_REFERENCE_TSC)
+
+#define HV_MSR_SINT0 (HV_X64_MSR_SINT0)
+#define HV_MSR_SVERSION (HV_X64_MSR_SVERSION)
+#define HV_MSR_SCONTROL (HV_X64_MSR_SCONTROL)
+#define HV_MSR_SIEFP (HV_X64_MSR_SIEFP)
+#define HV_MSR_SIMP (HV_X64_MSR_SIMP)
+#define HV_MSR_EOM (HV_X64_MSR_EOM)
+#define HV_MSR_SIRBP (HV_X64_MSR_SIRBP)
+
+#define HV_MSR_NESTED_SCONTROL (HV_X64_MSR_NESTED_SCONTROL)
+#define HV_MSR_NESTED_SVERSION (HV_X64_MSR_NESTED_SVERSION)
+#define HV_MSR_NESTED_SIEFP (HV_X64_MSR_NESTED_SIEFP)
+#define HV_MSR_NESTED_SIMP (HV_X64_MSR_NESTED_SIMP)
+#define HV_MSR_NESTED_EOM (HV_X64_MSR_NESTED_EOM)
+#define HV_MSR_NESTED_SINT0 (HV_X64_MSR_NESTED_SINT0)
+
+#define HV_MSR_STIMER0_CONFIG (HV_X64_MSR_STIMER0_CONFIG)
+#define HV_MSR_STIMER0_COUNT (HV_X64_MSR_STIMER0_COUNT)
+
+#elif defined(CONFIG_ARM64) /* CONFIG_X86 */
+
+#define HV_MSR_CRASH_P0 (HV_REGISTER_GUEST_CRASH_P0)
+#define HV_MSR_CRASH_P1 (HV_REGISTER_GUEST_CRASH_P1)
+#define HV_MSR_CRASH_P2 (HV_REGISTER_GUEST_CRASH_P2)
+#define HV_MSR_CRASH_P3 (HV_REGISTER_GUEST_CRASH_P3)
+#define HV_MSR_CRASH_P4 (HV_REGISTER_GUEST_CRASH_P4)
+#define HV_MSR_CRASH_CTL (HV_REGISTER_GUEST_CRASH_CTL)
+
+#define HV_MSR_VP_INDEX (HV_REGISTER_VP_INDEX)
+#define HV_MSR_TIME_REF_COUNT (HV_REGISTER_TIME_REF_COUNT)
+#define HV_MSR_REFERENCE_TSC (HV_REGISTER_REFERENCE_TSC)
+
+#define HV_MSR_SINT0 (HV_REGISTER_SINT0)
+#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_SIRBP (HV_REGISTER_SIRBP)
+
+#define HV_MSR_STIMER0_CONFIG (HV_REGISTER_STIMER0_CONFIG)
+#define HV_MSR_STIMER0_COUNT (HV_REGISTER_STIMER0_COUNT)
+
+#endif /* CONFIG_ARM64 */
+
+union hv_explicit_suspend_register {
+ u64 as_uint64;
+ struct {
+ u64 suspended : 1;
+ u64 reserved : 63;
+ } __packed;
+};
+
+union hv_intercept_suspend_register {
+ u64 as_uint64;
+ struct {
+ u64 suspended : 1;
+ u64 reserved : 63;
+ } __packed;
+};
+
+union hv_dispatch_suspend_register {
+ u64 as_uint64;
+ struct {
+ u64 suspended : 1;
+ u64 reserved : 63;
+ } __packed;
+};
+
+union hv_x64_interrupt_state_register {
+ u64 as_uint64;
+ struct {
+ u64 interrupt_shadow : 1;
+ u64 nmi_masked : 1;
+ u64 reserved : 62;
+ } __packed;
+};
+
+union hv_x64_pending_interruption_register {
+ u64 as_uint64;
+ struct {
+ u32 interruption_pending : 1;
+ u32 interruption_type : 3;
+ u32 deliver_error_code : 1;
+ u32 instruction_length : 4;
+ u32 nested_event : 1;
+ u32 reserved : 6;
+ u32 interruption_vector : 16;
+ u32 error_code;
+ } __packed;
+};
+
+union hv_register_value {
+ struct hv_u128 reg128;
+ u64 reg64;
+ u32 reg32;
+ u16 reg16;
+ u8 reg8;
+
+ struct hv_x64_segment_register segment;
+ struct hv_x64_table_register table;
+ union hv_explicit_suspend_register explicit_suspend;
+ union hv_intercept_suspend_register intercept_suspend;
+ union hv_dispatch_suspend_register dispatch_suspend;
+ union hv_x64_interrupt_state_register interrupt_state;
+ union hv_x64_pending_interruption_register pending_interruption;
+};
+
+#if defined(CONFIG_ARM64)
+/* HvGetVpRegisters returns an array of these output elements */
+struct hv_get_vp_registers_output {
+ union {
+ struct {
+ u32 a;
+ u32 b;
+ u32 c;
+ u32 d;
+ } as32 __packed;
+ struct {
+ u64 low;
+ u64 high;
+ } as64 __packed;
+ };
+};
+
+#endif /* CONFIG_ARM64 */
+
+struct hv_register_assoc {
+ u32 name; /* enum hv_register_name */
+ u32 reserved1;
+ u64 reserved2;
+ union hv_register_value value;
+} __packed;
+
+struct hv_input_get_vp_registers {
+ u64 partition_id;
+ u32 vp_index;
+ union hv_input_vtl input_vtl;
+ u8 rsvd_z8;
+ u16 rsvd_z16;
+ u32 names[];
+} __packed;
+
+struct hv_input_set_vp_registers {
+ u64 partition_id;
+ u32 vp_index;
+ union hv_input_vtl input_vtl;
+ u8 rsvd_z8;
+ u16 rsvd_z16;
+ struct hv_register_assoc elements[];
+} __packed;
+
+#define HV_UNMAP_GPA_LARGE_PAGE 0x2
+
+/* HvCallSendSyntheticClusterIpi hypercall */
+struct hv_send_ipi { /* HV_INPUT_SEND_SYNTHETIC_CLUSTER_IPI */
+ u32 vector;
+ u32 reserved;
+ u64 cpu_mask;
+} __packed;
+
+#define HV_X64_VTL_MASK GENMASK(3, 0)
+
+/* Hyper-V memory host visibility */
+enum hv_mem_host_visibility {
+ VMBUS_PAGE_NOT_VISIBLE = 0,
+ VMBUS_PAGE_VISIBLE_READ_ONLY = 1,
+ VMBUS_PAGE_VISIBLE_READ_WRITE = 3
+};
+
+/* HvCallModifySparseGpaPageHostVisibility hypercall */
+#define HV_MAX_MODIFY_GPA_REP_COUNT ((PAGE_SIZE / sizeof(u64)) - 2)
+struct hv_gpa_range_for_visibility {
+ u64 partition_id;
+ u32 host_visibility : 2;
+ u32 reserved0 : 30;
+ u32 reserved1;
+ u64 gpa_page_list[HV_MAX_MODIFY_GPA_REP_COUNT];
+} __packed;
+
+#if defined(CONFIG_X86)
+union hv_msi_address_register { /* HV_MSI_ADDRESS */
+ u32 as_uint32;
+ struct {
+ u32 reserved1 : 2;
+ u32 destination_mode : 1;
+ u32 redirection_hint : 1;
+ u32 reserved2 : 8;
+ u32 destination_id : 8;
+ u32 msi_base : 12;
+ };
+} __packed;
+
+union hv_msi_data_register { /* HV_MSI_ENTRY.Data */
+ u32 as_uint32;
+ struct {
+ u32 vector : 8;
+ u32 delivery_mode : 3;
+ u32 reserved1 : 3;
+ u32 level_assert : 1;
+ u32 trigger_mode : 1;
+ u32 reserved2 : 16;
+ };
+} __packed;
+
+union hv_msi_entry { /* HV_MSI_ENTRY */
+
+ u64 as_uint64;
+ struct {
+ union hv_msi_address_register address;
+ union hv_msi_data_register data;
+ } __packed;
+};
+
+#elif defined(CONFIG_ARM64) /* CONFIG_X86 */
+
+union hv_msi_entry {
+ u64 as_uint64[2];
+ struct {
+ u64 address;
+ u32 data;
+ u32 reserved;
+ } __packed;
+};
+#endif /* CONFIG_ARM64 */
+
+union hv_ioapic_rte {
+ u64 as_uint64;
+
+ struct {
+ u32 vector : 8;
+ u32 delivery_mode : 3;
+ u32 destination_mode : 1;
+ u32 delivery_status : 1;
+ u32 interrupt_polarity : 1;
+ u32 remote_irr : 1;
+ u32 trigger_mode : 1;
+ u32 interrupt_mask : 1;
+ u32 reserved1 : 15;
+
+ u32 reserved2 : 24;
+ u32 destination_id : 8;
+ };
+
+ struct {
+ u32 low_uint32;
+ u32 high_uint32;
+ };
+} __packed;
+
+enum hv_interrupt_source { /* HV_INTERRUPT_SOURCE */
+ HV_INTERRUPT_SOURCE_MSI = 1, /* MSI and MSI-X */
+ HV_INTERRUPT_SOURCE_IOAPIC,
+};
+
+struct hv_interrupt_entry { /* HV_INTERRUPT_ENTRY */
+ u32 source;
+ u32 reserved1;
+ union {
+ union hv_msi_entry msi_entry;
+ union hv_ioapic_rte ioapic_rte;
+ };
+} __packed;
+
+#define HV_DEVICE_INTERRUPT_TARGET_MULTICAST 1
+#define HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET 2
+
+struct hv_device_interrupt_target { /* HV_DEVICE_INTERRUPT_TARGET */
+ u32 vector;
+ u32 flags; /* HV_DEVICE_INTERRUPT_TARGET_* above */
+ union {
+ u64 vp_mask;
+ struct hv_vpset vp_set;
+ };
+} __packed;
+
+struct hv_retarget_device_interrupt { /* HV_INPUT_RETARGET_DEVICE_INTERRUPT */
+ u64 partition_id; /* use "self" */
+ u64 device_id;
+ struct hv_interrupt_entry int_entry;
+ u64 reserved2;
+ struct hv_device_interrupt_target int_target;
+} __packed __aligned(8);
+
+/* Data structures for HVCALL_MMIO_READ and HVCALL_MMIO_WRITE */
+#define HV_HYPERCALL_MMIO_MAX_DATA_LENGTH 64
+
+struct hv_mmio_read_input { /* HV_INPUT_MEMORY_MAPPED_IO_READ */
+ u64 gpa;
+ u32 size;
+ u32 reserved;
+} __packed;
+
+struct hv_mmio_read_output {
+ u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH];
+} __packed;
+
+struct hv_mmio_write_input {
+ u64 gpa;
+ u32 size;
+ u32 reserved;
+ u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH];
+} __packed;
+
+#endif /* _HV_HVGDK_MINI_H */
diff --git a/include/hyperv/hvhdk.h b/include/hyperv/hvhdk.h
new file mode 100644
index 000000000000..64407c2a3809
--- /dev/null
+++ b/include/hyperv/hvhdk.h
@@ -0,0 +1,733 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Type definitions for the Microsoft hypervisor.
+ */
+#ifndef _HV_HVHDK_H
+#define _HV_HVHDK_H
+
+#include <linux/build_bug.h>
+
+#include "hvhdk_mini.h"
+#include "hvgdk.h"
+
+/* Bits for dirty mask of hv_vp_register_page */
+#define HV_X64_REGISTER_CLASS_GENERAL 0
+#define HV_X64_REGISTER_CLASS_IP 1
+#define HV_X64_REGISTER_CLASS_XMM 2
+#define HV_X64_REGISTER_CLASS_SEGMENT 3
+#define HV_X64_REGISTER_CLASS_FLAGS 4
+
+#define HV_VP_REGISTER_PAGE_VERSION_1 1u
+
+struct hv_vp_register_page {
+ u16 version;
+ u8 isvalid;
+ u8 rsvdz;
+ u32 dirty;
+ union {
+ struct {
+ /* General purpose registers
+ * (HV_X64_REGISTER_CLASS_GENERAL)
+ */
+ union {
+ struct {
+ u64 rax;
+ u64 rcx;
+ u64 rdx;
+ u64 rbx;
+ u64 rsp;
+ u64 rbp;
+ u64 rsi;
+ u64 rdi;
+ u64 r8;
+ u64 r9;
+ u64 r10;
+ u64 r11;
+ u64 r12;
+ u64 r13;
+ u64 r14;
+ u64 r15;
+ } __packed;
+
+ u64 gp_registers[16];
+ };
+ /* Instruction pointer (HV_X64_REGISTER_CLASS_IP) */
+ u64 rip;
+ /* Flags (HV_X64_REGISTER_CLASS_FLAGS) */
+ u64 rflags;
+ } __packed;
+
+ u64 registers[18];
+ };
+ /* Volatile XMM registers (HV_X64_REGISTER_CLASS_XMM) */
+ union {
+ struct {
+ struct hv_u128 xmm0;
+ struct hv_u128 xmm1;
+ struct hv_u128 xmm2;
+ struct hv_u128 xmm3;
+ struct hv_u128 xmm4;
+ struct hv_u128 xmm5;
+ } __packed;
+
+ struct hv_u128 xmm_registers[6];
+ };
+ /* Segment registers (HV_X64_REGISTER_CLASS_SEGMENT) */
+ union {
+ struct {
+ struct hv_x64_segment_register es;
+ struct hv_x64_segment_register cs;
+ struct hv_x64_segment_register ss;
+ struct hv_x64_segment_register ds;
+ struct hv_x64_segment_register fs;
+ struct hv_x64_segment_register gs;
+ } __packed;
+
+ struct hv_x64_segment_register segment_registers[6];
+ };
+ /* Misc. control registers (cannot be set via this interface) */
+ u64 cr0;
+ u64 cr3;
+ u64 cr4;
+ u64 cr8;
+ u64 efer;
+ u64 dr7;
+ union hv_x64_pending_interruption_register pending_interruption;
+ union hv_x64_interrupt_state_register interrupt_state;
+ u64 instruction_emulation_hints;
+} __packed;
+
+#define HV_PARTITION_PROCESSOR_FEATURES_BANKS 2
+
+union hv_partition_processor_features {
+ u64 as_uint64[HV_PARTITION_PROCESSOR_FEATURES_BANKS];
+ struct {
+ u64 sse3_support : 1;
+ u64 lahf_sahf_support : 1;
+ u64 ssse3_support : 1;
+ u64 sse4_1_support : 1;
+ u64 sse4_2_support : 1;
+ u64 sse4a_support : 1;
+ u64 xop_support : 1;
+ u64 pop_cnt_support : 1;
+ u64 cmpxchg16b_support : 1;
+ u64 altmovcr8_support : 1;
+ u64 lzcnt_support : 1;
+ u64 mis_align_sse_support : 1;
+ u64 mmx_ext_support : 1;
+ u64 amd3dnow_support : 1;
+ u64 extended_amd3dnow_support : 1;
+ u64 page_1gb_support : 1;
+ u64 aes_support : 1;
+ u64 pclmulqdq_support : 1;
+ u64 pcid_support : 1;
+ u64 fma4_support : 1;
+ u64 f16c_support : 1;
+ u64 rd_rand_support : 1;
+ u64 rd_wr_fs_gs_support : 1;
+ u64 smep_support : 1;
+ u64 enhanced_fast_string_support : 1;
+ u64 bmi1_support : 1;
+ u64 bmi2_support : 1;
+ u64 hle_support_deprecated : 1;
+ u64 rtm_support_deprecated : 1;
+ u64 movbe_support : 1;
+ u64 npiep1_support : 1;
+ u64 dep_x87_fpu_save_support : 1;
+ u64 rd_seed_support : 1;
+ u64 adx_support : 1;
+ u64 intel_prefetch_support : 1;
+ u64 smap_support : 1;
+ u64 hle_support : 1;
+ u64 rtm_support : 1;
+ u64 rdtscp_support : 1;
+ u64 clflushopt_support : 1;
+ u64 clwb_support : 1;
+ u64 sha_support : 1;
+ u64 x87_pointers_saved_support : 1;
+ u64 invpcid_support : 1;
+ u64 ibrs_support : 1;
+ u64 stibp_support : 1;
+ u64 ibpb_support: 1;
+ u64 unrestricted_guest_support : 1;
+ u64 mdd_support : 1;
+ u64 fast_short_rep_mov_support : 1;
+ u64 l1dcache_flush_support : 1;
+ u64 rdcl_no_support : 1;
+ u64 ibrs_all_support : 1;
+ u64 skip_l1df_support : 1;
+ u64 ssb_no_support : 1;
+ u64 rsb_a_no_support : 1;
+ u64 virt_spec_ctrl_support : 1;
+ u64 rd_pid_support : 1;
+ u64 umip_support : 1;
+ u64 mbs_no_support : 1;
+ u64 mb_clear_support : 1;
+ u64 taa_no_support : 1;
+ u64 tsx_ctrl_support : 1;
+ /*
+ * N.B. The final processor feature bit in bank 0 is reserved to
+ * simplify potential downlevel backports.
+ */
+ u64 reserved_bank0 : 1;
+
+ /* N.B. Begin bank 1 processor features. */
+ u64 acount_mcount_support : 1;
+ u64 tsc_invariant_support : 1;
+ u64 cl_zero_support : 1;
+ u64 rdpru_support : 1;
+ u64 la57_support : 1;
+ u64 mbec_support : 1;
+ u64 nested_virt_support : 1;
+ u64 psfd_support : 1;
+ u64 cet_ss_support : 1;
+ u64 cet_ibt_support : 1;
+ u64 vmx_exception_inject_support : 1;
+ u64 enqcmd_support : 1;
+ u64 umwait_tpause_support : 1;
+ u64 movdiri_support : 1;
+ u64 movdir64b_support : 1;
+ u64 cldemote_support : 1;
+ u64 serialize_support : 1;
+ u64 tsc_deadline_tmr_support : 1;
+ u64 tsc_adjust_support : 1;
+ u64 fzlrep_movsb : 1;
+ u64 fsrep_stosb : 1;
+ u64 fsrep_cmpsb : 1;
+ u64 reserved_bank1 : 42;
+ } __packed;
+};
+
+union hv_partition_processor_xsave_features {
+ struct {
+ u64 xsave_support : 1;
+ u64 xsaveopt_support : 1;
+ u64 avx_support : 1;
+ u64 reserved1 : 61;
+ } __packed;
+ u64 as_uint64;
+};
+
+struct hv_partition_creation_properties {
+ union hv_partition_processor_features disabled_processor_features;
+ union hv_partition_processor_xsave_features
+ disabled_processor_xsave_features;
+} __packed;
+
+#define HV_PARTITION_SYNTHETIC_PROCESSOR_FEATURES_BANKS 1
+
+union hv_partition_synthetic_processor_features {
+ u64 as_uint64[HV_PARTITION_SYNTHETIC_PROCESSOR_FEATURES_BANKS];
+
+ struct {
+ u64 hypervisor_present : 1;
+ /* Support for HV#1: (CPUID leaves 0x40000000 - 0x40000006)*/
+ u64 hv1 : 1;
+ u64 access_vp_run_time_reg : 1; /* HV_X64_MSR_VP_RUNTIME */
+ u64 access_partition_reference_counter : 1; /* HV_X64_MSR_TIME_REF_COUNT */
+ u64 access_synic_regs : 1; /* SINT-related registers */
+ /*
+ * Access to HV_X64_MSR_STIMER0_CONFIG through
+ * HV_X64_MSR_STIMER3_COUNT.
+ */
+ u64 access_synthetic_timer_regs : 1;
+ u64 access_intr_ctrl_regs : 1; /* APIC MSRs and VP assist page*/
+ /* HV_X64_MSR_GUEST_OS_ID and HV_X64_MSR_HYPERCALL */
+ u64 access_hypercall_regs : 1;
+ u64 access_vp_index : 1;
+ u64 access_partition_reference_tsc : 1;
+ u64 access_guest_idle_reg : 1;
+ u64 access_frequency_regs : 1;
+ u64 reserved_z12 : 1;
+ u64 reserved_z13 : 1;
+ u64 reserved_z14 : 1;
+ u64 enable_extended_gva_ranges_for_flush_virtual_address_list : 1;
+ u64 reserved_z16 : 1;
+ u64 reserved_z17 : 1;
+ /* Use fast hypercall output. Corresponds to privilege. */
+ u64 fast_hypercall_output : 1;
+ u64 reserved_z19 : 1;
+ u64 start_virtual_processor : 1; /* Can start VPs */
+ u64 reserved_z21 : 1;
+ /* Synthetic timers in direct mode. */
+ u64 direct_synthetic_timers : 1;
+ u64 reserved_z23 : 1;
+ u64 extended_processor_masks : 1;
+
+ /* Enable various hypercalls */
+ u64 tb_flush_hypercalls : 1;
+ u64 synthetic_cluster_ipi : 1;
+ u64 notify_long_spin_wait : 1;
+ u64 query_numa_distance : 1;
+ u64 signal_events : 1;
+ u64 retarget_device_interrupt : 1;
+ u64 restore_time : 1;
+
+ /* EnlightenedVmcs nested enlightenment is supported. */
+ u64 enlightened_vmcs : 1;
+ u64 reserved : 31;
+ } __packed;
+};
+
+#define HV_MAKE_COMPATIBILITY_VERSION(major_, minor_) \
+ ((u32)((major_) << 8 | (minor_)))
+
+#define HV_COMPATIBILITY_21_H2 HV_MAKE_COMPATIBILITY_VERSION(0X6, 0X9)
+
+union hv_partition_isolation_properties {
+ u64 as_uint64;
+ struct {
+ u64 isolation_type: 5;
+ u64 isolation_host_type : 2;
+ u64 rsvd_z: 5;
+ u64 shared_gpa_boundary_page_number: 52;
+ } __packed;
+};
+
+/*
+ * Various isolation types supported by MSHV.
+ */
+#define HV_PARTITION_ISOLATION_TYPE_NONE 0
+#define HV_PARTITION_ISOLATION_TYPE_SNP 2
+#define HV_PARTITION_ISOLATION_TYPE_TDX 3
+
+/*
+ * Various host isolation types supported by MSHV.
+ */
+#define HV_PARTITION_ISOLATION_HOST_TYPE_NONE 0x0
+#define HV_PARTITION_ISOLATION_HOST_TYPE_HARDWARE 0x1
+#define HV_PARTITION_ISOLATION_HOST_TYPE_RESERVED 0x2
+
+/* Note: Exo partition is enabled by default */
+#define HV_PARTITION_CREATION_FLAG_EXO_PARTITION BIT(8)
+#define HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED BIT(13)
+#define HV_PARTITION_CREATION_FLAG_INTERCEPT_MESSAGE_PAGE_ENABLED BIT(19)
+#define HV_PARTITION_CREATION_FLAG_X2APIC_CAPABLE BIT(22)
+
+struct hv_input_create_partition {
+ u64 flags;
+ struct hv_proximity_domain_info proximity_domain_info;
+ u32 compatibility_version;
+ u32 padding;
+ struct hv_partition_creation_properties partition_creation_properties;
+ union hv_partition_isolation_properties isolation_properties;
+} __packed;
+
+struct hv_output_create_partition {
+ u64 partition_id;
+} __packed;
+
+struct hv_input_initialize_partition {
+ u64 partition_id;
+} __packed;
+
+struct hv_input_finalize_partition {
+ u64 partition_id;
+} __packed;
+
+struct hv_input_delete_partition {
+ u64 partition_id;
+} __packed;
+
+struct hv_input_get_partition_property {
+ u64 partition_id;
+ u32 property_code; /* enum hv_partition_property_code */
+ u32 padding;
+} __packed;
+
+struct hv_output_get_partition_property {
+ u64 property_value;
+} __packed;
+
+struct hv_input_set_partition_property {
+ u64 partition_id;
+ u32 property_code; /* enum hv_partition_property_code */
+ u32 padding;
+ u64 property_value;
+} __packed;
+
+enum hv_vp_state_page_type {
+ HV_VP_STATE_PAGE_REGISTERS = 0,
+ HV_VP_STATE_PAGE_INTERCEPT_MESSAGE = 1,
+ HV_VP_STATE_PAGE_COUNT
+};
+
+struct hv_input_map_vp_state_page {
+ u64 partition_id;
+ u32 vp_index;
+ u32 type; /* enum hv_vp_state_page_type */
+} __packed;
+
+struct hv_output_map_vp_state_page {
+ u64 map_location; /* GPA page number */
+} __packed;
+
+struct hv_input_unmap_vp_state_page {
+ u64 partition_id;
+ u32 vp_index;
+ u32 type; /* enum hv_vp_state_page_type */
+} __packed;
+
+struct hv_opaque_intercept_message {
+ u32 vp_index;
+} __packed;
+
+enum hv_port_type {
+ HV_PORT_TYPE_MESSAGE = 1,
+ HV_PORT_TYPE_EVENT = 2,
+ HV_PORT_TYPE_MONITOR = 3,
+ HV_PORT_TYPE_DOORBELL = 4 /* Root Partition only */
+};
+
+struct hv_port_info {
+ u32 port_type; /* enum hv_port_type */
+ u32 padding;
+ union {
+ struct {
+ u32 target_sint;
+ u32 target_vp;
+ u64 rsvdz;
+ } message_port_info;
+ struct {
+ u32 target_sint;
+ u32 target_vp;
+ u16 base_flag_number;
+ u16 flag_count;
+ u32 rsvdz;
+ } event_port_info;
+ struct {
+ u64 monitor_address;
+ u64 rsvdz;
+ } monitor_port_info;
+ struct {
+ u32 target_sint;
+ u32 target_vp;
+ u64 rsvdz;
+ } doorbell_port_info;
+ };
+} __packed;
+
+struct hv_connection_info {
+ u32 port_type;
+ u32 padding;
+ union {
+ struct {
+ u64 rsvdz;
+ } message_connection_info;
+ struct {
+ u64 rsvdz;
+ } event_connection_info;
+ struct {
+ u64 monitor_address;
+ } monitor_connection_info;
+ struct {
+ u64 gpa;
+ u64 trigger_value;
+ u64 flags;
+ } doorbell_connection_info;
+ };
+} __packed;
+
+/* Define synthetic interrupt controller flag constants. */
+#define HV_EVENT_FLAGS_COUNT (256 * 8)
+#define HV_EVENT_FLAGS_BYTE_COUNT (256)
+#define HV_EVENT_FLAGS32_COUNT (256 / sizeof(u32))
+
+/* linux side we create long version of flags to use long bit ops on flags */
+#define HV_EVENT_FLAGS_UL_COUNT (256 / sizeof(ulong))
+
+/* Define the synthetic interrupt controller event flags format. */
+union hv_synic_event_flags {
+ unsigned char flags8[HV_EVENT_FLAGS_BYTE_COUNT];
+ u32 flags32[HV_EVENT_FLAGS32_COUNT];
+ ulong flags[HV_EVENT_FLAGS_UL_COUNT]; /* linux only */
+};
+
+struct hv_synic_event_flags_page {
+ volatile union hv_synic_event_flags event_flags[HV_SYNIC_SINT_COUNT];
+};
+
+#define HV_SYNIC_EVENT_RING_MESSAGE_COUNT 63
+
+struct hv_synic_event_ring {
+ u8 signal_masked;
+ u8 ring_full;
+ u16 reserved_z;
+ u32 data[HV_SYNIC_EVENT_RING_MESSAGE_COUNT];
+} __packed;
+
+struct hv_synic_event_ring_page {
+ struct hv_synic_event_ring sint_event_ring[HV_SYNIC_SINT_COUNT];
+};
+
+/* Define SynIC control register. */
+union hv_synic_scontrol {
+ u64 as_uint64;
+ struct {
+ u64 enable : 1;
+ u64 reserved : 63;
+ } __packed;
+};
+
+/* Define the format of the SIEFP register */
+union hv_synic_siefp {
+ u64 as_uint64;
+ struct {
+ u64 siefp_enabled : 1;
+ u64 preserved : 11;
+ u64 base_siefp_gpa : 52;
+ } __packed;
+};
+
+union hv_synic_sirbp {
+ u64 as_uint64;
+ struct {
+ u64 sirbp_enabled : 1;
+ u64 preserved : 11;
+ u64 base_sirbp_gpa : 52;
+ } __packed;
+};
+
+union hv_interrupt_control {
+ u64 as_uint64;
+ struct {
+ u32 interrupt_type; /* enum hv_interrupt_type */
+ u32 level_triggered : 1;
+ u32 logical_dest_mode : 1;
+ u32 rsvd : 30;
+ } __packed;
+};
+
+struct hv_stimer_state {
+ struct {
+ u32 undelivered_msg_pending : 1;
+ u32 reserved : 31;
+ } __packed flags;
+ u32 resvd;
+ u64 config;
+ u64 count;
+ u64 adjustment;
+ u64 undelivered_exp_time;
+} __packed;
+
+struct hv_synthetic_timers_state {
+ struct hv_stimer_state timers[HV_SYNIC_STIMER_COUNT];
+ u64 reserved[5];
+} __packed;
+
+union hv_input_delete_vp {
+ u64 as_uint64[2];
+ struct {
+ u64 partition_id;
+ u32 vp_index;
+ u8 reserved[4];
+ } __packed;
+} __packed;
+
+struct hv_input_assert_virtual_interrupt {
+ u64 partition_id;
+ union hv_interrupt_control control;
+ u64 dest_addr; /* cpu's apic id */
+ u32 vector;
+ u8 target_vtl;
+ u8 rsvd_z0;
+ u16 rsvd_z1;
+} __packed;
+
+struct hv_input_create_port {
+ u64 port_partition_id;
+ union hv_port_id port_id;
+ u8 port_vtl;
+ u8 min_connection_vtl;
+ u16 padding;
+ u64 connection_partition_id;
+ struct hv_port_info port_info;
+ struct hv_proximity_domain_info proximity_domain_info;
+} __packed;
+
+union hv_input_delete_port {
+ u64 as_uint64[2];
+ struct {
+ u64 port_partition_id;
+ union hv_port_id port_id;
+ u32 reserved;
+ };
+} __packed;
+
+struct hv_input_connect_port {
+ u64 connection_partition_id;
+ union hv_connection_id connection_id;
+ u8 connection_vtl;
+ u8 rsvdz0;
+ u16 rsvdz1;
+ u64 port_partition_id;
+ union hv_port_id port_id;
+ u32 reserved2;
+ struct hv_connection_info connection_info;
+ struct hv_proximity_domain_info proximity_domain_info;
+} __packed;
+
+union hv_input_disconnect_port {
+ u64 as_uint64[2];
+ struct {
+ u64 connection_partition_id;
+ union hv_connection_id connection_id;
+ u32 is_doorbell: 1;
+ u32 reserved: 31;
+ } __packed;
+} __packed;
+
+union hv_input_notify_port_ring_empty {
+ u64 as_uint64;
+ struct {
+ u32 sint_index;
+ u32 reserved;
+ };
+} __packed;
+
+struct hv_vp_state_data_xsave {
+ u64 flags;
+ union hv_x64_xsave_xfem_register states;
+} __packed;
+
+/*
+ * For getting and setting VP state, there are two options based on the state type:
+ *
+ * 1.) Data that is accessed by PFNs in the input hypercall page. This is used
+ * for state which may not fit into the hypercall pages.
+ * 2.) Data that is accessed directly in the input\output hypercall pages.
+ * This is used for state that will always fit into the hypercall pages.
+ *
+ * In the future this could be dynamic based on the size if needed.
+ *
+ * Note these hypercalls have an 8-byte aligned variable header size as per the tlfs
+ */
+
+#define HV_GET_SET_VP_STATE_TYPE_PFN BIT(31)
+
+enum hv_get_set_vp_state_type {
+ /* HvGetSetVpStateLocalInterruptControllerState - APIC/GIC state */
+ HV_GET_SET_VP_STATE_LAPIC_STATE = 0 | HV_GET_SET_VP_STATE_TYPE_PFN,
+ HV_GET_SET_VP_STATE_XSAVE = 1 | HV_GET_SET_VP_STATE_TYPE_PFN,
+ HV_GET_SET_VP_STATE_SIM_PAGE = 2 | HV_GET_SET_VP_STATE_TYPE_PFN,
+ HV_GET_SET_VP_STATE_SIEF_PAGE = 3 | HV_GET_SET_VP_STATE_TYPE_PFN,
+ HV_GET_SET_VP_STATE_SYNTHETIC_TIMERS = 4,
+};
+
+struct hv_vp_state_data {
+ u32 type;
+ u32 rsvd;
+ struct hv_vp_state_data_xsave xsave;
+} __packed;
+
+struct hv_input_get_vp_state {
+ u64 partition_id;
+ u32 vp_index;
+ u8 input_vtl;
+ u8 rsvd0;
+ u16 rsvd1;
+ struct hv_vp_state_data state_data;
+ u64 output_data_pfns[];
+} __packed;
+
+union hv_output_get_vp_state {
+ struct hv_synthetic_timers_state synthetic_timers_state;
+} __packed;
+
+union hv_input_set_vp_state_data {
+ u64 pfns;
+ u8 bytes;
+} __packed;
+
+struct hv_input_set_vp_state {
+ u64 partition_id;
+ u32 vp_index;
+ u8 input_vtl;
+ u8 rsvd0;
+ u16 rsvd1;
+ struct hv_vp_state_data state_data;
+ union hv_input_set_vp_state_data data[];
+} __packed;
+
+/*
+ * Dispatch state for the VP communicated by the hypervisor to the
+ * VP-dispatching thread in the root on return from HVCALL_DISPATCH_VP.
+ */
+enum hv_vp_dispatch_state {
+ HV_VP_DISPATCH_STATE_INVALID = 0,
+ HV_VP_DISPATCH_STATE_BLOCKED = 1,
+ HV_VP_DISPATCH_STATE_READY = 2,
+};
+
+/*
+ * Dispatch event that caused the current dispatch state on return from
+ * HVCALL_DISPATCH_VP.
+ */
+enum hv_vp_dispatch_event {
+ HV_VP_DISPATCH_EVENT_INVALID = 0x00000000,
+ HV_VP_DISPATCH_EVENT_SUSPEND = 0x00000001,
+ HV_VP_DISPATCH_EVENT_INTERCEPT = 0x00000002,
+};
+
+#define HV_ROOT_SCHEDULER_MAX_VPS_PER_CHILD_PARTITION 1024
+/* The maximum array size of HV_GENERIC_SET (vp_set) buffer */
+#define HV_GENERIC_SET_QWORD_COUNT(max) (((((max) - 1) >> 6) + 1) + 2)
+
+struct hv_vp_signal_bitset_scheduler_message {
+ u64 partition_id;
+ u32 overflow_count;
+ u16 vp_count;
+ u16 reserved;
+
+#define BITSET_BUFFER_SIZE \
+ HV_GENERIC_SET_QWORD_COUNT(HV_ROOT_SCHEDULER_MAX_VPS_PER_CHILD_PARTITION)
+ union {
+ struct hv_vpset bitset;
+ u64 bitset_buffer[BITSET_BUFFER_SIZE];
+ } vp_bitset;
+#undef BITSET_BUFFER_SIZE
+} __packed;
+
+static_assert(sizeof(struct hv_vp_signal_bitset_scheduler_message) <=
+ (sizeof(struct hv_message) - sizeof(struct hv_message_header)));
+
+#define HV_MESSAGE_MAX_PARTITION_VP_PAIR_COUNT \
+ (((sizeof(struct hv_message) - sizeof(struct hv_message_header)) / \
+ (sizeof(u64 /* partition id */) + sizeof(u32 /* vp index */))) - 1)
+
+struct hv_vp_signal_pair_scheduler_message {
+ u32 overflow_count;
+ u8 vp_count;
+ u8 reserved1[3];
+
+ u64 partition_ids[HV_MESSAGE_MAX_PARTITION_VP_PAIR_COUNT];
+ u32 vp_indexes[HV_MESSAGE_MAX_PARTITION_VP_PAIR_COUNT];
+
+ u8 reserved2[4];
+} __packed;
+
+static_assert(sizeof(struct hv_vp_signal_pair_scheduler_message) ==
+ (sizeof(struct hv_message) - sizeof(struct hv_message_header)));
+
+/* Input and output structures for HVCALL_DISPATCH_VP */
+#define HV_DISPATCH_VP_FLAG_CLEAR_INTERCEPT_SUSPEND 0x1
+#define HV_DISPATCH_VP_FLAG_ENABLE_CALLER_INTERRUPTS 0x2
+#define HV_DISPATCH_VP_FLAG_SET_CALLER_SPEC_CTRL 0x4
+#define HV_DISPATCH_VP_FLAG_SKIP_VP_SPEC_FLUSH 0x8
+#define HV_DISPATCH_VP_FLAG_SKIP_CALLER_SPEC_FLUSH 0x10
+#define HV_DISPATCH_VP_FLAG_SKIP_CALLER_USER_SPEC_FLUSH 0x20
+
+struct hv_input_dispatch_vp {
+ u64 partition_id;
+ u32 vp_index;
+ u32 flags;
+ u64 time_slice; /* in 100ns */
+ u64 spec_ctrl;
+} __packed;
+
+struct hv_output_dispatch_vp {
+ u32 dispatch_state; /* enum hv_vp_dispatch_state */
+ u32 dispatch_event; /* enum hv_vp_dispatch_event */
+} __packed;
+
+#endif /* _HV_HVHDK_H */
diff --git a/include/hyperv/hvhdk_mini.h b/include/hyperv/hvhdk_mini.h
new file mode 100644
index 000000000000..46938b664f0c
--- /dev/null
+++ b/include/hyperv/hvhdk_mini.h
@@ -0,0 +1,310 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Type definitions for the Microsoft Hypervisor.
+ */
+#ifndef _HV_HVHDK_MINI_H
+#define _HV_HVHDK_MINI_H
+
+#include "hvgdk_mini.h"
+
+/*
+ * Doorbell connection_info flags.
+ */
+#define HV_DOORBELL_FLAG_TRIGGER_SIZE_MASK 0x00000007
+#define HV_DOORBELL_FLAG_TRIGGER_SIZE_ANY 0x00000000
+#define HV_DOORBELL_FLAG_TRIGGER_SIZE_BYTE 0x00000001
+#define HV_DOORBELL_FLAG_TRIGGER_SIZE_WORD 0x00000002
+#define HV_DOORBELL_FLAG_TRIGGER_SIZE_DWORD 0x00000003
+#define HV_DOORBELL_FLAG_TRIGGER_SIZE_QWORD 0x00000004
+#define HV_DOORBELL_FLAG_TRIGGER_ANY_VALUE 0x80000000
+
+/* Each generic set contains 64 elements */
+#define HV_GENERIC_SET_SHIFT (6)
+#define HV_GENERIC_SET_MASK (63)
+
+enum hv_generic_set_format {
+ HV_GENERIC_SET_SPARSE_4K,
+ HV_GENERIC_SET_ALL,
+};
+
+enum hv_scheduler_type {
+ HV_SCHEDULER_TYPE_LP = 1, /* Classic scheduler w/o SMT */
+ HV_SCHEDULER_TYPE_LP_SMT = 2, /* Classic scheduler w/ SMT */
+ HV_SCHEDULER_TYPE_CORE_SMT = 3, /* Core scheduler */
+ HV_SCHEDULER_TYPE_ROOT = 4, /* Root / integrated scheduler */
+ HV_SCHEDULER_TYPE_MAX
+};
+
+enum hv_partition_property_code {
+ /* Privilege properties */
+ HV_PARTITION_PROPERTY_PRIVILEGE_FLAGS = 0x00010000,
+ HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES = 0x00010001,
+
+ /* Resource properties */
+ HV_PARTITION_PROPERTY_GPA_PAGE_ACCESS_TRACKING = 0x00050005,
+ HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION = 0x00050017,
+
+ /* Compatibility properties */
+ HV_PARTITION_PROPERTY_PROCESSOR_XSAVE_FEATURES = 0x00060002,
+ HV_PARTITION_PROPERTY_MAX_XSAVE_DATA_SIZE = 0x00060008,
+ HV_PARTITION_PROPERTY_PROCESSOR_CLOCK_FREQUENCY = 0x00060009,
+};
+
+enum hv_system_property {
+ /* Add more values when needed */
+ HV_SYSTEM_PROPERTY_SCHEDULER_TYPE = 15,
+};
+
+struct hv_input_get_system_property {
+ u32 property_id; /* enum hv_system_property */
+ union {
+ u32 as_uint32;
+ /* More fields to be filled in when needed */
+ };
+} __packed;
+
+struct hv_output_get_system_property {
+ union {
+ u32 scheduler_type; /* enum hv_scheduler_type */
+ };
+} __packed;
+
+struct hv_proximity_domain_flags {
+ u32 proximity_preferred : 1;
+ u32 reserved : 30;
+ u32 proximity_info_valid : 1;
+} __packed;
+
+struct hv_proximity_domain_info {
+ u32 domain_id;
+ struct hv_proximity_domain_flags flags;
+} __packed;
+
+/* HvDepositMemory hypercall */
+struct hv_deposit_memory { /* HV_INPUT_DEPOSIT_MEMORY */
+ u64 partition_id;
+ u64 gpa_page_list[];
+} __packed;
+
+struct hv_input_withdraw_memory {
+ u64 partition_id;
+ struct hv_proximity_domain_info proximity_domain_info;
+} __packed;
+
+struct hv_output_withdraw_memory {
+ DECLARE_FLEX_ARRAY(u64, gpa_page_list);
+} __packed;
+
+/* HV Map GPA (Guest Physical Address) Flags */
+#define HV_MAP_GPA_PERMISSIONS_NONE 0x0
+#define HV_MAP_GPA_READABLE 0x1
+#define HV_MAP_GPA_WRITABLE 0x2
+#define HV_MAP_GPA_KERNEL_EXECUTABLE 0x4
+#define HV_MAP_GPA_USER_EXECUTABLE 0x8
+#define HV_MAP_GPA_EXECUTABLE 0xC
+#define HV_MAP_GPA_PERMISSIONS_MASK 0xF
+#define HV_MAP_GPA_ADJUSTABLE 0x8000
+#define HV_MAP_GPA_NO_ACCESS 0x10000
+#define HV_MAP_GPA_NOT_CACHED 0x200000
+#define HV_MAP_GPA_LARGE_PAGE 0x80000000
+
+struct hv_input_map_gpa_pages {
+ u64 target_partition_id;
+ u64 target_gpa_base;
+ u32 map_flags;
+ u32 padding;
+ u64 source_gpa_page_list[];
+} __packed;
+
+union hv_gpa_page_access_state_flags {
+ struct {
+ u64 clear_accessed : 1;
+ u64 set_accessed : 1;
+ u64 clear_dirty : 1;
+ u64 set_dirty : 1;
+ u64 reserved : 60;
+ } __packed;
+ u64 as_uint64;
+};
+
+struct hv_input_get_gpa_pages_access_state {
+ u64 partition_id;
+ union hv_gpa_page_access_state_flags flags;
+ u64 hv_gpa_page_number;
+} __packed;
+
+union hv_gpa_page_access_state {
+ struct {
+ u8 accessed : 1;
+ u8 dirty : 1;
+ u8 reserved: 6;
+ };
+ u8 as_uint8;
+} __packed;
+
+struct hv_lp_startup_status {
+ u64 hv_status;
+ u64 substatus1;
+ u64 substatus2;
+ u64 substatus3;
+ u64 substatus4;
+ u64 substatus5;
+ u64 substatus6;
+} __packed;
+
+struct hv_input_add_logical_processor {
+ u32 lp_index;
+ u32 apic_id;
+ struct hv_proximity_domain_info proximity_domain_info;
+} __packed;
+
+struct hv_output_add_logical_processor {
+ struct hv_lp_startup_status startup_status;
+} __packed;
+
+enum { /* HV_SUBNODE_TYPE */
+ HV_SUBNODE_ANY = 0,
+ HV_SUBNODE_SOCKET,
+ HV_SUBNODE_CLUSTER,
+ HV_SUBNODE_L3,
+ HV_SUBNODE_COUNT,
+ HV_SUBNODE_INVALID = -1
+};
+
+struct hv_create_vp { /* HV_INPUT_CREATE_VP */
+ u64 partition_id;
+ u32 vp_index;
+ u8 padding[3];
+ u8 subnode_type;
+ u64 subnode_id;
+ struct hv_proximity_domain_info proximity_domain_info;
+ u64 flags;
+} __packed;
+
+/* HV_INTERRUPT_TRIGGER_MODE */
+enum hv_interrupt_trigger_mode {
+ HV_INTERRUPT_TRIGGER_MODE_EDGE = 0,
+ HV_INTERRUPT_TRIGGER_MODE_LEVEL = 1,
+};
+
+/* HV_DEVICE_INTERRUPT_DESCRIPTOR */
+struct hv_device_interrupt_descriptor {
+ u32 interrupt_type;
+ u32 trigger_mode;
+ u32 vector_count;
+ u32 reserved;
+ struct hv_device_interrupt_target target;
+} __packed;
+
+/* HV_INPUT_MAP_DEVICE_INTERRUPT */
+struct hv_input_map_device_interrupt {
+ u64 partition_id;
+ u64 device_id;
+ u32 flags;
+ u32 base_irt_idx;
+ struct hv_interrupt_entry logical_interrupt_entry;
+ struct hv_device_interrupt_descriptor interrupt_descriptor;
+} __packed;
+
+/* HV_OUTPUT_MAP_DEVICE_INTERRUPT */
+struct hv_output_map_device_interrupt {
+ struct hv_interrupt_entry interrupt_entry;
+} __packed;
+
+/* HV_INPUT_UNMAP_DEVICE_INTERRUPT */
+struct hv_input_unmap_device_interrupt {
+ u64 partition_id;
+ u64 device_id;
+ struct hv_interrupt_entry interrupt_entry;
+ u32 flags;
+} __packed;
+
+#define HV_SOURCE_SHADOW_NONE 0x0
+#define HV_SOURCE_SHADOW_BRIDGE_BUS_RANGE 0x1
+
+struct hv_send_ipi_ex { /* HV_INPUT_SEND_SYNTHETIC_CLUSTER_IPI_EX */
+ u32 vector;
+ u32 reserved;
+ struct hv_vpset vp_set;
+} __packed;
+
+typedef u16 hv_pci_rid; /* HV_PCI_RID */
+typedef u16 hv_pci_segment; /* HV_PCI_SEGMENT */
+typedef u64 hv_logical_device_id;
+union hv_pci_bdf { /* HV_PCI_BDF */
+ u16 as_uint16;
+
+ struct {
+ u8 function : 3;
+ u8 device : 5;
+ u8 bus;
+ };
+} __packed;
+
+union hv_pci_bus_range {
+ u16 as_uint16;
+
+ struct {
+ u8 subordinate_bus;
+ u8 secondary_bus;
+ };
+} __packed;
+
+enum hv_device_type { /* HV_DEVICE_TYPE */
+ HV_DEVICE_TYPE_LOGICAL = 0,
+ HV_DEVICE_TYPE_PCI = 1,
+ HV_DEVICE_TYPE_IOAPIC = 2,
+ HV_DEVICE_TYPE_ACPI = 3,
+};
+
+union hv_device_id { /* HV_DEVICE_ID */
+ u64 as_uint64;
+
+ struct {
+ u64 reserved0 : 62;
+ u64 device_type : 2;
+ };
+
+ /* HV_DEVICE_TYPE_LOGICAL */
+ struct {
+ u64 id : 62;
+ u64 device_type : 2;
+ } logical;
+
+ /* HV_DEVICE_TYPE_PCI */
+ struct {
+ union {
+ hv_pci_rid rid;
+ union hv_pci_bdf bdf;
+ };
+
+ hv_pci_segment segment;
+ union hv_pci_bus_range shadow_bus_range;
+
+ u16 phantom_function_bits : 2;
+ u16 source_shadow : 1;
+
+ u16 rsvdz0 : 11;
+ u16 device_type : 2;
+ } pci;
+
+ /* HV_DEVICE_TYPE_IOAPIC */
+ struct {
+ u8 ioapic_id;
+ u8 rsvdz0;
+ u16 rsvdz1;
+ u16 rsvdz2;
+
+ u16 rsvdz3 : 14;
+ u16 device_type : 2;
+ } ioapic;
+
+ /* HV_DEVICE_TYPE_ACPI */
+ struct {
+ u32 input_mapping_base;
+ u32 input_mapping_count : 30;
+ u32 device_type : 2;
+ } acpi;
+} __packed;
+
+#endif /* _HV_HVHDK_MINI_H */
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 4/5] hyperv: Add hv_defs.h to conditionally include hyperv-tlfs.h or hvhdk.h
2024-10-03 19:50 [PATCH 0/5] Add new headers for Hyper-V Dom0 Nuno Das Neves
` (2 preceding siblings ...)
2024-10-03 19:51 ` [PATCH 3/5] hyperv: Add new Hyper-V headers Nuno Das Neves
@ 2024-10-03 19:51 ` Nuno Das Neves
2024-10-03 19:51 ` [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code Nuno Das Neves
` (3 subsequent siblings)
7 siblings, 0 replies; 27+ messages in thread
From: Nuno Das Neves @ 2024-10-03 19:51 UTC (permalink / raw)
To: linux-hyperv, linux-arm-kernel, linux-kernel, kvm, iommu, netdev,
linux-pci, linux-arch, virtualization
Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, luto, tglx,
mingo, bp, dave.hansen, x86, hpa, seanjc, pbonzini, peterz,
daniel.lezcano, joro, robin.murphy, davem, edumazet, kuba, pabeni,
lpieralisi, kw, robh, bhelgaas, arnd, sgarzare, jinankjain,
muminulrussell, skinsburskii, mukeshrathor
Include one or the other depending on whether HYPERV_NONTLFS_HEADERS is
defined.
This will allow Hyper-V code to use the new headers while other code can
continue using hyperv-tlfs.h which is only for Hyper-V guests.
Replace hyperv-tlfs.h in shared headers with hv_defs.h These headers are
shared between Hyper-V code and non-Hyper-V code (KVM for example). This
will allow switching to the new headers in Hyper-V code only.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
arch/arm64/include/asm/mshyperv.h | 2 +-
arch/x86/include/asm/mshyperv.h | 2 +-
arch/x86/include/asm/svm.h | 2 +-
include/asm-generic/mshyperv.h | 2 +-
include/clocksource/hyperv_timer.h | 2 +-
include/hyperv/hv_defs.h | 29 +++++++++++++++++++++++++++++
6 files changed, 34 insertions(+), 5 deletions(-)
create mode 100644 include/hyperv/hv_defs.h
diff --git a/arch/arm64/include/asm/mshyperv.h b/arch/arm64/include/asm/mshyperv.h
index a975e1a689dd..13b2b2218d85 100644
--- a/arch/arm64/include/asm/mshyperv.h
+++ b/arch/arm64/include/asm/mshyperv.h
@@ -20,7 +20,7 @@
#include <linux/types.h>
#include <linux/arm-smccc.h>
-#include <asm/hyperv-tlfs.h>
+#include <hyperv/hv_defs.h>
/*
* Declare calls to get and set Hyper-V VP register values on ARM64, which
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 47ca48062547..dc8587f02850 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -6,9 +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 <hyperv/hv_defs.h>
/*
* Hyper-V always provides a single IO-APIC at this MMIO address.
diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
index f0dea3750ca9..c682fc080310 100644
--- a/arch/x86/include/asm/svm.h
+++ b/arch/x86/include/asm/svm.h
@@ -5,7 +5,7 @@
#include <uapi/asm/svm.h>
#include <uapi/asm/kvm.h>
-#include <asm/hyperv-tlfs.h>
+#include <hyperv/hv_defs.h>
/*
* 32-bit intercept words in the VMCB Control Area, starting
diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index 8fe7aaab2599..8bd308ae1056 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -25,7 +25,7 @@
#include <linux/cpumask.h>
#include <linux/nmi.h>
#include <asm/ptrace.h>
-#include <asm/hyperv-tlfs.h>
+#include <hyperv/hv_defs.h>
#define VTPM_BASE_ADDRESS 0xfed40000
diff --git a/include/clocksource/hyperv_timer.h b/include/clocksource/hyperv_timer.h
index 6cdc873ac907..068ca1934c23 100644
--- a/include/clocksource/hyperv_timer.h
+++ b/include/clocksource/hyperv_timer.h
@@ -15,7 +15,7 @@
#include <linux/clocksource.h>
#include <linux/math64.h>
-#include <asm/hyperv-tlfs.h>
+#include <hyperv/hv_defs.h>
#define HV_MAX_MAX_DELTA_TICKS 0xffffffff
#define HV_MIN_DELTA_TICKS 1
diff --git a/include/hyperv/hv_defs.h b/include/hyperv/hv_defs.h
new file mode 100644
index 000000000000..eed500288499
--- /dev/null
+++ b/include/hyperv/hv_defs.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * This file includes Microsoft Hypervisor definitions from hyperv-tlfs.h, or
+ * hvhdk.h when HYPERV_NONTLFS_HEADERS is defined.
+ */
+/*
+ * NOTE:
+ * The typical #ifdef guard to prevent redefinition errors is intentionally
+ * omitted. This makes compiler error (either via #error or redefinition) in
+ * the case where hyperv-tlfs.h is accidentally included, followed by
+ * definition of HYPERV_NON_TLFS_HEADERS and inclusion of this file.
+ * If this file could only be included once, the compiler would ignore the
+ * attempt to use HYPERV_NONTLFS_HEADERS to include hvhdk.h.
+ */
+
+#ifdef HYPERV_NONTLFS_HEADERS
+
+#ifdef HYPERV_TLFS_HEADERS_INCLUDED
+#error "hyperv-tlfs.h was already included before HYPERV_NONTLFS_HEADERS was defined"
+#else
+#include <hyperv/hvhdk.h>
+#endif
+
+#else /* HYPERV_NONTLFS_HEADERS */
+
+#include <asm/hyperv-tlfs.h>
+#define HYPERV_TLFS_HEADERS_INCLUDED
+
+#endif /* !HYPERV_NONTLFS_HEADERS */
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
2024-10-03 19:50 [PATCH 0/5] Add new headers for Hyper-V Dom0 Nuno Das Neves
` (3 preceding siblings ...)
2024-10-03 19:51 ` [PATCH 4/5] hyperv: Add hv_defs.h to conditionally include hyperv-tlfs.h or hvhdk.h Nuno Das Neves
@ 2024-10-03 19:51 ` Nuno Das Neves
2024-10-04 15:58 ` Stanislav Kinsburskii
` (3 more replies)
2024-10-07 16:26 ` [PATCH 0/5] Add new headers for Hyper-V Dom0 Wei Liu
` (2 subsequent siblings)
7 siblings, 4 replies; 27+ messages in thread
From: Nuno Das Neves @ 2024-10-03 19:51 UTC (permalink / raw)
To: linux-hyperv, linux-arm-kernel, linux-kernel, kvm, iommu, netdev,
linux-pci, linux-arch, virtualization
Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, luto, tglx,
mingo, bp, dave.hansen, x86, hpa, seanjc, pbonzini, peterz,
daniel.lezcano, joro, robin.murphy, davem, edumazet, kuba, pabeni,
lpieralisi, kw, robh, bhelgaas, arnd, sgarzare, jinankjain,
muminulrussell, skinsburskii, mukeshrathor
To move toward importing headers from Hyper-V directly, switch to
using hvhdk.h in all Hyper-V code. KVM code that uses Hyper-V
definitions from hyperv-tlfs.h remains untouched.
Add HYPERV_NONTLFS_HEADERS everywhere mshyperv.h, asm/svm.h,
clocksource/hyperv_timer.h is included in Hyper-V code.
Replace hyperv-tlfs.h with hvhdk.h directly in linux/hyperv.h, and
define HYPERV_NONTLFS_HEADERS there, since it is only used in
Hyper-V device code.
Update a couple of definitions to updated names found in the new
headers: HV_EXT_MEM_HEAT_HINT, HV_SUBNODE_TYPE_ANY.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
arch/arm64/hyperv/hv_core.c | 1 +
arch/arm64/hyperv/mshyperv.c | 1 +
arch/x86/entry/vdso/vma.c | 1 +
arch/x86/hyperv/hv_apic.c | 1 +
arch/x86/hyperv/hv_init.c | 1 +
arch/x86/hyperv/hv_proc.c | 3 ++-
arch/x86/hyperv/hv_spinlock.c | 1 +
arch/x86/hyperv/hv_vtl.c | 1 +
arch/x86/hyperv/irqdomain.c | 1 +
arch/x86/hyperv/ivm.c | 1 +
arch/x86/hyperv/mmu.c | 1 +
arch/x86/hyperv/nested.c | 1 +
arch/x86/include/asm/vdso/gettimeofday.h | 1 +
arch/x86/kernel/cpu/mshyperv.c | 1 +
arch/x86/kernel/cpu/mtrr/generic.c | 1 +
drivers/clocksource/hyperv_timer.c | 1 +
drivers/hv/channel.c | 1 +
drivers/hv/channel_mgmt.c | 1 +
drivers/hv/connection.c | 1 +
drivers/hv/hv.c | 1 +
drivers/hv/hv_balloon.c | 3 ++-
drivers/hv/hv_common.c | 1 +
drivers/hv/hv_util.c | 1 +
drivers/hv/ring_buffer.c | 1 +
drivers/hv/vmbus_drv.c | 1 +
drivers/iommu/hyperv-iommu.c | 1 +
drivers/net/hyperv/netvsc.c | 1 +
drivers/pci/controller/pci-hyperv.c | 1 +
include/linux/hyperv.h | 3 ++-
29 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/hyperv/hv_core.c b/arch/arm64/hyperv/hv_core.c
index 9d1969b875e9..bb7f28f74bf4 100644
--- a/arch/arm64/hyperv/hv_core.c
+++ b/arch/arm64/hyperv/hv_core.c
@@ -14,6 +14,7 @@
#include <linux/arm-smccc.h>
#include <linux/module.h>
#include <asm-generic/bug.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
/*
diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c
index b1a4de4eee29..62b2a270ae65 100644
--- a/arch/arm64/hyperv/mshyperv.c
+++ b/arch/arm64/hyperv/mshyperv.c
@@ -15,6 +15,7 @@
#include <linux/errno.h>
#include <linux/version.h>
#include <linux/cpuhotplug.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
static bool hyperv_initialized;
diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
index 6d83ceb7f1ba..5f4053c49658 100644
--- a/arch/x86/entry/vdso/vma.c
+++ b/arch/x86/entry/vdso/vma.c
@@ -25,6 +25,7 @@
#include <asm/page.h>
#include <asm/desc.h>
#include <asm/cpufeature.h>
+#define HYPERV_NONTLFS_HEADERS
#include <clocksource/hyperv_timer.h>
#undef _ASM_X86_VVAR_H
diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
index f022d5f64fb6..4fe3b3b13256 100644
--- a/arch/x86/hyperv/hv_apic.c
+++ b/arch/x86/hyperv/hv_apic.c
@@ -26,6 +26,7 @@
#include <linux/slab.h>
#include <linux/cpuhotplug.h>
#include <asm/hypervisor.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include <asm/apic.h>
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index fc3c3d76c181..680c4abc456e 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -19,6 +19,7 @@
#include <asm/sev.h>
#include <asm/ibt.h>
#include <asm/hypervisor.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include <asm/idtentry.h>
#include <asm/set_memory.h>
diff --git a/arch/x86/hyperv/hv_proc.c b/arch/x86/hyperv/hv_proc.c
index b74c06c04ff1..428542134b84 100644
--- a/arch/x86/hyperv/hv_proc.c
+++ b/arch/x86/hyperv/hv_proc.c
@@ -7,6 +7,7 @@
#include <linux/cpuhotplug.h>
#include <linux/minmax.h>
#include <asm/hypervisor.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include <asm/apic.h>
@@ -176,7 +177,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
input->partition_id = partition_id;
input->vp_index = vp_index;
input->flags = flags;
- input->subnode_type = HvSubnodeAny;
+ input->subnode_type = HV_SUBNODE_ANY;
input->proximity_domain_info = hv_numa_node_to_pxm_info(node);
status = hv_do_hypercall(HVCALL_CREATE_VP, input, NULL);
local_irq_restore(irq_flags);
diff --git a/arch/x86/hyperv/hv_spinlock.c b/arch/x86/hyperv/hv_spinlock.c
index 151e851bef09..7e8e2c03f669 100644
--- a/arch/x86/hyperv/hv_spinlock.c
+++ b/arch/x86/hyperv/hv_spinlock.c
@@ -12,6 +12,7 @@
#include <linux/spinlock.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include <asm/paravirt.h>
#include <asm/apic.h>
diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c
index 04775346369c..a8bb6ad7efb6 100644
--- a/arch/x86/hyperv/hv_vtl.c
+++ b/arch/x86/hyperv/hv_vtl.c
@@ -10,6 +10,7 @@
#include <asm/boot.h>
#include <asm/desc.h>
#include <asm/i8259.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include <asm/realmode.h>
#include <../kernel/smpboot.h>
diff --git a/arch/x86/hyperv/irqdomain.c b/arch/x86/hyperv/irqdomain.c
index 3215a4a07408..977f90d08471 100644
--- a/arch/x86/hyperv/irqdomain.c
+++ b/arch/x86/hyperv/irqdomain.c
@@ -10,6 +10,7 @@
#include <linux/pci.h>
#include <linux/irq.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
static int hv_map_interrupt(union hv_device_id device_id, bool level,
diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
index b56d70612734..557a308e8e0a 100644
--- a/arch/x86/hyperv/ivm.c
+++ b/arch/x86/hyperv/ivm.c
@@ -9,6 +9,7 @@
#include <linux/bitfield.h>
#include <linux/types.h>
#include <linux/slab.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/svm.h>
#include <asm/sev.h>
#include <asm/io.h>
diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c
index cc8c3bd0e7c2..6bf9915611b8 100644
--- a/arch/x86/hyperv/mmu.c
+++ b/arch/x86/hyperv/mmu.c
@@ -5,6 +5,7 @@
#include <linux/types.h>
#include <asm/fpu/api.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include <asm/msr.h>
#include <asm/tlbflush.h>
diff --git a/arch/x86/hyperv/nested.c b/arch/x86/hyperv/nested.c
index ee06d0315c24..03775d72b7f9 100644
--- a/arch/x86/hyperv/nested.c
+++ b/arch/x86/hyperv/nested.c
@@ -11,6 +11,7 @@
#include <linux/types.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include <asm/tlbflush.h>
diff --git a/arch/x86/include/asm/vdso/gettimeofday.h b/arch/x86/include/asm/vdso/gettimeofday.h
index b2d2df026f6e..528ac66e366b 100644
--- a/arch/x86/include/asm/vdso/gettimeofday.h
+++ b/arch/x86/include/asm/vdso/gettimeofday.h
@@ -18,6 +18,7 @@
#include <asm/unistd.h>
#include <asm/msr.h>
#include <asm/pvclock.h>
+#define HYPERV_NONTLFS_HEADERS
#include <clocksource/hyperv_timer.h>
#define __vdso_data (VVAR(_vdso_data))
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 8e8fd23b1439..59bb8ab93dc2 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -20,6 +20,7 @@
#include <linux/random.h>
#include <asm/processor.h>
#include <asm/hypervisor.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include <asm/desc.h>
#include <asm/idtentry.h>
diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
index 7b29ebda024f..22228f2f550d 100644
--- a/arch/x86/kernel/cpu/mtrr/generic.c
+++ b/arch/x86/kernel/cpu/mtrr/generic.c
@@ -13,6 +13,7 @@
#include <asm/cacheinfo.h>
#include <asm/cpufeature.h>
#include <asm/hypervisor.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include <asm/tlbflush.h>
#include <asm/mtrr.h>
diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
index 1b7de45a7185..ec37476c4e15 100644
--- a/drivers/clocksource/hyperv_timer.c
+++ b/drivers/clocksource/hyperv_timer.c
@@ -22,6 +22,7 @@
#include <linux/irq.h>
#include <linux/acpi.h>
#include <linux/hyperv.h>
+#define HYPERV_NONTLFS_HEADERS
#include <clocksource/hyperv_timer.h>
#include <asm/mshyperv.h>
diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index fb8cd8469328..76d3c27e961e 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -19,6 +19,7 @@
#include <linux/interrupt.h>
#include <linux/set_memory.h>
#include <asm/page.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include "hyperv_vmbus.h"
diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 3c6011a48dab..e6d56c73175a 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -20,6 +20,7 @@
#include <linux/delay.h>
#include <linux/cpu.h>
#include <linux/hyperv.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include <linux/sched/isolation.h>
diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index f001ae880e1d..88546b0c2242 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -21,6 +21,7 @@
#include <linux/export.h>
#include <linux/io.h>
#include <linux/set_memory.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include "hyperv_vmbus.h"
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index e0d676c74f14..42f3790656e2 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -18,6 +18,7 @@
#include <linux/clockchips.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
+#define HYPERV_NONTLFS_HEADERS
#include <clocksource/hyperv_timer.h>
#include <asm/mshyperv.h>
#include <linux/set_memory.h>
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index a120e9b80ded..6b270ee75747 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -28,6 +28,7 @@
#include <linux/sizes.h>
#include <linux/hyperv.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#define CREATE_TRACE_POINTS
@@ -1583,7 +1584,7 @@ static int hv_free_page_report(struct page_reporting_dev_info *pr_dev_info,
return -ENOSPC;
}
- hint->type = HV_EXT_MEMORY_HEAT_HINT_TYPE_COLD_DISCARD;
+ hint->heat_type = HV_EXTMEM_HEAT_HINT_COLD_DISCARD;
hint->reserved = 0;
for_each_sg(sgl, sg, nents, i) {
union hv_gpa_page_range *range;
diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index a5217f837237..2723711868bc 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -28,6 +28,7 @@
#include <linux/slab.h>
#include <linux/dma-map-ops.h>
#include <linux/set_memory.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
/*
diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c
index c4f525325790..a17f6e6024a4 100644
--- a/drivers/hv/hv_util.c
+++ b/drivers/hv/hv_util.c
@@ -17,6 +17,7 @@
#include <linux/hyperv.h>
#include <linux/clockchips.h>
#include <linux/ptp_clock_kernel.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include "hyperv_vmbus.h"
diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 3c9b02471760..6bfd064b4e65 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -18,6 +18,7 @@
#include <linux/slab.h>
#include <linux/prefetch.h>
#include <linux/io.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include "hyperv_vmbus.h"
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 7242c4920427..71745d62e064 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -36,6 +36,7 @@
#include <linux/syscore_ops.h>
#include <linux/dma-map-ops.h>
#include <linux/pci.h>
+#define HYPERV_NONTLFS_HEADERS
#include <clocksource/hyperv_timer.h>
#include <asm/mshyperv.h>
#include "hyperv_vmbus.h"
diff --git a/drivers/iommu/hyperv-iommu.c b/drivers/iommu/hyperv-iommu.c
index 8a5c17b97310..ade14cc9c071 100644
--- a/drivers/iommu/hyperv-iommu.c
+++ b/drivers/iommu/hyperv-iommu.c
@@ -20,6 +20,7 @@
#include <asm/io_apic.h>
#include <asm/irq_remapping.h>
#include <asm/hypervisor.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include "irq_remapping.h"
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 2b6ec979a62f..55095c02cc78 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -23,6 +23,7 @@
#include <linux/filter.h>
#include <asm/sync_bitops.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
#include "hyperv_net.h"
diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
index cdd5be16021d..261ff8b80caa 100644
--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -50,6 +50,7 @@
#include <linux/irqdomain.h>
#include <linux/acpi.h>
#include <linux/sizes.h>
+#define HYPERV_NONTLFS_HEADERS
#include <asm/mshyperv.h>
/*
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index d0893ec488ae..64fd385723fc 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -24,7 +24,8 @@
#include <linux/mod_devicetable.h>
#include <linux/interrupt.h>
#include <linux/reciprocal_div.h>
-#include <asm/hyperv-tlfs.h>
+#include <hyperv/hvhdk.h>
+#define HYPERV_NONTLFS_HEADERS
#define MAX_PAGE_BUFFER_COUNT 32
#define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
2024-10-03 19:51 ` [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code Nuno Das Neves
@ 2024-10-04 15:58 ` Stanislav Kinsburskii
2024-10-05 0:07 ` Nuno Das Neves
2024-10-04 19:11 ` Simon Horman
` (2 subsequent siblings)
3 siblings, 1 reply; 27+ messages in thread
From: Stanislav Kinsburskii @ 2024-10-04 15:58 UTC (permalink / raw)
To: Nuno Das Neves
Cc: linux-hyperv, linux-arm-kernel, linux-kernel, kvm, iommu, netdev,
linux-pci, linux-arch, virtualization, kys, haiyangz, wei.liu,
decui, catalin.marinas, will, luto, tglx, mingo, bp, dave.hansen,
x86, hpa, seanjc, pbonzini, peterz, daniel.lezcano, joro,
robin.murphy, davem, edumazet, kuba, pabeni, lpieralisi, kw, robh,
bhelgaas, arnd, sgarzare, jinankjain, muminulrussell,
mukeshrathor
Hi Nuno,
On Thu, Oct 03, 2024 at 12:51:04PM -0700, Nuno Das Neves wrote:
> diff --git a/arch/arm64/hyperv/hv_core.c b/arch/arm64/hyperv/hv_core.c
> index 9d1969b875e9..bb7f28f74bf4 100644
> --- a/arch/arm64/hyperv/hv_core.c
> +++ b/arch/arm64/hyperv/hv_core.c
> @@ -14,6 +14,7 @@
> #include <linux/arm-smccc.h>
> #include <linux/module.h>
> #include <asm-generic/bug.h>
> +#define HYPERV_NONTLFS_HEADERS
> #include <asm/mshyperv.h>
>
Perhaps it would be cleaner to introduce a new header file to be
included, containing the new define and including <asm/mshyperv.h> instead.
Stas
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
2024-10-03 19:51 ` [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code Nuno Das Neves
2024-10-04 15:58 ` Stanislav Kinsburskii
@ 2024-10-04 19:11 ` Simon Horman
2024-10-04 23:36 ` Nuno Das Neves
2024-10-04 21:55 ` kernel test robot
2024-10-05 1:54 ` kernel test robot
3 siblings, 1 reply; 27+ messages in thread
From: Simon Horman @ 2024-10-04 19:11 UTC (permalink / raw)
To: Nuno Das Neves
Cc: linux-hyperv, linux-arm-kernel, linux-kernel, kvm, iommu, netdev,
linux-pci, linux-arch, virtualization, kys, haiyangz, wei.liu,
decui, catalin.marinas, will, luto, tglx, mingo, bp, dave.hansen,
x86, hpa, seanjc, pbonzini, peterz, daniel.lezcano, joro,
robin.murphy, davem, edumazet, kuba, pabeni, lpieralisi, kw, robh,
bhelgaas, arnd, sgarzare, jinankjain, muminulrussell,
skinsburskii, mukeshrathor
On Thu, Oct 03, 2024 at 12:51:04PM -0700, Nuno Das Neves wrote:
> To move toward importing headers from Hyper-V directly, switch to
> using hvhdk.h in all Hyper-V code. KVM code that uses Hyper-V
> definitions from hyperv-tlfs.h remains untouched.
>
> Add HYPERV_NONTLFS_HEADERS everywhere mshyperv.h, asm/svm.h,
> clocksource/hyperv_timer.h is included in Hyper-V code.
>
> Replace hyperv-tlfs.h with hvhdk.h directly in linux/hyperv.h, and
> define HYPERV_NONTLFS_HEADERS there, since it is only used in
> Hyper-V device code.
>
> Update a couple of definitions to updated names found in the new
> headers: HV_EXT_MEM_HEAT_HINT, HV_SUBNODE_TYPE_ANY.
>
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
...
> diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c
> index b1a4de4eee29..62b2a270ae65 100644
> --- a/arch/arm64/hyperv/mshyperv.c
> +++ b/arch/arm64/hyperv/mshyperv.c
> @@ -15,6 +15,7 @@
> #include <linux/errno.h>
> #include <linux/version.h>
> #include <linux/cpuhotplug.h>
> +#define HYPERV_NONTLFS_HEADERS
> #include <asm/mshyperv.h>
>
> static bool hyperv_initialized;
Hi,
With this change in place I see allmodconfig x86_64 builds reporting that
HV_REGISTER_FEATURES is undeclared.
arch/arm64/hyperv/mshyperv.c: In function 'hyperv_init':
arch/arm64/hyperv/mshyperv.c:53:26: error: 'HV_REGISTER_FEATURES' undeclared (first use in this function); did you mean 'HV_REGISTER_FEATURES_INFO'?
53 | hv_get_vpreg_128(HV_REGISTER_FEATURES, &result);
| ^~~~~~~~~~~~~~~~~~~~
| HV_REGISTER_FEATURES_INFO
arch/arm64/hyperv/mshyperv.c:53:26: note: each undeclared identifier is reported only once for each function it appears in
arch/arm64/hyperv/mshyperv.c:58:26: error: 'HV_REGISTER_ENLIGHTENMENTS' undeclared (first use in this function); did you mean 'HV_ACCESS_REENLIGHTENMENT'?
58 | hv_get_vpreg_128(HV_REGISTER_ENLIGHTENMENTS, &result);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
| HV_ACCESS_REENLIGHTENMENT
> diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
> index 6d83ceb7f1ba..5f4053c49658 100644
> --- a/arch/x86/entry/vdso/vma.c
> +++ b/arch/x86/entry/vdso/vma.c
> @@ -25,6 +25,7 @@
> #include <asm/page.h>
> #include <asm/desc.h>
> #include <asm/cpufeature.h>
> +#define HYPERV_NONTLFS_HEADERS
> #include <clocksource/hyperv_timer.h>
>
> #undef _ASM_X86_VVAR_H
> diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
> index f022d5f64fb6..4fe3b3b13256 100644
> --- a/arch/x86/hyperv/hv_apic.c
> +++ b/arch/x86/hyperv/hv_apic.c
> @@ -26,6 +26,7 @@
> #include <linux/slab.h>
> #include <linux/cpuhotplug.h>
> #include <asm/hypervisor.h>
> +#define HYPERV_NONTLFS_HEADERS
> #include <asm/mshyperv.h>
> #include <asm/apic.h>
>
> diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> index fc3c3d76c181..680c4abc456e 100644
> --- a/arch/x86/hyperv/hv_init.c
> +++ b/arch/x86/hyperv/hv_init.c
> @@ -19,6 +19,7 @@
> #include <asm/sev.h>
> #include <asm/ibt.h>
> #include <asm/hypervisor.h>
> +#define HYPERV_NONTLFS_HEADERS
> #include <asm/mshyperv.h>
> #include <asm/idtentry.h>
> #include <asm/set_memory.h>
And here too, with x86_64 allmodconfig.
In file included from ./include/linux/string.h:390,
from ./include/linux/efi.h:16,
from arch/x86/hyperv/hv_init.c:12:
arch/x86/hyperv/hv_init.c: In function 'get_vtl':
./include/linux/overflow.h:372:23: error: invalid application of 'sizeof' to incomplete type 'struct hv_get_vp_registers_input'
372 | sizeof(*(p)) + flex_array_size(p, member, count), \
| ^
./include/linux/fortify-string.h:502:42: note: in definition of macro '__fortify_memset_chk'
502 | size_t __fortify_size = (size_t)(size); \
| ^~~~
arch/x86/hyperv/hv_init.c:427:9: note: in expansion of macro 'memset'
427 | memset(input, 0, struct_size(input, element, 1));
| ^~~~~~
arch/x86/hyperv/hv_init.c:427:26: note: in expansion of macro 'struct_size'
427 | memset(input, 0, struct_size(input, element, 1));
| ^~~~~~~~~~~
[errors trimmed for the sake of brevity]
...
> diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c
> index 04775346369c..a8bb6ad7efb6 100644
> --- a/arch/x86/hyperv/hv_vtl.c
> +++ b/arch/x86/hyperv/hv_vtl.c
> @@ -10,6 +10,7 @@
> #include <asm/boot.h>
> #include <asm/desc.h>
> #include <asm/i8259.h>
> +#define HYPERV_NONTLFS_HEADERS
> #include <asm/mshyperv.h>
> #include <asm/realmode.h>
> #include <../kernel/smpboot.h>
And, likewise, with this patch applied I see a number of errors when
compiling this file. This is with allmodconfig on x86_64 with:
Modified: CONFIG_HYPERV=y (instead of m)
Added: CONFIG_HYPERV_VTL_MODE=y
arch/x86/hyperv/hv_vtl.c: In function 'hv_vtl_bringup_vcpu':
arch/x86/hyperv/hv_vtl.c:154:34: error: 'HVCALL_ENABLE_VP_VTL' undeclared (first use in this function)
154 | status = hv_do_hypercall(HVCALL_ENABLE_VP_VTL, input, NULL);
| ^~~~~~~~~~~~~~~~~~~~
arch/x86/hyperv/hv_vtl.c:154:34: note: each undeclared identifier is reported only once for each function it appears in
In file included from ./include/linux/string.h:390,
from ./include/linux/bitmap.h:13,
from ./include/linux/cpumask.h:12,
from ./arch/x86/include/asm/apic.h:5,
from arch/x86/hyperv/hv_vtl.c:9:
arch/x86/hyperv/hv_vtl.c: In function 'hv_vtl_apicid_to_vp_id':
arch/x86/hyperv/hv_vtl.c:189:32: error: invalid application of 'sizeof' to incomplete type 'struct hv_get_vp_from_apic_id_in'
189 | memset(input, 0, sizeof(*input));
| ^
./include/linux/fortify-string.h:502:42: note: in definition of macro '__fortify_memset_chk'
502 | size_t __fortify_size = (size_t)(size); \
| ^~~~
arch/x86/hyperv/hv_vtl.c:189:9: note: in expansion of macro 'memset'
189 | memset(input, 0, sizeof(*input));
| ^~~~~~
arch/x86/hyperv/hv_vtl.c:190:14: error: invalid use of undefined type 'struct hv_get_vp_from_apic_id_in'
190 | input->partition_id = HV_PARTITION_ID_SELF;
| ^~
arch/x86/hyperv/hv_vtl.c:191:14: error: invalid use of undefined type 'struct hv_get_vp_from_apic_id_in'
191 | input->apic_ids[0] = apic_id;
| ^~
arch/x86/hyperv/hv_vtl.c:195:45: error: 'HVCALL_GET_VP_ID_FROM_APIC_ID' undeclared (first use in this function)
195 | control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_ID_FROM_APIC_ID;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
2024-10-03 19:51 ` [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code Nuno Das Neves
2024-10-04 15:58 ` Stanislav Kinsburskii
2024-10-04 19:11 ` Simon Horman
@ 2024-10-04 21:55 ` kernel test robot
2024-10-05 1:54 ` kernel test robot
3 siblings, 0 replies; 27+ messages in thread
From: kernel test robot @ 2024-10-04 21:55 UTC (permalink / raw)
To: Nuno Das Neves, linux-hyperv, linux-arm-kernel, linux-kernel, kvm,
iommu, netdev, linux-pci, linux-arch, virtualization
Cc: oe-kbuild-all, kys, haiyangz, wei.liu, decui, catalin.marinas,
will, luto, tglx, mingo, bp, dave.hansen, x86, hpa, seanjc,
pbonzini, peterz, daniel.lezcano, joro, robin.murphy, davem,
edumazet
Hi Nuno,
kernel test robot noticed the following build errors:
[auto build test ERROR on tip/x86/core]
[also build test ERROR on arm64/for-next/core kvm/queue linus/master v6.12-rc1 next-20241004]
[cannot apply to kvm/linux-next]
[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-Move-hv_connection_id-to-hyperv-tlfs-h/20241004-035418
base: tip/x86/core
patch link: https://lore.kernel.org/r/1727985064-18362-6-git-send-email-nunodasneves%40linux.microsoft.com
patch subject: [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
config: x86_64-allmodconfig (https://download.01.org/0day-ci/archive/20241005/202410050518.LFXqJEpd-lkp@intel.com/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241005/202410050518.LFXqJEpd-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410050518.LFXqJEpd-lkp@intel.com/
All errors (new ones prefixed by >>):
>> arch/x86/hyperv/hv_init.c:428:19: error: invalid application of 'sizeof' to an incomplete type 'struct hv_get_vp_registers_input'
428 | memset(input, 0, struct_size(input, element, 1));
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:372:9: note: expanded from macro 'struct_size'
372 | sizeof(*(p)) + flex_array_size(p, member, count), \
| ^
include/linux/fortify-string.h:512:52: note: expanded from macro 'memset'
512 | #define memset(p, c, s) __fortify_memset_chk(p, c, s, \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
513 | __struct_size(p), __member_size(p))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/fortify-string.h:502:35: note: expanded from macro '__fortify_memset_chk'
502 | size_t __fortify_size = (size_t)(size); \
| ^~~~
arch/x86/hyperv/hv_init.c:419:9: note: forward declaration of 'struct hv_get_vp_registers_input'
419 | struct hv_get_vp_registers_input *input;
| ^
>> arch/x86/hyperv/hv_init.c:428:19: error: incomplete definition of type 'struct hv_get_vp_registers_input'
428 | memset(input, 0, struct_size(input, element, 1));
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:372:18: note: expanded from macro 'struct_size'
372 | sizeof(*(p)) + flex_array_size(p, member, count), \
| ^
include/linux/overflow.h:356:24: note: expanded from macro 'flex_array_size'
356 | (count) * sizeof(*(p)->member) + __must_be_array((p)->member), \
| ^
include/linux/fortify-string.h:512:52: note: expanded from macro 'memset'
512 | #define memset(p, c, s) __fortify_memset_chk(p, c, s, \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
513 | __struct_size(p), __member_size(p))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/fortify-string.h:502:35: note: expanded from macro '__fortify_memset_chk'
502 | size_t __fortify_size = (size_t)(size); \
| ^~~~
arch/x86/hyperv/hv_init.c:419:9: note: forward declaration of 'struct hv_get_vp_registers_input'
419 | struct hv_get_vp_registers_input *input;
| ^
>> arch/x86/hyperv/hv_init.c:428:19: error: incomplete definition of type 'struct hv_get_vp_registers_input'
428 | memset(input, 0, struct_size(input, element, 1));
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:372:18: note: expanded from macro 'struct_size'
372 | sizeof(*(p)) + flex_array_size(p, member, count), \
| ^
include/linux/overflow.h:356:55: note: expanded from macro 'flex_array_size'
356 | (count) * sizeof(*(p)->member) + __must_be_array((p)->member), \
| ^
include/linux/compiler.h:243:59: note: expanded from macro '__must_be_array'
243 | #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
| ^
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/build_bug.h:16:62: note: expanded from macro 'BUILD_BUG_ON_ZERO'
16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/fortify-string.h:512:52: note: expanded from macro 'memset'
512 | #define memset(p, c, s) __fortify_memset_chk(p, c, s, \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
513 | __struct_size(p), __member_size(p))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/fortify-string.h:502:35: note: expanded from macro '__fortify_memset_chk'
502 | size_t __fortify_size = (size_t)(size); \
| ^~~~
arch/x86/hyperv/hv_init.c:419:9: note: forward declaration of 'struct hv_get_vp_registers_input'
419 | struct hv_get_vp_registers_input *input;
| ^
>> arch/x86/hyperv/hv_init.c:428:19: error: incomplete definition of type 'struct hv_get_vp_registers_input'
428 | memset(input, 0, struct_size(input, element, 1));
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:372:18: note: expanded from macro 'struct_size'
372 | sizeof(*(p)) + flex_array_size(p, member, count), \
| ^
include/linux/overflow.h:357:30: note: expanded from macro 'flex_array_size'
357 | size_mul(count, sizeof(*(p)->member) + __must_be_array((p)->member)))
| ^
include/linux/fortify-string.h:512:52: note: expanded from macro 'memset'
512 | #define memset(p, c, s) __fortify_memset_chk(p, c, s, \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
513 | __struct_size(p), __member_size(p))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/fortify-string.h:502:35: note: expanded from macro '__fortify_memset_chk'
502 | size_t __fortify_size = (size_t)(size); \
| ^~~~
arch/x86/hyperv/hv_init.c:419:9: note: forward declaration of 'struct hv_get_vp_registers_input'
419 | struct hv_get_vp_registers_input *input;
| ^
>> arch/x86/hyperv/hv_init.c:428:19: error: incomplete definition of type 'struct hv_get_vp_registers_input'
428 | memset(input, 0, struct_size(input, element, 1));
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:372:18: note: expanded from macro 'struct_size'
372 | sizeof(*(p)) + flex_array_size(p, member, count), \
| ^
include/linux/overflow.h:357:61: note: expanded from macro 'flex_array_size'
357 | size_mul(count, sizeof(*(p)->member) + __must_be_array((p)->member)))
| ^
include/linux/compiler.h:243:59: note: expanded from macro '__must_be_array'
243 | #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
| ^
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/build_bug.h:16:62: note: expanded from macro 'BUILD_BUG_ON_ZERO'
16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/fortify-string.h:512:52: note: expanded from macro 'memset'
512 | #define memset(p, c, s) __fortify_memset_chk(p, c, s, \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
513 | __struct_size(p), __member_size(p))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/fortify-string.h:502:35: note: expanded from macro '__fortify_memset_chk'
502 | size_t __fortify_size = (size_t)(size); \
| ^~~~
arch/x86/hyperv/hv_init.c:419:9: note: forward declaration of 'struct hv_get_vp_registers_input'
419 | struct hv_get_vp_registers_input *input;
| ^
arch/x86/hyperv/hv_init.c:429:7: error: incomplete definition of type 'struct hv_get_vp_registers_input'
429 | input->header.partitionid = HV_PARTITION_ID_SELF;
| ~~~~~^
arch/x86/hyperv/hv_init.c:419:9: note: forward declaration of 'struct hv_get_vp_registers_input'
419 | struct hv_get_vp_registers_input *input;
| ^
arch/x86/hyperv/hv_init.c:430:7: error: incomplete definition of type 'struct hv_get_vp_registers_input'
430 | input->header.vpindex = HV_VP_INDEX_SELF;
| ~~~~~^
arch/x86/hyperv/hv_init.c:419:9: note: forward declaration of 'struct hv_get_vp_registers_input'
419 | struct hv_get_vp_registers_input *input;
| ^
arch/x86/hyperv/hv_init.c:431:7: error: incomplete definition of type 'struct hv_get_vp_registers_input'
431 | input->header.inputvtl = 0;
| ~~~~~^
arch/x86/hyperv/hv_init.c:419:9: note: forward declaration of 'struct hv_get_vp_registers_input'
419 | struct hv_get_vp_registers_input *input;
| ^
arch/x86/hyperv/hv_init.c:432:7: error: incomplete definition of type 'struct hv_get_vp_registers_input'
432 | input->element[0].name0 = HV_X64_REGISTER_VSM_VP_STATUS;
| ~~~~~^
arch/x86/hyperv/hv_init.c:419:9: note: forward declaration of 'struct hv_get_vp_registers_input'
419 | struct hv_get_vp_registers_input *input;
| ^
>> arch/x86/hyperv/hv_init.c:436:15: error: incomplete definition of type 'struct hv_get_vp_registers_output'
436 | ret = output->as64.low & HV_X64_VTL_MASK;
| ~~~~~~^
arch/x86/hyperv/hv_init.c:420:9: note: forward declaration of 'struct hv_get_vp_registers_output'
420 | struct hv_get_vp_registers_output *output;
| ^
10 errors generated.
--
>> arch/x86/hyperv/hv_vtl.c:154:27: error: use of undeclared identifier 'HVCALL_ENABLE_VP_VTL'
154 | status = hv_do_hypercall(HVCALL_ENABLE_VP_VTL, input, NULL);
| ^
>> arch/x86/hyperv/hv_vtl.c:189:25: error: invalid application of 'sizeof' to an incomplete type 'struct hv_get_vp_from_apic_id_in'
189 | memset(input, 0, sizeof(*input));
| ^~~~~~~~
include/linux/fortify-string.h:512:52: note: expanded from macro 'memset'
512 | #define memset(p, c, s) __fortify_memset_chk(p, c, s, \
| ^
include/linux/fortify-string.h:502:35: note: expanded from macro '__fortify_memset_chk'
502 | size_t __fortify_size = (size_t)(size); \
| ^~~~
arch/x86/hyperv/hv_vtl.c:183:9: note: forward declaration of 'struct hv_get_vp_from_apic_id_in'
183 | struct hv_get_vp_from_apic_id_in *input;
| ^
>> arch/x86/hyperv/hv_vtl.c:190:7: error: incomplete definition of type 'struct hv_get_vp_from_apic_id_in'
190 | input->partition_id = HV_PARTITION_ID_SELF;
| ~~~~~^
arch/x86/hyperv/hv_vtl.c:183:9: note: forward declaration of 'struct hv_get_vp_from_apic_id_in'
183 | struct hv_get_vp_from_apic_id_in *input;
| ^
arch/x86/hyperv/hv_vtl.c:191:7: error: incomplete definition of type 'struct hv_get_vp_from_apic_id_in'
191 | input->apic_ids[0] = apic_id;
| ~~~~~^
arch/x86/hyperv/hv_vtl.c:183:9: note: forward declaration of 'struct hv_get_vp_from_apic_id_in'
183 | struct hv_get_vp_from_apic_id_in *input;
| ^
>> arch/x86/hyperv/hv_vtl.c:195:38: error: use of undeclared identifier 'HVCALL_GET_VP_ID_FROM_APIC_ID'
195 | control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_ID_FROM_APIC_ID;
| ^
5 errors generated.
vim +428 arch/x86/hyperv/hv_init.c
99a0f46af6a771 Wei Liu 2021-02-03 414
f2a55d08d7e1a5 Saurabh Sengar 2023-09-19 415 #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
8387ce06d70bbb Tianyu Lan 2023-08-18 416 static u8 __init get_vtl(void)
8387ce06d70bbb Tianyu Lan 2023-08-18 417 {
8387ce06d70bbb Tianyu Lan 2023-08-18 418 u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS;
8387ce06d70bbb Tianyu Lan 2023-08-18 @419 struct hv_get_vp_registers_input *input;
8387ce06d70bbb Tianyu Lan 2023-08-18 420 struct hv_get_vp_registers_output *output;
8387ce06d70bbb Tianyu Lan 2023-08-18 421 unsigned long flags;
8387ce06d70bbb Tianyu Lan 2023-08-18 422 u64 ret;
8387ce06d70bbb Tianyu Lan 2023-08-18 423
8387ce06d70bbb Tianyu Lan 2023-08-18 424 local_irq_save(flags);
8387ce06d70bbb Tianyu Lan 2023-08-18 425 input = *this_cpu_ptr(hyperv_pcpu_input_arg);
8387ce06d70bbb Tianyu Lan 2023-08-18 426 output = (struct hv_get_vp_registers_output *)input;
8387ce06d70bbb Tianyu Lan 2023-08-18 427
8387ce06d70bbb Tianyu Lan 2023-08-18 @428 memset(input, 0, struct_size(input, element, 1));
8387ce06d70bbb Tianyu Lan 2023-08-18 429 input->header.partitionid = HV_PARTITION_ID_SELF;
8387ce06d70bbb Tianyu Lan 2023-08-18 430 input->header.vpindex = HV_VP_INDEX_SELF;
8387ce06d70bbb Tianyu Lan 2023-08-18 431 input->header.inputvtl = 0;
8387ce06d70bbb Tianyu Lan 2023-08-18 432 input->element[0].name0 = HV_X64_REGISTER_VSM_VP_STATUS;
8387ce06d70bbb Tianyu Lan 2023-08-18 433
8387ce06d70bbb Tianyu Lan 2023-08-18 434 ret = hv_do_hypercall(control, input, output);
8387ce06d70bbb Tianyu Lan 2023-08-18 435 if (hv_result_success(ret)) {
8387ce06d70bbb Tianyu Lan 2023-08-18 @436 ret = output->as64.low & HV_X64_VTL_MASK;
8387ce06d70bbb Tianyu Lan 2023-08-18 437 } else {
f2a55d08d7e1a5 Saurabh Sengar 2023-09-19 438 pr_err("Failed to get VTL(error: %lld) exiting...\n", ret);
f2a55d08d7e1a5 Saurabh Sengar 2023-09-19 439 BUG();
8387ce06d70bbb Tianyu Lan 2023-08-18 440 }
8387ce06d70bbb Tianyu Lan 2023-08-18 441
8387ce06d70bbb Tianyu Lan 2023-08-18 442 local_irq_restore(flags);
8387ce06d70bbb Tianyu Lan 2023-08-18 443 return ret;
8387ce06d70bbb Tianyu Lan 2023-08-18 444 }
f2a55d08d7e1a5 Saurabh Sengar 2023-09-19 445 #else
f2a55d08d7e1a5 Saurabh Sengar 2023-09-19 446 static inline u8 get_vtl(void) { return 0; }
f2a55d08d7e1a5 Saurabh Sengar 2023-09-19 447 #endif
8387ce06d70bbb Tianyu Lan 2023-08-18 448
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
2024-10-04 19:11 ` Simon Horman
@ 2024-10-04 23:36 ` Nuno Das Neves
0 siblings, 0 replies; 27+ messages in thread
From: Nuno Das Neves @ 2024-10-04 23:36 UTC (permalink / raw)
To: Simon Horman
Cc: linux-hyperv, linux-arm-kernel, linux-kernel, kvm, iommu, netdev,
linux-pci, linux-arch, virtualization, kys, haiyangz, wei.liu,
decui, catalin.marinas, will, luto, tglx, mingo, bp, dave.hansen,
x86, hpa, seanjc, pbonzini, peterz, daniel.lezcano, joro,
robin.murphy, davem, edumazet, kuba, pabeni, lpieralisi, kw, robh,
bhelgaas, arnd, sgarzare, jinankjain, muminulrussell,
skinsburskii, mukeshrathor
On 10/4/2024 12:11 PM, Simon Horman wrote:
> Hi,
>
> With this change in place I see allmodconfig x86_64 builds reporting that
> HV_REGISTER_FEATURES is undeclared.
>
> arch/arm64/hyperv/mshyperv.c: In function 'hyperv_init':
> arch/arm64/hyperv/mshyperv.c:53:26: error: 'HV_REGISTER_FEATURES' undeclared (first use in this function); did you mean 'HV_REGISTER_FEATURES_INFO'?
> 53 | hv_get_vpreg_128(HV_REGISTER_FEATURES, &result);
> | ^~~~~~~~~~~~~~~~~~~~
> | HV_REGISTER_FEATURES_INFO
> arch/arm64/hyperv/mshyperv.c:53:26: note: each undeclared identifier is reported only once for each function it appears in
> arch/arm64/hyperv/mshyperv.c:58:26: error: 'HV_REGISTER_ENLIGHTENMENTS' undeclared (first use in this function); did you mean 'HV_ACCESS_REENLIGHTENMENT'?
> 58 | hv_get_vpreg_128(HV_REGISTER_ENLIGHTENMENTS, &result);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~
> | HV_ACCESS_REENLIGHTENMENT
>
Ah, I did forgot to check arm64. Thanks for the catch, I'll be sure to
fix it for v2.
>
> And here too, with x86_64 allmodconfig.
>
> In file included from ./include/linux/string.h:390,
> from ./include/linux/efi.h:16,
> from arch/x86/hyperv/hv_init.c:12:
> arch/x86/hyperv/hv_init.c: In function 'get_vtl':
> ./include/linux/overflow.h:372:23: error: invalid application of 'sizeof' to incomplete type 'struct hv_get_vp_registers_input'
> 372 | sizeof(*(p)) + flex_array_size(p, member, count), \
> | ^
> ./include/linux/fortify-string.h:502:42: note: in definition of macro '__fortify_memset_chk'
> 502 | size_t __fortify_size = (size_t)(size); \
> | ^~~~
> arch/x86/hyperv/hv_init.c:427:9: note: in expansion of macro 'memset'
> 427 | memset(input, 0, struct_size(input, element, 1));
> | ^~~~~~
> arch/x86/hyperv/hv_init.c:427:26: note: in expansion of macro 'struct_size'
> 427 | memset(input, 0, struct_size(input, element, 1));
> | ^~~~~~~~~~~
>
> [errors trimmed for the sake of brevity]
>
> ...
>
Thanks
>
> And, likewise, with this patch applied I see a number of errors when
> compiling this file. This is with allmodconfig on x86_64 with:
>
> Modified: CONFIG_HYPERV=y (instead of m)
> Added: CONFIG_HYPERV_VTL_MODE=y
>
Thanks again,
Ah, I wish there was a way to check these different combinations of y/m
more easily.
> arch/x86/hyperv/hv_vtl.c: In function 'hv_vtl_bringup_vcpu':
> arch/x86/hyperv/hv_vtl.c:154:34: error: 'HVCALL_ENABLE_VP_VTL' undeclared (first use in this function)
> 154 | status = hv_do_hypercall(HVCALL_ENABLE_VP_VTL, input, NULL);
> | ^~~~~~~~~~~~~~~~~~~~
> arch/x86/hyperv/hv_vtl.c:154:34: note: each undeclared identifier is reported only once for each function it appears in
> In file included from ./include/linux/string.h:390,
> from ./include/linux/bitmap.h:13,
> from ./include/linux/cpumask.h:12,
> from ./arch/x86/include/asm/apic.h:5,
> from arch/x86/hyperv/hv_vtl.c:9:
> arch/x86/hyperv/hv_vtl.c: In function 'hv_vtl_apicid_to_vp_id':
> arch/x86/hyperv/hv_vtl.c:189:32: error: invalid application of 'sizeof' to incomplete type 'struct hv_get_vp_from_apic_id_in'
> 189 | memset(input, 0, sizeof(*input));
> | ^
> ./include/linux/fortify-string.h:502:42: note: in definition of macro '__fortify_memset_chk'
> 502 | size_t __fortify_size = (size_t)(size); \
> | ^~~~
> arch/x86/hyperv/hv_vtl.c:189:9: note: in expansion of macro 'memset'
> 189 | memset(input, 0, sizeof(*input));
> | ^~~~~~
> arch/x86/hyperv/hv_vtl.c:190:14: error: invalid use of undefined type 'struct hv_get_vp_from_apic_id_in'
> 190 | input->partition_id = HV_PARTITION_ID_SELF;
> | ^~
> arch/x86/hyperv/hv_vtl.c:191:14: error: invalid use of undefined type 'struct hv_get_vp_from_apic_id_in'
> 191 | input->apic_ids[0] = apic_id;
> | ^~
> arch/x86/hyperv/hv_vtl.c:195:45: error: 'HVCALL_GET_VP_ID_FROM_APIC_ID' undeclared (first use in this function)
> 195 | control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_ID_FROM_APIC_ID;
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ...
Looks like I'm missing a one or two definitions in the new headers, and the
names have changed slightly in couple of cases. I'll do some more thorough
checking and have it all fixed for v2.
I didn't know about this allmodconfig target, that will make it a bit easier!
Nuno
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
2024-10-04 15:58 ` Stanislav Kinsburskii
@ 2024-10-05 0:07 ` Nuno Das Neves
0 siblings, 0 replies; 27+ messages in thread
From: Nuno Das Neves @ 2024-10-05 0:07 UTC (permalink / raw)
To: Stanislav Kinsburskii
Cc: linux-hyperv, linux-arm-kernel, linux-kernel, kvm, iommu, netdev,
linux-pci, linux-arch, virtualization, kys, haiyangz, wei.liu,
decui, catalin.marinas, will, luto, tglx, mingo, bp, dave.hansen,
x86, hpa, seanjc, pbonzini, peterz, daniel.lezcano, joro,
robin.murphy, davem, edumazet, kuba, pabeni, lpieralisi, kw, robh,
bhelgaas, arnd, sgarzare, jinankjain, muminulrussell,
mukeshrathor
On 10/4/2024 8:58 AM, Stanislav Kinsburskii wrote:
> Hi Nuno,
>
> On Thu, Oct 03, 2024 at 12:51:04PM -0700, Nuno Das Neves wrote:
>> diff --git a/arch/arm64/hyperv/hv_core.c b/arch/arm64/hyperv/hv_core.c
>> index 9d1969b875e9..bb7f28f74bf4 100644
>> --- a/arch/arm64/hyperv/hv_core.c
>> +++ b/arch/arm64/hyperv/hv_core.c
>> @@ -14,6 +14,7 @@
>> #include <linux/arm-smccc.h>
>> #include <linux/module.h>
>> #include <asm-generic/bug.h>
>> +#define HYPERV_NONTLFS_HEADERS
>> #include <asm/mshyperv.h>
>>
>
> Perhaps it would be cleaner to introduce a new header file to be
> included, containing the new define and including <asm/mshyperv.h> instead.
>
> Stas
If I understand correctly, you're suggesting adding another stub named e.g.
"hv_mshyperv.h", containing:
#define HYPERV_NONTLFS_HEADERS
#include<asm/mshyperv.h>
Then in the roughly 24 places in this patch where we have:
+#define HYPERV_NONTLFS_HEADERS
Instead, we'd have:
-#include <asm/mshyperv.h>
+#include <hyperv/hv_mshyperv.h>
I suppose the current version is a bit opaque - it's not immediately clear
why HYPERV_NONTLFs_HEADERS is defined, and that it must be defined before
including asm/mshyperv.h - someone reading the code would have to go find
hv_defs.h to puzzle that out.
This improves the situation slightly by associating the #define with
asm/mshyperv.h. I'll consider it for v2, thanks!
Nuno
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
2024-10-03 19:51 ` [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code Nuno Das Neves
` (2 preceding siblings ...)
2024-10-04 21:55 ` kernel test robot
@ 2024-10-05 1:54 ` kernel test robot
3 siblings, 0 replies; 27+ messages in thread
From: kernel test robot @ 2024-10-05 1:54 UTC (permalink / raw)
To: Nuno Das Neves, linux-hyperv, linux-arm-kernel, linux-kernel, kvm,
iommu, netdev, linux-pci, linux-arch, virtualization
Cc: llvm, oe-kbuild-all, kys, haiyangz, wei.liu, decui,
catalin.marinas, will, luto, tglx, mingo, bp, dave.hansen, x86,
hpa, seanjc, pbonzini, peterz, daniel.lezcano, joro, robin.murphy,
davem, edumazet
Hi Nuno,
kernel test robot noticed the following build errors:
[auto build test ERROR on tip/x86/core]
[also build test ERROR on arm64/for-next/core kvm/queue linus/master v6.12-rc1 next-20241004]
[cannot apply to kvm/linux-next]
[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-Move-hv_connection_id-to-hyperv-tlfs-h/20241004-035418
base: tip/x86/core
patch link: https://lore.kernel.org/r/1727985064-18362-6-git-send-email-nunodasneves%40linux.microsoft.com
patch subject: [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20241005/202410050921.0o9FH5Ai-lkp@intel.com/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project fef3566a25ff0e34fb87339ba5e13eca17cec00f)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241005/202410050921.0o9FH5Ai-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410050921.0o9FH5Ai-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from arch/arm64/hyperv/mshyperv.c:13:
In file included from include/linux/acpi.h:39:
In file included from include/acpi/acpi_io.h:7:
In file included from arch/arm64/include/asm/acpi.h:14:
In file included from include/linux/memblock.h:12:
In file included from include/linux/mm.h:2228:
include/linux/vmstat.h:500:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
500 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
501 | item];
| ~~~~
include/linux/vmstat.h:507:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
507 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
508 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
include/linux/vmstat.h:514:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
514 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
| ~~~~~~~~~~~ ^ ~~~
include/linux/vmstat.h:519:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
519 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
520 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
include/linux/vmstat.h:528:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
528 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
529 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
>> arch/arm64/hyperv/mshyperv.c:53:19: error: use of undeclared identifier 'HV_REGISTER_FEATURES'; did you mean 'HV_REGISTER_FEATURES_INFO'?
53 | hv_get_vpreg_128(HV_REGISTER_FEATURES, &result);
| ^~~~~~~~~~~~~~~~~~~~
| HV_REGISTER_FEATURES_INFO
include/hyperv/hvgdk_mini.h:807:2: note: 'HV_REGISTER_FEATURES_INFO' declared here
807 | HV_REGISTER_FEATURES_INFO = 0x00000201,
| ^
>> arch/arm64/hyperv/mshyperv.c:58:19: error: use of undeclared identifier 'HV_REGISTER_ENLIGHTENMENTS'
58 | hv_get_vpreg_128(HV_REGISTER_ENLIGHTENMENTS, &result);
| ^
5 warnings and 2 errors generated.
vim +53 arch/arm64/hyperv/mshyperv.c
410779d8d81fcf Nuno Das Neves 2024-03-07 30
9bbb888824e38c Michael Kelley 2021-08-04 31 static int __init hyperv_init(void)
9bbb888824e38c Michael Kelley 2021-08-04 32 {
9bbb888824e38c Michael Kelley 2021-08-04 33 struct hv_get_vp_registers_output result;
9bbb888824e38c Michael Kelley 2021-08-04 34 u64 guest_id;
9bbb888824e38c Michael Kelley 2021-08-04 35 int ret;
9bbb888824e38c Michael Kelley 2021-08-04 36
9bbb888824e38c Michael Kelley 2021-08-04 37 /*
9bbb888824e38c Michael Kelley 2021-08-04 38 * Allow for a kernel built with CONFIG_HYPERV to be running in
9bbb888824e38c Michael Kelley 2021-08-04 39 * a non-Hyper-V environment, including on DT instead of ACPI.
9bbb888824e38c Michael Kelley 2021-08-04 40 * In such cases, do nothing and return success.
9bbb888824e38c Michael Kelley 2021-08-04 41 */
9bbb888824e38c Michael Kelley 2021-08-04 42 if (acpi_disabled)
9bbb888824e38c Michael Kelley 2021-08-04 43 return 0;
9bbb888824e38c Michael Kelley 2021-08-04 44
9bbb888824e38c Michael Kelley 2021-08-04 45 if (strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8))
9bbb888824e38c Michael Kelley 2021-08-04 46 return 0;
9bbb888824e38c Michael Kelley 2021-08-04 47
9bbb888824e38c Michael Kelley 2021-08-04 48 /* Setup the guest ID */
d5ebde1e2b4615 Li kunyu 2022-09-28 49 guest_id = hv_generate_guest_id(LINUX_VERSION_CODE);
b967df6293510b Nuno Das Neves 2024-03-12 50 hv_set_vpreg(HV_REGISTER_GUEST_OS_ID, guest_id);
9bbb888824e38c Michael Kelley 2021-08-04 51
9bbb888824e38c Michael Kelley 2021-08-04 52 /* Get the features and hints from Hyper-V */
9bbb888824e38c Michael Kelley 2021-08-04 @53 hv_get_vpreg_128(HV_REGISTER_FEATURES, &result);
9bbb888824e38c Michael Kelley 2021-08-04 54 ms_hyperv.features = result.as32.a;
9bbb888824e38c Michael Kelley 2021-08-04 55 ms_hyperv.priv_high = result.as32.b;
9bbb888824e38c Michael Kelley 2021-08-04 56 ms_hyperv.misc_features = result.as32.c;
9bbb888824e38c Michael Kelley 2021-08-04 57
9bbb888824e38c Michael Kelley 2021-08-04 @58 hv_get_vpreg_128(HV_REGISTER_ENLIGHTENMENTS, &result);
9bbb888824e38c Michael Kelley 2021-08-04 59 ms_hyperv.hints = result.as32.a;
9bbb888824e38c Michael Kelley 2021-08-04 60
9bbb888824e38c Michael Kelley 2021-08-04 61 pr_info("Hyper-V: privilege flags low 0x%x, high 0x%x, hints 0x%x, misc 0x%x\n",
9bbb888824e38c Michael Kelley 2021-08-04 62 ms_hyperv.features, ms_hyperv.priv_high, ms_hyperv.hints,
9bbb888824e38c Michael Kelley 2021-08-04 63 ms_hyperv.misc_features);
9bbb888824e38c Michael Kelley 2021-08-04 64
9bbb888824e38c Michael Kelley 2021-08-04 65 ret = hv_common_init();
9bbb888824e38c Michael Kelley 2021-08-04 66 if (ret)
9bbb888824e38c Michael Kelley 2021-08-04 67 return ret;
9bbb888824e38c Michael Kelley 2021-08-04 68
52ae076c3a9b36 Michael Kelley 2023-05-23 69 ret = cpuhp_setup_state(CPUHP_AP_HYPERV_ONLINE, "arm64/hyperv_init:online",
9bbb888824e38c Michael Kelley 2021-08-04 70 hv_common_cpu_init, hv_common_cpu_die);
9bbb888824e38c Michael Kelley 2021-08-04 71 if (ret < 0) {
9bbb888824e38c Michael Kelley 2021-08-04 72 hv_common_free();
9bbb888824e38c Michael Kelley 2021-08-04 73 return ret;
9bbb888824e38c Michael Kelley 2021-08-04 74 }
9bbb888824e38c Michael Kelley 2021-08-04 75
f2580a907e5c0e Michael Kelley 2024-03-18 76 ms_hyperv_late_init();
f2580a907e5c0e Michael Kelley 2024-03-18 77
9bbb888824e38c Michael Kelley 2021-08-04 78 hyperv_initialized = true;
9bbb888824e38c Michael Kelley 2021-08-04 79 return 0;
9bbb888824e38c Michael Kelley 2021-08-04 80 }
9bbb888824e38c Michael Kelley 2021-08-04 81
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 1/5] hyperv: Move hv_connection_id to hyperv-tlfs.h
2024-10-03 19:51 ` [PATCH 1/5] hyperv: Move hv_connection_id to hyperv-tlfs.h Nuno Das Neves
@ 2024-10-07 16:24 ` Wei Liu
0 siblings, 0 replies; 27+ messages in thread
From: Wei Liu @ 2024-10-07 16:24 UTC (permalink / raw)
To: Nuno Das Neves
Cc: linux-hyperv, linux-arm-kernel, linux-kernel, kvm, iommu, netdev,
linux-pci, linux-arch, virtualization, kys, haiyangz, wei.liu,
decui, catalin.marinas, will, luto, tglx, mingo, bp, dave.hansen,
x86, hpa, seanjc, pbonzini, peterz, daniel.lezcano, joro,
robin.murphy, davem, edumazet, kuba, pabeni, lpieralisi, kw, robh,
bhelgaas, arnd, sgarzare, jinankjain, muminulrussell,
skinsburskii, mukeshrathor
On Thu, Oct 03, 2024 at 12:51:00PM -0700, Nuno Das Neves wrote:
> This definition is in the wrong file; it is part of the TLFS doc.
>
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Acked-by: Wei Liu <wei.liu@kernel.org>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 2/5] hyperv: Remove unnecessary #includes
2024-10-03 19:51 ` [PATCH 2/5] hyperv: Remove unnecessary #includes Nuno Das Neves
@ 2024-10-07 16:24 ` Wei Liu
2024-10-10 18:21 ` Michael Kelley
1 sibling, 0 replies; 27+ messages in thread
From: Wei Liu @ 2024-10-07 16:24 UTC (permalink / raw)
To: Nuno Das Neves
Cc: linux-hyperv, linux-arm-kernel, linux-kernel, kvm, iommu, netdev,
linux-pci, linux-arch, virtualization, kys, haiyangz, wei.liu,
decui, catalin.marinas, will, luto, tglx, mingo, bp, dave.hansen,
x86, hpa, seanjc, pbonzini, peterz, daniel.lezcano, joro,
robin.murphy, davem, edumazet, kuba, pabeni, lpieralisi, kw, robh,
bhelgaas, arnd, sgarzare, jinankjain, muminulrussell,
skinsburskii, mukeshrathor
On Thu, Oct 03, 2024 at 12:51:01PM -0700, Nuno Das Neves wrote:
> asm/hyperv-tlfs.h is already included implicitly wherever mshyperv.h
> or linux/hyperv.h is included. Remove those redundancies.
>
> Remove includes of linux/hyperv.h and mshyperv.h where they are not
> needed.
>
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Acked-by: Wei Liu <wei.liu@kernel.org>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 0/5] Add new headers for Hyper-V Dom0
2024-10-03 19:50 [PATCH 0/5] Add new headers for Hyper-V Dom0 Nuno Das Neves
` (4 preceding siblings ...)
2024-10-03 19:51 ` [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code Nuno Das Neves
@ 2024-10-07 16:26 ` Wei Liu
2024-10-10 18:21 ` Michael Kelley
2024-10-31 19:05 ` Easwar Hariharan
7 siblings, 0 replies; 27+ messages in thread
From: Wei Liu @ 2024-10-07 16:26 UTC (permalink / raw)
To: Nuno Das Neves
Cc: linux-hyperv, linux-arm-kernel, linux-kernel, kvm, iommu, netdev,
linux-pci, linux-arch, virtualization, kys, haiyangz, wei.liu,
decui, catalin.marinas, will, luto, tglx, mingo, bp, dave.hansen,
x86, hpa, seanjc, pbonzini, peterz, daniel.lezcano, joro,
robin.murphy, davem, edumazet, kuba, pabeni, lpieralisi, kw, robh,
bhelgaas, arnd, sgarzare, jinankjain, muminulrussell,
skinsburskii, mukeshrathor
On Thu, Oct 03, 2024 at 12:50:59PM -0700, Nuno Das Neves wrote:
> To support Hyper-V Dom0 (aka Linux as root partition), many new
> definitions are required.
>
> The plan going forward is to directly import headers from
> Hyper-V. This is a more maintainable way to import definitions
> rather than via the TLFS doc. This patch series introduces
> new headers (hvhdk.h, hvgdk.h, etc, see patch #3) directly
> derived from Hyper-V code.
>
> This patch series replaces hyperv-tlfs.h with hvhdk.h, but only
> in Microsoft-maintained Hyper-V code where they are needed. This
> leaves the existing hyperv-tlfs.h in use elsewhere - notably for
> Hyper-V enlightenments on KVM guests.
It goes without saying that we need to make sure KVM still builds
correctly after this series. Please make sure to test that. Thanks.
Wei.
^ permalink raw reply [flat|nested] 27+ messages in thread
* RE: [PATCH 0/5] Add new headers for Hyper-V Dom0
2024-10-03 19:50 [PATCH 0/5] Add new headers for Hyper-V Dom0 Nuno Das Neves
` (5 preceding siblings ...)
2024-10-07 16:26 ` [PATCH 0/5] Add new headers for Hyper-V Dom0 Wei Liu
@ 2024-10-10 18:21 ` Michael Kelley
2024-10-11 1:34 ` [EXTERNAL] " MUKESH RATHOR
2024-10-23 0:51 ` Nuno Das Neves
2024-10-31 19:05 ` Easwar Hariharan
7 siblings, 2 replies; 27+ messages in thread
From: Michael Kelley @ 2024-10-10 18:21 UTC (permalink / raw)
To: Nuno Das Neves, linux-hyperv@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
iommu@lists.linux.dev, netdev@vger.kernel.org,
linux-pci@vger.kernel.org, linux-arch@vger.kernel.org,
virtualization@lists.linux.dev
Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
luto@kernel.org, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com,
peterz@infradead.org, daniel.lezcano@linaro.org, joro@8bytes.org,
robin.murphy@arm.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org,
kw@linux.com, robh@kernel.org, bhelgaas@google.com, arnd@arndb.de,
sgarzare@redhat.com, jinankjain@linux.microsoft.com,
muminulrussell@gmail.com, skinsburskii@linux.microsoft.com,
mukeshrathor@microsoft.com
From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, October 3, 2024 12:51 PM
>
> To support Hyper-V Dom0 (aka Linux as root partition), many new
> definitions are required.
>
> The plan going forward is to directly import headers from
> Hyper-V. This is a more maintainable way to import definitions
> rather than via the TLFS doc. This patch series introduces
> new headers (hvhdk.h, hvgdk.h, etc, see patch #3) directly
> derived from Hyper-V code.
>
> This patch series replaces hyperv-tlfs.h with hvhdk.h, but only
> in Microsoft-maintained Hyper-V code where they are needed. This
> leaves the existing hyperv-tlfs.h in use elsewhere - notably for
> Hyper-V enlightenments on KVM guests.
Could you elaborate on why the bifurcation is necessary? Is it an
interim step until the KVM code can use the new scheme as well?
Also, does "Hyper-V enlightenments on KVM guests" refer to
nested KVM running at L1 on an L0 Hyper-V, and supporting L2 guests?
Or is it the more general KVM support for mimicking Hyper-V for
the purposes of running Windows guests? From these patches, it
looks like your intention is for all KVM support for Hyper-V
functionality to continue to use the existing hyperv-tlfs.h file.
>
> An intermediary header "hv_defs.h" is introduced to conditionally
> include either hyperv-tlfs.h or hvhdk.h. This is required because
> several headers which today include hyperv-tlfs.h, are shared
> between Hyper-V and KVM code (e.g. mshyperv.h).
Have you considered user space code that uses
include/linux/hyperv.h? Which of the two schemes will it use? That code
needs to compile correctly on x86 and ARM64 after your changes.
User space code includes the separate DPDK project, and some of the
tools in the kernel tree under tools/hv. Anything that uses the
uio_hv_generic.c driver falls into this category.
I think there's also user space code that is built for vDSO that might pull
in the .h files you are modifying. There are in-progress patches dealing
with vDSO include files, such as [1]. My general comment on vDSO
is to be careful in making #include file changes that it uses, but I'm
not knowledgeable enough on how vDSO is built to give specific
guidance. :-(
Michael
[1] https://lore.kernel.org/lkml/20241010135146.181175-1-vincenzo.frascino@arm.com/
>
> Summary:
> Patch 1-2: Cleanup patches
> Patch 3: Add the new headers (hvhdk.h, etc..) in include/hyperv/
> Patch 4: Add hv_defs.h and use it in mshyperv.h, svm.h,
> hyperv_timer.h
> Patch 5: Switch to the new headers, only in Hyper-V code
>
> Nuno Das Neves (5):
> hyperv: Move hv_connection_id to hyperv-tlfs.h
> hyperv: Remove unnecessary #includes
> hyperv: Add new Hyper-V headers
> hyperv: Add hv_defs.h to conditionally include hyperv-tlfs.h or
> hvhdk.h
> hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
>
> arch/arm64/hyperv/hv_core.c | 3 +-
> arch/arm64/hyperv/mshyperv.c | 1 +
> arch/arm64/include/asm/mshyperv.h | 2 +-
> arch/x86/entry/vdso/vma.c | 1 +
> arch/x86/hyperv/hv_apic.c | 2 +-
> arch/x86/hyperv/hv_init.c | 3 +-
> arch/x86/hyperv/hv_proc.c | 4 +-
> arch/x86/hyperv/hv_spinlock.c | 1 +
> arch/x86/hyperv/hv_vtl.c | 1 +
> arch/x86/hyperv/irqdomain.c | 1 +
> arch/x86/hyperv/ivm.c | 2 +-
> arch/x86/hyperv/mmu.c | 2 +-
> arch/x86/hyperv/nested.c | 2 +-
> arch/x86/include/asm/kvm_host.h | 1 -
> arch/x86/include/asm/mshyperv.h | 3 +-
> arch/x86/include/asm/svm.h | 2 +-
> arch/x86/include/asm/vdso/gettimeofday.h | 1 +
> arch/x86/kernel/cpu/mshyperv.c | 2 +-
> arch/x86/kernel/cpu/mtrr/generic.c | 1 +
> arch/x86/kvm/vmx/vmx_onhyperv.h | 1 -
> arch/x86/mm/pat/set_memory.c | 2 -
> drivers/clocksource/hyperv_timer.c | 2 +-
> drivers/hv/channel.c | 1 +
> drivers/hv/channel_mgmt.c | 1 +
> drivers/hv/connection.c | 1 +
> drivers/hv/hv.c | 1 +
> drivers/hv/hv_balloon.c | 5 +-
> drivers/hv/hv_common.c | 2 +-
> drivers/hv/hv_kvp.c | 1 -
> drivers/hv/hv_snapshot.c | 1 -
> drivers/hv/hv_util.c | 1 +
> drivers/hv/hyperv_vmbus.h | 1 -
> drivers/hv/ring_buffer.c | 1 +
> drivers/hv/vmbus_drv.c | 1 +
> drivers/iommu/hyperv-iommu.c | 1 +
> drivers/net/hyperv/netvsc.c | 1 +
> drivers/pci/controller/pci-hyperv.c | 1 +
> include/asm-generic/hyperv-tlfs.h | 9 +
> include/asm-generic/mshyperv.h | 2 +-
> include/clocksource/hyperv_timer.h | 2 +-
> include/hyperv/hv_defs.h | 29 +
> include/hyperv/hvgdk.h | 66 ++
> include/hyperv/hvgdk_ext.h | 46 +
> include/hyperv/hvgdk_mini.h | 1212 ++++++++++++++++++++++
> include/hyperv/hvhdk.h | 733 +++++++++++++
> include/hyperv/hvhdk_mini.h | 310 ++++++
> include/linux/hyperv.h | 12 +-
> net/vmw_vsock/hyperv_transport.c | 1 -
> 48 files changed, 2442 insertions(+), 40 deletions(-)
> create mode 100644 include/hyperv/hv_defs.h
> create mode 100644 include/hyperv/hvgdk.h
> create mode 100644 include/hyperv/hvgdk_ext.h
> create mode 100644 include/hyperv/hvgdk_mini.h
> create mode 100644 include/hyperv/hvhdk.h
> create mode 100644 include/hyperv/hvhdk_mini.h
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* RE: [PATCH 2/5] hyperv: Remove unnecessary #includes
2024-10-03 19:51 ` [PATCH 2/5] hyperv: Remove unnecessary #includes Nuno Das Neves
2024-10-07 16:24 ` Wei Liu
@ 2024-10-10 18:21 ` Michael Kelley
2024-10-31 18:47 ` Nuno Das Neves
1 sibling, 1 reply; 27+ messages in thread
From: Michael Kelley @ 2024-10-10 18:21 UTC (permalink / raw)
To: Nuno Das Neves, linux-hyperv@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
iommu@lists.linux.dev, netdev@vger.kernel.org,
linux-pci@vger.kernel.org, linux-arch@vger.kernel.org,
virtualization@lists.linux.dev
Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
luto@kernel.org, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com,
peterz@infradead.org, daniel.lezcano@linaro.org, joro@8bytes.org,
robin.murphy@arm.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org,
kw@linux.com, robh@kernel.org, bhelgaas@google.com, arnd@arndb.de,
sgarzare@redhat.com, jinankjain@linux.microsoft.com,
muminulrussell@gmail.com, skinsburskii@linux.microsoft.com,
mukeshrathor@microsoft.com
From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, October 3, 2024 12:51 PM
>
> asm/hyperv-tlfs.h is already included implicitly wherever mshyperv.h
> or linux/hyperv.h is included. Remove those redundancies.
I've been under the impression that it is preferable to directly include
.h files for all definitions that a source code file uses, even if the
needed .h file is indirectly included by some other .h file. I looked through
the coding style documentation, and didn't find anything addressing
this topic, so maybe I'm wrong. But I know I've seen patches to other
parts of the kernel that were changes to follow the direct inclusion
approach. Direct inclusion is less fragile if the #include file nesting
structure changes (and perhaps removes the indirect inclusion).
The mshyperv.h and linux/hyperv.h dependency on hyperv-tlfs.h is
highly unlikely to change, so the chance of breakage is minimal. But
I wonder if your approach is going the wrong direction vs. preferred
kernel practices.
Michael
>
> Remove includes of linux/hyperv.h and mshyperv.h where they are not
> needed.
>
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> ---
> arch/arm64/hyperv/hv_core.c | 2 --
> arch/x86/hyperv/hv_apic.c | 1 -
> arch/x86/hyperv/hv_init.c | 2 --
> arch/x86/hyperv/hv_proc.c | 1 -
> arch/x86/hyperv/ivm.c | 1 -
> arch/x86/hyperv/mmu.c | 1 -
> arch/x86/hyperv/nested.c | 1 -
> arch/x86/include/asm/kvm_host.h | 1 -
> arch/x86/include/asm/mshyperv.h | 1 -
> arch/x86/kernel/cpu/mshyperv.c | 1 -
> arch/x86/kvm/vmx/vmx_onhyperv.h | 1 -
> arch/x86/mm/pat/set_memory.c | 2 --
> drivers/clocksource/hyperv_timer.c | 1 -
> drivers/hv/hv_balloon.c | 2 --
> drivers/hv/hv_common.c | 1 -
> drivers/hv/hv_kvp.c | 1 -
> drivers/hv/hv_snapshot.c | 1 -
> drivers/hv/hyperv_vmbus.h | 1 -
> net/vmw_vsock/hyperv_transport.c | 1 -
> 19 files changed, 23 deletions(-)
>
> diff --git a/arch/arm64/hyperv/hv_core.c b/arch/arm64/hyperv/hv_core.c
> index f1ebc025e1df..9d1969b875e9 100644
> --- a/arch/arm64/hyperv/hv_core.c
> +++ b/arch/arm64/hyperv/hv_core.c
> @@ -11,11 +11,9 @@
> #include <linux/types.h>
> #include <linux/export.h>
> #include <linux/mm.h>
> -#include <linux/hyperv.h>
> #include <linux/arm-smccc.h>
> #include <linux/module.h>
> #include <asm-generic/bug.h>
> -#include <asm/hyperv-tlfs.h>
> #include <asm/mshyperv.h>
>
> /*
> diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
> index 0569f579338b..f022d5f64fb6 100644
> --- a/arch/x86/hyperv/hv_apic.c
> +++ b/arch/x86/hyperv/hv_apic.c
> @@ -23,7 +23,6 @@
> #include <linux/vmalloc.h>
> #include <linux/mm.h>
> #include <linux/clockchips.h>
> -#include <linux/hyperv.h>
> #include <linux/slab.h>
> #include <linux/cpuhotplug.h>
> #include <asm/hypervisor.h>
> diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> index 17a71e92a343..fc3c3d76c181 100644
> --- a/arch/x86/hyperv/hv_init.c
> +++ b/arch/x86/hyperv/hv_init.c
> @@ -19,7 +19,6 @@
> #include <asm/sev.h>
> #include <asm/ibt.h>
> #include <asm/hypervisor.h>
> -#include <asm/hyperv-tlfs.h>
> #include <asm/mshyperv.h>
> #include <asm/idtentry.h>
> #include <asm/set_memory.h>
> @@ -27,7 +26,6 @@
> #include <linux/version.h>
> #include <linux/vmalloc.h>
> #include <linux/mm.h>
> -#include <linux/hyperv.h>
> #include <linux/slab.h>
> #include <linux/kernel.h>
> #include <linux/cpuhotplug.h>
> diff --git a/arch/x86/hyperv/hv_proc.c b/arch/x86/hyperv/hv_proc.c
> index 3fa1f2ee7b0d..b74c06c04ff1 100644
> --- a/arch/x86/hyperv/hv_proc.c
> +++ b/arch/x86/hyperv/hv_proc.c
> @@ -3,7 +3,6 @@
> #include <linux/vmalloc.h>
> #include <linux/mm.h>
> #include <linux/clockchips.h>
> -#include <linux/hyperv.h>
> #include <linux/slab.h>
> #include <linux/cpuhotplug.h>
> #include <linux/minmax.h>
> diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
> index 60fc3ed72830..b56d70612734 100644
> --- a/arch/x86/hyperv/ivm.c
> +++ b/arch/x86/hyperv/ivm.c
> @@ -7,7 +7,6 @@
> */
>
> #include <linux/bitfield.h>
> -#include <linux/hyperv.h>
> #include <linux/types.h>
> #include <linux/slab.h>
> #include <asm/svm.h>
> diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c
> index 1cc113200ff5..cc8c3bd0e7c2 100644
> --- a/arch/x86/hyperv/mmu.c
> +++ b/arch/x86/hyperv/mmu.c
> @@ -1,6 +1,5 @@
> #define pr_fmt(fmt) "Hyper-V: " fmt
>
> -#include <linux/hyperv.h>
> #include <linux/log2.h>
> #include <linux/slab.h>
> #include <linux/types.h>
> diff --git a/arch/x86/hyperv/nested.c b/arch/x86/hyperv/nested.c
> index 9dc259fa322e..ee06d0315c24 100644
> --- a/arch/x86/hyperv/nested.c
> +++ b/arch/x86/hyperv/nested.c
> @@ -11,7 +11,6 @@
>
>
> #include <linux/types.h>
> -#include <asm/hyperv-tlfs.h>
> #include <asm/mshyperv.h>
> #include <asm/tlbflush.h>
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 4a68cb3eba78..3627eab994a3 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -24,7 +24,6 @@
> #include <linux/pvclock_gtod.h>
> #include <linux/clocksource.h>
> #include <linux/irqbypass.h>
> -#include <linux/hyperv.h>
> #include <linux/kfifo.h>
>
> #include <asm/apic.h>
> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> index 390c4d13956d..47ca48062547 100644
> --- a/arch/x86/include/asm/mshyperv.h
> +++ b/arch/x86/include/asm/mshyperv.h
> @@ -9,7 +9,6 @@
> #include <asm/hyperv-tlfs.h>
> #include <asm/nospec-branch.h>
> #include <asm/paravirt.h>
> -#include <asm/mshyperv.h>
>
> /*
> * Hyper-V always provides a single IO-APIC at this MMIO address.
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index e0fd57a8ba84..8e8fd23b1439 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -20,7 +20,6 @@
> #include <linux/random.h>
> #include <asm/processor.h>
> #include <asm/hypervisor.h>
> -#include <asm/hyperv-tlfs.h>
> #include <asm/mshyperv.h>
> #include <asm/desc.h>
> #include <asm/idtentry.h>
> diff --git a/arch/x86/kvm/vmx/vmx_onhyperv.h
> b/arch/x86/kvm/vmx/vmx_onhyperv.h
> index eb48153bfd73..f4b081eb6521 100644
> --- a/arch/x86/kvm/vmx/vmx_onhyperv.h
> +++ b/arch/x86/kvm/vmx/vmx_onhyperv.h
> @@ -3,7 +3,6 @@
> #ifndef __ARCH_X86_KVM_VMX_ONHYPERV_H__
> #define __ARCH_X86_KVM_VMX_ONHYPERV_H__
>
> -#include <asm/hyperv-tlfs.h>
> #include <asm/mshyperv.h>
>
> #include <linux/jump_label.h>
> diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
> index 44f7b2ea6a07..85fa0d4509f0 100644
> --- a/arch/x86/mm/pat/set_memory.c
> +++ b/arch/x86/mm/pat/set_memory.c
> @@ -32,8 +32,6 @@
> #include <asm/pgalloc.h>
> #include <asm/proto.h>
> #include <asm/memtype.h>
> -#include <asm/hyperv-tlfs.h>
> -#include <asm/mshyperv.h>
>
> #include "../mm_internal.h"
>
> diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
> index b2a080647e41..1b7de45a7185 100644
> --- a/drivers/clocksource/hyperv_timer.c
> +++ b/drivers/clocksource/hyperv_timer.c
> @@ -23,7 +23,6 @@
> #include <linux/acpi.h>
> #include <linux/hyperv.h>
> #include <clocksource/hyperv_timer.h>
> -#include <asm/hyperv-tlfs.h>
> #include <asm/mshyperv.h>
>
> static struct clock_event_device __percpu *hv_clock_event;
> diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
> index c38dcdfcb914..a120e9b80ded 100644
> --- a/drivers/hv/hv_balloon.c
> +++ b/drivers/hv/hv_balloon.c
> @@ -28,8 +28,6 @@
> #include <linux/sizes.h>
>
> #include <linux/hyperv.h>
> -#include <asm/hyperv-tlfs.h>
> -
> #include <asm/mshyperv.h>
>
> #define CREATE_TRACE_POINTS
> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> index 9c452bfbd571..a5217f837237 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -28,7 +28,6 @@
> #include <linux/slab.h>
> #include <linux/dma-map-ops.h>
> #include <linux/set_memory.h>
> -#include <asm/hyperv-tlfs.h>
> #include <asm/mshyperv.h>
>
> /*
> diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c
> index d35b60c06114..68e73ec7ab28 100644
> --- a/drivers/hv/hv_kvp.c
> +++ b/drivers/hv/hv_kvp.c
> @@ -27,7 +27,6 @@
> #include <linux/connector.h>
> #include <linux/workqueue.h>
> #include <linux/hyperv.h>
> -#include <asm/hyperv-tlfs.h>
>
> #include "hyperv_vmbus.h"
> #include "hv_utils_transport.h"
> diff --git a/drivers/hv/hv_snapshot.c b/drivers/hv/hv_snapshot.c
> index 0d2184be1691..90fc935e89bd 100644
> --- a/drivers/hv/hv_snapshot.c
> +++ b/drivers/hv/hv_snapshot.c
> @@ -12,7 +12,6 @@
> #include <linux/connector.h>
> #include <linux/workqueue.h>
> #include <linux/hyperv.h>
> -#include <asm/hyperv-tlfs.h>
>
> #include "hyperv_vmbus.h"
> #include "hv_utils_transport.h"
> diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
> index 76ac5185a01a..321770d7ce25 100644
> --- a/drivers/hv/hyperv_vmbus.h
> +++ b/drivers/hv/hyperv_vmbus.h
> @@ -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>
> diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c
> index e2157e387217..f77f0ea1ddad 100644
> --- a/net/vmw_vsock/hyperv_transport.c
> +++ b/net/vmw_vsock/hyperv_transport.c
> @@ -13,7 +13,6 @@
> #include <linux/hyperv.h>
> #include <net/sock.h>
> #include <net/af_vsock.h>
> -#include <asm/hyperv-tlfs.h>
>
> /* Older (VMBUS version 'VERSION_WIN10' or before) Windows hosts have some
> * stricter requirements on the hv_sock ring buffer size of six 4K pages.
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* RE: [PATCH 3/5] hyperv: Add new Hyper-V headers
2024-10-03 19:51 ` [PATCH 3/5] hyperv: Add new Hyper-V headers Nuno Das Neves
@ 2024-10-10 18:21 ` Michael Kelley
2024-10-11 1:34 ` [EXTERNAL] " MUKESH RATHOR
0 siblings, 1 reply; 27+ messages in thread
From: Michael Kelley @ 2024-10-10 18:21 UTC (permalink / raw)
To: Nuno Das Neves, linux-hyperv@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
iommu@lists.linux.dev, netdev@vger.kernel.org,
linux-pci@vger.kernel.org, linux-arch@vger.kernel.org,
virtualization@lists.linux.dev
Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
luto@kernel.org, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com,
peterz@infradead.org, daniel.lezcano@linaro.org, joro@8bytes.org,
robin.murphy@arm.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org,
kw@linux.com, robh@kernel.org, bhelgaas@google.com, arnd@arndb.de,
sgarzare@redhat.com, jinankjain@linux.microsoft.com,
muminulrussell@gmail.com, skinsburskii@linux.microsoft.com,
mukeshrathor@microsoft.com
From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, October 3, 2024 12:51 PM
>
> Add definitions needed for privileged Hyper-V partitions.
>
> These files are derived from headers exported from the hypervisor code.
Could you elaborate on the naming conventions for the new files,
and the rules that govern what goes in what files? Specifically,
what is "hvgdk" vs. "hvhdk", and what are the _ext and _mini
suffixes? Even if the filenames are derived from Windows
Hyper-V source code, some explanation could be helpful. Maybe
the rules for what goes in what file could be captured in comments
at the top of each file. Or if the names are historical artifacts that
have no current value, then call that out so people like me don't try
to discern some meaning. :-)
> This is a step toward importing headers directly, similar to Xen public
> files in include/xen/interface/.
I'm not understanding this statement. The new files in this patch
are obviously following Linux kernel coding style, with Linux kernel
types, etc. I'm guessing there was a lot of "busy work" to take
Windows Hyper-V code and make it look like Linux kernel code. :-(
What would "importing headers directly" look like, and how is this
an interim step?
Also, it looks like these new files take a different approach for
instruction set architecture differences. There are inline #ifdef's
instead of the current method of having a common file, and then
architecture specific versions that include the common file. My
sense is that Linux kernel code prefers the current approach in
order to avoid #ifdef'ery, but maybe that's less practical when the
definitions are derived from Windows Hyper-V code. And with
only two architectures to deal with, the #ifdef's don't get
wild-and-crazy, which is good.
It also appears that a lot of the x86 specific definitions are *not*
under #ifdef x86, presumably because exposing those definitions
on the ARM64 side doesn't hurt anything. But some comments
on the top-level thinking and approach to architecture differences
would be helpful.
Michael
>
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> ---
> include/hyperv/hvgdk.h | 66 ++
> include/hyperv/hvgdk_ext.h | 46 ++
> include/hyperv/hvgdk_mini.h | 1212 +++++++++++++++++++++++++++++++++++
> include/hyperv/hvhdk.h | 733 +++++++++++++++++++++
> include/hyperv/hvhdk_mini.h | 310 +++++++++
> 5 files changed, 2367 insertions(+)
> create mode 100644 include/hyperv/hvgdk.h
> create mode 100644 include/hyperv/hvgdk_ext.h
> create mode 100644 include/hyperv/hvgdk_mini.h
> create mode 100644 include/hyperv/hvhdk.h
> create mode 100644 include/hyperv/hvhdk_mini.h
>
> diff --git a/include/hyperv/hvgdk.h b/include/hyperv/hvgdk.h
> new file mode 100644
> index 000000000000..af44e8034090
> --- /dev/null
> +++ b/include/hyperv/hvgdk.h
> @@ -0,0 +1,66 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Type definitions for the Microsoft Hypervisor.
> + */
> +#ifndef _HV_HVGDK_H
> +#define _HV_HVGDK_H
> +
> +#include "hvgdk_mini.h"
> +#include "hvgdk_ext.h"
> +
> +/*
> + * The guest OS needs to register the guest ID with the hypervisor.
> + * The guest ID is a 64 bit entity and the structure of this ID is
> + * specified in the Hyper-V TLFS specification.
> + *
> + * While the current guideline does not specify how Linux guest ID(s)
> + * need to be generated, our plan is to publish the guidelines for
> + * Linux and other guest operating systems that currently are hosted
> + * on Hyper-V. The implementation here conforms to this yet
> + * unpublished guidelines.
> + *
> + * Bit(s)
> + * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
> + * 62:56 - Os Type; Linux is 0x100
> + * 55:48 - Distro specific identification
> + * 47:16 - Linux kernel version number
> + * 15:0 - Distro specific identification
> + */
> +
> +#define HV_LINUX_VENDOR_ID 0x8100
> +
> +/*
> + * Hyper-V uses the software reserved 32 bytes in VMCB control area to expose
> + * SVM enlightenments to guests. This is documented in the TLFS doc.
> + * HV_VMX_ENLIGHTENED_VMCS or SVM_NESTED_ENLIGHTENED_VMCB_FIELDS
> + */
> +struct hv_vmcb_enlightenments {
> + struct __packed hv_enlightenments_control {
> + u32 nested_flush_hypercall : 1;
> + u32 msr_bitmap : 1;
> + u32 enlightened_npt_tlb: 1;
> + u32 reserved : 29;
> + } __packed hv_enlightenments_control;
> + u32 hv_vp_id;
> + u64 hv_vm_id;
> + u64 partition_assist_page;
> + u64 reserved;
> +} __packed;
> +
> +/* 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 _HV_HVGDK_H */
> diff --git a/include/hyperv/hvgdk_ext.h b/include/hyperv/hvgdk_ext.h
> new file mode 100644
> index 000000000000..641b591ee61f
> --- /dev/null
> +++ b/include/hyperv/hvgdk_ext.h
> @@ -0,0 +1,46 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Type definitions for the Microsoft Hypervisor.
> + */
> +#ifndef _HV_HVGDK_EXT_H
> +#define _HV_HVGDK_EXT_H
> +
> +#include "hvgdk_mini.h"
> +
> +/* Extended hypercalls */
> +#define HV_EXT_CALL_QUERY_CAPABILITIES 0x8001
> +#define HV_EXT_CALL_MEMORY_HEAT_HINT 0x8003
> +
> +/* Extended hypercalls */
> +enum { /* HV_EXT_CALL */
> + HV_EXTCALL_QUERY_CAPABILITIES = 0x8001,
> + HV_EXTCALL_MEMORY_HEAT_HINT = 0x8003,
> +};
> +
> +/* HV_EXT_OUTPUT_QUERY_CAPABILITIES */
> +#define HV_EXT_CAPABILITY_MEMORY_COLD_DISCARD_HINT BIT(8)
> +
> +enum { /* HV_EXT_MEMORY_HEAT_HINT_TYPE */
> + HV_EXTMEM_HEAT_HINT_COLD = 0,
> + HV_EXTMEM_HEAT_HINT_HOT = 1,
> + HV_EXTMEM_HEAT_HINT_COLD_DISCARD = 2,
> + HV_EXTMEM_HEAT_HINT_MAX
> +};
> +
> +/*
> + * The whole argument should fit in a page to be able to pass to the hypervisor
> + * in one hypercall.
> + */
> +#define HV_MEMORY_HINT_MAX_GPA_PAGE_RANGES \
> + ((HV_HYP_PAGE_SIZE - sizeof(struct hv_memory_hint)) / \
> + sizeof(union hv_gpa_page_range))
> +
> +/* HvExtCallMemoryHeatHint hypercall */
> +#define HV_EXT_MEMORY_HEAT_HINT_TYPE_COLD_DISCARD 2
> +struct hv_memory_hint { /* HV_EXT_INPUT_MEMORY_HEAT_HINT */
> + u64 heat_type : 2; /* HV_EXTMEM_HEAT_HINT_* */
> + u64 reserved : 62;
> + union hv_gpa_page_range ranges[];
> +} __packed;
> +
> +#endif /* _HV_HVGDK_EXT_H */
> diff --git a/include/hyperv/hvgdk_mini.h b/include/hyperv/hvgdk_mini.h
> new file mode 100644
> index 000000000000..b7dd22784c96
> --- /dev/null
> +++ b/include/hyperv/hvgdk_mini.h
> @@ -0,0 +1,1212 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Type definitions for the Microsoft hypervisor.
> + */
> +#ifndef _HV_HVGDK_MINI_H
> +#define _HV_HVGDK_MINI_H
> +
> +#include <linux/types.h>
> +#include <linux/bits.h>
> +
> +struct hv_u128 {
> + u64 low_part;
> + u64 high_part;
> +} __packed;
> +
> +/* NOTE: when adding below, update hv_status_to_string() */
> +#define HV_STATUS_SUCCESS 0x0
> +#define HV_STATUS_INVALID_HYPERCALL_CODE 0x2
> +#define HV_STATUS_INVALID_HYPERCALL_INPUT 0x3
> +#define HV_STATUS_INVALID_ALIGNMENT 0x4
> +#define HV_STATUS_INVALID_PARAMETER 0x5
> +#define HV_STATUS_ACCESS_DENIED 0x6
> +#define HV_STATUS_INVALID_PARTITION_STATE 0x7
> +#define HV_STATUS_OPERATION_DENIED 0x8
> +#define HV_STATUS_UNKNOWN_PROPERTY 0x9
> +#define HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE 0xA
> +#define HV_STATUS_INSUFFICIENT_MEMORY 0xB
> +#define HV_STATUS_INVALID_PARTITION_ID 0xD
> +#define HV_STATUS_INVALID_VP_INDEX 0xE
> +#define HV_STATUS_NOT_FOUND 0x10
> +#define HV_STATUS_INVALID_PORT_ID 0x11
> +#define HV_STATUS_INVALID_CONNECTION_ID 0x12
> +#define HV_STATUS_INSUFFICIENT_BUFFERS 0x13
> +#define HV_STATUS_NOT_ACKNOWLEDGED 0x14
> +#define HV_STATUS_INVALID_VP_STATE 0x15
> +#define HV_STATUS_NO_RESOURCES 0x1D
> +#define HV_STATUS_PROCESSOR_FEATURE_NOT_SUPPORTED 0x20
> +#define HV_STATUS_INVALID_LP_INDEX 0x41
> +#define HV_STATUS_INVALID_REGISTER_VALUE 0x50
> +#define HV_STATUS_OPERATION_FAILED 0x71
> +#define HV_STATUS_TIME_OUT 0x78
> +#define HV_STATUS_CALL_PENDING 0x79
> +#define HV_STATUS_VTL_ALREADY_ENABLED 0x86
> +
> +/*
> + * The Hyper-V TimeRefCount register and the TSC
> + * page provide a guest VM clock with 100ns tick rate
> + */
> +#define HV_CLOCK_HZ (NSEC_PER_SEC / 100)
> +
> +#define HV_HYP_PAGE_SHIFT 12
> +#define HV_HYP_PAGE_SIZE BIT(HV_HYP_PAGE_SHIFT)
> +#define HV_HYP_PAGE_MASK (~(HV_HYP_PAGE_SIZE - 1))
> +
> +#define HV_PARTITION_ID_INVALID ((u64)0)
> +#define HV_PARTITION_ID_SELF ((u64)-1)
> +
> +/* Hyper-V specific model specific registers (MSRs) */
> +
> +#if defined(CONFIG_X86)
> +/* HV_X64_SYNTHETIC_MSR */
> +#define HV_X64_MSR_GUEST_OS_ID 0x40000000
> +#define HV_X64_MSR_HYPERCALL 0x40000001
> +#define HV_X64_MSR_VP_INDEX 0x40000002
> +#define HV_X64_MSR_RESET 0x40000003
> +#define HV_X64_MSR_VP_RUNTIME 0x40000010
> +#define HV_X64_MSR_TIME_REF_COUNT 0x40000020
> +#define HV_X64_MSR_REFERENCE_TSC 0x40000021
> +#define HV_X64_MSR_TSC_FREQUENCY 0x40000022
> +#define HV_X64_MSR_APIC_FREQUENCY 0x40000023
> +
> +/* Define the virtual APIC registers */
> +#define HV_X64_MSR_EOI 0x40000070
> +#define HV_X64_MSR_ICR 0x40000071
> +#define HV_X64_MSR_TPR 0x40000072
> +#define HV_X64_MSR_VP_ASSIST_PAGE 0x40000073
> +
> +/* Note: derived, not in hvgdk_mini.h */
> +#define HV_X64_MSR_VP_ASSIST_PAGE_ENABLE 0x00000001
> +#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT 12
> +#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_MASK \
> + (~((1ull << HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT) - 1))
> +
> +/* Define synthetic interrupt controller model specific registers. */
> +#define HV_X64_MSR_SCONTROL 0x40000080
> +#define HV_X64_MSR_SVERSION 0x40000081
> +#define HV_X64_MSR_SIEFP 0x40000082
> +#define HV_X64_MSR_SIMP 0x40000083
> +#define HV_X64_MSR_EOM 0x40000084
> +#define HV_X64_MSR_SIRBP 0x40000085
> +#define HV_X64_MSR_SINT0 0x40000090
> +#define HV_X64_MSR_SINT1 0x40000091
> +#define HV_X64_MSR_SINT2 0x40000092
> +#define HV_X64_MSR_SINT3 0x40000093
> +#define HV_X64_MSR_SINT4 0x40000094
> +#define HV_X64_MSR_SINT5 0x40000095
> +#define HV_X64_MSR_SINT6 0x40000096
> +#define HV_X64_MSR_SINT7 0x40000097
> +#define HV_X64_MSR_SINT8 0x40000098
> +#define HV_X64_MSR_SINT9 0x40000099
> +#define HV_X64_MSR_SINT10 0x4000009A
> +#define HV_X64_MSR_SINT11 0x4000009B
> +#define HV_X64_MSR_SINT12 0x4000009C
> +#define HV_X64_MSR_SINT13 0x4000009D
> +#define HV_X64_MSR_SINT14 0x4000009E
> +#define HV_X64_MSR_SINT15 0x4000009F
> +
> +/* Define synthetic interrupt controller model specific registers for nested hypervisor */
> +#define HV_X64_MSR_NESTED_SCONTROL 0x40001080
> +#define HV_X64_MSR_NESTED_SVERSION 0x40001081
> +#define HV_X64_MSR_NESTED_SIEFP 0x40001082
> +#define HV_X64_MSR_NESTED_SIMP 0x40001083
> +#define HV_X64_MSR_NESTED_EOM 0x40001084
> +#define HV_X64_MSR_NESTED_SINT0 0x40001090
> +
> +/*
> + * Synthetic Timer MSRs. Four timers per vcpu.
> + */
> +#define HV_X64_MSR_STIMER0_CONFIG 0x400000B0
> +#define HV_X64_MSR_STIMER0_COUNT 0x400000B1
> +#define HV_X64_MSR_STIMER1_CONFIG 0x400000B2
> +#define HV_X64_MSR_STIMER1_COUNT 0x400000B3
> +#define HV_X64_MSR_STIMER2_CONFIG 0x400000B4
> +#define HV_X64_MSR_STIMER2_COUNT 0x400000B5
> +#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6
> +#define HV_X64_MSR_STIMER3_COUNT 0x400000B7
> +
> +/* Hyper-V guest idle MSR */
> +#define HV_X64_MSR_GUEST_IDLE 0x400000F0
> +
> +/* Hyper-V guest crash notification MSR's */
> +#define HV_X64_MSR_CRASH_P0 0x40000100
> +#define HV_X64_MSR_CRASH_P1 0x40000101
> +#define HV_X64_MSR_CRASH_P2 0x40000102
> +#define HV_X64_MSR_CRASH_P3 0x40000103
> +#define HV_X64_MSR_CRASH_P4 0x40000104
> +#define HV_X64_MSR_CRASH_CTL 0x40000105
> +
> +/* NOTE: derived, not in hvgdk_mini.h */
> +#define HV_X64_MSR_CRASH_PARAMS \
> + (1 + (HV_X64_MSR_CRASH_P4 - HV_X64_MSR_CRASH_P0))
> +
> +#define HV_IPI_LOW_VECTOR 0x10
> +#define HV_IPI_HIGH_VECTOR 0xff
> +
> +struct hv_reenlightenment_control {
> + u64 vector : 8;
> + u64 reserved1 : 8;
> + u64 enabled : 1;
> + u64 reserved2 : 15;
> + u64 target_vp : 32;
> +} __packed;
> +
> +struct hv_tsc_emulation_status { /* HV_TSC_EMULATION_STATUS */
> + u64 inprogress : 1;
> + u64 reserved : 63;
> +} __packed;
> +
> +struct hv_tsc_emulation_control { /* HV_TSC_INVARIANT_CONTROL */
> + u64 enabled : 1;
> + u64 reserved : 63;
> +} __packed;
> +
> +/* TSC emulation after migration */
> +#define HV_X64_MSR_REENLIGHTENMENT_CONTROL 0x40000106
> +#define HV_X64_MSR_TSC_EMULATION_CONTROL 0x40000107
> +#define HV_X64_MSR_TSC_EMULATION_STATUS 0x40000108
> +#define HV_X64_MSR_TSC_INVARIANT_CONTROL 0x40000118
> +#define HV_EXPOSE_INVARIANT_TSC BIT_ULL(0)
> +
> +#endif /* CONFIG_X86 */
> +
> +struct hv_get_partition_id { /* HV_OUTPUT_GET_PARTITION_ID */
> + u64 partition_id;
> +} __packed;
> +
> +/* HV_CRASH_CTL_REG_CONTENTS */
> +#define HV_CRASH_CTL_CRASH_NOTIFY_MSG BIT_ULL(62)
> +#define HV_CRASH_CTL_CRASH_NOTIFY BIT_ULL(63)
> +
> +union hv_reference_tsc_msr {
> + u64 as_uint64;
> + struct {
> + u64 enable : 1;
> + u64 reserved : 11;
> + u64 pfn : 52;
> + } __packed;
> +};
> +
> +/* The maximum number of sparse vCPU banks which can be encoded by 'struct hv_vpset' */
> +#define HV_MAX_SPARSE_VCPU_BANKS (64)
> +/* The number of vCPUs in one sparse bank */
> +#define HV_VCPUS_PER_SPARSE_BANK (64)
> +
> +/* Some of Hyper-V structs do not use hv_vpset where linux uses them */
> +struct hv_vpset { /* HV_VP_SET */
> + u64 format;
> + u64 valid_bank_mask;
> + u64 bank_contents[];
> +} __packed;
> +
> +/*
> + * Version info reported by hypervisor
> + * Changed to a union for convenience
> + */
> +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;
> + };
> +};
> +
> +/* HV_CPUID_FUNCTION */
> +#define HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS 0x40000000
> +#define HYPERV_CPUID_INTERFACE 0x40000001
> +#define HYPERV_CPUID_VERSION 0x40000002
> +#define HYPERV_CPUID_FEATURES 0x40000003
> +#define HYPERV_CPUID_ENLIGHTMENT_INFO 0x40000004
> +#define HYPERV_CPUID_IMPLEMENT_LIMITS 0x40000005
> +#define HYPERV_CPUID_CPU_MANAGEMENT_FEATURES 0x40000007
> +#define HYPERV_CPUID_NESTED_FEATURES 0x4000000A
> +#define HYPERV_CPUID_ISOLATION_CONFIG 0x4000000C
> +
> +#define HYPERV_CPUID_VIRT_STACK_INTERFACE 0x40000081
> +#define HYPERV_VS_INTERFACE_EAX_SIGNATURE 0x31235356 /* "VS#1" */
> +
> +#define HYPERV_CPUID_VIRT_STACK_PROPERTIES 0x40000082
> +/* Support for the extended IOAPIC RTE format */
> +#define HYPERV_VS_PROPERTIES_EAX_EXTENDED_IOAPIC_RTE BIT(2)
> +
> +#define HYPERV_HYPERVISOR_PRESENT_BIT 0x80000000
> +#define HYPERV_CPUID_MIN 0x40000005
> +#define HYPERV_CPUID_MAX 0x4000ffff
> +
> +/* HV_PARTITION_PRIVILEGE_MASK */
> +#define HV_MSR_VP_RUNTIME_AVAILABLE BIT(0)
> +#define HV_MSR_TIME_REF_COUNT_AVAILABLE BIT(1)
> +#define HV_MSR_SYNIC_AVAILABLE BIT(2)
> +#define HV_MSR_SYNTIMER_AVAILABLE BIT(3)
> +#define HV_MSR_APIC_ACCESS_AVAILABLE BIT(4)
> +#define HV_MSR_HYPERCALL_AVAILABLE BIT(5)
> +#define HV_MSR_VP_INDEX_AVAILABLE BIT(6)
> +#define HV_MSR_RESET_AVAILABLE BIT(7)
> +#define HV_MSR_STAT_PAGES_AVAILABLE BIT(8)
> +#define HV_MSR_REFERENCE_TSC_AVAILABLE BIT(9)
> +#define HV_MSR_GUEST_IDLE_AVAILABLE BIT(10)
> +#define HV_ACCESS_FREQUENCY_MSRS BIT(11)
> +#define HV_ACCESS_REENLIGHTENMENT BIT(13)
> +#define HV_ACCESS_TSC_INVARIANT BIT(15)
> +
> +/* HV_PARTITION_PRIVILEGE_MASK */
> +#define HV_CREATE_PARTITIONS BIT(0)
> +#define HV_ACCESS_PARTITION_ID BIT(1)
> +#define HV_ACCESS_MEMORY_POOL BIT(2)
> +#define HV_ADJUST_MESSAGE_BUFFERS BIT(3)
> +#define HV_POST_MESSAGES BIT(4)
> +#define HV_SIGNAL_EVENTS BIT(5)
> +#define HV_CREATE_PORT BIT(6)
> +#define HV_CONNECT_PORT BIT(7)
> +#define HV_ACCESS_STATS BIT(8)
> +#define HV_DEBUGGING BIT(11)
> +#define HV_CPU_MANAGEMENT BIT(12)
> +#define HV_ENABLE_EXTENDED_HYPERCALLS BIT(20)
> +#define HV_ISOLATION BIT(22)
> +
> +#if defined(CONFIG_X86)
> +/* HV_X64_HYPERVISOR_FEATURES (EDX) */
> +#define HV_X64_MWAIT_AVAILABLE BIT(0)
> +#define HV_X64_GUEST_DEBUGGING_AVAILABLE BIT(1)
> +#define HV_X64_PERF_MONITOR_AVAILABLE BIT(2)
> +#define HV_X64_CPU_DYNAMIC_PARTITIONING_AVAILABLE BIT(3)
> +#define HV_X64_HYPERCALL_XMM_INPUT_AVAILABLE BIT(4)
> +#define HV_X64_GUEST_IDLE_STATE_AVAILABLE BIT(5)
> +#define HV_FEATURE_FREQUENCY_MSRS_AVAILABLE BIT(8)
> +#define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE BIT(10)
> +#define HV_FEATURE_DEBUG_MSRS_AVAILABLE BIT(11)
> +/*
> + * Support for returning hypercall output block via XMM
> + * registers is available
> + */
> +#define HV_X64_HYPERCALL_XMM_OUTPUT_AVAILABLE BIT(15)
> +/* stimer Direct Mode is available */
> +#define HV_STIMER_DIRECT_MODE_AVAILABLE BIT(19)
> +
> +/* HV_X64_ENLIGHTENMENT_INFORMATION */
> +#define HV_X64_AS_SWITCH_RECOMMENDED BIT(0)
> +#define HV_X64_LOCAL_TLB_FLUSH_RECOMMENDED BIT(1)
> +#define HV_X64_REMOTE_TLB_FLUSH_RECOMMENDED BIT(2)
> +#define HV_X64_APIC_ACCESS_RECOMMENDED BIT(3)
> +#define HV_X64_SYSTEM_RESET_RECOMMENDED BIT(4)
> +#define HV_X64_RELAXED_TIMING_RECOMMENDED BIT(5)
> +#define HV_DEPRECATING_AEOI_RECOMMENDED BIT(9)
> +#define HV_X64_CLUSTER_IPI_RECOMMENDED BIT(10)
> +#define HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED BIT(11)
> +#define HV_X64_HYPERV_NESTED BIT(12)
> +#define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED BIT(14)
> +#define HV_X64_USE_MMIO_HYPERCALLS BIT(21)
> +
> +/* HYPERV_CPUID_ISOLATION_CONFIG.EBX bits. */
> +#define HV_ISOLATION_TYPE GENMASK(3, 0)
> +#define HV_SHARED_GPA_BOUNDARY_ACTIVE BIT(5)
> +#define HV_SHARED_GPA_BOUNDARY_BITS GENMASK(11, 6)
> +
> +/* HYPERV_CPUID_FEATURES.ECX bits. */
> +#define HV_VP_DISPATCH_INTERRUPT_INJECTION_AVAILABLE BIT(9)
> +#define HV_VP_GHCB_ROOT_MAPPING_AVAILABLE BIT(10)
> +
> +enum hv_isolation_type {
> + HV_ISOLATION_TYPE_NONE = 0, /* HV_PARTITION_ISOLATION_TYPE_NONE */
> + HV_ISOLATION_TYPE_VBS = 1,
> + HV_ISOLATION_TYPE_SNP = 2,
> + HV_ISOLATION_TYPE_TDX = 3
> +};
> +
> +union hv_x64_msr_hypercall_contents {
> + u64 as_uint64;
> + struct {
> + u64 enable : 1;
> + u64 reserved : 11;
> + u64 guest_physical_address : 52;
> + } __packed;
> +};
> +#endif /* CONFIG_X86 */
> +
> +#if defined(CONFIG_ARM64)
> +#define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE BIT(8)
> +#define HV_STIMER_DIRECT_MODE_AVAILABLE BIT(13)
> +#endif /* CONFIG_ARM64 */
> +
> +#if defined(CONFIG_X86)
> +#define HV_MAXIMUM_PROCESSORS 2048
> +#elif defined(CONFIG_ARM64) /* CONFIG_X86 */
> +#define HV_MAXIMUM_PROCESSORS 320
> +#endif /* CONFIG_ARM64 */
> +
> +#define HV_MAX_VP_INDEX (HV_MAXIMUM_PROCESSORS - 1)
> +#define HV_VP_INDEX_SELF ((u32)-2)
> +#define HV_ANY_VP ((u32)-1)
> +
> +union hv_vp_assist_msr_contents { /* HV_REGISTER_VP_ASSIST_PAGE */
> + u64 as_uint64;
> + struct {
> + u64 enable : 1;
> + u64 reserved : 11;
> + u64 pfn : 52;
> + } __packed;
> +};
> +
> +/* Declare the various hypercall operations. */
> +/* HV_CALL_CODE */
> +#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE 0x0002
> +#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST 0x0003
> +#define HVCALL_NOTIFY_LONG_SPIN_WAIT 0x0008
> +#define HVCALL_SEND_IPI 0x000b
> +#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013
> +#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX 0x0014
> +#define HVCALL_SEND_IPI_EX 0x0015
> +#define HVCALL_CREATE_PARTITION 0x0040
> +#define HVCALL_INITIALIZE_PARTITION 0x0041
> +#define HVCALL_FINALIZE_PARTITION 0x0042
> +#define HVCALL_DELETE_PARTITION 0x0043
> +#define HVCALL_GET_PARTITION_PROPERTY 0x0044
> +#define HVCALL_SET_PARTITION_PROPERTY 0x0045
> +#define HVCALL_GET_PARTITION_ID 0x0046
> +#define HVCALL_DEPOSIT_MEMORY 0x0048
> +#define HVCALL_WITHDRAW_MEMORY 0x0049
> +#define HVCALL_MAP_GPA_PAGES 0x004b
> +#define HVCALL_UNMAP_GPA_PAGES 0x004c
> +#define HVCALL_CREATE_VP 0x004e
> +#define HVCALL_DELETE_VP 0x004f
> +#define HVCALL_GET_VP_REGISTERS 0x0050
> +#define HVCALL_SET_VP_REGISTERS 0x0051
> +#define HVCALL_DELETE_PORT 0x0058
> +#define HVCALL_DISCONNECT_PORT 0x005b
> +#define HVCALL_POST_MESSAGE 0x005c
> +#define HVCALL_SIGNAL_EVENT 0x005d
> +#define HVCALL_POST_DEBUG_DATA 0x0069
> +#define HVCALL_RETRIEVE_DEBUG_DATA 0x006a
> +#define HVCALL_RESET_DEBUG_SESSION 0x006b
> +#define HVCALL_ADD_LOGICAL_PROCESSOR 0x0076
> +#define HVCALL_GET_SYSTEM_PROPERTY 0x007b
> +#define HVCALL_MAP_DEVICE_INTERRUPT 0x007c
> +#define HVCALL_UNMAP_DEVICE_INTERRUPT 0x007d
> +#define HVCALL_RETARGET_INTERRUPT 0x007e
> +#define HVCALL_NOTIFY_PORT_RING_EMPTY 0x008b
> +#define HVCALL_ASSERT_VIRTUAL_INTERRUPT 0x0094
> +#define HVCALL_CREATE_PORT 0x0095
> +#define HVCALL_CONNECT_PORT 0x0096
> +#define HVCALL_START_VP 0x0099
> +#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af
> +#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0
> +#define HVCALL_DISPATCH_VP 0x00c2
> +#define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db
> +#define HVCALL_MAP_VP_STATE_PAGE 0x00e1
> +#define HVCALL_UNMAP_VP_STATE_PAGE 0x00e2
> +#define HVCALL_GET_VP_STATE 0x00e3
> +#define HVCALL_SET_VP_STATE 0x00e4
> +#define HVCALL_MMIO_READ 0x0106
> +#define HVCALL_MMIO_WRITE 0x0107
> +
> +/* HV_HYPERCALL_INPUT */
> +#define HV_HYPERCALL_RESULT_MASK GENMASK_ULL(15, 0)
> +#define HV_HYPERCALL_FAST_BIT BIT(16)
> +#define HV_HYPERCALL_VARHEAD_OFFSET 17
> +#define HV_HYPERCALL_NESTED BIT(31)
> +#define HV_HYPERCALL_REP_COMP_OFFSET 32
> +#define HV_HYPERCALL_REP_COMP_1 BIT_ULL(32)
> +#define HV_HYPERCALL_REP_COMP_MASK GENMASK_ULL(43, 32)
> +#define HV_HYPERCALL_REP_START_OFFSET 48
> +#define HV_HYPERCALL_REP_START_MASK GENMASK_ULL(59, 48)
> +
> +/* HvFlushGuestPhysicalAddressSpace hypercalls */
> +struct hv_guest_mapping_flush {
> + u64 address_space;
> + u64 flags;
> +} __packed;
> +
> +/*
> + * HV_MAX_FLUSH_PAGES = "additional_pages" + 1. It's limited
> + * by the bitwidth of "additional_pages" in union hv_gpa_page_range.
> + */
> +#define HV_MAX_FLUSH_PAGES (2048)
> +#define HV_GPA_PAGE_RANGE_PAGE_SIZE_2MB 0
> +#define HV_GPA_PAGE_RANGE_PAGE_SIZE_1GB 1
> +
> +#define HV_FLUSH_ALL_PROCESSORS BIT(0)
> +#define HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES BIT(1)
> +#define HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY BIT(2)
> +#define HV_FLUSH_USE_EXTENDED_RANGE_FORMAT BIT(3)
> +
> +/* HvFlushGuestPhysicalAddressList, HvExtCallMemoryHeatHint hypercall */
> +union hv_gpa_page_range {
> + u64 address_space;
> + struct {
> + u64 additional_pages : 11;
> + u64 largepage : 1;
> + u64 basepfn : 52;
> + } page;
> + struct {
> + u64 reserved : 12;
> + u64 page_size : 1;
> + u64 reserved1 : 8;
> + u64 base_large_pfn : 43;
> + };
> +};
> +
> +/*
> + * All input flush parameters should be in single page. The max flush
> + * count is equal with how many entries of union hv_gpa_page_range can
> + * be populated into the input parameter page.
> + */
> +#define HV_MAX_FLUSH_REP_COUNT ((HV_HYP_PAGE_SIZE - 2 * sizeof(u64)) / \
> + sizeof(union hv_gpa_page_range))
> +
> +struct hv_guest_mapping_flush_list {
> + u64 address_space;
> + u64 flags;
> + union hv_gpa_page_range gpa_list[HV_MAX_FLUSH_REP_COUNT];
> +};
> +
> +struct hv_tlb_flush { /* HV_INPUT_FLUSH_VIRTUAL_ADDRESS_LIST */
> + u64 address_space;
> + u64 flags;
> + u64 processor_mask;
> + u64 gva_list[];
> +} __packed;
> +
> +/* HvFlushVirtualAddressSpaceEx, HvFlushVirtualAddressListEx hypercalls */
> +struct hv_tlb_flush_ex {
> + u64 address_space;
> + u64 flags;
> + struct hv_vpset hv_vp_set;
> + u64 gva_list[];
> +} __packed;
> +
> +struct ms_hyperv_tsc_page { /* HV_REFERENCE_TSC_PAGE */
> + volatile u32 tsc_sequence;
> + u32 reserved1;
> + volatile u64 tsc_scale;
> + volatile s64 tsc_offset;
> +} __packed;
> +
> +/* Define the number of synthetic interrupt sources. */
> +#define HV_SYNIC_SINT_COUNT (16)
> +
> +/* Hyper-V defined statically assigned SINTs */
> +#define HV_SYNIC_INTERCEPTION_SINT_INDEX 0x00000000
> +#define HV_SYNIC_IOMMU_FAULT_SINT_INDEX 0x00000001
> +#define HV_SYNIC_VMBUS_SINT_INDEX 0x00000002
> +#define HV_SYNIC_FIRST_UNUSED_SINT_INDEX 0x00000005
> +
> +/* mshv assigned SINT for doorbell */
> +#define HV_SYNIC_DOORBELL_SINT_INDEX HV_SYNIC_FIRST_UNUSED_SINT_INDEX
> +
> +enum hv_interrupt_type {
> + HV_X64_INTERRUPT_TYPE_FIXED = 0x0000,
> + HV_X64_INTERRUPT_TYPE_LOWESTPRIORITY = 0x0001,
> + HV_X64_INTERRUPT_TYPE_SMI = 0x0002,
> + HV_X64_INTERRUPT_TYPE_REMOTEREAD = 0x0003,
> + HV_X64_INTERRUPT_TYPE_NMI = 0x0004,
> + HV_X64_INTERRUPT_TYPE_INIT = 0x0005,
> + HV_X64_INTERRUPT_TYPE_SIPI = 0x0006,
> + HV_X64_INTERRUPT_TYPE_EXTINT = 0x0007,
> + HV_X64_INTERRUPT_TYPE_LOCALINT0 = 0x0008,
> + HV_X64_INTERRUPT_TYPE_LOCALINT1 = 0x0009,
> + HV_X64_INTERRUPT_TYPE_MAXIMUM = 0x000A,
> +};
> +
> +/* Define synthetic interrupt source. */
> +union hv_synic_sint {
> + u64 as_uint64;
> + struct {
> + u64 vector : 8;
> + u64 reserved1 : 8;
> + u64 masked : 1;
> + u64 auto_eoi : 1;
> + u64 polling : 1;
> + u64 as_intercept : 1;
> + u64 proxy : 1;
> + u64 reserved2 : 43;
> + } __packed;
> +};
> +
> +union hv_x64_xsave_xfem_register {
> + u64 as_uint64;
> + struct {
> + u32 low_uint32;
> + u32 high_uint32;
> + } __packed;
> + struct {
> + u64 legacy_x87 : 1;
> + u64 legacy_sse : 1;
> + u64 avx : 1;
> + u64 mpx_bndreg : 1;
> + u64 mpx_bndcsr : 1;
> + u64 avx_512_op_mask : 1;
> + u64 avx_512_zmmhi : 1;
> + u64 avx_512_zmm16_31 : 1;
> + u64 rsvd8_9 : 2;
> + u64 pasid : 1;
> + u64 cet_u : 1;
> + u64 cet_s : 1;
> + u64 rsvd13_16 : 4;
> + u64 xtile_cfg : 1;
> + u64 xtile_data : 1;
> + u64 rsvd19_63 : 45;
> + } __packed;
> +};
> +
> +/* Synthetic timer configuration */
> +union hv_stimer_config { /* HV_X64_MSR_STIMER_CONFIG_CONTENTS */
> + u64 as_uint64;
> + struct {
> + u64 enable : 1;
> + u64 periodic : 1;
> + u64 lazy : 1;
> + u64 auto_enable : 1;
> + u64 apic_vector : 8;
> + u64 direct_mode : 1;
> + u64 reserved_z0 : 3;
> + u64 sintx : 4;
> + u64 reserved_z1 : 44;
> + } __packed;
> +};
> +
> +/* Define the number of synthetic timers */
> +#define HV_SYNIC_STIMER_COUNT (4)
> +
> +/* Define port identifier type. */
> +union hv_port_id {
> + u32 asu32;
> + struct {
> + u32 id : 24;
> + u32 reserved : 8;
> + } __packed u;
> +};
> +
> +#define HV_MESSAGE_SIZE (256)
> +#define HV_MESSAGE_PAYLOAD_BYTE_COUNT (240)
> +#define HV_MESSAGE_PAYLOAD_QWORD_COUNT (30)
> +
> +/* Define hypervisor message types. */
> +enum hv_message_type {
> + HVMSG_NONE = 0x00000000,
> +
> + /* Memory access messages. */
> + HVMSG_UNMAPPED_GPA = 0x80000000,
> + HVMSG_GPA_INTERCEPT = 0x80000001,
> +
> + /* Timer notification messages. */
> + HVMSG_TIMER_EXPIRED = 0x80000010,
> +
> + /* Error messages. */
> + HVMSG_INVALID_VP_REGISTER_VALUE = 0x80000020,
> + HVMSG_UNRECOVERABLE_EXCEPTION = 0x80000021,
> + HVMSG_UNSUPPORTED_FEATURE = 0x80000022,
> +
> + /*
> + * Opaque intercept message. The original intercept message is only
> + * accessible from the mapped intercept message page.
> + */
> + HVMSG_OPAQUE_INTERCEPT = 0x8000003F,
> +
> + /* Trace buffer complete messages. */
> + HVMSG_EVENTLOG_BUFFERCOMPLETE = 0x80000040,
> +
> + /* Hypercall intercept */
> + HVMSG_HYPERCALL_INTERCEPT = 0x80000050,
> +
> + /* SynIC intercepts */
> + HVMSG_SYNIC_EVENT_INTERCEPT = 0x80000060,
> + HVMSG_SYNIC_SINT_INTERCEPT = 0x80000061,
> + HVMSG_SYNIC_SINT_DELIVERABLE = 0x80000062,
> +
> + /* Async call completion intercept */
> + HVMSG_ASYNC_CALL_COMPLETION = 0x80000070,
> +
> + /* Root scheduler messages */
> + HVMSG_SCHEDULER_VP_SIGNAL_BITSET = 0x80000100,
> + HVMSG_SCHEDULER_VP_SIGNAL_PAIR = 0x80000101,
> +
> + /* Platform-specific processor intercept messages. */
> + HVMSG_X64_IO_PORT_INTERCEPT = 0x80010000,
> + HVMSG_X64_MSR_INTERCEPT = 0x80010001,
> + HVMSG_X64_CPUID_INTERCEPT = 0x80010002,
> + HVMSG_X64_EXCEPTION_INTERCEPT = 0x80010003,
> + HVMSG_X64_APIC_EOI = 0x80010004,
> + HVMSG_X64_LEGACY_FP_ERROR = 0x80010005,
> + HVMSG_X64_IOMMU_PRQ = 0x80010006,
> + HVMSG_X64_HALT = 0x80010007,
> + HVMSG_X64_INTERRUPTION_DELIVERABLE = 0x80010008,
> + HVMSG_X64_SIPI_INTERCEPT = 0x80010009,
> +};
> +
> +/* Define the format of the SIMP register */
> +union hv_synic_simp {
> + u64 as_uint64;
> + struct {
> + u64 simp_enabled : 1;
> + u64 preserved : 11;
> + u64 base_simp_gpa : 52;
> + } __packed;
> +};
> +
> +union hv_message_flags {
> + u8 asu8;
> + struct {
> + u8 msg_pending : 1;
> + u8 reserved : 7;
> + } __packed;
> +};
> +
> +struct hv_message_header {
> + u32 message_type;
> + u8 payload_size;
> + union hv_message_flags message_flags;
> + u8 reserved[2];
> + union {
> + u64 sender;
> + union hv_port_id port;
> + };
> +} __packed;
> +
> +/*
> + * Message format for notifications delivered via
> + * intercept message(as_intercept=1)
> + */
> +struct hv_notification_message_payload {
> + u32 sint_index;
> +} __packed;
> +
> +struct hv_message {
> + struct hv_message_header header;
> + union {
> + u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
> + } u;
> +} __packed;
> +
> +/* Define the synthetic interrupt message page layout. */
> +struct hv_message_page {
> + struct hv_message sint_message[HV_SYNIC_SINT_COUNT];
> +} __packed;
> +
> +struct hv_x64_segment_register {
> + u64 base;
> + u32 limit;
> + u16 selector;
> + union {
> + struct {
> + u16 segment_type : 4;
> + u16 non_system_segment : 1;
> + u16 descriptor_privilege_level : 2;
> + u16 present : 1;
> + u16 reserved : 4;
> + u16 available : 1;
> + u16 _long : 1;
> + u16 _default : 1;
> + u16 granularity : 1;
> + } __packed;
> + u16 attributes;
> + };
> +} __packed;
> +
> +struct hv_x64_table_register {
> + u16 pad[3];
> + u16 limit;
> + u64 base;
> +} __packed;
> +
> +union hv_input_vtl {
> + u8 as_uint8;
> + struct {
> + u8 target_vtl : 4;
> + u8 use_target_vtl : 1;
> + u8 reserved_z : 3;
> + };
> +} __packed;
> +
> +struct hv_init_vp_context {
> + u64 rip;
> + u64 rsp;
> + u64 rflags;
> +
> + struct hv_x64_segment_register cs;
> + struct hv_x64_segment_register ds;
> + struct hv_x64_segment_register es;
> + struct hv_x64_segment_register fs;
> + struct hv_x64_segment_register gs;
> + struct hv_x64_segment_register ss;
> + struct hv_x64_segment_register tr;
> + struct hv_x64_segment_register ldtr;
> +
> + struct hv_x64_table_register idtr;
> + struct hv_x64_table_register gdtr;
> +
> + u64 efer;
> + u64 cr0;
> + u64 cr3;
> + u64 cr4;
> + u64 msr_cr_pat;
> +} __packed;
> +
> +struct hv_enable_vp_vtl {
> + u64 partition_id;
> + u32 vp_index;
> + union hv_input_vtl target_vtl;
> + u8 mbz0;
> + u16 mbz1;
> + struct hv_init_vp_context vp_context;
> +} __packed;
> +
> +struct hv_nested_enlightenments_control {
> + struct {
> + u32 directhypercall : 1;
> + u32 reserved : 31;
> + } __packed features;
> + struct {
> + u32 inter_partition_comm : 1;
> + u32 reserved : 31;
> + } __packed hypercall_controls;
> +} __packed;
> +
> +/* Define virtual processor assist page structure. */
> +struct hv_vp_assist_page {
> + u32 apic_assist;
> + u32 reserved1;
> + u32 vtl_entry_reason;
> + u32 vtl_reserved;
> + u64 vtl_ret_x64rax;
> + u64 vtl_ret_x64rcx;
> + struct hv_nested_enlightenments_control nested_control;
> + u8 enlighten_vmentry;
> + u8 reserved2[7];
> + u64 current_nested_vmcs;
> + u8 synthetic_time_unhalted_timer_expired;
> + u8 reserved3[7];
> + u8 virtualization_fault_information[40];
> + u8 reserved4[8];
> + u8 intercept_message[256];
> + u8 vtl_ret_actions[256];
> +} __packed;
> +
> +enum hv_register_name {
> + /* Suspend Registers */
> + HV_REGISTER_EXPLICIT_SUSPEND = 0x00000000,
> + HV_REGISTER_INTERCEPT_SUSPEND = 0x00000001,
> + HV_REGISTER_DISPATCH_SUSPEND = 0x00000003,
> +
> + /* Version - 128-bit result same as CPUID 0x40000002 */
> + HV_REGISTER_HYPERVISOR_VERSION = 0x00000100,
> +
> + /* Feature Access (registers are 128 bits) - same as CPUID 0x40000003 -
> 0x4000000B */
> + HV_REGISTER_PRIVILEGES_AND_FEATURES_INFO = 0x00000200,
> + HV_REGISTER_FEATURES_INFO = 0x00000201,
> + HV_REGISTER_IMPLEMENTATION_LIMITS_INFO =
> 0x00000202,
> + HV_REGISTER_HARDWARE_FEATURES_INFO = 0x00000203,
> + HV_REGISTER_CPU_MANAGEMENT_FEATURES_INFO = 0x00000204,
> + HV_REGISTER_SVM_FEATURES_INFO = 0x00000205,
> + HV_REGISTER_SKIP_LEVEL_FEATURES_INFO = 0x00000206,
> + HV_REGISTER_NESTED_VIRT_FEATURES_INFO = 0x00000207,
> + HV_REGISTER_IPT_FEATURES_INFO = 0x00000208,
> +
> + /* Guest Crash Registers */
> + HV_REGISTER_GUEST_CRASH_P0 = 0x00000210,
> + HV_REGISTER_GUEST_CRASH_P1 = 0x00000211,
> + HV_REGISTER_GUEST_CRASH_P2 = 0x00000212,
> + HV_REGISTER_GUEST_CRASH_P3 = 0x00000213,
> + HV_REGISTER_GUEST_CRASH_P4 = 0x00000214,
> + HV_REGISTER_GUEST_CRASH_CTL = 0x00000215,
> +
> + /* Misc */
> + HV_REGISTER_VP_RUNTIME = 0x00090000,
> + HV_REGISTER_GUEST_OS_ID = 0x00090002,
> + HV_REGISTER_VP_INDEX = 0x00090003,
> + HV_REGISTER_TIME_REF_COUNT = 0x00090004,
> + HV_REGISTER_CPU_MANAGEMENT_VERSION = 0x00090007,
> + HV_REGISTER_VP_ASSIST_PAGE = 0x00090013,
> + HV_REGISTER_VP_ROOT_SIGNAL_COUNT = 0x00090014,
> + HV_REGISTER_REFERENCE_TSC = 0x00090017,
> +
> + /* Hypervisor-defined Registers (Synic) */
> + HV_REGISTER_SINT0 = 0x000A0000,
> + HV_REGISTER_SINT1 = 0x000A0001,
> + HV_REGISTER_SINT2 = 0x000A0002,
> + HV_REGISTER_SINT3 = 0x000A0003,
> + HV_REGISTER_SINT4 = 0x000A0004,
> + HV_REGISTER_SINT5 = 0x000A0005,
> + HV_REGISTER_SINT6 = 0x000A0006,
> + HV_REGISTER_SINT7 = 0x000A0007,
> + HV_REGISTER_SINT8 = 0x000A0008,
> + HV_REGISTER_SINT9 = 0x000A0009,
> + HV_REGISTER_SINT10 = 0x000A000A,
> + HV_REGISTER_SINT11 = 0x000A000B,
> + HV_REGISTER_SINT12 = 0x000A000C,
> + HV_REGISTER_SINT13 = 0x000A000D,
> + HV_REGISTER_SINT14 = 0x000A000E,
> + HV_REGISTER_SINT15 = 0x000A000F,
> + HV_REGISTER_SCONTROL = 0x000A0010,
> + HV_REGISTER_SVERSION = 0x000A0011,
> + HV_REGISTER_SIEFP = 0x000A0012,
> + HV_REGISTER_SIMP = 0x000A0013,
> + HV_REGISTER_EOM = 0x000A0014,
> + HV_REGISTER_SIRBP = 0x000A0015,
> +
> + HV_REGISTER_NESTED_SINT0 = 0x000A1000,
> + HV_REGISTER_NESTED_SINT1 = 0x000A1001,
> + HV_REGISTER_NESTED_SINT2 = 0x000A1002,
> + HV_REGISTER_NESTED_SINT3 = 0x000A1003,
> + HV_REGISTER_NESTED_SINT4 = 0x000A1004,
> + HV_REGISTER_NESTED_SINT5 = 0x000A1005,
> + HV_REGISTER_NESTED_SINT6 = 0x000A1006,
> + HV_REGISTER_NESTED_SINT7 = 0x000A1007,
> + HV_REGISTER_NESTED_SINT8 = 0x000A1008,
> + HV_REGISTER_NESTED_SINT9 = 0x000A1009,
> + HV_REGISTER_NESTED_SINT10 = 0x000A100A,
> + HV_REGISTER_NESTED_SINT11 = 0x000A100B,
> + HV_REGISTER_NESTED_SINT12 = 0x000A100C,
> + HV_REGISTER_NESTED_SINT13 = 0x000A100D,
> + HV_REGISTER_NESTED_SINT14 = 0x000A100E,
> + HV_REGISTER_NESTED_SINT15 = 0x000A100F,
> + HV_REGISTER_NESTED_SCONTROL = 0x000A1010,
> + HV_REGISTER_NESTED_SVERSION = 0x000A1011,
> + HV_REGISTER_NESTED_SIFP = 0x000A1012,
> + HV_REGISTER_NESTED_SIPP = 0x000A1013,
> + HV_REGISTER_NESTED_EOM = 0x000A1014,
> + HV_REGISTER_NESTED_SIRBP = 0x000a1015,
> +
> + /* Hypervisor-defined Registers (Synthetic Timers) */
> + HV_REGISTER_STIMER0_CONFIG = 0x000B0000,
> + HV_REGISTER_STIMER0_COUNT = 0x000B0001,
> +
> + /* VSM */
> + HV_X64_REGISTER_VSM_VP_STATUS = 0x000D0003,
> +};
> +
> +/*
> + * Arch compatibility regs for use with hv_set/get_register
> + */
> +#if defined(CONFIG_X86)
> +
> +/*
> + * To support arch-generic 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_CRASH_P0 (HV_X64_MSR_CRASH_P0)
> +#define HV_MSR_CRASH_P1 (HV_X64_MSR_CRASH_P1)
> +#define HV_MSR_CRASH_P2 (HV_X64_MSR_CRASH_P2)
> +#define HV_MSR_CRASH_P3 (HV_X64_MSR_CRASH_P3)
> +#define HV_MSR_CRASH_P4 (HV_X64_MSR_CRASH_P4)
> +#define HV_MSR_CRASH_CTL (HV_X64_MSR_CRASH_CTL)
> +
> +#define HV_MSR_VP_INDEX (HV_X64_MSR_VP_INDEX)
> +#define HV_MSR_TIME_REF_COUNT (HV_X64_MSR_TIME_REF_COUNT)
> +#define HV_MSR_REFERENCE_TSC (HV_X64_MSR_REFERENCE_TSC)
> +
> +#define HV_MSR_SINT0 (HV_X64_MSR_SINT0)
> +#define HV_MSR_SVERSION (HV_X64_MSR_SVERSION)
> +#define HV_MSR_SCONTROL (HV_X64_MSR_SCONTROL)
> +#define HV_MSR_SIEFP (HV_X64_MSR_SIEFP)
> +#define HV_MSR_SIMP (HV_X64_MSR_SIMP)
> +#define HV_MSR_EOM (HV_X64_MSR_EOM)
> +#define HV_MSR_SIRBP (HV_X64_MSR_SIRBP)
> +
> +#define HV_MSR_NESTED_SCONTROL (HV_X64_MSR_NESTED_SCONTROL)
> +#define HV_MSR_NESTED_SVERSION (HV_X64_MSR_NESTED_SVERSION)
> +#define HV_MSR_NESTED_SIEFP (HV_X64_MSR_NESTED_SIEFP)
> +#define HV_MSR_NESTED_SIMP (HV_X64_MSR_NESTED_SIMP)
> +#define HV_MSR_NESTED_EOM (HV_X64_MSR_NESTED_EOM)
> +#define HV_MSR_NESTED_SINT0 (HV_X64_MSR_NESTED_SINT0)
> +
> +#define HV_MSR_STIMER0_CONFIG (HV_X64_MSR_STIMER0_CONFIG)
> +#define HV_MSR_STIMER0_COUNT (HV_X64_MSR_STIMER0_COUNT)
> +
> +#elif defined(CONFIG_ARM64) /* CONFIG_X86 */
> +
> +#define HV_MSR_CRASH_P0 (HV_REGISTER_GUEST_CRASH_P0)
> +#define HV_MSR_CRASH_P1 (HV_REGISTER_GUEST_CRASH_P1)
> +#define HV_MSR_CRASH_P2 (HV_REGISTER_GUEST_CRASH_P2)
> +#define HV_MSR_CRASH_P3 (HV_REGISTER_GUEST_CRASH_P3)
> +#define HV_MSR_CRASH_P4 (HV_REGISTER_GUEST_CRASH_P4)
> +#define HV_MSR_CRASH_CTL (HV_REGISTER_GUEST_CRASH_CTL)
> +
> +#define HV_MSR_VP_INDEX (HV_REGISTER_VP_INDEX)
> +#define HV_MSR_TIME_REF_COUNT (HV_REGISTER_TIME_REF_COUNT)
> +#define HV_MSR_REFERENCE_TSC (HV_REGISTER_REFERENCE_TSC)
> +
> +#define HV_MSR_SINT0 (HV_REGISTER_SINT0)
> +#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_SIRBP (HV_REGISTER_SIRBP)
> +
> +#define HV_MSR_STIMER0_CONFIG (HV_REGISTER_STIMER0_CONFIG)
> +#define HV_MSR_STIMER0_COUNT (HV_REGISTER_STIMER0_COUNT)
> +
> +#endif /* CONFIG_ARM64 */
> +
> +union hv_explicit_suspend_register {
> + u64 as_uint64;
> + struct {
> + u64 suspended : 1;
> + u64 reserved : 63;
> + } __packed;
> +};
> +
> +union hv_intercept_suspend_register {
> + u64 as_uint64;
> + struct {
> + u64 suspended : 1;
> + u64 reserved : 63;
> + } __packed;
> +};
> +
> +union hv_dispatch_suspend_register {
> + u64 as_uint64;
> + struct {
> + u64 suspended : 1;
> + u64 reserved : 63;
> + } __packed;
> +};
> +
> +union hv_x64_interrupt_state_register {
> + u64 as_uint64;
> + struct {
> + u64 interrupt_shadow : 1;
> + u64 nmi_masked : 1;
> + u64 reserved : 62;
> + } __packed;
> +};
> +
> +union hv_x64_pending_interruption_register {
> + u64 as_uint64;
> + struct {
> + u32 interruption_pending : 1;
> + u32 interruption_type : 3;
> + u32 deliver_error_code : 1;
> + u32 instruction_length : 4;
> + u32 nested_event : 1;
> + u32 reserved : 6;
> + u32 interruption_vector : 16;
> + u32 error_code;
> + } __packed;
> +};
> +
> +union hv_register_value {
> + struct hv_u128 reg128;
> + u64 reg64;
> + u32 reg32;
> + u16 reg16;
> + u8 reg8;
> +
> + struct hv_x64_segment_register segment;
> + struct hv_x64_table_register table;
> + union hv_explicit_suspend_register explicit_suspend;
> + union hv_intercept_suspend_register intercept_suspend;
> + union hv_dispatch_suspend_register dispatch_suspend;
> + union hv_x64_interrupt_state_register interrupt_state;
> + union hv_x64_pending_interruption_register pending_interruption;
> +};
> +
> +#if defined(CONFIG_ARM64)
> +/* HvGetVpRegisters returns an array of these output elements */
> +struct hv_get_vp_registers_output {
> + union {
> + struct {
> + u32 a;
> + u32 b;
> + u32 c;
> + u32 d;
> + } as32 __packed;
> + struct {
> + u64 low;
> + u64 high;
> + } as64 __packed;
> + };
> +};
> +
> +#endif /* CONFIG_ARM64 */
> +
> +struct hv_register_assoc {
> + u32 name; /* enum hv_register_name */
> + u32 reserved1;
> + u64 reserved2;
> + union hv_register_value value;
> +} __packed;
> +
> +struct hv_input_get_vp_registers {
> + u64 partition_id;
> + u32 vp_index;
> + union hv_input_vtl input_vtl;
> + u8 rsvd_z8;
> + u16 rsvd_z16;
> + u32 names[];
> +} __packed;
> +
> +struct hv_input_set_vp_registers {
> + u64 partition_id;
> + u32 vp_index;
> + union hv_input_vtl input_vtl;
> + u8 rsvd_z8;
> + u16 rsvd_z16;
> + struct hv_register_assoc elements[];
> +} __packed;
> +
> +#define HV_UNMAP_GPA_LARGE_PAGE 0x2
> +
> +/* HvCallSendSyntheticClusterIpi hypercall */
> +struct hv_send_ipi { /* HV_INPUT_SEND_SYNTHETIC_CLUSTER_IPI */
> + u32 vector;
> + u32 reserved;
> + u64 cpu_mask;
> +} __packed;
> +
> +#define HV_X64_VTL_MASK GENMASK(3, 0)
> +
> +/* Hyper-V memory host visibility */
> +enum hv_mem_host_visibility {
> + VMBUS_PAGE_NOT_VISIBLE = 0,
> + VMBUS_PAGE_VISIBLE_READ_ONLY = 1,
> + VMBUS_PAGE_VISIBLE_READ_WRITE = 3
> +};
> +
> +/* HvCallModifySparseGpaPageHostVisibility hypercall */
> +#define HV_MAX_MODIFY_GPA_REP_COUNT ((PAGE_SIZE / sizeof(u64)) - 2)
> +struct hv_gpa_range_for_visibility {
> + u64 partition_id;
> + u32 host_visibility : 2;
> + u32 reserved0 : 30;
> + u32 reserved1;
> + u64 gpa_page_list[HV_MAX_MODIFY_GPA_REP_COUNT];
> +} __packed;
> +
> +#if defined(CONFIG_X86)
> +union hv_msi_address_register { /* HV_MSI_ADDRESS */
> + u32 as_uint32;
> + struct {
> + u32 reserved1 : 2;
> + u32 destination_mode : 1;
> + u32 redirection_hint : 1;
> + u32 reserved2 : 8;
> + u32 destination_id : 8;
> + u32 msi_base : 12;
> + };
> +} __packed;
> +
> +union hv_msi_data_register { /* HV_MSI_ENTRY.Data */
> + u32 as_uint32;
> + struct {
> + u32 vector : 8;
> + u32 delivery_mode : 3;
> + u32 reserved1 : 3;
> + u32 level_assert : 1;
> + u32 trigger_mode : 1;
> + u32 reserved2 : 16;
> + };
> +} __packed;
> +
> +union hv_msi_entry { /* HV_MSI_ENTRY */
> +
> + u64 as_uint64;
> + struct {
> + union hv_msi_address_register address;
> + union hv_msi_data_register data;
> + } __packed;
> +};
> +
> +#elif defined(CONFIG_ARM64) /* CONFIG_X86 */
> +
> +union hv_msi_entry {
> + u64 as_uint64[2];
> + struct {
> + u64 address;
> + u32 data;
> + u32 reserved;
> + } __packed;
> +};
> +#endif /* CONFIG_ARM64 */
> +
> +union hv_ioapic_rte {
> + u64 as_uint64;
> +
> + struct {
> + u32 vector : 8;
> + u32 delivery_mode : 3;
> + u32 destination_mode : 1;
> + u32 delivery_status : 1;
> + u32 interrupt_polarity : 1;
> + u32 remote_irr : 1;
> + u32 trigger_mode : 1;
> + u32 interrupt_mask : 1;
> + u32 reserved1 : 15;
> +
> + u32 reserved2 : 24;
> + u32 destination_id : 8;
> + };
> +
> + struct {
> + u32 low_uint32;
> + u32 high_uint32;
> + };
> +} __packed;
> +
> +enum hv_interrupt_source { /* HV_INTERRUPT_SOURCE */
> + HV_INTERRUPT_SOURCE_MSI = 1, /* MSI and MSI-X */
> + HV_INTERRUPT_SOURCE_IOAPIC,
> +};
> +
> +struct hv_interrupt_entry { /* HV_INTERRUPT_ENTRY */
> + u32 source;
> + u32 reserved1;
> + union {
> + union hv_msi_entry msi_entry;
> + union hv_ioapic_rte ioapic_rte;
> + };
> +} __packed;
> +
> +#define HV_DEVICE_INTERRUPT_TARGET_MULTICAST 1
> +#define HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET 2
> +
> +struct hv_device_interrupt_target { /* HV_DEVICE_INTERRUPT_TARGET */
> + u32 vector;
> + u32 flags; /* HV_DEVICE_INTERRUPT_TARGET_* above */
> + union {
> + u64 vp_mask;
> + struct hv_vpset vp_set;
> + };
> +} __packed;
> +
> +struct hv_retarget_device_interrupt { /* HV_INPUT_RETARGET_DEVICE_INTERRUPT
> */
> + u64 partition_id; /* use "self" */
> + u64 device_id;
> + struct hv_interrupt_entry int_entry;
> + u64 reserved2;
> + struct hv_device_interrupt_target int_target;
> +} __packed __aligned(8);
> +
> +/* Data structures for HVCALL_MMIO_READ and HVCALL_MMIO_WRITE */
> +#define HV_HYPERCALL_MMIO_MAX_DATA_LENGTH 64
> +
> +struct hv_mmio_read_input { /* HV_INPUT_MEMORY_MAPPED_IO_READ */
> + u64 gpa;
> + u32 size;
> + u32 reserved;
> +} __packed;
> +
> +struct hv_mmio_read_output {
> + u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH];
> +} __packed;
> +
> +struct hv_mmio_write_input {
> + u64 gpa;
> + u32 size;
> + u32 reserved;
> + u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH];
> +} __packed;
> +
> +#endif /* _HV_HVGDK_MINI_H */
> diff --git a/include/hyperv/hvhdk.h b/include/hyperv/hvhdk.h
> new file mode 100644
> index 000000000000..64407c2a3809
> --- /dev/null
> +++ b/include/hyperv/hvhdk.h
> @@ -0,0 +1,733 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Type definitions for the Microsoft hypervisor.
> + */
> +#ifndef _HV_HVHDK_H
> +#define _HV_HVHDK_H
> +
> +#include <linux/build_bug.h>
> +
> +#include "hvhdk_mini.h"
> +#include "hvgdk.h"
> +
> +/* Bits for dirty mask of hv_vp_register_page */
> +#define HV_X64_REGISTER_CLASS_GENERAL 0
> +#define HV_X64_REGISTER_CLASS_IP 1
> +#define HV_X64_REGISTER_CLASS_XMM 2
> +#define HV_X64_REGISTER_CLASS_SEGMENT 3
> +#define HV_X64_REGISTER_CLASS_FLAGS 4
> +
> +#define HV_VP_REGISTER_PAGE_VERSION_1 1u
> +
> +struct hv_vp_register_page {
> + u16 version;
> + u8 isvalid;
> + u8 rsvdz;
> + u32 dirty;
> + union {
> + struct {
> + /* General purpose registers
> + * (HV_X64_REGISTER_CLASS_GENERAL)
> + */
> + union {
> + struct {
> + u64 rax;
> + u64 rcx;
> + u64 rdx;
> + u64 rbx;
> + u64 rsp;
> + u64 rbp;
> + u64 rsi;
> + u64 rdi;
> + u64 r8;
> + u64 r9;
> + u64 r10;
> + u64 r11;
> + u64 r12;
> + u64 r13;
> + u64 r14;
> + u64 r15;
> + } __packed;
> +
> + u64 gp_registers[16];
> + };
> + /* Instruction pointer (HV_X64_REGISTER_CLASS_IP) */
> + u64 rip;
> + /* Flags (HV_X64_REGISTER_CLASS_FLAGS) */
> + u64 rflags;
> + } __packed;
> +
> + u64 registers[18];
> + };
> + /* Volatile XMM registers (HV_X64_REGISTER_CLASS_XMM) */
> + union {
> + struct {
> + struct hv_u128 xmm0;
> + struct hv_u128 xmm1;
> + struct hv_u128 xmm2;
> + struct hv_u128 xmm3;
> + struct hv_u128 xmm4;
> + struct hv_u128 xmm5;
> + } __packed;
> +
> + struct hv_u128 xmm_registers[6];
> + };
> + /* Segment registers (HV_X64_REGISTER_CLASS_SEGMENT) */
> + union {
> + struct {
> + struct hv_x64_segment_register es;
> + struct hv_x64_segment_register cs;
> + struct hv_x64_segment_register ss;
> + struct hv_x64_segment_register ds;
> + struct hv_x64_segment_register fs;
> + struct hv_x64_segment_register gs;
> + } __packed;
> +
> + struct hv_x64_segment_register segment_registers[6];
> + };
> + /* Misc. control registers (cannot be set via this interface) */
> + u64 cr0;
> + u64 cr3;
> + u64 cr4;
> + u64 cr8;
> + u64 efer;
> + u64 dr7;
> + union hv_x64_pending_interruption_register pending_interruption;
> + union hv_x64_interrupt_state_register interrupt_state;
> + u64 instruction_emulation_hints;
> +} __packed;
> +
> +#define HV_PARTITION_PROCESSOR_FEATURES_BANKS 2
> +
> +union hv_partition_processor_features {
> + u64 as_uint64[HV_PARTITION_PROCESSOR_FEATURES_BANKS];
> + struct {
> + u64 sse3_support : 1;
> + u64 lahf_sahf_support : 1;
> + u64 ssse3_support : 1;
> + u64 sse4_1_support : 1;
> + u64 sse4_2_support : 1;
> + u64 sse4a_support : 1;
> + u64 xop_support : 1;
> + u64 pop_cnt_support : 1;
> + u64 cmpxchg16b_support : 1;
> + u64 altmovcr8_support : 1;
> + u64 lzcnt_support : 1;
> + u64 mis_align_sse_support : 1;
> + u64 mmx_ext_support : 1;
> + u64 amd3dnow_support : 1;
> + u64 extended_amd3dnow_support : 1;
> + u64 page_1gb_support : 1;
> + u64 aes_support : 1;
> + u64 pclmulqdq_support : 1;
> + u64 pcid_support : 1;
> + u64 fma4_support : 1;
> + u64 f16c_support : 1;
> + u64 rd_rand_support : 1;
> + u64 rd_wr_fs_gs_support : 1;
> + u64 smep_support : 1;
> + u64 enhanced_fast_string_support : 1;
> + u64 bmi1_support : 1;
> + u64 bmi2_support : 1;
> + u64 hle_support_deprecated : 1;
> + u64 rtm_support_deprecated : 1;
> + u64 movbe_support : 1;
> + u64 npiep1_support : 1;
> + u64 dep_x87_fpu_save_support : 1;
> + u64 rd_seed_support : 1;
> + u64 adx_support : 1;
> + u64 intel_prefetch_support : 1;
> + u64 smap_support : 1;
> + u64 hle_support : 1;
> + u64 rtm_support : 1;
> + u64 rdtscp_support : 1;
> + u64 clflushopt_support : 1;
> + u64 clwb_support : 1;
> + u64 sha_support : 1;
> + u64 x87_pointers_saved_support : 1;
> + u64 invpcid_support : 1;
> + u64 ibrs_support : 1;
> + u64 stibp_support : 1;
> + u64 ibpb_support: 1;
> + u64 unrestricted_guest_support : 1;
> + u64 mdd_support : 1;
> + u64 fast_short_rep_mov_support : 1;
> + u64 l1dcache_flush_support : 1;
> + u64 rdcl_no_support : 1;
> + u64 ibrs_all_support : 1;
> + u64 skip_l1df_support : 1;
> + u64 ssb_no_support : 1;
> + u64 rsb_a_no_support : 1;
> + u64 virt_spec_ctrl_support : 1;
> + u64 rd_pid_support : 1;
> + u64 umip_support : 1;
> + u64 mbs_no_support : 1;
> + u64 mb_clear_support : 1;
> + u64 taa_no_support : 1;
> + u64 tsx_ctrl_support : 1;
> + /*
> + * N.B. The final processor feature bit in bank 0 is reserved to
> + * simplify potential downlevel backports.
> + */
> + u64 reserved_bank0 : 1;
> +
> + /* N.B. Begin bank 1 processor features. */
> + u64 acount_mcount_support : 1;
> + u64 tsc_invariant_support : 1;
> + u64 cl_zero_support : 1;
> + u64 rdpru_support : 1;
> + u64 la57_support : 1;
> + u64 mbec_support : 1;
> + u64 nested_virt_support : 1;
> + u64 psfd_support : 1;
> + u64 cet_ss_support : 1;
> + u64 cet_ibt_support : 1;
> + u64 vmx_exception_inject_support : 1;
> + u64 enqcmd_support : 1;
> + u64 umwait_tpause_support : 1;
> + u64 movdiri_support : 1;
> + u64 movdir64b_support : 1;
> + u64 cldemote_support : 1;
> + u64 serialize_support : 1;
> + u64 tsc_deadline_tmr_support : 1;
> + u64 tsc_adjust_support : 1;
> + u64 fzlrep_movsb : 1;
> + u64 fsrep_stosb : 1;
> + u64 fsrep_cmpsb : 1;
> + u64 reserved_bank1 : 42;
> + } __packed;
> +};
> +
> +union hv_partition_processor_xsave_features {
> + struct {
> + u64 xsave_support : 1;
> + u64 xsaveopt_support : 1;
> + u64 avx_support : 1;
> + u64 reserved1 : 61;
> + } __packed;
> + u64 as_uint64;
> +};
> +
> +struct hv_partition_creation_properties {
> + union hv_partition_processor_features disabled_processor_features;
> + union hv_partition_processor_xsave_features
> + disabled_processor_xsave_features;
> +} __packed;
> +
> +#define HV_PARTITION_SYNTHETIC_PROCESSOR_FEATURES_BANKS 1
> +
> +union hv_partition_synthetic_processor_features {
> + u64 as_uint64[HV_PARTITION_SYNTHETIC_PROCESSOR_FEATURES_BANKS];
> +
> + struct {
> + u64 hypervisor_present : 1;
> + /* Support for HV#1: (CPUID leaves 0x40000000 - 0x40000006)*/
> + u64 hv1 : 1;
> + u64 access_vp_run_time_reg : 1; /* HV_X64_MSR_VP_RUNTIME */
> + u64 access_partition_reference_counter : 1; /*
> HV_X64_MSR_TIME_REF_COUNT */
> + u64 access_synic_regs : 1; /* SINT-related registers */
> + /*
> + * Access to HV_X64_MSR_STIMER0_CONFIG through
> + * HV_X64_MSR_STIMER3_COUNT.
> + */
> + u64 access_synthetic_timer_regs : 1;
> + u64 access_intr_ctrl_regs : 1; /* APIC MSRs and VP assist page*/
> + /* HV_X64_MSR_GUEST_OS_ID and HV_X64_MSR_HYPERCALL */
> + u64 access_hypercall_regs : 1;
> + u64 access_vp_index : 1;
> + u64 access_partition_reference_tsc : 1;
> + u64 access_guest_idle_reg : 1;
> + u64 access_frequency_regs : 1;
> + u64 reserved_z12 : 1;
> + u64 reserved_z13 : 1;
> + u64 reserved_z14 : 1;
> + u64 enable_extended_gva_ranges_for_flush_virtual_address_list : 1;
> + u64 reserved_z16 : 1;
> + u64 reserved_z17 : 1;
> + /* Use fast hypercall output. Corresponds to privilege. */
> + u64 fast_hypercall_output : 1;
> + u64 reserved_z19 : 1;
> + u64 start_virtual_processor : 1; /* Can start VPs */
> + u64 reserved_z21 : 1;
> + /* Synthetic timers in direct mode. */
> + u64 direct_synthetic_timers : 1;
> + u64 reserved_z23 : 1;
> + u64 extended_processor_masks : 1;
> +
> + /* Enable various hypercalls */
> + u64 tb_flush_hypercalls : 1;
> + u64 synthetic_cluster_ipi : 1;
> + u64 notify_long_spin_wait : 1;
> + u64 query_numa_distance : 1;
> + u64 signal_events : 1;
> + u64 retarget_device_interrupt : 1;
> + u64 restore_time : 1;
> +
> + /* EnlightenedVmcs nested enlightenment is supported. */
> + u64 enlightened_vmcs : 1;
> + u64 reserved : 31;
> + } __packed;
> +};
> +
> +#define HV_MAKE_COMPATIBILITY_VERSION(major_, minor_) \
> + ((u32)((major_) << 8 | (minor_)))
> +
> +#define HV_COMPATIBILITY_21_H2
> HV_MAKE_COMPATIBILITY_VERSION(0X6, 0X9)
> +
> +union hv_partition_isolation_properties {
> + u64 as_uint64;
> + struct {
> + u64 isolation_type: 5;
> + u64 isolation_host_type : 2;
> + u64 rsvd_z: 5;
> + u64 shared_gpa_boundary_page_number: 52;
> + } __packed;
> +};
> +
> +/*
> + * Various isolation types supported by MSHV.
> + */
> +#define HV_PARTITION_ISOLATION_TYPE_NONE 0
> +#define HV_PARTITION_ISOLATION_TYPE_SNP 2
> +#define HV_PARTITION_ISOLATION_TYPE_TDX 3
> +
> +/*
> + * Various host isolation types supported by MSHV.
> + */
> +#define HV_PARTITION_ISOLATION_HOST_TYPE_NONE 0x0
> +#define HV_PARTITION_ISOLATION_HOST_TYPE_HARDWARE 0x1
> +#define HV_PARTITION_ISOLATION_HOST_TYPE_RESERVED 0x2
> +
> +/* Note: Exo partition is enabled by default */
> +#define HV_PARTITION_CREATION_FLAG_EXO_PARTITION BIT(8)
> +#define HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED BIT(13)
> +#define HV_PARTITION_CREATION_FLAG_INTERCEPT_MESSAGE_PAGE_ENABLED
> BIT(19)
> +#define HV_PARTITION_CREATION_FLAG_X2APIC_CAPABLE BIT(22)
> +
> +struct hv_input_create_partition {
> + u64 flags;
> + struct hv_proximity_domain_info proximity_domain_info;
> + u32 compatibility_version;
> + u32 padding;
> + struct hv_partition_creation_properties partition_creation_properties;
> + union hv_partition_isolation_properties isolation_properties;
> +} __packed;
> +
> +struct hv_output_create_partition {
> + u64 partition_id;
> +} __packed;
> +
> +struct hv_input_initialize_partition {
> + u64 partition_id;
> +} __packed;
> +
> +struct hv_input_finalize_partition {
> + u64 partition_id;
> +} __packed;
> +
> +struct hv_input_delete_partition {
> + u64 partition_id;
> +} __packed;
> +
> +struct hv_input_get_partition_property {
> + u64 partition_id;
> + u32 property_code; /* enum hv_partition_property_code */
> + u32 padding;
> +} __packed;
> +
> +struct hv_output_get_partition_property {
> + u64 property_value;
> +} __packed;
> +
> +struct hv_input_set_partition_property {
> + u64 partition_id;
> + u32 property_code; /* enum hv_partition_property_code */
> + u32 padding;
> + u64 property_value;
> +} __packed;
> +
> +enum hv_vp_state_page_type {
> + HV_VP_STATE_PAGE_REGISTERS = 0,
> + HV_VP_STATE_PAGE_INTERCEPT_MESSAGE = 1,
> + HV_VP_STATE_PAGE_COUNT
> +};
> +
> +struct hv_input_map_vp_state_page {
> + u64 partition_id;
> + u32 vp_index;
> + u32 type; /* enum hv_vp_state_page_type */
> +} __packed;
> +
> +struct hv_output_map_vp_state_page {
> + u64 map_location; /* GPA page number */
> +} __packed;
> +
> +struct hv_input_unmap_vp_state_page {
> + u64 partition_id;
> + u32 vp_index;
> + u32 type; /* enum hv_vp_state_page_type */
> +} __packed;
> +
> +struct hv_opaque_intercept_message {
> + u32 vp_index;
> +} __packed;
> +
> +enum hv_port_type {
> + HV_PORT_TYPE_MESSAGE = 1,
> + HV_PORT_TYPE_EVENT = 2,
> + HV_PORT_TYPE_MONITOR = 3,
> + HV_PORT_TYPE_DOORBELL = 4 /* Root Partition only */
> +};
> +
> +struct hv_port_info {
> + u32 port_type; /* enum hv_port_type */
> + u32 padding;
> + union {
> + struct {
> + u32 target_sint;
> + u32 target_vp;
> + u64 rsvdz;
> + } message_port_info;
> + struct {
> + u32 target_sint;
> + u32 target_vp;
> + u16 base_flag_number;
> + u16 flag_count;
> + u32 rsvdz;
> + } event_port_info;
> + struct {
> + u64 monitor_address;
> + u64 rsvdz;
> + } monitor_port_info;
> + struct {
> + u32 target_sint;
> + u32 target_vp;
> + u64 rsvdz;
> + } doorbell_port_info;
> + };
> +} __packed;
> +
> +struct hv_connection_info {
> + u32 port_type;
> + u32 padding;
> + union {
> + struct {
> + u64 rsvdz;
> + } message_connection_info;
> + struct {
> + u64 rsvdz;
> + } event_connection_info;
> + struct {
> + u64 monitor_address;
> + } monitor_connection_info;
> + struct {
> + u64 gpa;
> + u64 trigger_value;
> + u64 flags;
> + } doorbell_connection_info;
> + };
> +} __packed;
> +
> +/* Define synthetic interrupt controller flag constants. */
> +#define HV_EVENT_FLAGS_COUNT (256 * 8)
> +#define HV_EVENT_FLAGS_BYTE_COUNT (256)
> +#define HV_EVENT_FLAGS32_COUNT (256 / sizeof(u32))
> +
> +/* linux side we create long version of flags to use long bit ops on flags */
> +#define HV_EVENT_FLAGS_UL_COUNT (256 / sizeof(ulong))
> +
> +/* Define the synthetic interrupt controller event flags format. */
> +union hv_synic_event_flags {
> + unsigned char flags8[HV_EVENT_FLAGS_BYTE_COUNT];
> + u32 flags32[HV_EVENT_FLAGS32_COUNT];
> + ulong flags[HV_EVENT_FLAGS_UL_COUNT]; /* linux only */
> +};
> +
> +struct hv_synic_event_flags_page {
> + volatile union hv_synic_event_flags event_flags[HV_SYNIC_SINT_COUNT];
> +};
> +
> +#define HV_SYNIC_EVENT_RING_MESSAGE_COUNT 63
> +
> +struct hv_synic_event_ring {
> + u8 signal_masked;
> + u8 ring_full;
> + u16 reserved_z;
> + u32 data[HV_SYNIC_EVENT_RING_MESSAGE_COUNT];
> +} __packed;
> +
> +struct hv_synic_event_ring_page {
> + struct hv_synic_event_ring sint_event_ring[HV_SYNIC_SINT_COUNT];
> +};
> +
> +/* Define SynIC control register. */
> +union hv_synic_scontrol {
> + u64 as_uint64;
> + struct {
> + u64 enable : 1;
> + u64 reserved : 63;
> + } __packed;
> +};
> +
> +/* Define the format of the SIEFP register */
> +union hv_synic_siefp {
> + u64 as_uint64;
> + struct {
> + u64 siefp_enabled : 1;
> + u64 preserved : 11;
> + u64 base_siefp_gpa : 52;
> + } __packed;
> +};
> +
> +union hv_synic_sirbp {
> + u64 as_uint64;
> + struct {
> + u64 sirbp_enabled : 1;
> + u64 preserved : 11;
> + u64 base_sirbp_gpa : 52;
> + } __packed;
> +};
> +
> +union hv_interrupt_control {
> + u64 as_uint64;
> + struct {
> + u32 interrupt_type; /* enum hv_interrupt_type */
> + u32 level_triggered : 1;
> + u32 logical_dest_mode : 1;
> + u32 rsvd : 30;
> + } __packed;
> +};
> +
> +struct hv_stimer_state {
> + struct {
> + u32 undelivered_msg_pending : 1;
> + u32 reserved : 31;
> + } __packed flags;
> + u32 resvd;
> + u64 config;
> + u64 count;
> + u64 adjustment;
> + u64 undelivered_exp_time;
> +} __packed;
> +
> +struct hv_synthetic_timers_state {
> + struct hv_stimer_state timers[HV_SYNIC_STIMER_COUNT];
> + u64 reserved[5];
> +} __packed;
> +
> +union hv_input_delete_vp {
> + u64 as_uint64[2];
> + struct {
> + u64 partition_id;
> + u32 vp_index;
> + u8 reserved[4];
> + } __packed;
> +} __packed;
> +
> +struct hv_input_assert_virtual_interrupt {
> + u64 partition_id;
> + union hv_interrupt_control control;
> + u64 dest_addr; /* cpu's apic id */
> + u32 vector;
> + u8 target_vtl;
> + u8 rsvd_z0;
> + u16 rsvd_z1;
> +} __packed;
> +
> +struct hv_input_create_port {
> + u64 port_partition_id;
> + union hv_port_id port_id;
> + u8 port_vtl;
> + u8 min_connection_vtl;
> + u16 padding;
> + u64 connection_partition_id;
> + struct hv_port_info port_info;
> + struct hv_proximity_domain_info proximity_domain_info;
> +} __packed;
> +
> +union hv_input_delete_port {
> + u64 as_uint64[2];
> + struct {
> + u64 port_partition_id;
> + union hv_port_id port_id;
> + u32 reserved;
> + };
> +} __packed;
> +
> +struct hv_input_connect_port {
> + u64 connection_partition_id;
> + union hv_connection_id connection_id;
> + u8 connection_vtl;
> + u8 rsvdz0;
> + u16 rsvdz1;
> + u64 port_partition_id;
> + union hv_port_id port_id;
> + u32 reserved2;
> + struct hv_connection_info connection_info;
> + struct hv_proximity_domain_info proximity_domain_info;
> +} __packed;
> +
> +union hv_input_disconnect_port {
> + u64 as_uint64[2];
> + struct {
> + u64 connection_partition_id;
> + union hv_connection_id connection_id;
> + u32 is_doorbell: 1;
> + u32 reserved: 31;
> + } __packed;
> +} __packed;
> +
> +union hv_input_notify_port_ring_empty {
> + u64 as_uint64;
> + struct {
> + u32 sint_index;
> + u32 reserved;
> + };
> +} __packed;
> +
> +struct hv_vp_state_data_xsave {
> + u64 flags;
> + union hv_x64_xsave_xfem_register states;
> +} __packed;
> +
> +/*
> + * For getting and setting VP state, there are two options based on the state type:
> + *
> + * 1.) Data that is accessed by PFNs in the input hypercall page. This is used
> + * for state which may not fit into the hypercall pages.
> + * 2.) Data that is accessed directly in the input\output hypercall pages.
> + * This is used for state that will always fit into the hypercall pages.
> + *
> + * In the future this could be dynamic based on the size if needed.
> + *
> + * Note these hypercalls have an 8-byte aligned variable header size as per the tlfs
> + */
> +
> +#define HV_GET_SET_VP_STATE_TYPE_PFN BIT(31)
> +
> +enum hv_get_set_vp_state_type {
> + /* HvGetSetVpStateLocalInterruptControllerState - APIC/GIC state */
> + HV_GET_SET_VP_STATE_LAPIC_STATE = 0 |
> HV_GET_SET_VP_STATE_TYPE_PFN,
> + HV_GET_SET_VP_STATE_XSAVE = 1 | HV_GET_SET_VP_STATE_TYPE_PFN,
> + HV_GET_SET_VP_STATE_SIM_PAGE = 2 |
> HV_GET_SET_VP_STATE_TYPE_PFN,
> + HV_GET_SET_VP_STATE_SIEF_PAGE = 3 |
> HV_GET_SET_VP_STATE_TYPE_PFN,
> + HV_GET_SET_VP_STATE_SYNTHETIC_TIMERS = 4,
> +};
> +
> +struct hv_vp_state_data {
> + u32 type;
> + u32 rsvd;
> + struct hv_vp_state_data_xsave xsave;
> +} __packed;
> +
> +struct hv_input_get_vp_state {
> + u64 partition_id;
> + u32 vp_index;
> + u8 input_vtl;
> + u8 rsvd0;
> + u16 rsvd1;
> + struct hv_vp_state_data state_data;
> + u64 output_data_pfns[];
> +} __packed;
> +
> +union hv_output_get_vp_state {
> + struct hv_synthetic_timers_state synthetic_timers_state;
> +} __packed;
> +
> +union hv_input_set_vp_state_data {
> + u64 pfns;
> + u8 bytes;
> +} __packed;
> +
> +struct hv_input_set_vp_state {
> + u64 partition_id;
> + u32 vp_index;
> + u8 input_vtl;
> + u8 rsvd0;
> + u16 rsvd1;
> + struct hv_vp_state_data state_data;
> + union hv_input_set_vp_state_data data[];
> +} __packed;
> +
> +/*
> + * Dispatch state for the VP communicated by the hypervisor to the
> + * VP-dispatching thread in the root on return from HVCALL_DISPATCH_VP.
> + */
> +enum hv_vp_dispatch_state {
> + HV_VP_DISPATCH_STATE_INVALID = 0,
> + HV_VP_DISPATCH_STATE_BLOCKED = 1,
> + HV_VP_DISPATCH_STATE_READY = 2,
> +};
> +
> +/*
> + * Dispatch event that caused the current dispatch state on return from
> + * HVCALL_DISPATCH_VP.
> + */
> +enum hv_vp_dispatch_event {
> + HV_VP_DISPATCH_EVENT_INVALID = 0x00000000,
> + HV_VP_DISPATCH_EVENT_SUSPEND = 0x00000001,
> + HV_VP_DISPATCH_EVENT_INTERCEPT = 0x00000002,
> +};
> +
> +#define HV_ROOT_SCHEDULER_MAX_VPS_PER_CHILD_PARTITION 1024
> +/* The maximum array size of HV_GENERIC_SET (vp_set) buffer */
> +#define HV_GENERIC_SET_QWORD_COUNT(max) (((((max) - 1) >> 6) + 1) + 2)
> +
> +struct hv_vp_signal_bitset_scheduler_message {
> + u64 partition_id;
> + u32 overflow_count;
> + u16 vp_count;
> + u16 reserved;
> +
> +#define BITSET_BUFFER_SIZE \
> +
> HV_GENERIC_SET_QWORD_COUNT(HV_ROOT_SCHEDULER_MAX_VPS_PER_C
> HILD_PARTITION)
> + union {
> + struct hv_vpset bitset;
> + u64 bitset_buffer[BITSET_BUFFER_SIZE];
> + } vp_bitset;
> +#undef BITSET_BUFFER_SIZE
> +} __packed;
> +
> +static_assert(sizeof(struct hv_vp_signal_bitset_scheduler_message) <=
> + (sizeof(struct hv_message) - sizeof(struct hv_message_header)));
> +
> +#define HV_MESSAGE_MAX_PARTITION_VP_PAIR_COUNT \
> + (((sizeof(struct hv_message) - sizeof(struct hv_message_header)) / \
> + (sizeof(u64 /* partition id */) + sizeof(u32 /* vp index */))) - 1)
> +
> +struct hv_vp_signal_pair_scheduler_message {
> + u32 overflow_count;
> + u8 vp_count;
> + u8 reserved1[3];
> +
> + u64 partition_ids[HV_MESSAGE_MAX_PARTITION_VP_PAIR_COUNT];
> + u32 vp_indexes[HV_MESSAGE_MAX_PARTITION_VP_PAIR_COUNT];
> +
> + u8 reserved2[4];
> +} __packed;
> +
> +static_assert(sizeof(struct hv_vp_signal_pair_scheduler_message) ==
> + (sizeof(struct hv_message) - sizeof(struct hv_message_header)));
> +
> +/* Input and output structures for HVCALL_DISPATCH_VP */
> +#define HV_DISPATCH_VP_FLAG_CLEAR_INTERCEPT_SUSPEND 0x1
> +#define HV_DISPATCH_VP_FLAG_ENABLE_CALLER_INTERRUPTS 0x2
> +#define HV_DISPATCH_VP_FLAG_SET_CALLER_SPEC_CTRL 0x4
> +#define HV_DISPATCH_VP_FLAG_SKIP_VP_SPEC_FLUSH 0x8
> +#define HV_DISPATCH_VP_FLAG_SKIP_CALLER_SPEC_FLUSH 0x10
> +#define HV_DISPATCH_VP_FLAG_SKIP_CALLER_USER_SPEC_FLUSH 0x20
> +
> +struct hv_input_dispatch_vp {
> + u64 partition_id;
> + u32 vp_index;
> + u32 flags;
> + u64 time_slice; /* in 100ns */
> + u64 spec_ctrl;
> +} __packed;
> +
> +struct hv_output_dispatch_vp {
> + u32 dispatch_state; /* enum hv_vp_dispatch_state */
> + u32 dispatch_event; /* enum hv_vp_dispatch_event */
> +} __packed;
> +
> +#endif /* _HV_HVHDK_H */
> diff --git a/include/hyperv/hvhdk_mini.h b/include/hyperv/hvhdk_mini.h
> new file mode 100644
> index 000000000000..46938b664f0c
> --- /dev/null
> +++ b/include/hyperv/hvhdk_mini.h
> @@ -0,0 +1,310 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Type definitions for the Microsoft Hypervisor.
> + */
> +#ifndef _HV_HVHDK_MINI_H
> +#define _HV_HVHDK_MINI_H
> +
> +#include "hvgdk_mini.h"
> +
> +/*
> + * Doorbell connection_info flags.
> + */
> +#define HV_DOORBELL_FLAG_TRIGGER_SIZE_MASK 0x00000007
> +#define HV_DOORBELL_FLAG_TRIGGER_SIZE_ANY 0x00000000
> +#define HV_DOORBELL_FLAG_TRIGGER_SIZE_BYTE 0x00000001
> +#define HV_DOORBELL_FLAG_TRIGGER_SIZE_WORD 0x00000002
> +#define HV_DOORBELL_FLAG_TRIGGER_SIZE_DWORD 0x00000003
> +#define HV_DOORBELL_FLAG_TRIGGER_SIZE_QWORD 0x00000004
> +#define HV_DOORBELL_FLAG_TRIGGER_ANY_VALUE 0x80000000
> +
> +/* Each generic set contains 64 elements */
> +#define HV_GENERIC_SET_SHIFT (6)
> +#define HV_GENERIC_SET_MASK (63)
> +
> +enum hv_generic_set_format {
> + HV_GENERIC_SET_SPARSE_4K,
> + HV_GENERIC_SET_ALL,
> +};
> +
> +enum hv_scheduler_type {
> + HV_SCHEDULER_TYPE_LP = 1, /* Classic scheduler w/o SMT */
> + HV_SCHEDULER_TYPE_LP_SMT = 2, /* Classic scheduler w/ SMT */
> + HV_SCHEDULER_TYPE_CORE_SMT = 3, /* Core scheduler */
> + HV_SCHEDULER_TYPE_ROOT = 4, /* Root / integrated scheduler */
> + HV_SCHEDULER_TYPE_MAX
> +};
> +
> +enum hv_partition_property_code {
> + /* Privilege properties */
> + HV_PARTITION_PROPERTY_PRIVILEGE_FLAGS = 0x00010000,
> + HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES =
> 0x00010001,
> +
> + /* Resource properties */
> + HV_PARTITION_PROPERTY_GPA_PAGE_ACCESS_TRACKING =
> 0x00050005,
> + HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION =
> 0x00050017,
> +
> + /* Compatibility properties */
> + HV_PARTITION_PROPERTY_PROCESSOR_XSAVE_FEATURES =
> 0x00060002,
> + HV_PARTITION_PROPERTY_MAX_XSAVE_DATA_SIZE = 0x00060008,
> + HV_PARTITION_PROPERTY_PROCESSOR_CLOCK_FREQUENCY =
> 0x00060009,
> +};
> +
> +enum hv_system_property {
> + /* Add more values when needed */
> + HV_SYSTEM_PROPERTY_SCHEDULER_TYPE = 15,
> +};
> +
> +struct hv_input_get_system_property {
> + u32 property_id; /* enum hv_system_property */
> + union {
> + u32 as_uint32;
> + /* More fields to be filled in when needed */
> + };
> +} __packed;
> +
> +struct hv_output_get_system_property {
> + union {
> + u32 scheduler_type; /* enum hv_scheduler_type */
> + };
> +} __packed;
> +
> +struct hv_proximity_domain_flags {
> + u32 proximity_preferred : 1;
> + u32 reserved : 30;
> + u32 proximity_info_valid : 1;
> +} __packed;
> +
> +struct hv_proximity_domain_info {
> + u32 domain_id;
> + struct hv_proximity_domain_flags flags;
> +} __packed;
> +
> +/* HvDepositMemory hypercall */
> +struct hv_deposit_memory { /* HV_INPUT_DEPOSIT_MEMORY */
> + u64 partition_id;
> + u64 gpa_page_list[];
> +} __packed;
> +
> +struct hv_input_withdraw_memory {
> + u64 partition_id;
> + struct hv_proximity_domain_info proximity_domain_info;
> +} __packed;
> +
> +struct hv_output_withdraw_memory {
> + DECLARE_FLEX_ARRAY(u64, gpa_page_list);
> +} __packed;
> +
> +/* HV Map GPA (Guest Physical Address) Flags */
> +#define HV_MAP_GPA_PERMISSIONS_NONE 0x0
> +#define HV_MAP_GPA_READABLE 0x1
> +#define HV_MAP_GPA_WRITABLE 0x2
> +#define HV_MAP_GPA_KERNEL_EXECUTABLE 0x4
> +#define HV_MAP_GPA_USER_EXECUTABLE 0x8
> +#define HV_MAP_GPA_EXECUTABLE 0xC
> +#define HV_MAP_GPA_PERMISSIONS_MASK 0xF
> +#define HV_MAP_GPA_ADJUSTABLE 0x8000
> +#define HV_MAP_GPA_NO_ACCESS 0x10000
> +#define HV_MAP_GPA_NOT_CACHED 0x200000
> +#define HV_MAP_GPA_LARGE_PAGE 0x80000000
> +
> +struct hv_input_map_gpa_pages {
> + u64 target_partition_id;
> + u64 target_gpa_base;
> + u32 map_flags;
> + u32 padding;
> + u64 source_gpa_page_list[];
> +} __packed;
> +
> +union hv_gpa_page_access_state_flags {
> + struct {
> + u64 clear_accessed : 1;
> + u64 set_accessed : 1;
> + u64 clear_dirty : 1;
> + u64 set_dirty : 1;
> + u64 reserved : 60;
> + } __packed;
> + u64 as_uint64;
> +};
> +
> +struct hv_input_get_gpa_pages_access_state {
> + u64 partition_id;
> + union hv_gpa_page_access_state_flags flags;
> + u64 hv_gpa_page_number;
> +} __packed;
> +
> +union hv_gpa_page_access_state {
> + struct {
> + u8 accessed : 1;
> + u8 dirty : 1;
> + u8 reserved: 6;
> + };
> + u8 as_uint8;
> +} __packed;
> +
> +struct hv_lp_startup_status {
> + u64 hv_status;
> + u64 substatus1;
> + u64 substatus2;
> + u64 substatus3;
> + u64 substatus4;
> + u64 substatus5;
> + u64 substatus6;
> +} __packed;
> +
> +struct hv_input_add_logical_processor {
> + u32 lp_index;
> + u32 apic_id;
> + struct hv_proximity_domain_info proximity_domain_info;
> +} __packed;
> +
> +struct hv_output_add_logical_processor {
> + struct hv_lp_startup_status startup_status;
> +} __packed;
> +
> +enum { /* HV_SUBNODE_TYPE */
> + HV_SUBNODE_ANY = 0,
> + HV_SUBNODE_SOCKET,
> + HV_SUBNODE_CLUSTER,
> + HV_SUBNODE_L3,
> + HV_SUBNODE_COUNT,
> + HV_SUBNODE_INVALID = -1
> +};
> +
> +struct hv_create_vp { /* HV_INPUT_CREATE_VP */
> + u64 partition_id;
> + u32 vp_index;
> + u8 padding[3];
> + u8 subnode_type;
> + u64 subnode_id;
> + struct hv_proximity_domain_info proximity_domain_info;
> + u64 flags;
> +} __packed;
> +
> +/* HV_INTERRUPT_TRIGGER_MODE */
> +enum hv_interrupt_trigger_mode {
> + HV_INTERRUPT_TRIGGER_MODE_EDGE = 0,
> + HV_INTERRUPT_TRIGGER_MODE_LEVEL = 1,
> +};
> +
> +/* HV_DEVICE_INTERRUPT_DESCRIPTOR */
> +struct hv_device_interrupt_descriptor {
> + u32 interrupt_type;
> + u32 trigger_mode;
> + u32 vector_count;
> + u32 reserved;
> + struct hv_device_interrupt_target target;
> +} __packed;
> +
> +/* HV_INPUT_MAP_DEVICE_INTERRUPT */
> +struct hv_input_map_device_interrupt {
> + u64 partition_id;
> + u64 device_id;
> + u32 flags;
> + u32 base_irt_idx;
> + struct hv_interrupt_entry logical_interrupt_entry;
> + struct hv_device_interrupt_descriptor interrupt_descriptor;
> +} __packed;
> +
> +/* HV_OUTPUT_MAP_DEVICE_INTERRUPT */
> +struct hv_output_map_device_interrupt {
> + struct hv_interrupt_entry interrupt_entry;
> +} __packed;
> +
> +/* HV_INPUT_UNMAP_DEVICE_INTERRUPT */
> +struct hv_input_unmap_device_interrupt {
> + u64 partition_id;
> + u64 device_id;
> + struct hv_interrupt_entry interrupt_entry;
> + u32 flags;
> +} __packed;
> +
> +#define HV_SOURCE_SHADOW_NONE 0x0
> +#define HV_SOURCE_SHADOW_BRIDGE_BUS_RANGE 0x1
> +
> +struct hv_send_ipi_ex { /* HV_INPUT_SEND_SYNTHETIC_CLUSTER_IPI_EX */
> + u32 vector;
> + u32 reserved;
> + struct hv_vpset vp_set;
> +} __packed;
> +
> +typedef u16 hv_pci_rid; /* HV_PCI_RID */
> +typedef u16 hv_pci_segment; /* HV_PCI_SEGMENT */
> +typedef u64 hv_logical_device_id;
> +union hv_pci_bdf { /* HV_PCI_BDF */
> + u16 as_uint16;
> +
> + struct {
> + u8 function : 3;
> + u8 device : 5;
> + u8 bus;
> + };
> +} __packed;
> +
> +union hv_pci_bus_range {
> + u16 as_uint16;
> +
> + struct {
> + u8 subordinate_bus;
> + u8 secondary_bus;
> + };
> +} __packed;
> +
> +enum hv_device_type { /* HV_DEVICE_TYPE */
> + HV_DEVICE_TYPE_LOGICAL = 0,
> + HV_DEVICE_TYPE_PCI = 1,
> + HV_DEVICE_TYPE_IOAPIC = 2,
> + HV_DEVICE_TYPE_ACPI = 3,
> +};
> +
> +union hv_device_id { /* HV_DEVICE_ID */
> + u64 as_uint64;
> +
> + struct {
> + u64 reserved0 : 62;
> + u64 device_type : 2;
> + };
> +
> + /* HV_DEVICE_TYPE_LOGICAL */
> + struct {
> + u64 id : 62;
> + u64 device_type : 2;
> + } logical;
> +
> + /* HV_DEVICE_TYPE_PCI */
> + struct {
> + union {
> + hv_pci_rid rid;
> + union hv_pci_bdf bdf;
> + };
> +
> + hv_pci_segment segment;
> + union hv_pci_bus_range shadow_bus_range;
> +
> + u16 phantom_function_bits : 2;
> + u16 source_shadow : 1;
> +
> + u16 rsvdz0 : 11;
> + u16 device_type : 2;
> + } pci;
> +
> + /* HV_DEVICE_TYPE_IOAPIC */
> + struct {
> + u8 ioapic_id;
> + u8 rsvdz0;
> + u16 rsvdz1;
> + u16 rsvdz2;
> +
> + u16 rsvdz3 : 14;
> + u16 device_type : 2;
> + } ioapic;
> +
> + /* HV_DEVICE_TYPE_ACPI */
> + struct {
> + u32 input_mapping_base;
> + u32 input_mapping_count : 30;
> + u32 device_type : 2;
> + } acpi;
> +} __packed;
> +
> +#endif /* _HV_HVHDK_MINI_H */
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [EXTERNAL] RE: [PATCH 3/5] hyperv: Add new Hyper-V headers
2024-10-10 18:21 ` Michael Kelley
@ 2024-10-11 1:34 ` MUKESH RATHOR
0 siblings, 0 replies; 27+ messages in thread
From: MUKESH RATHOR @ 2024-10-11 1:34 UTC (permalink / raw)
To: Michael Kelley, Nuno Das Neves, linux-hyperv@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
iommu@lists.linux.dev, netdev@vger.kernel.org,
linux-pci@vger.kernel.org, linux-arch@vger.kernel.org,
virtualization@lists.linux.dev
Cc: KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org, Dexuan Cui,
catalin.marinas@arm.com, will@kernel.org, luto@kernel.org,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org,
daniel.lezcano@linaro.org, joro@8bytes.org, robin.murphy@arm.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, lpieralisi@kernel.org, kw@linux.com,
robh@kernel.org, bhelgaas@google.com, arnd@arndb.de,
sgarzare@redhat.com, jinankjain@linux.microsoft.com,
muminulrussell@gmail.com, skinsburskii@linux.microsoft.com
Hi Michael,
I can answer some of the questions since I instigated this effort
while ago (you might find old email chain/s).
On 10/10/24 11:21, Michael Kelley wrote:
> From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent:
Thursday, October 3, 2024 12:51 PM
>>
>> Add definitions needed for privileged Hyper-V partitions.
>>
>> These files are derived from headers exported from the hypervisor code.
>
> Could you elaborate on the naming conventions for the new files,
> and the rules that govern what goes in what files? Specifically,
> what is "hvgdk" vs. "hvhdk", and what are the _ext and _mini
> suffixes? Even if the filenames are derived from Windows
hvhdk : hyp host development kit
hvgdk : hyp guest development kit
IOW, hdk files include data structures for a privileged VM, aka
dom0/root/host, and gdk targets an unprivileged VMs, ie, guests.
The _mini implies target is host/guest kernel, and non-mini
targets VMMs, but that appears more historic as over time
things moved from kernel to user space.
The hvgdk_ext was created for extended hypercalls.
Please note, these headers are publicly exported by the hypervisor
and consumed as is by Windows today (not sure about BSD and others),
so changing them is prob not feasible.
...
>> This is a step toward importing headers directly, similar to Xen public
>> files in include/xen/interface/.
>
> I'm not understanding this statement. The new files in this patch
> are obviously following Linux kernel coding style, with Linux kernel
> types, etc. I'm guessing there was a lot of "busy work" to take
> Windows Hyper-V code and make it look like Linux kernel code. :-(
> What would "importing headers directly" look like, and how is this
> an interim step?
Correct, they are currently not directly imported. The coding style
is different and also the hyp is not built using gcc/clang. So, we've
some work to do before we can use them as is. For now, we have
"mirrored" them manually enforcing Linux style. Going forward, we
have to decide if we can use them as is (there is some precedent in
linux for drivers including headers with different coding style) or
we can auto convert them via some tool or we can keep them manual
and modify them in sync with hyp modifying them. In any case, it
should be rare operation. Matching them now allows us to get there.
You are correct, it was "busy work", took me more than two weeks in
addition to time Nuno also spent.
> Also, it looks like these new files take a different approach for
> instruction set architecture differences. There are inline #ifdef's
> instead of the current method of having a common file, and then
> architecture specific versions that include the common file. My
> sense is that Linux kernel code prefers the current approach in
> order to avoid #ifdef'ery, but maybe that's less practical when the
> definitions are derived from Windows Hyper-V code. And with
> only two architectures to deal with, the #ifdef's don't get
> wild-and-crazy, which is good.
Well, we are trying to keep them as close to the originals as
possible. But now that linux support is here, we will work with
the producers of these headers, ie, the hyp team, to make them
more linux friendly going forward. Given there are other direct
consumers of the headers, Windows/BSD/.., it won't be right away,
as we'd have to coordinate and make sure all are happy.
Hope that makes sense.
Thanks,
-Mukesh
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [EXTERNAL] RE: [PATCH 0/5] Add new headers for Hyper-V Dom0
2024-10-10 18:21 ` Michael Kelley
@ 2024-10-11 1:34 ` MUKESH RATHOR
2024-10-23 0:04 ` Nuno Das Neves
2024-10-23 0:51 ` Nuno Das Neves
1 sibling, 1 reply; 27+ messages in thread
From: MUKESH RATHOR @ 2024-10-11 1:34 UTC (permalink / raw)
To: Michael Kelley, Nuno Das Neves, linux-hyperv@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
iommu@lists.linux.dev, netdev@vger.kernel.org,
linux-pci@vger.kernel.org, linux-arch@vger.kernel.org,
virtualization@lists.linux.dev
Cc: KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org, Dexuan Cui,
catalin.marinas@arm.com, will@kernel.org, luto@kernel.org,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org,
daniel.lezcano@linaro.org, joro@8bytes.org, robin.murphy@arm.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, lpieralisi@kernel.org, kw@linux.com,
robh@kernel.org, bhelgaas@google.com, arnd@arndb.de,
sgarzare@redhat.com, jinankjain@linux.microsoft.com,
muminulrussell@gmail.com, skinsburskii@linux.microsoft.com
On 10/10/24 11:21, Michael Kelley wrote:
> From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent:
Thursday, October 3, 2024 12:51 PM
>>
>> To support Hyper-V Dom0 (aka Linux as root partition), many new
>> definitions are required.
>>
>> The plan going forward is to directly import headers from
>> Hyper-V. This is a more maintainable way to import definitions
>> rather than via the TLFS doc. This patch series introduces
>> new headers (hvhdk.h, hvgdk.h, etc, see patch #3) directly
>> derived from Hyper-V code.
>>
>> This patch series replaces hyperv-tlfs.h with hvhdk.h, but only
>> in Microsoft-maintained Hyper-V code where they are needed. This
>> leaves the existing hyperv-tlfs.h in use elsewhere - notably for
>> Hyper-V enlightenments on KVM guests.
>
> Could you elaborate on why the bifurcation is necessary? Is it an
> interim step until the KVM code can use the new scheme as well?
> Also, does "Hyper-V enlightenments on KVM guests" refer to
> nested KVM running at L1 on an L0 Hyper-V, and supporting L2 guests?
> Or is it the more general KVM support for mimicking Hyper-V for
> the purposes of running Windows guests? From these patches, it
> looks like your intention is for all KVM support for Hyper-V
> functionality to continue to use the existing hyperv-tlfs.h file.
Like it says above, we are creating new dom0 (root/host) support
that requires many new defs only available to dom0 and not any
guest. Hypervisor makes them publicly available via hv*dk files.
Ideally, someday everybody will use those, I hope we can move in
that direction, but I guess one step at a time. For now, KVM can
continue to use the tlfs file, and if there is no resistance, we
can move them to hv*dk files also as next step and obsolete the
single tlfs file.
Since headers are the ultimate source of truth, this will allow
better maintenance, better debug/support experience, and a more
stable stack. It also enforces non-leaking of data structs from
private header files (unfortunately has happened).
Thanks
-Mukesh
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [EXTERNAL] RE: [PATCH 0/5] Add new headers for Hyper-V Dom0
2024-10-11 1:34 ` [EXTERNAL] " MUKESH RATHOR
@ 2024-10-23 0:04 ` Nuno Das Neves
2024-10-23 18:39 ` Michael Kelley
0 siblings, 1 reply; 27+ messages in thread
From: Nuno Das Neves @ 2024-10-23 0:04 UTC (permalink / raw)
To: MUKESH RATHOR, Michael Kelley, linux-hyperv@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
iommu@lists.linux.dev, netdev@vger.kernel.org,
linux-pci@vger.kernel.org, linux-arch@vger.kernel.org,
virtualization@lists.linux.dev
Cc: KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org, Dexuan Cui,
catalin.marinas@arm.com, will@kernel.org, luto@kernel.org,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org,
daniel.lezcano@linaro.org, joro@8bytes.org, robin.murphy@arm.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, lpieralisi@kernel.org, kw@linux.com,
robh@kernel.org, bhelgaas@google.com, arnd@arndb.de,
sgarzare@redhat.com, jinankjain@linux.microsoft.com,
muminulrussell@gmail.com, skinsburskii@linux.microsoft.com
Michael - sorry for the delay, I just got back from vacation.
On 10/10/2024 6:34 PM, MUKESH RATHOR wrote:
>
>
> On 10/10/24 11:21, Michael Kelley wrote:
> > From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent:
> Thursday, October 3, 2024 12:51 PM
> >>
> >> To support Hyper-V Dom0 (aka Linux as root partition), many new
> >> definitions are required.
> >>
> >> The plan going forward is to directly import headers from
> >> Hyper-V. This is a more maintainable way to import definitions
> >> rather than via the TLFS doc. This patch series introduces
> >> new headers (hvhdk.h, hvgdk.h, etc, see patch #3) directly
> >> derived from Hyper-V code.
> >>
> >> This patch series replaces hyperv-tlfs.h with hvhdk.h, but only
> >> in Microsoft-maintained Hyper-V code where they are needed. This
> >> leaves the existing hyperv-tlfs.h in use elsewhere - notably for
> >> Hyper-V enlightenments on KVM guests.
> >
> > Could you elaborate on why the bifurcation is necessary? Is it an
> > interim step until the KVM code can use the new scheme as well?
It's not strictly necessary. We chose this approach in order to
minimize any potential impact on KVM and other non-Microsoft-
maintained code that uses hyperv-tlfs.h. As Mukesh mentioned below,
eventually it will be better if everyone uses the new headers.
> > Also, does "Hyper-V enlightenments on KVM guests" refer to
> > nested KVM running at L1 on an L0 Hyper-V, and supporting L2 guests?
> > Or is it the more general KVM support for mimicking Hyper-V for
> > the purposes of running Windows guests? From these patches, it
> > looks like your intention is for all KVM support for Hyper-V
> > functionality to continue to use the existing hyperv-tlfs.h file.
You're correct - "all KVM support for Hyper-V" is really what I meant.
>
> Like it says above, we are creating new dom0 (root/host) support
> that requires many new defs only available to dom0 and not any
> guest. Hypervisor makes them publicly available via hv*dk files.
>
> Ideally, someday everybody will use those, I hope we can move in
> that direction, but I guess one step at a time. For now, KVM can
> continue to use the tlfs file, and if there is no resistance, we
> can move them to hv*dk files also as next step and obsolete the
> single tlfs file.
>
> Since headers are the ultimate source of truth, this will allow
> better maintenance, better debug/support experience, and a more
> stable stack. It also enforces non-leaking of data structs from
> private header files (unfortunately has happened).
>
> Thanks
> -Mukesh
>
Thanks for providing the additional context, Mukesh.
Nuno
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 0/5] Add new headers for Hyper-V Dom0
2024-10-10 18:21 ` Michael Kelley
2024-10-11 1:34 ` [EXTERNAL] " MUKESH RATHOR
@ 2024-10-23 0:51 ` Nuno Das Neves
2024-10-23 18:32 ` Michael Kelley
1 sibling, 1 reply; 27+ messages in thread
From: Nuno Das Neves @ 2024-10-23 0:51 UTC (permalink / raw)
To: Michael Kelley, linux-hyperv@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
iommu@lists.linux.dev, netdev@vger.kernel.org,
linux-pci@vger.kernel.org, linux-arch@vger.kernel.org,
virtualization@lists.linux.dev
Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
luto@kernel.org, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com,
peterz@infradead.org, daniel.lezcano@linaro.org, joro@8bytes.org,
robin.murphy@arm.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org,
kw@linux.com, robh@kernel.org, bhelgaas@google.com, arnd@arndb.de,
sgarzare@redhat.com, jinankjain@linux.microsoft.com,
muminulrussell@gmail.com, skinsburskii@linux.microsoft.com,
mukeshrathor@microsoft.com
On 10/10/2024 11:21 AM, Michael Kelley wrote:
> From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, October 3, 2024 12:51 PM
>>>> An intermediary header "hv_defs.h" is introduced to conditionally
>> include either hyperv-tlfs.h or hvhdk.h. This is required because
>> several headers which today include hyperv-tlfs.h, are shared
>> between Hyper-V and KVM code (e.g. mshyperv.h).
>
> Have you considered user space code that uses
> include/linux/hyperv.h? Which of the two schemes will it use? That code
> needs to compile correctly on x86 and ARM64 after your changes.
> User space code includes the separate DPDK project, and some of the
> tools in the kernel tree under tools/hv. Anything that uses the
> uio_hv_generic.c driver falls into this category.
>
Unless I misunderstand something, the uapi code isn't affected at all
by this patch set. e.g. the code in tools/hv uses include/uapi/linux/hyperv.h,
which doesn't include any other Hyper-V headers.
I'm not aware of how the DPDK project uses the Hyper-V definitions, but if it
is getting headers from uapi it should also be unaffected.
> I think there's also user space code that is built for vDSO that might pull
> in the .h files you are modifying. There are in-progress patches dealing
> with vDSO include files, such as [1]. My general comment on vDSO
> is to be careful in making #include file changes that it uses, but I'm
> not knowledgeable enough on how vDSO is built to give specific
> guidance. :-(
>
Hmm, interesting, looks like it does get used by userspace. The tsc page
is mapped into userspace in vdso.vma.c, and read in vdso/gettimeofday.h.
That is unexpected for me, since these things aren't in uapi. However I don't
anticipate a problem. The definitions used haven't changed, just the headers
they are included from.
Thanks
Nuno
> Michael
>
> [1] https://lore.kernel.org/lkml/20241010135146.181175-1-vincenzo.frascino@arm.com/
>
>>
>> Summary:
>> Patch 1-2: Cleanup patches
>> Patch 3: Add the new headers (hvhdk.h, etc..) in include/hyperv/
>> Patch 4: Add hv_defs.h and use it in mshyperv.h, svm.h,
>> hyperv_timer.h
>> Patch 5: Switch to the new headers, only in Hyper-V code
>>
>> Nuno Das Neves (5):
>> hyperv: Move hv_connection_id to hyperv-tlfs.h
>> hyperv: Remove unnecessary #includes
>> hyperv: Add new Hyper-V headers
>> hyperv: Add hv_defs.h to conditionally include hyperv-tlfs.h or
>> hvhdk.h
>> hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
>>
>> arch/arm64/hyperv/hv_core.c | 3 +-
>> arch/arm64/hyperv/mshyperv.c | 1 +
>> arch/arm64/include/asm/mshyperv.h | 2 +-
>> arch/x86/entry/vdso/vma.c | 1 +
>> arch/x86/hyperv/hv_apic.c | 2 +-
>> arch/x86/hyperv/hv_init.c | 3 +-
>> arch/x86/hyperv/hv_proc.c | 4 +-
>> arch/x86/hyperv/hv_spinlock.c | 1 +
>> arch/x86/hyperv/hv_vtl.c | 1 +
>> arch/x86/hyperv/irqdomain.c | 1 +
>> arch/x86/hyperv/ivm.c | 2 +-
>> arch/x86/hyperv/mmu.c | 2 +-
>> arch/x86/hyperv/nested.c | 2 +-
>> arch/x86/include/asm/kvm_host.h | 1 -
>> arch/x86/include/asm/mshyperv.h | 3 +-
>> arch/x86/include/asm/svm.h | 2 +-
>> arch/x86/include/asm/vdso/gettimeofday.h | 1 +
>> arch/x86/kernel/cpu/mshyperv.c | 2 +-
>> arch/x86/kernel/cpu/mtrr/generic.c | 1 +
>> arch/x86/kvm/vmx/vmx_onhyperv.h | 1 -
>> arch/x86/mm/pat/set_memory.c | 2 -
>> drivers/clocksource/hyperv_timer.c | 2 +-
>> drivers/hv/channel.c | 1 +
>> drivers/hv/channel_mgmt.c | 1 +
>> drivers/hv/connection.c | 1 +
>> drivers/hv/hv.c | 1 +
>> drivers/hv/hv_balloon.c | 5 +-
>> drivers/hv/hv_common.c | 2 +-
>> drivers/hv/hv_kvp.c | 1 -
>> drivers/hv/hv_snapshot.c | 1 -
>> drivers/hv/hv_util.c | 1 +
>> drivers/hv/hyperv_vmbus.h | 1 -
>> drivers/hv/ring_buffer.c | 1 +
>> drivers/hv/vmbus_drv.c | 1 +
>> drivers/iommu/hyperv-iommu.c | 1 +
>> drivers/net/hyperv/netvsc.c | 1 +
>> drivers/pci/controller/pci-hyperv.c | 1 +
>> include/asm-generic/hyperv-tlfs.h | 9 +
>> include/asm-generic/mshyperv.h | 2 +-
>> include/clocksource/hyperv_timer.h | 2 +-
>> include/hyperv/hv_defs.h | 29 +
>> include/hyperv/hvgdk.h | 66 ++
>> include/hyperv/hvgdk_ext.h | 46 +
>> include/hyperv/hvgdk_mini.h | 1212 ++++++++++++++++++++++
>> include/hyperv/hvhdk.h | 733 +++++++++++++
>> include/hyperv/hvhdk_mini.h | 310 ++++++
>> include/linux/hyperv.h | 12 +-
>> net/vmw_vsock/hyperv_transport.c | 1 -
>> 48 files changed, 2442 insertions(+), 40 deletions(-)
>> create mode 100644 include/hyperv/hv_defs.h
>> create mode 100644 include/hyperv/hvgdk.h
>> create mode 100644 include/hyperv/hvgdk_ext.h
>> create mode 100644 include/hyperv/hvgdk_mini.h
>> create mode 100644 include/hyperv/hvhdk.h
>> create mode 100644 include/hyperv/hvhdk_mini.h
>>
>> --
>> 2.34.1
>>
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* RE: [PATCH 0/5] Add new headers for Hyper-V Dom0
2024-10-23 0:51 ` Nuno Das Neves
@ 2024-10-23 18:32 ` Michael Kelley
0 siblings, 0 replies; 27+ messages in thread
From: Michael Kelley @ 2024-10-23 18:32 UTC (permalink / raw)
To: Nuno Das Neves, linux-hyperv@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
iommu@lists.linux.dev, netdev@vger.kernel.org,
linux-pci@vger.kernel.org, linux-arch@vger.kernel.org,
virtualization@lists.linux.dev
Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
luto@kernel.org, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com,
peterz@infradead.org, daniel.lezcano@linaro.org, joro@8bytes.org,
robin.murphy@arm.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org,
kw@linux.com, robh@kernel.org, bhelgaas@google.com, arnd@arndb.de,
sgarzare@redhat.com, jinankjain@linux.microsoft.com,
muminulrussell@gmail.com, skinsburskii@linux.microsoft.com,
mukeshrathor@microsoft.com
From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Tuesday, October 22, 2024 5:51 PM
>
> On 10/10/2024 11:21 AM, Michael Kelley wrote:
> >
[snip]
> > Have you considered user space code that uses
> > include/linux/hyperv.h? Which of the two schemes will it use? That code
> > needs to compile correctly on x86 and ARM64 after your changes.
> > User space code includes the separate DPDK project, and some of the
> > tools in the kernel tree under tools/hv. Anything that uses the
> > uio_hv_generic.c driver falls into this category.
> >
> Unless I misunderstand something, the uapi code isn't affected at all
> by this patch set. e.g. the code in tools/hv uses include/uapi/linux/hyperv.h,
> which doesn't include any other Hyper-V headers.
>
> I'm not aware of how the DPDK project uses the Hyper-V definitions, but if it
> is getting headers from uapi it should also be unaffected.
You are right. My mistake. User space code based on uio_hv_generic.c
maps the VMBus ring buffers into user space, and I thought that code
was pulling "struct hv_ring_buffer" from include/linux/hyperv.h file. But
DPDK and the tools/hv code each have their own completely separate
header file with the equivalent of "struct hv_ring_buffer". Duplicating
the ring buffer structure in multiple places probably isn't ideal, but the
decoupling helps in this case. ;-)
>
> > I think there's also user space code that is built for vDSO that might pull
> > in the .h files you are modifying. There are in-progress patches dealing
> > with vDSO include files, such as [1]. My general comment on vDSO
> > is to be careful in making #include file changes that it uses, but I'm
> > not knowledgeable enough on how vDSO is built to give specific
> > guidance. :-(
> >
> Hmm, interesting, looks like it does get used by userspace. The tsc page
> is mapped into userspace in vdso.vma.c, and read in vdso/gettimeofday.h.
>
> That is unexpected for me, since these things aren't in uapi. However I don't
> anticipate a problem. The definitions used haven't changed, just the headers
> they are included from.
>
Fair enough. I don't know enough about vDSO user space to add anything
helpful.
Michael
^ permalink raw reply [flat|nested] 27+ messages in thread
* RE: [EXTERNAL] RE: [PATCH 0/5] Add new headers for Hyper-V Dom0
2024-10-23 0:04 ` Nuno Das Neves
@ 2024-10-23 18:39 ` Michael Kelley
0 siblings, 0 replies; 27+ messages in thread
From: Michael Kelley @ 2024-10-23 18:39 UTC (permalink / raw)
To: Nuno Das Neves, MUKESH RATHOR, linux-hyperv@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
iommu@lists.linux.dev, netdev@vger.kernel.org,
linux-pci@vger.kernel.org, linux-arch@vger.kernel.org,
virtualization@lists.linux.dev
Cc: KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org, Dexuan Cui,
catalin.marinas@arm.com, will@kernel.org, luto@kernel.org,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org,
daniel.lezcano@linaro.org, joro@8bytes.org, robin.murphy@arm.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, lpieralisi@kernel.org, kw@linux.com,
robh@kernel.org, bhelgaas@google.com, arnd@arndb.de,
sgarzare@redhat.com, jinankjain@linux.microsoft.com,
muminulrussell@gmail.com, skinsburskii@linux.microsoft.com
From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Tuesday, October 22, 2024 5:04 PM
>
> Michael - sorry for the delay, I just got back from vacation.
>
> On 10/10/2024 6:34 PM, MUKESH RATHOR wrote:
> >
> >
> > On 10/10/24 11:21, Michael Kelley wrote:
> > > From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent:
> > Thursday, October 3, 2024 12:51 PM
> > >>
> > >> To support Hyper-V Dom0 (aka Linux as root partition), many new
> > >> definitions are required.
> > >>
> > >> The plan going forward is to directly import headers from
> > >> Hyper-V. This is a more maintainable way to import definitions
> > >> rather than via the TLFS doc. This patch series introduces
> > >> new headers (hvhdk.h, hvgdk.h, etc, see patch #3) directly
> > >> derived from Hyper-V code.
> > >>
> > >> This patch series replaces hyperv-tlfs.h with hvhdk.h, but only
> > >> in Microsoft-maintained Hyper-V code where they are needed. This
> > >> leaves the existing hyperv-tlfs.h in use elsewhere - notably for
> > >> Hyper-V enlightenments on KVM guests.
> > >
> > > Could you elaborate on why the bifurcation is necessary? Is it an
> > > interim step until the KVM code can use the new scheme as well?
>
> It's not strictly necessary. We chose this approach in order to
> minimize any potential impact on KVM and other non-Microsoft-
> maintained code that uses hyperv-tlfs.h. As Mukesh mentioned below,
> eventually it will be better if everyone uses the new headers.
Doing big changes incrementally is certainly useful and common enough
in kernel development. But having two sets of header files that define
the same thing, for use in two different parts of the code tree, seems
a bit off the beaten path. I don’t see that there would be significant
risk in doing KVM at the same time. But the KVM folks should weigh
in on this.
Just my $.02 worth, and I won't object whichever way you go.
Michael
>
> > > Also, does "Hyper-V enlightenments on KVM guests" refer to
> > > nested KVM running at L1 on an L0 Hyper-V, and supporting L2 guests?
> > > Or is it the more general KVM support for mimicking Hyper-V for
> > > the purposes of running Windows guests? From these patches, it
> > > looks like your intention is for all KVM support for Hyper-V
> > > functionality to continue to use the existing hyperv-tlfs.h file.
>
> You're correct - "all KVM support for Hyper-V" is really what I meant.
> >
> > Like it says above, we are creating new dom0 (root/host) support
> > that requires many new defs only available to dom0 and not any
> > guest. Hypervisor makes them publicly available via hv*dk files.
> >
> > Ideally, someday everybody will use those, I hope we can move in
> > that direction, but I guess one step at a time. For now, KVM can
> > continue to use the tlfs file, and if there is no resistance, we
> > can move them to hv*dk files also as next step and obsolete the
> > single tlfs file.
> >
> > Since headers are the ultimate source of truth, this will allow
> > better maintenance, better debug/support experience, and a more
> > stable stack. It also enforces non-leaking of data structs from
> > private header files (unfortunately has happened).
> >
> > Thanks
> > -Mukesh
> >
>
> Thanks for providing the additional context, Mukesh.
>
> Nuno
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 2/5] hyperv: Remove unnecessary #includes
2024-10-10 18:21 ` Michael Kelley
@ 2024-10-31 18:47 ` Nuno Das Neves
0 siblings, 0 replies; 27+ messages in thread
From: Nuno Das Neves @ 2024-10-31 18:47 UTC (permalink / raw)
To: Michael Kelley, linux-hyperv@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
iommu@lists.linux.dev, netdev@vger.kernel.org,
linux-pci@vger.kernel.org, linux-arch@vger.kernel.org,
virtualization@lists.linux.dev
Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
luto@kernel.org, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com,
peterz@infradead.org, daniel.lezcano@linaro.org, joro@8bytes.org,
robin.murphy@arm.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org,
kw@linux.com, robh@kernel.org, bhelgaas@google.com, arnd@arndb.de,
sgarzare@redhat.com, jinankjain@linux.microsoft.com,
muminulrussell@gmail.com, skinsburskii@linux.microsoft.com,
mukeshrathor@microsoft.com
On 10/10/2024 11:21 AM, Michael Kelley wrote:
> From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, October 3, 2024 12:51 PM
>>
>> asm/hyperv-tlfs.h is already included implicitly wherever mshyperv.h
>> or linux/hyperv.h is included. Remove those redundancies.
>
> I've been under the impression that it is preferable to directly include
> .h files for all definitions that a source code file uses, even if the
> needed .h file is indirectly included by some other .h file. I looked through
I've also heard this idea, and generally try to stick to it. I myself
haven't yet encountered a situation where doing this or not has greatly
impacted the readability of the code.
> the coding style documentation, and didn't find anything addressing
> this topic, so maybe I'm wrong. But I know I've seen patches to other
> parts of the kernel that were changes to follow the direct inclusion
> approach. Direct inclusion is less fragile if the #include file nesting
> structure changes (and perhaps removes the indirect inclusion).
>
> The mshyperv.h and linux/hyperv.h dependency on hyperv-tlfs.h is
> highly unlikely to change, so the chance of breakage is minimal. But
You probably already understood this after seeing the later patches, but
it's worth pointing out that the goal of this series is to change that
dependency (situationally), which is exactly why I created this precursor
patch.
> I wonder if your approach is going the wrong direction vs. preferred
> kernel practices.
>
I could replace <asm/hyperv-tlfs.h> with <hyperv/hvhdk.h> in most of these
cases (in v2), to preserve the explicit include of the definitions before
mshyperv.h or linux/hyperv.h. I will give it a try in v2.
Thanks,
Nuno
> Michael
>
>>
>> Remove includes of linux/hyperv.h and mshyperv.h where they are not
>> needed.
>>
>> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
>> ---
>> arch/arm64/hyperv/hv_core.c | 2 --
>> arch/x86/hyperv/hv_apic.c | 1 -
>> arch/x86/hyperv/hv_init.c | 2 --
>> arch/x86/hyperv/hv_proc.c | 1 -
>> arch/x86/hyperv/ivm.c | 1 -
>> arch/x86/hyperv/mmu.c | 1 -
>> arch/x86/hyperv/nested.c | 1 -
>> arch/x86/include/asm/kvm_host.h | 1 -
>> arch/x86/include/asm/mshyperv.h | 1 -
>> arch/x86/kernel/cpu/mshyperv.c | 1 -
>> arch/x86/kvm/vmx/vmx_onhyperv.h | 1 -
>> arch/x86/mm/pat/set_memory.c | 2 --
>> drivers/clocksource/hyperv_timer.c | 1 -
>> drivers/hv/hv_balloon.c | 2 --
>> drivers/hv/hv_common.c | 1 -
>> drivers/hv/hv_kvp.c | 1 -
>> drivers/hv/hv_snapshot.c | 1 -
>> drivers/hv/hyperv_vmbus.h | 1 -
>> net/vmw_vsock/hyperv_transport.c | 1 -
>> 19 files changed, 23 deletions(-)
>>
>> diff --git a/arch/arm64/hyperv/hv_core.c b/arch/arm64/hyperv/hv_core.c
>> index f1ebc025e1df..9d1969b875e9 100644
>> --- a/arch/arm64/hyperv/hv_core.c
>> +++ b/arch/arm64/hyperv/hv_core.c
>> @@ -11,11 +11,9 @@
>> #include <linux/types.h>
>> #include <linux/export.h>
>> #include <linux/mm.h>
>> -#include <linux/hyperv.h>
>> #include <linux/arm-smccc.h>
>> #include <linux/module.h>
>> #include <asm-generic/bug.h>
>> -#include <asm/hyperv-tlfs.h>
>> #include <asm/mshyperv.h>
>>
>> /*
>> diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
>> index 0569f579338b..f022d5f64fb6 100644
>> --- a/arch/x86/hyperv/hv_apic.c
>> +++ b/arch/x86/hyperv/hv_apic.c
>> @@ -23,7 +23,6 @@
>> #include <linux/vmalloc.h>
>> #include <linux/mm.h>
>> #include <linux/clockchips.h>
>> -#include <linux/hyperv.h>
>> #include <linux/slab.h>
>> #include <linux/cpuhotplug.h>
>> #include <asm/hypervisor.h>
>> diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
>> index 17a71e92a343..fc3c3d76c181 100644
>> --- a/arch/x86/hyperv/hv_init.c
>> +++ b/arch/x86/hyperv/hv_init.c
>> @@ -19,7 +19,6 @@
>> #include <asm/sev.h>
>> #include <asm/ibt.h>
>> #include <asm/hypervisor.h>
>> -#include <asm/hyperv-tlfs.h>
>> #include <asm/mshyperv.h>
>> #include <asm/idtentry.h>
>> #include <asm/set_memory.h>
>> @@ -27,7 +26,6 @@
>> #include <linux/version.h>
>> #include <linux/vmalloc.h>
>> #include <linux/mm.h>
>> -#include <linux/hyperv.h>
>> #include <linux/slab.h>
>> #include <linux/kernel.h>
>> #include <linux/cpuhotplug.h>
>> diff --git a/arch/x86/hyperv/hv_proc.c b/arch/x86/hyperv/hv_proc.c
>> index 3fa1f2ee7b0d..b74c06c04ff1 100644
>> --- a/arch/x86/hyperv/hv_proc.c
>> +++ b/arch/x86/hyperv/hv_proc.c
>> @@ -3,7 +3,6 @@
>> #include <linux/vmalloc.h>
>> #include <linux/mm.h>
>> #include <linux/clockchips.h>
>> -#include <linux/hyperv.h>
>> #include <linux/slab.h>
>> #include <linux/cpuhotplug.h>
>> #include <linux/minmax.h>
>> diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
>> index 60fc3ed72830..b56d70612734 100644
>> --- a/arch/x86/hyperv/ivm.c
>> +++ b/arch/x86/hyperv/ivm.c
>> @@ -7,7 +7,6 @@
>> */
>>
>> #include <linux/bitfield.h>
>> -#include <linux/hyperv.h>
>> #include <linux/types.h>
>> #include <linux/slab.h>
>> #include <asm/svm.h>
>> diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c
>> index 1cc113200ff5..cc8c3bd0e7c2 100644
>> --- a/arch/x86/hyperv/mmu.c
>> +++ b/arch/x86/hyperv/mmu.c
>> @@ -1,6 +1,5 @@
>> #define pr_fmt(fmt) "Hyper-V: " fmt
>>
>> -#include <linux/hyperv.h>
>> #include <linux/log2.h>
>> #include <linux/slab.h>
>> #include <linux/types.h>
>> diff --git a/arch/x86/hyperv/nested.c b/arch/x86/hyperv/nested.c
>> index 9dc259fa322e..ee06d0315c24 100644
>> --- a/arch/x86/hyperv/nested.c
>> +++ b/arch/x86/hyperv/nested.c
>> @@ -11,7 +11,6 @@
>>
>>
>> #include <linux/types.h>
>> -#include <asm/hyperv-tlfs.h>
>> #include <asm/mshyperv.h>
>> #include <asm/tlbflush.h>
>>
>> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
>> index 4a68cb3eba78..3627eab994a3 100644
>> --- a/arch/x86/include/asm/kvm_host.h
>> +++ b/arch/x86/include/asm/kvm_host.h
>> @@ -24,7 +24,6 @@
>> #include <linux/pvclock_gtod.h>
>> #include <linux/clocksource.h>
>> #include <linux/irqbypass.h>
>> -#include <linux/hyperv.h>
>> #include <linux/kfifo.h>
>>
>> #include <asm/apic.h>
>> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
>> index 390c4d13956d..47ca48062547 100644
>> --- a/arch/x86/include/asm/mshyperv.h
>> +++ b/arch/x86/include/asm/mshyperv.h
>> @@ -9,7 +9,6 @@
>> #include <asm/hyperv-tlfs.h>
>> #include <asm/nospec-branch.h>
>> #include <asm/paravirt.h>
>> -#include <asm/mshyperv.h>
>>
>> /*
>> * Hyper-V always provides a single IO-APIC at this MMIO address.
>> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
>> index e0fd57a8ba84..8e8fd23b1439 100644
>> --- a/arch/x86/kernel/cpu/mshyperv.c
>> +++ b/arch/x86/kernel/cpu/mshyperv.c
>> @@ -20,7 +20,6 @@
>> #include <linux/random.h>
>> #include <asm/processor.h>
>> #include <asm/hypervisor.h>
>> -#include <asm/hyperv-tlfs.h>
>> #include <asm/mshyperv.h>
>> #include <asm/desc.h>
>> #include <asm/idtentry.h>
>> diff --git a/arch/x86/kvm/vmx/vmx_onhyperv.h
>> b/arch/x86/kvm/vmx/vmx_onhyperv.h
>> index eb48153bfd73..f4b081eb6521 100644
>> --- a/arch/x86/kvm/vmx/vmx_onhyperv.h
>> +++ b/arch/x86/kvm/vmx/vmx_onhyperv.h
>> @@ -3,7 +3,6 @@
>> #ifndef __ARCH_X86_KVM_VMX_ONHYPERV_H__
>> #define __ARCH_X86_KVM_VMX_ONHYPERV_H__
>>
>> -#include <asm/hyperv-tlfs.h>
>> #include <asm/mshyperv.h>
>>
>> #include <linux/jump_label.h>
>> diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
>> index 44f7b2ea6a07..85fa0d4509f0 100644
>> --- a/arch/x86/mm/pat/set_memory.c
>> +++ b/arch/x86/mm/pat/set_memory.c
>> @@ -32,8 +32,6 @@
>> #include <asm/pgalloc.h>
>> #include <asm/proto.h>
>> #include <asm/memtype.h>
>> -#include <asm/hyperv-tlfs.h>
>> -#include <asm/mshyperv.h>
>>
>> #include "../mm_internal.h"
>>
>> diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
>> index b2a080647e41..1b7de45a7185 100644
>> --- a/drivers/clocksource/hyperv_timer.c
>> +++ b/drivers/clocksource/hyperv_timer.c
>> @@ -23,7 +23,6 @@
>> #include <linux/acpi.h>
>> #include <linux/hyperv.h>
>> #include <clocksource/hyperv_timer.h>
>> -#include <asm/hyperv-tlfs.h>
>> #include <asm/mshyperv.h>
>>
>> static struct clock_event_device __percpu *hv_clock_event;
>> diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
>> index c38dcdfcb914..a120e9b80ded 100644
>> --- a/drivers/hv/hv_balloon.c
>> +++ b/drivers/hv/hv_balloon.c
>> @@ -28,8 +28,6 @@
>> #include <linux/sizes.h>
>>
>> #include <linux/hyperv.h>
>> -#include <asm/hyperv-tlfs.h>
>> -
>> #include <asm/mshyperv.h>
>>
>> #define CREATE_TRACE_POINTS
>> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
>> index 9c452bfbd571..a5217f837237 100644
>> --- a/drivers/hv/hv_common.c
>> +++ b/drivers/hv/hv_common.c
>> @@ -28,7 +28,6 @@
>> #include <linux/slab.h>
>> #include <linux/dma-map-ops.h>
>> #include <linux/set_memory.h>
>> -#include <asm/hyperv-tlfs.h>
>> #include <asm/mshyperv.h>
>>
>> /*
>> diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c
>> index d35b60c06114..68e73ec7ab28 100644
>> --- a/drivers/hv/hv_kvp.c
>> +++ b/drivers/hv/hv_kvp.c
>> @@ -27,7 +27,6 @@
>> #include <linux/connector.h>
>> #include <linux/workqueue.h>
>> #include <linux/hyperv.h>
>> -#include <asm/hyperv-tlfs.h>
>>
>> #include "hyperv_vmbus.h"
>> #include "hv_utils_transport.h"
>> diff --git a/drivers/hv/hv_snapshot.c b/drivers/hv/hv_snapshot.c
>> index 0d2184be1691..90fc935e89bd 100644
>> --- a/drivers/hv/hv_snapshot.c
>> +++ b/drivers/hv/hv_snapshot.c
>> @@ -12,7 +12,6 @@
>> #include <linux/connector.h>
>> #include <linux/workqueue.h>
>> #include <linux/hyperv.h>
>> -#include <asm/hyperv-tlfs.h>
>>
>> #include "hyperv_vmbus.h"
>> #include "hv_utils_transport.h"
>> diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
>> index 76ac5185a01a..321770d7ce25 100644
>> --- a/drivers/hv/hyperv_vmbus.h
>> +++ b/drivers/hv/hyperv_vmbus.h
>> @@ -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>
>> diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c
>> index e2157e387217..f77f0ea1ddad 100644
>> --- a/net/vmw_vsock/hyperv_transport.c
>> +++ b/net/vmw_vsock/hyperv_transport.c
>> @@ -13,7 +13,6 @@
>> #include <linux/hyperv.h>
>> #include <net/sock.h>
>> #include <net/af_vsock.h>
>> -#include <asm/hyperv-tlfs.h>
>>
>> /* Older (VMBUS version 'VERSION_WIN10' or before) Windows hosts have some
>> * stricter requirements on the hv_sock ring buffer size of six 4K pages.
>> --
>> 2.34.1
>>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 0/5] Add new headers for Hyper-V Dom0
2024-10-03 19:50 [PATCH 0/5] Add new headers for Hyper-V Dom0 Nuno Das Neves
` (6 preceding siblings ...)
2024-10-10 18:21 ` Michael Kelley
@ 2024-10-31 19:05 ` Easwar Hariharan
2024-10-31 22:59 ` Nuno Das Neves
7 siblings, 1 reply; 27+ messages in thread
From: Easwar Hariharan @ 2024-10-31 19:05 UTC (permalink / raw)
To: Nuno Das Neves, linux-hyperv, linux-arm-kernel, linux-kernel, kvm,
iommu, netdev, linux-pci, linux-arch, virtualization
Cc: eahariha, kys, haiyangz, wei.liu, decui, catalin.marinas, will,
luto, tglx, mingo, bp, dave.hansen, x86, hpa, seanjc, pbonzini,
peterz, daniel.lezcano, joro, robin.murphy, davem, edumazet, kuba,
pabeni, lpieralisi, kw, robh, bhelgaas, arnd, sgarzare,
jinankjain, muminulrussell, skinsburskii, mukeshrathor, tyhicks
On 10/3/2024 12:50 PM, Nuno Das Neves wrote:
> To support Hyper-V Dom0 (aka Linux as root partition), many new
> definitions are required.
>
> The plan going forward is to directly import headers from
> Hyper-V. This is a more maintainable way to import definitions
> rather than via the TLFS doc. This patch series introduces
> new headers (hvhdk.h, hvgdk.h, etc, see patch #3) directly
> derived from Hyper-V code.
>
> This patch series replaces hyperv-tlfs.h with hvhdk.h, but only
> in Microsoft-maintained Hyper-V code where they are needed. This
> leaves the existing hyperv-tlfs.h in use elsewhere - notably for
> Hyper-V enlightenments on KVM guests.
>
> An intermediary header "hv_defs.h" is introduced to conditionally
> include either hyperv-tlfs.h or hvhdk.h. This is required because
> several headers which today include hyperv-tlfs.h, are shared
> between Hyper-V and KVM code (e.g. mshyperv.h).
>
> Summary:
> Patch 1-2: Cleanup patches
> Patch 3: Add the new headers (hvhdk.h, etc..) in include/hyperv/
> Patch 4: Add hv_defs.h and use it in mshyperv.h, svm.h,
> hyperv_timer.h
> Patch 5: Switch to the new headers, only in Hyper-V code
>
> Nuno Das Neves (5):
> hyperv: Move hv_connection_id to hyperv-tlfs.h
> hyperv: Remove unnecessary #includes
> hyperv: Add new Hyper-V headers
> hyperv: Add hv_defs.h to conditionally include hyperv-tlfs.h or
> hvhdk.h
> hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
>
What is the model for Hyper-V code that has both guest and host roles
where the corresponding hypercalls are available for both? As I
understand it, those are supposed to be in hvgdk*.h.
For a specific example, IOMMU hypercalls can operate on stage 2 or stage
1 translations depending on the role of the (hyper) caller and the input
values provided. Should a driver using these hypercalls import both
hvhdk* and hvgdk*? What about hyperv-tlfs?
Patches 4 and 5 seem to draw a bright line between host and guest roles
while the reality is more gray. Please do correct me if I'm wrong here,
perhaps the picture would be clearer if Stas' suggestion of a new header
file is implemented.
Thanks,
Easwar
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 0/5] Add new headers for Hyper-V Dom0
2024-10-31 19:05 ` Easwar Hariharan
@ 2024-10-31 22:59 ` Nuno Das Neves
0 siblings, 0 replies; 27+ messages in thread
From: Nuno Das Neves @ 2024-10-31 22:59 UTC (permalink / raw)
To: Easwar Hariharan, linux-hyperv, linux-arm-kernel, linux-kernel,
kvm, iommu, netdev, linux-pci, linux-arch, virtualization
Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, luto, tglx,
mingo, bp, dave.hansen, x86, hpa, seanjc, pbonzini, peterz,
daniel.lezcano, joro, robin.murphy, davem, edumazet, kuba, pabeni,
lpieralisi, kw, robh, bhelgaas, arnd, sgarzare, jinankjain,
muminulrussell, skinsburskii, mukeshrathor, tyhicks
On 10/31/2024 12:05 PM, Easwar Hariharan wrote:
> On 10/3/2024 12:50 PM, Nuno Das Neves wrote:
>> To support Hyper-V Dom0 (aka Linux as root partition), many new
>> definitions are required.
>>
>> The plan going forward is to directly import headers from
>> Hyper-V. This is a more maintainable way to import definitions
>> rather than via the TLFS doc. This patch series introduces
>> new headers (hvhdk.h, hvgdk.h, etc, see patch #3) directly
>> derived from Hyper-V code.
>>
>> This patch series replaces hyperv-tlfs.h with hvhdk.h, but only
>> in Microsoft-maintained Hyper-V code where they are needed. This
>> leaves the existing hyperv-tlfs.h in use elsewhere - notably for
>> Hyper-V enlightenments on KVM guests.
>>
>> An intermediary header "hv_defs.h" is introduced to conditionally
>> include either hyperv-tlfs.h or hvhdk.h. This is required because
>> several headers which today include hyperv-tlfs.h, are shared
>> between Hyper-V and KVM code (e.g. mshyperv.h).
>>
>> Summary:
>> Patch 1-2: Cleanup patches
>> Patch 3: Add the new headers (hvhdk.h, etc..) in include/hyperv/
>> Patch 4: Add hv_defs.h and use it in mshyperv.h, svm.h,
>> hyperv_timer.h
>> Patch 5: Switch to the new headers, only in Hyper-V code
>>
>> Nuno Das Neves (5):
>> hyperv: Move hv_connection_id to hyperv-tlfs.h
>> hyperv: Remove unnecessary #includes
>> hyperv: Add new Hyper-V headers
>> hyperv: Add hv_defs.h to conditionally include hyperv-tlfs.h or
>> hvhdk.h
>> hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code
>>
Hi Easwar, thanks for the questions. I will attempt to clarify.
>
> What is the model for Hyper-V code that has both guest and host roles
> where the corresponding hypercalls are available for both? As I
> understand it, those are supposed to be in hvgdk*.h.
>
It's true that the naming of the files implies hvgdk*.h is for guests,
and hvhdk*.h (which includes hvgdk*.h), is for hosts/dom0. But I would
only take that as a rough guide.
The real reason for keeping these names is to make it a easier to copy
and maintain the definitions from the Windows code into Linux, by
keeping the provenance of exactly where they came from.
> For a specific example, IOMMU hypercalls can operate on stage 2 or stage
> 1 translations depending on the role of the (hyper) caller and the input
> values provided. Should a driver using these hypercalls import both
> hvhdk* and hvgdk*? What about hyperv-tlfs?
>
I'd recommend importing hvhdk.h since it contains everything you need
(including hvgdk*.h).
The goal of this patchset is to move away from hyperv-tlfs.h, because by
definition it should only contain definitions from the TLFS document.
> Patches 4 and 5 seem to draw a bright line between host and guest roles
> while the reality is more gray. Please do correct me if I'm wrong here,
> perhaps the picture would be clearer if Stas' suggestion of a new header
> file is implemented.
>
Patches 4 and 5 introduce the new headers in a way that avoids any
potential impact on KVM and other non-Microsoft-maintained code.
The 'line' is not between guest and host, but between Microsoft-maintained
and non-Microsoft-maintained code.
Thanks,
Nuno
> Thanks,
> Easwar
^ permalink raw reply [flat|nested] 27+ messages in thread
end of thread, other threads:[~2024-10-31 22:59 UTC | newest]
Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-03 19:50 [PATCH 0/5] Add new headers for Hyper-V Dom0 Nuno Das Neves
2024-10-03 19:51 ` [PATCH 1/5] hyperv: Move hv_connection_id to hyperv-tlfs.h Nuno Das Neves
2024-10-07 16:24 ` Wei Liu
2024-10-03 19:51 ` [PATCH 2/5] hyperv: Remove unnecessary #includes Nuno Das Neves
2024-10-07 16:24 ` Wei Liu
2024-10-10 18:21 ` Michael Kelley
2024-10-31 18:47 ` Nuno Das Neves
2024-10-03 19:51 ` [PATCH 3/5] hyperv: Add new Hyper-V headers Nuno Das Neves
2024-10-10 18:21 ` Michael Kelley
2024-10-11 1:34 ` [EXTERNAL] " MUKESH RATHOR
2024-10-03 19:51 ` [PATCH 4/5] hyperv: Add hv_defs.h to conditionally include hyperv-tlfs.h or hvhdk.h Nuno Das Neves
2024-10-03 19:51 ` [PATCH 5/5] hyperv: Use hvhdk.h instead of hyperv-tlfs.h in Hyper-V code Nuno Das Neves
2024-10-04 15:58 ` Stanislav Kinsburskii
2024-10-05 0:07 ` Nuno Das Neves
2024-10-04 19:11 ` Simon Horman
2024-10-04 23:36 ` Nuno Das Neves
2024-10-04 21:55 ` kernel test robot
2024-10-05 1:54 ` kernel test robot
2024-10-07 16:26 ` [PATCH 0/5] Add new headers for Hyper-V Dom0 Wei Liu
2024-10-10 18:21 ` Michael Kelley
2024-10-11 1:34 ` [EXTERNAL] " MUKESH RATHOR
2024-10-23 0:04 ` Nuno Das Neves
2024-10-23 18:39 ` Michael Kelley
2024-10-23 0:51 ` Nuno Das Neves
2024-10-23 18:32 ` Michael Kelley
2024-10-31 19:05 ` Easwar Hariharan
2024-10-31 22:59 ` Nuno Das Neves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).