All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roman Kagan <rkagan@virtuozzo.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"K. Y. Srinivasan" <kys@microsoft.com>,
	"Vitaly Kuznetsov" <vkuznets@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	<x86@kernel.org>, Haiyang Zhang <haiyangz@microsoft.com>,
	<kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<devel@linuxdriverproject.org>,
	"Denis V . Lunev" <den@openvz.org>,
	Roman Kagan <rkagan@virtuozzo.com>
Subject: [PATCH 09/15] hyperv: unify Hyper-V msr definitions
Date: Tue, 20 Dec 2016 18:55:56 +0300	[thread overview]
Message-ID: <20161220155602.6298-10-rkagan@virtuozzo.com> (raw)
In-Reply-To: <20161220155602.6298-1-rkagan@virtuozzo.com>

Use the definitions already present in the uapi header.  Besides, drop
all bitfields for the msr values and use bitwise operations instead.

Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
 drivers/hv/hyperv_vmbus.h |  88 ---------------------------
 drivers/hv/hv.c           | 150 ++++++++++++++++++----------------------------
 2 files changed, 59 insertions(+), 179 deletions(-)

diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 7bf1b10..ac73832 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -94,63 +94,6 @@ struct hv_connection_info {
 	};
 };
 
-/*
- * Timer configuration register.
- */
-union hv_timer_config {
-	u64 as_uint64;
-	struct {
-		u64 enable:1;
-		u64 periodic:1;
-		u64 lazy:1;
-		u64 auto_enable:1;
-		u64 reserved_z0:12;
-		u64 sintx:4;
-		u64 reserved_z1:44;
-	};
-};
-
-/* Define SynIC control register. */
-union hv_synic_scontrol {
-	u64 as_uint64;
-	struct {
-		u64 enable:1;
-		u64 reserved:63;
-	};
-};
-
-/* 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 reserved2:46;
-	};
-};
-
-/* 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;
-	};
-};
-
-/* 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;
-	};
-};
-
 /* Definitions for the monitored notification facility */
 union hv_monitor_trigger_group {
 	u64 as_uint64;
@@ -239,37 +182,6 @@ enum hv_guest_os_microsoft_ids {
 	HVGUESTOS_MICROSOFT_WINDOWSCE	= 0x05
 };
 
-/*
- * Declare the MSR used to identify the guest OS.
- */
-#define HV_X64_MSR_GUEST_OS_ID	0x40000000
-
-union hv_x64_msr_guest_os_id_contents {
-	u64 as_uint64;
-	struct {
-		u64 build_number:16;
-		u64 service_version:8; /* Service Pack, etc. */
-		u64 minor_version:8;
-		u64 major_version:8;
-		u64 os_id:8; /* enum hv_guest_os_microsoft_ids (if Vendor=MS) */
-		u64 vendor_id:16; /* enum hv_guest_os_vendor */
-	};
-};
-
-/*
- * Declare the MSR used to setup pages used to communicate with the hypervisor.
- */
-#define HV_X64_MSR_HYPERCALL	0x40000001
-
-union hv_x64_msr_hypercall_contents {
-	u64 as_uint64;
-	struct {
-		u64 enable:1;
-		u64 reserved:11;
-		u64 guest_physical_address:52;
-	};
-};
-
 
 enum {
 	VMBUS_MESSAGE_CONNECTION_ID	= 1,
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index dddba07..7d2a3d1 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -181,7 +181,7 @@ static struct clocksource hyperv_cs_tsc = {
 int hv_init(void)
 {
 	int max_leaf;
-	union hv_x64_msr_hypercall_contents hypercall_msr;
+	u64 hypercall_msr = 0;
 	void *virtaddr = NULL;
 
 	memset(hv_context.synic_event_page, 0, sizeof(void *) * NR_CPUS);
@@ -206,30 +206,24 @@ int hv_init(void)
 	hv_context.guestid = generate_guest_id(0, LINUX_VERSION_CODE, 0);
 	wrmsrl(HV_X64_MSR_GUEST_OS_ID, hv_context.guestid);
 
-	/* See if the hypercall page is already set */
-	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
-
 	virtaddr = (void *)get_zeroed_page(GFP_KERNEL);
 	if (!virtaddr || set_memory_x((unsigned long)virtaddr, 1))
 		goto cleanup;
 	hv_context.hypercall_page = virtaddr;
 
-	hypercall_msr.enable = 1;
-
-	hypercall_msr.guest_physical_address =
-				virt_to_phys(virtaddr) >> PAGE_SHIFT;
-	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr);
+	hypercall_msr &= PAGE_MASK;
+	hypercall_msr = HV_X64_MSR_HYPERCALL_ENABLE | virt_to_phys(virtaddr);
+	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr);
 
 	/* Confirm that hypercall page did get setup. */
-	hypercall_msr.as_uint64 = 0;
-	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
-
-	if (!hypercall_msr.enable)
+	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr);
+	if (!(hypercall_msr & HV_X64_MSR_HYPERCALL_ENABLE))
 		goto cleanup;
 
 #ifdef CONFIG_X86_64
 	if (ms_hyperv.features & HV_X64_MSR_REFERENCE_TSC_AVAILABLE) {
-		union hv_x64_msr_hypercall_contents tsc_msr;
+		u64 tsc_msr;
 		void *va_tsc;
 
 		va_tsc = (void *)get_zeroed_page(GFP_KERNEL);
@@ -237,21 +231,19 @@ int hv_init(void)
 			goto cleanup;
 		hv_context.tsc_page = va_tsc;
 
-		rdmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
-
-		tsc_msr.enable = 1;
-		tsc_msr.guest_physical_address =
-				virt_to_phys(va_tsc) >> PAGE_SHIFT;
-
-		wrmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
+		rdmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr);
+		tsc_msr &= PAGE_MASK;
+		tsc_msr |= HV_X64_MSR_TSC_REFERENCE_ENABLE |
+			virt_to_phys(va_tsc);
+		wrmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr);
 		clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100);
 	}
 #endif
 	return 0;
 
 cleanup:
