qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] ivshmem: allow the sharing of hugepages
@ 2013-09-12 18:23 Damien Millescamps
  2013-09-14  9:36 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
  0 siblings, 1 reply; 3+ messages in thread
From: Damien Millescamps @ 2013-09-12 18:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial

According to shm_open specifications:

 A shared memory object should be identified by a name of the form /somename;
 that is, a null-terminated string of up to NAME_MAX (i.e., 255) characters
 consisting of an initial slash, followed by one or more characters, none of
 which are slashes.

This patch permits to share memory areas that do not specifically belong to
/dev/shmem.

A use case for this patch is sharing huge pages available through a
hugetlbfs mountpoint.

Signed-off-by: Damien Millescamps <damien.millescamps@6wind.com>
---
 hw/misc/ivshmem.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 2838866..9020bb2 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -751,9 +751,23 @@ static int pci_ivshmem_init(PCIDevice *dev)
 
         IVSHMEM_DPRINTF("using shm_open (shm object = %s)\n", s->shmobj);
 
+        /* 
+         * A shared memory object should be identified by a name of the form /somename; 
+         * that is, a null-terminated string of up to NAME_MAX (i.e., 255) characters 
+         * consisting of an initial slash, followed by one or more characters, none of 
+         * which are slashes.
+         */
+        if (s->shmobj && s->shmobj[0] == '/' && strstr(&s->shmobj[1], "/")) {
+            /* This can't be a shared memory object. */
+            fd = open(s->shmobj, O_RDWR);
+            if (fd < 0) {
+                perror("ivshmem - open");
+                exit(-1);
+            }
+        }
         /* try opening with O_EXCL and if it succeeds zero the memory
          * by truncating to 0 */
-        if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR|O_EXCL,
+        else if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR|O_EXCL,
                         S_IRWXU|S_IRWXG|S_IRWXO)) > 0) {
            /* truncate file to length PCI device's memory */
             if (ftruncate(fd, s->ivshmem_size) != 0) {
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-09-14 10:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-12 18:23 [Qemu-devel] [PATCH] ivshmem: allow the sharing of hugepages Damien Millescamps
2013-09-14  9:36 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2013-09-14 10:51   ` Damien Millescamps

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).