From patchwork Fri Apr 7 19:35:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9670321 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 32EB9602B3 for ; Fri, 7 Apr 2017 19:38:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EA6328647 for ; Fri, 7 Apr 2017 19:38:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 133382864F; Fri, 7 Apr 2017 19:38:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0ED2A28648 for ; Fri, 7 Apr 2017 19:38:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwZgT-0005lR-JG; Fri, 07 Apr 2017 19:36:37 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwZgS-0005lE-Fd for xen-devel@lists.xen.org; Fri, 07 Apr 2017 19:36:36 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id 9E/08-16497-34AE7E85; Fri, 07 Apr 2017 19:36:35 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42JxWrrBXtf51fM Ig8vrxCyWfFzM4sDocXT3b6YAxijWzLyk/IoE1ox51+6yF6wXrzja38DcwLhKqIuRk0NCwF9i 9s0ZLCA2m4C+xO4Xn5hAbBEBdYnTHRdZuxi5OJgF5jJKnDz2kx0kISwQK7F0xRkwm0VAReLRk RusIDavgIdE29XLjBBD5STOH//JDGJzCnhKHP7aBTZUCKhm5463bBC2msS1/kvsEL2CEidnPg E7gllAQuLgixfMExh5ZyFJzUKSWsDItIpRozi1qCy1SNfIUi+pKDM9oyQ3MTNH19DAVC83tbg 4MT01JzGpWC85P3cTIzB86hkYGHcwXt7id4hRkoNJSZRXwedJhBBfUn5KZUZicUZ8UWlOavEh RhkODiUJ3rsvnkcICRalpqdWpGXmAAMZJi3BwaMkwnsAJM1bXJCYW5yZDpE6xagoJc4r9RIoI QCSyCjNg2uDRc8lRlkpYV5GBgYGIZ6C1KLczBJU+VeM4hyMSsK8jiBTeDLzSuCmvwJazAS02O fWU5DFJYkIKakGxoLGbc/Pcp5nWxLHHhWj/2OxxoXHPydsT7xwyWeez8U8vZZZz9YyGf/mPRH otbx5gXvXjI6Y6blzankq37Q7uCv+yY01/c388fF0gSl3n/7ZMbc25ozPfqn3N9PX6p0MEfm2 RI79+qO2mafFNIw+lJTx3HjV9MB6R9maYp93b48s6X+8/vd7pRglluKMREMt5qLiRADB24x+m QIAAA== X-Env-Sender: prvs=2637cee0f=Andrew.Cooper3@citrix.com X-Msg-Ref: server-7.tower-206.messagelabs.com!1491593793!89617122!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 13019 invoked from network); 7 Apr 2017 19:36:35 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-7.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 7 Apr 2017 19:36:35 -0000 X-IronPort-AV: E=Sophos;i="5.37,167,1488844800"; d="scan'208";a="426734486" From: Andrew Cooper To: Xen-devel Date: Fri, 7 Apr 2017 20:35:52 +0100 Message-ID: <1491593753-1181-3-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1491593753-1181-1-git-send-email-andrew.cooper3@citrix.com> References: <1491593753-1181-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Julien Grall , Paul Durrant , Jan Beulich Subject: [Xen-devel] [PATCH v5 for-4.9 3/4] hvm/dmop: Implement copy_{to, from}_guest_buf_offset() helpers X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP copy_{to,from}_guest_buf() are now implemented using an offset of 0. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Paul Durrant CC: Julien Grall --- 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)