All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Pop <apop@bitdefender.com>
To: xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Razvan Cojocaru <rcojocaru@bitdefender.com>,
	George Dunlap <george.dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Adrian Pop <apop@bitdefender.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
	Julien Grall <julien.grall@arm.com>,
	Tamas K Lengyel <tamas@tklengyel.com>,
	Jan Beulich <jbeulich@suse.com>
Subject: [PATCH v2 1/2] x86/mem_access: Add a helper function for memaccess conversion
Date: Thu,  5 Jul 2018 13:44:44 +0300	[thread overview]
Message-ID: <20180705104445.8048-2-apop@bitdefender.com> (raw)
In-Reply-To: <20180705104445.8048-1-apop@bitdefender.com>

The p2m_access_to_xenmem_access() converts a p2m_access_t to a
xenmem_access_t.  It is complementary to xenmem_access_to_p2m_access().
It is currently only used by _p2m_get_mem_access().

Signed-off-by: Adrian Pop <apop@bitdefender.com>
---
 xen/arch/x86/mm/mem_access.c | 41 +++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c
index c0cd0174cf..e75ff0c735 100644
--- a/xen/arch/x86/mm/mem_access.c
+++ b/xen/arch/x86/mm/mem_access.c
@@ -33,16 +33,12 @@
 #include "mm-locks.h"
 
 /*
- * Get access type for a gfn.
- * If gfn == INVALID_GFN, gets the default access type.
+ * Convert a p2m_access_t to a xenmem_access_t.
  */
-static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn,
-                               xenmem_access_t *access)
+static int p2m_access_to_xenmem_access(struct p2m_domain *p2m,
+                                       p2m_access_t paccess,
+                                       xenmem_access_t *xaccess)
 {
-    p2m_type_t t;
-    p2m_access_t a;
-    mfn_t mfn;
-
     static const xenmem_access_t memaccess[] = {
 #define ACCESS(ac) [p2m_access_##ac] = XENMEM_access_##ac
             ACCESS(n),
@@ -58,12 +54,27 @@ static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn,
 #undef ACCESS
     };
 
+    if ( (unsigned int)paccess >= ARRAY_SIZE(memaccess) )
+        return -ERANGE;
+
+    *xaccess = memaccess[paccess];
+    return 0;
+}
+
+/*
+ * Get access type for a gfn.
+ * If gfn == INVALID_GFN, gets the default access type.
+ */
+static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn,
+                               xenmem_access_t *access)
+{
+    p2m_type_t t;
+    p2m_access_t a;
+    mfn_t mfn;
+
     /* If request to get default access. */
     if ( gfn_eq(gfn, INVALID_GFN) )
-    {
-        *access = memaccess[p2m->default_access];
-        return 0;
-    }
+        return p2m_access_to_xenmem_access(p2m, p2m->default_access, access);
 
     gfn_lock(p2m, gfn, 0);
     mfn = p2m->get_entry(p2m, gfn, &t, &a, 0, NULL, NULL);
@@ -72,11 +83,7 @@ static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn,
     if ( mfn_eq(mfn, INVALID_MFN) )
         return -ESRCH;
 
-    if ( (unsigned int)a >= ARRAY_SIZE(memaccess) )
-        return -ERANGE;
-
-    *access =  memaccess[a];
-    return 0;
+    return access_to_xenmem_access(p2m, a, access);
 }
 
 bool p2m_mem_access_emulate_check(struct vcpu *v,
-- 
2.17.0


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

  reply	other threads:[~2018-07-05 10:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-05 10:44 [PATCH v2 0/2] Add an altp2m subop for obtaining the page mem access Adrian Pop
2018-07-05 10:44 ` Adrian Pop [this message]
2018-07-05 16:53   ` [PATCH v2 1/2] x86/mem_access: Add a helper function for memaccess conversion Tamas K Lengyel
2018-07-05 21:07     ` Adrian Pop
2018-07-05 10:44 ` [PATCH v2 2/2] x86/altp2m: Add a subop for obtaining the memaccess of a page Adrian Pop
2018-07-09  8:35   ` Jan Beulich
2018-07-09  8:44     ` Razvan Cojocaru
2018-07-18  9:24     ` Adrian Pop

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=20180705104445.8048-2-apop@bitdefender.com \
    --to=apop@bitdefender.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=rcojocaru@bitdefender.com \
    --cc=sstabellini@kernel.org \
    --cc=tamas@tklengyel.com \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --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.