x86/hyperv: use dynamically allocated page for hypercalls
PATCH v3 1/1 x86/hyperv: use dynamically allocated page for hypercalls
Previously Xen placed the hypercall page at the highest possible MFN, but this caused problems on systems where there is more than 36 bits of physical address space.
In general, it also seems unreliable to assume that the highest possible MFN is not already reserved for some other purpose.
---
Changes from v2:
- Style fixes
- Change hypercall page notice to print the MFN instead, and use dprintk
Changes from v1:
- Continue to use fixmap infrastructure
- Use panic in Hyper-V setup() function instead of returning -ENOMEM on hypercall page allocation failure
xen/arch/x86/guest/hyperv/hyperv.c | 19 +++++++++---------- xen/arch/x86/include/asm/guest/hyperv.h | 3 --- 2 files changed, 9 insertions(+), 13 deletions(-)
xen/arch/x86/guest/hyperv/hyperv.c +9 -10
@@ -98,10 +98,18 @@ static void __init setup_hypercall_page(void)rdmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64);if ( !hypercall_msr.enable ) { - mfn =HV_HCALL_MFN ; +void *hcall_page =alloc_xenheap_page (); + +if ( !hcall_page ) +panic ("Hyper-V: Failed to allocate hypercall trampoline page\n" ); + + mfn =virt_to_mfn (hcall_page); hypercall_msr.enable =1 ; hypercall_msr.guest_physical_address = mfn;wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); + +dprintk (XENLOG_INFO , +"Hyper-V: Allocated hypercall page at MFN %lx\n" , mfn); }else mfn = hypercall_msr.guest_physical_address;
@@ -187,14 +195,6 @@ static int cf_check ap_setup(void)return setup_vp_assist (); } -static void __init cf_check e820_fixup(void) -{ -uint64_t s =HV_HCALL_MFN <<PAGE_SHIFT ; - -if ( !e820_add_range (s, s +PAGE_SIZE ,E820_RESERVED ) ) -panic ("Unable to reserve Hyper-V hypercall range\n" ); -} - static int cf_check flush_tlb(const cpumask_t *mask,const void *va,unsigned int flags) {
@@ -211,7 +211,6 @@ static const struct hypervisor_ops __initconst_cf_clobber ops = { .name = "Hyper-V", .setup = setup, .ap_setup = ap_setup, - .e820_fixup = e820_fixup, .flush_tlb = flush_tlb, };
xen/arch/x86/include/asm/guest/hyperv.h +0 -3
@@ -10,9 +10,6 @@#include <xen/types.h> -/* Use top-most MFN for hypercall page */ -#define HV_HCALL_MFN (((1ull << paddr_bits) - 1) >> HV_HYP_PAGE_SHIFT) -/* * The specification says: "The partition reference time is computed * by the following formula:
Signature · 1 line
2.39.5 (Apple Git-154)
Quoted 11 lines · Ariadne Conill
Previously Xen placed the hypercall page at the highest possible MFN, but this caused problems on systems where there is more than 36 bits of physical address space.
In general, it also seems unreliable to assume that the highest possible MFN is not already reserved for some other purpose.
Fixes 620fc734f854 ("x86/hyperv: setup hypercall page")Cc Alejandro Vallejo <[email protected]>Cc Alexander M. Merritt <[email protected]>Signed-off-by Ariadne Conill <[email protected]>
Thanks,
Jason
Quoted 3 lines · Ariadne Conill
Previously Xen placed the hypercall page at the highest possible MFN, but this caused problems on systems where there is more than 36 bits of physical address space.
Hmm, I should have asked already on the earlier version: What kinds of problems are these, beyond ...
Quoted 2 lines
In general, it also seems unreliable to assume that the highest possible MFN is not already reserved for some other purpose.
... this particular aspect? I find it puzzling that such problems would depend on the number of physical address bits.
Jan
Quoted 8 lines · Jan Beulich
Quoted 3 lines · Ariadne Conill
Previously Xen placed the hypercall page at the highest possible MFN, but this caused problems on systems where there is more than 36 bits of physical address space.
Hmm, I should have asked already on the earlier version: What kinds of problems are these, beyond ...
Quoted 7 lines
Quoted 2 lines
In general, it also seems unreliable to assume that the highest possible MFN is not already reserved for some other purpose.
... this particular aspect? I find it puzzling that such problems would depend on the number of physical address bits.
Jan
Pagefault on access (due to reserved bits being set) on access to the hypercall page. The available guest-physical address space doesn't seem to be as wide as advertised, though I didn't carry enough tests to single this as the only explanation. Seeing how we don't really know what's already on the last mfn this seems like a strict improvement irrespective of the actual cause of the fault.
Cheers,
Alejandro
Quoted 15 lines · Alejandro Vallejo
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Ariadne Conill
Previously Xen placed the hypercall page at the highest possible MFN, but this caused problems on systems where there is more than 36 bits of physical address space.
Quoted 8 lines
Hmm, I should have asked already on the earlier version: What kinds of problems are these, beyond ...
Quoted 2 lines
In general, it also seems unreliable to assume that the highest possible MFN is not already reserved for some other purpose.
... this particular aspect? I find it puzzling that such problems would depend on the number of physical address bits.
Quoted 6 lines
Pagefault on access (due to reserved bits being set) on access to the hypercall page. The available guest-physical address space doesn't seem to be as wide as advertised, though I didn't carry enough tests to single this as the only explanation. Seeing how we don't really know what's already on the last mfn this seems like a strict improvement irrespective of the actual cause of the fault.
No question there, yet the first paragraph is a little too vague for my taste. It'll also not help people later finding this commit and wondering what the issue was.
Jan
Quoted 11 lines · Ariadne Conill
Previously Xen placed the hypercall page at the highest possible MFN, but this caused problems on systems where there is more than 36 bits of physical address space.
In general, it also seems unreliable to assume that the highest possible MFN is not already reserved for some other purpose.
Fixes 620fc734f854 ("x86/hyperv: setup hypercall page")Cc Alejandro Vallejo <[email protected]>Cc Alexander M. Merritt <[email protected]>Signed-off-by Ariadne Conill <[email protected]>
I'm happy with the patch as-is, and I'm equally happy...
xen/arch/x86/guest/hyperv/hyperv.c static void __init setup_hypercall_page(void) · line 104
Quoted 13 lines
xen/arch/x86/guest/hyperv/hyperv.c +4
-1@@ -98,10 +98,18 @@ static void __init setup_hypercall_page(void)rdmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64);if ( !hypercall_msr.enable ) { - mfn =HV_HCALL_MFN ; +void *hcall_page =alloc_xenheap_page (); + +if ( !hcall_page ) +panic ("Hyper-V: Failed to allocate hypercall trampoline page\n" );
... with Roger's suggestion to probe <4G first with MEMF(32) here.
xen/arch/x86/guest/hyperv/hyperv.c static void __init setup_hypercall_page(void) · line 112
Quoted 8 lines
xen/arch/x86/guest/hyperv/hyperv.c +5
-0+ + mfn =virt_to_mfn (hcall_page); hypercall_msr.enable =1 ; hypercall_msr.guest_physical_address = mfn;wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); + +dprintk (XENLOG_INFO , +"Hyper-V: Allocated hypercall page at MFN %lx\n" , mfn);
nit: This is a personal preference thing, but I find %lx is very unhelpful when the variable is something like 0x123, as 123 might be misinterpreted to be in decimal. An mfn is not nearly as problematic as an error code, but %#lx avoids the ambiguity altogether.
Cheers,
Alejandro