From: Julien Grall <julien.grall@arm.com>
To: xen-devel@lists.xen.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Wei Liu <wei.liu2@citrix.com>,
George Dunlap <George.Dunlap@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
Julien Grall <julien.grall@arm.com>,
Jan Beulich <jbeulich@suse.com>
Subject: [PATCH v4 12/16] xen/mm: Switch common/memory.c to use typesafe MFN
Date: Wed, 21 Feb 2018 14:02:55 +0000 [thread overview]
Message-ID: <20180221140259.29360-13-julien.grall@arm.com> (raw)
In-Reply-To: <20180221140259.29360-1-julien.grall@arm.com>
A new helper copy_mfn_to_guest is introduced to easily to copy a MFN to
the guest memory.
Not functional change intended
Signed-off-by: Julien Grall <julien.grall@arm.com>
---
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: George Dunlap <George.Dunlap@eu.citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Tim Deegan <tim@xen.org>
Cc: Wei Liu <wei.liu2@citrix.com>
Changes in v4:
- Patch added
---
xen/common/memory.c | 72 ++++++++++++++++++++++++++++++++---------------------
1 file changed, 44 insertions(+), 28 deletions(-)
diff --git a/xen/common/memory.c b/xen/common/memory.c
index 59d23a2a98..93d856df02 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -33,6 +33,12 @@
#include <asm/guest.h>
#endif
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+
struct memop_args {
/* INPUT */
struct domain *domain; /* Domain to be affected. */
@@ -95,11 +101,18 @@ static unsigned int max_order(const struct domain *d)
return min(order, MAX_ORDER + 0U);
}
+/* Helper to copy a typesafe MFN to guest */
+#define copy_mfn_to_guest(hnd, off, mfn) \
+ ({ \
+ xen_pfn_t mfn_ = mfn_x(mfn); \
+ __copy_to_guest_offset(hnd, off, &mfn_, 1); \
+ })
+
static void increase_reservation(struct memop_args *a)
{
struct page_info *page;
unsigned long i;
- xen_pfn_t mfn;
+ mfn_t mfn;
struct domain *d = a->domain;
if ( !guest_handle_is_null(a->extent_list) &&
@@ -133,7 +146,7 @@ static void increase_reservation(struct memop_args *a)
!guest_handle_is_null(a->extent_list) )
{
mfn = page_to_mfn(page);
- if ( unlikely(__copy_to_guest_offset(a->extent_list, i, &mfn, 1)) )
+ if ( unlikely(copy_mfn_to_guest(a->extent_list, i, mfn)) )
goto out;
}
}
@@ -146,7 +159,8 @@ static void populate_physmap(struct memop_args *a)
{
struct page_info *page;
unsigned int i, j;
- xen_pfn_t gpfn, mfn;
+ xen_pfn_t gpfn;
+ mfn_t mfn;
struct domain *d = a->domain, *curr_d = current->domain;
bool need_tlbflush = false;
uint32_t tlbflush_timestamp = 0;
@@ -205,14 +219,15 @@ static void populate_physmap(struct memop_args *a)
{
if ( is_domain_direct_mapped(d) )
{
- mfn = gpfn;
+ mfn = _mfn(gpfn);
- for ( j = 0; j < (1U << a->extent_order); j++, mfn++ )
+ for ( j = 0; j < (1U << a->extent_order); j++,
+ mfn = mfn_add(mfn, 1) )
{
- if ( !mfn_valid(_mfn(mfn)) )
+ if ( !mfn_valid(mfn) )
{
- gdprintk(XENLOG_INFO, "Invalid mfn %#"PRI_xen_pfn"\n",
- mfn);
+ gdprintk(XENLOG_INFO, "Invalid mfn %#"PRI_mfn"\n",
+ mfn_x(mfn));
goto out;
}
@@ -220,14 +235,14 @@ static void populate_physmap(struct memop_args *a)
if ( !get_page(page, d) )
{
gdprintk(XENLOG_INFO,
- "mfn %#"PRI_xen_pfn" doesn't belong to d%d\n",
- mfn, d->domain_id);
+ "mfn %#"PRI_mfn" doesn't belong to d%d\n",
+ mfn_x(mfn), d->domain_id);
goto out;
}
put_page(page);
}
- mfn = gpfn;
+ mfn = _mfn(gpfn);
}
else
{
@@ -253,15 +268,15 @@ static void populate_physmap(struct memop_args *a)
mfn = page_to_mfn(page);
}
- guest_physmap_add_page(d, _gfn(gpfn), _mfn(mfn), a->extent_order);
+ guest_physmap_add_page(d, _gfn(gpfn), mfn, a->extent_order);
if ( !paging_mode_translate(d) )
{
for ( j = 0; j < (1U << a->extent_order); j++ )
- set_gpfn_from_mfn(mfn + j, gpfn + j);
+ set_gpfn_from_mfn(mfn_x(mfn_add(mfn, j)), gpfn + j);
/* Inform the domain of the new page's machine address. */
- if ( unlikely(__copy_to_guest_offset(a->extent_list, i, &mfn, 1)) )
+ if ( unlikely(copy_mfn_to_guest(a->extent_list, i, mfn)) )
goto out;
}
}
@@ -304,7 +319,7 @@ int guest_remove_page(struct domain *d, unsigned long gmfn)
if ( p2mt == p2m_ram_paging_out )
{
ASSERT(mfn_valid(mfn));
- page = mfn_to_page(mfn_x(mfn));
+ page = mfn_to_page(mfn);
if ( test_and_clear_bit(_PGC_allocated, &page->count_info) )
put_page(page);
}
@@ -349,7 +364,7 @@ int guest_remove_page(struct domain *d, unsigned long gmfn)
}
#endif /* CONFIG_X86 */
- page = mfn_to_page(mfn_x(mfn));
+ page = mfn_to_page(mfn);
if ( unlikely(!get_page(page, d)) )
{
put_gfn(d, gmfn);
@@ -490,7 +505,8 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
PAGE_LIST_HEAD(in_chunk_list);
PAGE_LIST_HEAD(out_chunk_list);
unsigned long in_chunk_order, out_chunk_order;
- xen_pfn_t gpfn, gmfn, mfn;
+ xen_pfn_t gpfn, gmfn;
+ mfn_t mfn;
unsigned long i, j, k;
unsigned int memflags = 0;
long rc = 0;
@@ -612,7 +628,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
p2m_type_t p2mt;
/* Shared pages cannot be exchanged */
- mfn = mfn_x(get_gfn_unshare(d, gmfn + k, &p2mt));
+ mfn = get_gfn_unshare(d, gmfn + k, &p2mt);
if ( p2m_is_shared(p2mt) )
{
put_gfn(d, gmfn + k);
@@ -620,9 +636,9 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
goto fail;
}
#else /* !CONFIG_X86 */
- mfn = mfn_x(gfn_to_mfn(d, _gfn(gmfn + k)));
+ mfn = gfn_to_mfn(d, _gfn(gmfn + k));
#endif
- if ( unlikely(!mfn_valid(_mfn(mfn))) )
+ if ( unlikely(!mfn_valid(mfn)) )
{
put_gfn(d, gmfn + k);
rc = -EINVAL;
@@ -669,10 +685,10 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
if ( !test_and_clear_bit(_PGC_allocated, &page->count_info) )
BUG();
mfn = page_to_mfn(page);
- gfn = mfn_to_gmfn(d, mfn);
+ gfn = mfn_to_gmfn(d, mfn_x(mfn));
/* Pages were unshared above */
BUG_ON(SHARED_M2P(gfn));
- if ( guest_physmap_remove_page(d, _gfn(gfn), _mfn(mfn), 0) )
+ if ( guest_physmap_remove_page(d, _gfn(gfn), mfn, 0) )
domain_crash(d);
put_page(page);
}
@@ -717,16 +733,16 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
}
mfn = page_to_mfn(page);
- guest_physmap_add_page(d, _gfn(gpfn), _mfn(mfn),
+ guest_physmap_add_page(d, _gfn(gpfn), mfn,
exch.out.extent_order);
if ( !paging_mode_translate(d) )
{
for ( k = 0; k < (1UL << exch.out.extent_order); k++ )
- set_gpfn_from_mfn(mfn + k, gpfn + k);
- if ( __copy_to_guest_offset(exch.out.extent_start,
- (i << out_chunk_order) + j,
- &mfn, 1) )
+ set_gpfn_from_mfn(mfn_x(mfn_add(mfn, k)), gpfn + k);
+ if ( copy_mfn_to_guest(exch.out.extent_start,
+ (i << out_chunk_order) + j,
+ mfn) )
rc = -EFAULT;
}
}
@@ -1221,7 +1237,7 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
if ( page )
{
rc = guest_physmap_remove_page(d, _gfn(xrfp.gpfn),
- _mfn(page_to_mfn(page)), 0);
+ page_to_mfn(page), 0);
put_page(page);
}
else
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-02-21 14:02 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-21 14:02 [PATCH v4 00/16] xen: Convert page_to_mfn and mfn_to_page to use typesafe MFN Julien Grall
2018-02-21 14:02 ` [PATCH v4 01/16] xen/tmem: Convert the file common/tmem_xen.c " Julien Grall
2018-02-21 14:02 ` [PATCH v4 02/16] xen/arm: setup: use maddr_to_mfn rather than _mfn(paddr_to_pfn(...)) Julien Grall
2018-02-21 14:02 ` [PATCH v4 03/16] xen/arm: mm: Use gaddr_to_gfn rather than _gfn(paddr_to_pfn(...)) Julien Grall
2018-02-21 14:02 ` [PATCH v4 04/16] xen/arm: mm: Remove unused M2P code Julien Grall
2018-02-21 14:02 ` [PATCH v4 05/16] xen/arm: mm: Remove unused relinquish_shared_pages Julien Grall
2018-02-21 14:02 ` [PATCH v4 06/16] xen/x86: Remove unused override of page_to_mfn/mfn_to_page Julien Grall
2018-03-01 11:20 ` George Dunlap
2018-03-02 14:42 ` Jan Beulich
2018-03-02 14:44 ` Julien Grall
2018-03-02 15:11 ` Jan Beulich
2018-03-05 13:29 ` Julien Grall
2018-02-21 14:02 ` [PATCH v4 07/16] xen/x86: mm: Switch x86/mm.c to use typesafe for virt_to_mfn Julien Grall
2018-03-02 14:45 ` Jan Beulich
2018-03-02 14:46 ` Julien Grall
2018-02-21 14:02 ` [PATCH v4 08/16] xen/mm: Drop the parameter mfn from populate_pt_range Julien Grall
2018-02-22 16:35 ` Wei Liu
2018-02-22 16:40 ` Julien Grall
2018-02-22 16:51 ` Wei Liu
2018-02-22 16:55 ` Julien Grall
2018-02-22 17:10 ` Wei Liu
2018-03-02 14:55 ` Jan Beulich
2018-03-05 13:43 ` Julien Grall
2018-03-05 14:00 ` Jan Beulich
2018-03-05 14:11 ` Julien Grall
2018-03-05 14:38 ` Jan Beulich
2018-03-09 17:29 ` Wei Liu
2018-03-11 19:30 ` Julien Grall
2018-03-12 6:36 ` Jan Beulich
2018-03-14 15:22 ` Julien Grall
2018-02-21 14:02 ` [PATCH v4 09/16] xen/pdx: Introduce helper to convert MFN <-> PDX Julien Grall
2018-02-22 16:39 ` Wei Liu
2018-02-21 14:02 ` [PATCH v4 10/16] xen/mm: Switch map_pages_to_xen to use MFN typesafe Julien Grall
2018-02-23 4:59 ` Tian, Kevin
2018-02-23 17:21 ` Wei Liu
2018-03-02 15:06 ` Jan Beulich
2018-03-02 15:08 ` Jan Beulich
2018-03-05 14:07 ` Julien Grall
2018-03-05 14:39 ` Jan Beulich
2018-03-05 14:44 ` Julien Grall
2018-02-21 14:02 ` [PATCH v4 11/16] xen/mm: Switch page_alloc.c to typesafe MFN Julien Grall
2018-02-23 17:21 ` Wei Liu
2018-03-02 15:18 ` Jan Beulich
2018-03-02 15:57 ` Julien Grall
2018-02-21 14:02 ` Julien Grall [this message]
2018-02-23 17:26 ` [PATCH v4 12/16] xen/mm: Switch common/memory.c to use " Wei Liu
2018-02-23 17:46 ` Julien Grall
2018-02-23 18:05 ` Wei Liu
2018-02-23 18:06 ` Julien Grall
2018-02-23 18:10 ` Wei Liu
2018-03-02 15:34 ` Jan Beulich
2018-03-05 14:18 ` Julien Grall
2018-03-05 14:41 ` Jan Beulich
2018-03-09 17:33 ` Wei Liu
2018-03-11 19:44 ` Julien Grall
2018-03-12 6:39 ` Jan Beulich
2018-03-14 16:08 ` Julien Grall
2018-02-21 14:02 ` [PATCH v4 13/16] xen/grant: Switch {create, replace}_grant_p2m_mapping to " Julien Grall
2018-02-23 17:29 ` Wei Liu
2018-03-02 15:38 ` Jan Beulich
2018-02-21 14:02 ` [PATCH v4 14/16] xen/grant: Switch common/grant_table.c to use " Julien Grall
2018-02-23 17:30 ` Wei Liu
2018-03-02 15:54 ` Jan Beulich
2018-03-02 15:59 ` Julien Grall
2018-03-02 16:12 ` Jan Beulich
2018-02-21 14:02 ` [PATCH v4 15/16] xen/x86: Switch mfn_to_page in x86_64/mm.c " Julien Grall
2018-03-02 15:57 ` Jan Beulich
2018-02-21 14:02 ` [PATCH v4 16/16] xen: Convert page_to_mfn and mfn_to_page " Julien Grall
2018-02-21 14:25 ` Razvan Cojocaru
2018-02-21 14:59 ` Paul Durrant
2018-02-21 23:20 ` Boris Ostrovsky
2018-02-23 4:59 ` Tian, Kevin
2018-02-23 17:31 ` Wei Liu
2018-03-02 16:08 ` Jan Beulich
2018-03-14 17:02 ` Julien Grall
2018-03-15 7:07 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180221140259.29360-13-julien.grall@arm.com \
--to=julien.grall@arm.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=sstabellini@kernel.org \
--cc=tim@xen.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.