Received: from eggs.gnu.org ([2001:4830:134:3::10]:54442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKBYl-0007jR-3q for qemu-devel@nongnu.org; Thu, 12 Sep 2013 14:24:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VKBYe-0005P2-Ui for qemu-devel@nongnu.org; Thu, 12 Sep 2013 14:24:07 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:63238) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKBYe-0005N6-Om for qemu-devel@nongnu.org; Thu, 12 Sep 2013 14:24:00 -0400 Received: by mail-wi0-f174.google.com with SMTP id hj3so3967905wib.13 for ; Thu, 12 Sep 2013 11:23:58 -0700 (PDT) From: Damien Millescamps Date: Thu, 12 Sep 2013 20:23:48 +0200 Message-Id: <1379010228-15324-1-git-send-email-damien.millescamps@6wind.com> Subject: [Qemu-devel] [PATCH] ivshmem: allow the sharing of hugepages List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org 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 --- 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