From patchwork Mon Nov 9 17:28:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 541916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 858DD1402C0 for ; Tue, 10 Nov 2015 04:55:16 +1100 (AEDT) Received: from localhost ([::1]:54578 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zvqew-00010K-J2 for incoming@patchwork.ozlabs.org; Mon, 09 Nov 2015 12:55:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvqH5-0005l2-Qo for qemu-devel@nongnu.org; Mon, 09 Nov 2015 12:30:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZvqH1-00058Z-UI for qemu-devel@nongnu.org; Mon, 09 Nov 2015 12:30:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37653) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvqH1-00058U-Q1 for qemu-devel@nongnu.org; Mon, 09 Nov 2015 12:30:31 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 8C1BE811D8 for ; Mon, 9 Nov 2015 17:30:31 +0000 (UTC) Received: from trasno.mitica (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tA9HT2xZ001694; Mon, 9 Nov 2015 12:30:30 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 9 Nov 2015 18:28:59 +0100 Message-Id: <1447090141-29074-56-git-send-email-quintela@redhat.com> In-Reply-To: <1447090141-29074-1-git-send-email-quintela@redhat.com> References: <1447090141-29074-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: amit.shah@redhat.com, dgilbert@redhat.com Subject: [Qemu-devel] [PULL 55/57] Disable mlock around incoming postcopy X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: "Dr. David Alan Gilbert" Userfault doesn't work with mlock; mlock is designed to nail down pages so they don't move, userfault is designed to tell you when they're not there. munlock the pages we userfault protect before postcopy. mlock everything again at the end if mlock is enabled. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: David Gibson Reviewed-by: Amit Shah Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- include/sysemu/sysemu.h | 1 + migration/postcopy-ram.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 05d1982..f992494 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -172,6 +172,7 @@ extern int boot_menu; extern bool boot_strict; extern uint8_t *boot_splash_filedata; extern size_t boot_splash_filedata_size; +extern bool enable_mlock; extern uint8_t qemu_extra_params_fw[2]; extern QEMUClockType rtc_clock; extern const char *mem_path; diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 8e107fe..1a24b09 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -87,6 +87,11 @@ static bool ufd_version_check(int ufd) return true; } +/* + * Note: This has the side effect of munlock'ing all of RAM, that's + * normally fine since if the postcopy succeeds it gets turned back on at the + * end. + */ bool postcopy_ram_supported_by_host(void) { long pagesize = getpagesize(); @@ -115,6 +120,15 @@ bool postcopy_ram_supported_by_host(void) } /* + * userfault and mlock don't go together; we'll put it back later if + * it was enabled. + */ + if (munlockall()) { + error_report("%s: munlockall: %s", __func__, strerror(errno)); + return -1; + } + + /* * We need to check that the ops we need are supported on anon memory * To do that we need to register a chunk and see the flags that * are returned. @@ -294,6 +308,16 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis) mis->have_fault_thread = false; } + if (enable_mlock) { + if (os_mlock() < 0) { + error_report("mlock: %s", strerror(errno)); + /* + * It doesn't feel right to fail at this point, we have a valid + * VM state. + */ + } + } + postcopy_state_set(POSTCOPY_INCOMING_END); migrate_send_rp_shut(mis, qemu_file_get_error(mis->from_src_file) != 0);