From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MInZh-0004Ww-NR for qemu-devel@nongnu.org; Mon, 22 Jun 2009 13:44:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MInZc-0004WM-R6 for qemu-devel@nongnu.org; Mon, 22 Jun 2009 13:44:57 -0400 Received: from [199.232.76.173] (port=58486 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MInZc-0004WJ-Ln for qemu-devel@nongnu.org; Mon, 22 Jun 2009 13:44:52 -0400 Received: from e38.co.us.ibm.com ([32.97.110.159]:37069) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MInZc-0000Zl-7l for qemu-devel@nongnu.org; Mon, 22 Jun 2009 13:44:52 -0400 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e38.co.us.ibm.com (8.13.1/8.13.1) with ESMTP id n5MHfifJ021215 for ; Mon, 22 Jun 2009 11:41:44 -0600 Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n5MHimaA213482 for ; Mon, 22 Jun 2009 11:44:49 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n5MHimVJ012013 for ; Mon, 22 Jun 2009 11:44:48 -0600 Message-ID: <4A3FC30E.5030804@us.ibm.com> Date: Mon, 22 Jun 2009 12:44:46 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] Re: [Qemu-commits] [COMMIT 3086844] Instead of writing a zero page, madvise it away References: <200906221549.n5MFn3Qd015389@d03av02.boulder.ibm.com> <4A3FAD69.60507@redhat.com> <4A3FB077.4040607@codemonkey.ws> <4A3FB390.4060809@redhat.com> <4A3FB95D.3060404@us.ibm.com> <4A3FBD61.8030109@redhat.com> In-Reply-To: <4A3FBD61.8030109@redhat.com> Content-Type: multipart/mixed; boundary="------------030402070409080004030601" List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: qemu-devel This is a multi-part message in MIME format. --------------030402070409080004030601 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit See attached. -- Regards, Anthony Liguori --------------030402070409080004030601 Content-Type: text/x-patch; name="zero-mem-madvise.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="zero-mem-madvise.patch" commit a70787dc8200dad03f3d3a85fdb40497f336f12b Author: Anthony Liguori Date: Mon Jun 22 12:39:00 2009 -0500 Make sure to zero out memory before calling madvise to increase robustness Avi pointed out that it's not entirely safe to rely on madvise zeroing out memory. So let's do it explicitly before calling madvise. Signed-off-by: Anthony Liguori diff --git a/vl.c b/vl.c index 60a00e1..1c077b4 100644 --- a/vl.c +++ b/vl.c @@ -3358,13 +3358,13 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) if (flags & RAM_SAVE_FLAG_COMPRESS) { uint8_t ch = qemu_get_byte(f); -#if defined(__linux__) + memset(qemu_get_ram_ptr(addr), ch, TARGET_PAGE_SIZE); +#ifndef _WIN32 if (ch == 0 && (!kvm_enabled() || kvm_has_sync_mmu())) { madvise(qemu_get_ram_ptr(addr), TARGET_PAGE_SIZE, MADV_DONTNEED); - } else + } #endif - memset(qemu_get_ram_ptr(addr), ch, TARGET_PAGE_SIZE); } else if (flags & RAM_SAVE_FLAG_PAGE) qemu_get_buffer(f, qemu_get_ram_ptr(addr), TARGET_PAGE_SIZE); } while (!(flags & RAM_SAVE_FLAG_EOS)); --------------030402070409080004030601--