2021-07-12 03:27:34

by Michael Kelley (LINUX)

[permalink] [raw]
Subject: [PATCH 0/3] Additional refactoring of Hyper-V arch specific code

This patch set moves additional Hyper-V code under arch/x86 into
arch-neutral hv_common.c where it can be shared by x86 and
and ARM64 implementations. The move reduces the overall lines
of code across both architectures, and removes code under
arch/ that isn't really architecture-specific.

The code is moved into hv_common.c because it must be
built-in to the kernel image, and not be part of a module.

No functional changes are intended.
Michael Kelley (3):
Drivers: hv: Make portions of Hyper-V init code be arch neutral
Drivers: hv: Add arch independent default functions for some Hyper-V
handlers
Drivers: hv: Move Hyper-V misc functionality to arch-neutral code

arch/x86/hyperv/hv_init.c | 101 +++-----------------
arch/x86/include/asm/mshyperv.h | 4 -
arch/x86/kernel/cpu/mshyperv.c | 24 -----
drivers/hv/hv_common.c | 198 ++++++++++++++++++++++++++++++++++++++++
include/asm-generic/mshyperv.h | 10 ++
5 files changed, 219 insertions(+), 118 deletions(-)

--
1.8.3.1


2021-07-12 03:27:58

by Michael Kelley (LINUX)

[permalink] [raw]
Subject: [PATCH 2/3] Drivers: hv: Add arch independent default functions for some Hyper-V handlers

Architecture independent Hyper-V code calls various arch-specific handlers
when needed. To aid in supporting multiple architectures, provide weak
defaults that can be overridden by arch-specific implementations where
appropriate. But when arch-specific overrides aren't needed or haven't
been implemented yet for a particular architecture, these stubs reduce
the amount of clutter under arch/.

No functional change.

Signed-off-by: Michael Kelley <[email protected]>
---
arch/x86/hyperv/hv_init.c | 2 --
arch/x86/kernel/cpu/mshyperv.c | 6 ------
drivers/hv/hv_common.c | 49 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index 5cc0c0f..e87a029 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -468,7 +468,6 @@ void hyperv_cleanup(void)
hypercall_msr.as_uint64 = 0;
wrmsrl(HV_X64_MSR_REFERENCE_TSC, hypercall_msr.as_uint64);
}
-EXPORT_SYMBOL_GPL(hyperv_cleanup);

