From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cam Macdonell Subject: Re: [PATCH v5 2/5] Support adding a file to qemu's ram allocation Date: Mon, 10 May 2010 09:32:02 -0600 Message-ID: References: <1271872408-22842-1-git-send-email-cam@cs.ualberta.ca> <1271872408-22842-2-git-send-email-cam@cs.ualberta.ca> <1271872408-22842-3-git-send-email-cam@cs.ualberta.ca> <4BE7E25F.20208@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org, "qemu-devel@nongnu.org Developers" , mtosatti@redhat.com To: Avi Kivity Return-path: Received: from mail-vw0-f46.google.com ([209.85.212.46]:63448 "EHLO mail-vw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752782Ab0EJPcE convert rfc822-to-8bit (ORCPT ); Mon, 10 May 2010 11:32:04 -0400 Received: by vws17 with SMTP id 17so165998vws.19 for ; Mon, 10 May 2010 08:32:02 -0700 (PDT) In-Reply-To: <4BE7E25F.20208@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, May 10, 2010 at 4:39 AM, Avi Kivity wrote: > On 04/21/2010 08:53 PM, Cam Macdonell wrote: >> >> This avoids the need of using qemu_ram_alloc and mmap with MAP_FIXED= to >> map a >> host file into guest RAM. =A0This function mmaps the opened file any= where >> and adds >> the memory to the ram blocks. >> >> Usage is >> >> qemu_ram_mmap(fd, size, MAP_SHARED, offset); >> > > Signoff? >> >> +ram_addr_t qemu_ram_mmap(int fd, ram_addr_t size, int flags, off_t >> offset) >> +{ >> + =A0 =A0RAMBlock *new_block; >> + >> + =A0 =A0size =3D TARGET_PAGE_ALIGN(size); >> + =A0 =A0new_block =3D qemu_malloc(sizeof(*new_block)); >> + >> + =A0 =A0/* map the file passed as a parameter to be this part of me= mory */ >> + =A0 =A0new_block->host =3D mmap(0, size, PROT_READ|PROT_WRITE, fla= gs, fd, >> offset); >> + >> + =A0 =A0if (new_block->host =3D=3D MAP_FAILED) >> + =A0 =A0 =A0 =A0exit(1); >> > > Braces after if () > >> + =A0 =A0if (kvm_enabled()) >> + =A0 =A0 =A0 =A0kvm_setup_guest_memory(new_block->host, size); >> + >> > > More braces. > This function is possibly made redundant by Marcelo's patch for qemu_ra= m_map http://kerneltrap.org/mailarchive/linux-kvm/2010/4/26/6261299 qemu_ram_map isn't merged yet either, but I'm fine with either one. Marcelo's requires the device to map the memory and then pass the pointer to be added to the memory allocation, so it gives the device full mapping control. Alternatively, I could add the protection flag to my function (I think that's all that is missing). Let me know and I'll change my patch if necessary. > -- > error compiling committee.c: too many arguments to function > >