Skip to contentSkip to conversation

Hyper-V: Remove x86-isms from architecture independent Hyper-V drivers

PATCH In review [email protected] 2 participants 2 messages Oct 25, 2017 – Oct 29, 2017

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

PATCH 1/1 Hyper-V: Remove x86-isms from architecture independent Hyper-V drivers

From: Michael Kelley <[email protected]>

hv_is_hypercall_page_setup() is used to check if Hyper-V is initialized, but a 'hypercall page' is an x86 implementation detail that isn't necessarily present on other architectures. Rename to the architecture independent hv_is_hyperv_initialized(). Use this function instead of direct references to x86-specific data structures in vmbus_drv.c, and remove 'x86' from the string name passed to cpuhp_setup_state().

---
 arch/x86/hyperv/hv_init.c       | 4 ++--
 arch/x86/include/asm/mshyperv.h | 4 ++--
 drivers/hv/hv.c                 | 2 +-
 drivers/hv/vmbus_drv.c          | 5 ++---
 4 files changed, 7 insertions(+), 8 deletions(-)
arch/x86/hyperv/hv_init.c +2 -2
index a5db63f728a2..38310bd091c2 100644
@@ -236,7 +236,7 @@ void hyperv_report_panic(struct pt_regs *regs)
 }
 EXPORT_SYMBOL_GPL(hyperv_report_panic);
 
-bool hv_is_hypercall_page_setup(void)
+bool hv_is_hyperv_initialized(void)
 {
 	union hv_x64_msr_hypercall_contents hypercall_msr;
 
@@ -249,4 +249,4 @@ bool hv_is_hypercall_page_setup(void)
 
 	return true;
 }
-EXPORT_SYMBOL_GPL(hv_is_hypercall_page_setup);
+EXPORT_SYMBOL_GPL(hv_is_hyperv_initialized);
arch/x86/include/asm/mshyperv.h +2 -2
index 530f448fddaf..b001f898ccf3 100644
@@ -311,11 +311,11 @@ void hyperv_init(void);
 void hyperv_setup_mmu_ops(void);
 void hyper_alloc_mmu(void);
 void hyperv_report_panic(struct pt_regs *regs);
-bool hv_is_hypercall_page_setup(void);
+bool hv_is_hyperv_initialized(void);
 void hyperv_cleanup(void);
 #else /* CONFIG_HYPERV */
 static inline void hyperv_init(void) {}
-static inline bool hv_is_hypercall_page_setup(void) { return false; }
+static inline bool hv_is_hyperv_initialized(void) { return false; }
 static inline void hyperv_cleanup(void) {}
 static inline void hyperv_setup_mmu_ops(void) {}
 #endif /* CONFIG_HYPERV */
drivers/hv/hv.c +1 -1
index 8267439dd1ee..ebad26053362 100644
@@ -49,7 +49,7 @@ struct hv_context hv_context = {
  */
 int hv_init(void)
 {
-	if (!hv_is_hypercall_page_setup())
+	if (!hv_is_hyperv_initialized())
 		return -ENOTSUPP;
 
 	hv_context.cpu_context = alloc_percpu(struct hv_per_cpu_context);
drivers/hv/vmbus_drv.c +2 -3
index 1da8e818f4de..12c51dc6bb7b 100644
@@ -37,7 +37,6 @@
 #include <linux/sched/task_stack.h>
 
 #include <asm/hyperv.h>
-#include <asm/hypervisor.h>
 #include <asm/mshyperv.h>
 #include <linux/notifier.h>
 #include <linux/ptrace.h>
@@ -1047,7 +1046,7 @@ static int vmbus_bus_init(void)
 	 * Initialize the per-cpu interrupt state and
 	 * connect to the host.
 	 */
-	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/hyperv:online",
+	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hyperv/vmbus:online",
 				hv_synic_init, hv_synic_cleanup);
 	if (ret < 0)
 		goto err_alloc;
@@ -1695,7 +1694,7 @@ static int __init hv_acpi_init(void)
 {
 	int ret, t;
 
-	if (x86_hyper != &x86_hyper_ms_hyperv)
+	if (!hv_is_hyperv_initialized())
 		return -ENODEV;
 
 	init_completion(&probe_event);
Signature · 1 line
2.14.1
#1 lore raw
Quoted 112 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, October 25, 2017 3:31 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Stephen Hemminger <[email protected]>; KY Srinivasan <[email protected]>
Cc: Michael Kelley (EOSG) <[email protected]>
Subject: [PATCH char-misc 1/1] Hyper-V: Remove x86-isms from architecture independent Hyper-V drivers

[This sender failed our fraud detection checks and may not be who they appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing]

From: Michael Kelley <[email protected]>

hv_is_hypercall_page_setup() is used to check if Hyper-V is initialized, but a 'hypercall page' is an x86 implementation detail that isn't necessarily present on other architectures. Rename to the architecture independent hv_is_hyperv_initialized(). Use this function instead of direct references to x86-specific data structures in vmbus_drv.c, and remove 'x86' from the string name passed to cpuhp_setup_state().

---
 arch/x86/hyperv/hv_init.c       | 4 ++--
 arch/x86/include/asm/mshyperv.h | 4 ++--
 drivers/hv/hv.c                 | 2 +-
 drivers/hv/vmbus_drv.c          | 5 ++---
 4 files changed, 7 insertions(+), 8 deletions(-)
arch/x86/hyperv/hv_init.c +2 -2
index a5db63f728a2..38310bd091c2 100644
@@ -236,7 +236,7 @@ void hyperv_report_panic(struct pt_regs *regs)
 }
 EXPORT_SYMBOL_GPL(hyperv_report_panic);
 
-bool hv_is_hypercall_page_setup(void)
+bool hv_is_hyperv_initialized(void)
 {
        union hv_x64_msr_hypercall_contents hypercall_msr;
 
@@ -249,4 +249,4 @@ bool hv_is_hypercall_page_setup(void)
 
        return true;
 }
-EXPORT_SYMBOL_GPL(hv_is_hypercall_page_setup);
+EXPORT_SYMBOL_GPL(hv_is_hyperv_initialized);
arch/x86/include/asm/mshyperv.h +2 -2
index 530f448fddaf..b001f898ccf3 100644
@@ -311,11 +311,11 @@ void hyperv_init(void);
 void hyperv_setup_mmu_ops(void);
 void hyper_alloc_mmu(void);
 void hyperv_report_panic(struct pt_regs *regs);
-bool hv_is_hypercall_page_setup(void);
+bool hv_is_hyperv_initialized(void);
 void hyperv_cleanup(void);
 #else /* CONFIG_HYPERV */
 static inline void hyperv_init(void) {}
-static inline bool hv_is_hypercall_page_setup(void) { return false; }
+static inline bool hv_is_hyperv_initialized(void) { return false; }
 static inline void hyperv_cleanup(void) {}
 static inline void hyperv_setup_mmu_ops(void) {}
 #endif /* CONFIG_HYPERV */
drivers/hv/hv.c +1 -1
index 8267439dd1ee..ebad26053362 100644
@@ -49,7 +49,7 @@ struct hv_context hv_context = {
  */
 int hv_init(void)
 {
-       if (!hv_is_hypercall_page_setup())
+       if (!hv_is_hyperv_initialized())
                return -ENOTSUPP;
 
        hv_context.cpu_context = alloc_percpu(struct hv_per_cpu_context);
drivers/hv/vmbus_drv.c +1 -2
index 1da8e818f4de..12c51dc6bb7b 100644
@@ -37,7 +37,6 @@
 #include <linux/sched/task_stack.h>
 
 #include <asm/hyperv.h>
-#include <asm/hypervisor.h>
 #include <asm/mshyperv.h>
 #include <linux/notifier.h>
 #include <linux/ptrace.h>
@@ -1047,7 +1046,7 @@ static int vmbus_bus_init(void)
         * Initialize the per-cpu interrupt state and
         * connect to the host.
         */
-       ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
 "x86/hyperv:online",
+       ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
 "hyperv/vmbus:online",
                                hv_synic_init, hv_synic_cleanup);
        if (ret < 0)
                goto err_alloc;

drivers/hv/vmbus_drv.c static int __init hv_acpi_init(void) · line 1697

Quoted 5 lines
drivers/hv/vmbus_drv.c +1 -1
@@ -1695,7 +1694,7 @@ static int __init hv_acpi_init(void)
 {
        int ret, t;
 
-       if (x86_hyper != &x86_hyper_ms_hyperv)
+       if (!hv_is_hyperv_initialized())

We are checking to see if we are running on MSFT Hyper-V. This check was added to deal with situations where Xen/KVM were emulating Hyper-V. It may not be safe to replace this check with the call to hv_is_hyperv_initialized(). Perhaps we can add a new architecture independent function to check the hypervisor - something like running_on_mshyperv() that can be used here.

Regards,

K. Y

Quoted 5 lines
drivers/hv/vmbus_drv.c +0 -1
                return -ENODEV;
 
        init_completion(&probe_event);
--

2.14.1