xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@linaro.org>
To: xen-devel@lists.xen.org
Cc: Julien Grall <julien.grall@linaro.org>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [PATCH v2 8/9] xen/tmem: Convert the file common/tmem_xen.c to use typesafe MFN
Date: Thu,  5 Oct 2017 18:42:21 +0100	[thread overview]
Message-ID: <20171005174222.29161-9-julien.grall@linaro.org> (raw)
In-Reply-To: <20171005174222.29161-1-julien.grall@linaro.org>

The file common/tmem_xen.c is now converted to use typesafe. This is
requiring to override the macro page_to_mfn to make it work with mfn_t.

Note that all variables converted to mfn_t havem there initial value,
when set, switch from 0 to INVALID_MFN. This is fine because the initial
values was always overriden before used.

Also add a couple of missing newlines suggested by Andrew in the code.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

---

Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

    Changes in v2:
        - Add missing newlines
        - Add Andrew's reviewed-by
---
 xen/common/tmem_xen.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/xen/common/tmem_xen.c b/xen/common/tmem_xen.c
index 20f74b268f..bd52e44faf 100644
--- a/xen/common/tmem_xen.c
+++ b/xen/common/tmem_xen.c
@@ -14,6 +14,10 @@
 #include <xen/cpu.h>
 #include <xen/init.h>
 
