From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X37Vh-0007uL-Rb for qemu-devel@nongnu.org; Fri, 04 Jul 2014 13:43:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X37Vb-0000RU-Le for qemu-devel@nongnu.org; Fri, 04 Jul 2014 13:42:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8613) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X37Vb-0000QP-C5 for qemu-devel@nongnu.org; Fri, 04 Jul 2014 13:42:51 -0400 From: "Dr. David Alan Gilbert (git)" Date: Fri, 4 Jul 2014 18:41:40 +0100 Message-Id: <1404495717-4239-30-git-send-email-dgilbert@redhat.com> In-Reply-To: <1404495717-4239-1-git-send-email-dgilbert@redhat.com> References: <1404495717-4239-1-git-send-email-dgilbert@redhat.com> Subject: [Qemu-devel] [PATCH 29/46] postcopy: ram_enable_notify to switch on userfault List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, lilei@linux.vnet.ibm.com, quintela@redhat.com From: "Dr. David Alan Gilbert" Signed-off-by: Dr. David Alan Gilbert --- include/migration/postcopy-ram.h | 5 +++++ postcopy-ram.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/include/migration/postcopy-ram.h b/include/migration/postcopy-ram.h index b5f0cb5..383b1e8 100644 --- a/include/migration/postcopy-ram.h +++ b/include/migration/postcopy-ram.h @@ -28,6 +28,11 @@ int postcopy_send_discard_bitmap(MigrationState *ms); int postcopy_ram_discard_range(MigrationIncomingState *mis, uint8_t *start, uint8_t *end); +/* + * 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 into diff --git a/postcopy-ram.c b/postcopy-ram.c index 2159c60..c605dd3 100644 --- a/postcopy-ram.c +++ b/postcopy-ram.c @@ -337,9 +337,38 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis) return 0; } +/* + * Mark the given area of RAM as requiring notification to unwritten areas + * 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 + * Returns 0 on success + */ +static int postcopy_ram_sensitise_area(const char *block_name, void *host_addr, + ram_addr_t offset, ram_addr_t length, + void *opaque) +{ + if (madvise(host_addr, length, MADV_USERFAULT)) { + perror("postcopy_ram_sensitise_area"); + 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, NULL)) { + 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"); @@ -365,6 +394,11 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis) return -1; } +int postcopy_ram_enable_notify(MigrationIncomingState *mis) +{ + fprintf(stderr, "postcopy_ram_enable_notify: No OS support\n"); + return -1; +} #endif /* ------------------------------------------------------------------------- */ -- 1.9.3