All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Cam Macdonell <cam@cs.ualberta.ca>, kvm@vger.kernel.org
Subject: Re: [PATCH] Add shared memory PCI device that shares a memory object betweens VMs
Date: Wed, 01 Apr 2009 21:07:53 +0300	[thread overview]
Message-ID: <49D3AD79.7080708@redhat.com> (raw)
In-Reply-To: <49D3965C.1030503@codemonkey.ws>

Anthony Liguori wrote:
> Hi Cam,
>
> Cam Macdonell wrote:
>> This patch supports sharing memory between VMs and between the 
>> host/VM.  It's a first cut and comments are encouraged.  The goal is 
>> to support simple Inter-VM communication
>> with zero-copy access to shared memory.
>>   
>
> Nice work!
>
> I would suggest two design changes to make here.  The first is that I 
> think you should use virtio.

I disagree with this.  While virtio is excellent at exporting guest 
memory, it isn't so good at importing another guest's memory.

>   The second is that I think instead of relying on mapping in device 
> memory to the guest, you should have the guest allocate it's own 
> memory to dedicate to sharing.

That's not what you describe below.  You're having the guest allocate 
parts of its address space that happen to be used by RAM, and overlaying 
those parts with the shared memory.

> Right now, you've got a bit of a hole in your implementation because 
> you only support files that are powers-of-two in size even though 
> that's not documented/enforced.  This is a limitation of PCI resource 
> regions.  

While the BAR needs to be a power of two, I don't think the RAM backing 
it needs to be.

> Also, the PCI memory hole is limited in size today which is going to 
> put an upper bound on the amount of memory you could ever map into a 
> guest.  

Today.  We could easily lift this restriction by supporting 64-bit 
BARs.  It would probably take only a few lines of code.

> Since you're using qemu_ram_alloc() also, it makes hotplug unworkable 
> too since qemu_ram_alloc() is a static allocation from a contiguous heap.

We need to fix this anyway, for memory hotplug.

>
> If you used virtio, what you could do is provide a ring queue that was 
> used to communicate a series of requests/response.  The exchange might 
> look like this:
>
> guest: REQ discover memory region
> host: RSP memory region id: 4 size: 8k
> guest: REQ map region id: 4 size: 8k: sgl: {(addr=43000, size=4k), 
> (addr=944000,size=4k)}
> host: RSP mapped region id: 4
> guest: REQ notify region id: 4
> host: RSP notify region id: 4
> guest: REQ poll region id: 4
> host: RSP poll region id: 4

That looks significantly more complex.

>
> And the REQ/RSP order does not have to be in series like this.  In 
> general, you need one entry on the queue to poll for new memory 
> regions, one entry for each mapped region to poll for incoming 
> notification, and then the remaining entries can be used to send 
> short-lived requests/responses.
>
> It's important that the REQ map takes a scatter/gather list of 
> physical addresses because after running for a while, it's unlikely 
> that you'll be able to allocate any significant size of contiguous 
> memory.
>
> From a QEMU perspective, you would do memory sharing by waiting for a 
> map REQ from the guest and then you would complete the request by 
> doing an mmap(MAP_FIXED) with the appropriate parameters into 
> phys_ram_base.

That will fragment the vma list.  And what do you do when you unmap the 
region?

How does a 256M guest map 1G of shared memory?

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


  reply	other threads:[~2009-04-01 18:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-01 15:43 [PATCH] Add shared memory PCI device that shares a memory object betweens VMs Cam Macdonell
2009-04-01 16:29 ` Anthony Liguori
2009-04-01 18:07   ` Avi Kivity [this message]
2009-04-01 18:52     ` Anthony Liguori
2009-04-01 20:32       ` Cam Macdonell
2009-04-02  7:07         ` Avi Kivity
2009-04-03 16:54           ` Cam Macdonell
2009-04-02  7:05       ` Avi Kivity
2009-04-19  5:22       ` Cameron Macdonell
2009-04-19 10:26         ` Avi Kivity
     [not found]           ` <f3b32c250904202348t6514d3efjc691b48c4dafe76a@mail.gmail.com>
2009-04-22 22:41             ` Cam Macdonell
     [not found]               ` <f3b32c250904222355y687c39ecl11c52267a1ea7386@mail.gmail.com>
2009-04-23 16:28                 ` Cam Macdonell

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=49D3AD79.7080708@redhat.com \
    --to=avi@redhat.com \
    --cc=anthony@codemonkey.ws \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.