PCI Shared memory device
Subsystems (3)
v4 cover PCI Shared memory device
Latest patch for PCI shared memory device that maps a host shared memory object to be shared between guests
new in this series
- moved to single Doorbell register and use datamatch to trigger different VMs rather than one register per eventfd
- remove writing arbitrary values to eventfds. Only values of 1 are now written to ensure correct usage
Cam Macdonell (3):
Device specification for shared memory PCI device Support adding a file to qemu's ram allocation Inter-VM shared memory PCI device
Makefile.target | 3 + cpu-common.h | 1 + docs/specs/ivshmem_device_spec.txt | 85 +++++ exec.c | 33 ++ hw/ivshmem.c | 700 ++++++++++++++++++++++++++++++++++++ qemu-char.c | 6 + qemu-char.h | 3 + 7 files changed, 831 insertions(+), 0 deletions(-) create mode 100644 docs/specs/ivshmem_device_spec.txt create mode 100644 hw/ivshmem.c
PATCH v4 1/3 Device specification for shared memory PCI device
--- docs/specs/ivshmem_device_spec.txt | 85 ++++++++++++++++++++++++++++++++++++ 1 files changed, 85 insertions(+), 0 deletions(-) create mode 100644 docs/specs/ivshmem_device_spec.txt
docs/specs/ivshmem_device_spec.txt new file +85 -0
@@ -0,0 +1,85 @@ + +Device Specification for Inter-VM shared memory device +------------------------------------------------------ + +The Inter-VM shared memory device is designed to share a region of memory to +userspace in multiple virtual guests. The memory region does not belong to any +guest, but is a POSIX memory object on the host. Optionally, the device may +support sending interrupts to other guests sharing the same memory region. + +The Inter-VM PCI device +----------------------- + +BARs + +The device supports three BARs. BAR0 is a 1 Kbyte MMIO region to support +registers. BAR1 is used for MSI-X when it is enabled in the device. BAR2 is +used to map the shared memory object from the host. The size of BAR2 is +specified when the guest is started and must be a power of 2 in size. + +Registers + +The device currently supports 4 registers of 32-bits each. Registers +are used for synchronization between guests sharing the same memory object when +interrupts are supported (this requires using the shared memory server). + +The server assigns each VM an ID number and sends this ID number to the Qemu +process when the guest starts. + +enum ivshmem_registers { + IntrMask = 0, + IntrStatus = 4, + IVPosition = 8, + Doorbell = 12 +}; + +The first two registers are the interrupt mask and status registers. Mask and +status are only used with pin-based interrupts. They are unused with MSI +interrupts. The IVPosition register is read-only and reports the guest's ID +number. To interrupt another guest, a guest must write to the Doorbell +register. The doorbell register is 32-bits, logically divided into two 16-bit +fields. The high 16-bits are the guest ID to interrupt and the low 16-bits are +the interrupt vector to trigger. + +The semantics of the value written to the doorbell depends on whether the +device is using MSI or a regular pin-based interrupt. In short, MSI uses +vectors and regular interrupts set the status register. + +Regular Interrupts +------------------ + +If regular interrupts are used (due to either a guest not supporting MSI or the +user specifying not to use them on startup) then the value written to the lower +16-bits of the Doorbell register results is arbitrary and will trigger an +interrupt in the destination guest. + +An interrupt is also generated when a new guest accesses the shared memory +region. A status of (2^32 - 1) indicates that a new guest has joined. + +Message Signalled Interrupts +---------------------------- + +A ivshmem device may support multiple MSI vectors. If so, the lower 16-bits +written to the Doorbell register must be between 1 and the maximum number of +vectors the guest supports. The lower 16 bits written to the doorbell is the +MSI vector that will be raised in the destination guest. The number of MSI +vectors can vary but it is set when the VM is started, however vector 0 is +used to notify that a new guest has joined. Guests should not use vector 0 for +any other purpose. + +The important thing to remember with MSI is that it is only a signal, no status +is set (since MSI interrupts are not shared). All information other than the +interrupt itself should be communicated via the shared memory region. Devices +supporting multiple MSI vectors can use different vectors to indicate different +events have occurred. The semantics of interrupt vectors are left to the +user's discretion. + +Usage in the Guest +------------------ + +The shared memory device is intended to be used with the provided UIO driver. +Very little configuration is needed. The guest should map BAR0 to access the +registers (an array of 32-bit ints allows simple writing) and map BAR2 to +access the shared memory region itself. The size of the shared memory region +is specified when the guest (or shared memory server) is started. A guest may +map the whole shared memory region or only part of it.
Signature · 1 line
1.6.0.6
PATCH v4 2/3 Support adding a file to qemu's ram allocation
This avoids the need of using qemu_ram_alloc and mmap with MAP_FIXED to map a host file into guest RAM. This function mmaps the opened file anywhere and adds the memory to the ram blocks.
Usage is
qemu_ram_mmap(fd, size, MAP_SHARED, offset);
--- cpu-common.h | 1 + exec.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 0 deletions(-)
cpu-common.h +1 -0
@@ -32,6 +32,7 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr, }ram_addr_t cpu_get_physical_page_desc (target_phys_addr_t addr); +ram_addr_t qemu_ram_mmap (int ,ram_addr_t ,int ,int );ram_addr_t qemu_ram_alloc (ram_addr_t );void qemu_ram_free (ram_addr_t addr);/* This should only be used for ram local to a device. */
exec.c +33 -0
@@ -2811,6 +2811,39 @@ static void *file_ram_alloc(ram_addr_t memory, const char *path) }#endif +ram_addr_t qemu_ram_mmap (int fd,ram_addr_t size,int flags,int offset) +{ +RAMBlock *new_block; + + size =TARGET_PAGE_ALIGN (size); + new_block =qemu_malloc (sizeof (*new_block)); + +// map the file passed as a parameter to be this part of memory + new_block->host =mmap (0 , size,PROT_READ |PROT_WRITE , flags, fd, offset); + +#ifdef MADV_MERGEABLE +madvise (new_block->host, size,MADV_MERGEABLE ); +#endif + + new_block->offset = last_ram_offset; + new_block->length = size; + + new_block->next = ram_blocks; + ram_blocks = new_block; + + phys_ram_dirty =qemu_realloc (phys_ram_dirty, + (last_ram_offset + size) >>TARGET_PAGE_BITS ); +memset (phys_ram_dirty + (last_ram_offset >>TARGET_PAGE_BITS ), +0xff , size >>TARGET_PAGE_BITS ); + + last_ram_offset += size; + +if (kvm_enabled ()) +kvm_setup_guest_memory (new_block->host, size); + +return new_block->offset; +} +ram_addr_t qemu_ram_alloc (ram_addr_t size) {RAMBlock *new_block;
Signature · 1 line
1.6.0.6
PATCH v4 3/3 Inter-VM shared memory PCI device
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 MB>[,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 MB>[,shm=<shm name>][,chardev=<id>][,msi=on]
[,irqfd=on][,vectors=n]
-chardev socket,path=<path>,id=<id>Sample programs, init scripts and the shared memory server are available in a git repo here:
www.gitorious.org/nahanni
--- Makefile.target | 3 + hw/ivshmem.c | 700 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-char.c | 6 + qemu-char.h | 3 + 4 files changed, 712 insertions(+), 0 deletions(-) create mode 100644 hw/ivshmem.c
Makefile.target +3 -0
@@ -199,6 +199,9 @@ obj-$(CONFIG_USB_OHCI) += usb-ohci.o obj-y += rtl8139.o obj-y += e1000.o +# Inter-VM PCI shared memory +obj-y += ivshmem.o + # Hardware support obj-i386-y = pckbd.o dma.o obj-i386-y += vga.o
hw/ivshmem.c new file +700 -0
700 lines not on this page · raw message
qemu-char.c +6 -0
@@ -2076,6 +2076,12 @@ static void tcp_chr_read(void *opaque) } } +CharDriverState *qemu_chr_open_eventfd (int eventfd){ + +return qemu_chr_open_fd (eventfd, eventfd); + +} +static void tcp_chr_connect (void *opaque) {CharDriverState *chr = opaque;
qemu-char.h +3 -0
@@ -93,6 +93,9 @@ void qemu_chr_info_print(Monitor *mon, const QObject *ret_data);void qemu_chr_info (Monitor *mon,QObject **ret_data);CharDriverState *qemu_chr_find (const char *name); +/* add an eventfd to the qemu devices that are polled */ +CharDriverState *qemu_chr_open_eventfd (int eventfd); +extern int term_escape_char;/* async I/O support */
Signature · 1 line
1.6.0.6
PATCH v4 1/1 Shared memory uio_pci driver
In reply to Cam MacdonellThis patch adds a driver for my shared memory PCI device using the uio_pci interface. The driver has three memory regions. The first memory region is for device registers for sending interrupts. The second BAR is for receiving MSI-X interrupts and the third memory region maps the shared memory. The device only exports the first and third memory regions to userspace.
This driver supports MSI-X and regular pin interrupts. Currently, the number of MSI vectors is set to 2 (one for new connections and the other for interrupts) but it could easily be increased. If MSI is not available, then regular interrupts will be used.
This version added formatting and style corrections as well as better error-checking and cleanup when errors occur.
--- drivers/uio/Kconfig | 8 ++ drivers/uio/Makefile | 1 + drivers/uio/uio_ivshmem.c | 252 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 261 insertions(+), 0 deletions(-) create mode 100644 drivers/uio/uio_ivshmem.c
drivers/uio/Kconfig +8 -0
@@ -74,6 +74,14 @@ config UIO_SERCOS3 If you compile this as a module, it will be called uio_sercos3. +config UIO_IVSHMEM + tristate "KVM shared memory PCI driver" + default n + help + Userspace I/O interface for the KVM shared memory device. This + driver will make available two memory regions, the first is + registers and the second is a region for sharing between VMs. + config UIO_PCI_GENERIC tristate "Generic driver for PCI 2.3 and PCI Express cards" depends on PCI
drivers/uio/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_UIO_AEC) += uio_aec.o obj-$(CONFIG_UIO_SERCOS3) += uio_sercos3.o obj-$(CONFIG_UIO_PCI_GENERIC) += uio_pci_generic.o obj-$(CONFIG_UIO_NETX) += uio_netx.o +obj-$(CONFIG_UIO_IVSHMEM) += uio_ivshmem.o
drivers/uio/uio_ivshmem.c new file +252 -0
252 lines not on this page · raw message
Signature · 1 line
1.6.0.6
Re: [PATCH v4 1/3] Device specification for shared memory PCI device
In reply to Cam MacdonellOn 04/08/2010 01:51 AM, Cam Macdonell wrote:
(sorry about the late review)
docs/specs/ivshmem_device_spec.txt line 54
Quoted 9 lines
docs/specs/ivshmem_device_spec.txt new file +8
-0+ +Regular Interrupts +------------------ + +If regular interrupts are used (due to either a guest not supporting MSI or the +user specifying not to use them on startup) then the value written to the lower +16-bits of the Doorbell register results is arbitrary and will trigger an +interrupt in the destination guest.
Does the value written show up in the status register? If yes, it can get overwritten by other interrupts. If not, the lower 16 bits should be reserved to the value 1 for future expansion. Basically it means that the pci interrupt is equivalent to to vector 1.
docs/specs/ivshmem_device_spec.txt line 57
Quoted 4 lines
docs/specs/ivshmem_device_spec.txt new file +3
-0+ +An interrupt is also generated when a new guest accesses the shared memory +region. A status of (2^32 - 1) indicates that a new guest has joined.
Suggest making this a bitfield, define bit 0 as 'at least some other machine has signalled you' and bit 1 as 'at least one other machine has joined'.
docs/specs/ivshmem_device_spec.txt line 68
Quoted 12 lines
docs/specs/ivshmem_device_spec.txt new file +11
-0+ +Message Signalled Interrupts +---------------------------- + +A ivshmem device may support multiple MSI vectors. If so, the lower 16-bits +written to the Doorbell register must be between 1 and the maximum number of +vectors the guest supports. The lower 16 bits written to the doorbell is the +MSI vector that will be raised in the destination guest. The number of MSI +vectors can vary but it is set when the VM is started, however vector 0 is +used to notify that a new guest has joined. Guests should not use vector 0 for +any other purpose.
Come to think about it, the guest has joined is actually pointless. Since it hasn't initialized yet you can't talk to it. So it's best to leave it completely to the application, which can initialize shared memory and start sending interrupts. An application defined protocol can handle joining.
How is initialization performed? I guess we can define memory to start zeroed and let participants compete to acquire a lock.
Need to document the mask register.
Do we want an interrupt on a guest leaving? Let's not complicate things.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
Re: [PATCH v4 2/3] Support adding a file to qemu's ram allocation
In reply to Cam MacdonellQuoted 17 lines · Cam Macdonell
This avoids the need of using
qemu_ram_allocand mmap withMAP_FIXEDto map a host file into guest RAM. This function mmaps the opened file anywhere and adds the memory to the ram blocks.Usage is
qemu_ram_mmap(fd, size, MAP_SHARED, offset);--- cpu-common.h | 1 + exec.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 0 deletions(-)cpu-common.h +0
-0
cpu-common.h static inline void cpu_register_physical_memory(target_phys_addr_t start_addr, · line 36
Quoted 5 lines
cpu-common.h +1
-0@@ -32,6 +32,7 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr, }ram_addr_t cpu_get_physical_page_desc (target_phys_addr_t addr); +ram_addr_t qemu_ram_mmap (int ,ram_addr_t ,int ,int );
Use prototypes with argument names please. That's not the style around it, but that's bad style.
cpu-common.h static inline void cpu_register_physical_memory(target_phys_addr_t start_addr, · line 38
Quoted 3 lines
cpu-common.h +1
-0+ram_addr_t qemu_ram_mmap (int fd,ram_addr_t size,int flags,int offset)
off_t offset
cpu-common.h static inline void cpu_register_physical_memory(target_phys_addr_t start_addr,
Quoted 8 lines
cpu-common.h +7
-0+{ +RAMBlock *new_block; + + size =TARGET_PAGE_ALIGN (size); + new_block =qemu_malloc (sizeof (*new_block)); + +// map the file passed as a parameter to be this part of memory
/* comments */
Quoted 2 lines
+
new_block->host=mmap(0, size, PROT_READ|PROT_WRITE, flags, fd, offset);
Error checking.
cpu-common.h
Quoted 5 lines
cpu-common.h +4
-0+ +#ifdef MADV_MERGEABLE +madvise (new_block->host, size,MADV_MERGEABLE ); +#endif
Won't work (ksm only merges anonymous pages), but keep it there in case it learns about pagecache.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
Re: [PATCH v4 3/3] Inter-VM shared memory PCI device
In reply to Cam MacdonellQuoted 7 lines · Cam Macdonell
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 MB>[,shm=<shm name>]
Can that be <size in format accepted by -m> (2M, 4G, 19T, ...).
Quoted 7 lines
Interrupts are supported between multiple VMs by using a shared memory server by using a chardev socket.
-device ivshmem,size=<size in MB>[,shm=<shm name>][,chardev=<id>][,msi=on] [,irqfd=on][,vectors=n] -chardev socket,path=<path>,id=<id>
Do we need the irqfd parameter? Should be on by default.
On the other hand, it may fail with older kernels with limited irqfd slots, so better keep it there.
Quoted 5 lines
Sample programs, init scripts and the shared memory server are available in a git repo here:
www.gitorious.org/nahanni
Please consider qemu.git/contrib.
Quoted 6 lines
--- Makefile.target | 3 + hw/ivshmem.c | 700 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-char.c | 6 + qemu-char.h | 3 +
qemu-doc.texi | 45 +++++++++++++
Quoted 8 lines
4 files changed, 712 insertions(+), 0 deletions(-)create mode 100644
hw/ivshmem.cMakefile.target +0
-0
Makefile.target obj-$(CONFIG_USB_OHCI) += usb-ohci.o · line 205
Quoted 7 lines
Makefile.target +3
-0@@ -199,6 +199,9 @@ obj-$(CONFIG_USB_OHCI) += usb-ohci.o obj-y += rtl8139.o obj-y += e1000.o +# Inter-VM PCI shared memory +obj-y += ivshmem.o +
depends on CONFIG_PCI
Makefile.target obj-$(CONFIG_USB_OHCI) += usb-ohci.o
Quoted 5 lines
Makefile.target +3
-0# Hardware support + +#define PCI_COMMAND_IOACCESS 0x0001 +#define PCI_COMMAND_MEMACCESS 0x0002
Should be in pci.h?
Makefile.target
Quoted 3 lines
Makefile.target +2
-0+ +#define DEBUG_IVSHMEM
Disable for production.
Makefile.target
Quoted 5 lines
Makefile.target +4
-0+ +#define IVSHMEM_IRQFD 0 +#define IVSHMEM_MSI 1 +#define IVSHMEM_MAX_EVENTFDS 16
Too low? why limit?
Makefile.target
Quoted 6 lines
Makefile.target +5
-0+ +struct eventfd_entry { + PCIDevice *pdev; + int vector; +};
Coding style: EventfdEntry, and a typedef.
Quoted 5 lines
Makefile.target +4
-0+ +typedef struct IVShmemState { + PCIDevice dev; + uint32_t intrmask;
Makefile.target
Quoted 10 lines
Makefile.target +10
-0+ uint32_t intrstatus; + uint32_t doorbell; + + CharDriverState * chr; + CharDriverState ** eventfd_chr; + int ivshmem_mmio_io_addr; + + pcibus_t mmio_addr; + uint8_t *ivshmem_ptr; + unsigned long ivshmem_offset;
off_t
Quoted 2 lines
+ unsigned int
ivshmem_size;
ram_addr_t
Makefile.target
Quoted 7 lines
Makefile.target +6
-0+ +/* accessing registers - based on rtl8139 */ +static void ivshmem_update_irq(IVShmemState *s, int val) +{ + int isr; + isr = (s->intrstatus& s->intrmask)& 0xffffffff;
This is highly undocumented, but fits my suggested 'status is bitmap'. 'isr' needs to be uint32_t if you mask it like that.
Quoted 11 lines
Makefile.target +10
-0+ + /* don't print ISR resets */ + if (isr) { + IVSHMEM_DPRINTF("Set IRQ to %d (%04x %04x)\n", + isr ? 1 : 0, s->intrstatus, s->intrmask); + } + + qemu_set_irq(s->dev.irq[0], (isr != 0)); +} +
Makefile.target
Quoted 10 lines
Makefile.target +8
-0+ + +static void create_shared_memory_BAR(IVShmemState *s, int fd) { + + s->shm_fd = fd; + + s->ivshmem_offset = qemu_ram_mmap(s->shm_fd, s->ivshmem_size, + MAP_SHARED, 0);
Where did the offset go?
Makefile.target
Quoted 3 lines
Makefile.target +2
-0+ + s->ivshmem_ptr = qemu_get_ram_ptr(s->ivshmem_offset);
Never used, please drop.
Makefile.target
Quoted 5 lines
Makefile.target +4
-0+ + /* region for shared memory */ + pci_register_bar(&s->dev, 2, s->ivshmem_size, + PCI_BASE_ADDRESS_SPACE_MEMORY, ivshmem_map);
Might be worthwhile to mark it as a 64-bit BAR. Please test with ridiculous shared memory sizes.
Quoted 10 lines
Makefile.target +9
-0+} + +static int ivshmem_irqfd(PCIDevice* pdev, uint16_t vector, int fd) +{ + struct kvm_irqfd call = { }; + int r; + + IVSHMEM_DPRINTF("inside irqfd\n"); + if (vector>= pdev->msix_entries_nr)
Makefile.target
Quoted 10 lines
Makefile.target +10
-0+ return -EINVAL; + call.fd = fd; + call.gsi = pdev->msix_irq_entries[vector].gsi; + r = kvm_vm_ioctl(kvm_state, KVM_IRQFD,&call); + if (r< 0) { + IVSHMEM_DPRINTF("allocating irqfd failed %d\n", r); + return r; + } + return 0; +}
should be in kvm.c for reuse.
Quoted 5 lines
Makefile.target +4
-0+ +static int ivshmem_ioeventfd(IVShmemState* s, int posn, int fd, int vector) +{ +
Makefile.target
Quoted 10 lines
Makefile.target +10
-0+ int ret; + struct kvm_ioeventfd iofd; + + iofd.datamatch = (posn<< 16) | vector; + iofd.addr = s->mmio_addr + Doorbell; + iofd.len = 4; + iofd.flags = KVM_IOEVENTFD_FLAG_DATAMATCH; + iofd.fd = fd; + + ret = kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD,&iofd);
Ditto.
Makefile.target
Quoted 11 lines
Makefile.target +10
-0+ + if (ret< 0) { + fprintf(stderr, "error assigning ioeventfd (%d)\n", ret); + perror(strerror(ret)); + } else { + IVSHMEM_DPRINTF("success assigning ioeventfd (%d:%d)\n", posn, vector); + } + + return ret; +}
blank line here.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
Re: [PATCH v4] Shared memory uio_pci driver
In reply to Cam MacdonellQuoted 6 lines · Cam Macdonell
This patch adds a driver for my shared memory PCI device using the
uio_pciinterface. The driver has three memory regions. The first memory region is for device registers for sending interrupts. The second BAR is for receiving MSI-X interrupts and the third memory region maps the shared memory. The device only exports the first and third memory regions to userspace.
Quoted 9 lines
This driver supports MSI-X and regular pin interrupts. Currently, the number of MSI vectors is set to 2 (one for new connections and the other for interrupts) but it could easily be increased. If MSI is not available, then regular interrupts will be used.
This version added formatting and style corrections as well as better error-checking and cleanup when errors occur.
There is work now to bring msi to the generic pci 2.3 driver, perhaps we can use that instead. From a quick look it looks fine.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
Re: [PATCH v4 1/3] Device specification for shared memory PCI device
In reply to Avi KivityQuoted 4 lines · Avi Kivity
On 04/08/2010 01:51 AM, Cam Macdonell wrote:
(sorry about the late review)
Quoted 16 lines
Quoted 11 lines
docs/specs/ivshmem_device_spec.txt new file +5
-0+ +Regular Interrupts +------------------ + +If regular interrupts are used (due to either a guest not supporting MSIor the
+user specifying not to use them on startup) then the value written to the lower
+16-bits of the Doorbell register results is arbitrary and will trigger an +interrupt in the destination guest.Does the value written show up in the status register? If yes, it can get overwritten by other interrupts. If not, the lower 16 bits should be reserved to the value 1 for future expansion. Basically it means that the pci interrupt is equivalent to to vector 1.
The status register is only 1 or 0. I've made it so 1 is the only value written to trigger an interrupt.
Quoted 25 lines
Quoted 6 lines
(quoted diff) +2
-0+ +An interrupt is also generated when a new guest accesses the sharedmemory
+region. A status of (2^32 - 1) indicates that a new guest has joined.Suggest making this a bitfield, define bit 0 as 'at least some other machine has signalled you' and bit 1 as 'at least one other machine has joined'.
Quoted 15 lines
docs/specs/ivshmem_device_spec.txt new file +5
-0+ +Message Signalled Interrupts +---------------------------- + +A ivshmem device may support multiple MSI vectors. If so, the lower16-bits
+written to the Doorbell register must be between 1 and the maximum number of
+vectors the guest supports. The lower 16 bits written to the doorbell is the
+MSI vector that will be raised in the destination guest. The number of MSI
+vectors can vary but it is set when the VM is started, however vector 0 is
+used to notify that a new guest has joined. Guests should not use vector
Quoted 8 lines
Quoted 3 lines
0 for
+any other purpose.Come to think about it, the guest has joined is actually pointless. Since it hasn't initialized yet you can't talk to it. So it's best to leave it completely to the application, which can initialize shared memory and start sending interrupts. An application defined protocol can handle joining.
Good point.
Quoted 2 lines
How is initialization performed? I guess we can define memory to start zeroed and let participants compete to acquire a lock.
No initialization of the memory occurs presently.
With interrupts the shared memory server could zero the memory. Without the server (non-interrupt case) the guests can try and open the shared memory with O_EXCL first and zero the memory if it succeeds. If O_EXCL fails, then guest would open without O_EXCL and not initialize.
Quoted 2 lines
Need to document the mask register.
Currently only applies with regular interrupts. Since the status register is only 0 or 1, then only the first bit has any affect. I'll add this to the spec.
Quoted 2 lines
Do we want an interrupt on a guest leaving? Let's not complicate things.
Probably not if we don't have one on join.
Cam
Quoted 2 lines · Cam Macdonell
Latest patch for PCI shared memory device that maps a host shared memory object to be shared between guests
FWIW, I still think it would be better to reuse virtio-pci spec for feature negotiation, control etc even
if Anthony nacks the reuse of virtio code in qemu.
Signature · 1 line
MST
Re: [PATCH v4 3/3] Inter-VM shared memory PCI device
In reply to Avi KivityQuoted 30 lines · Avi Kivity
Quoted 11 lines · Cam Macdonell
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 MB>[,shm=<shm name>]
Can that be <size in format accepted by -m> (2M, 4G, 19T, ...).
Quoted 9 lines
Interrupts are supported between multiple VMs by using a shared memory server
by using a chardev socket.-device ivshmem,size=<size in MB>[,shm=<shm
name>][,chardev=<id>][,msi=on]
[,irqfd=on][,vectors=n]
-chardev socket,path=<path>,id=<id>Do we need the irqfd parameter? Should be on by default.
On the other hand, it may fail with older kernels with limited irqfd slots, so better keep it there.
Quoted 8 lines
Quoted 6 lines
Sample programs, init scripts and the shared memory server are available in a
git repo here:www.gitorious.org/nahanni
Please consider qemu.git/contrib.
Should the compilation be tied into Qemu's regular build with a switch (e.g. --enable-ivshmem-server)? Or should it be its own separate build?
Cam
Quoted 10 lines
Quoted 8 lines
---
Makefile.target | 3 +
hw/ivshmem.c | 700
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
qemu-char.c | 6 +
qemu-char.h | 3 +qemu-doc.texi | 45 +++++++++++++
Seems to be light on qdev devices. I notice there is a section named "Data Type Index" that "could be used for qdev device names and options", but is currently empty. Should I place documentation there of device there or just add it to "3.3 Invocation"?
Quoted 12 lines
Quoted 12 lines
4 files changed, 712 insertions(+), 0 deletions(-)create mode 100644
hw/ivshmem.cMakefile.target +0
-0@@ -199,6 +199,9 @@ obj-$(CONFIG_USB_OHCI) += usb-ohci.oobj-y += rtl8139.o
obj-y += e1000.o
Quoted 6 lines
Makefile.target obj-$(CONFIG_USB_OHCI) += usb-ohci.o · line 204
Quoted 4 lines
Makefile.target +3
-0+# Inter-VM PCI shared memory +obj-y += ivshmem.o +depends on
CONFIG_PCI
as in
obj-($CONFIG_PCI) += ivshmem.o
the variable CONFIG_PCI doesn't seem to be set during configuration. I don't see any other PCI devices that depend on it. Do we also want to depend on CONFIG_KVM?
Quoted 9 lines
Makefile.target
Quoted 7 lines
Makefile.target +6
-0+static void create_shared_memory_BAR(IVShmemState *s, int fd) { + + s->shm_fd = fd; + + s->ivshmem_offset = qemu_ram_mmap(s->shm_fd, s->ivshmem_size, + MAP_SHARED, 0);Where did the offset go?
0 is the offset. I include the offset parameter in qemu_ram_mmap() to make it flexible for other uses. Are you suggesting to take an optional offset as an argument to -device?
Cam
Re: [PATCH v4 3/3] Inter-VM shared memory PCI device
Quoted 5 lines · Cam Macdonell
Quoted 5 lines
Quoted 5 lines
Sample programs, init scripts and the shared memory server are available in a
git repo here:
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
www.gitorious.org/nahanni
Please consider qemu.git/contrib.
Should the compilation be tied into Qemu's regular build with a switch (e.g. --enable-ivshmem-server)? Or should it be its own separate build?
It can have its own makefile.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
--- Makefile.target | 3 + hw/ivshmem.c | 700 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-char.c | 6 + qemu-char.h | 3 +
Quoted 7 lines
Quoted 2 lines
qemu-doc.texi | 45 +++++++++++++
Seems to be light on qdev devices. I notice there is a section named "Data Type Index" that "could be used for qdev device names and options", but is currently empty. Should I place documentation there of device there or just add it to "3.3 Invocation"?
I think those are in qemu-options.hx. Just put it somewhere where it seems appropriate.
Quoted 20 lines
Quoted 13 lines
Quoted 13 lines
4 files changed, 712 insertions(+), 0 deletions(-)create mode 100644
hw/ivshmem.cMakefile.target +0
-0@@ -199,6 +199,9 @@ obj-$(CONFIG_USB_OHCI) += usb-ohci.o obj-y += rtl8139.o obj-y += e1000.oQuoted 7 lines
Makefile.target obj-$(CONFIG_USB_OHCI) += usb-ohci.o
Quoted 5 lines
Makefile.target +3
-0+# Inter-VM PCI shared memory +obj-y += ivshmem.o +depends on
CONFIG_PCI
Quoted 7 lines
as in
obj-($CONFIG_PCI) += ivshmem.o
the variable
CONFIG_PCIdoesn't seem to be set during configuration. I don't see any other PCI devices that depend on it.
My mistake, keep as is.
Quoted 3 lines
Do we also want
to depend onCONFIG_KVM?
No real need.
Quoted 10 lines
Quoted 10 lines
Makefile.target obj-$(CONFIG_USB_OHCI) += usb-ohci.o
Quoted 8 lines
Makefile.target +6
-0+static void create_shared_memory_BAR(IVShmemState *s, int fd) { + + s->shm_fd = fd; + + s->ivshmem_offset = qemu_ram_mmap(s->shm_fd, s->ivshmem_size, + MAP_SHARED, 0);Where did the offset go?
Quoted 2 lines
0 is the offset. I include the offset parameter in
qemu_ram_mmap()to make it flexible for other uses.
Makes sense.
Quoted 3 lines
Are you suggesting to take an
optional offset as an argument to -device?
No need.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Re: [PATCH v4] Shared memory uio_pci driver
In reply to Avi KivityQuoted 4 lines · Avi Kivity
There is work now to bring msi to the generic pci 2.3 driver, perhaps we can use that instead. From a quick look it looks fine.
I'd be interested to follow this development. I can't find anything on LKML, is it being discussed anywhere?
Thanks,
Cam
Re: [PATCH v4] Shared memory uio_pci driver
Quoted 10 lines · Cam Macdonell
Quoted 4 lines · Avi Kivity
There is work now to bring msi to the generic pci 2.3 driver, perhaps we can use that instead. From a quick look it looks fine.
I'd be interested to follow this development. I can't find anything on LKML, is it being discussed anywhere?
Look for patches from Tom Lyon (on kvm@ as well).
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.