All of lore.kernel.org
 help / color / mirror / Atom feed
From: <jennifer.herbert@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Julien Grall <julien.grall@arm.com>,
	Paul Durrant <paul.durrant@citrix.com>,
	Jennifer Herbert <Jennifer.Herbert@citrix.com>,
	Jan Beulich <JBeulich@suse.com>
Subject: [PATCH v8 for-4.9 3/5] hvm/dmop: Implement copy_{to, from}_guest_buf() in terms of raw accessors
Date: Fri, 21 Apr 2017 14:05:50 +0000	[thread overview]
Message-ID: <1492783552-29472-3-git-send-email-jennifer.herbert@citrix.com> (raw)
In-Reply-To: <1492783552-29472-1-git-send-email-jennifer.herbert@citrix.com>

From: Andrew Cooper <andrew.cooper3@citrix.com>

This also allows the usual cases to be simplified, by omitting an unnecessary
buf parameters, and because the macros can appropriately size the object.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Jennifer Herbert <Jennifer.Herbert@citrix.com>
--
CC: Paul Durrant <paul.durrant@citrix.com>
CC: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Jan Beulich <JBeulich@suse.com>
CC: Julien Grall <julien.grall@arm.com>
---
Rebased.
---
 xen/arch/x86/hvm/dm.c | 43 ++++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c
index 89186d2..b31c252 100644
--- a/xen/arch/x86/hvm/dm.c
+++ b/xen/arch/x86/hvm/dm.c
@@ -32,38 +32,47 @@ struct dmop_args {
     struct xen_dm_op_buf buf[2];
 };
 
-static bool copy_buf_from_guest(const xen_dm_op_buf_t bufs[],
-                                unsigned int nr_bufs, void *dst,
-                                unsigned int idx, size_t dst_size)
+static bool _raw_copy_from_guest_buf(void *dst,
+                                     const struct dmop_args *args,
+                                     unsigned int buf_idx,
+                                     size_t dst_bytes)
 {
     size_t buf_bytes;
 
-    if ( idx >= nr_bufs )
+    if ( buf_idx >= args->nr_bufs )
         return false;
 
-    buf_bytes = bufs[idx].size;
-    if ( dst_size > buf_bytes )
+    buf_bytes =  args->buf[buf_idx].size;
+
+    if ( dst_bytes > buf_bytes )
         return false;
 
-    return !copy_from_guest(dst, bufs[idx].h, dst_size);
+    return !copy_from_guest(dst, args->buf[buf_idx].h, dst_bytes);
 }
 
-static bool copy_buf_to_guest(const xen_dm_op_buf_t bufs[],
-                              unsigned int nr_bufs, unsigned int idx,
-                              const void *src, size_t src_size)
+static bool _raw_copy_to_guest_buf(const struct dmop_args *args,
+                                   unsigned int buf_idx,
+                                   const void *src, size_t src_bytes)
 {
     size_t buf_bytes;
 
-    if ( idx >= nr_bufs )
+    if ( buf_idx >= args->nr_bufs )
         return false;
 
-    buf_bytes = bufs[idx].size;
-    if ( src_size > buf_bytes )
+    buf_bytes = args->buf[buf_idx].size;
+
+    if ( src_bytes > buf_bytes )
         return false;
 
-    return !copy_to_guest(bufs[idx].h, src, src_size);
+    return !copy_to_guest(args->buf[buf_idx].h, src, src_bytes);
 }
 
+#define COPY_FROM_GUEST_BUF(dst, args, buf_idx) \
+    _raw_copy_from_guest_buf(&dst, args, buf_idx, sizeof(dst))
+
+#define COPY_TO_GUEST_BUF(args, buf_idx, src) \
+    _raw_copy_to_guest_buf(args, buf_idx, &src, sizeof(src))
+
 static int track_dirty_vram(struct domain *d, xen_pfn_t first_pfn,
                             unsigned int nr, const struct xen_dm_op_buf *buf)
 {
@@ -314,7 +323,7 @@ static int dm_op(const struct dmop_args *op_args)
     if ( rc )
         goto out;
 
-    if ( !copy_buf_from_guest(&op_args->buf[0], op_args->nr_bufs, &op, 0, sizeof(op)) )
+    if ( !COPY_FROM_GUEST_BUF(op, op_args, 0) );
     {
         rc = -EFAULT;
         goto out;
@@ -570,8 +579,8 @@ static int dm_op(const struct dmop_args *op_args)
     }
 
     if ( (!rc || rc == -ERESTART) &&
-         !const_op &&
-         !copy_buf_to_guest(&op_args->buf[0], op_args->nr_bufs, 0, &op, sizeof(op)) )
+         !const_op && !COPY_TO_GUEST_BUF(op_args, 0, op) )
+
         rc = -EFAULT;
 
  out:
-- 
2.1.4


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

  parent reply	other threads:[~2017-04-21 14:05 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-21 14:05 [PATCH v8 for-4.9 1/5] hvm/dmop: Box dmop_args rather than passing multiple parameters around jennifer.herbert
2017-04-21 14:05 ` [PATCH v8 for-4.9 2/5] hvm/dmop: Make copy_buf_{from, to}_guest for a buffer not big enough an error jennifer.herbert
2017-04-21 14:09   ` Paul Durrant
2017-04-21 14:05 ` jennifer.herbert [this message]
2017-04-21 14:11   ` [PATCH v8 for-4.9 3/5] hvm/dmop: Implement copy_{to, from}_guest_buf() in terms of raw accessors Paul Durrant
2017-04-21 15:45   ` Jan Beulich
2017-04-21 16:10     ` Andrew Cooper
2017-04-24  8:19       ` Jan Beulich
2017-04-25 20:03         ` Andrew Cooper
2017-04-26  7:37           ` Jan Beulich
2017-04-26  7:46   ` Jan Beulich
2017-04-21 14:05 ` [PATCH v8 for-4.9 4/5] hvm/dmop: Implement copy_{to, from}_guest_buf_offset() helpers jennifer.herbert
2017-04-21 15:46   ` Jan Beulich
2017-04-21 14:05 ` [PATCH v8 for-4.9 5/5] dmop: Add xendevicemodel_modified_memory_bulk() jennifer.herbert
2017-04-21 14:17 ` [PATCH v8 for-4.9 1/5] hvm/dmop: Box dmop_args rather than passing multiple parameters around Julien Grall
2017-04-21 14:42   ` Andrew Cooper
2017-04-21 14:44   ` Jennifer Herbert
2017-04-24 10:23     ` 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=1492783552-29472-3-git-send-email-jennifer.herbert@citrix.com \
    --to=jennifer.herbert@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=julien.grall@arm.com \
    --cc=paul.durrant@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.