From nobody Sun Feb 8 18:29:23 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.zoho.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 1487964905849797.607631305792; Fri, 24 Feb 2017 11:35:05 -0800 (PST) Received: from localhost ([::1]:39624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chLdv-00083h-OT for importer@patchew.org; Fri, 24 Feb 2017 14:35:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53462) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKbz-0000zn-J1 for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:29:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKbw-0007yR-T2 for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:28:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52136) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKbw-0007xy-K3 for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:28:56 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2E1F7E9E2 for ; Fri, 24 Feb 2017 18:28:56 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-182.ams2.redhat.com [10.36.117.182]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OISjTZ002473; Fri, 24 Feb 2017 13:28:55 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, lvivier@redhat.com Date: Fri, 24 Feb 2017 18:28:35 +0000 Message-Id: <20170224182844.32452-8-dgilbert@redhat.com> In-Reply-To: <20170224182844.32452-1-dgilbert@redhat.com> References: <20170224182844.32452-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 24 Feb 2017 18:28:56 +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] [PATCH v3 07/16] postcopy: Plumb pagesize down into place helpers 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: aarcange@redhat.com 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: "Dr. David Alan Gilbert" Now we deal with normal size pages and huge pages we need to tell the place handlers the size we're dealing with and make sure the temporary page is large enough. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Reviewed-by: Laurent Vivier --- include/migration/postcopy-ram.h | 6 +++-- migration/postcopy-ram.c | 47 ++++++++++++++++++++++++------------= ---- migration/ram.c | 15 +++++++------ 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/include/migration/postcopy-ram.h b/include/migration/postcopy-= ram.h index 43bbbca..8e036b9 100644 --- a/include/migration/postcopy-ram.h +++ b/include/migration/postcopy-ram.h @@ -74,13 +74,15 @@ void postcopy_discard_send_finish(MigrationState *ms, * to use other postcopy_ routines to allocate. * returns 0 on success */ -int postcopy_place_page(MigrationIncomingState *mis, void *host, void *fro= m); +int postcopy_place_page(MigrationIncomingState *mis, void *host, void *fro= m, + size_t pagesize); =20 /* * Place a zero page at (host) atomically * returns 0 on success */ -int postcopy_place_page_zero(MigrationIncomingState *mis, void *host); +int postcopy_place_page_zero(MigrationIncomingState *mis, void *host, + size_t pagesize); =20 /* * Allocate a page of memory that can be mapped at a later point in time diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 1e3d22f..a8b7fed 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -321,7 +321,7 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingStat= e *mis) migrate_send_rp_shut(mis, qemu_file_get_error(mis->from_src_file) !=3D= 0); =20 if (mis->postcopy_tmp_page) { - munmap(mis->postcopy_tmp_page, getpagesize()); + munmap(mis->postcopy_tmp_page, mis->largest_page_size); mis->postcopy_tmp_page =3D NULL; } trace_postcopy_ram_incoming_cleanup_exit(); @@ -543,13 +543,14 @@ int postcopy_ram_enable_notify(MigrationIncomingState= *mis) * Place a host page (from) at (host) atomically * returns 0 on success */ -int postcopy_place_page(MigrationIncomingState *mis, void *host, void *fro= m) +int postcopy_place_page(MigrationIncomingState *mis, void *host, void *fro= m, + size_t pagesize) { struct uffdio_copy copy_struct; =20 copy_struct.dst =3D (uint64_t)(uintptr_t)host; copy_struct.src =3D (uint64_t)(uintptr_t)from; - copy_struct.len =3D getpagesize(); + copy_struct.len =3D pagesize; copy_struct.mode =3D 0; =20 /* copy also acks to the kernel waking the stalled thread up @@ -559,8 +560,8 @@ int postcopy_place_page(MigrationIncomingState *mis, vo= id *host, void *from) */ if (ioctl(mis->userfault_fd, UFFDIO_COPY, ©_struct)) { int e =3D errno; - error_report("%s: %s copy host: %p from: %p", - __func__, strerror(e), host, from); + error_report("%s: %s copy host: %p from: %p (size: %zd)", + __func__, strerror(e), host, from, pagesize); =20 return -e; } @@ -573,23 +574,29 @@ int postcopy_place_page(MigrationIncomingState *mis, = void *host, void *from) * Place a zero page at (host) atomically * returns 0 on success */ -int postcopy_place_page_zero(MigrationIncomingState *mis, void *host) +int postcopy_place_page_zero(MigrationIncomingState *mis, void *host, + size_t pagesize) { - struct uffdio_zeropage zero_struct; + trace_postcopy_place_page_zero(host); =20 - zero_struct.range.start =3D (uint64_t)(uintptr_t)host; - zero_struct.range.len =3D getpagesize(); - zero_struct.mode =3D 0; + if (pagesize =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; =20 - if (ioctl(mis->userfault_fd, UFFDIO_ZEROPAGE, &zero_struct)) { - int e =3D errno; - error_report("%s: %s zero host: %p", - __func__, strerror(e), host); + if (ioctl(mis->userfault_fd, UFFDIO_ZEROPAGE, &zero_struct)) { + int e =3D errno; + error_report("%s: %s zero host: %p", + __func__, strerror(e), host); =20 - return -e; + return -e; + } + } else { + /* TODO: The kernel can't use UFFDIO_ZEROPAGE for hugepages */ + assert(0); } =20 - trace_postcopy_place_page_zero(host); return 0; } =20 @@ -604,7 +611,7 @@ int postcopy_place_page_zero(MigrationIncomingState *mi= s, void *host) void *postcopy_get_tmp_page(MigrationIncomingState *mis) { if (!mis->postcopy_tmp_page) { - mis->postcopy_tmp_page =3D mmap(NULL, getpagesize(), + mis->postcopy_tmp_page =3D mmap(NULL, mis->largest_page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mis->postcopy_tmp_page =3D=3D MAP_FAILED) { @@ -649,13 +656,15 @@ int postcopy_ram_enable_notify(MigrationIncomingState= *mis) return -1; } =20 -int postcopy_place_page(MigrationIncomingState *mis, void *host, void *fro= m) +int postcopy_place_page(MigrationIncomingState *mis, void *host, void *fro= m, + size_t pagesize) { assert(0); return -1; } =20 -int postcopy_place_page_zero(MigrationIncomingState *mis, void *host) +int postcopy_place_page_zero(MigrationIncomingState *mis, void *host, + size_t pagesize) { assert(0); return -1; diff --git a/migration/ram.c b/migration/ram.c index 44fe960..ff86664 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2402,6 +2402,7 @@ static int ram_load_postcopy(QEMUFile *f) void *host =3D NULL; void *page_buffer =3D NULL; void *place_source =3D NULL; + RAMBlock *block =3D NULL; uint8_t ch; =20 addr =3D qemu_get_be64(f); @@ -2411,7 +2412,7 @@ static int ram_load_postcopy(QEMUFile *f) trace_ram_load_postcopy_loop((uint64_t)addr, flags); place_needed =3D false; if (flags & (RAM_SAVE_FLAG_COMPRESS | RAM_SAVE_FLAG_PAGE)) { - RAMBlock *block =3D ram_block_from_stream(f, flags); + block =3D ram_block_from_stream(f, flags); =20 host =3D host_from_ram_block_offset(block, addr); if (!host) { @@ -2486,14 +2487,14 @@ static int ram_load_postcopy(QEMUFile *f) =20 if (place_needed) { /* This gets called at the last target page in the host page */ + void *place_dest =3D host + TARGET_PAGE_SIZE - block->page_siz= e; + if (all_zero) { - ret =3D postcopy_place_page_zero(mis, - host + TARGET_PAGE_SIZE - - qemu_host_page_size); + ret =3D postcopy_place_page_zero(mis, place_dest, + block->page_size); } else { - ret =3D postcopy_place_page(mis, host + TARGET_PAGE_SIZE - - qemu_host_page_size, - place_source); + ret =3D postcopy_place_page(mis, place_dest, + place_source, block->page_size); } } if (!ret) { --=20 2.9.3