-	hypercall_msr.as_uint64 = 0;
-	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+	hypercall_msr &= ~HV_X64_MSR_HYPERCALL_ENABLE;
+	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr);
 	free_page((unsigned long)virtaddr);
 
 	return -ENOTSUPP;
@@ -264,13 +256,14 @@ int hv_init(void)
  */
 void hv_cleanup(bool crash)
 {
-	union hv_x64_msr_hypercall_contents hypercall_msr;
+	u64 msr;
 
 	/* Reset our OS id */
 	wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
 
-	hypercall_msr.as_uint64 = 0;
-	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+	rdmsrl(HV_X64_MSR_HYPERCALL, msr);
+	msr &= ~HV_X64_MSR_HYPERCALL_ENABLE;
+	wrmsrl(HV_X64_MSR_HYPERCALL, msr);
 	if (!crash)
 		free_page((unsigned long)hv_context.hypercall_page);
 	hv_context.hypercall_page = NULL;
@@ -289,8 +282,9 @@ void hv_cleanup(bool crash)
 			clocksource_unregister(&hyperv_cs_tsc);
 		}
 
-		hypercall_msr.as_uint64 = 0;
-		wrmsrl(HV_X64_MSR_REFERENCE_TSC, hypercall_msr.as_uint64);
+		rdmsrl(HV_X64_MSR_REFERENCE_TSC, msr);
+		msr &= ~HV_X64_MSR_TSC_REFERENCE_ENABLE;
+		wrmsrl(HV_X64_MSR_REFERENCE_TSC, msr);
 		if (!crash)
 			free_page((unsigned long)hv_context.tsc_page);
 		hv_context.tsc_page = NULL;
@@ -352,12 +346,10 @@ static int hv_ce_shutdown(struct clock_event_device *evt)
 
 static int hv_ce_set_oneshot(struct clock_event_device *evt)
 {
-	union hv_timer_config timer_cfg;
+	u64 timer_cfg = HV_STIMER_ENABLE | HV_STIMER_AUTOENABLE |
+		(VMBUS_MESSAGE_SINT << 16);
 
-	timer_cfg.enable = 1;
-	timer_cfg.auto_enable = 1;
-	timer_cfg.sintx = VMBUS_MESSAGE_SINT;
-	wrmsrl(HV_X64_MSR_STIMER0_CONFIG, timer_cfg.as_uint64);
+	wrmsrl(HV_X64_MSR_STIMER0_CONFIG, timer_cfg);
 
 	return 0;
 }