+/* 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))
+
 bool __read_mostly opt_tmem;
 boolean_param("tmem", opt_tmem);
 
@@ -31,7 +35,7 @@ static DEFINE_PER_CPU_READ_MOSTLY(unsigned char *, dstmem);
 static DEFINE_PER_CPU_READ_MOSTLY(void *, scratch_page);
 
 #if defined(CONFIG_ARM)
-static inline void *cli_get_page(xen_pfn_t cmfn, unsigned long *pcli_mfn,
+static inline void *cli_get_page(xen_pfn_t cmfn, mfn_t *pcli_mfn,
                                  struct page_info **pcli_pfp, bool cli_write)
 {
     ASSERT_UNREACHABLE();
@@ -39,14 +43,14 @@ static inline void *cli_get_page(xen_pfn_t cmfn, unsigned long *pcli_mfn,
 }
 
 static inline void cli_put_page(void *cli_va, struct page_info *cli_pfp,
-                                unsigned long cli_mfn, bool mark_dirty)
+                                mfn_t cli_mfn, bool mark_dirty)
 {
     ASSERT_UNREACHABLE();
 }
 #else
 #include <asm/p2m.h>
 
-static inline void *cli_get_page(xen_pfn_t cmfn, unsigned long *pcli_mfn,
+static inline void *cli_get_page(xen_pfn_t cmfn, mfn_t *pcli_mfn,
                                  struct page_info **pcli_pfp, bool cli_write)
 {
     p2m_type_t t;
@@ -68,16 +72,17 @@ static inline void *cli_get_page(xen_pfn_t cmfn, unsigned long *pcli_mfn,
 
     *pcli_mfn = page_to_mfn(page);
     *pcli_pfp = page;
-    return map_domain_page(_mfn(*pcli_mfn));
+
+    return map_domain_page(*pcli_mfn);
 }
 
 static inline void cli_put_page(void *cli_va, struct page_info *cli_pfp,
-                                unsigned long cli_mfn, bool mark_dirty)
+                                mfn_t cli_mfn, bool mark_dirty)
 {
     if ( mark_dirty )
     {
         put_page_and_type(cli_pfp);
-        paging_mark_dirty(current->domain, _mfn(cli_mfn));
+        paging_mark_dirty(current->domain, cli_mfn);
     }
     else
         put_page(cli_pfp);
@@ -88,14 +93,14 @@ static inline void cli_put_page(void *cli_va, struct page_info *cli_pfp,
 int tmem_copy_from_client(struct page_info *pfp,
     xen_pfn_t cmfn, tmem_cli_va_param_t clibuf)
 {
-    unsigned long tmem_mfn, cli_mfn = 0;
+    mfn_t tmem_mfn, cli_mfn = INVALID_MFN;
     char *tmem_va, *cli_va = NULL;
     struct page_info *cli_pfp = NULL;
     int rc = 1;
 
     ASSERT(pfp != NULL);
     tmem_mfn = page_to_mfn(pfp);
-    tmem_va = map_domain_page(_mfn(tmem_mfn));
+    tmem_va = map_domain_page(tmem_mfn);
     if ( guest_handle_is_null(clibuf) )
     {
         cli_va = cli_get_page(cmfn, &cli_mfn, &cli_pfp, 0);
@@ -125,7 +130,7 @@ int tmem_compress_from_client(xen_pfn_t cmfn,
     unsigned char *wmem = this_cpu(workmem);
     char *scratch = this_cpu(scratch_page);
     struct page_info *cli_pfp = NULL;
-    unsigned long cli_mfn = 0;
+    mfn_t cli_mfn = INVALID_MFN;
     void *cli_va = NULL;
 
     if ( dmem == NULL || wmem == NULL )
@@ -152,7 +157,7 @@ int tmem_compress_from_client(xen_pfn_t cmfn,
 int tmem_copy_to_client(xen_pfn_t cmfn, struct page_info *pfp,
     tmem_cli_va_param_t clibuf)
 {
-    unsigned long tmem_mfn, cli_mfn = 0;
+    mfn_t tmem_mfn, cli_mfn = INVALID_MFN;
     char *tmem_va, *cli_va = NULL;
     struct page_info *cli_pfp = NULL;
     int rc = 1;
@@ -165,7 +170,8 @@ int tmem_copy_to_client(xen_pfn_t cmfn, struct page_info *pfp,
             return -EFAULT;
     }
     tmem_mfn = page_to_mfn(pfp);
-    tmem_va = map_domain_page(_mfn(tmem_mfn));
+    tmem_va = map_domain_page(tmem_mfn);
+
     if ( cli_va )
     {
         memcpy(cli_va, tmem_va, PAGE_SIZE);
@@ -181,7 +187,7 @@ int tmem_copy_to_client(xen_pfn_t cmfn, struct page_info *pfp,
 int tmem_decompress_to_client(xen_pfn_t cmfn, void *tmem_va,
                                     size_t size, tmem_cli_va_param_t clibuf)
 {
-    unsigned long cli_mfn = 0;
+    mfn_t cli_mfn = INVALID_MFN;
     struct page_info *cli_pfp = NULL;
     void *cli_va = NULL;
     char *scratch = this_cpu(scratch_page);
-- 
2.11.0


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

  parent reply	other threads:[~2017-10-05 17:42 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-05 17:42 [PATCH v2 0/9] xen: Convert __page_to_mfn and __mfn_to_page to use typesafe MFN Julien Grall
2017-10-05 17:42 ` [PATCH v2 1/9] xen/arm: domain_build: Clean-up insert_11_bank Julien Grall
2017-10-05 17:42 ` [PATCH v2 2/9] xen/arm32: mm: Rework is_xen_heap_page to avoid nameclash Julien Grall
2017-10-05 17:42 ` [PATCH v2 3/9] xen/x86: mem_sharing: Use copy_domain_page in __mem_sharing_unshare_page Julien Grall
2017-10-05 17:49   ` Andrew Cooper
2017-10-05 17:52   ` Tamas K Lengyel
2017-10-05 17:42 ` [PATCH v2 4/9] xen/x86: Use maddr_to_page and maddr_to_mfn to avoid open-coded >> PAGE_SHIFT Julien Grall
2017-10-05 17:42 ` [PATCH v2 5/9] xen/kimage: Remove defined but unused variables Julien Grall
2017-10-05 17:42 ` [PATCH v2 6/9] xen/kexec, kimage: Convert kexec and kimage to use typesafe mfn_t Julien Grall
2017-10-05 17:51   ` Andrew Cooper
2017-10-05 17:42 ` [PATCH v2 7/9] xen/xenoprof: Convert the file to use typesafe MFN Julien Grall
2017-10-05 17:42 ` Julien Grall [this message]
2017-10-05 17:42 ` [PATCH v2 9/9] xen: Convert __page_to_mfn and __mfn_to_page " Julien Grall
2017-10-05 17:59   ` Andrew Cooper
2017-10-05 18:31   ` Razvan Cojocaru
2017-10-06  9:11   ` Paul Durrant
2017-10-06 10:49     ` Julien Grall
2017-10-06 10:55       ` Paul Durrant
2017-10-06 11:00         ` Julien Grall
2017-10-06 11:44           ` Paul Durrant
2017-10-06 13:02   ` Boris Ostrovsky
2017-10-09 11:42   ` Jan Beulich
2017-10-09 12:20     ` Julien Grall
2017-10-09 13:40       ` Jan Beulich
2017-10-09 13:48         ` Julien Grall
2017-10-09 14:07           ` Jan Beulich
2017-10-10  5:18   ` Tian, Kevin

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=20171005174222.29161-9-julien.grall@linaro.org \
    --to=julien.grall@linaro.org \
    --cc=konrad.wilk@oracle.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).