From: Cam Macdonell <cam@cs.ualberta.ca>
To: Avi Kivity <avi@redhat.com>
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: Re: [PATCH v5 4/5] Inter-VM shared memory PCI device
Date: Mon, 10 May 2010 17:17:39 -0600 [thread overview]
Message-ID: <AANLkTimxzp92RodmKqMZE9mOkprw6ToF8FAXeMeLnYTE@mail.gmail.com> (raw)
In-Reply-To: <4BE7F517.5010707@redhat.com>
On Mon, May 10, 2010 at 5:59 AM, Avi Kivity <avi@redhat.com> wrote:
> On 04/21/2010 08:53 PM, Cam Macdonell wrote:
>>
>> Support an inter-vm shared memory device that maps a shared-memory object
>> as a
>> PCI device in the guest. This patch also supports interrupts between
>> guest by
>> communicating over a unix domain socket. This patch applies to the
>> qemu-kvm
>> repository.
>>
>> -device ivshmem,size=<size in format accepted by -m>[,shm=<shm name>]
>>
>> Interrupts are supported between multiple VMs by using a shared memory
>> server
>> by using a chardev socket.
>>
>> -device ivshmem,size=<size in format accepted by -m>[,shm=<shm name>]
>> [,chardev=<id>][,msi=on][,irqfd=on][,vectors=n]
>> -chardev socket,path=<path>,id=<id>
>>
>> (shared memory server is qemu.git/contrib/ivshmem-server)
>>
>> Sample programs and init scripts are in a git repo here:
>>
>>
>> +typedef struct EventfdEntry {
>> + PCIDevice *pdev;
>> + int vector;
>> +} EventfdEntry;
>> +
>> +typedef struct IVShmemState {
>> + PCIDevice dev;
>> + uint32_t intrmask;
>> + uint32_t intrstatus;
>> + uint32_t doorbell;
>> +
>> + CharDriverState * chr;
>> + CharDriverState ** eventfd_chr;
>> + int ivshmem_mmio_io_addr;
>> +
>> + pcibus_t mmio_addr;
>> + unsigned long ivshmem_offset;
>> + uint64_t ivshmem_size; /* size of shared memory region */
>> + int shm_fd; /* shared memory file descriptor */
>> +
>> + int nr_allocated_vms;
>> + /* array of eventfds for each guest */
>> + int ** eventfds;
>> + /* keep track of # of eventfds for each guest*/
>> + int * eventfds_posn_count;
>>
>
> More readable:
>
> typedef struct Peer {
> int nb_eventfds;
> int *eventfds;
> } Peer;
> int nb_peers;
> Peer *peers;
>
> Does eventfd_chr need to be there as well?
No it does not, eventfd_chr store character devices for receiving
interrupts when irqfd is not available, so we only them for this
guest, not for our peers.
I've switched over to this more readable naming you've suggested.
>
>> +
>> + int nr_alloc_guests;
>> + int vm_id;
>> + int num_eventfds;
>> + uint32_t vectors;
>> + uint32_t features;
>> + EventfdEntry *eventfd_table;
>> +
>> + char * shmobj;
>> + char * sizearg;
>>
>
> Does this need to be part of the state?
They are because they're passed in as qdev properties from the
command-line so I thought they needed to be in the state struct to be
assigned via DEFINE_PROP_...
>
>> +} IVShmemState;
>> +
>> +/* registers for the Inter-VM shared memory device */
>> +enum ivshmem_registers {
>> + IntrMask = 0,
>> + IntrStatus = 4,
>> + IVPosition = 8,
>> + Doorbell = 12,
>> +};
>> +
>> +static inline uint32_t ivshmem_has_feature(IVShmemState *ivs, int
>> feature) {
>> + return (ivs->features& (1<< feature));
>> +}
>> +
>> +static inline int is_power_of_two(int x) {
>> + return (x& (x-1)) == 0;
>> +}
>>
>
> argument needs to be uint64_t to avoid overflow with large BARs. Return
> type can be bool.
>
>> +static void ivshmem_io_writel(void *opaque, uint8_t addr, uint32_t val)
>> +{
>> + IVShmemState *s = opaque;
>> +
>> + u_int64_t write_one = 1;
>> + u_int16_t dest = val>> 16;
>> + u_int16_t vector = val& 0xff;
>> +
>> + addr&= 0xfe;
>>
>
> Why 0xfe? Can understand 0xfc or 0xff.
Forgot to change to 0xfc when registers went from 16 to 32-bits.
>
>> +
>> + switch (addr)
>> + {
>> + case IntrMask:
>> + ivshmem_IntrMask_write(s, val);
>> + break;
>> +
>> + case IntrStatus:
>> + ivshmem_IntrStatus_write(s, val);
>> + break;
>> +
>> + case Doorbell:
>> + /* check doorbell range */
>> + if ((vector>= 0)&& (vector< s->eventfds_posn_count[dest]))
>> {
>>
>
> What if dest is too big? We overflow s->eventfds_posn_count.
added a check for that.
Thanks,
Cam
next prev parent reply other threads:[~2010-05-10 23:17 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-21 17:53 [PATCH v5 0/5] PCI Shared Memory device Cam Macdonell
2010-04-21 17:53 ` [PATCH v5 1/5] Device specification for shared memory PCI device Cam Macdonell
2010-04-21 17:53 ` [PATCH v5 2/5] Support adding a file to qemu's ram allocation Cam Macdonell
2010-04-21 17:53 ` [PATCH v5 3/5] Add functions for assigning ioeventfd and irqfds Cam Macdonell
2010-04-21 17:53 ` [PATCH v5 4/5] Inter-VM shared memory PCI device Cam Macdonell
2010-04-21 18:00 ` [PATCH v5 5/5] shared memory server for inter-VM shared memory Cam Macdonell
2010-05-05 16:57 ` [PATCH v5 4/5] RESEND: Inter-VM shared memory PCI device Cam Macdonell
2010-05-06 17:32 ` [PATCH v5 4/5] " Anthony Liguori
2010-05-06 17:59 ` Cam Macdonell
2010-05-10 11:59 ` Avi Kivity
2010-05-10 15:22 ` Cam Macdonell
2010-05-10 15:28 ` Avi Kivity
2010-05-10 15:38 ` Anthony Liguori
2010-05-10 16:20 ` Cam Macdonell
2010-05-10 16:52 ` Anthony Liguori
2010-05-18 16:58 ` Cam Macdonell
2010-05-18 17:27 ` Avi Kivity
2010-05-10 16:59 ` Avi Kivity
2010-05-10 17:25 ` Anthony Liguori
2010-05-10 17:43 ` Cam Macdonell
2010-05-10 17:52 ` Anthony Liguori
2010-05-10 18:01 ` Cam Macdonell
2010-05-11 7:59 ` Avi Kivity
2010-05-11 13:10 ` Anthony Liguori
2010-05-11 14:03 ` Avi Kivity
2010-05-11 14:17 ` Cam Macdonell
2010-05-11 14:53 ` Avi Kivity
2010-05-11 15:51 ` Anthony Liguori
2010-05-11 16:39 ` Cam Macdonell
2010-05-11 17:05 ` Anthony Liguori
2010-05-11 17:50 ` Cam Macdonell
2010-05-11 18:13 ` Avi Kivity
2010-05-12 15:32 ` Cam Macdonell
2010-05-12 15:48 ` Avi Kivity
2010-05-11 18:09 ` Avi Kivity
2010-05-11 7:55 ` Avi Kivity
2010-05-10 15:41 ` Cam Macdonell
2010-05-10 16:40 ` Avi Kivity
2010-05-10 16:48 ` Cam Macdonell
2010-05-12 15:49 ` Avi Kivity
2010-05-12 16:14 ` Cam Macdonell
2010-05-12 16:45 ` Avi Kivity
2010-05-10 23:17 ` Cam Macdonell [this message]
2010-05-11 8:03 ` Avi Kivity
2010-05-13 21:10 ` Cam Macdonell
2010-05-15 6:05 ` Avi Kivity
2010-05-10 10:43 ` [PATCH v5 3/5] Add functions for assigning ioeventfd and irqfds Avi Kivity
2010-05-10 15:13 ` Cam Macdonell
2010-05-10 15:17 ` Avi Kivity
2010-05-10 10:39 ` [PATCH v5 2/5] Support adding a file to qemu's ram allocation Avi Kivity
2010-05-10 15:32 ` 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=AANLkTimxzp92RodmKqMZE9mOkprw6ToF8FAXeMeLnYTE@mail.gmail.com \
--to=cam@cs.ualberta.ca \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.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).