From patchwork Tue Dec 11 12:34:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 205196 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 4774E2C0087 for ; Tue, 11 Dec 2012 23:35:36 +1100 (EST) Received: from localhost ([::1]:49649 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiP3e-0002Gm-7Z for incoming@patchwork.ozlabs.org; Tue, 11 Dec 2012 07:35:34 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiP3F-0001od-9t for qemu-devel@nongnu.org; Tue, 11 Dec 2012 07:35:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TiP32-0000nA-Pk for qemu-devel@nongnu.org; Tue, 11 Dec 2012 07:35:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36785) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiP32-0000n6-IJ for qemu-devel@nongnu.org; Tue, 11 Dec 2012 07:34:56 -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 (8.14.4/8.14.4) with ESMTP id qBBCYsgf022461 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Dec 2012 07:34:54 -0500 Received: from trasno.mitica (ovpn-113-46.phx2.redhat.com [10.3.113.46]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qBBCYnSc009223; Tue, 11 Dec 2012 07:34:53 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Tue, 11 Dec 2012 13:34:49 +0100 Message-Id: <1355229289-27574-3-git-send-email-quintela@redhat.com> In-Reply-To: <1355229289-27574-1-git-send-email-quintela@redhat.com> References: <1355229289-27574-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: David Gibson 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 From: David Gibson 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 Signed-off-by: Juan Quintela --- 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