xen/pvshim: fixes for staging
v3 cover xen/pvshim: fixes for staging
Hello,
The following series contain some code and style fixes for the pvshim (comet) code that has been merged into staging. IMHO patches 1-3 should be backported to the stable comet branch.
A branch with the series is also available at:
git://xenbits.xen.org/people/royger/xen.git pvshim_fixes_v3
Thanks, Roger.
Roger Pau Monne (7):
xen/pvshim: map vcpu_info earlier for APs
xen/pvh: place the trampoline starting at MFN 1 xen/pvshim: identity pin shim vCPUs to pCPUs
xen/pvshim: re-order replace_va_mapping code
xen/pvshim: fix coding style issues
firmware/shim: fix build process to use POSIX find options xen/pvshim: switch shim.c to use typesafe mfn_to_page and virt_to_mfn
tools/firmware/xen-dir/Makefile | 3 +- xen/arch/x86/boot/head.S | 3 ++ xen/arch/x86/dom0_build.c | 5 ++-- xen/arch/x86/mm.c | 9 ++++-- xen/arch/x86/pv/shim.c | 63 ++++++++++++++++++++--------------------- xen/arch/x86/smpboot.c | 6 ++-- 6 files changed, 47 insertions(+), 42 deletions(-)
Signature · 7 lines
2.15.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 1/7 xen/pvshim: map vcpu_info earlier for APs
Or else init_percpu_time is going to dereference a NULL pointer when trying to access vcpu_info.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
---
Should be backported to the 4.10.0-shim-comet branch.
--- xen/arch/x86/smpboot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/smpboot.c +3 -3
@@ -349,6 +349,9 @@ void start_secondary(void *unused)else microcode_resume_cpu (cpu); +if ( xen_guest ) +hypervisor_ap_setup (); +smp_callin ();init_percpu_time ();
@@ -376,9 +379,6 @@ void start_secondary(void *unused)cpumask_set_cpu (cpu, &cpu_online_map);unlock_vector_lock (); -if ( xen_guest ) -hypervisor_ap_setup (); -/* We can take interrupts now: we're officially "up". */ local_irq_enable ();mtrr_ap_init ();
Signature · 7 lines
2.15.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 2/7 xen/pvh: place the trampoline starting at MFN 1
In reply to Roger Pau MonneSince PVH guest jump straight into trampoline_setup trampoline_phys is not initialized, thus the trampoline is relocated to address 0.
This works, but has the undesirable effect of having VA 0 mapped to MFN 0, which means NULL pointed dereferences no longer trigger a page fault.
In order to solve this, place the trampoline starting at MFN 1 and reserve the memory used by it.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Ian Jackson <[email protected]>
---
Changes since v2:
- Clarify comments.
Changes since v1:
- Expand comment in head.S.
- Add a BUG_ON to check trampoline_phys value in the PVH case.
---
Should be backported to the 4.10.0-shim-comet branch.
--- xen/arch/x86/boot/head.S | 3 +++ xen/arch/x86/mm.c | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-)
xen/arch/x86/boot/head.S +3 -0
@@ -411,6 +411,9 @@ __pvh_start: /* Skip bootloader setup and bios setup, go straight to trampoline */ movb $1, sym_esi(pvh_boot) movb $1, sym_esi(skip_realmode) + + /* Set trampoline_phys to use mfn 1 to avoid having a mapping at VA 0 */ + movw $0x1000, sym_esi(trampoline_phys) jmp trampoline_setup #endif /* CONFIG_PVH_GUEST */
xen/arch/x86/mm.c +7 -2
@@ -292,9 +292,14 @@ void __init arch_init_memory(void)/* * First 1MB of RAM is historically marked as I/O. If we booted PVH, * reclaim the space. Irrespective, leave MFN 0 as special for the sake -* of 0 being a very common default value. +* of 0 being a very common default value. Also reserve the RAM needed by +* the trampoline on PVH starting at MFN 1. */ -for ( i =0 ; i < (pvh_boot ?1 :0x100 ); i++ ) +BUG_ON (pvh_boot && trampoline_phys !=0x1000 ); +for ( i =0 ; + i < (pvh_boot ? (1 +PFN_UP (trampoline_end - trampoline_start)) + :0x100 ); + i++ )share_xen_page_with_guest (mfn_to_page (_mfn (i)), dom_io, XENSHARE_writable);
Signature · 7 lines
2.15.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 6/7 firmware/shim: fix build process to use POSIX find options
In reply to Roger Pau MonneThe -printf find option is not POSIX compatible, so replace it with another rune.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Drop the exec rune and instead process the whole output at once.
--- tools/firmware/xen-dir/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/firmware/xen-dir/Makefile +2 -1
@@ -21,7 +21,8 @@ linkfarm.stamp: $(DEP_DIRS) $(DEP_FILES) FORCE $(foreach d, $(LINK_DIRS), \ (mkdir -p $(D)/$(d); \ cd $(D)/$(d); \ - find $(XEN_ROOT)/$(d)/ -type d -printf "./%P\n" | xargs mkdir -p);) + find $(XEN_ROOT)/$(d)/ -type d |\ + sed 's,^$(XEN_ROOT)/$(d)/,,g' | xargs mkdir -p);) $(foreach d, $(LINK_DIRS), \ (cd $(XEN_ROOT); \ find $(d) ! -type l -type f \
Signature · 7 lines
2.15.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 7/7 xen/pvshim: switch shim.c to use typesafe mfn_to_page and virt_to_mfn
In reply to Roger Pau MonneNo functional change intended.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
--- xen/arch/x86/pv/shim.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
xen/arch/x86/pv/shim.c +16 -10
@@ -37,6 +37,11 @@#include <compat/grant_table.h> +#undef mfn_to_page +#define mfn_to_page (mfn) __mfn_to_page(mfn_x(mfn)) +#undef virt_to_mfn +#define virt_to_mfn (va) _mfn(__virt_to_mfn(va)) +#ifndef CONFIG_PV_SHIM_EXCLUSIVE bool pv_shim;boolean_param ("pv-shim" , pv_shim);
@@ -115,17 +120,17 @@ uint64_t pv_shim_mem(uint64_t avail)#define COMPAT_L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)static void __init replace_va_mapping (struct domain *d,l4_pgentry_t *l4start, -unsigned long va,unsigned long mfn) +unsigned long va,mfn_t mfn) {l4_pgentry_t *pl4e = l4start +l4_table_offset (va);l3_pgentry_t *pl3e =l4e_to_l3e (*pl4e) +l3_table_offset (va);l2_pgentry_t *pl2e =l3e_to_l2e (*pl3e) +l2_table_offset (va);l1_pgentry_t *pl1e =l2e_to_l1e (*pl2e) +l1_table_offset (va); -struct page_info *page =mfn_to_page (l1e_get_pfn (*pl1e)); +struct page_info *page =mfn_to_page (l1e_get_mfn (*pl1e));put_page_and_type (page); - *pl1e =l1e_from_pfn (mfn, (!is_pv_32bit_domain (d) ?L1_PROT + *pl1e =l1e_from_mfn (mfn, (!is_pv_32bit_domain (d) ?L1_PROT :COMPAT_L1_PROT )); }
@@ -165,8 +170,9 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start, (si) = param; \if ( va ) \ { \ -share_xen_page_with_guest (mfn_to_page (param), d, XENSHARE_writable); \ -replace_va_mapping (d, l4start, va, param); \ +share_xen_page_with_guest (mfn_to_page (_mfn (param)), d, \ + XENSHARE_writable); \ +replace_va_mapping (d, l4start, va,_mfn (param)); \dom0_update_physmap (d,PFN_DOWN ((va) - va_start), param, vphysmap); \ } \else \
@@ -186,17 +192,17 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start, {/* Allocate a new page for DomU's PV console */ void *page =alloc_xenheap_pages (0 ,MEMF_bits (32 )); -uint64_t console_mfn; +mfn_t console_mfn;ASSERT (page);clear_page (page); console_mfn =virt_to_mfn (page); - si->console.domU.mfn = console_mfn; + si->console.domU.mfn =mfn_x (console_mfn);share_xen_page_with_guest (mfn_to_page (console_mfn), d, XENSHARE_writable);replace_va_mapping (d, l4start, console_va, console_mfn);dom0_update_physmap (d, (console_va - va_start) >>PAGE_SHIFT , - console_mfn, vphysmap); +mfn_x (console_mfn), vphysmap);consoled_set_ring_addr (page); } pv_hypercall_table_replace(__HYPERVISOR_event_channel_op,
@@ -232,7 +238,7 @@ static void write_start_info(struct domain *d)BUG_ON (xen_hypercall_hvm_get_param (HVM_PARAM_CONSOLE_EVTCHN , ¶m)); si->console.domU.evtchn = param;if ( pv_console ) - si->console.domU.mfn =virt_to_mfn (consoled_get_ring_addr ()); + si->console.domU.mfn =mfn_x (virt_to_mfn (consoled_get_ring_addr ()));else if (xen_hypercall_hvm_get_param (HVM_PARAM_CONSOLE_PFN , &si->console.domU.mfn) )BUG ();
@@ -334,7 +340,7 @@ int pv_shim_shutdown(uint8_t reason)if ( d->arch.pirq_eoi_map !=NULL ) {unmap_domain_page_global (d->arch.pirq_eoi_map); -put_page_and_type (mfn_to_page (d->arch.pirq_eoi_map_mfn)); +put_page_and_type (mfn_to_page (_mfn (d->arch.pirq_eoi_map_mfn))); d->arch.pirq_eoi_map =NULL ; d->arch.pirq_eoi_map_mfn =0 ; d->arch.auto_unmask =0 ;
Signature · 7 lines
2.15.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 5/7 xen/pvshim: fix coding style issues
In reply to Roger Pau MonneFix a couple of coding style issues.
No code or functional change.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
--- xen/arch/x86/pv/shim.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
xen/arch/x86/pv/shim.c +9 -9
@@ -264,14 +264,14 @@ int pv_shim_shutdown(uint8_t reason) &old_console_pfn));/* Pause the other vcpus before starting the migration. */ -for_each_vcpu (d, v) + for_each_vcpu ( d, v )if ( v != current )vcpu_pause_by_systemcontroller (v); rc =xen_hypercall_shutdown (SHUTDOWN_suspend);if ( rc ) { -for_each_vcpu (d, v) + for_each_vcpu ( d, v )if ( v != current )vcpu_unpause_by_systemcontroller (v);
@@ -347,7 +347,7 @@ int pv_shim_shutdown(uint8_t reason)*/ write_start_info (d); -for_each_vcpu (d, v) + for_each_vcpu ( d, v ) {/* Unmap guest vcpu_info pages. */ unmap_vcpu_info (v);
@@ -428,7 +428,7 @@ static long pv_shim_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)*/ rc =xen_hypercall_event_channel_op (EVTCHNOP_alloc_unbound, &alloc);if ( rc ) -break ; +break ;/* Force L1 to use the event channel port allocated on L0. */ rc =evtchn_bind_virq (&virq, alloc.port);
@@ -477,7 +477,7 @@ static long pv_shim_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { rc =xen_hypercall_event_channel_op (EVTCHNOP_bind_vcpu, &vcpu);if ( !rc ) -evtchn_assign_vcpu (d, vcpu.port, vcpu.vcpu); +evtchn_assign_vcpu (d, vcpu.port, vcpu.vcpu); }break ;
@@ -596,9 +596,9 @@ void pv_shim_inject_evtchn(unsigned int port) {if (port_is_valid (guest, port) ) { -struct evtchn *chn =evtchn_from_port (guest, port); +struct evtchn *chn =evtchn_from_port (guest, port); -evtchn_port_set_pending (guest, chn->notify_vcpu_id, chn); +evtchn_port_set_pending (guest, chn->notify_vcpu_id, chn); } }
@@ -633,7 +633,7 @@ static long pv_shim_grant_table_op(unsigned int cmd, } if ( compat )#define XLAT_gnttab_setup_table_HNDL_frame_list (d, s) -XLAT_gnttab_setup_table (&nat, &cmp); +XLAT_gnttab_setup_table (&nat, &cmp);#undef XLAT_gnttab_setup_table_HNDL_frame_list nat.status = GNTST_okay;
@@ -728,7 +728,7 @@ static long pv_shim_grant_table_op(unsigned int cmd, if ( compat )#define XLAT_gnttab_setup_table_HNDL_frame_list (d, s) -XLAT_gnttab_setup_table (&cmp, &nat); +XLAT_gnttab_setup_table (&cmp, &nat);#undef XLAT_gnttab_setup_table_HNDL_frame_list if ( unlikely(compat ? __copy_to_guest(uop, &cmp, 1)
Signature · 7 lines
2.15.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 3/7 xen/pvshim: identity pin shim vCPUs to pCPUs
In reply to Roger Pau MonneSince VCPUOP_{up/down} already identity maps vCPU hotplug to pCPU hotplug also identity pin the vCPUs to the pCPUs in the scheduler. This prevents vCPU migration and should improve performance.
While there also use __cpumask_set_cpu instead of cpumask_set_cpu, there's no need to use the locked variant.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Ian Jackson <[email protected]>
---
Changes since v1:
- Clarify commit message.
---
Should be backported to the 4.10.0-shim-comet branch.
--- xen/arch/x86/dom0_build.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
xen/arch/x86/dom0_build.c +2 -3
@@ -140,9 +140,8 @@ struct vcpu *__init dom0_setup_vcpu(struct domain *d, {if ( pv_shim ) { - -cpumask_setall (v->cpu_hard_affinity); -cpumask_setall (v->cpu_soft_affinity); +__cpumask_set_cpu (vcpu_id, v->cpu_hard_affinity); +__cpumask_set_cpu (vcpu_id, v->cpu_soft_affinity); }else {
Signature · 7 lines
2.15.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/pvshim: switch shim.c to use typesafe mfn_to_page and virt_to_mfn
In reply to Roger Pau MonneQuoted 8 lines · Roger Pau Monne
No functional change intended.
Signed-off-by Roger Pau Monné <[email protected]>Requested-by Andrew Cooper <[email protected]>---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Thanks.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 4/7 xen/pvshim: re-order replace_va_mapping code
In reply to Roger Pau MonneNo functional change.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
Changes since v1:
- Fix double ; and space.
--- xen/arch/x86/pv/shim.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
xen/arch/x86/pv/shim.c +6 -15
@@ -117,21 +117,12 @@ uint64_t pv_shim_mem(uint64_t avail)static void __init replace_va_mapping (struct domain *d,l4_pgentry_t *l4start,unsigned long va,unsigned long mfn) { -struct page_info *page; -l4_pgentry_t *pl4e; -l3_pgentry_t *pl3e; -l2_pgentry_t *pl2e; -l1_pgentry_t *pl1e; - - pl4e = l4start +l4_table_offset (va); - pl3e =l4e_to_l3e (*pl4e); - pl3e +=l3_table_offset (va); - pl2e =l3e_to_l2e (*pl3e); - pl2e +=l2_table_offset (va); - pl1e =l2e_to_l1e (*pl2e); - pl1e +=l1_table_offset (va); - - page =mfn_to_page (l1e_get_pfn (*pl1e)); +l4_pgentry_t *pl4e = l4start +l4_table_offset (va); +l3_pgentry_t *pl3e =l4e_to_l3e (*pl4e) +l3_table_offset (va); +l2_pgentry_t *pl2e =l3e_to_l2e (*pl3e) +l2_table_offset (va); +l1_pgentry_t *pl1e =l2e_to_l1e (*pl2e) +l1_table_offset (va); +struct page_info *page =mfn_to_page (l1e_get_pfn (*pl1e)); +put_page_and_type (page); *pl1e = l1e_from_pfn(mfn, (!is_pv_32bit_domain(d) ? L1_PROT
Signature · 7 lines
2.15.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/pvshim: switch shim.c to use typesafe mfn_to_page and virt_to_mfn
In reply to Roger Pau MonneQuoted 4 lines · Roger Pau Monne
No functional change intended.
Signed-off-by Roger Pau Monné <[email protected]>Requested-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 6/7] firmware/shim: fix build process to use POSIX find options
In reply to Roger Pau MonneRoger Pau Monne writes ("[PATCH v3 6/7] firmware/shim: fix build process to use POSIX find options"):
Quoted 2 lines
The -printf find option is not POSIX compatible, so replace it with another rune.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 6/7] firmware/shim: fix build process to use POSIX find options
In reply to Roger Pau MonneQuoted 4 lines · Roger Pau Monne
The -printf find option is not POSIX compatible, so replace it with another rune.
Signed-off-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel