diff mbox series

[v2,2/3] x86/mm: Introduce altp2m_set_entry_by_page_order

Message ID 20190405132521.6630-2-aisaila@bitdefender.com (mailing list archive)
State Superseded
Headers show
Series [v2,1/3] x86/mm: Introduce altp2m_get_gfn_type_access | expand

Commit Message

Alexandru Stefan ISAILA April 5, 2019, 1:25 p.m. UTC
This patch moves common code from p2m_set_altp2m_mem_access() and
p2m_change_altp2m_gfn() into one function

Signed-off-by: Alexandru Isaila <aisaila@bitdefender.com>
---
 xen/arch/x86/mm/mem_access.c |  7 ++-----
 xen/arch/x86/mm/p2m.c        | 12 ++----------
 xen/include/asm-x86/p2m.h    | 11 +++++++++++
 3 files changed, 15 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c
index 608f748a57..a26727dfee 100644
--- a/xen/arch/x86/mm/mem_access.c
+++ b/xen/arch/x86/mm/mem_access.c
@@ -275,11 +275,8 @@  int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m,
     /* If this is a superpage, copy that first */
     if ( page_order != PAGE_ORDER_4K && found_in_hostp2m )
     {
-        unsigned long mask = ~((1UL << page_order) - 1);
-        gfn_t gfn2 = _gfn(gfn_l & mask);
-        mfn_t mfn2 = _mfn(mfn_x(mfn) & mask);
-
-        rc = ap2m->set_entry(ap2m, gfn2, mfn2, page_order, t, old_a, 1);
+        rc = altp2m_set_entry_by_page_order(ap2m, gfn_l, mfn, page_order,
+                                            t, old_a);
         if ( rc )
             return rc;
     }
diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index b2a5c0c42e..1f852694ff 100644
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -2653,17 +2653,9 @@  int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx,
 
     /* If this is a superpage, copy that first */
     if ( page_order != PAGE_ORDER_4K && found_in_hostp2m )
-    {
-        gfn_t gfn;
-        unsigned long mask;
-
-        mask = ~((1UL << page_order) - 1);
-        gfn = _gfn(gfn_x(old_gfn) & mask);
-        mfn = _mfn(mfn_x(mfn) & mask);
-
-        if ( ap2m->set_entry(ap2m, gfn, mfn, page_order, t, a, 1) )
+        if ( altp2m_set_entry_by_page_order(ap2m, gfn_x(old_gfn), mfn,
+                                            page_order, t, a) )
             goto out;
-    }
 
     mfn = altp2m_get_gfn_type_access(ap2m, new_gfn, &t, &a, &page_order, &found_in_hostp2m);
 
diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h
index 42068b4aed..8ac9427743 100644
--- a/xen/include/asm-x86/p2m.h
+++ b/xen/include/asm-x86/p2m.h
@@ -471,6 +471,17 @@  static inline mfn_t altp2m_get_gfn_type_access(
     return mfn;
 }
 
+static inline int altp2m_set_entry_by_page_order(
+    struct p2m_domain *ap2m, unsigned long gfn,  mfn_t mfn,
+    unsigned int page_order, p2m_type_t t, p2m_access_t a)
+{
+    unsigned long mask = ~((1UL << page_order) - 1);
+    gfn_t gfn2 = _gfn(gfn & mask);
+    mfn_t mfn2 = _mfn(mfn_x(mfn) & mask);
+
+    return ap2m->set_entry(ap2m, gfn2, mfn2, page_order, t, a, 1);
+}
+
 /* Syntactic sugar: most callers will use one of these. */
 #define get_gfn(d, g, t)         get_gfn_type((d), (g), (t), P2M_ALLOC)
 #define get_gfn_query(d, g, t)   get_gfn_type((d), (g), (t), 0)