All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@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>,
	Jan Beulich <JBeulich@suse.com>
Subject: [PATCH v5 for-4.9 3/4] hvm/dmop: Implement copy_{to, from}_guest_buf_offset() helpers
Date: Fri, 7 Apr 2017 20:35:52 +0100	[thread overview]
Message-ID: <1491593753-1181-3-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1491593753-1181-1-git-send-email-andrew.cooper3@citrix.com>

copy_{to,from}_guest_buf() are now implemented using an offset of 0.

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

diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c
index 3d8ae89..d584aba 100644
--- a/xen/arch/x86/hvm/dm.c
+++ b/xen/arch/x86/hvm/dm.c
@@ -37,9 +37,9 @@ struct dmop_bufs {
 #undef MAX_NR_BUFS
 };
 
-static bool _raw_copy_from_guest_buf(
+static bool _raw_copy_from_guest_buf_offset(
     const struct dmop_bufs *bufs, unsigned int idx,
-    void *dst, size_t dst_bytes)
+    size_t offset_bytes, void *dst, size_t dst_bytes)
 {
     size_t buf_bytes;
 
@@ -48,17 +48,20 @@ static bool _raw_copy_from_guest_buf(
 
     buf_bytes = bufs->buf[idx].size;
 
-    if ( dst_bytes > buf_bytes )
+    if ( offset_bytes >= dst_bytes ||
+         (offset_bytes + dst_bytes) < offset_bytes ||
+         (offset_bytes + dst_bytes) > dst_bytes )
         return false;
 
     memset(dst, 0, dst_bytes);
 
-    return !copy_from_guest(dst, bufs->buf[idx].h, dst_bytes);
+    return !copy_from_guest_offset(dst, bufs->buf[idx].h,
+                                   offset_bytes, dst_bytes);
 }
 
-static bool _raw_copy_to_guest_buf(
+static bool _raw_copy_to_guest_buf_offset(
     struct dmop_bufs *bufs, unsigned int idx,
-    const void *src, size_t src_bytes)
+    size_t offset_bytes, const void *src, size_t src_bytes)
 {
     size_t buf_bytes;
 
@@ -67,17 +70,28 @@ static bool _raw_copy_to_guest_buf(
 
     buf_bytes = bufs->buf[idx].size;
 
-    if ( src_bytes > buf_bytes )
+    if ( offset_bytes >= src_bytes ||
+         (offset_bytes + src_bytes) < offset_bytes ||
+         (offset_bytes + src_bytes) > src_bytes )
         return false;
 
-    return !copy_to_guest(bufs->buf[idx].h, src, src_bytes);
+    return !copy_to_guest_offset(bufs->buf[idx].h, offset_bytes,
+                                 src, src_bytes);
 }
 
+#define copy_from_guest_buf_offset(bufs, buf_idx, offset_bytes, dst) \
+    _raw_copy_from_guest_buf_offset(bufs, buf_idx, offset_bytes, \
+                                    dst, sizeof(*(dst)))
+
+#define copy_to_guest_buf_offset(bufs, buf_idx, offset_bytes, src) \
+    _raw_copy_to_guest_buf_offset(bufs, buf_idx, offset_bytes, \
+                                  src, sizeof(*(src)))
+
 #define copy_from_guest_buf(bufs, buf_idx, dst) \
-    _raw_copy_from_guest_buf(bufs, buf_idx, dst, sizeof(*(dst)))
+    copy_from_guest_buf_offset(bufs, buf_idx, 0, dst)
 
 #define copy_to_guest_buf(bufs, buf_idx, src) \
-    _raw_copy_to_guest_buf(bufs, buf_idx, src, sizeof(*(src)))
+    copy_to_guest_buf_offset(bufs, buf_idx, 0, src)
 
 static int track_dirty_vram(struct domain *d, xen_pfn_t first_pfn,
                             unsigned int nr, struct xen_dm_op_buf *buf)
-- 
2.1.4


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

  parent reply	other threads:[~2017-04-07 19:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-07 19:35 [PATCH v5 for-4.9 1/4] hvm/dmop: Box dmop_bufs rather than passing two parameters around Andrew Cooper
2017-04-07 19:35 ` [PATCH v5 for-4.9 2/4] hvm/dmop: Implement copy_{to, from}_guest_buf() in terms of raw accessors Andrew Cooper
2017-04-10  9:48   ` Jan Beulich
2017-04-07 19:35 ` Andrew Cooper [this message]
2017-04-10  9:11   ` [PATCH v5 for-4.9 3/4] hvm/dmop: Implement copy_{to, from}_guest_buf_offset() helpers Paul Durrant
2017-04-10  9:35     ` Andrew Cooper
2017-04-10  9:52       ` Paul Durrant
2017-04-10  9:57         ` Andrew Cooper
2017-04-10 10:04           ` Paul Durrant
2017-04-07 19:35 ` [PATCH v5 for-4.9 4/4] dmop: Add xendevicemodel_modified_memory_bulk() Andrew Cooper
2017-04-10  9:04 ` [PATCH v5 for-4.9 1/4] hvm/dmop: Box dmop_bufs rather than passing two parameters around Paul Durrant
2017-04-10  9:29   ` Andrew Cooper
2017-04-10  9:40     ` Paul Durrant
2017-04-10 10:04       ` Andrew Cooper
2017-04-10 10:12         ` Paul Durrant
2017-04-10 10:06       ` Jennifer Herbert
2017-04-10 10:18         ` Paul Durrant
2017-04-10  9:39 ` 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=1491593753-1181-3-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.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.