More Hyper-V infrastructures
PATCH v5 2/12 x86/hypervisor: make hypervisor_ap_setup return an error code
In reply to Wei LiuWe want to be able to handle AP setup error in the upper layer.
--- xen/arch/x86/guest/hypervisor.c | 6 ++++-- xen/arch/x86/guest/xen/xen.c | 11 +++++++++-- xen/include/asm-x86/guest/hypervisor.h | 6 +++--- 3 files changed, 16 insertions(+), 7 deletions(-)
xen/arch/x86/guest/hypervisor.c +4 -2
@@ -52,10 +52,12 @@ void __init hypervisor_setup(void) ops->setup (); } -void hypervisor_ap_setup (void ) +int hypervisor_ap_setup (void ) {if ( ops && ops->ap_setup ) - ops->ap_setup (); +return ops->ap_setup (); + +return 0 ; }void hypervisor_resume (void )
xen/arch/x86/guest/xen/xen.c +9 -2
@@ -257,11 +257,18 @@ static void __init setup(void)init_evtchn (); } -static void ap_setup (void ) +static int ap_setup (void ) { +int rc; +set_vcpu_id (); -map_vcpuinfo (); + rc =map_vcpuinfo (); +if ( rc ) +return rc; +init_evtchn (); + +return 0 ; }int xg_alloc_unused_page (mfn_t *mfn)
xen/include/asm-x86/guest/hypervisor.h +3 -3
@@ -25,7 +25,7 @@ struct hypervisor_ops {/* Main setup routine */ void (*setup)(void );/* AP setup */ -void (*ap_setup)(void ); +int (*ap_setup)(void );/* Resume from suspension */ void (*resume)(void ); };
@@ -34,7 +34,7 @@ struct hypervisor_ops {const char *hypervisor_probe (void );void hypervisor_setup (void ); -void hypervisor_ap_setup (void ); +int hypervisor_ap_setup (void );void hypervisor_resume (void );#else
@@ -44,7 +44,7 @@ void hypervisor_resume(void);static inline const char *hypervisor_probe (void ) {return NULL ; }static inline void hypervisor_setup (void ) {ASSERT_UNREACHABLE (); } -static inline void hypervisor_ap_setup (void ) {ASSERT_UNREACHABLE (); } +static inline int hypervisor_ap_setup (void ) {ASSERT_UNREACHABLE ();return 0 ; }static inline void hypervisor_resume (void ) {ASSERT_UNREACHABLE (); }#endif /* CONFIG_GUEST */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
v5 cover More Hyper-V infrastructures
This patch sereis implements several important functionalities to run Xen on top of Hyper-V.
See individual patches for more details. First few patches are generic x86 changes. The rest is Hyper-V specific.
I've checked the assembly code as well as putting in a test patch to make sure the hypercall interface is implemented correctly.
Wei.
Wei Liu (12):
MAINTAINERS: put Hyper-V code under Viridian maintainership x86/hypervisor: make hypervisor_ap_setup return an error code x86/smp: don't online cpu if hypervisor_ap_setup fails
x86: make paddr_bits available earlier
x86: provide executable fixmap facility x86/hypervisor: provide hypervisor_reserve_top_pages x86/hyperv: setup hypercall page
x86/hyperv: provide Hyper-V hypercall functions
DO NOT APPLY: x86/hyperv: issue an hypercall x86/hyperv: provide percpu hypercall input page x86/hyperv: retrieve vp_index from Hyper-V x86/hyperv: setup VP assist page
MAINTAINERS | 6 +- xen/arch/x86/boot/x86_64.S | 15 ++- xen/arch/x86/e820.c | 19 ++- xen/arch/x86/guest/hyperv/hyperv.c | 155 ++++++++++++++++++++++- xen/arch/x86/guest/hyperv/private.h | 31 +++++ xen/arch/x86/guest/hypervisor.c | 14 +- xen/arch/x86/guest/xen/xen.c | 11 +- xen/arch/x86/livepatch.c | 3 +- xen/arch/x86/mm.c | 15 ++- xen/arch/x86/setup.c | 5 +- xen/arch/x86/smpboot.c | 12 +- xen/arch/x86/xen.lds.S | 7 + xen/include/asm-x86/config.h | 2 +- xen/include/asm-x86/fixmap.h | 24 ++++ xen/include/asm-x86/guest/hyperv-hcall.h | 96 ++++++++++++++ xen/include/asm-x86/guest/hyperv-tlfs.h | 5 +- xen/include/asm-x86/guest/hyperv.h | 3 + xen/include/asm-x86/guest/hypervisor.h | 10 +- 18 files changed, 398 insertions(+), 35 deletions(-) create mode 100644 xen/arch/x86/guest/hyperv/private.h create mode 100644 xen/include/asm-x86/guest/hyperv-hcall.h
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 1/12 MAINTAINERS: put Hyper-V code under Viridian maintainership
And add myself as a maintainer.
Sort the list alphabetically while at it.
--- MAINTAINERS | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
MAINTAINERS +4 -1
@@ -514,10 +514,13 @@ F: xen/arch/x86/mm/shadow/ X86 VIRIDIAN ENLIGHTENMENTS M: Paul Durrant <[email protected]> +M: Wei Liu <[email protected]> S: Supported +F: xen/arch/x86/guest/hyperv/ F: xen/arch/x86/hvm/viridian/ -F: xen/include/asm-x86/hvm/viridian.h +F: xen/include/asm-x86/guest/hyperv.h F: xen/include/asm-x86/guest/hyperv-tlfs.h +F: xen/include/asm-x86/hvm/viridian.h XENTRACE M: George Dunlap <[email protected]>
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 3/12 x86/smp: don't online cpu if hypervisor_ap_setup fails
In reply to Wei LiuPush hypervisor_ap_setup down to smp_callin.
Take the chance to replace xen_guest with cpu_has_hypervisor.
--- xen/arch/x86/smpboot.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
xen/arch/x86/smpboot.c +7 -3
@@ -199,6 +199,13 @@ static void smp_callin(void) goto halt; } +if ( cpu_has_hypervisor && (rc =hypervisor_ap_setup ()) !=0 ) + { +printk ("CPU%d: Failed to initialise hypervisor functions. Not coming online.\n" , cpu); + cpu_error = rc; + goto halt; + } +if ( (rc =hvm_cpu_up ()) !=0 ) {printk ("CPU%d: Failed to initialise HVM. Not coming online.\n" , cpu);
@@ -371,9 +378,6 @@ void start_secondary(void *unused)tsx_init ();/* Needs microcode. May change HLE/RTM feature bits. */ -if ( xen_guest ) -hypervisor_ap_setup (); -smp_callin ();set_cpu_sibling_map (cpu);
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 4/12 x86: make paddr_bits available earlier
In reply to Wei LiuMove early_cpu_init before init_e820, such that paddr_bits can be used by e820 code.
This will reduce code repetition and prepare for further adjustment when L0 hypervisor comes into play.
--- xen/arch/x86/e820.c | 14 ++++---------- xen/arch/x86/setup.c | 5 +++-- 2 files changed, 7 insertions(+), 12 deletions(-)
xen/arch/x86/e820.c +4 -10
@@ -420,7 +420,7 @@ static uint64_t __init mtrr_top_of_ram(void) {uint32_t eax, ebx, ecx, edx;uint64_t mtrr_cap, mtrr_def, addr_mask, base, mask, top; -unsigned int i, phys_bits =36 ; +unsigned int i;/* By default we check only Intel systems. */ if ( e820_mtrr_clip ==-1 )
@@ -445,15 +445,9 @@ static uint64_t __init mtrr_top_of_ram(void)if ( !test_bit (X86_FEATURE_MTRR &31 , &edx) )return 0 ; -/* Find the physical address size for this CPU. */ - eax =cpuid_eax (0x80000000 ); -if ( (eax >>16 ) ==0x8000 && eax >=0x80000008 ) - { - phys_bits = (uint8_t )cpuid_eax (0x80000008 ); -if ( phys_bits >PADDR_BITS ) - phys_bits =PADDR_BITS ; - } - addr_mask = ((1ull << phys_bits) -1 ) & ~((1ull <<12 ) -1 ); +/* paddr_bits must have been set at this point */ +ASSERT (paddr_bits); + addr_mask = ((1ull << paddr_bits) -1 ) &PAGE_MASK ;rdmsrl (MSR_MTRRcap, mtrr_cap);rdmsrl (MSR_MTRRdefType, mtrr_def);
xen/arch/x86/setup.c +3 -2
@@ -954,6 +954,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)else panic ("Bootloader provided no memory information\n" ); +/* This must come before e820 code becuause it sets paddr_bits. */ +early_cpu_init (); +/* Sanitise the raw E820 map to produce a final clean version. */ max_page = raw_max_page =init_e820 (memmap_type, &e820_raw);
@@ -1532,8 +1535,6 @@ void __init noreturn __start_xen(unsigned long mbi_p)softirq_init ();tasklet_subsys_init (); -early_cpu_init (); -paging_init ();tboot_probe ();
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 5/12 x86: provide executable fixmap facility
In reply to Wei LiuThis allows us to set aside some address space for executable mapping. This fixed map range starts from XEN_VIRT_END so that it is within reach of the .text section.
Shift the percpu stub range and shrink livepatch range accordingly.
---
v5:
1. drop __virt_to_fix_x
2. also check FIX*_RESERVED in __set_fixmap*
3. generate global symbol to be used in linker script
4. address other misc comments
--- xen/arch/x86/boot/x86_64.S | 15 ++++++++++++--- xen/arch/x86/livepatch.c | 3 ++- xen/arch/x86/mm.c | 15 ++++++++++++++- xen/arch/x86/smpboot.c | 2 +- xen/arch/x86/xen.lds.S | 3 +++ xen/include/asm-x86/config.h | 2 +- xen/include/asm-x86/fixmap.h | 25 +++++++++++++++++++++++++ 7 files changed, 58 insertions(+), 7 deletions(-)
xen/arch/x86/boot/x86_64.S +12 -3
@@ -81,11 +81,20 @@ GLOBAL(l2_directmap) .size l2_directmap, . - l2_directmap /* - * L2 mapping the Xen text/data/bss region, constructed dynamically. Uses 1x - * 4k page. + * L2 mapping the Xen text/data/bss region, constructed dynamically. + * Executable fixmap is hooked up statically. + * Uses 1x 4k page. */ GLOBAL(l2_xenmap) - .fill L2_PAGETABLE_ENTRIES, 8, 0 + idx = 0 + .rept L2_PAGETABLE_ENTRIES + .if idx == l2_table_offset(FIXADDR_X_TOP - 1) + .quad sym_offs(l1_fixmap_x) + __PAGE_HYPERVISOR + .else + .quad 0 + .endif + idx = idx + 1 + .endr .size l2_xenmap, . - l2_xenmap /* L2 mapping the fixmap. Uses 1x 4k page. */
xen/arch/x86/livepatch.c +2 -1
@@ -12,6 +12,7 @@#include <xen/livepatch.h> #include <xen/sched.h> +#include <asm/fixmap.h> #include <asm/nmi.h> #include <asm/livepatch.h>
@@ -311,7 +312,7 @@ void __init arch_livepatch_init(void)void *start, *end; start = (void *)xen_virt_end; - end = (void *)(XEN_VIRT_END -NR_CPUS *PAGE_SIZE ); + end = (void *)(XEN_VIRT_END -FIXADDR_X_SIZE -NR_CPUS *PAGE_SIZE );BUG_ON (end <= start);
xen/arch/x86/mm.c +14 -1
@@ -157,6 +157,8 @@/* Mapping of the fixmap space needed early. */ l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) l1_fixmap[L1_PAGETABLE_ENTRIES ]; +l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) + l1_fixmap_x[L1_PAGETABLE_ENTRIES ];paddr_t __read_mostly mem_hotplug;
@@ -5718,10 +5720,21 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)void __set_fixmap (enum fixed_addresses idx,unsigned long mfn,unsigned long flags) { -BUG_ON (idx >= __end_of_fixed_addresses); +BUG_ON (idx >= __end_of_fixed_addresses || idx <=FIX_RESERVED );map_pages_to_xen (__fix_to_virt (idx),_mfn (mfn),1 , flags); } +void __set_fixmap_x ( +enum fixed_addresses_x idx,unsigned long mfn,unsigned long flags) +{ +BUG_ON (idx >= __end_of_fixed_addresses_x || idx <=FIX_X_RESERVED ); +map_pages_to_xen (__fix_x_to_virt (idx),_mfn (mfn),1 , flags); + +/* Generate a symbol to be used in linker script */ + asm (".equ FIXADDR_X_SIZE, %c0; .global FIXADDR_X_SIZE" + ::"i" (__end_of_fixed_addresses_x <<PAGE_SHIFT ) ); +} +void *__init arch_vmap_virt_end (void ) {return fix_to_virt (__end_of_fixed_addresses);
xen/arch/x86/smpboot.c +1 -1
@@ -644,7 +644,7 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn)unmap_domain_page (memset (__map_domain_page (pg),0xcc ,PAGE_SIZE )); } - stub_va =XEN_VIRT_END - (cpu +1 ) *PAGE_SIZE ; + stub_va =XEN_VIRT_END -FIXADDR_X_SIZE - (cpu +1 ) *PAGE_SIZE ;if (map_pages_to_xen (stub_va,page_to_mfn (pg),1 ,PAGE_HYPERVISOR_RX |MAP_SMALL_PAGES ) ) {
xen/arch/x86/xen.lds.S +3 -0
@@ -3,6 +3,8 @@ #include <xen/cache.h> #include <xen/lib.h> + +#include <asm/fixmap.h> #include <asm/page.h> #undef ENTRY #undef ALIGN
@@ -353,6 +355,7 @@ SECTIONS } ASSERT(__2M_rwdata_end <= XEN_VIRT_END - XEN_VIRT_START + __XEN_VIRT_START - + FIXADDR_X_SIZE - DIV_ROUND_UP(NR_CPUS, STUBS_PER_PAGE) * PAGE_SIZE, "Xen image overlaps stubs area")
xen/include/asm-x86/config.h +1 -1
@@ -218,7 +218,7 @@ extern unsigned char boot_edid_info[128];/* Slot 261: high read-only compat machine-to-phys conversion table (1GB). */ #define HIRO_COMPAT_MPT_VIRT_START RDWR_COMPAT_MPT_VIRT_END#define HIRO_COMPAT_MPT_VIRT_END (HIRO_COMPAT_MPT_VIRT_START + GB(1)) -/* Slot 261: xen text, static data and bss (1GB). */ +/* Slot 261: xen text, static data, bss, per-cpu stubs and executable fixmap (1GB). */ #define XEN_VIRT_START (HIRO_COMPAT_MPT_VIRT_END)#define XEN_VIRT_END (XEN_VIRT_START + GB(1))
xen/include/asm-x86/fixmap.h +25 -0
@@ -15,6 +15,7 @@#include <asm/page.h> #define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE) +#define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE)#ifndef __ASSEMBLY__
@@ -89,6 +90,30 @@ static inline unsigned long virt_to_fix(const unsigned long vaddr)return __virt_to_fix (vaddr); } +enum fixed_addresses_x { +/* Index 0 is reserved since fix_x_to_virt(0) == FIXADDR_X_TOP. */ +FIX_X_RESERVED , +#ifdef CONFIG_HYPERV_GUEST +FIX_X_HYPERV_HCALL , +#endif + __end_of_fixed_addresses_x +}; + +#define FIXADDR_X_SIZE (__end_of_fixed_addresses_x << PAGE_SHIFT) +#define FIXADDR_X_START (FIXADDR_X_TOP - FIXADDR_X_SIZE) + +extern void __set_fixmap_x ( +enum fixed_addresses_x idx,unsigned long mfn,unsigned long flags); + +#define set_fixmap_x (idx, phys) \ + __set_fixmap_x(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR_RX | MAP_SMALL_PAGES) + +#define clear_fixmap_x (idx) __set_fixmap_x(idx, 0, 0) + +#define __fix_x_to_virt (x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT)) + +#define fix_x_to_virt (x) ((void *)__fix_x_to_virt(x)) +#endif /* __ASSEMBLY__ */ #endif
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 6/12 x86/hypervisor: provide hypervisor_reserve_top_pages
In reply to Wei LiuThis function will return the number of pages that need to be reserved in the machine address space.
E820 code will use that number to adjust the maximum PFN available to Xen.
--- xen/arch/x86/guest/hypervisor.c | 8 ++++++++ xen/include/asm-x86/guest/hypervisor.h | 4 ++++ 2 files changed, 12 insertions(+)
xen/arch/x86/guest/hypervisor.c +8 -0
@@ -66,6 +66,14 @@ void hypervisor_resume(void) ops->resume (); } +unsigned int hypervisor_reserve_top_pages (void ) +{ +if ( ops && ops->reserve_top_pages ) +return ops->reserve_top_pages (); + +return 0 ; +} +/* * Local variables: * mode: C
xen/include/asm-x86/guest/hypervisor.h +4 -0
@@ -28,6 +28,8 @@ struct hypervisor_ops {int (*ap_setup)(void );/* Resume from suspension */ void (*resume)(void ); +/* How many top pages to be reserved in machine address space? */ +unsigned int (*reserve_top_pages)(void ); };#ifdef CONFIG_GUEST
@@ -36,6 +38,7 @@ const char *hypervisor_probe(void);void hypervisor_setup (void );int hypervisor_ap_setup (void );void hypervisor_resume (void ); +unsigned int hypervisor_reserve_top_pages (void );#else
@@ -46,6 +49,7 @@ static inline const char *hypervisor_probe(void) { return NULL; }static inline void hypervisor_setup (void ) {ASSERT_UNREACHABLE (); }static inline int hypervisor_ap_setup (void ) {ASSERT_UNREACHABLE ();return 0 ; }static inline void hypervisor_resume (void ) {ASSERT_UNREACHABLE (); } +static inline unsigned int hypervisor_reserve_top_pages (void ) {return 0 ; }#endif /* CONFIG_GUEST */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 7/12 x86/hyperv: setup hypercall page
In reply to Wei LiuHyper-V uses a technique called overlay page for its hypercall page. It will insert a backing page to the guest when the hypercall functionality is enabled. That means we can use a page that is not backed by real memory for hypercall page.
Use the top-most addressable page for that purpose. Adjust e820 code accordingly.
We also need to register Xen's guest OS ID to Hyper-V. Use 0x3 as the vendor ID. Fix the comment in hyperv-tlfs.h while at it.
---
v5:
1. use hypervisor_reserve_top_pages
2. add a macro for hypercall page mfn
3. address other misc comments
v4:
1. Use fixmap
2. Follow routines listed in TLFS
--- xen/arch/x86/e820.c | 5 +++ xen/arch/x86/guest/hyperv/hyperv.c | 57 +++++++++++++++++++++++-- xen/include/asm-x86/guest/hyperv-tlfs.h | 5 ++- xen/include/asm-x86/guest/hyperv.h | 3 ++ 4 files changed, 65 insertions(+), 5 deletions(-)
xen/arch/x86/e820.c +5 -0
@@ -343,6 +343,7 @@ static unsigned long __init find_max_pfn(void) {unsigned int i;unsigned long max_pfn =0 ; +unsigned long top_pfn = ((1ull << paddr_bits) -1 ) >>PAGE_SHIFT ;for (i =0 ; i < e820.nr_map; i++) {unsigned long start, end;
@@ -357,6 +358,10 @@ static unsigned long __init find_max_pfn(void) max_pfn = end; } + top_pfn -=hypervisor_reserve_top_pages (); +if ( max_pfn >= top_pfn ) + max_pfn = top_pfn; +return max_pfn; }
xen/arch/x86/guest/hyperv/hyperv.c +54 -3
75 lines not on this page · raw message
xen/include/asm-x86/guest/hyperv-tlfs.h +3 -2
@@ -318,15 +318,16 @@ struct ms_hyperv_tsc_page {* * Bit(s) * 63 - Indicates if the OS is Open Source or not; 1 is Open Source -* 62:56 - Os Type; Linux is 0x100 +* 62:56 - Os Type; Linux 0x1, FreeBSD 0x2, Xen 0x3 * 55:48 - Distro specific identification -* 47:16 - Linux kernel version number +* 47:16 - Guest OS version number * 15:0 - Distro specific identification * * */ #define HV_LINUX_VENDOR_ID 0x8100 +#define HV_XEN_VENDOR_ID 0x8300union hv_guest_os_id {uint64_t raw;
xen/include/asm-x86/guest/hyperv.h +3 -0
@@ -21,6 +21,9 @@#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 · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 8/12 x86/hyperv: provide Hyper-V hypercall functions
In reply to Wei LiuThese functions will be used later to make hypercalls to Hyper-V.
---
v5:
1. Switch back to direct call
2. Fix some issues pointed out by Jan
I tried using the asm(".equ ..") trick but hit a problem with %c again.
mm.c:5736:5: error: invalid 'asm': operand is not a condition code, invalid operand code 'c'
asm ( ".equ HV_HCALL_PAGE, %c0; .global HV_HCALL_PAGE"
--- MAINTAINERS | 1 + xen/arch/x86/guest/hyperv/hyperv.c | 6 ++ xen/arch/x86/xen.lds.S | 4 + xen/include/asm-x86/fixmap.h | 3 +- xen/include/asm-x86/guest/hyperv-hcall.h | 96 ++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 xen/include/asm-x86/guest/hyperv-hcall.h
MAINTAINERS +1 -0
@@ -519,6 +519,7 @@ S: Supported F: xen/arch/x86/guest/hyperv/ F: xen/arch/x86/hvm/viridian/ F: xen/include/asm-x86/guest/hyperv.h +F: xen/include/asm-x86/guest/hyperv-hcall.h F: xen/include/asm-x86/guest/hyperv-tlfs.h F: xen/include/asm-x86/hvm/viridian.h
xen/arch/x86/guest/hyperv/hyperv.c +6 -0
@@ -123,6 +123,12 @@ static const struct hypervisor_ops ops = { .setup = setup, }; +static void __maybe_unused build_assertions (void ) +{ +/* We use 1 in linker script */ +BUILD_BUG_ON (FIX_X_HYPERV_HCALL !=1 ); +} +/* * Local variables: * mode: C
xen/arch/x86/xen.lds.S +4 -0
@@ -329,6 +329,10 @@ SECTIONS efi = .; #endif +#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1)); +#endif + /* Sections to be discarded */ /DISCARD/ : { *(.exit.text)
xen/include/asm-x86/fixmap.h +1 -2
@@ -16,6 +16,7 @@#define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE)#define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE) +#define __fix_x_to_virt (x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT))#ifndef __ASSEMBLY__
@@ -110,8 +111,6 @@ extern void __set_fixmap_x(#define clear_fixmap_x (idx) __set_fixmap_x(idx, 0, 0) -#define __fix_x_to_virt (x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT)) -#define fix_x_to_virt (x) ((void *)__fix_x_to_virt(x))#endif /* __ASSEMBLY__ */
xen/include/asm-x86/guest/hyperv-hcall.h new file +96 -0
96 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 9/12 DO NOT APPLY: x86/hyperv: issue an hypercall
In reply to Wei LiuTest if the infrastructure works.
--- xen/arch/x86/guest/hyperv/hyperv.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
xen/arch/x86/guest/hyperv/hyperv.c +14 -0
@@ -23,6 +23,7 @@#include <asm/fixmap.h> #include <asm/guest.h> +#include <asm/guest/hyperv-hcall.h> #include <asm/guest/hyperv-tlfs.h> #include <asm/processor.h>
@@ -111,6 +112,19 @@ static void __init setup_hypercall_page(void)BUG_ON (!hypercall_msr.enable);set_fixmap_x (FIX_X_HYPERV_HCALL , mfn <<PAGE_SHIFT ); + +/* XXX Wei: Issue an hypercall here to make sure things are set up +* correctly. When there is actual use of the hypercall facility, +* this can be removed. +*/ + { +uint16_t r =hv_do_hypercall (0xffff ,0 ,0 ); +BUG_ON (r !=HV_STATUS_INVALID_HYPERCALL_CODE ); + r =hv_do_fast_hypercall (0xffff ,0 ,0 ); +BUG_ON (r !=HV_STATUS_INVALID_HYPERCALL_CODE ); + +printk ("Successfully issued Hyper-V hypercalls\n" ); + } }static void __init setup (void )
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 10/12 x86/hyperv: provide percpu hypercall input page
In reply to Wei LiuHyper-V's input / output argument must be 8 bytes aligned an not cross page boundary. One way to satisfy those requirements is to use percpu page.
For the foreseeable future we only need to provide input for TLB and APIC hypercalls, so skip setting up an output page.
We will also need to provide an ap_setup hook for secondary cpus to setup its own input page.
---
v5:
1. Adjust to new ap_setup
2. Change variable name to hv_pcpu_input_page
v4:
1. Change wording in commit message
2. Prevent leak
3. Introduce a private header
v3:
1. Use xenheap page instead
2. Drop page tracking structure
3. Drop Paul's review tag
--- xen/arch/x86/guest/hyperv/hyperv.c | 31 +++++++++++++++++++++++++++++ xen/arch/x86/guest/hyperv/private.h | 29 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 xen/arch/x86/guest/hyperv/private.h
xen/arch/x86/guest/hyperv/hyperv.c +31 -0
@@ -27,7 +27,10 @@#include <asm/guest/hyperv-tlfs.h> #include <asm/processor.h> +#include "private.h" +struct ms_hyperv_info __read_mostly ms_hyperv; +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_page);static uint64_t generate_guest_id (void ) {
@@ -127,14 +130,42 @@ static void __init setup_hypercall_page(void) } } +static int setup_hypercall_pcpu_arg (void ) +{ +void *mapping; + +if (this_cpu (hv_pcpu_input_page) ) +return 0 ; + + mapping =alloc_xenheap_page (); +if ( !mapping ) + { +printk ("Failed to allocate hypercall input page for CPU%u\n" , +smp_processor_id ()); +return -ENOMEM ; + } + +this_cpu (hv_pcpu_input_page) = mapping; + +return 0 ; +} +static void __init setup (void ) {setup_hypercall_page (); +if (setup_hypercall_pcpu_arg () ) +panic ("Hypercall percpu arg setup failed\n" ); +} + +static int ap_setup (void ) +{ +return setup_hypercall_pcpu_arg (); }static const struct hypervisor_ops ops = { .name ="Hyper-V" , .setup = setup, + .ap_setup = ap_setup, };static void __maybe_unused build_assertions (void )
xen/arch/x86/guest/hyperv/private.h new file +29 -0
@@ -0,0 +1,29 @@ +/****************************************************************************** +* arch/x86/guest/hyperv/private.h +* +* Definitions / declarations only useful to Hyper-V code. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* 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. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2020 Microsoft. +*/ + +#ifndef __XEN_HYPERV_PRIVIATE_H__ +#define __XEN_HYPERV_PRIVIATE_H__ + +#include <xen/percpu.h> + +DECLARE_PER_CPU(void *, hv_pcpu_input_page); + +#endif /* __XEN_HYPERV_PRIVIATE_H__ */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 11/12 x86/hyperv: retrieve vp_index from Hyper-V
In reply to Wei LiuThis will be useful when invoking hypercall that targets specific vcpu(s).
---
v5:
1. Add Jan's Ack.
v4:
1. Use private.h
2. Add Paul's review tag
v2:
1. Fold into setup_pcpu_arg function
--- xen/arch/x86/guest/hyperv/hyperv.c | 5 +++++ xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 6 insertions(+)
xen/arch/x86/guest/hyperv/hyperv.c +5 -0
@@ -31,6 +31,7 @@struct ms_hyperv_info __read_mostly ms_hyperv; DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_page); +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index);static uint64_t generate_guest_id (void ) {
@@ -133,6 +134,7 @@ static void __init setup_hypercall_page(void)static int setup_hypercall_pcpu_arg (void ) {void *mapping; +uint64_t vp_index_msr;if (this_cpu (hv_pcpu_input_page) )return 0 ;
@@ -147,6 +149,9 @@ static int setup_hypercall_pcpu_arg(void)this_cpu (hv_pcpu_input_page) = mapping; +rdmsrl (HV_X64_MSR_VP_INDEX , vp_index_msr); +this_cpu (hv_vp_index) = vp_index_msr; +return 0 ; }
xen/arch/x86/guest/hyperv/private.h +1 -0
@@ -25,5 +25,6 @@#include <xen/percpu.h> DECLARE_PER_CPU(void *, hv_pcpu_input_page); +DECLARE_PER_CPU(unsigned int, hv_vp_index);#endif /* __XEN_HYPERV_PRIVIATE_H__ */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 12/12 x86/hyperv: setup VP assist page
In reply to Wei LiuVP assist page is rather important as we need to toggle some bits in it for efficient nested virtualisation.
---
v5:
1. Deal with error properly instead of always panicking
2. Swap percpu variables declarations' location
v4:
1. Use private.h
2. Prevent leak
v3:
1. Use xenheap page
2. Drop set_vp_assist
v2:
1. Use HV_HYP_PAGE_SHIFT instead
--- xen/arch/x86/guest/hyperv/hyperv.c | 44 ++++++++++++++++++++++++++++- xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 44 insertions(+), 1 deletion(-)
xen/arch/x86/guest/hyperv/hyperv.c +43 -1
@@ -31,6 +31,7 @@struct ms_hyperv_info __read_mostly ms_hyperv; DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_page); +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_vp_assist); DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index);static uint64_t generate_guest_id (void )
@@ -155,16 +156,57 @@ static int setup_hypercall_pcpu_arg(void)return 0 ; } +static int setup_vp_assist (void ) +{ +void *mapping; +uint64_t val; + + mapping =this_cpu (hv_vp_assist); + +if ( !mapping ) + { + mapping =alloc_xenheap_page (); +if ( !mapping ) + { +printk ("Failed to allocate vp_assist page for CPU%u\n" , +smp_processor_id ()); +return -ENOMEM ; + } + +clear_page (mapping); +this_cpu (hv_vp_assist) = mapping; + } + + val = (virt_to_mfn (mapping) <<HV_HYP_PAGE_SHIFT ) + |HV_X64_MSR_VP_ASSIST_PAGE_ENABLE ; +wrmsrl (HV_X64_MSR_VP_ASSIST_PAGE , val); + +return 0 ; +} +static void __init setup (void ) {setup_hypercall_page (); +if (setup_hypercall_pcpu_arg () )panic ("Hypercall percpu arg setup failed\n" ); + +if (setup_vp_assist () ) +panic ("VP assist page setup failed\n" ); }static int ap_setup (void ) { -return setup_hypercall_pcpu_arg (); +int rc; + + rc =setup_hypercall_pcpu_arg (); +if ( rc ) + goto out; + + rc =setup_vp_assist (); + + out: +return rc; }static const struct hypervisor_ops ops = {
xen/arch/x86/guest/hyperv/private.h +1 -0
@@ -25,6 +25,7 @@#include <xen/percpu.h> DECLARE_PER_CPU(void *, hv_pcpu_input_page); +DECLARE_PER_CPU(void *, hv_vp_assist); DECLARE_PER_CPU(unsigned int, hv_vp_index);#endif /* __XEN_HYPERV_PRIVIATE_H__ */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 01/12] MAINTAINERS: put Hyper-V code under Viridian maintainership
In reply to Wei LiuQuoted 14 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Wei Liu
Sent: 29 January 2020 20:20
To: Xen Development List <[email protected]>
Cc: Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Wei Liu <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; George Dunlap <[email protected]>; Andrew Cooper <[email protected]>; Durrant, Paul <[email protected]>; Ian Jackson <[email protected]>; Michael Kelley <[email protected]>; Julien Grall <[email protected]>
Subject: [Xen-devel] [PATCH v5 01/12]MAINTAINERS: put Hyper-V code under Viridian maintainership
Quoted 6 lines
And add myself as a maintainer.
Sort the list alphabetically while at it.
Signed-off-by Wei Liu <[email protected]>Signed-off-by Wei Liu <[email protected]>
Quoted 27 lines
--- MAINTAINERS | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)MAINTAINERS +4
-2@@ -514,10 +514,13 @@ F: xen/arch/x86/mm/shadow/ X86 VIRIDIAN ENLIGHTENMENTS M: Paul Durrant <[email protected]> +M: Wei Liu <[email protected]> S: Supported +F: xen/arch/x86/guest/hyperv/ F: xen/arch/x86/hvm/viridian/ -F: xen/include/asm-x86/hvm/viridian.h +F: xen/include/asm-x86/guest/hyperv.h F: xen/include/asm-x86/guest/hyperv-tlfs.h +F: xen/include/asm-x86/hvm/viridian.h XENTRACE M: George Dunlap <[email protected]> --2.20.1
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 07/12] x86/hyperv: setup hypercall page
In reply to Wei LiuQuoted 80 lines
-----Original Message-----
From: Wei Liu <[email protected]> On Behalf Of Wei Liu
Sent: 29 January 2020 20:20
To: Xen Development List <[email protected]>
Cc: Durrant, Paul <[email protected]>; Michael Kelley <[email protected]>; Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [PATCH v5 07/12] x86/hyperv: setup hypercall pageHyper-V uses a technique called overlay page for its hypercall page. It will insert a backing page to the guest when the hypercall functionality is enabled. That means we can use a page that is not backed by real memory for hypercall page.
Use the top-most addressable page for that purpose. Adjust e820 code accordingly.
We also need to register Xen's guest OS ID to Hyper-V. Use
0x3as the vendor ID. Fix the comment inhyperv-tlfs.hwhile at it.Signed-off-by Wei Liu <[email protected]>---
v5:
1. usehypervisor_reserve_top_pages
2. add a macro for hypercall page mfn
3. address other misc commentsv4:
1. Use fixmap
2. Follow routines listed in TLFS--- xen/arch/x86/e820.c | 5 +++ xen/arch/x86/guest/hyperv/hyperv.c | 57 +++++++++++++++++++++++-- xen/include/asm-x86/guest/hyperv-tlfs.h | 5 ++- xen/include/asm-x86/guest/hyperv.h | 3 ++ 4 files changed, 65 insertions(+), 5 deletions(-)xen/arch/x86/e820.c +5
-0@@ -343,6 +343,7 @@ static unsigned long __init find_max_pfn(void) {unsigned int i;unsigned long max_pfn =0 ; +unsigned long top_pfn = ((1ull << paddr_bits) -1 ) >>PAGE_SHIFT ;for (i =0 ; i < e820.nr_map; i++) {unsigned long start, end;@@ -357,6 +358,10 @@ static unsigned long __init find_max_pfn(void) max_pfn = end; } + top_pfn -=hypervisor_reserve_top_pages (); +if ( max_pfn >= top_pfn ) + max_pfn = top_pfn; +return max_pfn; }xen/arch/x86/guest/hyperv/hyperv.c +3
-1@@ -19,15 +19,26 @@* Copyright (c) 2019 Microsoft. */ #include <xen/init.h> +#include <xen/version.h> +#include <asm/fixmap.h> #include <asm/guest.h> #include <asm/guest/hyperv-tlfs.h> +#include <asm/processor.h> struct ms_hyperv_info __read_mostly ms_hyperv; -static const struct hypervisor_ops ops = {
xen/arch/x86/guest/hyperv/hyperv.c line 38
Quoted 10 lines
xen/arch/x86/guest/hyperv/hyperv.c +8
-2- .name = "Hyper-V", -}; +static uint64_t generate_guest_id (void ) +{ +uint64_t id; + + id = (uint64_t )HV_XEN_VENDOR_ID <<48 ; + id |= (xen_major_version () <<16 ) |xen_minor_version (); + +return id;
I think this should use the hv_guest_os_id union. You can then set the values using the bit-fields and return the raw.
Paul
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 02/12] x86/hypervisor: make hypervisor_ap_setup return an error code
In reply to Wei LiuQuoted 1 line · Wei Liu
We want to be able to handle AP setup error in the upper layer.
Thanks, some comments below.
Quoted 33 lines
Signed-off-by Wei Liu <[email protected]>--- xen/arch/x86/guest/hypervisor.c | 6 ++++-- xen/arch/x86/guest/xen/xen.c | 11 +++++++++-- xen/include/asm-x86/guest/hypervisor.h | 6 +++--- 3 files changed, 16 insertions(+), 7 deletions(-)xen/arch/x86/guest/hypervisor.c +4
-2@@ -52,10 +52,12 @@ void __init hypervisor_setup(void) ops->setup (); } -void hypervisor_ap_setup (void ) +int hypervisor_ap_setup (void ) {if ( ops && ops->ap_setup ) - ops->ap_setup (); +return ops->ap_setup (); + +return 0 ; }void hypervisor_resume (void )xen/arch/x86/guest/xen/xen.c +0
-0@@ -257,11 +257,18 @@ static void __init setup(void)init_evtchn ();
xen/arch/x86/guest/xen/xen.c static void __init setup(void) · line 265
Quoted 10 lines
xen/arch/x86/guest/xen/xen.c +4
-2} -static void ap_setup (void ) +static int ap_setup (void ) { +int rc; +set_vcpu_id (); -map_vcpuinfo (); + rc =map_vcpuinfo ();
map_vcpuinfo should be changed so that the BUG_ON is removed, and an error is only returned if VCPUOP_register_vcpu_info fails and vcpu >= XEN_LEGACY_MAX_VCPUS, else no error should be returned.
xen/arch/x86/guest/xen/xen.c static void __init setup(void) · line 271
Quoted 6 lines
xen/arch/x86/guest/xen/xen.c +5
-0+if ( rc ) +return rc; +init_evtchn (); + +return 0 ;
In order to keep this shorter, you could do:
if ( !rc )
init_evtchn();
return rc;
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
In reply to Wei LiuQuoted 15 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Wei Liu
Sent: 29 January 2020 20:21
To: Xen Development List <[email protected]>
Cc: Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Wei Liu <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; George Dunlap <[email protected]>; Andrew Cooper <[email protected]>; Durrant, Paul <[email protected]>; Ian Jackson <[email protected]>; Michael Kelley <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
Quoted 3 lines
These functions will be used later to make hypercalls to Hyper-V.
Signed-off-by Wei Liu <[email protected]>
Quoted 197 lines
---
v5:
1. Switch back to direct call
2. Fix some issues pointed out by JanI tried using the
asm(".equ ..")trick but hit a problem with %c again.mm.c:5736:5: error: invalid 'asm': operand is not a condition code, invalid operand code 'c'
asm ( ".equHV_HCALL_PAGE, %c0; .globalHV_HCALL_PAGE"--- MAINTAINERS | 1 + xen/arch/x86/guest/hyperv/hyperv.c | 6 ++ xen/arch/x86/xen.lds.S | 4 + xen/include/asm-x86/fixmap.h | 3 +- xen/include/asm-x86/guest/hyperv-hcall.h | 96 ++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 xen/include/asm-x86/guest/hyperv-hcall.hMAINTAINERS +1
-0@@ -519,6 +519,7 @@ S: Supported F: xen/arch/x86/guest/hyperv/ F: xen/arch/x86/hvm/viridian/ F: xen/include/asm-x86/guest/hyperv.h +F: xen/include/asm-x86/guest/hyperv-hcall.h F: xen/include/asm-x86/guest/hyperv-tlfs.h F: xen/include/asm-x86/hvm/viridian.hxen/arch/x86/guest/hyperv/hyperv.c +6
-0@@ -123,6 +123,12 @@ static const struct hypervisor_ops ops = { .setup = setup, }; +static void __maybe_unused build_assertions (void ) +{ +/* We use 1 in linker script */ +BUILD_BUG_ON (FIX_X_HYPERV_HCALL !=1 ); +} +/* * Local variables: * mode: C xen/arch/x86/xen.lds.S +4
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endif +#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1)); +#endif + /* Sections to be discarded */ /DISCARD/ : { *(.exit.text)xen/include/asm-x86/fixmap.h +1
-2@@ -16,6 +16,7 @@#define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE)#define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE) +#define __fix_x_to_virt (x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT))#ifndef __ASSEMBLY__@@ -110,8 +111,6 @@ extern void __set_fixmap_x(#define clear_fixmap_x (idx) __set_fixmap_x(idx, 0, 0) -#define __fix_x_to_virt (x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT)) -#define fix_x_to_virt (x) ((void *)__fix_x_to_virt(x))#endif /* __ASSEMBLY__ */ xen/include/asm- renamed from xen/include/asm-x86/guest/hyperv-hcall.h +0
-0
x86/guest/hyperv-hcall.h
new file mode 100644
index 0000000000..5b7509b3b5xen/include/asm-x86/guest/hyperv-hcall.h new file +1
-0@@ -0,0 +1,96 @@ +/************************************************************************ ******
+ *asm-x86/guest/hyperv-hcall.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms and conditions 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. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; If not, see
<http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2019 Microsoft.
+ */xen/include/asm-x86/guest/hyperv-hcall.h new file +13
-0+ +#ifndef __X86_HYPERV_HCALL_H__ +#define __X86_HYPERV_HCALL_H__ + +#include <xen/lib.h> +#include <xen/types.h> + +#include <asm/asm_defns.h> +#include <asm/fixmap.h> +#include <asm/guest/hyperv-tlfs.h> +#include <asm/page.h> + +static inline uint64_t hv_do_hypercall(uint64_t control, paddr_t
input_addr,xen/include/asm-x86/guest/hyperv-hcall.h new file +16
-0+ paddr_t output_addr) +{ +uint64_t status; + register unsigned long r8 asm("r8") = output_addr; + + asmvolatile ("call hv_hcall_page" + :"=a" (status),"+c" (control), + "+d" (input_addr) ASM_CALL_CONSTRAINT + :"r" (r8) + :"memory" ); + +return status; +} + +static inline uint64_t hv_do_fast_hypercall (uint16_t code, + uint64_t input1, uint64_tinput2)
xen/include/asm-x86/guest/hyperv-hcall.h new file +15
-0+{ +uint64_t status; +uint64_t control = code |HV_HYPERCALL_FAST_BIT ; + register unsigned long r8 asm("r8") = input2; + + asmvolatile ("call hv_hcall_page" + :"=a" (status),"+c" (control), + "+d" (input1) ASM_CALL_CONSTRAINT + :"r" (r8) + : ); + +return status; +} + +static inline uint64_t hv_do_rep_hypercall(uint16_t code, uint16_t
rep_count,xen/include/asm-x86/guest/hyperv-hcall.h new file +35
-1+uint16_t varhead_size, + paddr_t input, paddr_t output) +{ + uint64_t control = code; +uint64_t status; +uint16_t rep_comp; + + control |= (uint64_t )varhead_size <<HV_HYPERCALL_VARHEAD_OFFSET ; + control |= (uint64_t )rep_count <<HV_HYPERCALL_REP_COMP_OFFSET ; + +do { + status =hv_do_hypercall (control, input, output); +if ( (status &HV_HYPERCALL_RESULT_MASK ) !=HV_STATUS_SUCCESS ) +break ; + + rep_comp =MASK_EXTR (status,HV_HYPERCALL_REP_COMP_MASK ); + + control &= ~HV_HYPERCALL_REP_START_MASK ; + control |=MASK_INSR (rep_comp,HV_HYPERCALL_REP_START_MASK ); + }while ( rep_comp < rep_count ); + +return status; +} + +#endif /* __X86_HYPERV_HCALL_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ --2.20.1
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 03/12] x86/smp: don't online cpu if hypervisor_ap_setup fails
In reply to Wei LiuQuoted 5 lines · Wei Liu
Push
hypervisor_ap_setupdown tosmp_callin.Take the chance to replace
xen_guestwithcpu_has_hypervisor.Signed-off-by Wei Liu <[email protected]>
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 10/12] x86/hyperv: provide percpu hypercall input page
In reply to Wei LiuQuoted 16 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Wei Liu
Sent: 29 January 2020 20:21
To: Xen Development List <[email protected]>
Cc: Wei Liu <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Durrant, Paul <[email protected]>; Michael Kelley <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [Xen-devel] [PATCH v5 10/12] x86/hyperv: provide percpu hypercall input pageHyper-V's input / output argument must be 8 bytes aligned an not cross page boundary. One way to satisfy those requirements is to use percpu page.
Quoted 7 lines
For the foreseeable future we only need to provide input for TLB and APIC hypercalls, so skip setting up an output page.
We will also need to provide an
ap_setuphook for secondary cpus to setup its own input page.Signed-off-by Wei Liu <[email protected]>
Quoted 120 lines
---
v5:
1. Adjust to newap_setup
2. Change variable name tohv_pcpu_input_pagev4:
1. Change wording in commit message
2. Prevent leak
3. Introduce a private headerv3:
1. Use xenheap page instead
2. Drop page tracking structure
3. Drop Paul's review tag--- xen/arch/x86/guest/hyperv/hyperv.c | 31 +++++++++++++++++++++++++++++ xen/arch/x86/guest/hyperv/private.h | 29 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 xen/arch/x86/guest/hyperv/private.hxen/arch/x86/guest/hyperv/hyperv.c +31
-0@@ -27,7 +27,10 @@#include <asm/guest/hyperv-tlfs.h> #include <asm/processor.h> +#include "private.h" +struct ms_hyperv_info __read_mostly ms_hyperv; +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_page);static uint64_t generate_guest_id (void ) {@@ -127,14 +130,42 @@ static void __init setup_hypercall_page(void) } } +static int setup_hypercall_pcpu_arg (void ) +{ +void *mapping; + +if (this_cpu (hv_pcpu_input_page) ) +return 0 ; + + mapping =alloc_xenheap_page (); +if ( !mapping ) + { +printk ("Failed to allocate hypercall input page for CPU%u\n" , +smp_processor_id ()); +return -ENOMEM ; + } + +this_cpu (hv_pcpu_input_page) = mapping; + +return 0 ; +} +static void __init setup (void ) {setup_hypercall_page (); +if (setup_hypercall_pcpu_arg () ) +panic ("Hypercall percpu arg setup failed\n" ); +} + +static int ap_setup (void ) +{ +return setup_hypercall_pcpu_arg (); }static const struct hypervisor_ops ops = { .name ="Hyper-V" , .setup = setup, + .ap_setup = ap_setup, };static void __maybe_unused build_assertions (void )xen/arch/x86/guest/hyperv/private.h new file +1
-0@@ -0,0 +1,29 @@ +/************************************************************************ ******
+ *arch/x86/guest/hyperv/private.h
+ *
+ * Definitions / declarations only useful to Hyper-V code.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2020 Microsoft.
+ */xen/arch/x86/guest/hyperv/private.h new file +9
-1+ +#ifndef __XEN_HYPERV_PRIVIATE_H__ +#define __XEN_HYPERV_PRIVIATE_H__ + +#include <xen/percpu.h> + +DECLARE_PER_CPU(void *, hv_pcpu_input_page); + +#endif /* __XEN_HYPERV_PRIVIATE_H__ */ --2.20.1
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 04/12] x86: make paddr_bits available earlier
In reply to Wei LiuQuoted 7 lines · Wei Liu
Move
early_cpu_initbeforeinit_e820, such thatpaddr_bitscan be used by e820 code.This will reduce code repetition and prepare for further adjustment when L0 hypervisor comes into play.
Signed-off-by Wei Liu <[email protected]>
One typo below.
Quoted 42 lines
--- xen/arch/x86/e820.c | 14 ++++---------- xen/arch/x86/setup.c | 5 +++-- 2 files changed, 7 insertions(+), 12 deletions(-)xen/arch/x86/e820.c +4
-10@@ -420,7 +420,7 @@ static uint64_t __init mtrr_top_of_ram(void) {uint32_t eax, ebx, ecx, edx;uint64_t mtrr_cap, mtrr_def, addr_mask, base, mask, top; -unsigned int i, phys_bits =36 ; +unsigned int i;/* By default we check only Intel systems. */ if ( e820_mtrr_clip ==-1 )@@ -445,15 +445,9 @@ static uint64_t __init mtrr_top_of_ram(void)if ( !test_bit (X86_FEATURE_MTRR &31 , &edx) )return 0 ; -/* Find the physical address size for this CPU. */ - eax =cpuid_eax (0x80000000 ); -if ( (eax >>16 ) ==0x8000 && eax >=0x80000008 ) - { - phys_bits = (uint8_t )cpuid_eax (0x80000008 ); -if ( phys_bits >PADDR_BITS ) - phys_bits =PADDR_BITS ; - } - addr_mask = ((1ull << phys_bits) -1 ) & ~((1ull <<12 ) -1 ); +/* paddr_bits must have been set at this point */ +ASSERT (paddr_bits); + addr_mask = ((1ull << paddr_bits) -1 ) &PAGE_MASK ;rdmsrl (MSR_MTRRcap, mtrr_cap);rdmsrl (MSR_MTRRdefType, mtrr_def);xen/arch/x86/setup.c +0
-0
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 957
Quoted 4 lines
xen/arch/x86/setup.c +1
-0@@ -954,6 +954,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)else panic ("Bootloader provided no memory information\n" ); +/* This must come before e820 code becuause it sets paddr_bits. */
^ because
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 06/12] x86/hypervisor: provide hypervisor_reserve_top_pages
In reply to Wei LiuQuoted 7 lines · Wei Liu
This function will return the number of pages that need to be reserved in the machine address space.
E820 code will use that number to adjust the maximum PFN available to Xen.
Signed-off-by Wei Liu <[email protected]>
It's hard to figure out whether the proposed code is suitable since it's not yet called by any other function, and there's no hypervisor implementation.
I wouldn't mind if this was merged into the next patch so that there's a implementation and a user of the introduced code.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 12/12] x86/hyperv: setup VP assist page
In reply to Wei LiuQuoted 64 lines
-----Original Message-----
From: Wei Liu <[email protected]> On Behalf Of Wei Liu
Sent: 29 January 2020 20:21
To: Xen Development List <[email protected]>
Cc: Durrant, Paul <[email protected]>; Michael Kelley <[email protected]>; Wei Liu <[email protected]>; Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [PATCH v5 12/12] x86/hyperv: setup VP assist pageVP assist page is rather important as we need to toggle some bits in it for efficient nested virtualisation.
Signed-off-by Wei Liu <[email protected]>---
v5:
1. Deal with error properly instead of always panicking
2. Swap percpu variables declarations' locationv4:
1. Useprivate.h
2. Prevent leakv3:
1. Use xenheap page
2. Dropset_vp_assistv2:
1. UseHV_HYP_PAGE_SHIFTinstead--- xen/arch/x86/guest/hyperv/hyperv.c | 44 ++++++++++++++++++++++++++++- xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 44 insertions(+), 1 deletion(-)xen/arch/x86/guest/hyperv/hyperv.c +14
-0@@ -31,6 +31,7 @@struct ms_hyperv_info __read_mostly ms_hyperv; DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_page); +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_vp_assist); DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index);static uint64_t generate_guest_id (void )@@ -155,16 +156,57 @@ static int setup_hypercall_pcpu_arg(void)return 0 ; } +static int setup_vp_assist (void ) +{ +void *mapping; +uint64_t val; + + mapping =this_cpu (hv_vp_assist); + +if ( !mapping ) + { + mapping =alloc_xenheap_page (); +if ( !mapping ) + { + printk("Failed to allocate vp_assist page for CPU%u\n",
xen/arch/x86/guest/hyperv/hyperv.c static int setup_hypercall_pcpu_arg(void) · line 181
Quoted 10 lines
xen/arch/x86/guest/hyperv/hyperv.c +10
-0+ smp_processor_id()); +return -ENOMEM ; + } + +clear_page (mapping); +this_cpu (hv_vp_assist) = mapping; + } + + val = (virt_to_mfn (mapping) <<HV_HYP_PAGE_SHIFT ) + |HV_X64_MSR_VP_ASSIST_PAGE_ENABLE ;
Perhaps it would be neater to put the viridian_page_msr union into hyperv-tlfs.h and then use that.
Paul
Quoted 46 lines
xen/arch/x86/guest/hyperv/hyperv.c +19
-1+wrmsrl (HV_X64_MSR_VP_ASSIST_PAGE , val); + +return 0 ; +} +static void __init setup (void ) {setup_hypercall_page (); +if (setup_hypercall_pcpu_arg () )panic ("Hypercall percpu arg setup failed\n" ); + +if (setup_vp_assist () ) +panic ("VP assist page setup failed\n" ); }static int ap_setup (void ) { -return setup_hypercall_pcpu_arg (); +int rc; + + rc =setup_hypercall_pcpu_arg (); +if ( rc ) + goto out; + + rc =setup_vp_assist (); + + out: +return rc; }static const struct hypervisor_ops ops = {xen/arch/x86/guest/hyperv/private.h +1
-1@@ -25,6 +25,7 @@#include <xen/percpu.h> DECLARE_PER_CPU(void *, hv_pcpu_input_page); +DECLARE_PER_CPU(void *, hv_vp_assist); DECLARE_PER_CPU(unsigned int, hv_vp_index);#endif /* __XEN_HYPERV_PRIVIATE_H__ */ --
Quoted 1 line
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 07/12] x86/hyperv: setup hypercall page
In reply to Wei LiuQuoted 41 lines · Wei Liu
Hyper-V uses a technique called overlay page for its hypercall page. It will insert a backing page to the guest when the hypercall functionality is enabled. That means we can use a page that is not backed by real memory for hypercall page.
Use the top-most addressable page for that purpose. Adjust e820 code accordingly.
We also need to register Xen's guest OS ID to Hyper-V. Use
0x3as the vendor ID. Fix the comment inhyperv-tlfs.hwhile at it.Signed-off-by Wei Liu <[email protected]>---
v5:
1. usehypervisor_reserve_top_pages
2. add a macro for hypercall page mfn
3. address other misc commentsv4:
1. Use fixmap
2. Follow routines listed in TLFS--- xen/arch/x86/e820.c | 5 +++ xen/arch/x86/guest/hyperv/hyperv.c | 57 +++++++++++++++++++++++-- xen/include/asm-x86/guest/hyperv-tlfs.h | 5 ++- xen/include/asm-x86/guest/hyperv.h | 3 ++ 4 files changed, 65 insertions(+), 5 deletions(-)xen/arch/x86/e820.c +1
-0@@ -343,6 +343,7 @@ static unsigned long __init find_max_pfn(void) {unsigned int i;unsigned long max_pfn =0 ; +unsigned long top_pfn = ((1ull << paddr_bits) -1 ) >>PAGE_SHIFT ;for (i =0 ; i < e820.nr_map; i++) {unsigned long start, end;
xen/arch/x86/e820.c static unsigned long __init find_max_pfn(void) · line 363
Quoted 6 lines
xen/arch/x86/e820.c +3
-0@@ -357,6 +358,10 @@ static unsigned long __init find_max_pfn(void) max_pfn = end; } + top_pfn -=hypervisor_reserve_top_pages (); +if ( max_pfn >= top_pfn ) + max_pfn = top_pfn;
Hm, I'm not sure I see the point of this. The value returned by find_max_pfn is the maximum RAM address found in the memory map, but the physical address you are using to map the hypercall page is almost certainly much higher than the maximum address found in the physmap (and certainly not RAM), and hence I'm not sure what's the point of this.
Also you haven't introduced a HyperV implementation of hypervisor_reserve_top_pages so far, so it's hard to tell the intend of this.
Quoted 113 lines
xen/arch/x86/e820.c +1
-0+return max_pfn; }xen/arch/x86/guest/hyperv/hyperv.c +54
-3@@ -19,15 +19,26 @@* Copyright (c) 2019 Microsoft. */ #include <xen/init.h> +#include <xen/version.h> +#include <asm/fixmap.h> #include <asm/guest.h> #include <asm/guest/hyperv-tlfs.h> +#include <asm/processor.h> struct ms_hyperv_info __read_mostly ms_hyperv; -static const struct hypervisor_ops ops = { - .name ="Hyper-V" , -}; +static uint64_t generate_guest_id (void ) +{ +uint64_t id; + + id = (uint64_t )HV_XEN_VENDOR_ID <<48 ; + id |= (xen_major_version () <<16 ) |xen_minor_version (); + +return id; +} + +static const struct hypervisor_ops ops;const struct hypervisor_ops *__init hyperv_probe (void ) {@@ -72,6 +83,46 @@ 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; +union hv_guest_os_id guest_id; +unsigned long mfn; + +rdmsrl (HV_X64_MSR_GUEST_OS_ID , guest_id.raw); +if ( !guest_id.raw ) + { + guest_id.raw =generate_guest_id (); +wrmsrl (HV_X64_MSR_GUEST_OS_ID , guest_id.raw); + } + +rdmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); +if ( !hypercall_msr.enable ) + { + mfn =HV_HCALL_MFN ; + hypercall_msr.enable =1 ; + hypercall_msr.guest_physical_address = mfn; +wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); + }else { + mfn = hypercall_msr.guest_physical_address; + } + +rdmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); +BUG_ON (!hypercall_msr.enable); + +set_fixmap_x (FIX_X_HYPERV_HCALL , mfn <<PAGE_SHIFT ); +} + +static void __init setup (void ) +{ +setup_hypercall_page (); +} + +static const struct hypervisor_ops ops = { + .name ="Hyper-V" , + .setup = setup, +}; +/* * Local variables: * mode: C xen/include/asm-x86/guest/hyperv-tlfs.h +3
-2@@ -318,15 +318,16 @@ struct ms_hyperv_tsc_page {* * Bit(s) * 63 - Indicates if the OS is Open Source or not; 1 is Open Source -* 62:56 - Os Type; Linux is 0x100 +* 62:56 - Os Type; Linux 0x1, FreeBSD 0x2, Xen 0x3 * 55:48 - Distro specific identification -* 47:16 - Linux kernel version number +* 47:16 - Guest OS version number * 15:0 - Distro specific identification * * */ #define HV_LINUX_VENDOR_ID 0x8100 +#define HV_XEN_VENDOR_ID 0x8300union hv_guest_os_id {uint64_t raw;xen/include/asm-x86/guest/hyperv.h +0
-0
xen/include/asm-x86/guest/hyperv.h line 25
Quoted 5 lines
xen/include/asm-x86/guest/hyperv.h +2
-0@@ -21,6 +21,9 @@#include <xen/types.h> +/* Use top-most MFN for hypercall page */ +#define HV_HCALL_MFN (((1ull << paddr_bits) - 1) >> HV_HYP_PAGE_SHIFT)
I think you should use PAGE_SHIFT here, or else you also need to make sure the fixmap reserved entry is of size ((1 << HV_HYP_PAGE_SHIFT) - 1), and the call to set_fixmap_x in setup_hypercall_page needs to take this into account AFAICT and not use PAGE_SHIFT.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 05/12] x86: provide executable fixmap facility
In reply to Wei Liuxen/arch/x86/mm.c int destroy_xen_mappings(unsigned long s, unsigned long e) · line 5735
Quoted 10 lines · Wei Liu
xen/arch/x86/mm.c +9
-0+void __set_fixmap_x ( +enum fixed_addresses_x idx,unsigned long mfn,unsigned long flags) +{ +BUG_ON (idx >= __end_of_fixed_addresses_x || idx <=FIX_X_RESERVED ); +map_pages_to_xen (__fix_x_to_virt (idx),_mfn (mfn),1 , flags); + +/* Generate a symbol to be used in linker script */ + asm (".equ FIXADDR_X_SIZE, %c0; .global FIXADDR_X_SIZE" + ::"i" (__end_of_fixed_addresses_x <<PAGE_SHIFT ) );
The (__end << SHIFT) part can be replaced with FIXADDR_X_SIZE (the macro defined in fixmap.h) directly.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 07/12] x86/hyperv: setup hypercall page
In reply to Roger Pau MonnéQuoted 45 lines · Roger Pau Monné
Quoted 44 lines · Wei Liu
Hyper-V uses a technique called overlay page for its hypercall page. It will insert a backing page to the guest when the hypercall functionality is enabled. That means we can use a page that is not backed by real memory for hypercall page.
Use the top-most addressable page for that purpose. Adjust e820 code accordingly.
We also need to register Xen's guest OS ID to Hyper-V. Use
0x3as the vendor ID. Fix the comment inhyperv-tlfs.hwhile at it.Signed-off-by Wei Liu <[email protected]>---
v5:
1. usehypervisor_reserve_top_pages
2. add a macro for hypercall page mfn
3. address other misc commentsv4:
1. Use fixmap
2. Follow routines listed in TLFS--- xen/arch/x86/e820.c | 5 +++ xen/arch/x86/guest/hyperv/hyperv.c | 57 +++++++++++++++++++++++-- xen/include/asm-x86/guest/hyperv-tlfs.h | 5 ++- xen/include/asm-x86/guest/hyperv.h | 3 ++ 4 files changed, 65 insertions(+), 5 deletions(-)xen/arch/x86/e820.c +1
-0@@ -343,6 +343,7 @@ static unsigned long __init find_max_pfn(void) {unsigned int i;unsigned long max_pfn =0 ; +unsigned long top_pfn = ((1ull << paddr_bits) -1 ) >>PAGE_SHIFT ;for (i =0 ; i < e820.nr_map; i++) {unsigned long start, end;@@ -357,6 +358,10 @@ static unsigned long __init find_max_pfn(void) max_pfn = end; }
Quoted 10 lines
xen/arch/x86/e820.c static unsigned long __init find_max_pfn(void) · line 363
Quoted 3 lines
xen/arch/x86/e820.c +3
-0+ top_pfn -=hypervisor_reserve_top_pages (); +if ( max_pfn >= top_pfn ) + max_pfn = top_pfn;Hm, I'm not sure I see the point of this. The value returned by
find_max_pfnis the maximum RAM address found in the memory map, but the physical address you are using to map the hypercall page is almost certainly much higher than the maximum address found in the physmap (and certainly not RAM), and hence I'm not sure what's the point of this.
Yes, the keyword is "almost certainly". :-)
This is done for correctness's sake. I don't expect in practice there would be a configuration that has that much memory, but correctness is still important.
It also guards against weird configuration in which memory is put into that part of the physical address space for whatever reason. I don't know why anyone would do that, but again, we should be prepared for that.
Quoted 4 lines
Also you haven't introduced a HyperV implementation of
hypervisor_reserve_top_pagesso far, so it's hard to tell the intend of this.
D'oh. That was supposed to be in this patch. I guess I forgot to commit that hunk!
That function for Hyper-V is going to return 1 (page).
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/e820.c +1
-0+return max_pfn; }
[...]
Quoted 8 lines
Quoted 8 lines
xen/include/asm-x86/guest/hyperv.h +0
-0@@ -21,6 +21,9 @@#include <xen/types.h>
Quoted 7 lines
xen/include/asm-x86/guest/hyperv.h line 25
Quoted 2 lines
xen/include/asm-x86/guest/hyperv.h +2
-0+/* Use top-most MFN for hypercall page */ +#define HV_HCALL_MFN (((1ull << paddr_bits) - 1) >> HV_HYP_PAGE_SHIFT)I think you should use
PAGE_SHIFThere, or else you also need to make sure the fixmap reserved entry is of size ((1 <<HV_HYP_PAGE_SHIFT) - 1), and the call toset_fixmap_xinsetup_hypercall_pageneeds to take this into account AFAICT and not usePAGE_SHIFT.
PAGE_SHIFT and HV_HYP_PAGE_SHIFT are in fact the same.
I can add a BUILD_BUG_ON somewhere.
Wei.
Quoted 2 lines
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 07/12] x86/hyperv: setup hypercall page
In reply to Durrant, PaulQuoted 6 lines · Paul
Quoted 6 lines
xen/arch/x86/guest/hyperv/hyperv.c +3
-3-static const struct hypervisor_ops ops = { - .name ="Hyper-V" , -}; +static uint64_t generate_guest_id (void ) +{ +uint64_t id;
Quoted 8 lines
xen/arch/x86/guest/hyperv/hyperv.c line 38
Quoted 5 lines
xen/arch/x86/guest/hyperv/hyperv.c +5
-0+ + id = (uint64_t )HV_XEN_VENDOR_ID <<48 ; + id |= (xen_major_version () <<16 ) |xen_minor_version (); + +return id;I think this should use the
hv_guest_os_idunion. You can then set the values using the bit-fields and return the raw.
NP.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 07/12] x86/hyperv: setup hypercall page
In reply to Wei LiuQuoted 70 lines · Wei Liu
Quoted 45 lines · Roger Pau Monné
Quoted 44 lines · Wei Liu
Hyper-V uses a technique called overlay page for its hypercall page. It will insert a backing page to the guest when the hypercall functionality is enabled. That means we can use a page that is not backed by real memory for hypercall page.
Use the top-most addressable page for that purpose. Adjust e820 code accordingly.
We also need to register Xen's guest OS ID to Hyper-V. Use
0x3as the vendor ID. Fix the comment inhyperv-tlfs.hwhile at it.Signed-off-by Wei Liu <[email protected]>---
v5:
1. usehypervisor_reserve_top_pages
2. add a macro for hypercall page mfn
3. address other misc commentsv4:
1. Use fixmap
2. Follow routines listed in TLFS--- xen/arch/x86/e820.c | 5 +++ xen/arch/x86/guest/hyperv/hyperv.c | 57 +++++++++++++++++++++++-- xen/include/asm-x86/guest/hyperv-tlfs.h | 5 ++- xen/include/asm-x86/guest/hyperv.h | 3 ++ 4 files changed, 65 insertions(+), 5 deletions(-)xen/arch/x86/e820.c +1
-0@@ -343,6 +343,7 @@ static unsigned long __init find_max_pfn(void) {unsigned int i;unsigned long max_pfn =0 ; +unsigned long top_pfn = ((1ull << paddr_bits) -1 ) >>PAGE_SHIFT ;for (i =0 ; i < e820.nr_map; i++) {unsigned long start, end;@@ -357,6 +358,10 @@ static unsigned long __init find_max_pfn(void) max_pfn = end; }Quoted 10 lines
xen/arch/x86/e820.c static unsigned long __init find_max_pfn(void) · line 363
Quoted 3 lines
xen/arch/x86/e820.c +3
-0+ top_pfn -=hypervisor_reserve_top_pages (); +if ( max_pfn >= top_pfn ) + max_pfn = top_pfn;Hm, I'm not sure I see the point of this. The value returned by
find_max_pfnis the maximum RAM address found in the memory map, but the physical address you are using to map the hypercall page is almost certainly much higher than the maximum address found in the physmap (and certainly not RAM), and hence I'm not sure what's the point of this.Yes, the keyword is "almost certainly". :-)
This is done for correctness's sake. I don't expect in practice there would be a configuration that has that much memory, but correctness is still important.
It also guards against weird configuration in which memory is put into that part of the physical address space for whatever reason. I don't know why anyone would do that, but again, we should be prepared for that.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Also you haven't introduced a HyperV implementation of
hypervisor_reserve_top_pagesso far, so it's hard to tell the intend of this.D'oh. That was supposed to be in this patch. I guess I forgot to commit that hunk!
That function for Hyper-V is going to return 1 (page).
But that would likely be wrong, unless the memory map has a RAM region that expands up to (1 << paddr_bits)?
Or else you are just removing a page from the last RAM region in the memory map for no reason. max_pfn is almost certainly way below (1 << paddr_bits).
I think what you need is a hook that modifies the memory map and adds a reserved region at ((1 << paddr_bits) - PAGE_SIZE) of size PAGE_SIZE. See where pv_shim_fixup_e820 is used, and I think you want to make this a hypervisor hook and add the HyperV code to reserve the hypercall page in the e820 there.
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/e820.c +1
-0+return max_pfn; }[...]
Quoted 8 lines
Quoted 8 lines
xen/include/asm-x86/guest/hyperv.h +0
-0@@ -21,6 +21,9 @@#include <xen/types.h> Quoted 7 lines
xen/include/asm-x86/guest/hyperv.h line 25
Quoted 2 lines
xen/include/asm-x86/guest/hyperv.h +2
-0+/* Use top-most MFN for hypercall page */ +#define HV_HCALL_MFN (((1ull << paddr_bits) - 1) >> HV_HYP_PAGE_SHIFT)I think you should use
PAGE_SHIFThere, or else you also need to make sure the fixmap reserved entry is of size ((1 <<HV_HYP_PAGE_SHIFT) - 1), and the call toset_fixmap_xinsetup_hypercall_pageneeds to take this into account AFAICT and not usePAGE_SHIFT.
Quoted 3 lines
PAGE_SHIFTandHV_HYP_PAGE_SHIFTare in fact the same.I can add a
BUILD_BUG_ONsomewhere.
Yes please.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 07/12] x86/hyperv: setup hypercall page
Quoted 78 lines · Roger Pau Monné
Quoted 77 lines · Wei Liu
Quoted 45 lines · Roger Pau Monné
Quoted 44 lines · Wei Liu
Hyper-V uses a technique called overlay page for its hypercall page. It will insert a backing page to the guest when the hypercall functionality is enabled. That means we can use a page that is not backed by real memory for hypercall page.
Use the top-most addressable page for that purpose. Adjust e820 code accordingly.
We also need to register Xen's guest OS ID to Hyper-V. Use
0x3as the vendor ID. Fix the comment inhyperv-tlfs.hwhile at it.Signed-off-by Wei Liu <[email protected]>---
v5:
1. usehypervisor_reserve_top_pages
2. add a macro for hypercall page mfn
3. address other misc commentsv4:
1. Use fixmap
2. Follow routines listed in TLFS--- xen/arch/x86/e820.c | 5 +++ xen/arch/x86/guest/hyperv/hyperv.c | 57 +++++++++++++++++++++++-- xen/include/asm-x86/guest/hyperv-tlfs.h | 5 ++- xen/include/asm-x86/guest/hyperv.h | 3 ++ 4 files changed, 65 insertions(+), 5 deletions(-)xen/arch/x86/e820.c +1
-0@@ -343,6 +343,7 @@ static unsigned long __init find_max_pfn(void) {unsigned int i;unsigned long max_pfn =0 ; +unsigned long top_pfn = ((1ull << paddr_bits) -1 ) >>PAGE_SHIFT ;for (i =0 ; i < e820.nr_map; i++) {unsigned long start, end;@@ -357,6 +358,10 @@ static unsigned long __init find_max_pfn(void) max_pfn = end; }Quoted 10 lines
xen/arch/x86/e820.c static unsigned long __init find_max_pfn(void) · line 363
Quoted 3 lines
xen/arch/x86/e820.c +3
-0+ top_pfn -=hypervisor_reserve_top_pages (); +if ( max_pfn >= top_pfn ) + max_pfn = top_pfn;Hm, I'm not sure I see the point of this. The value returned by
find_max_pfnis the maximum RAM address found in the memory map, but the physical address you are using to map the hypercall page is almost certainly much higher than the maximum address found in the physmap (and certainly not RAM), and hence I'm not sure what's the point of this.Yes, the keyword is "almost certainly". :-)
This is done for correctness's sake. I don't expect in practice there would be a configuration that has that much memory, but correctness is still important.
It also guards against weird configuration in which memory is put into that part of the physical address space for whatever reason. I don't know why anyone would do that, but again, we should be prepared for that.
Quoted 4 lines
Also you haven't introduced a HyperV implementation of
hypervisor_reserve_top_pagesso far, so it's hard to tell the intend of this.D'oh. That was supposed to be in this patch. I guess I forgot to commit that hunk!
Quoted 9 lines
Quoted 1 line
That function for Hyper-V is going to return 1 (page).
But that would likely be wrong, unless the memory map has a RAM region that expands up to (1 <<
paddr_bits)?Or else you are just removing a page from the last RAM region in the memory map for no reason.
max_pfnis almost certainly way below (1 <<paddr_bits).
Why? The adjustment will not be applied unless RAM overlaps with that reserved region.
Quoted 5 lines
I think what you need is a hook that modifies the memory map and adds a reserved region at ((1 <<
paddr_bits) -PAGE_SIZE) of sizePAGE_SIZE. See wherepv_shim_fixup_e820is used, and I think you want to make this a hypervisor hook and add the HyperV code to reserve the hypercall page in the e820 there.
That works for me too. Let's see what other people think.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 04/12] x86: make paddr_bits available earlier
In reply to Roger Pau MonnéQuoted 3 lines · Roger Pau Monné
Quoted 2 lines
+ /* This must come before e820 code becuause it sets
paddr_bits. */^ because
Fixed. Thanks.
Wei.
Quoted 2 lines
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
In reply to Wei LiuQuoted 38 lines · Wei Liu
These functions will be used later to make hypercalls to Hyper-V.
Signed-off-by Wei Liu <[email protected]>---
v5:
1. Switch back to direct call
2. Fix some issues pointed out by JanI tried using the
asm(".equ ..")trick but hit a problem with %c again.mm.c:5736:5: error: invalid 'asm': operand is not a condition code, invalid operand code 'c'
asm ( ".equHV_HCALL_PAGE, %c0; .globalHV_HCALL_PAGE"--- MAINTAINERS | 1 + xen/arch/x86/guest/hyperv/hyperv.c | 6 ++ xen/arch/x86/xen.lds.S | 4 + xen/include/asm-x86/fixmap.h | 3 +- xen/include/asm-x86/guest/hyperv-hcall.h | 96 ++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 xen/include/asm-x86/guest/hyperv-hcall.hMAINTAINERS +1
-0@@ -519,6 +519,7 @@ S: Supported F: xen/arch/x86/guest/hyperv/ F: xen/arch/x86/hvm/viridian/ F: xen/include/asm-x86/guest/hyperv.h +F: xen/include/asm-x86/guest/hyperv-hcall.h F: xen/include/asm-x86/guest/hyperv-tlfs.h F: xen/include/asm-x86/hvm/viridian.hxen/arch/x86/guest/hyperv/hyperv.c +0
-0
xen/arch/x86/guest/hyperv/hyperv.c static const struct hypervisor_ops ops = { · line 129
Quoted 7 lines
xen/arch/x86/guest/hyperv/hyperv.c +4
-0@@ -123,6 +123,12 @@ static const struct hypervisor_ops ops = { .setup = setup, }; +static void __maybe_unused build_assertions (void ) +{ +/* We use 1 in linker script */ +BUILD_BUG_ON (FIX_X_HYPERV_HCALL !=1 );
I wouldn't mind if this was placed together with the hypercall page setup instead of creating a dummy function for it.
Quoted 10 lines
xen/arch/x86/guest/hyperv/hyperv.c +2
-0+} +/* * Local variables: * mode: C xen/arch/x86/xen.lds.S +0
-0
xen/arch/x86/xen.lds.S SECTIONS · line 333
Quoted 5 lines
xen/arch/x86/xen.lds.S +2
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endif +#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1));
I assume there's no way to use FIX_X_HYPERV_HCALL because it's an enum?
Quoted 18 lines
xen/arch/x86/xen.lds.S +2
-0+#endif + /* Sections to be discarded */ /DISCARD/ : { *(.exit.text)xen/include/asm-x86/fixmap.h +1
-0@@ -16,6 +16,7 @@#define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE)#define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE) +#define __fix_x_to_virt (x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT))#ifndef __ASSEMBLY__
xen/include/asm-x86/fixmap.h extern void __set_fixmap_x( · line 114
Quoted 6 lines
xen/include/asm-x86/fixmap.h +0
-2@@ -110,8 +111,6 @@ extern void __set_fixmap_x(#define clear_fixmap_x (idx) __set_fixmap_x(idx, 0, 0) -#define __fix_x_to_virt (x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT)) -#define fix_x_to_virt (x) ((void *)__fix_x_to_virt(x))
This seems like some unrelated code movement?
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 07/12] x86/hyperv: setup hypercall page
In reply to Wei LiuQuoted 84 lines · Wei Liu
Quoted 83 lines · Roger Pau Monné
Quoted 70 lines · Wei Liu
Quoted 45 lines · Roger Pau Monné
Quoted 44 lines · Wei Liu
Hyper-V uses a technique called overlay page for its hypercall page. It will insert a backing page to the guest when the hypercall functionality is enabled. That means we can use a page that is not backed by real memory for hypercall page.
Use the top-most addressable page for that purpose. Adjust e820 code accordingly.
We also need to register Xen's guest OS ID to Hyper-V. Use
0x3as the vendor ID. Fix the comment inhyperv-tlfs.hwhile at it.Signed-off-by Wei Liu <[email protected]>---
v5:
1. usehypervisor_reserve_top_pages
2. add a macro for hypercall page mfn
3. address other misc commentsv4:
1. Use fixmap
2. Follow routines listed in TLFS--- xen/arch/x86/e820.c | 5 +++ xen/arch/x86/guest/hyperv/hyperv.c | 57 +++++++++++++++++++++++-- xen/include/asm-x86/guest/hyperv-tlfs.h | 5 ++- xen/include/asm-x86/guest/hyperv.h | 3 ++ 4 files changed, 65 insertions(+), 5 deletions(-)xen/arch/x86/e820.c +1
-0@@ -343,6 +343,7 @@ static unsigned long __init find_max_pfn(void) {unsigned int i;unsigned long max_pfn =0 ; +unsigned long top_pfn = ((1ull << paddr_bits) -1 ) >>PAGE_SHIFT ;for (i =0 ; i < e820.nr_map; i++) {unsigned long start, end;@@ -357,6 +358,10 @@ static unsigned long __init find_max_pfn(void) max_pfn = end; }Quoted 10 lines
xen/arch/x86/e820.c static unsigned long __init find_max_pfn(void) · line 363
Quoted 3 lines
xen/arch/x86/e820.c +3
-0+ top_pfn -=hypervisor_reserve_top_pages (); +if ( max_pfn >= top_pfn ) + max_pfn = top_pfn;Hm, I'm not sure I see the point of this. The value returned by
find_max_pfnis the maximum RAM address found in the memory map, but the physical address you are using to map the hypercall page is almost certainly much higher than the maximum address found in the physmap (and certainly not RAM), and hence I'm not sure what's the point of this.Yes, the keyword is "almost certainly". :-)
This is done for correctness's sake. I don't expect in practice there would be a configuration that has that much memory, but correctness is still important.
It also guards against weird configuration in which memory is put into that part of the physical address space for whatever reason. I don't know why anyone would do that, but again, we should be prepared for that.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Also you haven't introduced a HyperV implementation of
hypervisor_reserve_top_pagesso far, so it's hard to tell the intend of this.D'oh. That was supposed to be in this patch. I guess I forgot to commit that hunk!
That function for Hyper-V is going to return 1 (page).
But that would likely be wrong, unless the memory map has a RAM region that expands up to (1 <<
paddr_bits)?
Quoted 7 lines
Quoted 4 lines
Or else you are just removing a page from the last RAM region in the memory map for no reason.
max_pfnis almost certainly way below (1 <<paddr_bits).Why? The adjustment will not be applied unless RAM overlaps with that reserved region.
Oh, OK, from your previous reply I understood that hypervisor_reserve_top_pages would unconditionally return 1 for HyperV, so that would end up always subtracting 1 page from the last RAM region, even when not overlapping with (1 << paddr_bits).
Quoted 8 lines
Quoted 6 lines
I think what you need is a hook that modifies the memory map and adds a reserved region at ((1 <<
paddr_bits) -PAGE_SIZE) of sizePAGE_SIZE. See wherepv_shim_fixup_e820is used, and I think you want to make this a hypervisor hook and add the HyperV code to reserve the hypercall page in the e820 there.That works for me too. Let's see what other people think.
I think that's the safest way, as you can assure there's nothing in the region to be used by the hypercall page, and you can actually mark it as reserved in the e820.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 10/12] x86/hyperv: provide percpu hypercall input page
In reply to Wei LiuQuoted 11 lines · Wei Liu
Hyper-V's input / output argument must be 8 bytes aligned an not cross page boundary. One way to satisfy those requirements is to use percpu page.
For the foreseeable future we only need to provide input for TLB and APIC hypercalls, so skip setting up an output page.
We will also need to provide an
ap_setuphook for secondary cpus to setup its own input page.Signed-off-by Wei Liu <[email protected]>
Just some nits below.
Quoted 25 lines
---
v5:
1. Adjust to newap_setup
2. Change variable name tohv_pcpu_input_pagev4:
1. Change wording in commit message
2. Prevent leak
3. Introduce a private headerv3:
1. Use xenheap page instead
2. Drop page tracking structure
3. Drop Paul's review tag--- xen/arch/x86/guest/hyperv/hyperv.c | 31 +++++++++++++++++++++++++++++ xen/arch/x86/guest/hyperv/private.h | 29 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 xen/arch/x86/guest/hyperv/private.hxen/arch/x86/guest/hyperv/hyperv.c +0
-0
xen/arch/x86/guest/hyperv/hyperv.c line 33
Quoted 7 lines
xen/arch/x86/guest/hyperv/hyperv.c +3
-0@@ -27,7 +27,10 @@#include <asm/guest/hyperv-tlfs.h> #include <asm/processor.h> +#include "private.h" +struct ms_hyperv_info __read_mostly ms_hyperv; +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_page);
I would drop the 'pcpu_' from the name, as you already know it's per-cpu because of the accessors you have to use.
xen/arch/x86/guest/hyperv/hyperv.c static void __init setup_hypercall_page(void) · line 135
Quoted 10 lines
xen/arch/x86/guest/hyperv/hyperv.c +3
-0static uint64_t generate_guest_id (void ) {@@ -127,14 +130,42 @@ static void __init setup_hypercall_page(void) } } +static int setup_hypercall_pcpu_arg (void ) +{ +void *mapping;
There's no need for the local variable, you can just assign to this_cpu(hv_pcpu_input_page) directly, as a failure will just set it to NULL (as it already was).
xen/arch/x86/guest/hyperv/hyperv.c static void __init setup_hypercall_page(void) · line 144
Quoted 9 lines
xen/arch/x86/guest/hyperv/hyperv.c +9
-0+ +if (this_cpu (hv_pcpu_input_page) ) +return 0 ; + + mapping =alloc_xenheap_page (); +if ( !mapping ) + { +printk ("Failed to allocate hypercall input page for CPU%u\n" , +smp_processor_id ());
I find it clearer to have the CPU%u prefix at the begging of the line, but it's up to you.
xen/arch/x86/guest/hyperv/hyperv.c static void __init setup_hypercall_page(void) · line 157
Quoted 13 lines
xen/arch/x86/guest/hyperv/hyperv.c +10
-0+return -ENOMEM ; + } + +this_cpu (hv_pcpu_input_page) = mapping; + +return 0 ; +} +static void __init setup (void ) {setup_hypercall_page (); +if (setup_hypercall_pcpu_arg () ) +panic ("Hypercall percpu arg setup failed\n" );
Could you add "HyperV hypercall...", just hypercall page is too generic IMO.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
In reply to Roger Pau MonnéQuoted 14 lines · Roger Pau Monné
Quoted 14 lines
xen/arch/x86/guest/hyperv/hyperv.c +2
-0+} +/* * Local variables: * mode: C xen/arch/x86/xen.lds.S +0
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endif
Quoted 6 lines
xen/arch/x86/xen.lds.S SECTIONS · line 333
Quoted 2 lines
xen/arch/x86/xen.lds.S +2
-0+#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1));I assume there's no way to use
FIX_X_HYPERV_HCALLbecause it's an enum?
Yes.
And the trick to generate a symbol didn't work either.
Quoted 19 lines
Quoted 19 lines
xen/arch/x86/xen.lds.S +2
-0+#endif + /* Sections to be discarded */ /DISCARD/ : { *(.exit.text)xen/include/asm-x86/fixmap.h +1
-0@@ -16,6 +16,7 @@#define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE)#define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE) +#define __fix_x_to_virt (x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT))#ifndef __ASSEMBLY__@@ -110,8 +111,6 @@ extern void __set_fixmap_x(
Quoted 8 lines
xen/include/asm-x86/fixmap.h extern void __set_fixmap_x( · line 114
Quoted 5 lines
xen/include/asm-x86/fixmap.h +0
-2#define clear_fixmap_x (idx) __set_fixmap_x(idx, 0, 0) -#define __fix_x_to_virt (x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT)) -#define fix_x_to_virt (x) ((void *)__fix_x_to_virt(x))This seems like some unrelated code movement?
It is required. This section is not supposed to be used in linker script. I have to move that macro ahead.
Quoted 1 line
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
Quoted 22 lines · Wei Liu
Quoted 14 lines · Roger Pau Monné
Quoted 14 lines
xen/arch/x86/guest/hyperv/hyperv.c +2
-0+} +/* * Local variables: * mode: C xen/arch/x86/xen.lds.S +0
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endifQuoted 6 lines
xen/arch/x86/xen.lds.S SECTIONS · line 333
Quoted 2 lines
xen/arch/x86/xen.lds.S +2
-0+#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1));I assume there's no way to use
FIX_X_HYPERV_HCALLbecause it's an enum?
Quoted 3 lines
Yes.
And the trick to generate a symbol didn't work either.
And you must define that symbol in the linker script? It doesn't seem to be used at link time.
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
xen/arch/x86/xen.lds.S +2
-0+#endif + /* Sections to be discarded */ /DISCARD/ : { *(.exit.text)xen/include/asm-x86/fixmap.h +1
-0@@ -16,6 +16,7 @@#define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE)#define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE) +#define __fix_x_to_virt (x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT))#ifndef __ASSEMBLY__@@ -110,8 +111,6 @@ extern void __set_fixmap_x(Quoted 8 lines
xen/include/asm-x86/fixmap.h extern void __set_fixmap_x( · line 114
Quoted 5 lines
xen/include/asm-x86/fixmap.h +0
-2#define clear_fixmap_x (idx) __set_fixmap_x(idx, 0, 0) -#define __fix_x_to_virt (x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT)) -#define fix_x_to_virt (x) ((void *)__fix_x_to_virt(x))This seems like some unrelated code movement?
Quoted 2 lines
It is required. This section is not supposed to be used in linker script. I have to move that macro ahead.
Oh, but you introduce that macro in patch #5, can you place it at the right position when introduced?
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
Quoted 23 lines · Roger Pau Monné
Quoted 22 lines · Wei Liu
Quoted 20 lines · Roger Pau Monné
Quoted 11 lines
xen/arch/x86/guest/hyperv/hyperv.c +2
-0+} +/* * Local variables: * mode: C xen/arch/x86/xen.lds.S +0
-0xen/arch/x86/xen.lds.S SECTIONS · line 333
Quoted 5 lines
xen/arch/x86/xen.lds.S +2
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endif +#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1));I assume there's no way to use
FIX_X_HYPERV_HCALLbecause it's an enum?
Quoted 7 lines
Quoted 3 lines
Yes.
And the trick to generate a symbol didn't work either.
And you must define that symbol in the linker script? It doesn't seem to be used at link time.
I don't follow. I wish I could define and use a symbol in the linker script but couldn't.
As for defining a symbol, see the patch that introduces the executable fixmap facility, in function __set_fixmap_x.
Quoted 28 lines
Quoted 28 lines
Quoted 27 lines
Quoted 18 lines
xen/arch/x86/xen.lds.S +2
-0+#endif + /* Sections to be discarded */ /DISCARD/ : { *(.exit.text)xen/include/asm-x86/fixmap.h +1
-0@@ -16,6 +16,7 @@#define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE)#define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE) +#define __fix_x_to_virt (x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT))#ifndef __ASSEMBLY__xen/include/asm-x86/fixmap.h extern void __set_fixmap_x( · line 114
Quoted 6 lines
xen/include/asm-x86/fixmap.h +0
-2@@ -110,8 +111,6 @@ extern void __set_fixmap_x(#define clear_fixmap_x (idx) __set_fixmap_x(idx, 0, 0) -#define __fix_x_to_virt (x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT)) -#define fix_x_to_virt (x) ((void *)__fix_x_to_virt(x))This seems like some unrelated code movement?
Quoted 5 lines
Quoted 2 lines
It is required. This section is not supposed to be used in linker script. I have to move that macro ahead.
Oh, but you introduce that macro in patch #5, can you place it at the right position when introduced?
It wasn't needed in the linker script until now. I don't mind doing it that way, but sometimes I'm told to now introduce something until it is used. I wish we could be more consistent on this sort of things.
And frankly this sort of change adds no particular value in this series whatsoever.
Wei.
Quoted 2 lines
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 12/12] x86/hyperv: setup VP assist page
In reply to Wei LiuQuoted 37 lines · Wei Liu
VP assist page is rather important as we need to toggle some bits in it for efficient nested virtualisation.
Signed-off-by Wei Liu <[email protected]>---
v5:
1. Deal with error properly instead of always panicking
2. Swap percpu variables declarations' locationv4:
1. Useprivate.h
2. Prevent leakv3:
1. Use xenheap page
2. Dropset_vp_assistv2:
1. UseHV_HYP_PAGE_SHIFTinstead--- xen/arch/x86/guest/hyperv/hyperv.c | 44 ++++++++++++++++++++++++++++- xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 44 insertions(+), 1 deletion(-)xen/arch/x86/guest/hyperv/hyperv.c +1
-0@@ -31,6 +31,7 @@struct ms_hyperv_info __read_mostly ms_hyperv; DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_page); +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_vp_assist); DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index);static uint64_t generate_guest_id (void )
xen/arch/x86/guest/hyperv/hyperv.c static int setup_hypercall_pcpu_arg(void) · line 164
Quoted 9 lines
xen/arch/x86/guest/hyperv/hyperv.c +6
-0@@ -155,16 +156,57 @@ static int setup_hypercall_pcpu_arg(void)return 0 ; } +static int setup_vp_assist (void ) +{ +void *mapping; +uint64_t val; + + mapping =this_cpu (hv_vp_assist);
You could also avoid the usage of the local mapping variable here.
Quoted 6 lines
xen/arch/x86/guest/hyperv/hyperv.c +6
-0+ +if ( !mapping ) + { + mapping =alloc_xenheap_page (); +if ( !mapping ) + {
xen/arch/x86/guest/hyperv/hyperv.c static int setup_hypercall_pcpu_arg(void) · line 180
Quoted 10 lines
xen/arch/x86/guest/hyperv/hyperv.c +10
-0+printk ("Failed to allocate vp_assist page for CPU%u\n" , +smp_processor_id ()); +return -ENOMEM ; + } + +clear_page (mapping); +this_cpu (hv_vp_assist) = mapping; + } + + val = (virt_to_mfn (mapping) <<HV_HYP_PAGE_SHIFT )
There's virt_to_maddr which would avoid the shift.
Quoted 15 lines
xen/arch/x86/guest/hyperv/hyperv.c +10
-0+ | HV_X64_MSR_VP_ASSIST_PAGE_ENABLE; +wrmsrl (HV_X64_MSR_VP_ASSIST_PAGE , val); + +return 0 ; +} +static void __init setup (void ) {setup_hypercall_page (); +if (setup_hypercall_pcpu_arg () )panic ("Hypercall percpu arg setup failed\n" ); + +if (setup_vp_assist () ) +panic ("VP assist page setup failed\n" );
xen/arch/x86/guest/hyperv/hyperv.c static int setup_hypercall_pcpu_arg(void) · line 204
Quoted 10 lines
xen/arch/x86/guest/hyperv/hyperv.c +5
-1}static int ap_setup (void ) { -return setup_hypercall_pcpu_arg (); +int rc; + + rc =setup_hypercall_pcpu_arg (); +if ( rc ) + goto out;
No need for a label, as just returning here would make the function shorter:
rc = setup_hypercall_pcpu_arg();
if ( rc )
return rc;
return setup_vp_assist();
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 02/12] x86/hypervisor: make hypervisor_ap_setup return an error code
In reply to Roger Pau MonnéQuoted 40 lines · Roger Pau Monné
Quoted 1 line · Wei Liu
We want to be able to handle AP setup error in the upper layer.
Thanks, some comments below.
Quoted 35 lines
Signed-off-by Wei Liu <[email protected]>--- xen/arch/x86/guest/hypervisor.c | 6 ++++-- xen/arch/x86/guest/xen/xen.c | 11 +++++++++-- xen/include/asm-x86/guest/hypervisor.h | 6 +++--- 3 files changed, 16 insertions(+), 7 deletions(-)xen/arch/x86/guest/hypervisor.c +4
-2@@ -52,10 +52,12 @@ void __init hypervisor_setup(void) ops->setup (); } -void hypervisor_ap_setup (void ) +int hypervisor_ap_setup (void ) {if ( ops && ops->ap_setup ) - ops->ap_setup (); +return ops->ap_setup (); + +return 0 ; }void hypervisor_resume (void )xen/arch/x86/guest/xen/xen.c +0
-0@@ -257,11 +257,18 @@ static void __init setup(void)init_evtchn (); }
Quoted 12 lines
xen/arch/x86/guest/xen/xen.c static void __init setup(void) · line 265
Quoted 8 lines
xen/arch/x86/guest/xen/xen.c +4
-2-static void ap_setup (void ) +static int ap_setup (void ) { +int rc; +set_vcpu_id (); -map_vcpuinfo (); + rc =map_vcpuinfo ();
map_vcpuinfoshould be changed so that theBUG_ONis removed, and an error is only returned ifVCPUOP_register_vcpu_infofails and vcpu >=XEN_LEGACY_MAX_VCPUS, else no error should be returned.
Done.
Quoted 10 lines
xen/arch/x86/guest/xen/xen.c static void __init setup(void) · line 271
Quoted 7 lines
xen/arch/x86/guest/xen/xen.c +5
-0+if ( rc ) +return rc; +init_evtchn (); + +return 0 ;In order to keep this shorter, you could do:
Quoted 4 lines
if ( !rc )
init_evtchn();return rc;
Done.
Wei.
Quoted 2 lines
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 12/12] x86/hyperv: setup VP assist page
In reply to Durrant, PaulQuoted 7 lines · Paul
xen/arch/x86/guest/hyperv/hyperv.c static int setup_hypercall_pcpu_arg(void) · line 181
Quoted 3 lines
xen/arch/x86/guest/hyperv/hyperv.c +3
-0+ + val = (virt_to_mfn (mapping) <<HV_HYP_PAGE_SHIFT ) + |HV_X64_MSR_VP_ASSIST_PAGE_ENABLE ;Perhaps it would be neater to put the
viridian_page_msrunion intohyperv-tlfs.hand then use that.
Done. Now this series is one patch longer...
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 12/12] x86/hyperv: setup VP assist page
In reply to Roger Pau MonnéQuoted 41 lines · Roger Pau Monné
Quoted 40 lines · Wei Liu
VP assist page is rather important as we need to toggle some bits in it for efficient nested virtualisation.
Signed-off-by Wei Liu <[email protected]>---
v5:
1. Deal with error properly instead of always panicking
2. Swap percpu variables declarations' locationv4:
1. Useprivate.h
2. Prevent leakv3:
1. Use xenheap page
2. Dropset_vp_assistv2:
1. UseHV_HYP_PAGE_SHIFTinstead--- xen/arch/x86/guest/hyperv/hyperv.c | 44 ++++++++++++++++++++++++++++- xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 44 insertions(+), 1 deletion(-)xen/arch/x86/guest/hyperv/hyperv.c +1
-0@@ -31,6 +31,7 @@struct ms_hyperv_info __read_mostly ms_hyperv; DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_page); +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_vp_assist); DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index);static uint64_t generate_guest_id (void )@@ -155,16 +156,57 @@ static int setup_hypercall_pcpu_arg(void)return 0 ; }
Quoted 8 lines
xen/arch/x86/guest/hyperv/hyperv.c static int setup_hypercall_pcpu_arg(void) · line 164
Quoted 6 lines
xen/arch/x86/guest/hyperv/hyperv.c +6
-0+static int setup_vp_assist (void ) +{ +void *mapping; +uint64_t val; + + mapping =this_cpu (hv_vp_assist);You could also avoid the usage of the local mapping variable here.
this_cpu(...) is longer than mapping. But since you ask for the change, I have made the change.
Quoted 11 lines
Quoted 11 lines
xen/arch/x86/guest/hyperv/hyperv.c +10
-0+ +if ( !mapping ) + { + mapping =alloc_xenheap_page (); +if ( !mapping ) + { +printk ("Failed to allocate vp_assist page for CPU%u\n" , +smp_processor_id ()); +return -ENOMEM ; + }
Quoted 8 lines
xen/arch/x86/guest/hyperv/hyperv.c static int setup_hypercall_pcpu_arg(void) · line 180
Quoted 6 lines
xen/arch/x86/guest/hyperv/hyperv.c +6
-0+ +clear_page (mapping); +this_cpu (hv_vp_assist) = mapping; + } + + val = (virt_to_mfn (mapping) <<HV_HYP_PAGE_SHIFT )There's
virt_to_maddrwhich would avoid the shift.
This line is gone.
Quoted 30 lines
Quoted 16 lines
xen/arch/x86/guest/hyperv/hyperv.c +10
-0+ | HV_X64_MSR_VP_ASSIST_PAGE_ENABLE; +wrmsrl (HV_X64_MSR_VP_ASSIST_PAGE , val); + +return 0 ; +} +static void __init setup (void ) {setup_hypercall_page (); +if (setup_hypercall_pcpu_arg () )panic ("Hypercall percpu arg setup failed\n" ); + +if (setup_vp_assist () ) +panic ("VP assist page setup failed\n" );xen/arch/x86/guest/hyperv/hyperv.c static int setup_hypercall_pcpu_arg(void) · line 204
Quoted 10 lines
xen/arch/x86/guest/hyperv/hyperv.c +5
-1}static int ap_setup (void ) { -return setup_hypercall_pcpu_arg (); +int rc; + + rc =setup_hypercall_pcpu_arg (); +if ( rc ) + goto out;No need for a label, as just returning here would make the function shorter:
Quoted 5 lines
rc =
setup_hypercall_pcpu_arg();
if ( rc )return rc;return
setup_vp_assist();
Done.
Wei.
Quoted 2 lines
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 10/12] x86/hyperv: provide percpu hypercall input page
In reply to Roger Pau MonnéQuoted 8 lines · Roger Pau Monné
Quoted 7 lines · Wei Liu
Hyper-V's input / output argument must be 8 bytes aligned an not cross page boundary. One way to satisfy those requirements is to use percpu page.
For the foreseeable future we only need to provide input for TLB and APIC hypercalls, so skip setting up an output page.
Quoted 9 lines
Quoted 4 lines
We will also need to provide an
ap_setuphook for secondary cpus to setup its own input page.Signed-off-by Wei Liu <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>Just some nits below.
All comments addressed.
Wei.
Quoted 2 lines
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
In reply to Wei LiuQuoted 26 lines · Wei Liu
Quoted 25 lines · Roger Pau Monné
Quoted 24 lines · Wei Liu
Quoted 14 lines · Roger Pau Monné
Quoted 14 lines
xen/arch/x86/guest/hyperv/hyperv.c +2
-0+} +/* * Local variables: * mode: C xen/arch/x86/xen.lds.S +0
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endifQuoted 6 lines
xen/arch/x86/xen.lds.S SECTIONS · line 333
Quoted 2 lines
xen/arch/x86/xen.lds.S +2
-0+#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1));I assume there's no way to use
FIX_X_HYPERV_HCALLbecause it's an enum?Yes.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
And the trick to generate a symbol didn't work either.
And you must define that symbol in the linker script? It doesn't seem to be used at link time.
I don't follow. I wish I could define and use a symbol in the linker script but couldn't.
It's likely my fault, as I haven't been following the patch series in that much detail. I assume this is done in order to generate better code, rather than doing something like:
void *hv_hcall_page = fix_x_to_virt(FIX_X_HYPERV_HCALL);
In a C file somewhere when the hypercall page is setup?
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
Quoted 36 lines · Roger Pau Monné
Quoted 26 lines · Wei Liu
Quoted 25 lines · Roger Pau Monné
Quoted 24 lines · Wei Liu
Quoted 14 lines · Roger Pau Monné
Quoted 14 lines
xen/arch/x86/guest/hyperv/hyperv.c +2
-0+} +/* * Local variables: * mode: C xen/arch/x86/xen.lds.S +0
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endifQuoted 6 lines
xen/arch/x86/xen.lds.S SECTIONS · line 333
Quoted 2 lines
xen/arch/x86/xen.lds.S +2
-0+#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1));I assume there's no way to use
FIX_X_HYPERV_HCALLbecause it's an enum?Yes.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
And the trick to generate a symbol didn't work either.
And you must define that symbol in the linker script? It doesn't seem to be used at link time.
I don't follow. I wish I could define and use a symbol in the linker script but couldn't.
Quoted 7 lines
It's likely my fault, as I haven't been following the patch series in that much detail. I assume this is done in order to generate better code, rather than doing something like:
void
*hv_hcall_page=fix_x_to_virt(FIX_X_HYPERV_HCALL);In a C file somewhere when the hypercall page is setup?
Andrew wanted badly to be able to use direct call in the hypercall functions. This is what we managed to come up with so far.
I think what you wrote will still result in an indirect call.
(The majority of my time spent on this series has been extending Xen to do more than it could before.)
Wei.
Quoted 2 lines
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
Quoted 45 lines · Wei Liu
Quoted 36 lines · Roger Pau Monné
Quoted 26 lines · Wei Liu
Quoted 25 lines · Roger Pau Monné
Quoted 24 lines · Wei Liu
Quoted 14 lines · Roger Pau Monné
Quoted 14 lines
(quoted diff) +2
-0+} + /* * Local variables: * mode: Cxen/arch/x86/xen.lds.S +0
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endifQuoted 6 lines
xen/arch/x86/xen.lds.S SECTIONS · line 333
Quoted 2 lines
xen/arch/x86/xen.lds.S +2
-0+#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1));I assume there's no way to use
FIX_X_HYPERV_HCALLbecause it's an enum?Yes.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
And the trick to generate a symbol didn't work either.
And you must define that symbol in the linker script? It doesn't seem to be used at link time.
I don't follow. I wish I could define and use a symbol in the linker script but couldn't.
Quoted 7 lines
It's likely my fault, as I haven't been following the patch series in that much detail. I assume this is done in order to generate better code, rather than doing something like:
void
*hv_hcall_page=fix_x_to_virt(FIX_X_HYPERV_HCALL);In a C file somewhere when the hypercall page is setup?
Quoted 7 lines
Andrew wanted badly to be able to use direct call in the hypercall functions. This is what we managed to come up with so far.
I think what you wrote will still result in an indirect call.
(The majority of my time spent on this series has been extending Xen to do more than it could before.)
Ack, sorry to bother you with questions you have already answered. Not sure whether defining hv_hcall_page as a global const would make much difference. Could you maybe use something like alternative_vcall patching to get rid of the indirection?
I have to admit I find this all quite hard to follow and reason about, likely because of the mix of C, assembly, and linker script to build this machinery, but that doesn't mean this isn't the best way.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
Quoted 49 lines · Roger Pau Monné
Quoted 48 lines · Wei Liu
Quoted 36 lines · Roger Pau Monné
Quoted 26 lines · Wei Liu
Quoted 25 lines · Roger Pau Monné
Quoted 24 lines · Wei Liu
Quoted 14 lines · Roger Pau Monné
Quoted 14 lines
(quoted diff) +2
-0+} + /* * Local variables: * mode: Cxen/arch/x86/xen.lds.S +0
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endifQuoted 6 lines
xen/arch/x86/xen.lds.S SECTIONS · line 333
Quoted 2 lines
xen/arch/x86/xen.lds.S +2
-0+#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1));I assume there's no way to use
FIX_X_HYPERV_HCALLbecause it's an enum?Yes.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
And the trick to generate a symbol didn't work either.
And you must define that symbol in the linker script? It doesn't seem to be used at link time.
I don't follow. I wish I could define and use a symbol in the linker script but couldn't.
Quoted 7 lines
It's likely my fault, as I haven't been following the patch series in that much detail. I assume this is done in order to generate better code, rather than doing something like:
void
*hv_hcall_page=fix_x_to_virt(FIX_X_HYPERV_HCALL);In a C file somewhere when the hypercall page is setup?
Andrew wanted badly to be able to use direct call in the hypercall functions. This is what we managed to come up with so far.
Quoted 6 lines
Quoted 4 lines
I think what you wrote will still result in an indirect call.
(The majority of my time spent on this series has been extending Xen to do more than it could before.)
Ack, sorry to bother you with questions you have already answered. Not
No worries. I value your feedback. And having more people understand what is going on is important to the project.
Quoted 3 lines
sure whether defining
hv_hcall_pageas a global const would make much difference. Could you maybe use something likealternative_vcallpatching to get rid of the indirection?
Tried that and didn't work either. :-(
Quoted 5 lines
I have to admit I find this all quite hard to follow and reason about, likely because of the mix of C, assembly, and linker script to build this machinery, but that doesn't mean this isn't the best way.
Yes, a lot of trickeries are used to make this work. Not the most elegant combination I would say, but it does achieve what is desired.
Wei.
Quoted 1 line
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
Quoted 57 lines · Wei Liu
Quoted 49 lines · Roger Pau Monné
Quoted 48 lines · Wei Liu
Quoted 36 lines · Roger Pau Monné
Quoted 26 lines · Wei Liu
Quoted 25 lines · Roger Pau Monné
Quoted 24 lines · Wei Liu
Quoted 14 lines · Roger Pau Monné
Quoted 14 lines
(quoted diff) +2
-0+} + /* * Local variables: * mode: Cxen/arch/x86/xen.lds.S +0
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endifQuoted 6 lines
xen/arch/x86/xen.lds.S SECTIONS · line 333
Quoted 2 lines
xen/arch/x86/xen.lds.S +2
-0+#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1));I assume there's no way to use
FIX_X_HYPERV_HCALLbecause it's an enum?Yes.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
And the trick to generate a symbol didn't work either.
And you must define that symbol in the linker script? It doesn't seem to be used at link time.
I don't follow. I wish I could define and use a symbol in the linker script but couldn't.
Quoted 7 lines
It's likely my fault, as I haven't been following the patch series in that much detail. I assume this is done in order to generate better code, rather than doing something like:
void
*hv_hcall_page=fix_x_to_virt(FIX_X_HYPERV_HCALL);In a C file somewhere when the hypercall page is setup?
Andrew wanted badly to be able to use direct call in the hypercall functions. This is what we managed to come up with so far.
Quoted 6 lines
Quoted 4 lines
I think what you wrote will still result in an indirect call.
(The majority of my time spent on this series has been extending Xen to do more than it could before.)
Ack, sorry to bother you with questions you have already answered. Not
Quoted 8 lines
No worries. I value your feedback. And having more people understand what is going on is important to the project.
Quoted 3 lines
sure whether defining
hv_hcall_pageas a global const would make much difference. Could you maybe use something likealternative_vcallpatching to get rid of the indirection?Tried that and didn't work either. :-(
How do you check whether there's an indirect call or not when using alternative_vcall?
It's my understanding that in that case the patching will happen at runtime, and hence the generated assembly code would still use an indirect call, but once patched at runtime it should become a direct call.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
Quoted 61 lines · Roger Pau Monné
Quoted 60 lines · Wei Liu
Quoted 49 lines · Roger Pau Monné
Quoted 48 lines · Wei Liu
Quoted 36 lines · Roger Pau Monné
Quoted 26 lines · Wei Liu
Quoted 25 lines · Roger Pau Monné
Quoted 24 lines · Wei Liu
Quoted 14 lines · Roger Pau Monné
Quoted 14 lines
(quoted diff) +2
-0+} + /* * Local variables: * mode: Cxen/arch/x86/xen.lds.S +0
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endifQuoted 6 lines
xen/arch/x86/xen.lds.S SECTIONS · line 333
Quoted 2 lines
xen/arch/x86/xen.lds.S +2
-0+#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1));I assume there's no way to use
FIX_X_HYPERV_HCALLbecause it's an enum?Yes.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
And the trick to generate a symbol didn't work either.
And you must define that symbol in the linker script? It doesn't seem to be used at link time.
I don't follow. I wish I could define and use a symbol in the linker script but couldn't.
Quoted 7 lines
It's likely my fault, as I haven't been following the patch series in that much detail. I assume this is done in order to generate better code, rather than doing something like:
void
*hv_hcall_page=fix_x_to_virt(FIX_X_HYPERV_HCALL);In a C file somewhere when the hypercall page is setup?
Andrew wanted badly to be able to use direct call in the hypercall functions. This is what we managed to come up with so far.
Quoted 6 lines
Quoted 4 lines
I think what you wrote will still result in an indirect call.
(The majority of my time spent on this series has been extending Xen to do more than it could before.)
Ack, sorry to bother you with questions you have already answered. Not
No worries. I value your feedback. And having more people understand what is going on is important to the project.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
sure whether defining
hv_hcall_pageas a global const would make much difference. Could you maybe use something likealternative_vcallpatching to get rid of the indirection?Tried that and didn't work either. :-(
How do you check whether there's an indirect call or not when using
alternative_vcall?
I didn't check, because alternative_vcall didn't compile in that case.
Quoted 4 lines
It's my understanding that in that case the patching will happen at runtime, and hence the generated assembly code would still use an indirect call, but once patched at runtime it should become a direct call.
It didn't even compile. :-(
Wei.
Quoted 2 lines
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 07/12] x86/hyperv: setup hypercall page
In reply to Roger Pau MonnéQuoted 105 lines · Roger Pau Monné
Quoted 84 lines · Wei Liu
Quoted 83 lines · Roger Pau Monné
Quoted 70 lines · Wei Liu
Quoted 45 lines · Roger Pau Monné
Quoted 44 lines · Wei Liu
Hyper-V uses a technique called overlay page for its hypercall page. It will insert a backing page to the guest when the hypercall functionality is enabled. That means we can use a page that is not backed by real memory for hypercall page.
Use the top-most addressable page for that purpose. Adjust e820 code accordingly.
We also need to register Xen's guest OS ID to Hyper-V. Use
0x3as the vendor ID. Fix the comment inhyperv-tlfs.hwhile at it.Signed-off-by Wei Liu <[email protected]>---
v5:
1. usehypervisor_reserve_top_pages
2. add a macro for hypercall page mfn
3. address other misc commentsv4:
1. Use fixmap
2. Follow routines listed in TLFS--- xen/arch/x86/e820.c | 5 +++ xen/arch/x86/guest/hyperv/hyperv.c | 57 +++++++++++++++++++++++-- xen/include/asm-x86/guest/hyperv-tlfs.h | 5 ++- xen/include/asm-x86/guest/hyperv.h | 3 ++ 4 files changed, 65 insertions(+), 5 deletions(-)xen/arch/x86/e820.c +1
-0@@ -343,6 +343,7 @@ static unsigned long __init find_max_pfn(void) {unsigned int i;unsigned long max_pfn =0 ; +unsigned long top_pfn = ((1ull << paddr_bits) -1 ) >>PAGE_SHIFT ;for (i =0 ; i < e820.nr_map; i++) {unsigned long start, end;@@ -357,6 +358,10 @@ static unsigned long __init find_max_pfn(void) max_pfn = end; }Quoted 10 lines
xen/arch/x86/e820.c static unsigned long __init find_max_pfn(void) · line 363
Quoted 3 lines
xen/arch/x86/e820.c +3
-0+ top_pfn -=hypervisor_reserve_top_pages (); +if ( max_pfn >= top_pfn ) + max_pfn = top_pfn;Hm, I'm not sure I see the point of this. The value returned by
find_max_pfnis the maximum RAM address found in the memory map, but the physical address you are using to map the hypercall page is almost certainly much higher than the maximum address found in the physmap (and certainly not RAM), and hence I'm not sure what's the point of this.Yes, the keyword is "almost certainly". :-)
This is done for correctness's sake. I don't expect in practice there would be a configuration that has that much memory, but correctness is still important.
It also guards against weird configuration in which memory is put into that part of the physical address space for whatever reason. I don't know why anyone would do that, but again, we should be prepared for that.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Also you haven't introduced a HyperV implementation of
hypervisor_reserve_top_pagesso far, so it's hard to tell the intend of this.D'oh. That was supposed to be in this patch. I guess I forgot to commit that hunk!
That function for Hyper-V is going to return 1 (page).
But that would likely be wrong, unless the memory map has a RAM region that expands up to (1 <<
paddr_bits)?Quoted 7 lines
Quoted 4 lines
Or else you are just removing a page from the last RAM region in the memory map for no reason.
max_pfnis almost certainly way below (1 <<paddr_bits).Why? The adjustment will not be applied unless RAM overlaps with that reserved region.
Oh, OK, from your previous reply I understood that
hypervisor_reserve_top_pageswould unconditionally return 1 for HyperV, so that would end up always subtracting 1 page from the last RAM region, even when not overlapping with (1 <<paddr_bits).Quoted 7 lines
Quoted 6 lines
I think what you need is a hook that modifies the memory map and adds a reserved region at ((1 <<
paddr_bits) -PAGE_SIZE) of sizePAGE_SIZE. See wherepv_shim_fixup_e820is used, and I think you want to make this a hypervisor hook and add the HyperV code to reserve the hypercall page in the e820 there.
Quoted 5 lines
Quoted 1 line
That works for me too. Let's see what other people think.
I think that's the safest way, as you can assure there's nothing in the region to be used by the hypercall page, and you can actually mark it as reserved in the e820.
I like this idea. I will post a new version shortly.
Wei.
Quoted 2 lines
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 05/12] x86: provide executable fixmap facility
In reply to Wei LiuQuoted 14 lines · Wei Liu
xen/arch/x86/mm.c int destroy_xen_mappings(unsigned long s, unsigned long e) · line 5735
Quoted 10 lines · Wei Liu
xen/arch/x86/mm.c +9
-0+void __set_fixmap_x ( +enum fixed_addresses_x idx,unsigned long mfn,unsigned long flags) +{ +BUG_ON (idx >= __end_of_fixed_addresses_x || idx <=FIX_X_RESERVED ); +map_pages_to_xen (__fix_x_to_virt (idx),_mfn (mfn),1 , flags); + +/* Generate a symbol to be used in linker script */ + asm (".equ FIXADDR_X_SIZE, %c0; .global FIXADDR_X_SIZE" + ::"i" (__end_of_fixed_addresses_x <<PAGE_SHIFT ) );The (
__end<< SHIFT) part can be replaced withFIXADDR_X_SIZE(the macro defined infixmap.h) directly.
I also discover that this snippet to generate symbol should be moved else where because if Hyper-V support is compiled out, this function has no user. That causes it to be DCE'd. FIXADDR_X_SIZE would be gone and linking would fail.
I have moved this to arch_init_memory. Its storage will be reclaimed during runtime, but this symbol is not used anywhere else in code, so we should be fine.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 05/12] x86: provide executable fixmap facility
Quoted 16 lines · Wei Liu
Quoted 14 lines · Wei Liu
xen/arch/x86/mm.c int destroy_xen_mappings(unsigned long s, unsigned long e) · line 5735
Quoted 10 lines · Wei Liu
xen/arch/x86/mm.c +9
-0+void __set_fixmap_x ( +enum fixed_addresses_x idx,unsigned long mfn,unsigned long flags) +{ +BUG_ON (idx >= __end_of_fixed_addresses_x || idx <=FIX_X_RESERVED ); +map_pages_to_xen (__fix_x_to_virt (idx),_mfn (mfn),1 , flags); + +/* Generate a symbol to be used in linker script */ + asm (".equ FIXADDR_X_SIZE, %c0; .global FIXADDR_X_SIZE" + ::"i" (__end_of_fixed_addresses_x <<PAGE_SHIFT ) );The (
__end<< SHIFT) part can be replaced withFIXADDR_X_SIZE(the macro defined infixmap.h) directly.
Quoted 8 lines
I also discover that this snippet to generate symbol should be moved else where because if Hyper-V support is compiled out, this function has no user. That causes it to be DCE'd.
FIXADDR_X_SIZEwould be gone and linking would fail.I have moved this to
arch_init_memory. Its storage will be reclaimed during runtime, but this symbol is not used anywhere else in code, so we should be fine.
Storage? This is a constant, i.e. just a symbol without any storage. Therefore an __init function is a very good place to put it. It could also live outside of any function, if only file scope asm()-s finally permitted [certain] inputs.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 05/12] x86: provide executable fixmap facility
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Wei Liu
Quoted 14 lines · Wei Liu
xen/arch/x86/mm.c int destroy_xen_mappings(unsigned long s, unsigned long e) · line 5735
Quoted 10 lines · Wei Liu
xen/arch/x86/mm.c +9
-0+void __set_fixmap_x ( +enum fixed_addresses_x idx,unsigned long mfn,unsigned long flags) +{ +BUG_ON (idx >= __end_of_fixed_addresses_x || idx <=FIX_X_RESERVED ); +map_pages_to_xen (__fix_x_to_virt (idx),_mfn (mfn),1 , flags); + +/* Generate a symbol to be used in linker script */ + asm (".equ FIXADDR_X_SIZE, %c0; .global FIXADDR_X_SIZE" + ::"i" (__end_of_fixed_addresses_x <<PAGE_SHIFT ) );The (
__end<< SHIFT) part can be replaced withFIXADDR_X_SIZE(the macro defined infixmap.h) directly.I also discover that this snippet to generate symbol should be moved else where because if Hyper-V support is compiled out, this function has no user. That causes it to be DCE'd.
FIXADDR_X_SIZEwould be gone and linking would fail.
Quoted 5 lines
Quoted 3 lines
I have moved this to
arch_init_memory. Its storage will be reclaimed during runtime, but this symbol is not used anywhere else in code, so we should be fine.Storage? This is a constant, i.e. just a symbol without any
"Its" meaning arch_init_memory, but I wasn't clear. Sorry.
Quoted 3 lines
storage. Therefore an
__initfunction is a very good place to put it. It could also live outside of any function, if only file scope asm()-s finally permitted [certain] inputs.
Tried putting in in file scope, didn't work.
Wei.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 03/12] x86/smp: don't online cpu if hypervisor_ap_setup fails
In reply to Wei LiuQuoted 14 lines · Wei Liu
Push
hypervisor_ap_setupdown tosmp_callin.Take the chance to replace
xen_guestwithcpu_has_hypervisor.Signed-off-by Wei Liu <[email protected]>--- xen/arch/x86/smpboot.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)xen/arch/x86/smpboot.c +0
-0
xen/arch/x86/smpboot.c static void smp_callin(void) · line 207
Quoted 9 lines
xen/arch/x86/smpboot.c +6
-0@@ -199,6 +199,13 @@ static void smp_callin(void) goto halt; } +if ( cpu_has_hypervisor && (rc =hypervisor_ap_setup ()) !=0 ) + { +printk ("CPU%d: Failed to initialise hypervisor functions. Not coming online.\n" , cpu); + cpu_error = rc; + goto halt; + }
There are a few things done up from here which may possibly better come after hypervisor interface setup (the two APIC related calls in particular). Are you sure you can safely move it this far down in the function?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Jan Beulich
Acked-byRe: [Xen-devel] [PATCH v5 04/12] x86: make paddr_bits available earlier
In reply to Wei LiuQuoted 6 lines · Wei Liu
Quoted 3 lines · Roger Pau Monné
Quoted 2 lines
+ /* This must come before e820 code becuause it sets
paddr_bits. */^ because
Fixed. Thanks.
And then
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 07/12] x86/hyperv: setup hypercall page
In reply to Wei LiuQuoted 8 lines · Wei Liu
Quoted 5 lines · Roger Pau Monné
I think what you need is a hook that modifies the memory map and adds a reserved region at ((1 <<
paddr_bits) -PAGE_SIZE) of sizePAGE_SIZE. See wherepv_shim_fixup_e820is used, and I think you want to make this a hypervisor hook and add the HyperV code to reserve the hypercall page in the e820 there.That works for me too. Let's see what other people think.
The idea lgtm, pending seeing it actually carried out.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 03/12] x86/smp: don't online cpu if hypervisor_ap_setup fails
In reply to Jan BeulichQuoted 18 lines · Jan Beulich
Quoted 17 lines · Wei Liu
Push
hypervisor_ap_setupdown tosmp_callin.Take the chance to replace
xen_guestwithcpu_has_hypervisor.Signed-off-by Wei Liu <[email protected]>--- xen/arch/x86/smpboot.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)xen/arch/x86/smpboot.c +0
-0@@ -199,6 +199,13 @@ static void smp_callin(void) goto halt; }
Quoted 11 lines
xen/arch/x86/smpboot.c static void smp_callin(void) · line 207
Quoted 6 lines
xen/arch/x86/smpboot.c +6
-0+if ( cpu_has_hypervisor && (rc =hypervisor_ap_setup ()) !=0 ) + { +printk ("CPU%d: Failed to initialise hypervisor functions. Not coming online.\n" , cpu); + cpu_error = rc; + goto halt; + }There are a few things done up from here which may possibly better come after hypervisor interface setup (the two APIC related calls in particular). Are you sure you can safely move it this far down in the function?
Xen guest's usage of APIC is no different than, say, hvm's usage. If hvm can be this far down, Xen / Hyper-V can, too.
Furthermore, APIC code has no dependency on guest code.
Wei.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
In reply to Wei LiuQuoted 22 lines · Wei Liu
Quoted 14 lines · Roger Pau Monné
Quoted 14 lines
xen/arch/x86/guest/hyperv/hyperv.c +2
-0+} +/* * Local variables: * mode: C xen/arch/x86/xen.lds.S +0
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endifQuoted 6 lines
xen/arch/x86/xen.lds.S SECTIONS · line 333
Quoted 2 lines
xen/arch/x86/xen.lds.S +2
-0+#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1));I assume there's no way to use
FIX_X_HYPERV_HCALLbecause it's an enum?
Quoted 3 lines
Yes.
And the trick to generate a symbol didn't work either.
I guess I need an explanation here. Aiui you don't really need the definition to be in the linker script, and it could as well be in e.g. assembly code. How does the same .equ approach not work in this case?
Also I think the above will trigger the warnings Andrew had mentioned (on irc?) from the code generating xen.efi's runtime relocation table. Just like in
ASSERT(__2M_rwdata_end <= XEN_VIRT_END - XEN_VIRT_START + __XEN_VIRT_START -
NR_CPUS * PAGE_SIZE,
"Xen image overlaps stubs area")
I think you need to adjust by __XEN_VIRT_START - XEN_VIRT_START.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Wei Liu
Quoted 20 lines · Roger Pau Monné
Quoted 11 lines
xen/arch/x86/guest/hyperv/hyperv.c +2
-0+} +/* * Local variables: * mode: C xen/arch/x86/xen.lds.S +0
-0xen/arch/x86/xen.lds.S SECTIONS · line 333
Quoted 5 lines
xen/arch/x86/xen.lds.S +2
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endif +#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1));I assume there's no way to use
FIX_X_HYPERV_HCALLbecause it's an enum?
Quoted 9 lines
Quoted 3 lines
Yes.
And the trick to generate a symbol didn't work either.
I guess I need an explanation here. Aiui you don't really need the definition to be in the linker script, and it could as well be in e.g. assembly code. How does the same .equ approach not work in this case?
In commit message:
mm.c:5736:5: error: invalid 'asm': operand is not a condition code, invalid operand code 'c'
asm ( ".equ HV_HCALL_PAGE, %c0; .global HV_HCALL_PAGE"
ISTR you once mentioned in IRC that there is a way around this (with a new modifier / qualifier), but I don't have the log anymore.
Quoted 4 lines
Also I think the above will trigger the warnings Andrew had mentioned (on irc?) from the code generating xen.efi's runtime relocation table. Just like in
It was a reply to v4. <[email protected]>
I don't see the warning with this patch.
Wei.
Quoted 7 lines
ASSERT(__2M_rwdata_end <=
XEN_VIRT_END-XEN_VIRT_START+__XEN_VIRT_START-
NR_CPUS*PAGE_SIZE,
"Xen image overlaps stubs area")I think you need to adjust by
__XEN_VIRT_START-XEN_VIRT_START.Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
In reply to Wei LiuQuoted 4 lines · Wei Liu
I tried using the
asm(".equ ..")trick but hit a problem with %c again.mm.c:5736:5: error: invalid 'asm': operand is not a condition code, invalid operand code 'c'
asm ( ".equHV_HCALL_PAGE, %c0; .globalHV_HCALL_PAGE"
Would you mind also indicating what the input operand actually was? According to my looking at gcc sources when you first mentioned this (on irc iirc), much depends on it actually be recognizable as a constant by the compiler.
xen/include/asm-x86/guest/hyperv-hcall.h line 34
Quoted 5 lines
xen/include/asm-x86/guest/hyperv-hcall.h new file +5
-0+static inline uint64_t hv_do_hypercall (uint64_t control,paddr_t input_addr, +paddr_t output_addr) +{ +uint64_t status; + register unsigned long r8 asm("r8") = output_addr;
I guess strictly speaking this wants to be asm ( "r8" ), albeit I now realize that I've similarly not played by style in alternative_callN(). In the end I guess - either way.
xen/include/asm-x86/guest/hyperv-hcall.h line 39
Quoted 4 lines
xen/include/asm-x86/guest/hyperv-hcall.h new file +4
-0+ asmvolatile ("call hv_hcall_page" + :"=a" (status),"+c" (control), + "+d" (input_addr) ASM_CALL_CONSTRAINT + : "r" (r8)
Why "+c" and "+d" but just "r"? If r8 gets treated differently from rcx and rdx, please attach a brief comment.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 11/12] x86/hyperv: retrieve vp_index from Hyper-V
In reply to Wei LiuQuoted 9 lines · Wei Liu
This will be useful when invoking hypercall that targets specific vcpu(s).
Signed-off-by Wei Liu <[email protected]>Reviewed-by Paul Durrant <[email protected]>Acked-by Jan Beulich <[email protected]>---
v5:
1. Add Jan's Ack.
And I now realize that it's actually irrelevant for this
Quoted 3 lines
xen/arch/x86/guest/hyperv/hyperv.c | 5 +++++ xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 6 insertions(+)
set of changed files. (Feel free to keep, of course.)
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Jan Beulich
Reviewed-byRe: [Xen-devel] [PATCH v5 03/12] x86/smp: don't online cpu if hypervisor_ap_setup fails
In reply to Wei LiuQuoted 31 lines · Wei Liu
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Wei Liu
Push
hypervisor_ap_setupdown tosmp_callin.Take the chance to replace
xen_guestwithcpu_has_hypervisor.Signed-off-by Wei Liu <[email protected]>--- xen/arch/x86/smpboot.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)xen/arch/x86/smpboot.c +0
-0@@ -199,6 +199,13 @@ static void smp_callin(void) goto halt; }Quoted 11 lines
xen/arch/x86/smpboot.c static void smp_callin(void) · line 207
Quoted 6 lines
xen/arch/x86/smpboot.c +6
-0+if ( cpu_has_hypervisor && (rc =hypervisor_ap_setup ()) !=0 ) + { +printk ("CPU%d: Failed to initialise hypervisor functions. Not coming online.\n" , cpu); + cpu_error = rc; + goto halt; + }There are a few things done up from here which may possibly better come after hypervisor interface setup (the two APIC related calls in particular). Are you sure you can safely move it this far down in the function?
Quoted 4 lines
Xen guest's usage of APIC is no different than, say, hvm's usage. If hvm can be this far down, Xen / Hyper-V can, too.
Furthermore, APIC code has no dependency on guest code.
Hmm, okay, there's no way for a HVM guest to run without LAPIC emulation right now. This should be fine then:
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
In reply to Wei LiuQuoted 34 lines · Wei Liu
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Wei Liu
Quoted 20 lines · Roger Pau Monné
Quoted 11 lines
xen/arch/x86/guest/hyperv/hyperv.c +2
-0+} +/* * Local variables: * mode: C xen/arch/x86/xen.lds.S +0
-0xen/arch/x86/xen.lds.S SECTIONS · line 333
Quoted 5 lines
xen/arch/x86/xen.lds.S +2
-0@@ -329,6 +329,10 @@ SECTIONS efi = .; #endif +#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1));I assume there's no way to use
FIX_X_HYPERV_HCALLbecause it's an enum?Quoted 9 lines
Quoted 3 lines
Yes.
And the trick to generate a symbol didn't work either.
I guess I need an explanation here. Aiui you don't really need the definition to be in the linker script, and it could as well be in e.g. assembly code. How does the same .equ approach not work in this case?
Quoted 5 lines
In commit message:
mm.c:5736:5: error: invalid 'asm': operand is not a condition code, invalid operand code 'c'
asm ( ".equHV_HCALL_PAGE, %c0; .globalHV_HCALL_PAGE"
But this lacks the other half of the asm().
Quoted 2 lines
ISTR you once mentioned in IRC that there is a way around this (with a new modifier / qualifier), but I don't have the log anymore.
And I think we did say that we didn't want to go too far with using gcc internals. IOW I think trying different modifiers is out of question now (it was -%n0 iirc), but getting past gcc not recognizing the constant as being a constant may still be a viable route.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
In reply to Jan BeulichQuoted 10 lines · Jan Beulich
Quoted 4 lines · Wei Liu
I tried using the
asm(".equ ..")trick but hit a problem with %c again.mm.c:5736:5: error: invalid 'asm': operand is not a condition code, invalid operand code 'c'
asm ( ".equHV_HCALL_PAGE, %c0; .globalHV_HCALL_PAGE"Would you mind also indicating what the input operand actually was? According to my looking at gcc sources when you first mentioned this (on irc iirc), much depends on it actually be recognizable as a constant by the compiler.
Something along the line:
asm ( ".equ HV_HCALL_PAGE, %c0; .global HV_HCALL_PAGE"
:: "i" (__fix_x_to_virt(FIX_X_HV...))
Quoted 10 lines
xen/include/asm-x86/guest/hyperv-hcall.h line 34
Quoted 6 lines
xen/include/asm-x86/guest/hyperv-hcall.h new file +5
-0+static inline uint64_t hv_do_hypercall (uint64_t control,paddr_t input_addr, +paddr_t output_addr) +{ +uint64_t status; + register unsigned long r8 asm("r8") = output_addr;I guess strictly speaking this wants to be asm ( "r8" ), albeit I now realize that I've similarly not played by style in
alternative_callN(). In the end I guess - either way.
OK. I can fix this.
Quoted 9 lines
xen/include/asm-x86/guest/hyperv-hcall.h line 39
Quoted 5 lines
xen/include/asm-x86/guest/hyperv-hcall.h new file +4
-0+ asmvolatile ("call hv_hcall_page" + :"=a" (status),"+c" (control), + "+d" (input_addr) ASM_CALL_CONSTRAINT + : "r" (r8)Why "+c" and "+d" but just "r"? If r8 gets treated differently from rcx and rdx, please attach a brief comment.
Off the top of my head: r8 will not be modified by Hyper-V, while others may.
Wei.
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
Quoted 12 lines · Wei Liu
Quoted 10 lines · Jan Beulich
Quoted 4 lines · Wei Liu
I tried using the
asm(".equ ..")trick but hit a problem with %c again.mm.c:5736:5: error: invalid 'asm': operand is not a condition code, invalid operand code 'c'
asm ( ".equHV_HCALL_PAGE, %c0; .globalHV_HCALL_PAGE"Would you mind also indicating what the input operand actually was? According to my looking at gcc sources when you first mentioned this (on irc iirc), much depends on it actually be recognizable as a constant by the compiler.
Quoted 4 lines
Something along the line:
asm ( ".equ
HV_HCALL_PAGE, %c0; .globalHV_HCALL_PAGE":: "i" (__fix_x_to_virt(FIX_X_HV...))
Quite a bit of playing later, %P0 is documented, supported already in gcc 4.1.x, and also used in a few cases by Linux. %p0 would be another documented alternative, but support for this looks to have been introduced later. Not being able to use %c0 here still smells like a bug (and I guess I'll enter one.)
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Wei Liu
Quoted 10 lines · Jan Beulich
Quoted 4 lines · Wei Liu
I tried using the
asm(".equ ..")trick but hit a problem with %c again.mm.c:5736:5: error: invalid 'asm': operand is not a condition code, invalid operand code 'c'
asm ( ".equHV_HCALL_PAGE, %c0; .globalHV_HCALL_PAGE"Would you mind also indicating what the input operand actually was? According to my looking at gcc sources when you first mentioned this (on irc iirc), much depends on it actually be recognizable as a constant by the compiler.
Something along the line:
Quoted 8 lines
Quoted 2 lines
asm ( ".equ
HV_HCALL_PAGE, %c0; .globalHV_HCALL_PAGE":: "i" (__fix_x_to_virt(FIX_X_HV...))Quite a bit of playing later, %P0 is documented, supported already in gcc 4.1.x, and also used in a few cases by Linux. %p0 would be another documented alternative, but support for this looks to have been introduced later. Not being able to use %c0 here still smells like a bug (and I guess I'll enter one.)
OK. Let me try that.
If that turns out successful, do you want me to change the other instance to %P0 too?
Wei.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
Quoted 25 lines · Wei Liu
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Wei Liu
Quoted 10 lines · Jan Beulich
Quoted 4 lines · Wei Liu
I tried using the
asm(".equ ..")trick but hit a problem with %c again.mm.c:5736:5: error: invalid 'asm': operand is not a condition code, invalid operand code 'c'
asm ( ".equHV_HCALL_PAGE, %c0; .globalHV_HCALL_PAGE"Would you mind also indicating what the input operand actually was? According to my looking at gcc sources when you first mentioned this (on irc iirc), much depends on it actually be recognizable as a constant by the compiler.
Something along the line:
Quoted 8 lines
Quoted 2 lines
asm ( ".equ
HV_HCALL_PAGE, %c0; .globalHV_HCALL_PAGE":: "i" (__fix_x_to_virt(FIX_X_HV...))Quite a bit of playing later, %P0 is documented, supported already in gcc 4.1.x, and also used in a few cases by Linux. %p0 would be another documented alternative, but support for this looks to have been introduced later. Not being able to use %c0 here still smells like a bug (and I guess I'll enter one.)
Quoted 4 lines
OK. Let me try that.
If that turns out successful, do you want me to change the other instance to %P0 too?
That was a pretty small value, wasn't it? I guess it might be safer to switch to %P (and then perhaps also elsewhere in the code base). But during my playing with it I also noticed there's a signedness bug (affecting all possible modifiers), so we need to watch out for results being right in any event.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions
Quoted 26 lines · Jan Beulich
Quoted 25 lines · Wei Liu
Quoted 23 lines · Jan Beulich
Quoted 12 lines · Wei Liu
Quoted 10 lines · Jan Beulich
Quoted 4 lines · Wei Liu
I tried using the
asm(".equ ..")trick but hit a problem with %c again.mm.c:5736:5: error: invalid 'asm': operand is not a condition code, invalid operand code 'c'
asm ( ".equHV_HCALL_PAGE, %c0; .globalHV_HCALL_PAGE"Would you mind also indicating what the input operand actually was? According to my looking at gcc sources when you first mentioned this (on irc iirc), much depends on it actually be recognizable as a constant by the compiler.
Quoted 4 lines
Something along the line:
asm ( ".equ
HV_HCALL_PAGE, %c0; .globalHV_HCALL_PAGE":: "i" (__fix_x_to_virt(FIX_X_HV...))Quite a bit of playing later, %P0 is documented, supported already in gcc 4.1.x, and also used in a few cases by Linux. %p0 would be another documented alternative, but support for this looks to have been introduced later. Not being able to use %c0 here still smells like a bug (and I guess I'll enter one.)
Quoted 7 lines
Quoted 4 lines
OK. Let me try that.
If that turns out successful, do you want me to change the other instance to %P0 too?
That was a pretty small value, wasn't it? I guess it might be safer to switch to %P (and then perhaps also elsewhere in the code base).
Yes. That value is 0x2000 at the moment.
Quoted 3 lines
But during my playing with it I also noticed there's a signedness bug (affecting all possible modifiers), so we need to watch out for results being right in any event.
Using %P0 works just fine for that instance, the generated value looks correct, so I will use it.
Wei.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel