Skip to contentSkip to conversation

x86/mm: Use mfn_t for new_guest_cr3()

PATCH In review Andrew Cooper 6 participants 11 messages Aug 30, 2017 – Sep 1, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 x86/mm: Use mfn_t for new_guest_cr3()

No functional change (as confirmed by diffing the assembly).

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>

For some reason best known to GCC, there is one single change:

@@ -145835,7 +145835,7 @@

 ffff82d0802864f8:      85 c0                   test   %eax,%eax
 ffff82d0802864fa:      75 e0                   jne    ffff82d0802864dc <new_guest_cr3+0x7c>
 ffff82d0802864fc:      4c 8b ad 08 0b 00 00    mov    0xb08(%rbp),%r13
-ffff82d080286503:      49 39 dd                cmp    %rbx,%r13
+ffff82d080286503:      4c 39 eb                cmp    %r13,%rbx
 ffff82d080286506:      0f 84 74 01 00 00       je     ffff82d080286680 <new_guest_cr3+0x220>
 ffff82d08028650c:      41 f6 84 24 19 06 00    testb  $0x8,0x619(%r12)
 ffff82d080286513:      00 08

This is from the mfn_eq() alteration, and must be a side effect from using an inline function. The net result is still correct, as only the zero flag is checked.

---
 xen/arch/x86/mm.c              | 35 ++++++++++++++++++-----------------
 xen/arch/x86/pv/emul-priv-op.c |  2 +-
 xen/include/asm-x86/mm.h       |  2 +-
 3 files changed, 20 insertions(+), 19 deletions(-)
xen/arch/x86/mm.c +18 -17
index 1f23470..dc07b4f 100644
@@ -2772,23 +2772,23 @@ int vcpu_destroy_pagetables(struct vcpu *v)
     return rc != -EINTR ? rc : -ERESTART;
 }
 
-int new_guest_cr3(unsigned long mfn)
+int new_guest_cr3(mfn_t mfn)
 {
     struct vcpu *curr = current;
     struct domain *d = curr->domain;
     int rc;
-    unsigned long old_base_mfn;
+    mfn_t old_base_mfn;
 
     if ( is_pv_32bit_domain(d) )
     {
-        unsigned long gt_mfn = pagetable_get_pfn(curr->arch.guest_table);
-        l4_pgentry_t *pl4e = map_domain_page(_mfn(gt_mfn));
+        mfn_t mmfn = pagetable_get_mfn(curr->arch.guest_table);
+        l4_pgentry_t *pl4e = map_domain_page(mmfn);
 
         rc = mod_l4_entry(pl4e,
-                          l4e_from_pfn(mfn,
+                          l4e_from_mfn(mfn,
                                        (_PAGE_PRESENT | _PAGE_RW |
                                         _PAGE_USER | _PAGE_ACCESSED)),
-                          gt_mfn, 0, curr);
+                          mfn_x(mmfn), 0, curr);
         unmap_domain_page(pl4e);
         switch ( rc )
         {
@@ -2800,7 +2800,7 @@ int new_guest_cr3(unsigned long mfn)
         default:
             gdprintk(XENLOG_WARNING,
                      "Error while installing new compat baseptr %" PRI_mfn "\n",
-                     mfn);
+                     mfn_x(mfn));
             return rc;
         }
 
@@ -2814,20 +2814,20 @@ int new_guest_cr3(unsigned long mfn)
     if ( unlikely(rc) )
         return rc;
 
-    old_base_mfn = pagetable_get_pfn(curr->arch.guest_table);
+    old_base_mfn = pagetable_get_mfn(curr->arch.guest_table);
     /*
      * This is particularly important when getting restarted after the
      * previous attempt got preempted in the put-old-MFN phase.
      */
-    if ( old_base_mfn == mfn )
+    if ( mfn_eq(old_base_mfn, mfn) )
     {
         write_ptbase(curr);
         return 0;
     }
 
     rc = paging_mode_refcounts(d)
-         ? (get_page_from_mfn(_mfn(mfn), d) ? 0 : -EINVAL)
-         : get_page_and_type_from_mfn(_mfn(mfn), PGT_root_page_table, d, 0, 1);
+         ? (get_page_from_mfn(mfn, d) ? 0 : -EINVAL)
+         : get_page_and_type_from_mfn(mfn, PGT_root_page_table, d, 0, 1);
     switch ( rc )
     {
     case 0:
@@ -2837,22 +2837,23 @@ int new_guest_cr3(unsigned long mfn)
         return -ERESTART;
     default:
         gdprintk(XENLOG_WARNING,
-                 "Error while installing new baseptr %" PRI_mfn "\n", mfn);
+                 "Error while installing new baseptr %" PRI_mfn "\n",
+                 mfn_x(mfn));
         return rc;
     }
 
     invalidate_shadow_ldt(curr, 0);
 
     if ( !VM_ASSIST(d, m2p_strict) && !paging_mode_refcounts(d) )
