From patchwork Thu Oct 5 11:13: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: 821714 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y79Bx0k8Jz9t1G for ; Thu, 5 Oct 2017 22:14:17 +1100 (AEDT) Received: from localhost ([::1]:39098 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e046Z-0001tx-2z for incoming@patchwork.ozlabs.org; Thu, 05 Oct 2017 07:14:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0460-0001tk-6k for qemu-devel@nongnu.org; Thu, 05 Oct 2017 07:13:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e045w-00064X-TM for qemu-devel@nongnu.org; Thu, 05 Oct 2017 07:13:40 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:42456) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e045w-000622-J9 for qemu-devel@nongnu.org; Thu, 05 Oct 2017 07:13:36 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20171005111333euoutp016c6ccf269ea37829f44d38a9ba7d15f5~qqD76cBAB1541215412euoutp01e; Thu, 5 Oct 2017 11:13:33 +0000 (GMT) Received: from eusmges4.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20171005111333eucas1p1f271d547d60cb117f90718a83310c91f~qqD7Pm_f61747717477eucas1p1F; Thu, 5 Oct 2017 11:13:33 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges4.samsung.com (EUCPMTA) with SMTP id 1D.D8.12944.CD316D95; Thu, 5 Oct 2017 12:13:32 +0100 (BST) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20171005111332eucas1p164cbc61ee4cb82c4bf6d592a32bba46b~qqD6p3Akt1810618106eucas1p1p; Thu, 5 Oct 2017 11:13:32 +0000 (GMT) X-AuditID: cbfec7f4-f79ab6d000003290-49-59d613dc2276 Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 58.40.18832.CD316D95; Thu, 5 Oct 2017 12:13:32 +0100 (BST) Received: from aperevalov-ubuntu.rnd.samsung.ru ([106.109.129.199]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OXC00MZ6KIBXN90@eusync4.samsung.com>; Thu, 05 Oct 2017 12:13:32 +0100 (BST) From: Alexey Perevalov To: qemu-devel@nongnu.org Date: Thu, 05 Oct 2017 14:13:19 +0300 Message-id: <1507202000-22469-3-git-send-email-a.perevalov@samsung.com> X-Mailer: git-send-email 2.7.4 In-reply-to: <1507202000-22469-1-git-send-email-a.perevalov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrEIsWRmVeSWpSXmKPExsWy7djP87p3hK9FGjzdoG8x9+55FovebffY LaZ9vs1ucaX9J7vFlv3f2C2O9+5gsbizpY/Jgd3jybXNTB7v911l8+jbsooxgDmKyyYlNSez LLVI3y6BK+Ppwzb2gtuSFS2Nr9gaGB8LdzFyckgImE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LCKUSS1 tDg3PbfYUK84Mbe4NC9dLzk/dxMjMIC2Hfu5eQfjpY3BhxgFOBiVeHg9tl6NFGJNLCuuzD3E KMHBrCTCq/QfKMSbklhZlVqUH19UmpNafIhRmoNFSZy3d8/qSCGB9MSS1OzU1ILUIpgsEwen VAMja4OHYEHuD6tFz5sXsvZlP/Ks53gewfJ9t9r0a/NXuhotuah8Pq3+2MenIiIN27j8/n1n uOpyc3aKwz6Hh24Fq868uNS0TumtxpU9jJIdxYVHCw/P/9lo79Ii5B9bK+Jr1xsYcII77lBE 9turmmFBBm6/cyflyrlL/eT2nflyxvb9+20/vH6nxFKckWioxVxUnAgAOD0whRwCAAA= X-CMS-MailID: 20171005111332eucas1p164cbc61ee4cb82c4bf6d592a32bba46b X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?utf-8?q?Alexey_Perevalov=1BSRR-Virtualization_Lab=1B?= =?utf-8?b?7IK87ISx7KCE7J6QG1NlbmlvciBFbmdpbmVlcg==?= X-Global-Sender: =?utf-8?q?Alexey_Perevalov=1BSRR-Virtualization_Lab=1BSa?= =?utf-8?q?msung_Electronics=1BSenior_Engineer?= X-Sender-Code: =?utf-8?q?C10=1BCISHQ=1BC10GD01GD010154?= CMS-TYPE: 201P X-CMS-RootMailID: 20171005111332eucas1p164cbc61ee4cb82c4bf6d592a32bba46b X-RootMTR: 20171005111332eucas1p164cbc61ee4cb82c4bf6d592a32bba46b References: <1507202000-22469-1-git-send-email-a.perevalov@samsung.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 210.118.77.11 Subject: [Qemu-devel] [PATCH v10 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: heetae82.ahn@samsung.com, quintela@redhat.com, Alexey Perevalov , peterx@redhat.com, dgilbert@redhat.com, i.maximets@samsung.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 d3073b9..8bf6432 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -641,6 +641,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 @@ -648,20 +667,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); @@ -683,12 +696,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);