@@ -474,52 +466,39 @@ void hv_synic_free(void)
  */
 void hv_synic_init(void *arg)
 {
-	u64 version;
-	union hv_synic_simp simp;
-	union hv_synic_siefp siefp;
-	union hv_synic_sint shared_sint;
-	union hv_synic_scontrol sctrl;
-	u64 vp_index;
-
+	u64 msr;
 	int cpu = smp_processor_id();
 
 	if (!hv_context.hypercall_page)
 		return;
 
 	/* Check the version */
-	rdmsrl(HV_X64_MSR_SVERSION, version);
+	rdmsrl(HV_X64_MSR_SVERSION, msr);
 
 	/* Setup the Synic's message page */
-	rdmsrl(HV_X64_MSR_SIMP, simp.as_uint64);
-	simp.simp_enabled = 1;
-	simp.base_simp_gpa = virt_to_phys(hv_context.synic_message_page[cpu])
-		>> PAGE_SHIFT;
-
-	wrmsrl(HV_X64_MSR_SIMP, simp.as_uint64);
+	rdmsrl(HV_X64_MSR_SIMP, msr);
+	msr &= PAGE_MASK;
+	msr |= virt_to_phys(hv_context.synic_message_page[cpu]) |
+		HV_SYNIC_SIMP_ENABLE;
+	wrmsrl(HV_X64_MSR_SIMP, msr);
 
 	/* Setup the Synic's event page */
-	rdmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64);
-	siefp.siefp_enabled = 1;
-	siefp.base_siefp_gpa = virt_to_phys(hv_context.synic_event_page[cpu])
-		>> PAGE_SHIFT;
-
-	wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64);
+	rdmsrl(HV_X64_MSR_SIEFP, msr);
+	msr &= PAGE_MASK;
+	msr |= virt_to_phys(hv_context.synic_event_page[cpu]) |
+		HV_SYNIC_SIEFP_ENABLE;
+	wrmsrl(HV_X64_MSR_SIEFP, msr);
 
 	/* Setup the shared SINT. */
-	rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
-
-	shared_sint.as_uint64 = 0;
-	shared_sint.vector = HYPERVISOR_CALLBACK_VECTOR;
-	shared_sint.masked = false;
-	shared_sint.auto_eoi = true;
-
-	wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
+	rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, msr);
+	msr &= ~(HV_SYNIC_SINT_MASKED | HV_SYNIC_SINT_VECTOR_MASK);
+	msr |= HYPERVISOR_CALLBACK_VECTOR | HV_SYNIC_SINT_AUTO_EOI;
+	wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, msr);
 
 	/* Enable the global synic bit */
-	rdmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64);
-	sctrl.enable = 1;
-
-	wrmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64);
+	rdmsrl(HV_X64_MSR_SCONTROL, msr);
+	msr |= HV_SYNIC_CONTROL_ENABLE;
+	wrmsrl(HV_X64_MSR_SCONTROL, msr);
 
 	hv_context.synic_initialized = true;
 
@@ -528,8 +507,8 @@ void hv_synic_init(void *arg)
 	 * of cpuid and Linux' notion of cpuid.
 	 * This array will be indexed using Linux cpuid.
 	 */
-	rdmsrl(HV_X64_MSR_VP_INDEX, vp_index);
-	hv_context.vp_index[cpu] = (u32)vp_index;
+	rdmsrl(HV_X64_MSR_VP_INDEX, msr);
+	hv_context.vp_index[cpu] = (u32)msr;
 
 	INIT_LIST_HEAD(&hv_context.percpu_list[cpu]);
 
@@ -563,10 +542,7 @@ void hv_synic_clockevents_cleanup(void)
  */
 void hv_synic_cleanup(void *arg)
 {
-	union hv_synic_sint shared_sint;
-	union hv_synic_simp simp;
-	union hv_synic_siefp siefp;
-	union hv_synic_scontrol sctrl;
+	u64 msr;
 	int cpu = smp_processor_id();
 
 	if (!hv_context.synic_initialized)
@@ -578,28 +554,20 @@ void hv_synic_cleanup(void *arg)
 		hv_ce_shutdown(hv_context.clk_evt[cpu]);
 	}
 
-	rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
-
-	shared_sint.masked = 1;
-
-	/* Need to correctly cleanup in the case of SMP!!! */
-	/* Disable the interrupt */
-	wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
-
-	rdmsrl(HV_X64_MSR_SIMP, simp.as_uint64);
-	simp.simp_enabled = 0;
-	simp.base_simp_gpa = 0;
-
-	wrmsrl(HV_X64_MSR_SIMP, simp.as_uint64);
+	rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, msr);
+	msr |= HV_SYNIC_SINT_MASKED;
+	wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, msr);
 
-	rdmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64);
-	siefp.siefp_enabled = 0;
-	siefp.base_siefp_gpa = 0;
+	rdmsrl(HV_X64_MSR_SIMP, msr);
+	msr &= ~HV_SYNIC_SIMP_ENABLE;
+	wrmsrl(HV_X64_MSR_SIMP, msr);
 
-	wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64);
+	rdmsrl(HV_X64_MSR_SIEFP, msr);
+	msr &= ~HV_SYNIC_SIEFP_ENABLE;
+	wrmsrl(HV_X64_MSR_SIEFP, msr);
 
 	/* Disable the global synic bit */
-	rdmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64);
-	sctrl.enable = 0;
-	wrmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64);
+	rdmsrl(HV_X64_MSR_SCONTROL, msr);
+	msr &= ~HV_SYNIC_CONTROL_ENABLE;
+	wrmsrl(HV_X64_MSR_SCONTROL, msr);
 }
-- 
2.9.3

WARNING: multiple messages have this Message-ID (diff)
From: Roman Kagan <rkagan@virtuozzo.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"K. Y. Srinivasan" <kys@microsoft.com>,
	"Vitaly Kuznetsov" <vkuznets@redhat.com>
Cc: kvm@vger.kernel.org, "Denis V . Lunev" <den@openvz.org>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	Ingo Molnar <mingo@redhat.com>,
	Roman Kagan <rkagan@virtuozzo.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	devel@linuxdriverproject.org,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 09/15] hyperv: unify Hyper-V msr definitions
Date: Tue, 20 Dec 2016 18:55:56 +0300	[thread overview]
Message-ID: <20161220155602.6298-10-rkagan@virtuozzo.com> (raw)
In-Reply-To: <20161220155602.6298-1-rkagan@virtuozzo.com>

Use the definitions already present in the uapi header.  Besides, drop
all bitfields for the msr values and use bitwise operations instead.

Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
 drivers/hv/hyperv_vmbus.h |  88 ---------------------------
 drivers/hv/hv.c           | 150 ++++++++++++++++++----------------------------
 2 files changed, 59 insertions(+), 179 deletions(-)

diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 7bf1b10..ac73832 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -94,63 +94,6 @@ struct hv_connection_info {
 	};
 };
 
