Received: from eggs.gnu.org ([2001:4830:134:3::10]:54162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLYLu-0001Rp-KS for qemu-devel@nongnu.org; Mon, 16 Sep 2013 08:56:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VLYLm-0003Gv-RI for qemu-devel@nongnu.org; Mon, 16 Sep 2013 08:56:30 -0400 Received: from mail-bk0-f52.google.com ([209.85.214.52]:40648) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLYLm-0003GQ-Jf for qemu-devel@nongnu.org; Mon, 16 Sep 2013 08:56:22 -0400 Received: by mail-bk0-f52.google.com with SMTP id e11so1459368bkh.39 for ; Mon, 16 Sep 2013 05:56:21 -0700 (PDT) From: Damien Millescamps Date: Mon, 16 Sep 2013 14:56:15 +0200 Message-Id: <1379336175-822-1-git-send-email-damien.millescamps@6wind.com> Subject: [Qemu-devel] [PATCH RESEND] 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 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 --- docs/specs/ivshmem_device_spec.txt | 5 +++-- hw/misc/ivshmem.c | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/specs/ivshmem_device_spec.txt b/docs/specs/ivshmem_device_spec.txt index 667a862..3137e60 100644 --- a/docs/specs/ivshmem_device_spec.txt +++ b/docs/specs/ivshmem_device_spec.txt @@ -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 diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 2838866..9178ccc 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -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) { -- 1.7.2.5