From patchwork Tue Oct 6 13:33:23 2015
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Pavel Fedin
X-Patchwork-Id: 526767
Return-Path:
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])
(using TLSv1 with cipher AES256-SHA (256/256 bits))
(No client certificate requested)
by ozlabs.org (Postfix) with ESMTPS id 62E33140082
for ;
Wed, 7 Oct 2015 00:34:34 +1100 (AEDT)
Received: from localhost ([::1]:51698 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.71) (envelope-from
)
id 1ZjSO0-0005Aq-7q
for incoming@patchwork.ozlabs.org; Tue, 06 Oct 2015 09:34:32 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49824)
by lists.gnu.org with esmtp (Exim 4.71)
(envelope-from ) id 1ZjSN6-0003rq-A6
for qemu-devel@nongnu.org; Tue, 06 Oct 2015 09:33:40 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
(envelope-from ) id 1ZjSN2-0004IJ-Rw
for qemu-devel@nongnu.org; Tue, 06 Oct 2015 09:33:36 -0400
Received: from mailout1.w1.samsung.com ([210.118.77.11]:21801)
by eggs.gnu.org with esmtp (Exim 4.71)
(envelope-from ) id 1ZjSN2-0004Hs-Jy
for qemu-devel@nongnu.org; Tue, 06 Oct 2015 09:33:32 -0400
Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245])
by mailout1.w1.samsung.com
(Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5
2014)) with ESMTP id <0NVS00JCHWBTK0C0@mailout1.w1.samsung.com> for
qemu-devel@nongnu.org; Tue, 06 Oct 2015 14:33:29 +0100 (BST)
X-AuditID: cbfec7f5-f794b6d000001495-c8-5613cda9ba1e
Received: from eusync3.samsung.com ( [203.254.199.213])
by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 8D.25.05269.9ADC3165;
Tue, 6 Oct 2015 14:33:29 +0100 (BST)
Received: from fedinw7x64 ([106.109.131.169])
by eusync3.samsung.com (Oracle Communications Messaging Server
7.0.5.31.0 64bit (built May 5 2014))
with ESMTPA id <0NVS0088PWBQRE70@eusync3.samsung.com>; Tue,
06 Oct 2015 14:33:29 +0100 (BST)
From: Pavel Fedin
To: qemu-devel@nongnu.org
Date: Tue, 06 Oct 2015 16:33:23 +0300
Message-id: <017e01d1003b$959bc820$c0d35860$@samsung.com>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7bit
X-Mailer: Microsoft Outlook 14.0
Thread-index: AdEAOw/3HurzjuUUQyqifHTXjiv5DQ==
Content-language: ru
X-Brightmail-Tracker:
H4sIAAAAAAAAA+NgFjrALMWRmVeSWpSXmKPExsVy+t/xq7orzwqHGcxfrW7x5N93RovjvTtY
HJg8nlzbzOQxYepSlgCmKC6blNSczLLUIn27BK6MzRu3MRd8MqxoeXefrYHxtlIXIyeHhICJ
xPTXl1ghbDGJC/fWs4HYQgJLGSX6D8V3MXIB2d8ZJdY9nsIIkmATUJc4/fUDC4gtIiAp8bvr
NDOIzSygJrFt4VywuLCAtcSlGZvAhrIIqEps2vkPzOYVsJRY0PORBcIWlPgx+R4LRK+WxPqd
x5kgbHmJzWveMkMcpCCx4+xrRohdehKT/81lhKgRkZj27x7zBEaBWUhGzUIyahaSUbOQtCxg
ZFnFKJpamlxQnJSea6RXnJhbXJqXrpecn7uJERKuX3cwLj1mdYhRgINRiYdX4qZQmBBrYllx
Ze4hRgkOZiURXoUjwmFCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeWfueh8iJJCeWJKanZpakFoE
k2Xi4JRqYJR8vsuxxItJd2Uqx62v8vwVgj3np3zMvD5lWsqypXbsl/cfiu4Xedydvf3sgytL
d2e8OWek+3z2qwUrt6ZbiSj/FpsSb/5ei+W2uU7Y46/PVn91mnclp/hV4KEeje7i1zMmuT+q
ueZy2m3q0VM/op3al0xYNIHR/lHvtjvWAu8cHxyKbX/bX9mpxFKckWioxVxUnAgAdulh1VMC AAA=
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
recognized.
X-Received-From: 210.118.77.11
Cc: 'Michael Tokarev'
Subject: [Qemu-devel] [PATCH v4] ivshmem: allow the sharing of hugepages
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org
Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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 new parameter 'file' has been added to specify the file to use.
A use case for this patch is sharing huge pages available through a
hugetlbfs mountpoint.
Signed-off-by: Damien Millescamps
Signed-off-by: Pavel Fedin
---
2 years passed since the last review of this, and the original author never came back. So i decided
to pick up this work because my project is interested in this feature. I am keeping patch version
numbering, but the original changelog was lost.
Relevant thread here: https://lists.gnu.org/archive/html/qemu-trivial/2013-09/msg00148.html
v3 => v4:
- Fixed documentation and wordings according to the last review
- Report also actual error messages
- Added missing exit()
- Fixed up code style according to latest checkpatch rules
---
docs/specs/ivshmem_device_spec.txt | 7 ++--
hw/misc/ivshmem.c | 67 +++++++++++++++++++++++++-------------
2 files changed, 50 insertions(+), 24 deletions(-)
diff --git a/docs/specs/ivshmem_device_spec.txt b/docs/specs/ivshmem_device_spec.txt
index 667a862..8b108e7 100644
--- a/docs/specs/ivshmem_device_spec.txt
+++ b/docs/specs/ivshmem_device_spec.txt
@@ -4,8 +4,11 @@ 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 (for instance,
+hugepage-backed file) 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 cc76989..999ed7d 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -100,9 +100,10 @@ typedef struct IVShmemState {
Error *migration_blocker;
- char * shmobj;
- char * sizearg;
- char * role;
+ char *shmobj;
+ char *fileobj;
+ char *sizearg;
+ char *role;
int role_val; /* scalar to avoid multiple string comparisons */
} IVShmemState;
@@ -769,9 +770,9 @@ static int pci_ivshmem_init(PCIDevice *dev)
/* if we get a UNIX socket as the parameter we will talk
* to the ivshmem server to receive the memory region */
- if (s->shmobj != NULL) {
+ if (s->shmobj != NULL || s->fileobj != NULL) {
error_report("WARNING: do not specify both 'chardev' "
- "and 'shm' with ivshmem");
+ "and 'shm' or 'file' with ivshmem");
}
IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n",
@@ -797,28 +798,49 @@ static int pci_ivshmem_init(PCIDevice *dev)
} else {
/* just map the file immediately, we're not using a server */
int fd;
+ int is_shm = !!(s->shmobj != NULL);
+ int is_file = !!(s->fileobj != NULL);
- if (s->shmobj == NULL) {
- error_report("Must specify 'chardev' or 'shm' to ivshmem");
+ if (!(is_shm ^ is_file)) {
+ error_report("Must specify one of 'chardev', 'shm' or 'file' "
+ "to ivshmem");
exit(1);
}
- IVSHMEM_DPRINTF("using shm_open (shm object = %s)\n", s->shmobj);
-
- /* 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,
- S_IRWXU|S_IRWXG|S_IRWXO)) > 0) {
- /* truncate file to length PCI device's memory */
- if (ftruncate(fd, s->ivshmem_size) != 0) {
- error_report("could not truncate shared file");
+ if (is_shm) {
+ IVSHMEM_DPRINTF("using shm_open (shm object = %s)\n", s->shmobj);
+
+ /* try opening with O_EXCL and if it succeeds zero the memory
+ * by truncating to 0 */
+ fd = shm_open(s->shmobj, O_CREAT|O_RDWR|O_EXCL,
+ S_IRWXU|S_IRWXG|S_IRWXO);
+ if (fd > 0) {
+ /* truncate file to length PCI device's memory */
+ if (ftruncate(fd, s->ivshmem_size) != 0) {
+ error_report("could not truncate shared file: %s",
+ strerror(errno));
+ exit(1);
+ }
+ } else {
+ fd = shm_open(s->shmobj, O_CREAT|O_RDWR,
+ S_IRWXU|S_IRWXG|S_IRWXO);
+ if (fd < 0) {
+ error_report("could not open shared file: %s",
+ strerror(errno));
+ exit(1);
+ }
+ }
+ } else {
+ IVSHMEM_DPRINTF("using open (file object = %s)\n", s->fileobj);
+
+ /* try opening a mmap's file. This file must have been previously
+ * created on the host */
+ fd = open(s->fileobj, O_RDWR);
+ if (fd < 0) {
+ error_report("ivshmem: could not open file: %s\n",
+ strerror(errno));
+ exit(-1);
}
-
- } else if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR,
- S_IRWXU|S_IRWXG|S_IRWXO)) < 0) {
- error_report("could not open shared file");
- exit(1);
-
}
if (check_shm_size(s, fd) == -1) {
@@ -856,6 +878,7 @@ static Property ivshmem_properties[] = {
DEFINE_PROP_BIT("ioeventfd", IVShmemState, features, IVSHMEM_IOEVENTFD, false),
DEFINE_PROP_BIT("msi", IVShmemState, features, IVSHMEM_MSI, true),
DEFINE_PROP_STRING("shm", IVShmemState, shmobj),
+ DEFINE_PROP_STRING("file", IVShmemState, fileobj),
DEFINE_PROP_STRING("role", IVShmemState, role),
DEFINE_PROP_UINT32("use64", IVShmemState, ivshmem_64bit, 1),
DEFINE_PROP_END_OF_LIST(),