ivshmem: allow the sharing of hugepages
PATCH RESEND 1/1 ivshmem: allow the sharing of hugepages
This patch permits to share memory areas that do not specifically belong to /dev/shm. In such case, the file must be already present when launching qemu.
A use case for this patch is sharing huge pages available through a hugetlbfs mountpoint.
--- docs/specs/ivshmem_device_spec.txt | 5 +++-- hw/misc/ivshmem.c | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-)
docs/specs/ivshmem_device_spec.txt +3 -2
@@ -4,8 +4,9 @@ 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. +guest, but is a either a POSIX memory object or a mmap'd file (such as a +hugepage) on the host. Optionally, the device may support sending interrupts +to other guests sharing the same memory region. The Inter-VM PCI device
hw/misc/ivshmem.c +7 -3
@@ -762,9 +762,13 @@ static int pci_ivshmem_init(PCIDevice *dev) }else if ((fd =shm_open (s->shmobj,O_CREAT |O_RDWR ,S_IRWXU |S_IRWXG |S_IRWXO )) <0 ) { -fprintf (stderr,"ivshmem: could not open shared file\n" ); -exit (-1 ); - +/* Try with open() in case the file is not in /dev/shm/ +* This is usefull for sharing hugepages for example */ + fd =open (s->shmobj,O_RDWR ); +if (fd <0 ) { +fprintf (stderr,"ivshmem: could not open shared file\n" ); +exit (-1 ); + } }if (check_shm_size (s, fd) ==-1 ) {
Signature · 1 line
1.7.2.5
Quoted 36 lines · Damien Millescamps
This patch permits to share memory areas that do not specifically belong to
/dev/shm. In such case, the file must be already present when launching qemu.A use case for this patch is sharing huge pages available through a hugetlbfs mountpoint.
Signed-off-by Damien Millescamps <[email protected]>--- docs/specs/ivshmem_device_spec.txt | 5 +++-- hw/misc/ivshmem.c | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-)docs/specs/ivshmem_device_spec.txt +3
-2@@ -4,8 +4,9 @@ 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. +guest, but is a either a POSIX memory object or a mmap'd file (such as a +hugepage) on the host. Optionally, the device may support sending interrupts +to other guests sharing the same memory region. The Inter-VM PCI devicehw/misc/ivshmem.c +0
-0@@ -762,9 +762,13 @@ static int pci_ivshmem_init(PCIDevice *dev) }else if ((fd =shm_open (s->shmobj,O_CREAT |O_RDWR ,S_IRWXU |S_IRWXG |S_IRWXO )) <0 ) {
hw/misc/ivshmem.c static int pci_ivshmem_init(PCIDevice *dev) · line 771
Quoted 10 lines
hw/misc/ivshmem.c +7
-3-fprintf (stderr,"ivshmem: could not open shared file\n" ); -exit (-1 ); - +/* Try with open() in case the file is not in /dev/shm/ +* This is usefull for sharing hugepages for example */ + fd =open (s->shmobj,O_RDWR ); +if (fd <0 ) { +fprintf (stderr,"ivshmem: could not open shared file\n" ); +exit (-1 ); + }
IME this kind of auto-magical fallback behaviour is a bad idea. If we want to support non-SHM files for the ivshmem device, then it should be done with an explicit command line property. eg where we currently have a 'size' and 'shm' property on the cli:
-device ivshmem,size=24124324,shm=nameofshmobj
it could allow an alternative 'file' property to point to a pre-created filename
-device ivshmem,file=/some/file/path
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 11 lines · Daniel P. Berrange
IME this kind of auto-magical fallback behaviour is a bad idea. If we want to support non-SHM files for the ivshmem device, then it should be done with an explicit command line property. eg where we currently have a 'size' and 'shm' property on the cli:
-device ivshmem,size=24124324,shm=nameofshmobjit could allow an alternative 'file' property to point to a pre-created filename
-device ivshmem,file=/some/file/path
This patch was based on the fact that in the glibc, shm_open() is nothing more than an open() with /dev/shm/ prepended to the shared memory object name. Hence, only a small modification was needed to change this behavior.
Indeed, having different parameters to specify between a file and a POSIX shared memory object should be clearer for the user experience.
I have reworked the patch and will send it asap.
Thanks,
Signature · 1 line
Damien