From: kys@exchange.microsoft.com
To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com,
vkuznets@redhat.com, jasowang@redhat.com,
leann.ogasawara@canonical.com, rkagan@virtuozzo.com,
x86@kernel.org, tglx@linutronix.de, hpa@zytor.com
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Subject: [PATCH 03/18] Drivers: hv vmbus: Move Hypercall page setup out of common code
Date: Fri, 30 Dec 2016 13:35:57 -0800 [thread overview]
Message-ID: <1483133772-29776-3-git-send-email-kys@exchange.microsoft.com> (raw)
In-Reply-To: <1483133772-29776-1-git-send-email-kys@exchange.microsoft.com>
From: K. Y. Srinivasan <kys@microsoft.com>
As part of the effort to separate out architecture specific code, move the
hypercall page setup to an architecture specific file.
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
---
arch/x86/Kbuild | 3 ++
arch/x86/hyperv/Makefile | 1 +
arch/x86/hyperv/hv_init.c | 62 +++++++++++++++++++++++++++++++++++++++
arch/x86/include/asm/mshyperv.h | 5 +++
arch/x86/kernel/cpu/mshyperv.c | 7 ++++
drivers/hv/hv.c | 45 ++--------------------------
6 files changed, 81 insertions(+), 42 deletions(-)
create mode 100644 arch/x86/hyperv/Makefile
create mode 100644 arch/x86/hyperv/hv_init.c
diff --git a/arch/x86/Kbuild b/arch/x86/Kbuild
index eb3abf8..586b786 100644
--- a/arch/x86/Kbuild
+++ b/arch/x86/Kbuild
@@ -7,6 +7,9 @@ obj-$(CONFIG_KVM) += kvm/
# Xen paravirtualization support
obj-$(CONFIG_XEN) += xen/
+# Hyper-V paravirtualization support
+obj-$(CONFIG_HYPERVISOR_GUEST) += hyperv/
+
# lguest paravirtualization support
obj-$(CONFIG_LGUEST_GUEST) += lguest/
diff --git a/arch/x86/hyperv/Makefile b/arch/x86/hyperv/Makefile
new file mode 100644
index 0000000..171ae09
--- /dev/null
+++ b/arch/x86/hyperv/Makefile
@@ -0,0 +1 @@
+obj-y := hv_init.o
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
new file mode 100644
index 0000000..3206bfda
--- /dev/null
+++ b/arch/x86/hyperv/hv_init.c
@@ -0,0 +1,62 @@
+/*
+ * X86 specific Hyper-V initialization code.
+ *
+ * Copyright (C) 2016, Microsoft, Inc.
+ *
+ * Author : K. Y. Srinivasan <kys@microsoft.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT. See the GNU General Public License for more
+ * details.
+ *
+ */
+
+#include <linux/types.h>
+#include <asm/hypervisor.h>
+#include <asm/hyperv.h>
+#include <asm/mshyperv.h>
+#include <linux/version.h>
+#include <linux/vmalloc.h>
+#include <linux/mm.h>
+
+void *hv_hypercall_pg;
+/*
+ * This function is to be invoked early in the boot sequence after the
+ * hypervisor has been detected.
+ *
+ * 1. Setup the hypercall page.
+ */
+void hyperv_init(void)
+{
+ u64 guest_id;
+ union hv_x64_msr_hypercall_contents hypercall_msr;
+
+ if (x86_hyper != &x86_hyper_ms_hyperv)
+ return;
+
+ /*
+ * Setup the hypercall page and enable hypercalls.
+ * 1. Register the guest ID
+ * 2. Enable the hypercall and register the hypercall page
+ */
+ guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0);
+ wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id);
+
+ hv_hypercall_pg = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
+ if (hv_hypercall_pg == NULL) {
+ wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
+ return;
+ }
+
+ rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+ hypercall_msr.enable = 1;
+ hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg);
+ wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+}
+EXPORT_SYMBOL_GPL(hv_hypercall_pg);
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 15a0c27..e5f57e1 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -80,4 +80,9 @@ static inline __u64 generate_guest_id(__u64 d_info1, __u64 kernel_version,
void hv_remove_kexec_handler(void);
void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs));
void hv_remove_crash_handler(void);
+
+#if IS_ENABLED(CONFIG_HYPERV)
+void hyperv_init(void);
+extern void *hv_hypercall_pg;
+#endif
#endif
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 8f44c5a..8b376f8 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -204,6 +204,13 @@ static void __init ms_hyperv_init_platform(void)
*/
if (efi_enabled(EFI_BOOT))
x86_platform.get_nmi_reason = hv_get_nmi_reason;
+
+#if IS_ENABLED(CONFIG_HYPERV)
+ /*
+ * Setup the hook to get control post apic initialization.
+ */
+ x86_platform.apic_post_init = hyperv_init;
+#endif
}
const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index 04a0fd8..a11e827 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -193,7 +193,6 @@ int hv_init(void)
{
int max_leaf;
union hv_x64_msr_hypercall_contents hypercall_msr;
- void *virtaddr = NULL;
memset(hv_context.synic_event_page, 0, sizeof(void *) * NR_CPUS);
memset(hv_context.synic_message_page, 0,
@@ -211,33 +210,15 @@ int hv_init(void)
max_leaf = query_hypervisor_info();
- /*
- * Write our OS ID.
- */
- 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 = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
-
- if (!virtaddr)
- goto cleanup;
-
- hypercall_msr.enable = 1;
-
- hypercall_msr.guest_physical_address = vmalloc_to_pfn(virtaddr);
- wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
-
- /* 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)
- goto cleanup;
+ return -ENOTSUPP;
- hv_context.hypercall_page = virtaddr;
+ hv_context.hypercall_page = hv_hypercall_pg;
#ifdef CONFIG_X86_64
if (ms_hyperv.features & HV_X64_MSR_REFERENCE_TSC_AVAILABLE) {
@@ -261,15 +242,6 @@ int hv_init(void)
return 0;
cleanup:
- if (virtaddr) {
- if (hypercall_msr.enable) {
- hypercall_msr.as_uint64 = 0;
- wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
- }
-
- vfree(virtaddr);
- }
-
return -ENOTSUPP;
}
@@ -280,20 +252,9 @@ int hv_init(void)
*/
void hv_cleanup(bool crash)
{
- union hv_x64_msr_hypercall_contents hypercall_msr;
-
- /* Reset our OS id */
- wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
-
- if (hv_context.hypercall_page) {
- hypercall_msr.as_uint64 = 0;
- wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
- if (!crash)
- vfree(hv_context.hypercall_page);
- hv_context.hypercall_page = NULL;
- }
#ifdef CONFIG_X86_64
+ union hv_x64_msr_hypercall_contents hypercall_msr;
/*
* Cleanup the TSC page based CS.
*/
--
1.7.4.1
next prev parent reply other threads:[~2016-12-30 19:40 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-30 21:35 [PATCH 00/18] Drivers: hv: vmbus: Restructure architecture specific code kys
2016-12-30 21:35 ` [PATCH 01/18] Drivers: hv: vmbus: Move the definition of hv_x64_msr_hypercall_contents kys
2016-12-30 21:35 ` [PATCH 02/18] Drivers: hv: vmbus: Move the definition of generate_guest_id() kys
2016-12-30 21:35 ` kys [this message]
2016-12-30 21:35 ` [PATCH 04/18] Drivers: hv: vmbus: Move Hypercall invocation code out of common code kys
2016-12-30 21:35 ` [PATCH 05/18] Drivers: hv: vmbus: Consolidate all Hyper-V specific clocksource code kys
2016-12-30 21:36 ` [PATCH 06/18] Drivers: hv: vmbus: Move the extracting of Hypervisor version information kys
2016-12-30 21:36 ` [PATCH 07/18] Drivers: hv: vmbus: Move the crash notification function kys
2016-12-30 21:36 ` [PATCH 08/18] Drivers: hv: vmbus: Move the check for hypercall page setup kys
2016-12-30 21:36 ` [PATCH 09/18] Drivers: hv: vmbus: Move the code to signal end of message kys
2016-12-30 21:36 ` [PATCH 10/18] Drivers: hv: vmbus: Restructure the clockevents code kys
2016-12-30 21:36 ` [PATCH 11/18] Drivers: hv: util: Use hv_get_current_tick() to get current tick kys
2016-12-30 21:36 ` [PATCH 12/18] Drivers: hv: vmbus: Get rid of an unsused variable kys
2016-12-30 21:36 ` [PATCH 13/18] Drivers: hv: vmbus: Define APIs to manipulate the message page kys
2016-12-30 21:36 ` [PATCH 14/18] Drivers: hv: vmbus: Define APIs to manipulate the event page kys
2016-12-30 21:36 ` [PATCH 15/18] Drivers: hv: vmbus: Define APIs to manipulate the synthetic interrupt controller kys
2016-12-30 21:36 ` [PATCH 16/18] Drivers: hv: vmbus: Define an API to retrieve virtual processor index kys
2016-12-30 21:36 ` [PATCH 17/18] Drivers: hv: vmbus: Define an APIs to manage interrupt state kys
2016-12-30 21:36 ` [PATCH 18/18] Drivers: hv: vmbus: Cleanup hyperv_vmbus.h kys
2017-01-10 17:27 ` [PATCH 01/18] Drivers: hv: vmbus: Move the definition of hv_x64_msr_hypercall_contents Greg KH
2017-01-12 2:32 ` KY Srinivasan
2017-01-12 18:29 ` Stephen Hemminger
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=1483133772-29776-3-git-send-email-kys@exchange.microsoft.com \
--to=kys@exchange.microsoft.com \
--cc=apw@canonical.com \
--cc=devel@linuxdriverproject.org \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=jasowang@redhat.com \
--cc=kys@microsoft.com \
--cc=leann.ogasawara@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=olaf@aepfle.de \
--cc=rkagan@virtuozzo.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®