void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die)
{
@@ -542,4 +541,3 @@ bool hv_is_isolation_supported(void)
{
return hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE;
}
-EXPORT_SYMBOL_GPL(hv_is_isolation_supported);
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 9bcf417..3e5a3f5 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -58,14 +58,12 @@ void hv_setup_vmbus_handler(void (*handler)(void))
{
vmbus_handler = handler;
}
-EXPORT_SYMBOL_GPL(hv_setup_vmbus_handler);

void hv_remove_vmbus_handler(void)
{
/* We have no way to deallocate the interrupt gate */
vmbus_handler = NULL;
}
-EXPORT_SYMBOL_GPL(hv_remove_vmbus_handler);

/*
* Routines to do per-architecture handling of stimer0
@@ -100,25 +98,21 @@ void hv_setup_kexec_handler(void (*handler)(void))
{
hv_kexec_handler = handler;
}
-EXPORT_SYMBOL_GPL(hv_setup_kexec_handler);

void hv_remove_kexec_handler(void)
{
hv_kexec_handler = NULL;
}
-EXPORT_SYMBOL_GPL(hv_remove_kexec_handler);

void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs))
{
hv_crash_handler = handler;
}
-EXPORT_SYMBOL_GPL(hv_setup_crash_handler);

void hv_remove_crash_handler(void)
{
hv_crash_handler = NULL;
}
-EXPORT_SYMBOL_GPL(hv_remove_crash_handler);

#ifdef CONFIG_KEXEC_CORE
static void hv_machine_shutdown(void)
diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index 9305850..c429306 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -16,6 +16,7 @@
#include <linux/export.h>
#include <linux/bitfield.h>
#include <linux/cpumask.h>
+#include <linux/ptrace.h>
#include <linux/slab.h>
#include <asm/hyperv-tlfs.h>
#include <asm/mshyperv.h>
@@ -195,3 +196,51 @@ bool hv_query_ext_cap(u64 cap_query)
return hv_extended_cap & cap_query;
}
EXPORT_SYMBOL_GPL(hv_query_ext_cap);
+
+/* These __weak functions provide default "no-op" behavior and
+ * may be overridden by architecture specific versions. Architectures
+ * for which the default "no-op" behavior is sufficient can leave
+ * them unimplemented and not be cluttered with a bunch of stub
+ * functions in arch-specific code.
+ */
+
+bool __weak hv_is_isolation_supported(void)
+{
+ return false;
+}
+EXPORT_SYMBOL_GPL(hv_is_isolation_supported);
+
+void __weak hv_setup_vmbus_handler(void (*handler)(void))
+{
+}
+EXPORT_SYMBOL_GPL(hv_setup_vmbus_handler);
+
+void __weak hv_remove_vmbus_handler(void)
+{
+}
+EXPORT_SYMBOL_GPL(hv_remove_vmbus_handler);
+
+void __weak hv_setup_kexec_handler(void (*handler)(void))
+{
+}
+EXPORT_SYMBOL_GPL(hv_setup_kexec_handler);
+
+void __weak hv_remove_kexec_handler(void)
+{
+}
+EXPORT_SYMBOL_GPL(hv_remove_kexec_handler);
+
+void __weak hv_setup_crash_handler(void (*handler)(struct pt_regs *regs))
+{
+}
+EXPORT_SYMBOL_GPL(hv_setup_crash_handler);
+
+void __weak hv_remove_crash_handler(void)
+{
+}
+EXPORT_SYMBOL_GPL(hv_remove_crash_handler);
+
+void __weak hyperv_cleanup(void)
+{
+}
+EXPORT_SYMBOL_GPL(hyperv_cleanup);
--
1.8.3.1

2021-07-12 03:28:01

by Michael Kelley (LINUX)

[permalink] [raw]
Subject: [PATCH 3/3] Drivers: hv: Move Hyper-V misc functionality to arch-neutral code

The check for whether hibernation is possible, and the enabling of
Hyper-V panic notification during kexec, are both architecture neutral.
Move the code from under arch/x86 and into drivers/hv/hv_common.c where
it can also be used for ARM64.

No functional change.

Signed-off-by: Michael Kelley <[email protected]>
---
arch/x86/hyperv/hv_init.c | 8 +-------
arch/x86/kernel/cpu/mshyperv.c | 11 -----------
drivers/hv/hv_common.c | 18 ++++++++++++++++++
3 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index e87a029..6f247e7 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -7,10 +7,10 @@
* Author : K. Y. Srinivasan <[email protected]>
*/

-#include <linux/acpi.h>
#include <linux/efi.h>
#include <linux/types.h>
#include <linux/bitfield.h>
+#include <linux/io.h>
#include <asm/apic.h>
#include <asm/desc.h>
#include <asm/hypervisor.h>
@@ -523,12 +523,6 @@ bool hv_is_hyperv_initialized(void)
}
EXPORT_SYMBOL_GPL(hv_is_hyperv_initialized);

-bool hv_is_hibernation_supported(void)
-{
- return !hv_root_partition && acpi_sleep_state_supported(ACPI_STATE_S4);
-}
-EXPORT_SYMBOL_GPL(hv_is_hibernation_supported);
-
enum hv_isolation_type hv_get_isolation_type(void)
{
if (!(ms_hyperv.priv_high & HV_ISOLATION))
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 3e5a3f5..ec428e2 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -17,7 +17,6 @@
#include <linux/irq.h>
#include <linux/kexec.h>
#include <linux/i8253.h>
-#include <linux/panic_notifier.h>
#include <linux/random.h>
#include <asm/processor.h>
#include <asm/hypervisor.h>
@@ -322,16 +321,6 @@ static void __init ms_hyperv_init_platform(void)
ms_hyperv.nested_features);
}

- /*
- * Hyper-V expects to get crash register data or kmsg when
- * crash enlightment is available and system crashes. Set
- * crash_kexec_post_notifiers to be true to make sure that
- * calling crash enlightment interface before running kdump
- * kernel.
- */
- if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE)
- crash_kexec_post_notifiers = true;
-
#ifdef CONFIG_X86_LOCAL_APIC
if (ms_hyperv.features & HV_ACCESS_FREQUENCY_MSRS &&
ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) {
diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index c429306..3ff8446 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -13,9 +13,11 @@
*/

#include <linux/types.h>
+#include <linux/acpi.h>
#include <linux/export.h>
#include <linux/bitfield.h>
#include <linux/cpumask.h>
+#include <linux/panic_notifier.h>
#include <linux/ptrace.h>
#include <linux/slab.h>
#include <asm/hyperv-tlfs.h>
@@ -64,6 +66,16 @@ int __init hv_common_init(void)
int i;

/*
+ * Hyper-V expects to get crash register data or kmsg when
+ * crash enlightment is available and system crashes. Set
+ * crash_kexec_post_notifiers to be true to make sure that
+ * calling crash enlightment interface before running kdump
+ * kernel.
+ */
+ if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE)
+ crash_kexec_post_notifiers = true;
+
+ /*
* Allocate the per-CPU state for the hypercall input arg.
* If this allocation fails, we will not be able to setup
* (per-CPU) hypercall input page and thus this failure is
@@ -197,6 +209,12 @@ bool hv_query_ext_cap(u64 cap_query)
}
EXPORT_SYMBOL_GPL(hv_query_ext_cap);

+bool hv_is_hibernation_supported(void)
+{
+ return !hv_root_partition && acpi_sleep_state_supported(ACPI_STATE_S4);
+}
+EXPORT_SYMBOL_GPL(hv_is_hibernation_supported);
+
/* These __weak functions provide default "no-op" behavior and
* may be overridden by architecture specific versions. Architectures
* for which the default "no-op" behavior is sufficient can leave
--
1.8.3.1

2021-07-14 09:39:48

by Wei Liu

[permalink] [raw]
Subject: Re: [PATCH 0/3] Additional refactoring of Hyper-V arch specific code

On Sun, Jul 11, 2021 at 08:25:13PM -0700, Michael Kelley wrote:
> This patch set moves additional Hyper-V code under arch/x86 into
> arch-neutral hv_common.c where it can be shared by x86 and
> and ARM64 implementations. The move reduces the overall lines
> of code across both architectures, and removes code under
> arch/ that isn't really architecture-specific.
>
> The code is moved into hv_common.c because it must be
> built-in to the kernel image, and not be part of a module.
>
> No functional changes are intended.
> Michael Kelley (3):
> Drivers: hv: Make portions of Hyper-V init code be arch neutral
> Drivers: hv: Add arch independent default functions for some Hyper-V
> handlers
> Drivers: hv: Move Hyper-V misc functionality to arch-neutral code
>
> arch/x86/hyperv/hv_init.c | 101 +++-----------------
> arch/x86/include/asm/mshyperv.h | 4 -
> arch/x86/kernel/cpu/mshyperv.c | 24 -----
> drivers/hv/hv_common.c | 198 ++++++++++++++++++++++++++++++++++++++++
> include/asm-generic/mshyperv.h | 10 ++
> 5 files changed, 219 insertions(+), 118 deletions(-)
>

Applied to hyperv-next. Thanks.

> --
> 1.8.3.1
>