-/*
- * Timer configuration register.
- */
-union hv_timer_config {
-	u64 as_uint64;
-	struct {
-		u64 enable:1;
-		u64 periodic:1;
-		u64 lazy:1;
-		u64 auto_enable:1;
-		u64 reserved_z0:12;
-		u64 sintx:4;
-		u64 reserved_z1:44;
-	};
-};
-
-/* Define SynIC control register. */
-union hv_synic_scontrol {
-	u64 as_uint64;
-	struct {
-		u64 enable:1;
-		u64 reserved:63;
-	};
-};
-
-/* 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 reserved2:46;
-	};
-};
-
-/* 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;
-	};
-};
-
-/* 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;
-	};
-};
-
 /* Definitions for the monitored notification facility */
 union hv_monitor_trigger_group {
 	u64 as_uint64;
@@ -239,37 +182,6 @@ enum hv_guest_os_microsoft_ids {
 	HVGUESTOS_MICROSOFT_WINDOWSCE	= 0x05
 };
 
-/*
- * Declare the MSR used to identify the guest OS.
- */
-#define HV_X64_MSR_GUEST_OS_ID	0x40000000
-
-union hv_x64_msr_guest_os_id_contents {
-	u64 as_uint64;
-	struct {
-		u64 build_number:16;
-		u64 service_version:8; /* Service Pack, etc. */
-		u64 minor_version:8;
-		u64 major_version:8;
-		u64 os_id:8; /* enum hv_guest_os_microsoft_ids (if Vendor=MS) */
-		u64 vendor_id:16; /* enum hv_guest_os_vendor */
-	};
-};
-
-/*
- * Declare the MSR used to setup pages used to communicate with the hypervisor.
- */
-#define HV_X64_MSR_HYPERCALL	0x40000001
-
-union hv_x64_msr_hypercall_contents {
-	u64 as_uint64;
-	struct {
-		u64 enable:1;
-		u64 reserved:11;
-		u64 guest_physical_address:52;
-	};
-};
-
 
 enum {
 	VMBUS_MESSAGE_CONNECTION_ID	= 1,
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index dddba07..7d2a3d1 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -181,7 +181,7 @@ static struct clocksource hyperv_cs_tsc = {
 int hv_init(void)
 {
 	int max_leaf;
-	union hv_x64_msr_hypercall_contents hypercall_msr;
+	u64 hypercall_msr = 0;
 	void *virtaddr = NULL;
 
 	memset(hv_context.synic_event_page, 0, sizeof(void *) * NR_CPUS);
@@ -206,30 +206,24 @@ int hv_init(void)
 	hv_context.guestid = generate_guest_id(0, LINUX_VERSION_CODE, 0);
 	wrmsrl(HV_X64_MSR_GUEST_OS_ID, hv_context.guestid);
 
-	/* See if the hypercall page is already set */
-	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
-
 	virtaddr = (void *)get_zeroed_page(GFP_KERNEL);
 	if (!virtaddr || set_memory_x((unsigned long)virtaddr, 1))
 		goto cleanup;
 	hv_context.hypercall_page = virtaddr;
 
-	hypercall_msr.enable = 1;
-
-	hypercall_msr.guest_physical_address =
-				virt_to_phys(virtaddr) >> PAGE_SHIFT;
-	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr);
+	hypercall_msr &= PAGE_MASK;
+	hypercall_msr = HV_X64_MSR_HYPERCALL_ENABLE | virt_to_phys(virtaddr);
+	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr);
 
 	/* Confirm that hypercall page did get setup. */
-	hypercall_msr.as_uint64 = 0;
-	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
-
-	if (!hypercall_msr.enable)
+	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr);
+	if (!(hypercall_msr & HV_X64_MSR_HYPERCALL_ENABLE))
 		goto cleanup;
 
 #ifdef CONFIG_X86_64
 	if (ms_hyperv.features & HV_X64_MSR_REFERENCE_TSC_AVAILABLE) {
-		union hv_x64_msr_hypercall_contents tsc_msr;
+		u64 tsc_msr;
 		void *va_tsc;
 
 		va_tsc = (void *)get_zeroed_page(GFP_KERNEL);
@@ -237,21 +231,19 @@ int hv_init(void)
 			goto cleanup;
 		hv_context.tsc_page = va_tsc;
 
-		rdmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
-
-		tsc_msr.enable = 1;
-		tsc_msr.guest_physical_address =
-				virt_to_phys(va_tsc) >> PAGE_SHIFT;
-
-		wrmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
+		rdmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr);
+		tsc_msr &= PAGE_MASK;
+		tsc_msr |= HV_X64_MSR_TSC_REFERENCE_ENABLE |
+			virt_to_phys(va_tsc);
+		wrmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr);
 		clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100);
 	}
 #endif
 	return 0;
 
 cleanup:
-	hypercall_msr.as_uint64 = 0;
-	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+	hypercall_msr &= ~HV_X64_MSR_HYPERCALL_ENABLE;
+	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr);
 	free_page((unsigned long)virtaddr);
 
 	return -ENOTSUPP;
@@ -264,13 +256,14 @@ int hv_init(void)
  */
 void hv_cleanup(bool crash)
 {
-	union hv_x64_msr_hypercall_contents hypercall_msr;
+	u64 msr;
 
 	/* Reset our OS id */
 	wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
 
-	hypercall_msr.as_uint64 = 0;
-	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+	rdmsrl(HV_X64_MSR_HYPERCALL, msr);
+	msr &= ~HV_X64_MSR_HYPERCALL_ENABLE;
+	wrmsrl(HV_X64_MSR_HYPERCALL, msr);
 	if (!crash)
 		free_page((unsigned long)hv_context.hypercall_page);
 	hv_context.hypercall_page = NULL;
@@ -289,8 +282,9 @@ void hv_cleanup(bool crash)
 			clocksource_unregister(&hyperv_cs_tsc);
 		}
 
