All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: sstabellini@kernel.org, xen-devel@lists.xenproject.org
Cc: Julien Grall <julien.grall@arm.com>
Subject: [PATCH 2/8] xen/arm: p2m: Introduce p2m_get_page_from_gfn
Date: Tue,  6 Nov 2018 19:14:48 +0000	[thread overview]
Message-ID: <20181106191454.22143-3-julien.grall@arm.com> (raw)
In-Reply-To: <20181106191454.22143-1-julien.grall@arm.com>

In a follow-up patches, we will need to handle get_page_from_gfn
differently for DOMID_XEN. To keep the code simple move the current
content in a new separate helper p2m_get_page_from_gfn.

Note the new helper is a not anymore a static inline function as the helper
is quite complex.

Finally, take the opportunity to use typesafe gfn as the change is
minor.

Signed-off-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/p2m.c        | 32 ++++++++++++++++++++++++++++++++
 xen/include/asm-arm/p2m.h | 33 ++++-----------------------------
 2 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index 30cfb01498..04c8718e9f 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -379,6 +379,38 @@ mfn_t p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t)
     return mfn;
 }
 
+struct page_info *p2m_get_page_from_gfn(struct domain *d, gfn_t gfn,
+                                        p2m_type_t *t)
+{
+    struct page_info *page;
+    p2m_type_t p2mt;
+    mfn_t mfn = p2m_lookup(d, gfn, &p2mt);
+
+    if (t)
+        *t = p2mt;
+
+    if ( !p2m_is_any_ram(p2mt) )
+        return NULL;
+
+    if ( !mfn_valid(mfn) )
+        return NULL;
+    page = mfn_to_page(mfn);
+
+    /*
+     * get_page won't work on foreign mapping because the page doesn't
+     * belong to the current domain.
+     */
+    if ( p2m_is_foreign(p2mt) )
+    {
+        struct domain *fdom = page_get_owner_and_reference(page);
+        ASSERT(fdom != NULL);
+        ASSERT(fdom != d);
+        return page;
+    }
+
+    return (get_page(page, d) ? page: NULL);
+}
+
 int guest_physmap_mark_populate_on_demand(struct domain *d,
                                           unsigned long gfn,
                                           unsigned int order)
diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
index c03557544a..a5914136e3 100644
--- a/xen/include/asm-arm/p2m.h
+++ b/xen/include/asm-arm/p2m.h
@@ -269,38 +269,13 @@ typedef unsigned int p2m_query_t;
 #define P2M_ALLOC    (1u<<0)   /* Populate PoD and paged-out entries */
 #define P2M_UNSHARE  (1u<<1)   /* Break CoW sharing */
 
+struct page_info *p2m_get_page_from_gfn(struct domain *d, gfn_t gfn,
+                                        p2m_type_t *t);
+
 static inline struct page_info *get_page_from_gfn(
     struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q)
 {
-    struct page_info *page;
-    p2m_type_t p2mt;
-    mfn_t mfn = p2m_lookup(d, _gfn(gfn), &p2mt);
-
-    if (t)
-        *t = p2mt;
-
-    if ( !p2m_is_any_ram(p2mt) )
-        return NULL;
-
-    if ( !mfn_valid(mfn) )
-        return NULL;
-    page = mfn_to_page(mfn);
-
-    /*
-     * get_page won't work on foreign mapping because the page doesn't
-     * belong to the current domain.
-     */
-    if ( p2m_is_foreign(p2mt) )
-    {
-        struct domain *fdom = page_get_owner_and_reference(page);
-        ASSERT(fdom != NULL);
-        ASSERT(fdom != d);
-        return page;
-    }
-
-    if ( !get_page(page, d) )
-        return NULL;
-    return page;
+    return p2m_get_page_from_gfn(d, _gfn(gfn), t);
 }
 
 int get_page_type(struct page_info *page, unsigned long type);
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-11-06 19:15 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-06 19:14 [PATCH 0/8] xen/arm: Add xentrace support Julien Grall
2018-11-06 19:14 ` [PATCH 1/8] xen/page_alloc: Move get_pg_owner()/put_pg_owner() from x86 to common code Julien Grall
2018-11-07  9:28   ` Jan Beulich
2018-11-09 18:06     ` Julien Grall
2018-11-06 19:14 ` Julien Grall [this message]
2018-11-15 13:31   ` [PATCH 2/8] xen/arm: p2m: Introduce p2m_get_page_from_gfn Andrii Anisov
2018-11-15 13:35     ` Andrii Anisov
2018-11-15 15:22     ` Julien Grall
2018-12-20 11:20       ` Andrii Anisov
2018-11-06 19:14 ` [PATCH 3/8] xen/arm: Rename p2m_map_foreign to p2m_map_foreign_rw Julien Grall
2018-11-15 11:42   ` Andrii Anisov
2018-11-15 12:07     ` Julien Grall
2018-11-06 19:14 ` [PATCH 4/8] xen/arm: Add support for read-only foreign mappings Julien Grall
2018-11-15 11:33   ` Andrii Anisov
2018-11-15 11:40     ` Julien Grall
2018-11-15 12:02       ` Andrii Anisov
2018-11-15 12:09         ` Julien Grall
2018-11-15 13:19           ` Andrii Anisov
2018-11-15 15:05             ` Julien Grall
2018-11-15 18:44               ` Stefano Stabellini
2018-11-15 19:06                 ` Julien Grall
2018-11-15 19:48                   ` Stefano Stabellini
2018-11-15 20:20                     ` Julien Grall
2018-11-16  9:05                       ` Andrii Anisov
2018-11-16  8:37               ` Andrii Anisov
2018-11-20 15:27               ` Andrii Anisov
2018-12-20 11:21               ` Andrii Anisov
2018-11-06 19:14 ` [PATCH 5/8] xen/arm: Allow a privileged domain to map foreign page from DOMID_XEN Julien Grall
2018-11-15 13:45   ` Andrii Anisov
2018-11-06 19:14 ` [PATCH 6/8] xen/arm: Initialize trace buffer Julien Grall
2018-11-15 13:49   ` Andrii Anisov
2018-11-06 19:14 ` [PATCH 7/8] xenalyze: Build for Both ARM and x86 Platforms Julien Grall
2018-11-07 13:04   ` Wei Liu
2018-11-06 19:14 ` [PATCH 8/8] xen: Swich parameter in get_page_from_gfn to use typesafe gfn Julien Grall
2018-11-06 20:11   ` Andrew Cooper
2018-11-07  8:57     ` Paul Durrant
2018-11-07 13:08       ` Andrew Cooper
2018-11-07 13:08     ` Julien Grall
2018-11-07  9:24   ` Paul Durrant
2018-11-07 13:05     ` Julien Grall
2018-11-12 16:49   ` Andrii Anisov
2018-11-12 16:52     ` Julien Grall
2018-11-12 16:58       ` Andrii Anisov
2018-11-12 17:09         ` Julien Grall

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=20181106191454.22143-3-julien.grall@arm.com \
    --to=julien.grall@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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.