-        fill_ro_mpt(_mfn(mfn));
-    curr->arch.guest_table = pagetable_from_pfn(mfn);
+        fill_ro_mpt(mfn);
+    curr->arch.guest_table = pagetable_from_mfn(mfn);
     update_cr3(curr);
 
     write_ptbase(curr);
 
-    if ( likely(old_base_mfn != 0) )
+    if ( likely(mfn_x(old_base_mfn) != 0) )
     {
-        struct page_info *page = mfn_to_page(_mfn(old_base_mfn));
+        struct page_info *page = mfn_to_page(old_base_mfn);
 
         if ( paging_mode_refcounts(d) )
             put_page(page);
@@ -3180,7 +3181,7 @@ long do_mmuext_op(
             else if ( unlikely(paging_mode_translate(currd)) )
                 rc = -EINVAL;
             else
-                rc = new_guest_cr3(op.arg1.mfn);
+                rc = new_guest_cr3(_mfn(op.arg1.mfn));
             break;
 
         case MMUEXT_NEW_USER_BASEPTR: {
xen/arch/x86/pv/emul-priv-op.c +1 -1
index af1624a..54a63c2 100644
@@ -774,7 +774,7 @@ static int priv_op_write_cr(unsigned int reg, unsigned long val,
         page = get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC);
         if ( !page )
             break;
-        rc = new_guest_cr3(mfn_x(page_to_mfn(page)));
+        rc = new_guest_cr3(page_to_mfn(page));
         put_page(page);
 
         switch ( rc )
xen/include/asm-x86/mm.h +1 -1
index ec7ce3c..4c03a33 100644
@@ -539,7 +539,7 @@ void audit_domains(void);
 
 #endif
 
-int new_guest_cr3(unsigned long pfn);
+int new_guest_cr3(mfn_t mfn);
 void make_cr3(struct vcpu *v, unsigned long mfn);
 void update_cr3(struct vcpu *v);
 int vcpu_destroy_pagetables(struct vcpu *);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH 2/2 x86/mm: Use mfn_t for make_cr3()

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Tim Deegan <[email protected]>
CC: George Dunlap <[email protected]>

---
 xen/arch/x86/mm.c               | 10 +++++-----
 xen/arch/x86/mm/hap/hap.c       |  2 +-
 xen/arch/x86/mm/shadow/common.c |  8 ++++----
 xen/arch/x86/mm/shadow/multi.c  |  4 ++--
 xen/include/asm-x86/mm.h        |  2 +-
 5 files changed, 13 insertions(+), 13 deletions(-)
xen/arch/x86/mm.c +5 -5
index dc07b4f..f0c81e7 100644
@@ -498,9 +498,9 @@ void free_shared_domheap_page(struct page_info *page)
     free_domheap_page(page);
 }
 
-void make_cr3(struct vcpu *v, unsigned long mfn)
+void make_cr3(struct vcpu *v, mfn_t mfn)
 {
-    v->arch.cr3 = mfn << PAGE_SHIFT;
+    v->arch.cr3 = mfn_x(mfn) << PAGE_SHIFT;
 }
 
 void write_ptbase(struct vcpu *v)
@@ -518,7 +518,7 @@ void write_ptbase(struct vcpu *v)
  */
 void update_cr3(struct vcpu *v)
 {
-    unsigned long cr3_mfn;
+    mfn_t cr3_mfn;
 
     if ( paging_mode_enabled(v->domain) )
     {
@@ -527,9 +527,9 @@ void update_cr3(struct vcpu *v)
     }
 
     if ( !(v->arch.flags & TF_kernel_mode) )
-        cr3_mfn = pagetable_get_pfn(v->arch.guest_table_user);
+        cr3_mfn = pagetable_get_mfn(v->arch.guest_table_user);
     else
-        cr3_mfn = pagetable_get_pfn(v->arch.guest_table);
+        cr3_mfn = pagetable_get_mfn(v->arch.guest_table);
 
     make_cr3(v, cr3_mfn);
 }
xen/arch/x86/mm/hap/hap.c +1 -1
index 15e4877..6946fde 100644
@@ -719,7 +719,7 @@ static void hap_update_paging_modes(struct vcpu *v)
     {
         mfn_t mmfn = hap_make_monitor_table(v);
         v->arch.monitor_table = pagetable_from_mfn(mmfn);
-        make_cr3(v, mfn_x(mmfn));
+        make_cr3(v, mmfn);
         hvm_update_host_cr3(v);
     }
 
xen/arch/x86/mm/shadow/common.c +4 -4
index e8ee6db..3926ed6 100644
@@ -2961,7 +2961,7 @@ static void sh_update_paging_modes(struct vcpu *v)
         {
             mfn_t mmfn = v->arch.paging.mode->shadow.make_monitor_table(v);
             v->arch.monitor_table = pagetable_from_mfn(mmfn);
-            make_cr3(v, mfn_x(mmfn));
+            make_cr3(v, mmfn);
             hvm_update_host_cr3(v);
         }
 
@@ -3004,7 +3004,7 @@ static void sh_update_paging_modes(struct vcpu *v)
                 /* Don't be running on the old monitor table when we
                  * pull it down!  Switch CR3, and warn the HVM code that
                  * its host cr3 has changed. */
-                make_cr3(v, mfn_x(new_mfn));
+                make_cr3(v, new_mfn);
                 if ( v == current )
                     write_ptbase(v);
                 hvm_update_host_cr3(v);
@@ -3380,9 +3380,9 @@ static int shadow_one_bit_disable(struct domain *d, u32 mode)
             if ( v->arch.paging.mode )
                 v->arch.paging.mode->shadow.detach_old_tables(v);
             if ( !(v->arch.flags & TF_kernel_mode) )
-                make_cr3(v, pagetable_get_pfn(v->arch.guest_table_user));
+                make_cr3(v, pagetable_get_mfn(v->arch.guest_table_user));
             else
-                make_cr3(v, pagetable_get_pfn(v->arch.guest_table));
+                make_cr3(v, pagetable_get_mfn(v->arch.guest_table));
 
 #if (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC)
             {
xen/arch/x86/mm/shadow/multi.c +2 -2
index c5c0af8..f7efe66 100644
@@ -4273,7 +4273,7 @@ sh_update_cr3(struct vcpu *v, int do_locking)
     ///
     if ( shadow_mode_external(d) )
     {
-        make_cr3(v, pagetable_get_pfn(v->arch.monitor_table));
+        make_cr3(v, pagetable_get_mfn(v->arch.monitor_table));
     }
     else // not shadow_mode_external...
     {
@@ -4287,7 +4287,7 @@ sh_update_cr3(struct vcpu *v, int do_locking)
         v->arch.cr3 = virt_to_maddr(&v->arch.paging.shadow.l3table);
 #else
         /* 4-on-4: Just use the shadow top-level directly */
-        make_cr3(v, pagetable_get_pfn(v->arch.shadow_table[0]));
+        make_cr3(v, pagetable_get_mfn(v->arch.shadow_table[0]));
 #endif
     }
 
xen/include/asm-x86/mm.h +1 -1
index 4c03a33..dce3f16 100644
@@ -540,7 +540,7 @@ void audit_domains(void);
 #endif
 
 int new_guest_cr3(mfn_t mfn);
-void make_cr3(struct vcpu *v, unsigned long mfn);
+void make_cr3(struct vcpu *v, mfn_t mfn);
 void update_cr3(struct vcpu *v);
 int vcpu_destroy_pagetables(struct vcpu *);
 void *do_page_walk(struct vcpu *v, unsigned long addr);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by
#3 lore raw

Re: [PATCH 2/2] x86/mm: Use mfn_t for make_cr3()

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 30.08.17 at 15:08, <[email protected]> wrote:
Quoted 3 lines · Andrew Cooper

No functional change.

As a side note, I can see instances of mmfn here too, but here (other than in patch 1) the first m quite clearly stands for "monitor". There's nothing formally called "monitor" on that other path, though.

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

Acked-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] x86/mm: Use mfn_t for make_cr3()

In reply to Andrew Cooper
Quoted 3 lines · Andrew Cooper

No functional change.

Quoted 136 lines

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Tim Deegan <[email protected]>
CC: George Dunlap <[email protected]>

---
 xen/arch/x86/mm.c               | 10 +++++-----
 xen/arch/x86/mm/hap/hap.c       |  2 +-
 xen/arch/x86/mm/shadow/common.c |  8 ++++----
 xen/arch/x86/mm/shadow/multi.c  |  4 ++--
 xen/include/asm-x86/mm.h        |  2 +-
 5 files changed, 13 insertions(+), 13 deletions(-)
xen/arch/x86/mm.c +5 -5
index dc07b4f..f0c81e7 100644
@@ -498,9 +498,9 @@ void free_shared_domheap_page(struct page_info *page)
     free_domheap_page(page);
 }
 
-void make_cr3(struct vcpu *v, unsigned long mfn)
+void make_cr3(struct vcpu *v, mfn_t mfn)
 {
-    v->arch.cr3 = mfn << PAGE_SHIFT;
+    v->arch.cr3 = mfn_x(mfn) << PAGE_SHIFT;
 }
 
 void write_ptbase(struct vcpu *v)
@@ -518,7 +518,7 @@ void write_ptbase(struct vcpu *v)
  */
 void update_cr3(struct vcpu *v)
 {
-    unsigned long cr3_mfn;
+    mfn_t cr3_mfn;
 
     if ( paging_mode_enabled(v->domain) )
     {
@@ -527,9 +527,9 @@ void update_cr3(struct vcpu *v)
     }
 
     if ( !(v->arch.flags & TF_kernel_mode) )
-        cr3_mfn = pagetable_get_pfn(v->arch.guest_table_user);
+        cr3_mfn = pagetable_get_mfn(v->arch.guest_table_user);
     else
-        cr3_mfn = pagetable_get_pfn(v->arch.guest_table);
+        cr3_mfn = pagetable_get_mfn(v->arch.guest_table);
 
     make_cr3(v, cr3_mfn);
 }
xen/arch/x86/mm/hap/hap.c +1 -1
index 15e4877..6946fde 100644
@@ -719,7 +719,7 @@ static void hap_update_paging_modes(struct vcpu *v)
     {
         mfn_t mmfn = hap_make_monitor_table(v);
         v->arch.monitor_table = pagetable_from_mfn(mmfn);
-        make_cr3(v, mfn_x(mmfn));
+        make_cr3(v, mmfn);
         hvm_update_host_cr3(v);
     }
 
xen/arch/x86/mm/shadow/common.c +4 -4
index e8ee6db..3926ed6 100644
@@ -2961,7 +2961,7 @@ static void sh_update_paging_modes(struct vcpu *v)
         {
             mfn_t mmfn = v->arch.paging.mode->shadow.make_monitor_table(v);
             v->arch.monitor_table = pagetable_from_mfn(mmfn);
-            make_cr3(v, mfn_x(mmfn));
+            make_cr3(v, mmfn);
             hvm_update_host_cr3(v);
         }
 
@@ -3004,7 +3004,7 @@ static void sh_update_paging_modes(struct vcpu *v)
                 /* Don't be running on the old monitor table when we
                  * pull it down!  Switch CR3, and warn the HVM code that
                  * its host cr3 has changed. */
-                make_cr3(v, mfn_x(new_mfn));
+                make_cr3(v, new_mfn);
                 if ( v == current )
                     write_ptbase(v);
                 hvm_update_host_cr3(v);
@@ -3380,9 +3380,9 @@ static int shadow_one_bit_disable(struct domain *d, u32 mode)
             if ( v->arch.paging.mode )
                 v->arch.paging.mode->shadow.detach_old_tables(v);
             if ( !(v->arch.flags & TF_kernel_mode) )
-                make_cr3(v, pagetable_get_pfn(v->arch.guest_table_user));
+                make_cr3(v, pagetable_get_mfn(v->arch.guest_table_user));
             else
-                make_cr3(v, pagetable_get_pfn(v->arch.guest_table));
+                make_cr3(v, pagetable_get_mfn(v->arch.guest_table));
 
 #if (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC)
             {
xen/arch/x86/mm/shadow/multi.c +2 -2
index c5c0af8..f7efe66 100644
@@ -4273,7 +4273,7 @@ sh_update_cr3(struct vcpu *v, int do_locking)
     ///
     if ( shadow_mode_external(d) )
     {
-        make_cr3(v, pagetable_get_pfn(v->arch.monitor_table));
+        make_cr3(v, pagetable_get_mfn(v->arch.monitor_table));
     }
     else // not shadow_mode_external...
     {
@@ -4287,7 +4287,7 @@ sh_update_cr3(struct vcpu *v, int do_locking)
         v->arch.cr3 = virt_to_maddr(&v->arch.paging.shadow.l3table);
 #else
         /* 4-on-4: Just use the shadow top-level directly */
-        make_cr3(v, pagetable_get_pfn(v->arch.shadow_table[0]));
+        make_cr3(v, pagetable_get_mfn(v->arch.shadow_table[0]));
 #endif
     }
 
xen/include/asm-x86/mm.h +1 -2
index 4c03a33..dce3f16 100644
@@ -540,7 +540,7 @@ void audit_domains(void);
 #endif
 
 int new_guest_cr3(mfn_t mfn);
-void make_cr3(struct vcpu *v, unsigned long mfn);
+void make_cr3(struct vcpu *v, mfn_t mfn);
 void update_cr3(struct vcpu *v);
 int vcpu_destroy_pagetables(struct vcpu *);
 void *do_page_walk(struct vcpu *v, unsigned long addr);
--

2.1.4

Quoted 4 lines

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

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

#7 lore raw
In reply to Andrew Cooper
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 30.08.17 at 14:19, <[email protected]> wrote:
xen/arch/x86/mm.c +1 -1
@@ -2772,23 +2772,23 @@ int vcpu_destroy_pagetables(struct vcpu *v)
     return rc != -EINTR ? rc : -ERESTART;
 }
 
-int new_guest_cr3(unsigned long mfn)
+int new_guest_cr3(mfn_t mfn)
 {
     struct vcpu *curr = current;
     struct domain *d = curr->domain;

xen/arch/x86/mm.c int vcpu_destroy_pagetables(struct vcpu *v) · line 2785

Quoted 10 lines
xen/arch/x86/mm.c +3 -3
     int rc;
-    unsigned long old_base_mfn;
+    mfn_t old_base_mfn;
 
     if ( is_pv_32bit_domain(d) )
     {
-        unsigned long gt_mfn = pagetable_get_pfn(curr->arch.guest_table);
-        l4_pgentry_t *pl4e = map_domain_page(_mfn(gt_mfn));
+        mfn_t mmfn = pagetable_get_mfn(curr->arch.guest_table);
+        l4_pgentry_t *pl4e = map_domain_page(mmfn);

What was wrong with "gt_mfn" for "guest table MFN"? I can't help thinking mmfn is a typo, where you've hit the m key one too many times. What is that first m supposed to stand for?

Other than this the patch is certainly fine.

Jan

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

#8 lore raw
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 30.08.17 at 14:19, <[email protected]> wrote:
xen/arch/x86/mm.c +2 -2
@@ -2772,23 +2772,23 @@ int vcpu_destroy_pagetables(struct vcpu *v)
     return rc != -EINTR ? rc : -ERESTART;
 }
 
-int new_guest_cr3(unsigned long mfn)
+int new_guest_cr3(mfn_t mfn)
 {
     struct vcpu *curr = current;
     struct domain *d = curr->domain;
     int rc;
-    unsigned long old_base_mfn;
+    mfn_t old_base_mfn;
 
Quoted 9 lines

xen/arch/x86/mm.c int vcpu_destroy_pagetables(struct vcpu *v) · line 2785

Quoted 6 lines
xen/arch/x86/mm.c +2 -2
     if ( is_pv_32bit_domain(d) )
     {
-        unsigned long gt_mfn = pagetable_get_pfn(curr->arch.guest_table);
-        l4_pgentry_t *pl4e = map_domain_page(_mfn(gt_mfn));
+        mfn_t mmfn = pagetable_get_mfn(curr->arch.guest_table);
+        l4_pgentry_t *pl4e = map_domain_page(mmfn);

What was wrong with "gt_mfn" for "guest table MFN"? I can't help thinking mmfn is a typo, where you've hit the m key one too many times. What is that first m supposed to stand for?

mmfn is the shadow code nomenclature for the monitor mfn. I can move back to gt_mfn if you think thats clearer.

~Andrew

Quoted 5 lines

Other than this the patch is certainly fine.

Jan

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

Acked-by
#9 lore raw
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 30.08.17 at 17:57, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 30.08.17 at 14:19, <[email protected]> wrote:
xen/arch/x86/mm.c +2 -2
@@ -2772,23 +2772,23 @@ int vcpu_destroy_pagetables(struct vcpu *v)
     return rc != -EINTR ? rc : -ERESTART;
 }
 
-int new_guest_cr3(unsigned long mfn)
+int new_guest_cr3(mfn_t mfn)
 {
     struct vcpu *curr = current;
     struct domain *d = curr->domain;
     int rc;
-    unsigned long old_base_mfn;
+    mfn_t old_base_mfn;
 
Quoted 9 lines

xen/arch/x86/mm.c int vcpu_destroy_pagetables(struct vcpu *v) · line 2785

Quoted 6 lines
xen/arch/x86/mm.c +2 -2
     if ( is_pv_32bit_domain(d) )
     {
-        unsigned long gt_mfn = pagetable_get_pfn(curr->arch.guest_table);
-        l4_pgentry_t *pl4e = map_domain_page(_mfn(gt_mfn));
+        mfn_t mmfn = pagetable_get_mfn(curr->arch.guest_table);
+        l4_pgentry_t *pl4e = map_domain_page(mmfn);

What was wrong with "gt_mfn" for "guest table MFN"? I can't help thinking mmfn is a typo, where you've hit the m key one too many times. What is that first m supposed to stand for?

Quoted 2 lines

mmfn is the shadow code nomenclature for the monitor mfn. I can move back to gt_mfn if you think thats clearer.

I'm not going to insist, but I'd appreciate keeping the original name.

Jan

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

Acked-by on v1 1/2
#10 lore raw
In reply to Andrew Cooper
Quoted 3 lines · Andrew Cooper

No functional change (as confirmed by diffing the assembly).

Quoted 161 lines

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>

For some reason best known to GCC, there is one single change:

(quoted diff) +1 -1
@@ -145835,7 +145835,7 @@
 ffff82d0802864f8:      85 c0                   test   %eax,%eax
 ffff82d0802864fa:      75 e0                   jne    ffff82d0802864dc <new_guest_cr3+0x7c>
 ffff82d0802864fc:      4c 8b ad 08 0b 00 00    mov    0xb08(%rbp),%r13
-ffff82d080286503:      49 39 dd                cmp    %rbx,%r13
+ffff82d080286503:      4c 39 eb                cmp    %r13,%rbx
 ffff82d080286506:      0f 84 74 01 00 00       je     ffff82d080286680 <new_guest_cr3+0x220>
 ffff82d08028650c:      41 f6 84 24 19 06 00    testb  $0x8,0x619(%r12)
 ffff82d080286513:      00 08

This is from the mfn_eq() alteration, and must be a side effect from using an inline function. The net result is still correct, as only the zero flag is checked.

---
 xen/arch/x86/mm.c              | 35 ++++++++++++++++++-----------------
 xen/arch/x86/pv/emul-priv-op.c |  2 +-
 xen/include/asm-x86/mm.h       |  2 +-
 3 files changed, 20 insertions(+), 19 deletions(-)
xen/arch/x86/mm.c +18 -17
index 1f23470..dc07b4f 100644
@@ -2772,23 +2772,23 @@ int vcpu_destroy_pagetables(struct vcpu *v)
     return rc != -EINTR ? rc : -ERESTART;
 }
 
-int new_guest_cr3(unsigned long mfn)
+int new_guest_cr3(mfn_t mfn)
 {
     struct vcpu *curr = current;
     struct domain *d = curr->domain;
     int rc;
-    unsigned long old_base_mfn;
+    mfn_t old_base_mfn;
 
     if ( is_pv_32bit_domain(d) )
     {
-        unsigned long gt_mfn = pagetable_get_pfn(curr->arch.guest_table);
-        l4_pgentry_t *pl4e = map_domain_page(_mfn(gt_mfn));
+        mfn_t mmfn = pagetable_get_mfn(curr->arch.guest_table);
+        l4_pgentry_t *pl4e = map_domain_page(mmfn);
 
         rc = mod_l4_entry(pl4e,
-                          l4e_from_pfn(mfn,
+                          l4e_from_mfn(mfn,
                                        (_PAGE_PRESENT | _PAGE_RW |
                                         _PAGE_USER | _PAGE_ACCESSED)),
-                          gt_mfn, 0, curr);
+                          mfn_x(mmfn), 0, curr);
         unmap_domain_page(pl4e);
         switch ( rc )
         {
@@ -2800,7 +2800,7 @@ int new_guest_cr3(unsigned long mfn)
         default:
             gdprintk(XENLOG_WARNING,
                      "Error while installing new compat baseptr %" PRI_mfn "\n",
-                     mfn);
+                     mfn_x(mfn));
             return rc;
         }
 
@@ -2814,20 +2814,20 @@ int new_guest_cr3(unsigned long mfn)
     if ( unlikely(rc) )
         return rc;
 
-    old_base_mfn = pagetable_get_pfn(curr->arch.guest_table);
+    old_base_mfn = pagetable_get_mfn(curr->arch.guest_table);
     /*
      * This is particularly important when getting restarted after the
      * previous attempt got preempted in the put-old-MFN phase.
      */
-    if ( old_base_mfn == mfn )
+    if ( mfn_eq(old_base_mfn, mfn) )
     {
         write_ptbase(curr);
         return 0;
     }
 
     rc = paging_mode_refcounts(d)
-         ? (get_page_from_mfn(_mfn(mfn), d) ? 0 : -EINVAL)
-         : get_page_and_type_from_mfn(_mfn(mfn), PGT_root_page_table, d, 0, 1);
+         ? (get_page_from_mfn(mfn, d) ? 0 : -EINVAL)
+         : get_page_and_type_from_mfn(mfn, PGT_root_page_table, d, 0, 1);
     switch ( rc )
     {
     case 0:
@@ -2837,22 +2837,23 @@ int new_guest_cr3(unsigned long mfn)
         return -ERESTART;
     default:
         gdprintk(XENLOG_WARNING,
-                 "Error while installing new baseptr %" PRI_mfn "\n", mfn);
+                 "Error while installing new baseptr %" PRI_mfn "\n",
+                 mfn_x(mfn));
         return rc;
     }
 
     invalidate_shadow_ldt(curr, 0);
 
     if ( !VM_ASSIST(d, m2p_strict) && !paging_mode_refcounts(d) )
-        fill_ro_mpt(_mfn(mfn));
-    curr->arch.guest_table = pagetable_from_pfn(mfn);
+        fill_ro_mpt(mfn);
+    curr->arch.guest_table = pagetable_from_mfn(mfn);
     update_cr3(curr);
 
     write_ptbase(curr);
 
-    if ( likely(old_base_mfn != 0) )
+    if ( likely(mfn_x(old_base_mfn) != 0) )
     {
-        struct page_info *page = mfn_to_page(_mfn(old_base_mfn));
+        struct page_info *page = mfn_to_page(old_base_mfn);
 
         if ( paging_mode_refcounts(d) )
             put_page(page);
@@ -3180,7 +3181,7 @@ long do_mmuext_op(
             else if ( unlikely(paging_mode_translate(currd)) )
                 rc = -EINVAL;
             else
-                rc = new_guest_cr3(op.arg1.mfn);
+                rc = new_guest_cr3(_mfn(op.arg1.mfn));
             break;
 
         case MMUEXT_NEW_USER_BASEPTR: {
xen/arch/x86/pv/emul-priv-op.c +1 -1
index af1624a..54a63c2 100644
@@ -774,7 +774,7 @@ static int priv_op_write_cr(unsigned int reg, unsigned long val,
         page = get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC);
         if ( !page )
             break;
-        rc = new_guest_cr3(mfn_x(page_to_mfn(page)));
+        rc = new_guest_cr3(page_to_mfn(page));
         put_page(page);
 
         switch ( rc )
xen/include/asm-x86/mm.h +1 -2
index ec7ce3c..4c03a33 100644
@@ -539,7 +539,7 @@ void audit_domains(void);
 
 #endif
 
-int new_guest_cr3(unsigned long pfn);
+int new_guest_cr3(mfn_t mfn);
 void make_cr3(struct vcpu *v, unsigned long mfn);
 void update_cr3(struct vcpu *v);
 int vcpu_destroy_pagetables(struct vcpu *);
--

2.1.4

Quoted 4 lines

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

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