Skip to contentSkip to conversation

Split hyperv-tlfs.h into generic and arch specific files

PATCH Applied Michael Kelley 3 participants 7 messages Apr 22, 2020 – Apr 23, 2020

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

v2 cover Split hyperv-tlfs.h into generic and arch specific files

This series splits hyperv-tlfs.h into architecture independent and architecture specific files so that the arch independent portion can be shared between the x86/x64 and ARM64 code for Hyper-V. While the Hyper-V team has not released a version of the TLFS document that clearly specifies which portions of the interface are arch independent, we can make a fairly good assessment based on implementation work done to support Linux guests on Hyper-V on ARM64, and on private communication with the Hyper-V team. Definitions are considered arch independent if they are implemented by Hyper-V on both architectures (x86/x64 and ARM64), even if they are currently needed by Linux code only on one architecture.

Many definitions in hyperv-tlfs.h have historically contained "X64" in the name, which doesn't make sense for architecture independent definitions. While many of the occurrences of "X64" have already been removed, some still remain in definitions that should be arch independent. The split removes the "X64" from the definitions so that the arch independent hyper-tlfs.h has no occurrences of "X64". However, to keep this patch set separate from a wider change in the names, aliases are added in the x86/x64 specific hyperv-tlfs.h so that existing code continues to compile. The definitions can be fixed throughout the code in a more incremental fashion in separate patches, and then the aliases can be removed.

Where it is not clear if definitions are arch independent, they have been kept in the x86/x64 specific file. The Hyper-V team is aiming to have a version of the TLFS document covering ARM64 by the end of calendar 2020, so additional definitions may be moved into the arch independent portion after the new TLFS document is released.

The first two patches in the series clean up the existing hyperv-tlfs.h file a bit by removing duplicate or unnecessary definitions so they are not propagated across the split. The third patch does the split, and the fourth patch adds new definitions that are needed on ARM64 but are generic.

These changes have no functional impact.

These patches are built against linux-next-20200415

---

Changes in v2:
* Improved definitions for Get/SetVpRegisters hypercalls in include/asm-generic/hyperv-tlfs.h in Patch 4 [Vitaly Kuznetsov]
* Updated MAINTAINERS with new file in Patch 3

Michael Kelley (4):
KVM: x86: hyperv: Remove duplicate definitions of Reference TSC Page x86/hyperv: Remove HV_PROCESSOR_POWER_STATE #defines x86/hyperv: Split hyperv-tlfs.h into arch dependent and independent
files
asm-generic/hyperv: Add definitions for Get/SetVpRegister hypercalls

 MAINTAINERS                        |   1 +
 arch/x86/include/asm/hyperv-tlfs.h | 472 +++------------------------
 arch/x86/include/asm/kvm_host.h    |   2 +-
 arch/x86/kvm/hyperv.c              |   4 +-
 include/asm-generic/hyperv-tlfs.h  | 493 +++++++++++++++++++++++++++++
 5 files changed, 533 insertions(+), 439 deletions(-)
 create mode 100644 include/asm-generic/hyperv-tlfs.h
Signature · 1 line
2.18.2
#1 lore raw

PATCH v2 1/4 KVM: x86: hyperv: Remove duplicate definitions of Reference TSC Page

The Hyper-V Reference TSC Page structure is defined twice. struct ms_hyperv_tsc_page has padding out to a full 4 Kbyte page size. But the padding is not needed because the declaration includes a union with HV_HYP_PAGE_SIZE. KVM uses the second definition, which is struct _HV_REFERENCE_TSC_PAGE, because it does not have the padding.

Fix the duplication by removing the padding from ms_hyperv_tsc_page. Fix up the KVM code to use it. Remove the no longer used struct _HV_REFERENCE_TSC_PAGE.

There is no functional change.

---
 arch/x86/include/asm/hyperv-tlfs.h | 8 --------
 arch/x86/include/asm/kvm_host.h    | 2 +-
 arch/x86/kvm/hyperv.c              | 4 ++--
 3 files changed, 3 insertions(+), 11 deletions(-)
