From patchwork Mon Jun 26 08:35:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Perevalov X-Patchwork-Id: 9808809 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 9DA6760209 for ; Mon, 26 Jun 2017 08:37:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A670C27968 for ; Mon, 26 Jun 2017 08:37:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A4F32841E; Mon, 26 Jun 2017 08:37:20 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 22C4427968 for ; Mon, 26 Jun 2017 08:37:20 +0000 (UTC) Received: from localhost ([::1]:45299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPPWJ-0001IQ-8v for patchwork-qemu-devel@patchwork.kernel.org; Mon, 26 Jun 2017 04:37:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42072) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPPV2-0001F1-4g for qemu-devel@nongnu.org; Mon, 26 Jun 2017 04:36:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPPUz-0003Eg-0T for qemu-devel@nongnu.org; Mon, 26 Jun 2017 04:36:00 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:32251) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dPPUy-0003ED-Nr for qemu-devel@nongnu.org; Mon, 26 Jun 2017 04:35:56 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OS5004JFBVT7H70@mailout1.w1.samsung.com> for qemu-devel@nongnu.org; Mon, 26 Jun 2017 09:35:53 +0100 (BST) Received: from eusmges2.samsung.com (unknown [203.254.199.241]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170626083553eucas1p1573f6de9cddbe33afe82529ff62b28da~Lnwby3BEx2569625696eucas1p1T; Mon, 26 Jun 2017 08:35:53 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2.samsung.com (EUCPMTA) with SMTP id A4.33.04459.867C0595; Mon, 26 Jun 2017 09:35:52 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20170626083552eucas1p24efde91b6a4544fb77927f3b93d83cdf~LnwawfAtn2007020070eucas1p2S; Mon, 26 Jun 2017 08:35:52 +0000 (GMT) X-AuditID: cbfec7f1-f796e6d00000116b-21-5950c7688b59 Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 1B.ED.20206.767C0595; Mon, 26 Jun 2017 09:35:51 +0100 (BST) Received: from aperevalov-ubuntu.rnd.samsung.ru ([106.109.129.199]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OS500G3ZBVGGX60@eusync3.samsung.com>; Mon, 26 Jun 2017 09:35:51 +0100 (BST) From: Alexey Perevalov To: qemu-devel@nongnu.org Date: Mon, 26 Jun 2017 11:35:19 +0300 Message-id: <1498466120-5836-3-git-send-email-a.perevalov@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1498466120-5836-1-git-send-email-a.perevalov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFIsWRmVeSWpSXmKPExsWy7djP87oZxwMiDR5fsbKYe/c8i0Xvtnvs Flfaf7JbbNn/jd3ieO8OFos7W/qYHNg8nlzbzOTxft9VNo++LasYA5ijuGxSUnMyy1KL9O0S uDLu/XrPWHBbsuLSppVsDYyPhbsYOTkkBEwkVmy+ygJhi0lcuLeerYuRi0NIYCmjxNc115gg nM+MEgs3NwBVcYB1HHnuBhFfxijxcfoeFginm0niwdV9YEVsAgYS++7ZgkwVEZCU+N11mhmk hlmglVGive8RM0hCWMBd4vma5YwgNouAqsTiBcvYQWxeATeJqx9OskKcJCdx8thkVpCZnED1 0/dyg8yRELjPJtHyrIMZ4iBZiU0HmCHKXSQu370I1Sos8er4FnYIW0bi8uRuFojedkaJ7p2d rBDOBEaJM9P/QlXZS5y6eZUJxGYW4JOYtG061AJeiY42IQjTQ2LZw1CIakeJl9veMEL8PotR onfrT/YJjDILGBlWMYqklhbnpqcWG+kVJ+YWl+al6yXn525iBMbo6X/HP+5gfH/C6hCjAAej Eg/vAeuASCHWxLLiytxDjBIczEoivBu3AYV4UxIrq1KL8uOLSnNSiw8xSnOwKInzcp26FiEk kJ5YkpqdmlqQWgSTZeLglGpgXPLK2vjCW/vLb7ZffiRlws0+efVH66+ZmtMtzVktF0ac1ozb eb3Q1cS10fvjBzG+9ifLbqr/tFv+Jdc75Mzb9o7PF5q1Vv1m/eH0cfMfXzP9FzLsx/ky2tem Lo1USd4lcm3mt4/iil131RctCZ/pbJVZni+fu/uo4tYV8gyC/j8+tS6eElHFrcRSnJFoqMVc VJwIAAQrs0DNAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBLMWRmVeSWpSXmKPExsVy+t/xq7rpxwMiDf7vNrGYe/c8i0Xvtnvs Flfaf7JbbNn/jd3ieO8OFos7W/qYHNg8nlzbzOTxft9VNo++LasYA5ij3GwyUhNTUosUUvOS 81My89JtlUJD3HQtlBTyEnNTbZUidH1DgpQUyhJzSoE8IwM04OAc4B6spG+X4JZx79d7xoLb khWXNq1ka2B8LNzFyMEhIWAiceS5WxcjJ5ApJnHh3nq2LkYuDiGBJYwSy/+cZQdJCAn0Mkmc +GcFUs8mYCCx754tSFhEQFLid9dpZpB6ZoFWRoknjbPA6oUF3CWer1nOCGKzCKhKLF6wDCzO K+AmcfXDSVaIZXISJ49NZgWZyQlUP30vN8QqN4kHq7ayTmDkXcDIsIpRJLW0ODc9t9hIrzgx t7g0L10vOT93EyMwVLcd+7llB2PXu+BDjAIcjEo8vAesAyKFWBPLiitzDzFKcDArifBu3AYU 4k1JrKxKLcqPLyrNSS0+xGgKdNNEZinR5HxgHOWVxBuaGJpbGhoZW1iYGxkpifNO/XAlXEgg PbEkNTs1tSC1CKaPiYNTqoFxYzOzdEl+7/r5ZWeWs156XR3ymk3qSGeZ6pw76sp1S0y95sTL nd96x/LIB+uyLfGN1gqnlS58TGV2mKLfYriP7cSdtMo1Qkd/bL4fXZ7EZh7fKT4lob08YhrP jRtsGiqs82sertRMj/L+dmLZd69LXwS7leMcO7bzHi+tmxMyWWRH0R2Gjy1KLMUZiYZazEXF iQDuRc41awIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170626083552eucas1p24efde91b6a4544fb77927f3b93d83cdf X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?QWxleGV5IFBlcmV2YWxvdhtTUlItVmlydHVhbGl6YXRpb24g?= =?UTF-8?B?TGFiG+yCvOyEseyghOyekBtTZW5pb3IgRW5naW5lZXI=?= X-Global-Sender: =?UTF-8?B?QWxleGV5IFBlcmV2YWxvdhtTUlItVmlydHVhbGl6YXRpb24g?= =?UTF-8?B?TGFiG1NhbXN1bmcgRWxlY3Ryb25pY3MbU2VuaW9yIEVuZ2luZWVy?= X-Sender-Code: =?UTF-8?B?QzEwG0NJU0hRG0MxMEdEMDFHRDAxMDE1NA==?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170626083552eucas1p24efde91b6a4544fb77927f3b93d83cdf X-RootMTR: 20170626083552eucas1p24efde91b6a4544fb77927f3b93d83cdf References: <1498466120-5836-1-git-send-email-a.perevalov@samsung.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 210.118.77.11 Subject: [Qemu-devel] [PATCH v4 2/3] migration: introduce qemu_ufd_copy_ioctl helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: i.maximets@samsung.com, dgilbert@redhat.com, Alexey Perevalov , peterx@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Just for placing auxilary operations inside helper, auxilary operations like: track received pages, notify about copying operation in futher patches. Reviewed-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Signed-off-by: Alexey Perevalov --- migration/postcopy-ram.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index dae41b5..293db97 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -561,6 +561,25 @@ int postcopy_ram_enable_notify(MigrationIncomingState *mis) return 0; } +static int qemu_ufd_copy_ioctl(int userfault_fd, void *host_addr, + void *from_addr, uint64_t pagesize) +{ + if (from_addr) { + struct uffdio_copy copy_struct; + copy_struct.dst = (uint64_t)(uintptr_t)host_addr; + copy_struct.src = (uint64_t)(uintptr_t)from_addr; + copy_struct.len = pagesize; + copy_struct.mode = 0; + return ioctl(userfault_fd, UFFDIO_COPY, ©_struct); + } else { + struct uffdio_zeropage zero_struct; + zero_struct.range.start = (uint64_t)(uintptr_t)host_addr; + zero_struct.range.len = pagesize; + zero_struct.mode = 0; + return ioctl(userfault_fd, UFFDIO_ZEROPAGE, &zero_struct); + } +} + /* * Place a host page (from) at (host) atomically * returns 0 on success @@ -568,20 +587,14 @@ int postcopy_ram_enable_notify(MigrationIncomingState *mis) int postcopy_place_page(MigrationIncomingState *mis, void *host, void *from, RAMBlock *rb) { - struct uffdio_copy copy_struct; size_t pagesize = qemu_ram_pagesize(rb); - copy_struct.dst = (uint64_t)(uintptr_t)host; - copy_struct.src = (uint64_t)(uintptr_t)from; - copy_struct.len = pagesize; - copy_struct.mode = 0; - /* copy also acks to the kernel waking the stalled thread up * TODO: We can inhibit that ack and only do it if it was requested * which would be slightly cheaper, but we'd have to be careful * of the order of updating our page state. */ - if (ioctl(mis->userfault_fd, UFFDIO_COPY, ©_struct)) { + if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, from, pagesize)) { int e = errno; error_report("%s: %s copy host: %p from: %p (size: %zd)", __func__, strerror(e), host, from, pagesize); @@ -603,12 +616,7 @@ int postcopy_place_page_zero(MigrationIncomingState *mis, void *host, trace_postcopy_place_page_zero(host); if (qemu_ram_pagesize(rb) == getpagesize()) { - struct uffdio_zeropage zero_struct; - zero_struct.range.start = (uint64_t)(uintptr_t)host; - zero_struct.range.len = getpagesize(); - zero_struct.mode = 0; - - if (ioctl(mis->userfault_fd, UFFDIO_ZEROPAGE, &zero_struct)) { + if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, NULL, getpagesize())) { int e = errno; error_report("%s: %s zero host: %p", __func__, strerror(e), host);