From nobody Mon Feb 9 22:39:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775993570639.6674399822285; Mon, 23 Oct 2017 09:26:33 -0700 (PDT) Received: from localhost ([::1]:39593 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fYc-0002gf-CA for importer@patchew.org; Mon, 23 Oct 2017 12:26:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHc-0005wh-BO for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:09:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHa-0000Zp-3d for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59732) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHZ-0000Ye-Rv for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:54 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F1BF461D22; Mon, 23 Oct 2017 16:08:52 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 349A078DF4; Mon, 23 Oct 2017 16:08:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F1BF461D22 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:57 +0200 Message-Id: <20171023160800.20540-19-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 23 Oct 2017 16:08:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 18/21] 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: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com, Alexey Perevalov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Alexey Perevalov 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 Signed-off-by: Juan Quintela --- 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 d3073b93b5..8bf6432567 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -641,6 +641,25 @@ int postcopy_ram_enable_notify(MigrationIncomingState = *mis) return 0; } =20 +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 =3D (uint64_t)(uintptr_t)host_addr; + copy_struct.src =3D (uint64_t)(uintptr_t)from_addr; + copy_struct.len =3D pagesize; + copy_struct.mode =3D 0; + return ioctl(userfault_fd, UFFDIO_COPY, ©_struct); + } else { + struct uffdio_zeropage zero_struct; + zero_struct.range.start =3D (uint64_t)(uintptr_t)host_addr; + zero_struct.range.len =3D pagesize; + zero_struct.mode =3D 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 *fro= m, RAMBlock *rb) { - struct uffdio_copy copy_struct; size_t pagesize =3D qemu_ram_pagesize(rb); =20 - copy_struct.dst =3D (uint64_t)(uintptr_t)host; - copy_struct.src =3D (uint64_t)(uintptr_t)from; - copy_struct.len =3D pagesize; - copy_struct.mode =3D 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 =3D 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 *m= is, void *host, trace_postcopy_place_page_zero(host); =20 if (qemu_ram_pagesize(rb) =3D=3D getpagesize()) { - struct uffdio_zeropage zero_struct; - zero_struct.range.start =3D (uint64_t)(uintptr_t)host; - zero_struct.range.len =3D getpagesize(); - zero_struct.mode =3D 0; - - if (ioctl(mis->userfault_fd, UFFDIO_ZEROPAGE, &zero_struct)) { + if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, NULL, getpagesize= ())) { int e =3D errno; error_report("%s: %s zero host: %p", __func__, strerror(e), host); --=20 2.13.6