From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xlugb-0000wJ-BY for qemu-devel@nongnu.org; Wed, 05 Nov 2014 02:07:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XlugX-00071X-29 for qemu-devel@nongnu.org; Wed, 05 Nov 2014 02:07:20 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:41492) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlugW-000707-9A for qemu-devel@nongnu.org; Wed, 05 Nov 2014 02:07:16 -0500 Date: Wed, 5 Nov 2014 17:49:54 +1100 From: David Gibson Message-ID: <20141105064954.GC26255@voom.redhat.com> References: <1412358473-31398-1-git-send-email-dgilbert@redhat.com> <1412358473-31398-33-git-send-email-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="jy6Sn24JjFx/iggw" Content-Disposition: inline In-Reply-To: <1412358473-31398-33-git-send-email-dgilbert@redhat.com> Subject: Re: [Qemu-devel] [PATCH v4 32/47] postcopy: ram_enable_notify to switch on userfault List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert (git)" Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, lilei@linux.vnet.ibm.com, quintela@redhat.com, cristian.klein@cs.umu.se, qemu-devel@nongnu.org, amit.shah@redhat.com, yanghy@cn.fujitsu.com --jy6Sn24JjFx/iggw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Oct 03, 2014 at 06:47:38PM +0100, Dr. David Alan Gilbert (git) wrot= e: > From: "Dr. David Alan Gilbert" >=20 > Signed-off-by: Dr. David Alan Gilbert > --- > include/migration/migration.h | 2 ++ > include/migration/postcopy-ram.h | 6 +++++ > postcopy-ram.c | 49 ++++++++++++++++++++++++++++++++++= +++++- > savevm.c | 9 ++++++++ > 4 files changed, 65 insertions(+), 1 deletion(-) >=20 > diff --git a/include/migration/migration.h b/include/migration/migration.h > index be63c89..b01cc17 100644 > --- a/include/migration/migration.h > +++ b/include/migration/migration.h > @@ -87,6 +87,8 @@ struct MigrationIncomingState { > POSTCOPY_RAM_INCOMING_END > } postcopy_ram_state; > =20 > + /* For the kernel to send us notifications */ > + int userfault_fd; > QEMUFile *return_path; > QemuMutex rp_mutex; /* We send replies from multiple threads= */ > PostcopyPMI postcopy_pmi; > diff --git a/include/migration/postcopy-ram.h b/include/migration/postcop= y-ram.h > index 8f237a2..413b670 100644 > --- a/include/migration/postcopy-ram.h > +++ b/include/migration/postcopy-ram.h > @@ -19,6 +19,12 @@ > int postcopy_ram_hosttest(void); > =20 > /* > + * Make all of RAM sensitive to accesses to areas that haven't yet been = written > + * and wire up anything necessary to deal with it. > + */ > +int postcopy_ram_enable_notify(MigrationIncomingState *mis); > + > +/* > * Initialise postcopy-ram, setting the RAM to a state where we can go i= nto > * postcopy later; must be called prior to any precopy. > * called from arch_init's similarly named ram_postcopy_incoming_init > diff --git a/postcopy-ram.c b/postcopy-ram.c > index 8eccf26..925ac77 100644 > --- a/postcopy-ram.c > +++ b/postcopy-ram.c > @@ -485,9 +485,51 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingS= tate *mis) > return 0; > } > =20 > +/* > + * Mark the given area of RAM as requiring notification to unwritten are= as > + * Used as a callback on qemu_ram_foreach_block. > + * host_addr: Base of area to mark > + * offset: Offset in the whole ram arena > + * length: Length of the section > + * opaque: Unused ^^^^^^ This appears to be wrong - opaque is used to find the MIS. > + * Returns 0 on success > + */ > +static int postcopy_ram_sensitise_area(const char *block_name, void *hos= t_addr, > + ram_addr_t offset, ram_addr_t len= gth, > + void *opaque) > +{ > + MigrationIncomingState *mis =3D opaque; > + uint64_t tokern[2]; "tokern"? > + > + if (madvise(host_addr, length, MADV_USERFAULT)) { > + perror("postcopy_ram_sensitise_area madvise"); > + return -1; > + } > + > + /* Now tell our userfault_fd that it's responsible for this area */ > + tokern[0] =3D (uint64_t)(uintptr_t)host_addr | 1; /* 1 means registe= r area */ > + tokern[1] =3D (uint64_t)(uintptr_t)host_addr + length; > + if (write(mis->userfault_fd, tokern, 16) !=3D 16) { > + perror("postcopy_ram_sensitise_area write"); > + madvise(host_addr, length, MADV_NOUSERFAULT); > + return -1; > + } > + > + return 0; > +} > + > +int postcopy_ram_enable_notify(MigrationIncomingState *mis) > +{ > + /* Mark so that we get notified of accesses to unwritten areas */ > + if (qemu_ram_foreach_block(postcopy_ram_sensitise_area, mis)) { > + return -1; > + } > + > + return 0; > +} > + > #else > /* No target OS support, stubs just fail */ > - > int postcopy_ram_hosttest(void) > { > error_report("postcopy_ram_hosttest: No OS support"); > @@ -528,6 +570,11 @@ int postcopy_ram_discard_range(MigrationIncomingStat= e *mis, uint8_t *start, > { > assert(0); > } > + > +int postcopy_ram_enable_notify(MigrationIncomingState *mis) > +{ > + assert(0); > +} > #endif > =20 > /* ---------------------------------------------------------------------= ---- */ > diff --git a/savevm.c b/savevm.c > index 54bdb26..859c96f 100644 > --- a/savevm.c > +++ b/savevm.c > @@ -1304,6 +1304,15 @@ static int loadvm_postcopy_ram_handle_listen(Migra= tionIncomingState *mis) > =20 > mis->postcopy_ram_state =3D POSTCOPY_RAM_INCOMING_LISTENING; > =20 > + /* > + * Sensitise RAM - can now generate requests for blocks that don't e= xist > + * However, at this point the CPU shouldn't be running, and the IO > + * shouldn't be doing anything yet so don't actually expect requests > + */ > + if (postcopy_ram_enable_notify(mis)) { > + return -1; > + } > + > /* TODO start up the postcopy listening thread */ > return 0; > } --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --jy6Sn24JjFx/iggw Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJUWciSAAoJEGw4ysog2bOSbooP/i0B6hoXH+r9G140+GuIGi2E zDMjfQcAC1DWjlKKGo+JaA4S/UUH8HCYjaW/Pq8Mi0n6Rv/egh5fEZ5sgaG2OfeA nTbizmxx3tfX2EF6WjOqiWuHvcdTvkZ+Gu1iZ2WLuExqly1VkoUA/uABRujukmwe nb9EEUJPr0VA/39mvYotddujvw1245q+eGngwg5QQiJtyUv070UzB8KA2ZZdgUr6 0rog+OrSa66F7Kyq/G6xyN2lvCPgMXlnIDE3sAhsPn2+pJKypZ9jazPhtWDoAmJV iH2gYn/5VZd/59kQpGt5V9GcGcv6y8Gdr7YAt/4/mGpRiJIcfDzB0kx/AiyCe6jS ySDkhaH4pcQb3pSY7SDas9efnn57w49eFkS7WAH3EtMwGwaMAeF5mHpD2ZOYzCon B+sMXJo/TeOdjS5ZhmcjVZz/uffO5fZl0nJUmHOzCXNJYjtR/qMtZlxxwquc4vxG H+vmqvWTdHjNGn9M1fIaEFV1lbpyPrgALVuOMusByBQcqZvkEtedp/I+3mKC1mN6 MGZ5q35HEy8voVnD1uJ4oPpQOgQ/fK9xdk2K6nZWKSd3tSuNXp+VMVgMlKj+790J iJNW1fcJx1NYM4NEomYSg6+cn4gI51B53r7oPrEL2myHepbh9O0iTEIPj4bidPZ5 zEWa6i16ljNNKW6Hr+1t =gOZf -----END PGP SIGNATURE----- --jy6Sn24JjFx/iggw--