From: Cam Macdonell Subject: [PATCH] Inter-VM shared memory PCI device Date: Tue, 9 Mar 2010 08:27:09 -0700 Message-ID: <8286e4ee1003090727j1d45e5dq3bc5d2ae89c354c@mail.gmail.com> References: <1267833161-25267-1-git-send-email-cam@cs.ualberta.ca> <1267833161-25267-2-git-send-email-cam@cs.ualberta.ca> <4B94C9B3.1060904@redhat.com> <8286e4ee1003080957v9bb4837x187cebb8477348c2@mail.gmail.com> <4B962301.3030008@redhat.com> <8286e4ee1003090724m1ef0b571g8b705a24e36e1753@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE To: kvm@vger.kernel.org, qemu-devel@nongnu.org Return-path: Received: from mail-iw0-f176.google.com ([209.85.223.176]:41782 "EHLO mail-iw0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751642Ab0CIP1K convert rfc822-to-8bit (ORCPT ); Tue, 9 Mar 2010 10:27:10 -0500 Received: by iwn6 with SMTP id 6so3681500iwn.4 for ; Tue, 09 Mar 2010 07:27:09 -0800 (PST) In-Reply-To: <8286e4ee1003090724m1ef0b571g8b705a24e36e1753@mail.gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Mar 9, 2010 at 3:29 AM, Avi Kivity wrote: > On 03/08/2010 07:57 PM, Cam Macdonell wrote: >> >>> Can you provide a spec that describes the device? =A0This would be = useful >>> for >>> maintaining the code, writing guest drivers, and as a framework for >>> review. >>> >> >> I'm not sure if you want the Qemu command-line part as part of the >> spec here, but I've included for completeness. >> > > I meant something from the guest's point of view, so command line syn= tax is > less important. =A0It should be equally applicable to a real PCI card= that > works with the same driver. > > See http://ozlabs.org/~rusty/virtio-spec/ for an example. > >> The Inter-VM Shared Memory PCI device >> ----------------------------------------------------------- >> >> BARs >> >> The device supports two BARs. =A0BAR0 is a 256-byte MMIO region to >> support registers >> > > (but might be extended in the future) > >> and BAR1 is used to map the shared memory object from the host. =A0T= he size >> of >> BAR1 is specified on the command-line and must be a power of 2 in si= ze. >> >> Registers >> >> BAR0 currently supports 5 registers of 16-bits each. > > Suggest making registers 32-bits, friendlier towards non-x86. > >> =A0Registers are used >> for synchronization between guests sharing the same memory object wh= en >> interrupts are supported (this requires using the shared memory serv= er). >> > > How does the driver detect whether interrupts are supported or not? At the moment, the VM ID is set to -1 if interrupts aren't supported, but that may not be the clearest way to do things. =A0With UIO is there a way to detect if the interrupt pin is on? > >> When using interrupts, VMs communicate with a shared memory server t= hat >> passes >> the shared memory object file descriptor using SCM_RIGHTS. =A0The se= rver >> assigns >> each VM an ID number and sends this ID number to the Qemu process al= ong >> with a >> series of eventfd file descriptors, one per guest using the shared m= emory >> server. =A0These eventfds will be used to send interrupts between gu= ests. >> =A0Each >> guest listens on the eventfd corresponding to their ID and may use t= he >> others >> for sending interrupts to other guests. >> >> enum ivshmem_registers { >> =A0 =A0 IntrMask =3D 0, >> =A0 =A0 IntrStatus =3D 2, >> =A0 =A0 Doorbell =3D 4, >> =A0 =A0 IVPosition =3D 6, >> =A0 =A0 IVLiveList =3D 8 >> }; >> >> The first two registers are the interrupt mask and status registers. >> Interrupts are triggered when a message is received on the guest's e= ventfd >> from >> another VM. =A0Writing to the 'Doorbell' register is how synchroniza= tion >> messages >> are sent to other VMs. >> >> The IVPosition register is read-only and reports the guest's ID numb= er. >> =A0The >> IVLiveList register is also read-only and reports a bit vector of >> currently >> live VM IDs. >> > > That limits the number of guests to 16. True, it could grow to 32 or 64 without difficulty. =A0We could leave 'liveness' to the user (could be implemented using the shared memory region) or via the interrupts that arrive on guest attach/detach as you suggest below.. > >> The Doorbell register is 16-bits, but is treated as two 8-bit values= =2E =A0The >> upper 8-bits are used for the destination VM ID. =A0The lower 8-bits= are the >> value which will be written to the destination VM and what the guest >> status >> register will be set to when the interrupt is trigger is the destina= tion >> guest. >> > > What happens when two interrupts are sent back-to-back to the same gu= est? > =A0Will the first status value be lost? Right now, it would be. =A0I believe that eventfd has a counting semaphore option, that could prevent loss of status (but limits what the status could be). =A0My understanding of uio_pci interrupt handling is fairly new, but we could have the uio driver store the interrupt statuses to avoid losing them. > > Also, reading the status register requires a vmexit. =A0I suggest dro= pping it > and requiring the application to manage this information in the share= d > memory area (where it could do proper queueing of multiple messages). > >> A value of 255 in the upper 8-bits will trigger a broadcast where th= e >> message >> will be sent to all other guests. >> > > Please consider adding: > > - MSI support Sure, I'll look into it. > - interrupt on a guest attaching/detaching to the shared memory devic= e Sure. > > With MSI you could also have the doorbell specify both guest ID and v= ector > number, which may be useful. > > Thanks for this - it definitely makes reviewing easier.