x86/pv: Consistently use typesafe helpers in all files
authorAndrew Cooper <andrew.cooper3@citrix.com>
Sat, 26 Aug 2017 10:40:56 +0000 (10:40 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 30 Aug 2017 10:03:08 +0000 (11:03 +0100)
Rather than having a mix of code behaviour.  This requires updating
pagetable_{get,from}_page() to use the non-overridden helpers.

This requires some adjustments in priv_op_{read,write}_cr(), which is most
easily done by switching CR3 handling to using mfn_t.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/pv/callback.c
xen/arch/x86/pv/domain.c
xen/arch/x86/pv/emul-gate-op.c
xen/arch/x86/pv/emul-priv-op.c
xen/arch/x86/pv/iret.c
xen/arch/x86/pv/traps.c
xen/include/asm-x86/page.h

index 5957cb5085ba1481d1a1eed63a2bf4375757e77e..97d8438600acdcb54516ac0bc1fd4128b1f99285 100644 (file)
 
 #include <public/callback.h>
 
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+
 static int register_guest_nmi_callback(unsigned long address)
 {
     struct vcpu *curr = current;
index 6cb61f2e14cb9d048c764bd14af0882491784cd1..c8b9cb645b2993dbc8e01140edef681eb9615526 100644 (file)
 
 #include <asm/pv/domain.h>
 
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+
 static void noreturn continue_nonidle_domain(struct vcpu *v)
 {
     check_wakeup_from_wait();
index cdf3b308f2845728ae1deb42b283534a0b23b633..0a7381a094be43d55ac762bf7eba4b7de30e3329 100644 (file)
 
 #include "emulate.h"
 
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+
 static int read_gate_descriptor(unsigned int gate_sel,
                                 const struct vcpu *v,
                                 unsigned int *sel,
index d50f51944f177347b37aea02395c513072dedf8a..af1624ae268694bae825fcd5320286d4840d1f72 100644 (file)
 #include "../x86_64/mmconfig.h"
 #include "emulate.h"
 
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+
 /***********************
  * I/O emulation support
  */
@@ -709,21 +715,21 @@ static int priv_op_read_cr(unsigned int reg, unsigned long *val,
     case 3: /* Read CR3 */
     {
         const struct domain *currd = curr->domain;
-        unsigned long mfn;
+        mfn_t mfn;
 
         if ( !is_pv_32bit_domain(currd) )
         {
-            mfn = pagetable_get_pfn(curr->arch.guest_table);
-            *val = xen_pfn_to_cr3(mfn_to_gmfn(currd, mfn));
+            mfn = pagetable_get_mfn(curr->arch.guest_table);
+            *val = xen_pfn_to_cr3(mfn_to_gmfn(currd, mfn_x(mfn)));
         }
         else
         {
             l4_pgentry_t *pl4e =
-                map_domain_page(_mfn(pagetable_get_pfn(curr->arch.guest_table)));
+                map_domain_page(pagetable_get_mfn(curr->arch.guest_table));
 
-            mfn = l4e_get_pfn(*pl4e);
+            mfn = l4e_get_mfn(*pl4e);
             unmap_domain_page(pl4e);
-            *val = compat_pfn_to_cr3(mfn_to_gmfn(currd, mfn));
+            *val = compat_pfn_to_cr3(mfn_to_gmfn(currd, mfn_x(mfn)));
         }
         /* PTs should not be shared */
         BUG_ON(page_get_owner(mfn_to_page(mfn)) == dom_cow);
@@ -768,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(page_to_mfn(page));
+        rc = new_guest_cr3(mfn_x(page_to_mfn(page)));
         put_page(page);
 
         switch ( rc )
index ca433a69c446c2641146be437b9db2e37bc7388a..56aeac360a6c498c7a87189f79d0c9573bf672bb 100644 (file)
 #include <asm/current.h>
 #include <asm/traps.h>
 
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+
 unsigned long do_iret(void)
 {
     struct cpu_user_regs *regs = guest_cpu_user_regs();
index 2a605edf7f8056c0dd78f64c3f7a92f8750a3efb..d122881d1332823d906468367f5ec7d776bc60b2 100644 (file)
 #include <asm/shared.h>
 #include <asm/traps.h>
 
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+
 void do_entry_int82(struct cpu_user_regs *regs)
 {
     if ( unlikely(untrusted_msi) )
index b4ce5ae47427656bb3a86e43f6c47588960ca699..cde5c6b89b8b4ef84631d824e1894821ce632113 100644 (file)
@@ -215,13 +215,13 @@ static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags)
 /* Page-table type. */
 typedef struct { u64 pfn; } pagetable_t;
 #define pagetable_get_paddr(x)  ((paddr_t)(x).pfn << PAGE_SHIFT)
-#define pagetable_get_page(x)   mfn_to_page((x).pfn)
+#define pagetable_get_page(x)   __mfn_to_page((x).pfn)
 #define pagetable_get_pfn(x)    ((x).pfn)
 #define pagetable_get_mfn(x)    _mfn(((x).pfn))
 #define pagetable_is_null(x)    ((x).pfn == 0)
 #define pagetable_from_pfn(pfn) ((pagetable_t) { (pfn) })
 #define pagetable_from_mfn(mfn) ((pagetable_t) { mfn_x(mfn) })
-#define pagetable_from_page(pg) pagetable_from_pfn(page_to_mfn(pg))
+#define pagetable_from_page(pg) pagetable_from_pfn(__page_to_mfn(pg))
 #define pagetable_from_paddr(p) pagetable_from_pfn((p)>>PAGE_SHIFT)
 #define pagetable_null()        pagetable_from_pfn(0)