@@ -1 +1,2 @@
+obj-y += hypercall_page.o
obj-y += hyperv.o
new file mode 100644
@@ -0,0 +1,21 @@
+#include <asm/asm_defns.h>
+#include <asm/page.h>
+
+ .section ".text.page_aligned", "ax", @progbits
+ .p2align PAGE_SHIFT
+GLOBAL(hv_hypercall_page)
+ /* Return -1 for "not yet ready" state */
+ mov -1, %rax
+ ret
+1:
+ /* Fill the rest with `ret` */
+ .fill PAGE_SIZE - (1b - hv_hypercall_page), 1, 0xc3
+ .type hv_hypercall_page, STT_OBJECT
+ .size hv_hypercall_page, PAGE_SIZE
+
+/*
+ * Local variables:
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ */
@@ -19,16 +19,16 @@
* Copyright (c) 2019 Microsoft.
*/
#include <xen/init.h>
+#include <xen/domain_page.h>
#include <asm/guest.h>
#include <asm/guest/hyperv-tlfs.h>
struct ms_hyperv_info __read_mostly ms_hyperv;
-static const struct hypervisor_ops ops = {
- .name = "Hyper-V",
-};
+extern char hv_hypercall_page[];
+static const struct hypervisor_ops ops;
const struct hypervisor_ops *__init hyperv_probe(void)
{
uint32_t eax, ebx, ecx, edx;
@@ -72,6 +72,27 @@ const struct hypervisor_ops *__init hyperv_probe(void)
return &ops;
}
+static void __init setup_hypercall_page(void)
+{
+ union hv_x64_msr_hypercall_contents hypercall_msr;
+
+ rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+ hypercall_msr.enable = 1;
+ hypercall_msr.guest_physical_address =
+ __pa(hv_hypercall_page) >> HV_HYP_PAGE_SHIFT;
+ wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+}
+
+static void __init setup(void)
+{
+ setup_hypercall_page();
+}
+
+static const struct hypervisor_ops ops = {
+ .name = "Hyper-V",
+ .setup = setup,
+};
+
/*
* Local variables:
* mode: C
Signed-off-by: Wei Liu <liuwe@microsoft.com> --- v2: 1. Fix issue discovered by Michael 2. Use a statically allocated page as hypercall page --- xen/arch/x86/guest/hyperv/Makefile | 1 + xen/arch/x86/guest/hyperv/hypercall_page.S | 21 +++++++++++++++++ xen/arch/x86/guest/hyperv/hyperv.c | 27 +++++++++++++++++++--- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 xen/arch/x86/guest/hyperv/hypercall_page.S