@@ -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;
}
@@ -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);
@@ -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)
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(-)