arch/x86/include/asm/hyperv-tlfs.h +0 -8
index 29336574d0bc..0e4d76920957 100644
@@ -303,7 +303,6 @@ struct ms_hyperv_tsc_page {
 	u32 reserved1;
 	volatile u64 tsc_scale;
 	volatile s64 tsc_offset;
-	u64 reserved2[509];
 }  __packed;
 
 /*
@@ -433,13 +432,6 @@ enum HV_GENERIC_SET_FORMAT {
  */
 #define HV_CLOCK_HZ (NSEC_PER_SEC/100)
 
-typedef struct _HV_REFERENCE_TSC_PAGE {
-	__u32 tsc_sequence;
-	__u32 res1;
-	__u64 tsc_scale;
-	__s64 tsc_offset;
-}  __packed HV_REFERENCE_TSC_PAGE, *PHV_REFERENCE_TSC_PAGE;
-
 /* Define the number of synthetic interrupt sources. */
 #define HV_SYNIC_SINT_COUNT		(16)
 /* Define the expected SynIC version. */
arch/x86/include/asm/kvm_host.h +1 -1
index 42a2d0d3984a..4698343b9a05 100644
@@ -865,7 +865,7 @@ struct kvm_hv {
 	u64 hv_crash_param[HV_X64_MSR_CRASH_PARAMS];
 	u64 hv_crash_ctl;
 
-	HV_REFERENCE_TSC_PAGE tsc_ref;
+	struct ms_hyperv_tsc_page tsc_ref;
 
 	struct idr conn_to_evt;
 
arch/x86/kvm/hyperv.c +2 -2
index bcefa9d4e57e..1f3c6fd3cdaa 100644
@@ -900,7 +900,7 @@ static int kvm_hv_msr_set_crash_data(struct kvm_vcpu *vcpu,
  * These two equivalencies are implemented in this function.
  */
 static bool compute_tsc_page_parameters(struct pvclock_vcpu_time_info *hv_clock,
-					HV_REFERENCE_TSC_PAGE *tsc_ref)
+					struct ms_hyperv_tsc_page *tsc_ref)
 {
 	u64 max_mul;
 
@@ -941,7 +941,7 @@ void kvm_hv_setup_tsc_page(struct kvm *kvm,
 	u64 gfn;
 
 	BUILD_BUG_ON(sizeof(tsc_seq) != sizeof(hv->tsc_ref.tsc_sequence));
-	BUILD_BUG_ON(offsetof(HV_REFERENCE_TSC_PAGE, tsc_sequence) != 0);
+	BUILD_BUG_ON(offsetof(struct ms_hyperv_tsc_page, tsc_sequence) != 0);
 
 	if (!(hv->hv_tsc_page & HV_X64_MSR_TSC_REFERENCE_ENABLE))
 		return;
Signature · 1 line
2.18.2
#2 lore raw

PATCH v2 2/4 x86/hyperv: Remove HV_PROCESSOR_POWER_STATE #defines

In reply to Michael Kelley

The HV_PROCESSOR_POWER_STATE_C<n> #defines date back to year 2010, but they are not in the TLFS v6.0 document and are not used anywhere in Linux. Remove them.

---
 arch/x86/include/asm/hyperv-tlfs.h | 5 -----
 1 file changed, 5 deletions(-)
arch/x86/include/asm/hyperv-tlfs.h +0 -5
index 0e4d76920957..2dd1ceb2bcf8 100644
@@ -390,11 +390,6 @@ struct hv_tsc_emulation_status {
 #define HV_X64_MSR_TSC_REFERENCE_ENABLE		0x00000001
 #define HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT	12
 
-#define HV_PROCESSOR_POWER_STATE_C0		0
-#define HV_PROCESSOR_POWER_STATE_C1		1
-#define HV_PROCESSOR_POWER_STATE_C2		2
-#define HV_PROCESSOR_POWER_STATE_C3		3
-
 #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)
Signature · 1 line
2.18.2
#3 lore raw

PATCH v2 3/4 x86/hyperv: Split hyperv-tlfs.h into arch dependent and independent files

In reply to Michael Kelley

In preparation for adding ARM64 support, split hyperv-tlfs.h into architecture dependent and architecture independent files, similar to what has been done with mshyperv.h. Move architecture independent definitions into include/asm-generic/hyperv-tlfs.h. The split will avoid duplicating significant lines of code in the ARM64 version of hyperv-tlfs.h. The split has no functional impact.

Some of the common definitions have "X64" in the symbol name. Change these to remove the "X64" in the architecture independent version of hyperv-tlfs.h, but add aliases with the "X64" in the x86 version so that x86 code will continue to compile. A later patch set will change all the references and allow removal of the aliases.

---
 MAINTAINERS                        |   1 +
 arch/x86/include/asm/hyperv-tlfs.h | 459 +++--------------------------
 include/asm-generic/hyperv-tlfs.h  | 442 +++++++++++++++++++++++++++
 3 files changed, 479 insertions(+), 423 deletions(-)
 create mode 100644 include/asm-generic/hyperv-tlfs.h
MAINTAINERS +1 -0
index cb68a9437eff..843f2f30648f 100644
@@ -7884,6 +7884,7 @@ F:	drivers/pci/controller/pci-hyperv.c
 F:	drivers/scsi/storvsc_drv.c
 F:	drivers/uio/uio_hv_generic.c
 F:	drivers/video/fbdev/hyperv_fb.c
+F:	include/asm-generic/hyperv-tlfs.h
 F:	include/asm-generic/mshyperv.h
 F:	include/clocksource/hyperv_timer.h
 F:	include/linux/hyperv.h
arch/x86/include/asm/hyperv-tlfs.h +36 -423

537 lines not on this page · raw message

include/asm-generic/hyperv-tlfs.h new file +442 -0

442 lines not on this page · raw message

Signature · 1 line
2.18.2
#4 lore raw

PATCH v2 4/4 asm-generic/hyperv: Add definitions for Get/SetVpRegister hypercalls

In reply to Michael Kelley

Add definitions for GetVpRegister and SetVpRegister hypercalls, which are implemented for both x86 and ARM64.

---
 include/asm-generic/hyperv-tlfs.h | 51 +++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
include/asm-generic/hyperv-tlfs.h +51 -0
index 1f92ef92eb56..262fae9526b1 100644
@@ -141,6 +141,8 @@ struct ms_hyperv_tsc_page {
 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX	0x0013
 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX	0x0014
 #define HVCALL_SEND_IPI_EX			0x0015
+#define HVCALL_GET_VP_REGISTERS			0x0050
+#define HVCALL_SET_VP_REGISTERS			0x0051
 #define HVCALL_POST_MESSAGE			0x005c
 #define HVCALL_SIGNAL_EVENT			0x005d
 #define HVCALL_RETARGET_INTERRUPT		0x007e
@@ -439,4 +441,53 @@ struct hv_retarget_device_interrupt {
 	struct hv_device_interrupt_target int_target;
 } __packed __aligned(8);
 
+
+/* HvGetVpRegisters hypercall input with variable size reg name list*/
+struct hv_get_vp_registers_input {
+	struct {
+		u64 partitionid;
+		u32 vpindex;
+		u8  inputvtl;
+		u8  padding[3];
+	} header;
+	struct input {
+		u32 name0;
+		u32 name1;
+	} element[];
+} __packed;
+
+
+/* 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;
+	};
+};
+
+/* HvSetVpRegisters hypercall with variable size reg name/value list*/
+struct hv_set_vp_registers_input {
+	struct {
+		u64 partitionid;
+		u32 vpindex;
+		u8  inputvtl;
+		u8  padding[3];
+	} header;
+	struct {
+		u32 name;
+		u32 padding1;
+		u64 padding2;
+		u64 valuelow;
+		u64 valuehigh;
+	} element[];
+} __packed;
+
 #endif
Signature · 1 line
2.18.2
maintainer Reviewed-by on v2 4/4
#5 lore raw

Re: [PATCH v2 4/4] asm-generic/hyperv: Add definitions for Get/SetVpRegister hypercalls

Quoted 65 lines · Michael Kelley

Add definitions for GetVpRegister and SetVpRegister hypercalls, which are implemented for both x86 and ARM64.

---
 include/asm-generic/hyperv-tlfs.h | 51 +++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
include/asm-generic/hyperv-tlfs.h +42 -0
index 1f92ef92eb56..262fae9526b1 100644
@@ -141,6 +141,8 @@ struct ms_hyperv_tsc_page {
 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX	0x0013
 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX	0x0014
 #define HVCALL_SEND_IPI_EX			0x0015
+#define HVCALL_GET_VP_REGISTERS			0x0050
+#define HVCALL_SET_VP_REGISTERS			0x0051
 #define HVCALL_POST_MESSAGE			0x005c
 #define HVCALL_SIGNAL_EVENT			0x005d
 #define HVCALL_RETARGET_INTERRUPT		0x007e
@@ -439,4 +441,53 @@ struct hv_retarget_device_interrupt {
 	struct hv_device_interrupt_target int_target;
 } __packed __aligned(8);
 
+
+/* HvGetVpRegisters hypercall input with variable size reg name list*/
+struct hv_get_vp_registers_input {
+	struct {
+		u64 partitionid;
+		u32 vpindex;
+		u8  inputvtl;
+		u8  padding[3];
+	} header;
+	struct input {
+		u32 name0;
+		u32 name1;
+	} element[];
+} __packed;
+
+
+/* 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;
+	};
+};
+
+/* HvSetVpRegisters hypercall with variable size reg name/value list*/
+struct hv_set_vp_registers_input {
+	struct {
+		u64 partitionid;
+		u32 vpindex;
+		u8  inputvtl;
+		u8  padding[3];
+	} header;

include/asm-generic/hyperv-tlfs.h struct hv_retarget_device_interrupt { · line 493

Quoted 10 lines
include/asm-generic/hyperv-tlfs.h +9 -0
+	struct {
+		u32 name;
+		u32 padding1;
+		u64 padding2;
+		u64 valuelow;
+		u64 valuehigh;
+	} element[];
+} __packed;
+
 #endif

Thank you for making these changes,

Signature · 1 line
Vitaly
maintainer Applied
#6 lore raw
In reply to Michael Kelley
Quoted 29 lines · Michael Kelley

This series splits hyperv-tlfs.h into architecture independent and architecture specific files so that the arch independent portion can be shared between the x86/x64 and ARM64 code for Hyper-V. While the Hyper-V team has not released a version of the TLFS document that clearly specifies which portions of the interface are arch independent, we can make a fairly good assessment based on implementation work done to support Linux guests on Hyper-V on ARM64, and on private communication with the Hyper-V team. Definitions are considered arch independent if they are implemented by Hyper-V on both architectures (x86/x64 and ARM64), even if they are currently needed by Linux code only on one architecture.

Many definitions in hyperv-tlfs.h have historically contained "X64" in the name, which doesn't make sense for architecture independent definitions. While many of the occurrences of "X64" have already been removed, some still remain in definitions that should be arch independent. The split removes the "X64" from the definitions so that the arch independent hyper-tlfs.h has no occurrences of "X64". However, to keep this patch set separate from a wider change in the names, aliases are added in the x86/x64 specific hyperv-tlfs.h so that existing code continues to compile. The definitions can be fixed throughout the code in a more incremental fashion in separate patches, and then the aliases can be removed.

Where it is not clear if definitions are arch independent, they have been kept in the x86/x64 specific file. The Hyper-V team is aiming to have a version of the TLFS document covering ARM64 by the end of calendar 2020, so additional definitions may be moved into the arch independent portion after the new TLFS document is released.

Quoted 8 lines

The first two patches in the series clean up the existing hyperv-tlfs.h file a bit by removing duplicate or unnecessary definitions so they are not propagated across the split. The third patch does the split, and the fourth patch adds new definitions that are needed on ARM64 but are generic.

These changes have no functional impact.

These patches are built against linux-next-20200415

Applied to hyperv-next. Thanks.

Wei.