kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Donnelly <sfdonnelly@gmail.com>
To: Cam Macdonell <cam@cs.ualberta.ca>
Cc: Avi Kivity <avi@redhat.com>,
	"kvm@vger.kernel.org list" <kvm@vger.kernel.org>
Subject: Re: R/W HG memory mappings with kvm?
Date: Tue, 28 Jul 2009 09:32:52 +1200	[thread overview]
Message-ID: <5f370d430907271432y5283c2cat7673efeed0febe20@mail.gmail.com> (raw)
In-Reply-To: <4A6DBE54.3080609@cs.ualberta.ca>

Hi Cam,

> Sorry I haven't answered your email from last Thursday.  I'll answer it
> shortly.

Thanks, I'm still chipping away at it slowly.

>> On Thu, Jul 9, 2009 at 6:01 PM, Cam Macdonell<cam@cs.ualberta.ca> wrote:
>>
>>> The memory for the device allocated as a POSIX shared memory object and
>>> then
>>> mmapped on to the allocated BAR region in Qemu's allocated memory.
>>>  That's
>>> actually one spot that needs a bit of fixing by passing the already
>>> allocated memory object to qemu instead of mmapping on to it.
>>
>> If you work out how to use pre-existing host memory rather than
>> allocating it inside qemu I would be interested.
>
> How is the host memory pre-existing?

It comes from outside qemu, it is mapped in via mmap.

>> I would like to have qemu mmap memory from a host char driver, and
>> then in turn register that mapping as a PCI BAR for the guest device.
>> (I know this sounds like pci pass-through, but it isn't.)
>
> In my setup, qemu just calls mmap on the shared memory object that was
> opened.  So I *think* that switching the shm_open(...) to
> open("/dev/chardev"), might be all that's necessary as long as your char
> device handles mmapping.

It does, but it maps memory into the user program rather than out.

>> What I don't understand is how to turn the host address returned from
>> mmap into a ram_addr_t to pass to pci_register_bar.
>
> Memory must be allocated using the qemu RAM functions.

That seems to be the problem. The memory cannot be allocated by
qemu_ram_alloc, because it is coming from the mmap call. The memory is
already allocated outside the qemu process. mmap can indicate where in
the qemu process address space the local mapping should be, but
mapping it 'on top' of memory allocated with qemu_ram_alloc doesn't
seem to work (I get a BUG in gfn_to_pfn).

>  Look at
> qemu_ram_alloc() and qemu_get_ram_ptr() which are a two step process that
> allocate the memory.  Then notice that the ivshmem_ptr is mmapped on to the
> memory that is returned from the qemu_get_ram_ptr.
>
> pci_register_bar calls a function (the last parameter passed to it) that in
> turn calls cpu_register_physical_memory which registers the allocated memory
> (accessed a s->ivshmem_ptr) as the BAR.

Right, that seems to make sense for your application where you
allocate the memory in qemu and then share it externally via shm.

Have you thought about how to use a shm file that has already been
allocated by another application? I think you mentioned this as a
feature you were going to look at in one of your list posts.

Regards,
Stephen.

  reply	other threads:[~2009-07-27 21:32 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-05 22:41 R/W HG memory mappings with kvm? Stephen Donnelly
2009-07-06  7:38 ` Avi Kivity
2009-07-07 22:23   ` Stephen Donnelly
2009-07-08  4:36     ` Avi Kivity
2009-07-08 21:33       ` Stephen Donnelly
2009-07-09  8:10         ` Avi Kivity
2009-07-08 21:45       ` Cam Macdonell
2009-07-08 22:01         ` Stephen Donnelly
2009-07-09  6:01           ` Cam Macdonell
2009-07-09 22:38             ` Stephen Donnelly
2009-07-10 17:03               ` Cam Macdonell
2009-07-12 21:28                 ` Stephen Donnelly
2009-07-14 22:25                   ` [PATCH] Support shared memory device PCI device Cam Macdonell
     [not found]             ` <5f370d430907262256rd7f9fdalfbbec1f9492ce86@mail.gmail.com>
2009-07-27 14:48               ` R/W HG memory mappings with kvm? Cam Macdonell
2009-07-27 21:32                 ` Stephen Donnelly [this message]
2009-07-28  8:54                   ` Avi Kivity
2009-07-28 23:06                     ` Stephen Donnelly
2009-08-13  4:07                       ` Stephen Donnelly
2009-08-19 12:14                         ` Avi Kivity
2009-08-23 21:59                           ` Stephen Donnelly
2009-08-24  4:55                             ` Avi Kivity
2009-08-26 10:22                               ` Avi Kivity
2009-08-27  2:39                                 ` Stephen Donnelly
2009-08-27  2:34                               ` Stephen Donnelly
2009-08-27  4:08                                 ` Avi Kivity
2009-08-30 22:33                                   ` Stephen Donnelly
2009-08-31  8:44                                     ` Avi Kivity
2009-08-31 21:13                                       ` Stephen Donnelly
2009-09-09 12:50                                         ` Avi Kivity
2009-07-29 23:52                     ` Cam Macdonell
2009-07-30  9:31                       ` Avi Kivity
2009-09-28 18:27 Tsuyoshi Ozawa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5f370d430907271432y5283c2cat7673efeed0febe20@mail.gmail.com \
    --to=sfdonnelly@gmail.com \
    --cc=avi@redhat.com \
    --cc=cam@cs.ualberta.ca \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).