Skip to contentSkip to conversation

xen/pvshim: fixes for staging

PATCH In review Roger Pau Monne 4 participants 12 messages Jan 18, 2018

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 63ca053b35..2cdd431b5f 100644
@@ -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
#2 lore raw

PATCH v3 2/7 xen/pvh: place the trampoline starting at MFN 1

In reply to Roger Pau Monne

Since 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
index 4fe5a776b1..0f652cea11 100644
@@ -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
index 1147a1afb1..275e68c417 100644
@@ -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
#6 lore raw

PATCH v3 6/7 firmware/shim: fix build process to use POSIX find options

In reply to Roger Pau Monne

The -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
index adf6c31e8d..53eb3b6543 100644
@@ -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
#9 lore raw

PATCH v3 7/7 xen/pvshim: switch shim.c to use typesafe mfn_to_page and virt_to_mfn

In reply to Roger Pau Monne

No 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
index 903562e8e4..d5383dcfc7 100644
@@ -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, &param));
     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
#5 lore raw

PATCH v3 5/7 xen/pvshim: fix coding style issues

In reply to Roger Pau Monne

Fix 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
index aa5d416b75..903562e8e4 100644
@@ -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
#3 lore raw

PATCH v3 3/7 xen/pvshim: identity pin shim vCPUs to pCPUs

In reply to Roger Pau Monne

Since 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
index 17cb1272c1..555660b853 100644
@@ -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
Acked-by on v3 7/7
#10 lore raw

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 Monne
Quoted 8 lines · Roger Pau Monne

No functional change intended.

---
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

#4 lore raw

PATCH v3 4/7 xen/pvshim: re-order replace_va_mapping code

In reply to Roger Pau Monne

No 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
index 702249719e..aa5d416b75 100644
@@ -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
Reviewed-by on v3 7/7
#11 lore raw

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 Monne
Quoted 4 lines · Roger Pau Monne

No functional change intended.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v3 6/7
#7 lore raw

Re: [PATCH v3 6/7] firmware/shim: fix build process to use POSIX find options

In reply to Roger Pau Monne

Roger 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

Acked-by on v3 6/7
#8 lore raw

Re: [PATCH v3 6/7] firmware/shim: fix build process to use POSIX find options

In reply to Roger Pau Monne
Quoted 4 lines · Roger Pau Monne

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