-		hypercall_msr.as_uint64 = 0;
-		wrmsrl(HV_X64_MSR_REFERENCE_TSC, hypercall_msr.as_uint64);
+		rdmsrl(HV_X64_MSR_REFERENCE_TSC, msr);
+		msr &= ~HV_X64_MSR_TSC_REFERENCE_ENABLE;
+		wrmsrl(HV_X64_MSR_REFERENCE_TSC, msr);
 		if (!crash)
 			free_page((unsigned long)hv_context.tsc_page);
 		hv_context.tsc_page = NULL;
@@ -352,12 +346,10 @@ static int hv_ce_shutdown(struct clock_event_device *evt)
 
 static int hv_ce_set_oneshot(struct clock_event_device *evt)
 {
-	union hv_timer_config timer_cfg;
+	u64 timer_cfg = HV_STIMER_ENABLE | HV_STIMER_AUTOENABLE |
+		(VMBUS_MESSAGE_SINT << 16);
 
-	timer_cfg.enable = 1;
-	timer_cfg.auto_enable = 1;
-	timer_cfg.sintx = VMBUS_MESSAGE_SINT;
-	wrmsrl(HV_X64_MSR_STIMER0_CONFIG, timer_cfg.as_uint64);
+	wrmsrl(HV_X64_MSR_STIMER0_CONFIG, timer_cfg);
 
 	return 0;
 }
@@ -474,52 +466,39 @@ void hv_synic_free(void)
  */
 void hv_synic_init(void *arg)
 {
-	u64 version;
-	union hv_synic_simp simp;
-	union hv_synic_siefp siefp;
-	union hv_synic_sint shared_sint;
-	union hv_synic_scontrol sctrl;
-	u64 vp_index;
-
+	u64 msr;
 	int cpu = smp_processor_id();
 
 	if (!hv_context.hypercall_page)
 		return;
 
 	/* Check the version */
-	rdmsrl(HV_X64_MSR_SVERSION, version);
+	rdmsrl(HV_X64_MSR_SVERSION, msr);
 
 	/* Setup the Synic's message page */
-	rdmsrl(HV_X64_MSR_SIMP, simp.as_uint64);
-	simp.simp_enabled = 1;
-	simp.base_simp_gpa = virt_to_phys(hv_context.synic_message_page[cpu])
-		>> PAGE_SHIFT;
-
-	wrmsrl(HV_X64_MSR_SIMP, simp.as_uint64);
+	rdmsrl(HV_X64_MSR_SIMP, msr);
+	msr &= PAGE_MASK;
+	msr |= virt_to_phys(hv_context.synic_message_page[cpu]) |
+		HV_SYNIC_SIMP_ENABLE;
+	wrmsrl(HV_X64_MSR_SIMP, msr);
 
 	/* Setup the Synic's event page */
-	rdmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64);
-	siefp.siefp_enabled = 1;
-	siefp.base_siefp_gpa = virt_to_phys(hv_context.synic_event_page[cpu])
-		>> PAGE_SHIFT;
-
-	wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64);
+	rdmsrl(HV_X64_MSR_SIEFP, msr);
+	msr &= PAGE_MASK;
+	msr |= virt_to_phys(hv_context.synic_event_page[cpu]) |
+		HV_SYNIC_SIEFP_ENABLE;
+	wrmsrl(HV_X64_MSR_SIEFP, msr);
 
 	/* Setup the shared SINT. */
-	rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
-
-	shared_sint.as_uint64 = 0;
-	shared_sint.vector = HYPERVISOR_CALLBACK_VECTOR;
-	shared_sint.masked = false;
-	shared_sint.auto_eoi = true;
-
-	wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
+	rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, msr);
+	msr &= ~(HV_SYNIC_SINT_MASKED | HV_SYNIC_SINT_VECTOR_MASK);
+	msr |= HYPERVISOR_CALLBACK_VECTOR | HV_SYNIC_SINT_AUTO_EOI;
+	wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, msr);
 
 	/* Enable the global synic bit */
-	rdmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64);
-	sctrl.enable = 1;
-
-	wrmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64);
+	rdmsrl(HV_X64_MSR_SCONTROL, msr);
+	msr |= HV_SYNIC_CONTROL_ENABLE;
+	wrmsrl(HV_X64_MSR_SCONTROL, msr);
 
 	hv_context.synic_initialized = true;
 
@@ -528,8 +507,8 @@ void hv_synic_init(void *arg)
 	 * of cpuid and Linux' notion of cpuid.
 	 * This array will be indexed using Linux cpuid.
 	 */
-	rdmsrl(HV_X64_MSR_VP_INDEX, vp_index);
-	hv_context.vp_index[cpu] = (u32)vp_index;
+	rdmsrl(HV_X64_MSR_VP_INDEX, msr);
+	hv_context.vp_index[cpu] = (u32)msr;
 
 	INIT_LIST_HEAD(&hv_context.percpu_list[cpu]);
 
@@ -563,10 +542,7 @@ void hv_synic_clockevents_cleanup(void)
  */
 void hv_synic_cleanup(void *arg)
 {
-	union hv_synic_sint shared_sint;
-	union hv_synic_simp simp;
-	union hv_synic_siefp siefp;
-	union hv_synic_scontrol sctrl;
+	u64 msr;
 	int cpu = smp_processor_id();
 
 	if (!hv_context.synic_initialized)
@@ -578,28 +554,20 @@ void hv_synic_cleanup(void *arg)
 		hv_ce_shutdown(hv_context.clk_evt[cpu]);
 	}
 
-	rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
-
-	shared_sint.masked = 1;
-
-	/* Need to correctly cleanup in the case of SMP!!! */
-	/* Disable the interrupt */
-	wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
-
-	rdmsrl(HV_X64_MSR_SIMP, simp.as_uint64);
-	simp.simp_enabled = 0;
-	simp.base_simp_gpa = 0;
-
-	wrmsrl(HV_X64_MSR_SIMP, simp.as_uint64);
+	rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, msr);
+	msr |= HV_SYNIC_SINT_MASKED;
+	wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, msr);
 
-	rdmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64);
-	siefp.siefp_enabled = 0;
-	siefp.base_siefp_gpa = 0;
+	rdmsrl(HV_X64_MSR_SIMP, msr);
+	msr &= ~HV_SYNIC_SIMP_ENABLE;
+	wrmsrl(HV_X64_MSR_SIMP, msr);
 
-	wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64);
+	rdmsrl(HV_X64_MSR_SIEFP, msr);
+	msr &= ~HV_SYNIC_SIEFP_ENABLE;
+	wrmsrl(HV_X64_MSR_SIEFP, msr);
 
 	/* Disable the global synic bit */
-	rdmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64);
-	sctrl.enable = 0;
-	wrmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64);
+	rdmsrl(HV_X64_MSR_SCONTROL, msr);
+	msr &= ~HV_SYNIC_CONTROL_ENABLE;
+	wrmsrl(HV_X64_MSR_SCONTROL, msr);
 }
-- 
2.9.3

  parent reply	other threads:[~2016-12-20 19:12 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-20 15:55 [PATCH 00/15] hyperv: more stuff to uapi + cleanup Roman Kagan
2016-12-20 15:55 ` [PATCH 01/15] hyperv: consolidate TSC ref page definitions Roman Kagan
2016-12-20 20:57   ` KY Srinivasan
2016-12-21  6:25     ` Roman Kagan
2016-12-21  6:25       ` Roman Kagan
2016-12-20 15:55 ` [PATCH 02/15] hyperv: uapi-fy synic event flags definitions Roman Kagan
2016-12-20 15:55   ` Roman Kagan
2016-12-20 17:24   ` Stephen Hemminger
2016-12-20 17:24     ` Stephen Hemminger
2016-12-21  6:33     ` Roman Kagan
2016-12-21  6:33       ` Roman Kagan
2016-12-21 10:58   ` kbuild test robot
2016-12-21 18:58   ` KY Srinivasan
2016-12-21 18:58     ` KY Srinivasan
2016-12-20 15:55 ` [PATCH 03/15] hyperv: use standard bitops Roman Kagan
2016-12-20 15:55   ` Roman Kagan
2016-12-21 12:00   ` Olaf Hering
2016-12-21 13:23     ` Roman Kagan
2016-12-22 12:33       ` Paolo Bonzini
2016-12-21 19:08   ` KY Srinivasan
2016-12-21 19:08     ` KY Srinivasan
2016-12-20 15:55 ` [PATCH 04/15] hyperv: define VMBus message type Roman Kagan
2016-12-20 15:55   ` Roman Kagan
2016-12-20 15:55 ` [PATCH 05/15] hyperv: GFP_ATOMIC -> GFP_KERNEL Roman Kagan
2016-12-20 15:55   ` Roman Kagan
2016-12-20 15:55 ` [PATCH 06/15] hyperv: avoid unnecessary vmalloc Roman Kagan
2016-12-20 15:55   ` Roman Kagan
2016-12-21 19:19   ` KY Srinivasan
2016-12-20 15:55 ` [PATCH 07/15] hyperv: dedup cpuid definitions Roman Kagan
2016-12-20 15:55   ` Roman Kagan
2016-12-20 15:55 ` [PATCH 08/15] hyperv: dedup crash msr related definitions Roman Kagan
2016-12-20 15:55   ` Roman Kagan
2016-12-20 15:55 ` Roman Kagan [this message]
2016-12-20 15:55   ` [PATCH 09/15] hyperv: unify Hyper-V msr definitions Roman Kagan
2016-12-20 15:55 ` [PATCH 10/15] hyperv: uapi-fy PostMessage and SignalEvent hypercall structures Roman Kagan
2016-12-20 15:55   ` Roman Kagan
2016-12-21 19:27   ` KY Srinivasan
2016-12-20 15:55 ` [PATCH 11/15] hyperv: uapi-fy monitored notification structures Roman Kagan
2016-12-20 15:55   ` Roman Kagan
2016-12-20 15:55 ` [PATCH 12/15] hyperv: move VMBus connection ids to uapi Roman Kagan
2016-12-20 17:25   ` Stephen Hemminger
2016-12-21  6:29     ` Roman Kagan
2016-12-21  6:29       ` Roman Kagan
2016-12-21 12:18       ` Christoph Hellwig
2016-12-21 12:59         ` Roman Kagan
2016-12-21 12:59           ` Roman Kagan
2016-12-21 14:26           ` Christoph Hellwig
2016-12-21 14:39             ` Roman Kagan
2016-12-21 14:39               ` Roman Kagan
2016-12-21 15:39             ` Paolo Bonzini
2016-12-21 15:43               ` Christoph Hellwig
2016-12-21 15:43                 ` Christoph Hellwig
2016-12-21 17:25                 ` Paolo Bonzini
2016-12-21 17:50                 ` Stephen Hemminger
2016-12-21 17:50                   ` Stephen Hemminger
2016-12-21 17:53                   ` Paolo Bonzini
2016-12-21 17:53                     ` Paolo Bonzini
2016-12-21 17:58                   ` Christoph Hellwig
2016-12-21 17:58                     ` Christoph Hellwig
2016-12-21 18:02                     ` Stephen Hemminger
2016-12-21 18:02                       ` Stephen Hemminger
2016-12-21 19:54                       ` KY Srinivasan
2016-12-21 19:54                         ` KY Srinivasan
2016-12-28 17:09                         ` Roman Kagan
2016-12-28 17:09                           ` Roman Kagan
2016-12-29 18:29                           ` Stephen Hemminger
2016-12-29 18:29                             ` Stephen Hemminger
2017-01-02  8:19                           ` Paolo Bonzini
2017-01-09  8:32                             ` Roman Kagan
2017-01-09  8:40                               ` hpa
2017-01-09  8:58                                 ` Roman Kagan
2017-01-09  8:58                                   ` Roman Kagan
2017-01-09  9:02                                 ` Paolo Bonzini
2017-01-02 19:39                           ` Stephen Hemminger
2017-01-02 19:39                             ` Stephen Hemminger
2017-01-03  9:32                             ` Paolo Bonzini
2016-12-20 15:56 ` [PATCH 13/15] hyperv: move function close to its only callsite Roman Kagan
2016-12-20 15:56 ` [PATCH 14/15] hyperv_vmbus: drop unused definitions Roman Kagan
2016-12-20 15:56 ` [PATCH 15/15] hyperv: redefine hv_message without bitfields Roman Kagan
2016-12-21 18:00 ` [PATCH 00/15] hyperv: more stuff to uapi + cleanup KY Srinivasan
2016-12-28 16:57   ` Roman Kagan
2016-12-28 16:57     ` Roman Kagan
2016-12-30 19:45     ` KY Srinivasan
2016-12-30 19:45       ` KY Srinivasan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161220155602.6298-10-rkagan@virtuozzo.com \
    --to=rkagan@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=devel@linuxdriverproject.org \
    --cc=haiyangz@microsoft.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.