From patchwork Tue Dec 4 00:38:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 203516 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B6E212C008A for ; Tue, 4 Dec 2012 11:37:35 +1100 (EST) Received: from localhost ([::1]:41596 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfgVx-0004U9-VN for incoming@patchwork.ozlabs.org; Mon, 03 Dec 2012 19:37:33 -0500 Received: from eggs.gnu.org ([208.118.235.92]:44502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfgVM-0002xt-3n for qemu-devel@nongnu.org; Mon, 03 Dec 2012 19:37:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TfgVF-0004tD-Rb for qemu-devel@nongnu.org; Mon, 03 Dec 2012 19:36:56 -0500 Received: from ozlabs.org ([2402:b800:7003:1:1::1]:49330) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfgVF-0004rM-DF for qemu-devel@nongnu.org; Mon, 03 Dec 2012 19:36:49 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id F01692C00AC; Tue, 4 Dec 2012 11:36:42 +1100 (EST) From: David Gibson To: aliguori@us.ibm.com, quintela@redhat.com Date: Tue, 4 Dec 2012 11:38:39 +1100 Message-Id: <1354581520-25993-3-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1354581520-25993-1-git-send-email-david@gibson.dropbear.id.au> References: <1354581520-25993-1-git-send-email-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2402:b800:7003:1:1::1 Cc: aik@ozlabs.ru, David Gibson , qemu-devel@nongnu.org, qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH 2/2] migration: Fix madvise breakage if host and guest have different page sizes 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 madvise(DONTNEED) will throw away the contents of the whole page at the given address, even if the given length is less than the page size. One can argue about whether that's the correct behaviour, but that's what it's done for a long time in Linux at least. That means that the madvise() in ram_load(), on a setup where TARGET_PAGE_SIZE is smaller than the host page size, can throw away data in guest pages adjacent to the one it's actually processing right now, leading to guest memory corruption on an incoming migration. This patch therefore, disables the madvise() if the host page size is larger than TARGET_PAGE_SIZE. This means we don't get the benefits of that madvise() in this case, but a more complete fix is more difficult to accomplish. This at least fixes the guest memory corruption. Signed-off-by: David Gibson Reported-by: Alexey Kardashevskiy --- arch_init.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch_init.c b/arch_init.c index b75a4c5..83dcc53 100644 --- a/arch_init.c +++ b/arch_init.c @@ -840,7 +840,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) memset(host, ch, TARGET_PAGE_SIZE); #ifndef _WIN32 if (ch == 0 && - (!kvm_enabled() || kvm_has_sync_mmu())) { + (!kvm_enabled() || kvm_has_sync_mmu()) && + getpagesize() <= TARGET_PAGE_SIZE) { qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED); } #endif