Support adding a file to qemu's ram allocation
PATCH 1/1 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_add_file_to_ram(fd, size, MAP_SHARED);
--- cpu-common.h | 1 + exec.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 0 deletions(-)
cpu-common.h +1 -0
@@ -30,6 +30,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_add_file_to_ram (int ,ram_addr_t ,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
@@ -2623,6 +2623,39 @@ static void *file_ram_alloc(ram_addr_t memory, const char *path)extern const char *mem_path; +ram_addr_t qemu_add_file_to_ram (int fd,ram_addr_t size,int flags) +{ +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,0 ); + +#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 1/1 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.
This device now creates a qemu character device and sends 1-bytes messages to trigger interrupts. Writes are trigger by writing to the "Doorbell" register on the shared memory PCI device. The lower 8-bits of the value written to this register are sent as the 1-byte message so different meanings of interrupts can be supported.
Interrupts are supported between multiple VMs by using a shared memory server
-ivshmem <size in MB>,[unix:<path>][file]
Interrupts can also be used between host and guest as well by implementing a listener on the host that talks to shared memory server. The shared memory server passes file descriptors for the shared memory object and eventfds (our interrupt mechanism) to the respective qemu instances.
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 | 561 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pc.c | 6 + hw/pc.h | 3 + qemu-char.c | 6 + qemu-char.h | 3 + qemu-options.hx | 12 ++ sysemu.h | 8 + vl.c | 13 ++ 9 files changed, 615 insertions(+), 0 deletions(-) create mode 100644 hw/ivshmem.c
Makefile.target +3 -0
@@ -217,6 +217,9 @@ obj-y += pcnet.o obj-y += rtl8139.o obj-y += e1000.o +# Inter-VM PCI shared memory +obj-y += ivshmem.o + # Hardware support obj-i386-y = ide/core.o ide/qdev.o ide/isa.o ide/pci.o ide/piix.o obj-i386-y += pckbd.o $(sound-obj-y) dma.o
hw/ivshmem.c new file +561 -0
561 lines not on this page · raw message
hw/pc.c +6 -0
@@ -90,6 +90,8 @@ struct e820_table {static struct e820_table e820_table; +extern int ivshmem_enabled; + typedef struct isa_irq_state { qemu_irq *i8259; qemu_irq *ioapic;
@@ -965,6 +967,10 @@ static void pc_init1(ram_addr_t ram_size, } } +if (pci_enabled && ivshmem_enabled) { +pci_ivshmem_init (pci_bus); + } + rtc_state =rtc_init (2000 );qemu_register_boot_set (pc_boot_set, rtc_state);
hw/pc.h +3 -0
@@ -167,6 +167,9 @@ void isa_ne2000_init(int base, int irq, NICInfo *nd);void extboot_init (BlockDriverState *bs); +/* ivshmem.c */ +int pci_ivshmem_init (PCIBus *bus); +int cpu_is_bsp (CPUState *env);/* e820 types */
qemu-char.c +6 -0
@@ -2066,6 +2066,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 */
qemu-options.hx +12 -0
@@ -1679,6 +1679,18 @@ STEXI Setup monitor on chardev @var{name}. ETEXI +DEF("ivshmem", HAS_ARG, QEMU_OPTION_ivshmem, \ + "-ivshmem size,unix:file connects to shared memory PCI card server \ + listening on unix domain socket 'path' of at least 'size' (in MB) and \ + exposes as a PCI device in the guest\n") +STEXI +@item -ivshmem @var{size},unix:@var{file} +Connects to a shared memory PCI server at UDS @var{file} that shares a POSIX +shared object of size @var{size} and creates a PCI device of the same size that +maps the shared object (received from the server) into the device for guests to +access. The servers also sends eventfds to the guest to support interrupts. +ETEXI + DEF("debugcon", HAS_ARG, QEMU_OPTION_debugcon, \ "-debugcon dev redirect the debug console to char device 'dev'\n") STEXI
sysemu.h +8 -0
@@ -241,6 +241,14 @@ extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS ]; +/* inter-VM shared memory devices */ + +#define MAX_IVSHMEM_DEVICES 1 + +extern CharDriverState * ivshmem_chardev; +void ivshmem_init (const char * optarg); +int ivshmem_get_size (void ); +#define TFR (expr) do { if ((expr) != -1) break; } while (errno == EINTR)#ifdef HAS_AUDIO
vl.c +13 -0
@@ -194,6 +194,7 @@ int autostart;static int rtc_utc =1 ;static int rtc_date_offset =-1 ;/* -1 means no change */ QEMUClock *rtc_clock; +int ivshmem_enabled =0 ;int vga_interface_type =VGA_NONE ;#ifdef TARGET_SPARC int graphic_width =1024 ;
@@ -212,6 +213,8 @@ int no_quit = 0;CharDriverState *serial_hds[MAX_SERIAL_PORTS ];CharDriverState *parallel_hds[MAX_PARALLEL_PORTS ];CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES ]; +CharDriverState *ivshmem_chardev; +const char * ivshmem_device;#ifdef TARGET_I386 int win2k_install_hack =0 ;int rtc_td_hack =0 ;
@@ -4953,6 +4956,8 @@ int main(int argc, char **argv, char **envp) kernel_cmdline ="" ; cyls = heads = secs =0 ; translation =BIOS_ATA_TRANSLATION_AUTO ; + ivshmem_device =NULL ; + ivshmem_chardev =NULL ;for (i =0 ; i <MAX_NODES ; i++) { node_mem[i] =0 ;
@@ -5439,6 +5444,10 @@ int main(int argc, char **argv, char **envp)add_device_config (DEV_PARALLEL , optarg); default_parallel =0 ;break ; +case QEMU_OPTION_ivshmem: + ivshmem_device = optarg; + ivshmem_enabled =1 ; +break ;case QEMU_OPTION_debugcon:add_device_config (DEV_DEBUGCON , optarg);break ;
@@ -5956,6 +5965,10 @@ int main(int argc, char **argv, char **envp)if (ram_size ==0 ) ram_size =DEFAULT_RAM_SIZE *1024 *1024 ; +if (ivshmem_enabled) { +ivshmem_init (ivshmem_device); + } +/* init the dynamic translator */ cpu_exec_init_all (tb_size *1024 *1024 );
Signature · 1 line
1.6.0.6
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 4 lines
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.
No. All new devices should be fully qdev based.
I suspect you've also ignored a load of coherency issues, especially when not using KVM. As soon as you have shared memory in more than one host thread/process you have to worry about memory barriers.
Paul
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 10 lines · Paul Brook
Quoted 4 lines
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.No. All new devices should be fully qdev based.
I suspect you've also ignored a load of coherency issues, especially when not using KVM. As soon as you have shared memory in more than one host thread/process you have to worry about memory barriers.
Yes. Guest-observable behaviour is likely to be quite different on different hosts, expecially beteen x86 and non-x86 hosts, which is not good at all for emulation.
Memory barriers performed by the guest would help, but would not remove the fact that behaviour would vary beteen different host types if a guest doesn't call them. I.e. you could accidentally have some guests working fine for years on x86 hosts, which gain subtle memory corruption as soon as you run them on a different host.
This is acceptable when recompiling code for different architectures, but it's asking for trouble with binary guest images which aren't supposed to depend on host architecture.
However, coherence could be made host-type-independent by the host mapping and unampping pages, so that each page is only mapped into one guest (or guest CPU) at a time. Just like some clustering filesystems do to maintain coherence.
-- Jamie
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Am 08.03.2010 um 02:45 schrieb Jamie Lokier <[email protected]>:
Quoted 22 lines
Quoted 10 lines · Paul Brook
Quoted 4 lines
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.
No. All new devices should be fully qdev based.
I suspect you've also ignored a load of coherency issues, especially when not using KVM. As soon as you have shared memory in more than one host thread/process you have to worry about memory barriers.
Yes. Guest-observable behaviour is likely to be quite different on different hosts, expecially beteen x86 and non-x86 hosts, which is not good at all for emulation.
Memory barriers performed by the guest would help, but would not remove the fact that behaviour would vary beteen different host types if a guest doesn't call them. I.e. you could accidentally have some guests working fine for years on x86 hosts, which gain subtle memory corruption as soon as you run them on a different host.
Quoted 8 lines
This is acceptable when recompiling code for different architectures, but it's asking for trouble with binary guest images which aren't supposed to depend on host architecture.
However, coherence could be made host-type-independent by the host mapping and unampping pages, so that each page is only mapped into one guest (or guest CPU) at a time. Just like some clustering filesystems do to maintain coherence.
Or we could put in some code that tells the guest the host shm architecture and only accept x86 on x86 for now. If anyone cares for other combinations, they're free to implement them.
Seriously, we're looking at an interface designed for kvm here. Let's please keep it as simple and fast as possible for the actual use case, not some theoretically possible ones.
Alex
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 7 lines · Alexander Graf
Or we could put in some code that tells the guest the host shm architecture and only accept x86 on x86 for now. If anyone cares for other combinations, they're free to implement them.
Seriously, we're looking at an interface designed for kvm here. Let's please keep it as simple and fast as possible for the actual use case, not some theoretically possible ones.
The concern is that a perfectly working guest image running on kvm, the guest being some OS or app that uses this facility (_not_ a kvm-only guest driver), is later run on qemu on a different host, and then mostly works except for some silent data corruption.
That is not a theoretical scenario.
Well, the bit with this driver is theoretical, obviously :-) But not the bit about moving to a different host.
-- Jamie
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 16 lines · Jamie Lokier
Quoted 8 lines · Alexander Graf
Or we could put in some code that tells the guest the host shm architecture and only accept x86 on x86 for now. If anyone cares for other combinations, they're free to implement them.
Seriously, we're looking at an interface designed for kvm here. Let's please keep it as simple and fast as possible for the actual use case, not some theoretically possible ones.
The concern is that a perfectly working guest image running on kvm, the guest being some OS or app that uses this facility (_not_ a kvm-only guest driver), is later run on qemu on a different host, and then mostly works except for some silent data corruption.
Quoted 5 lines
That is not a theoretical scenario.
Well, the bit with this driver is theoretical, obviously :-) But not the bit about moving to a different host.
I agree. Hence there should be a safety check so people can't corrupt their data silently.
Alex
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
In reply to Jamie LokierQuoted 10 lines · Jamie Lokier
Quoted 8 lines · Alexander Graf
Or we could put in some code that tells the guest the host shm architecture and only accept x86 on x86 for now. If anyone cares for other combinations, they're free to implement them.
Seriously, we're looking at an interface designed for kvm here. Let's please keep it as simple and fast as possible for the actual use case, not some theoretically possible ones.
Quoted 7 lines
The concern is that a perfectly working guest image running on kvm, the guest being some OS or app that uses this facility (_not_ a kvm-only guest driver), is later run on qemu on a different host, and then mostly works except for some silent data corruption.
That is not a theoretical scenario.
Hint: no matter what you do, shared memory is a hack that's going to lead to subtle failures one way or another.
It's useful to support because it has some interesting academic uses but it's not a mechanism that can ever be used for real world purposes.
It's impossible to support save/restore correctly. It can never be made to work with TCG in a safe way. That's why I've been advocating keeping this as simple as humanly possible. It's just not worth trying to make this fancier than it needs to be because it will never be fully correct.
Regards,
Anthony Liguori
Quoted 9 lines
Well, the bit with this driver is theoretical, obviously :-) But not the bit about moving to a different host.
-- Jamie
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
In reply to Jamie LokierQuoted 4 lines
However, coherence could be made host-type-independent by the host mapping and unampping pages, so that each page is only mapped into one guest (or guest CPU) at a time. Just like some clustering filesystems do to maintain coherence.
You're assuming that a TLB flush implies a write barrier, and a TLB miss implies a read barrier. I'd be surprised if this were true in general.
Paul
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 7 lines · Paul Brook
Quoted 4 lines
However, coherence could be made host-type-independent by the host mapping and unampping pages, so that each page is only mapped into one guest (or guest CPU) at a time. Just like some clustering filesystems do to maintain coherence.
You're assuming that a TLB flush implies a write barrier, and a TLB miss implies a read barrier. I'd be surprised if this were true in general.
The host driver itself can issue full barriers at the same time as it maps pages on TLB miss, and would probably have to interrupt the guest's SMP KVM threads to insert a full barrier when broadcasting a TLB flush on unmap.
-- Jamie
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
In reply to Paul BrookQuoted 11 lines · Paul Brook
Quoted 5 lines
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.No. All new devices should be fully qdev based.
I suspect you've also ignored a load of coherency issues, especially when not using KVM. As soon as you have shared memory in more than one host thread/process you have to worry about memory barriers.
Shouldn't it be sufficient to require the guest to issue barriers (and to ensure tcg honours the barriers, if someone wants this with tcg)?.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 6 lines · Paul Brook
Quoted 5 lines
Quoted 4 lines
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.
Quoted 8 lines
Quoted 5 lines
No. All new devices should be fully qdev based.
I suspect you've also ignored a load of coherency issues, especially when not using KVM. As soon as you have shared memory in more than one host thread/process you have to worry about memory barriers.
Shouldn't it be sufficient to require the guest to issue barriers (and to ensure tcg honours the barriers, if someone wants this with tcg)?.
In a cross environment that becomes extremely hairy. For example the x86 architecture effectively has an implicit write barrier before every store, and an implicit read barrier before every load.
Paul
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 13 lines · Paul Brook
Quoted 13 lines · Paul Brook
Quoted 12 lines
Quoted 6 lines
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.
No. All new devices should be fully qdev based.
I suspect you've also ignored a load of coherency issues, especially when not using KVM. As soon as you have shared memory in more than one host thread/process you have to worry about memory barriers.
Quoted 7 lines
Quoted 3 lines
Shouldn't it be sufficient to require the guest to issue barriers (and to ensure tcg honours the barriers, if someone wants this with tcg)?.
In a cross environment that becomes extremely hairy. For example the x86 architecture effectively has an implicit write barrier before every store, and an implicit read barrier before every load.
Ah yes. For cross tcg environments you can map the memory using mmio callbacks instead of directly, and issue the appropriate barriers there.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 17 lines · Avi Kivity
Quoted 16 lines · Paul Brook
Quoted 16 lines · Paul Brook
Quoted 6 lines
Quoted 6 lines
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.
Quoted 6 lines
No. All new devices should be fully qdev based.
I suspect you've also ignored a load of coherency issues, especially when not using KVM. As soon as you have shared memory in more than one host thread/process you have to worry about memory barriers.
Shouldn't it be sufficient to require the guest to issue barriers (and to ensure tcg honours the barriers, if someone wants this with tcg)?.
Quoted 8 lines
Quoted 5 lines
In a cross environment that becomes extremely hairy. For example the x86 architecture effectively has an implicit write barrier before every store, and
an implicit read barrier before every load.Ah yes. For cross tcg environments you can map the memory using mmio callbacks instead of directly, and issue the appropriate barriers there.
That makes sense. It will force an mmio callback for every access to the shared memory, which is ok for correctness but vastly slower when running in TCG compared with KVM.
But it's hard to see what else could be done - those implicit write barries on x86 have to be emulated somehow. For TCG without inter-vm shared memory, those barriers aren't a problem.
Non-random-corruption guest behaviour is paramount, so I hope the inter-vm device will add those mmio callbacks for the cross-arch case before it sees much action. (Strictly, it isn't cross-arch, but host-has-more-relaxed-implicit-memory-model-than-guest. I'm assuming TCG doesn't reorder memory instructions).
-- Jamie
Re: [PATCH] Inter-VM shared memory PCI device
In reply to Avi KivityQuoted 11 lines · Avi Kivity
Quoted 10 lines · Paul Brook
Quoted 10 lines · Paul Brook
Quoted 9 lines
Quoted 4 lines
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.
No. All new devices should be fully qdev based.
I suspect you've also ignored a load of coherency issues, especially when not using KVM. As soon as you have shared memory in more than one host thread/process you have to worry about memory barriers.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Shouldn't it be sufficient to require the guest to issue barriers (and to ensure tcg honours the barriers, if someone wants this with tcg)?.
In a cross environment that becomes extremely hairy. For example the x86 architecture effectively has an implicit write barrier before every store, and an implicit read barrier before every load.
Ah yes. For cross tcg environments you can map the memory using mmio callbacks instead of directly, and issue the appropriate barriers there.
Not good enough unless you want to severely restrict the use of shared memory within the guest.
For instance, it's going to be useful to assume that you atomic instructions remain atomic. Crossing architecture boundaries here makes these assumptions invalid. A barrier is not enough.
Shared memory only makes sense when using KVM. In fact, we should actively disable the shared memory device when not using KVM.
Regards,
Anthony Liguori
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 6 lines · Anthony Liguori
Quoted 1 line
Ah yes. For cross tcg environments you can map the memory using mmio callbacks instead of directly, and issue the appropriate barriers there.
Not good enough unless you want to severely restrict the use of shared memory within the guest.
For instance, it's going to be useful to assume that you atomic instructions remain atomic. Crossing architecture boundaries here makes these assumptions invalid. A barrier is not enough.
You could make the mmio callbacks flow to the shared memory server over the unix-domain socket, which would then serialize them. Still need to keep RMWs as single operations. When the host supports it, implement the operation locally (you can't render cmpxchg16b on i386, for example).
Quoted 1 line
Shared memory only makes sense when using KVM. In fact, we should actively disable the shared memory device when not using KVM.
Looks like that's the only practical choice.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 9 lines · Avi Kivity
Quoted 6 lines · Anthony Liguori
Quoted 1 line
Ah yes. For cross tcg environments you can map the memory using mmio callbacks instead of directly, and issue the appropriate barriers there.
Not good enough unless you want to severely restrict the use of shared memory within the guest.
For instance, it's going to be useful to assume that you atomic instructions remain atomic. Crossing architecture boundaries here makes these assumptions invalid. A barrier is not enough.
You could make the mmio callbacks flow to the shared memory server over the unix-domain socket, which would then serialize them. Still need to keep RMWs as single operations. When the host supports it, implement the operation locally (you can't render cmpxchg16b on i386, for example).
But now you have a requirement that the shmem server runs in lock-step with the guest VCPU which has to happen for every single word of data transferred.
You're much better off using a bulk-data transfer API that relaxes coherency requirements. IOW, shared memory doesn't make sense for TCG :-)
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 5 lines · Anthony Liguori
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Anthony Liguori
Quoted 1 line
Ah yes. For cross tcg environments you can map the memory using mmio callbacks instead of directly, and issue the appropriate barriers there.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Not good enough unless you want to severely restrict the use of shared memory within the guest.
For instance, it's going to be useful to assume that you atomic instructions remain atomic. Crossing architecture boundaries here makes these assumptions invalid. A barrier is not enough.
You could make the mmio callbacks flow to the shared memory server over the unix-domain socket, which would then serialize them. Still need to keep RMWs as single operations. When the host supports it, implement the operation locally (you can't render cmpxchg16b on i386, for example).
But now you have a requirement that the shmem server runs in lock-step with the guest VCPU which has to happen for every single word of data transferred.
Alternative implementation: expose a futex in a shared memory object and use that to serialize access. Now all accesses happen from vcpu context, and as long as there is no contention, should be fast, at least relative to tcg.
Quoted 1 line
You're much better off using a bulk-data transfer API that relaxes coherency requirements. IOW, shared memory doesn't make sense for TCG :-)
Rather, tcg doesn't make sense for shared memory smp. But we knew that already.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 5 lines
Quoted 2 lines
You're much better off using a bulk-data transfer API that relaxes coherency requirements. IOW, shared memory doesn't make sense for TCG
Rather, tcg doesn't make sense for shared memory smp. But we knew that already.
In think TCG SMP is a hard, but soluble problem, especially when you're running guests used to coping with NUMA.
TCG interacting with third parties via shared memory is probably never going to make sense.
Paul
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 9 lines · Paul Brook
Quoted 6 lines
Quoted 3 lines
You're much better off using a bulk-data transfer API that relaxes coherency requirements. IOW, shared memory doesn't make sense for TCG
Rather, tcg doesn't make sense for shared memory smp. But we knew that already.
In think TCG SMP is a hard, but soluble problem, especially when you're running guests used to coping with NUMA.
Do you mean by using a per-cpu tlb? These kind of solutions are generally slow, but tcg's slowness may mask this out.
Quoted 3 lines
TCG interacting with third parties via shared memory is probably never going to make sense.
The third party in this case is qemu.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 12 lines · Paul Brook
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
You're much better off using a bulk-data transfer API that relaxes coherency requirements. IOW, shared memory doesn't make sense for TCG
Rather, tcg doesn't make sense for shared memory smp. But we knew that already.
In think TCG SMP is a hard, but soluble problem, especially when you're running guests used to coping with NUMA.
Do you mean by using a per-cpu tlb? These kind of solutions are generally slow, but tcg's slowness may mask this out.
Yes.
Quoted 4 lines
Quoted 2 lines
TCG interacting with third parties via shared memory is probably never going to make sense.
The third party in this case is qemu.
Maybe. But it's a different instance of qemu, and once this feature exists I bet people will use it for other things.
Paul
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
In reply to Paul BrookQuoted 12 lines · Paul Brook
Quoted 12 lines · Paul Brook
Quoted 10 lines
Quoted 4 lines
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.
No. All new devices should be fully qdev based.
I suspect you've also ignored a load of coherency issues, especially when not using KVM. As soon as you have shared memory in more than one host thread/process you have to worry about memory barriers.
Quoted 6 lines
Quoted 2 lines
Shouldn't it be sufficient to require the guest to issue barriers (and to ensure tcg honours the barriers, if someone wants this with tcg)?.
In a cross environment that becomes extremely hairy. For example the x86 architecture effectively has an implicit write barrier before every store, and an implicit read barrier before every load.
Btw, x86 doesn't have any implicit barriers due to ordinary loads. Only stores and atomics have implicit barriers, afaik.
-- Jamie
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 6 lines
Quoted 3 lines
In a cross environment that becomes extremely hairy. For example the x86 architecture effectively has an implicit write barrier before every store, and an implicit read barrier before every load.
Btw, x86 doesn't have any implicit barriers due to ordinary loads. Only stores and atomics have implicit barriers, afaik.
As of March 2009[1] Intel guarantees that memory reads occur in order (they may only be reordered relative to writes). It appears AMD do not provide this guarantee, which could be an interesting problem for heterogeneous migration..
Paul
[*] The most recent docs I have handy. Up to and including Core-2 Duo.
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 7 lines · Paul Brook
Quoted 6 lines
Quoted 3 lines
In a cross environment that becomes extremely hairy. For example the x86 architecture effectively has an implicit write barrier before every store, and an implicit read barrier before every load.
Btw, x86 doesn't have any implicit barriers due to ordinary loads. Only stores and atomics have implicit barriers, afaik.
Quoted 8 lines
As of March 2009[1] Intel guarantees that memory reads occur in order (they may only be reordered relative to writes). It appears AMD do not provide this guarantee, which could be an interesting problem for heterogeneous migration..
Paul
[*] The most recent docs I have handy. Up to and including Core-2 Duo.
Interesting, but what ordering would cause problems that AMD would do but Intel wouldn't? Wouldn't that ordering cause the same problems for POSIX shared memory in general (regardless of Qemu) on AMD?
I think shared memory breaks migration anyway.
Cam
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 13 lines · Cam Macdonell
Quoted 11 lines · Paul Brook
Quoted 7 lines
Quoted 4 lines
In a cross environment that becomes extremely hairy. For example the x86 architecture effectively has an implicit write barrier before every store, and an implicit read barrier before every load.
Btw, x86 doesn't have any implicit barriers due to ordinary loads. Only stores and atomics have implicit barriers, afaik.
As of March 2009[1] Intel guarantees that memory reads occur in order (they may only be reordered relative to writes). It appears AMD do not provide this guarantee, which could be an interesting problem for heterogeneous migration..
Quoted 9 lines
Quoted 5 lines
Paul
[*] The most recent docs I have handy. Up to and including Core-2 Duo.
Interesting, but what ordering would cause problems that AMD would do but Intel wouldn't? Wouldn't that ordering cause the same problems for POSIX shared memory in general (regardless of Qemu) on AMD?
If some code was written for the Intel guarantees it would break if migrated to AMD. Of course, it would also break if run on AMD in the first place.
Quoted 2 lines
I think shared memory breaks migration anyway.
Until someone implements distributed shared memory.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
As of March 2009[1] Intel guarantees that memory reads occur in order (they may only be reordered relative to writes). It appears AMD do not provide this guarantee, which could be an interesting problem for heterogeneous migration..
Quoted 7 lines
Quoted 3 lines
Interesting, but what ordering would cause problems that AMD would do but Intel wouldn't? Wouldn't that ordering cause the same problems for POSIX shared memory in general (regardless of Qemu) on AMD?
If some code was written for the Intel guarantees it would break if migrated to AMD. Of course, it would also break if run on AMD in the first place.
Right. This is independent of shared memory, and is a case where reporting an Intel CPUID on and AMD host might get you into trouble.
Paul
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
In reply to Paul BrookQuoted 11 lines · Paul Brook
Quoted 6 lines
Quoted 3 lines
In a cross environment that becomes extremely hairy. For example the x86 architecture effectively has an implicit write barrier before every store, and an implicit read barrier before every load.
Btw, x86 doesn't have any implicit barriers due to ordinary loads. Only stores and atomics have implicit barriers, afaik.
As of March 2009[1] Intel guarantees that memory reads occur in order (they may only be reordered relative to writes). It appears AMD do not provide this guarantee, which could be an interesting problem for heterogeneous migration..
(Summary: At least on AMD64, it does too, for normal accesses to naturally aligned addresses in write-back cacheable memory.)
Oh, that's interesting. Way back when I guess we knew writes were in order and it wasn't explicit that reads were, hence smp_rmb() using a locked atomic.
Here is a post by Nick Piggin from 2007 with links to Intel _and_ AMD documents asserting that reads to cacheable memory are in program order:
http://lkml.org/lkml/2007/9/28/212
Subject: [patch] x86: improved memory barrier implementation
Links to documents:
http://developer.intel.com/products/processor/manuals/318147.pdf http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24593.pdf
The Intel link doesn't work any more, but the AMD one does.
Nick asserts "both manufacturers are committed to in-order loads from cacheable memory for the x86 architecture".
I have just read the AMD document, and it is in there (but not completely obviously), in section 7.2. The implicit load-load and store-store barriers are only guaranteed for "normal cacheable accesses on naturally aligned boundaries to WB [write-back cacheable] memory". There are also implicit load-store barriers but not store-load.
Note that the document covers AMD64; it does not say anything about their (now old) 32-bit processors.
Quoted 1 line
[*] The most recent docs I have handy. Up to and including Core-2 Duo.
Are you sure the read ordering applies to 32-bit Intel and AMD CPUs too?
Many years ago, before 64-bit x86 existed, I recall discussions on LKML where it was made clear that stores were performed in program order. If it were known at the time that loads were performed in program order on 32-bit x86s, I would have expected that to have been mentioned by someone.
-- Jamie
Re: [Qemu-devel] [PATCH] Inter-VM shared memory PCI device
Quoted 26 lines · Jamie Lokier
Quoted 11 lines · Paul Brook
Quoted 6 lines
Quoted 3 lines
In a cross environment that becomes extremely hairy. For example the x86 architecture effectively has an implicit write barrier before every store, and an implicit read barrier before every load.
Btw, x86 doesn't have any implicit barriers due to ordinary loads. Only stores and atomics have implicit barriers, afaik.
As of March 2009[1] Intel guarantees that memory reads occur in order (they may only be reordered relative to writes). It appears AMD do not provide this guarantee, which could be an interesting problem for heterogeneous migration..
(Summary: At least on AMD64, it does too, for normal accesses to naturally aligned addresses in write-back cacheable memory.)
Oh, that's interesting. Way back when I guess we knew writes were in order and it wasn't explicit that reads were, hence
smp_rmb()using a locked atomic.Here is a post by Nick Piggin from 2007 with links to Intel _and_ AMD documents asserting that reads to cacheable memory are in program order:
http://lkml.org/lkml/2007/9/28/212
Subject: [patch] x86: improved memory barrier implementation
Quoted 6 lines
Links to documents:
http://developer.intel.com/products/processor/manuals/318147.pdf http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24593.pdfThe Intel link doesn't work any more, but the AMD one does.
It might have been merged into their development manual now.
Quoted 2 lines
Nick asserts "both manufacturers are committed to in-order loads from cacheable memory for the x86 architecture".
At the time we did ask Intel and AMD engineers. We talked with Andy Glew from Intel I believe, but I can't recall the AMD contact. Linus was involved in the discussions as well. We tried to do the right thing with this.
Quoted 9 lines
I have just read the AMD document, and it is in there (but not completely obviously), in section 7.2. The implicit load-load and store-store barriers are only guaranteed for "normal cacheable accesses on naturally aligned boundaries to WB [write-back cacheable] memory". There are also implicit load-store barriers but not store-load.
Note that the document covers AMD64; it does not say anything about their (now old) 32-bit processors.
Hmm. Well it couldn't hurt to ask again. We've never seen any problems yet, so I'm rather sure we're in the clear.
Quoted 10 lines
Quoted 2 lines
[*] The most recent docs I have handy. Up to and including Core-2 Duo.
Are you sure the read ordering applies to 32-bit Intel and AMD CPUs too?
Many years ago, before 64-bit x86 existed, I recall discussions on LKML where it was made clear that stores were performed in program order. If it were known at the time that loads were performed in program order on 32-bit x86s, I would have expected that to have been mentioned by someone.
The way it was explained to us by the Intel engineer is that they had implemented only visibly in-order loads, but they wanted to keep their options open in future so they did not want to commit to in order loads as an ISA feature.
So when the whitepaper was released we got their blessing to retroactively apply the rules to previous CPUs.
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 27 lines · Nick Piggin
Quoted 26 lines · Jamie Lokier
Quoted 11 lines · Paul Brook
Quoted 6 lines
Quoted 3 lines
In a cross environment that becomes extremely hairy. For example the x86 architecture effectively has an implicit write barrier before every store, and an implicit read barrier before every load.
Btw, x86 doesn't have any implicit barriers due to ordinary loads. Only stores and atomics have implicit barriers, afaik.
As of March 2009[1] Intel guarantees that memory reads occur in order (they may only be reordered relative to writes). It appears AMD do not provide this guarantee, which could be an interesting problem for heterogeneous migration..
(Summary: At least on AMD64, it does too, for normal accesses to naturally aligned addresses in write-back cacheable memory.)
Oh, that's interesting. Way back when I guess we knew writes were in order and it wasn't explicit that reads were, hence
smp_rmb()using a locked atomic.Here is a post by Nick Piggin from 2007 with links to Intel _and_ AMD documents asserting that reads to cacheable memory are in program order:
http://lkml.org/lkml/2007/9/28/212
Subject: [patch] x86: improved memory barrier implementation
Quoted 8 lines
Quoted 6 lines
Links to documents:
http://developer.intel.com/products/processor/manuals/318147.pdf http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24593.pdfThe Intel link doesn't work any more, but the AMD one does.
It might have been merged into their development manual now.
It was (http://www.intel.com/products/processor/manuals/):
Intel╝ 64 Architecture Memory Ordering White Paper
This document has been merged into Volume 3A of Intel 64 and IA-32 Architectures Software Developer's Manual.
[..snip..]
Signature · 1 line
mailto:[email protected]
Re: [PATCH] Inter-VM shared memory PCI device
In reply to Cam MacdonellQuoted 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.
This device now creates a qemu character device and sends 1-bytes messages to trigger interrupts. Writes are trigger by writing to the "Doorbell" register on the shared memory PCI device. The lower 8-bits of the value written to this register are sent as the 1-byte message so different meanings of interrupts can be supported.
Quoted 10 lines
Interrupts are supported between multiple VMs by using a shared memory server
-ivshmem<size in MB>,[unix:<path>][file]
Interrupts can also be used between host and guest as well by implementing a listener on the host that talks to shared memory server. The shared memory server passes file descriptors for the shared memory object and eventfds (our interrupt mechanism) to the respective qemu instances.
Can you provide a spec that describes the device? This would be useful for maintaining the code, writing guest drivers, and as a framework for review.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 33 lines · Avi Kivity
Quoted 22 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.This device now creates a qemu character device and sends 1-bytes messages to
trigger interrupts. Writes are trigger by writing to the "Doorbell" register
on the shared memory PCI device. The lower 8-bits of the value written to this
register are sent as the 1-byte message so different meanings of interrupts can
be supported.Interrupts are supported between multiple VMs by using a shared memory server
-ivshmem<size in MB>,[unix:<path>][file]
Quoted 9 lines
Interrupts can also be used between host and guest as well by implementing a
listener on the host that talks to shared memory server. The shared memory
server passes file descriptors for the shared memory object and eventfds (our
interrupt mechanism) to the respective qemu instances.
Quoted 2 lines
Can you provide a spec that describes the device? This 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.
Device Specification for Inter-VM shared memory device
-----------------------------------------------------------------------------------
Qemu Command-line
-------------------------------
The command-line for inter-vm shared memory is as follows
-ivshmem <size>,[unix:]name
the <size> argument specifies the size of the shared memory object. The second option specifies either a unix domain socket (when using the unix: prefix) or a name for the shared memory object.
If a unix domain socket is specified, the guest will receive the shared object from the shared memory server listening on that socket and will support interrupts with the other guests using that server. Each server only serves one memory object.
If a name is specified on the command line (without 'unix:'), then the guest will open the POSIX shared memory object with that name (in /dev/shm) and the specified size. The guest will NOT support interrupts but the shared memory object can be shared between multiple guests.
The Inter-VM Shared Memory PCI device
-----------------------------------------------------------
BARs
The device supports two BARs. BAR0 is a 256-byte MMIO region to support registers
and BAR1 is used to map the shared memory object from the host. The size of BAR1 is specified on the command-line and must be a power of 2 in size.
Registers
BAR0 currently supports 5 registers of 16-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).
When using interrupts, VMs communicate with a shared memory server that passes the shared memory object file descriptor using SCM_RIGHTS. The server assigns each VM an ID number and sends this ID number to the Qemu process along with a series of eventfd file descriptors, one per guest using the shared memory server. These eventfds will be used to send interrupts between guests. Each guest listens on the eventfd corresponding to their ID and may use the others for sending interrupts to other guests.
enum ivshmem_registers {
IntrMask = 0,
IntrStatus = 2,
Doorbell = 4,
IVPosition = 6,
IVLiveList = 8
};
The first two registers are the interrupt mask and status registers. Interrupts are triggered when a message is received on the guest's eventfd from another VM. Writing to the 'Doorbell' register is how synchronization messages are sent to other VMs.
The IVPosition register is read-only and reports the guest's ID number. The IVLiveList register is also read-only and reports a bit vector of currently live VM IDs.
The Doorbell register is 16-bits, but is treated as two 8-bit values. The upper 8-bits are used for the destination VM ID. The 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 destination guest. A value of 255 in the upper 8-bits will trigger a broadcast where the message will be sent to all other guests.
Cheers,
Cam
Quoted 5 lines
--
error compilingcommittee.c: too many arguments to function
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 7 lines · Cam Macdonell
Quoted 4 lines
Can you provide a spec that describes the device? This 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 syntax is less important. It 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.
Quoted 8 lines
The Inter-VM Shared Memory PCI device
-----------------------------------------------------------BARs
The device supports two BARs. BAR0 is a 256-byte MMIO region to support registers
(but might be extended in the future)
Quoted 6 lines
and BAR1 is used to map the shared memory object from the host. The size of BAR1 is specified on the command-line and must be a power of 2 in size.
Registers
BAR0 currently supports 5 registers of 16-bits each.
Suggest making registers 32-bits, friendlier towards non-x86.
Quoted 4 lines
Registers are used
for synchronization between guests sharing the same memory object when interrupts are supported (this requires using the shared memory server).
How does the driver detect whether interrupts are supported or not?
Quoted 16 lines
When using interrupts, VMs communicate with a shared memory server that passes the shared memory object file descriptor using
SCM_RIGHTS. The server assigns each VM an ID number and sends this ID number to the Qemu process along with a series of eventfd file descriptors, one per guest using the shared memory server. These eventfds will be used to send interrupts between guests. Each guest listens on the eventfd corresponding to their ID and may use the others for sending interrupts to other guests.enum
ivshmem_registers{
IntrMask = 0,
IntrStatus = 2,
Doorbell = 4,
IVPosition = 6,
IVLiveList = 8
};
Quoted 9 lines
The first two registers are the interrupt mask and status registers. Interrupts are triggered when a message is received on the guest's eventfd from another VM. Writing to the 'Doorbell' register is how synchronization messages are sent to other VMs.
The IVPosition register is read-only and reports the guest's ID number. The IVLiveList register is also read-only and reports a bit vector of currently live VM IDs.
That limits the number of guests to 16.
Quoted 5 lines
The Doorbell register is 16-bits, but is treated as two 8-bit values. The upper 8-bits are used for the destination VM ID. The 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 destination guest.
What happens when two interrupts are sent back-to-back to the same guest? Will the first status value be lost?
Also, reading the status register requires a vmexit. I suggest dropping it and requiring the application to manage this information in the shared memory area (where it could do proper queueing of multiple messages).
Quoted 3 lines
A value of 255 in the upper 8-bits will trigger a broadcast where the message will be sent to all other guests.
Please consider adding:
- MSI support
- interrupt on a guest attaching/detaching to the shared memory device
With MSI you could also have the doorbell specify both guest ID and vector number, which may be useful.
Thanks for this - it definitely makes reviewing easier.
Signature · 1 line
error compiling committee.c: too many arguments to function
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 Inter-VM shared memory PCI device
Quoted 37 lines · Avi Kivity
Quoted 10 lines · Cam Macdonell
Quoted 6 lines
Can you provide a spec that describes the device? This 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 syntax is less important. It 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.
Quoted 8 lines
The Inter-VM Shared Memory PCI device
-----------------------------------------------------------BARs
The device supports two BARs. BAR0 is a 256-byte MMIO region to support registers
(but might be extended in the future)
Quoted 7 lines
and BAR1 is used to map the shared memory object from the host. The size of
BAR1 is specified on the command-line and must be a power of 2 in size.Registers
BAR0 currently supports 5 registers of 16-bits each.
Quoted 8 lines
Suggest making registers 32-bits, friendlier towards non-x86.
Quoted 4 lines
Registers are used
for synchronization between guests sharing the same memory object when interrupts are supported (this requires using the shared memory server).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. With UIO is there a way to detect if the interrupt pin is on?
Quoted 29 lines
Quoted 29 lines
When using interrupts, VMs communicate with a shared memory server that passes
the shared memory object file descriptor usingSCM_RIGHTS. The server assigns
each VM an ID number and sends this ID number to the Qemu process along with a
series of eventfd file descriptors, one per guest using the shared memory server. These eventfds will be used to send interrupts between guests. Each
guest listens on the eventfd corresponding to their ID and may use the others
for sending interrupts to other guests.enum
ivshmem_registers{
IntrMask = 0,
IntrStatus = 2,
Doorbell = 4,
IVPosition = 6,
IVLiveList = 8
};The first two registers are the interrupt mask and status registers. Interrupts are triggered when a message is received on the guest's eventfd from
another VM. Writing to the 'Doorbell' register is how synchronization messages
are sent to other VMs.
Quoted 8 lines
Quoted 6 lines
The IVPosition register is read-only and reports the guest's ID number. The
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. We 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..
Quoted 11 lines
Quoted 8 lines
The Doorbell register is 16-bits, but is treated as two 8-bit values. The upper 8-bits are used for the destination VM ID. The 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 destination guest.What happens when two interrupts are sent back-to-back to the same guest? Will the first status value be lost?
Right now, it would be. I believe that eventfd has a counting semaphore option, that could prevent loss of status (but limits what the status could be). My understanding of uio_pci interrupt handling is fairly new, but we could have the uio driver store the interrupt statuses to avoid losing them.
Quoted 5 lines
Also, reading the status register requires a vmexit. I suggest dropping it and requiring the application to manage this information in the shared memory area (where it could do proper queueing of multiple messages).
Quoted 8 lines
Quoted 4 lines
A value of 255 in the upper 8-bits will trigger a broadcast where the message
will be sent to all other guests.Please consider adding:
- MSI support
Sure, I'll look into it.
Quoted 1 line
- interrupt on a guest attaching/detaching to the shared memory device
Sure.
Quoted 5 lines
With MSI you could also have the doorbell specify both guest ID and vector number, which may be useful.
Thanks for this - it definitely makes reviewing easier.
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 7 lines · Cam Macdonell
Quoted 7 lines
Quoted 7 lines
Registers are used
for synchronization between guests sharing the same memory object when interrupts are supported (this requires using the shared memory server).
Quoted 6 lines
Quoted 2 lines
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. With UIO is there a way to detect if the interrupt pin is on?
I suggest not designing the device to uio. Make it a good guest-independent device, and if uio doesn't fit it, change it.
Why not support interrupts unconditionally? Is the device useful without interrupts?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
The Doorbell register is 16-bits, but is treated as two 8-bit values. The upper 8-bits are used for the destination VM ID. The 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 destination guest.
Quoted 7 lines
Quoted 3 lines
What happens when two interrupts are sent back-to-back to the same guest?
Will the first status value be lost?Right now, it would be. I believe that eventfd has a counting semaphore option, that could prevent loss of status (but limits what the status could be).
It only counts the number of interrupts (and kvm will coalesce them anyway).
Quoted 4 lines
My understanding of
uio_pciinterrupt handling
is fairly new, but we could have the uio driver store the interrupt statuses to avoid losing them.
There's nowhere to store them if we use ioeventfd/irqfd. I think it's both easier and more efficient to leave this to the application (to store into shared memory).
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Cam Macdonell
Quoted 6 lines
Quoted 6 lines
Registers are used
for synchronization between guests sharing the same memory object when interrupts are supported (this requires using the shared memory server).
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
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. With UIO is there a way to detect if the interrupt pin is on?
I suggest not designing the device to uio. Make it a good guest-independent device, and if uio doesn't fit it, change it.
You can always fall back to reading the config space directly. It's not strictly required that you stick to the UIO interface.
Quoted 1 line
Why not support interrupts unconditionally? Is the device useful without interrupts?
You can always just have interrupts enabled and not use them if that's desired.
Regards,
Anthony Liguori
Re: [PATCH] Inter-VM shared memory PCI device
In reply to Avi KivityQuoted 17 lines · Avi Kivity
Quoted 8 lines · Cam Macdonell
Quoted 8 lines
Quoted 7 lines
Registers are used
for synchronization between guests sharing the same memory object when interrupts are supported (this requires using the shared memory server).Quoted 7 lines
Quoted 2 lines
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. With UIO is there a way to detect if the interrupt pin is on?
Quoted 5 lines
I suggest not designing the device to uio. Make it a good guest-independent device, and if uio doesn't fit it, change it.
Why not support interrupts unconditionally? Is the device useful without interrupts?
Currently my patch works with or without the shared memory server. If you give the parameter
-ivshmem 256,foo
then this will create (if necessary) and map /dev/shm/foo as the shared region without interrupt support. Some users of shared memory are using it this way.
Going forward we can require the shared memory server and always have interrupts enabled.
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 11 lines
The Doorbell register is 16-bits, but is treated as two 8-bit values. The
upper 8-bits are used for the destination VM ID. The 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 destination guest.What happens when two interrupts are sent back-to-back to the same guest? Will the first status value be lost?
Quoted 6 lines
Quoted 4 lines
Right now, it would be. I believe that eventfd has a counting semaphore option, that could prevent loss of status (but limits what the status could be).
It only counts the number of interrupts (and kvm will coalesce them anyway).
Right.
Quoted 9 lines
Quoted 5 lines
My understanding of
uio_pciinterrupt handling
is fairly new, but we could have the uio driver store the interrupt statuses to avoid losing them.There's nowhere to store them if we use ioeventfd/irqfd. I think it's both easier and more efficient to leave this to the application (to store into shared memory).
Agreed.
Cam
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 29 lines · Cam Macdonell
Quoted 18 lines · Avi Kivity
Quoted 8 lines · Cam Macdonell
Quoted 8 lines
Quoted 8 lines
Registers are used
for synchronization between guests sharing the same memory object when interrupts are supported (this requires using the shared memory server).Quoted 8 lines
Quoted 3 lines
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. With UIO is there a way to detect if the interrupt pin is on?
Quoted 6 lines
I suggest not designing the device to uio. Make it a good guest-independent device, and if uio doesn't fit it, change it.
Why not support interrupts unconditionally? Is the device useful without interrupts?
Currently my patch works with or without the shared memory server. If you give the parameter
Quoted 9 lines
-ivshmem 256,foo
then this will create (if necessary) and map
/dev/shm/fooas the shared region without interrupt support. Some users of shared memory are using it this way.Going forward we can require the shared memory server and always have interrupts enabled.
Can you explain how they synchronize? Polling? Using the network? Using it as a shared cache?
If it's a reasonable use case it makes sense to keep it.
Another thing comes to mind - a shared memory ID, in case a guest has multiple cards.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 47 lines · Avi Kivity
Quoted 46 lines · Cam Macdonell
Quoted 26 lines · Avi Kivity
Quoted 13 lines · Cam Macdonell
Quoted 13 lines
Quoted 12 lines
Registers are used
for synchronization between guests sharing the same memory object when interrupts are supported (this requires using the shared memory server).Quoted 9 lines
Quoted 3 lines
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. With UIO is there a way to detect if the interrupt pin is on?
Quoted 7 lines
I suggest not designing the device to uio. Make it a good guest-independent
device, and if uio doesn't fit it, change it.Why not support interrupts unconditionally? Is the device useful without interrupts?
Currently my patch works with or without the shared memory server. If you give the parameter
-ivshmem 256,foo
then this will create (if necessary) and map
/dev/shm/fooas the shared region without interrupt support. Some users of shared memory are using it this way.
Quoted 9 lines
Quoted 3 lines
Going forward we can require the shared memory server and always have interrupts enabled.
Can you explain how they synchronize? Polling? Using the network? Using it as a shared cache?
If it's a reasonable use case it makes sense to keep it.
Do you mean how they synchronize without interrupts? One project I've been contacted about uses the shared region directly for synchronization for simulations running in different VMs that share data in the memory region. In my tests spinlocks in the shared region work between guests.
If we want to keep the serverless implementation, do we need to support shm_open with -chardev somehow? Something like -chardev shm,name=foo. Right now my qdev implementation just passes the name to the -device option and opens it.
Quoted 2 lines
Another thing comes to mind - a shared memory ID, in case a guest has multiple cards.
Sure, a number that can be passed on the command-line and stored in a register?
Cam
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 56 lines · Cam Macdonell
Quoted 54 lines · Avi Kivity
Quoted 39 lines · Cam Macdonell
Quoted 25 lines · Avi Kivity
Quoted 12 lines · Cam Macdonell
Quoted 12 lines
Quoted 12 lines
Registers are used
for synchronization between guests sharing the same memory object when interrupts are supported (this requires using the shared memory server).Quoted 10 lines
Quoted 4 lines
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. With UIO is there a way to detect if the interrupt pin is on?
Quoted 8 lines
I suggest not designing the device to uio. Make it a good guest-independent
device, and if uio doesn't fit it, change it.Why not support interrupts unconditionally? Is the device useful without interrupts?
Currently my patch works with or without the shared memory server. If you give the parameter
Quoted 10 lines
-ivshmem 256,foo
then this will create (if necessary) and map
/dev/shm/fooas the shared region without interrupt support. Some users of shared memory are using it this way.Going forward we can require the shared memory server and always have interrupts enabled.
Can you explain how they synchronize? Polling? Using the network? Using it as a shared cache?
Quoted 9 lines
Quoted 3 lines
If it's a reasonable use case it makes sense to keep it.
Do you mean how they synchronize without interrupts? One project I've been contacted about uses the shared region directly for synchronization for simulations running in different VMs that share data in the memory region. In my tests spinlocks in the shared region work between guests.
I see.
Quoted 5 lines
If we want to keep the serverless implementation, do we need to support
shm_openwith -chardev somehow? Something like -chardev shm,name=foo. Right now my qdev implementation just passes the name to the -device option and opens it.
I think using the file name is fine.
Quoted 5 lines
Quoted 3 lines
Another thing comes to mind - a shared memory ID, in case a guest has multiple cards.
Sure, a number that can be passed on the command-line and stored in a register?
Yes. NICs use the MAC address and storage uses the disk serial number, this is the same thing for shared memory.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH] Inter-VM shared memory PCI device
In reply to Cam MacdonellQuoted 17 lines · Cam Macdonell
enum
ivshmem_registers{
IntrMask = 0,
IntrStatus = 2,
Doorbell = 4,
IVPosition = 6,
IVLiveList = 8
};The first two registers are the interrupt mask and status registers. Interrupts are triggered when a message is received on the guest's eventfd from another VM. Writing to the 'Doorbell' register is how synchronization messages are sent to other VMs.
The IVPosition register is read-only and reports the guest's ID number. The IVLiveList register is also read-only and reports a bit vector of currently live VM IDs.
Quoted 6 lines
The Doorbell register is 16-bits, but is treated as two 8-bit values. The upper 8-bits are used for the destination VM ID. The 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 destination guest. A value of 255 in the upper 8-bits will trigger a broadcast where the message will be sent to all other guests.
This means you have at least two intercepts for each message:
1. Sender writes to doorbell
2. Receiver gets interrupted
With optionally two more intercepts in order to avoid interrupting the receiver every time:
3. Receiver masks interrupt in order to process data
4. Receiver unmasks interrupt when it's done and status is no longer pending
I believe you can do much better than this, you combine status and mask bits, making this level triggered, and move to a bitmask of all guests:
In order to send an interrupt to another guest, the sender first checks the bit for the receiver. If it's '1', no need for any intercept, the receiver will come back anyway. If it's zero, write a '1' bit, which gets OR'd into the bitmask by the host. The receiver gets interrupted at a raising edge and just leaves the bit on, until it's done processing, then turns the bit off by writing a '1' into its own location in the mask.
Arnd
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 40 lines · Arnd Bergmann
Quoted 17 lines · Cam Macdonell
enum
ivshmem_registers{
IntrMask = 0,
IntrStatus = 2,
Doorbell = 4,
IVPosition = 6,
IVLiveList = 8
};The first two registers are the interrupt mask and status registers. Interrupts are triggered when a message is received on the guest's eventfd from another VM. Writing to the 'Doorbell' register is how synchronization messages are sent to other VMs.
The IVPosition register is read-only and reports the guest's ID number. The IVLiveList register is also read-only and reports a bit vector of currently live VM IDs.
Quoted 7 lines
The Doorbell register is 16-bits, but is treated as two 8-bit values. The upper 8-bits are used for the destination VM ID. The 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 destination guest. A value of 255 in the upper 8-bits will trigger a broadcast where the message will be sent to all other guests.
This means you have at least two intercepts for each message:
1. Sender writes to doorbell
2. Receiver gets interruptedWith optionally two more intercepts in order to avoid interrupting the receiver every time:
3. Receiver masks interrupt in order to process data
4. Receiver unmasks interrupt when it's done and status is no longer pendingI believe you can do much better than this, you combine status and mask bits, making this level triggered, and move to a bitmask of all guests:
Quoted 7 lines
In order to send an interrupt to another guest, the sender first checks the bit for the receiver. If it's '1', no need for any intercept, the receiver will come back anyway. If it's zero, write a '1' bit, which gets OR'd into the bitmask by the host. The receiver gets interrupted at a raising edge and just leaves the bit on, until it's done processing, then turns the bit off by writing a '1' into its own location in the mask.
We could make the masking in RAM, not in registers, like virtio, which would require no exits. It would then be part of the application specific protocol and out of scope of of this spec.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 62 lines · Avi Kivity
Quoted 53 lines · Arnd Bergmann
Quoted 22 lines · Cam Macdonell
enum
ivshmem_registers{
IntrMask = 0,
IntrStatus = 2,
Doorbell = 4,
IVPosition = 6,
IVLiveList = 8
};The first two registers are the interrupt mask and status registers. Interrupts are triggered when a message is received on the guest's eventfd from
another VM. Writing to the 'Doorbell' register is how synchronization messages
are sent to other VMs.The IVPosition register is read-only and reports the guest's ID number. The
IVLiveList register is also read-only and reports a bit vector of currently
live VM IDs.Quoted 12 lines
The Doorbell register is 16-bits, but is treated as two 8-bit values. The
upper 8-bits are used for the destination VM ID. The 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 destination guest.
A value of 255 in the upper 8-bits will trigger a broadcast where the message
will be sent to all other guests.This means you have at least two intercepts for each message:
1. Sender writes to doorbell
2. Receiver gets interruptedWith optionally two more intercepts in order to avoid interrupting the receiver every time:
3. Receiver masks interrupt in order to process data
4. Receiver unmasks interrupt when it's done and status is no longer pendingI believe you can do much better than this, you combine status and mask bits, making this level triggered, and move to a bitmask of all guests:
Quoted 7 lines
In order to send an interrupt to another guest, the sender first checks the bit for the receiver. If it's '1', no need for any intercept, the receiver will come back anyway. If it's zero, write a '1' bit, which gets OR'd into the bitmask by the host. The receiver gets interrupted at a raising edge and just leaves the bit on, until it's done processing, then turns the bit off by writing a '1' into its own location in the mask.
Quoted 4 lines
We could make the masking in RAM, not in registers, like virtio, which would require no exits. It would then be part of the application specific protocol and out of scope of of this spec.
This kind of implementation would be possible now since with UIO it's up to the application whether to mask interrupts or not and what interrupts mean. We could leave the interrupt mask register for those who want that behaviour. Arnd's idea would remove the need for the Doorbell and Mask, but we will always need at least one MMIO register to send whatever interrupts we do send.
Cam
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 6 lines · Cam Macdonell
Quoted 5 lines
We could make the masking in RAM, not in registers, like virtio, which would require no exits. It would then be part of the application specific protocol and out of scope of of this spec.
Quoted 6 lines
This kind of implementation would be possible now since with UIO it's up to the application whether to mask interrupts or not and what interrupts mean. We could leave the interrupt mask register for those who want that behaviour. Arnd's idea would remove the need for the Doorbell and Mask, but we will always need at least one MMIO register to send whatever interrupts we do send.
You'd also have to be very careful if the notification is in RAM to avoid races between one guest triggering an interrupt and another guest clearing its interrupt mask.
A totally different option that avoids this whole problem would be to separate the signalling from the shared memory, making the PCI shared memory device a trivial device with a single memory BAR, and using something a higher-level concept like a virtio based serial line for the actual signalling.
Arnd
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 18 lines · Arnd Bergmann
Quoted 5 lines · Cam Macdonell
Quoted 5 lines
We could make the masking in RAM, not in registers, like virtio, which would require no exits. It would then be part of the application specific protocol and out of scope of of this spec.
Quoted 7 lines
This kind of implementation would be possible now since with UIO it's up to the application whether to mask interrupts or not and what interrupts mean. We could leave the interrupt mask register for those who want that behaviour. Arnd's idea would remove the need for the Doorbell and Mask, but we will always need at least one MMIO register to send whatever interrupts we do send.
You'd also have to be very careful if the notification is in RAM to avoid races between one guest triggering an interrupt and another guest clearing its interrupt mask.
Quoted 6 lines
A totally different option that avoids this whole problem would be to separate the signalling from the shared memory, making the PCI shared memory device a trivial device with a single memory BAR, and using something a higher-level concept like a virtio based serial line for the actual signalling.
That would be much slower. The current scheme allows for an ioeventfd/irqfd short circuit which allows one guest to interrupt another without involving their qemus at all.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 10 lines · Avi Kivity
Quoted 6 lines
A totally different option that avoids this whole problem would be to separate the signalling from the shared memory, making the PCI shared memory device a trivial device with a single memory BAR, and using something a higher-level concept like a virtio based serial line for the actual signalling.
That would be much slower. The current scheme allows for an ioeventfd/irqfd short circuit which allows one guest to interrupt another without involving their qemus at all.
Yes, the serial line approach would be much slower, but my point was that we can do signaling over "something else", which could well be something building on irqfd.
Arnd
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 9 lines · Arnd Bergmann
Quoted 7 lines · Avi Kivity
Quoted 7 lines
A totally different option that avoids this whole problem would be to separate the signalling from the shared memory, making the PCI shared memory device a trivial device with a single memory BAR, and using something a higher-level concept like a virtio based serial line for the actual signalling.
Quoted 8 lines
Quoted 4 lines
That would be much slower. The current scheme allows for an ioeventfd/irqfd short circuit which allows one guest to interrupt another without involving their qemus at all.
Yes, the serial line approach would be much slower, but my point was that we can do signaling over "something else", which could well be something building on irqfd.
Well, we could, but it seems to make things more complicated? A card with shared memory, and another card with an interrupt interconnect?
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH] Inter-VM shared memory PCI device
Quoted 10 lines · Avi Kivity
Quoted 7 lines
Quoted 4 lines
That would be much slower. The current scheme allows for an ioeventfd/irqfd short circuit which allows one guest to interrupt another without involving their qemus at all.
Yes, the serial line approach would be much slower, but my point was that we can do signaling over "something else", which could well be something building on irqfd.
Well, we could, but it seems to make things more complicated? A card with shared memory, and another card with an interrupt interconnect?
Yes, I agree that it's more complicated if you have a specific application in mind that needs one of each, and most use cases that want shared memory also need an interrupt mechanism, but it's not always the case:
- You could use ext2 with -o xip on a private mapping of a shared host file in order to share the page cache. This does not need any interrupts.
- If you have more than two parties sharing the segment, there are different ways to communicate, e.g. always send an interrupt to all others, or have dedicated point-to-point connections. There is also some complexity in trying to cover all possible cases in one driver.
I have to say that I also really like the idea of futex over shared memory, which could potentially make this all a lot simpler. I don't know how this would best be implemented on the host though.
Arnd
Quoted 6 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_add_file_to_ram(fd, size, MAP_SHARED);
A traditional name would be qemu_ram_mmap() as a counterpart to qemu_ram_alloc(). Would be nice to accept an offset.
Signature · 1 line
error compiling committee.c: too many arguments to function