From patchwork Mon Sep 16 13:46:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Millescamps X-Patchwork-Id: 275220 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 72C362C00C9 for ; Mon, 16 Sep 2013 23:46:44 +1000 (EST) Received: from localhost ([::1]:34461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLZ8U-0008Hj-LE for incoming@patchwork.ozlabs.org; Mon, 16 Sep 2013 09:46:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLZ89-0008HZ-2c for qemu-devel@nongnu.org; Mon, 16 Sep 2013 09:46:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VLZ82-0002FD-TX for qemu-devel@nongnu.org; Mon, 16 Sep 2013 09:46:21 -0400 Received: from mail-bk0-f42.google.com ([209.85.214.42]:36055) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLZ82-0002Ey-Jt for qemu-devel@nongnu.org; Mon, 16 Sep 2013 09:46:14 -0400 Received: by mail-bk0-f42.google.com with SMTP id my10so1578734bkb.29 for ; Mon, 16 Sep 2013 06:46:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/BOdhMU7Q50KCSwIZ72H6muCyWw2bmVWWsvHLMIWSoI=; b=LkwsD90b5wGxovlbSiTS+7EJDRry2ff1TpJpDuH1/scC+DKfWk33xwy6DZHfEy6VOy rJ2pQf/5bC26ezThxzl5fFgbZ8YhuhMy6+zjie8LpIFMUbgq2Yp2zAJE4c9T42iesx2y p2IpU0gvGl3SUzDkA08+l6pXxHf8zfYloLBZE5ihC+AMyZEfESWGrzAx0Iz9FVLpqEx6 3C9a9eQ8/xIYoSuAy4/39bMzUTTfdI9Uo8bh7dEO7qyooa7Rjgv3WZE+ISfmD1NRCpDW BqJROuFoQku1o/42O8RkygjjYcFvv5K85d2zYH4phuUZXlmCy3i1xI+0HOxZGuwGhYyj HiMw== X-Gm-Message-State: ALoCoQkUFnmlAc/kZWLdRzpNKmrexUtEQJ9uZOzEcpgiyK64Sl21D876oGyJaTAnGvSgqQRVQ+E/ X-Received: by 10.205.36.70 with SMTP id sz6mr24008255bkb.12.1379339173654; Mon, 16 Sep 2013 06:46:13 -0700 (PDT) Received: from 6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by mx.google.com with ESMTPSA id zl3sm7702315bkb.4.1969.12.31.16.00.00 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Mon, 16 Sep 2013 06:46:12 -0700 (PDT) From: Damien Millescamps To: qemu-devel@nongnu.org Date: Mon, 16 Sep 2013 15:46:07 +0200 Message-Id: <1379339167-1428-1-git-send-email-damien.millescamps@6wind.com> X-Mailer: git-send-email 1.7.2.5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.214.42 Cc: qemu-trivial@nongnu.org Subject: [Qemu-devel] [PATCH v3] 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 --- docs/specs/ivshmem_device_spec.txt | 5 ++- hw/misc/ivshmem.c | 52 +++++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 20 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..a9f268d 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -98,6 +98,7 @@ typedef struct IVShmemState { Error *migration_blocker; char * shmobj; + char * fileobj; char * sizearg; char * role; int role_val; /* scalar to avoid multiple string comparisons */ @@ -715,9 +716,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) { fprintf(stderr, "WARNING: do not specify both 'chardev' " - "and 'shm' with ivshmem\n"); + "and 'shm' or 'file' with ivshmem\n"); } IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n", @@ -743,28 +744,42 @@ 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) { - fprintf(stderr, "Must specify 'chardev' or 'shm' to ivshmem\n"); + if (!(is_shm ^ is_file)) { + fprintf(stderr, "Must specify one, and only one, in 'chardev'," + " 'file' or 'shm' to ivshmem\n"); 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) { - fprintf(stderr, "ivshmem: could not truncate shared file\n"); + 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 */ + 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) { + fprintf(stderr, "ivshmem: could not truncate" + " shared file\n"); + } + + } 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); } + } else { + IVSHMEM_DPRINTF("using open (file object = %s)\n", s->fileobj); - } 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 opening a mmap's file. This file must have been previously + * created on the host */ + if ((fd = open(s->fileobj, O_RDWR)) < 0) { + fprintf(stderr, "ivshmem: could not open mmap'd file\n"); + exit(-1); + } } if (check_shm_size(s, fd) == -1) { @@ -804,6 +819,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(),