From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=41346 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPyNG-0005Mp-Pr for qemu-devel@nongnu.org; Tue, 07 Dec 2010 09:18:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPyNF-0005aT-OS for qemu-devel@nongnu.org; Tue, 07 Dec 2010 09:18:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57576) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPyNF-0005aE-FV for qemu-devel@nongnu.org; Tue, 07 Dec 2010 09:18:33 -0500 Message-ID: <4CFE4234.9020305@redhat.com> Date: Tue, 07 Dec 2010 15:18:28 +0100 From: Jes Sorensen MIME-Version: 1.0 References: <1291399402-20366-1-git-send-email-mdroth@linux.vnet.ibm.com> <1291399402-20366-8-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1291399402-20366-8-git-send-email-mdroth@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [RFC][PATCH v5 07/21] virtagent: add va.getfile RPC List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Roth Cc: agl@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com, abeekhof@redhat.com, qemu-devel@nongnu.org, aliguori@linux.vnet.ibm.com, ryanh@us.ibm.com On 12/03/10 19:03, Michael Roth wrote: > Add RPC to retrieve a guest file. This interface is intended > for smaller reads like peeking at logs and /proc and such. I think you need to redesign your approach here..... see below. In 06/21 you had: +#define VA_GETFILE_MAX 1 << 30 > + while ((ret = read(fd, buf, VA_FILEBUF_LEN)) > 0) { > + file_contents = qemu_realloc(file_contents, count + VA_FILEBUF_LEN); > + memcpy(file_contents + count, buf, ret); UH OH! realloc will do a malloc and a memcpy of the data, this is going to turn into a really nasty malloc memcpy loop if someone tries to transfer a large file using this method. You could end up with almost 4GB of parallel allocations for a guest that might have been configured as a 1GB guest. This would allow the guest to effectively blow the expected memory consumption out of the water. It's not exactly going to be fast either :( Maybe use a tmp file, and write data out to that as you receive it to avoid the malloc ballooning. Jes