From patchwork Thu Apr 20 17:59:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jennifer Herbert X-Patchwork-Id: 9691081 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 80FDA6038D for ; Thu, 20 Apr 2017 18:02:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 780D528479 for ; Thu, 20 Apr 2017 18:02:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CDEF28497; Thu, 20 Apr 2017 18:02:43 +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 161B028479 for ; Thu, 20 Apr 2017 18:02:43 +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 1d1GNJ-0004ro-0x; Thu, 20 Apr 2017 18:00:13 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1GNH-0004rI-O5 for xen-devel@lists.xen.org; Thu, 20 Apr 2017 18:00:11 +0000 Received: from [193.109.254.147] by server-2.bemta-6.messagelabs.com id D5/6C-03058-B27F8F85; Thu, 20 Apr 2017 18:00:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42JxWrohUlfr+48 Ig9//tC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oxbV0+xFpyTqzi3bSdjA+MO0S5GTg4JAX+J l/OnsoDYbALKEr0TXzOD2CIC6hKnOy6ydjFycTALnGWUuPxwN1hCWCBY4nLfOyYQm0VAVWL/o w+MIDavgJfEqZNf2SGGykmcP/4TrJ5TwFtiweIjYLYQUM3/pkWsELaGRP/B+6wQvYISJ2c+AT uCWUBC4uCLF8wTGHlnIUnNQpJawMi0ilGjOLWoLLVI19BCL6koMz2jJDcxM0fX0MBMLze1uDg xPTUnMalYLzk/dxMjMHwYgGAH482NAYcYJTmYlER51eb+iBDiS8pPqcxILM6ILyrNSS0+xCjD waEkwXvuK1BOsCg1PbUiLTMHGMgwaQkOHiUR3isgad7igsTc4sx0iNQpRkUpcd53IAkBkERGa R5cGyx6LjHKSgnzMgIdIsRTkFqUm1mCKv+KUZyDUUmYV+cb0BSezLwSuOmvgBYzAS0+6we2uC QRISXVwBjeKuERm6koddU0aB8bR2m/ltyu+Sw1b+ezfRZukwtsDo3t/V21VtjwFWf3PlPnJQY 5U987Na2Vu5l06Tzvq4urVsr1pc78n/Z4zYwZT+Y6xx5p7Io6GxKiuUerhbF/+svd3VL+b5lF D8VV3b53M6v199UzymZem36s2S+ybnu0Ho/hvwl8HUosxRmJhlrMRcWJAMSnH5OZAgAA X-Env-Sender: prvs=276ecb9c3=jennifer.herbert@citrix.com X-Msg-Ref: server-11.tower-27.messagelabs.com!1492711208!67643263!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 50397 invoked from network); 20 Apr 2017 18:00:10 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-11.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 20 Apr 2017 18:00:10 -0000 X-IronPort-AV: E=Sophos;i="5.37,225,1488844800"; d="scan'208";a="420128750" From: To: Xen-devel Date: Thu, 20 Apr 2017 17:59:48 +0000 Message-ID: <1492711189-2857-3-git-send-email-jennifer.herbert@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1492711189-2857-1-git-send-email-jennifer.herbert@citrix.com> References: <1492711189-2857-1-git-send-email-jennifer.herbert@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Julien Grall , Paul Durrant , Jennifer Herbert , Jan Beulich Subject: [Xen-devel] [PATCH 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 From: Jennifer Herbert copy_{to,from}_guest_buf() are now implemented using an offset of 0. Signed-off-by: Andrew Cooper Signed-off-by: Jennifer Herbert Reviewed-by: Jan Beulich Reviewed-by: Paul Durrant --- CC: Paul Durrant CC: Andrew Cooper CC: Jan Beulich CC: Julien Grall --- xen/arch/x86/hvm/dm.c | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c index 3607ddb..6990725 100644 --- a/xen/arch/x86/hvm/dm.c +++ b/xen/arch/x86/hvm/dm.c @@ -32,10 +32,11 @@ struct dmop_args { struct xen_dm_op_buf buf[2]; }; -static bool _raw_copy_from_guest_buf(void *dst, - const struct dmop_args *args, - unsigned int buf_idx, - size_t dst_bytes) +static bool _raw_copy_from_guest_buf_offset(void *dst, + const struct dmop_args *args, + unsigned int buf_idx, + size_t offset_bytes, + size_t dst_bytes) { size_t buf_bytes; @@ -44,15 +45,20 @@ static bool _raw_copy_from_guest_buf(void *dst, buf_bytes = args->buf[buf_idx].size; - if ( dst_bytes > buf_bytes ) + if ( offset_bytes >= buf_bytes || + (offset_bytes + dst_bytes) < offset_bytes || + (offset_bytes + dst_bytes) > buf_bytes ) return false; - return !copy_from_guest(dst, args->buf[buf_idx].h, buf_bytes); + return !copy_from_guest_offset(dst, args->buf[buf_idx].h, + offset_bytes, dst_bytes); } -static bool _raw_copy_to_guest_buf(struct dmop_args *args, - unsigned int buf_idx, - const void *src, size_t src_bytes) +static bool _raw_copy_to_guest_buf_offset(struct dmop_args *args, + unsigned int buf_idx, + size_t offset_bytes, + const void *src, + size_t src_bytes) { size_t buf_bytes; @@ -61,17 +67,29 @@ static bool _raw_copy_to_guest_buf(struct dmop_args *args, buf_bytes = args->buf[buf_idx].size; - if ( src_bytes > buf_bytes ) + + if ( offset_bytes >= buf_bytes || + (offset_bytes + src_bytes) < offset_bytes || + (offset_bytes + src_bytes) > buf_bytes ) return false; - return !copy_to_guest(args->buf[buf_idx].h, src, buf_bytes); + return !copy_to_guest_offset(args->buf[buf_idx].h, offset_bytes, + 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_from_guest_buf_offset(dst, bufs, buf_idx, offset_bytes) \ + _raw_copy_from_guest_buf_offset(dst, bufs, buf_idx, offset_bytes, \ + 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(dst, bufs, buf_idx) \ + copy_from_guest_buf_offset(dst, bufs, buf_idx, 0) -#define copy_to_guest_buf(args, buf_idx, src) \ - _raw_copy_to_guest_buf(args, buf_idx, src, sizeof(*(src))) +#define copy_to_guest_buf(bufs, buf_idx, 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)