From patchwork Thu Sep 12 18:23:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Millescamps X-Patchwork-Id: 274581 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 2488A2C035C for ; Fri, 13 Sep 2013 04:24:36 +1000 (EST) Received: from localhost ([::1]:43266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKBZB-0007kQ-Bq for incoming@patchwork.ozlabs.org; Thu, 12 Sep 2013 14:24:33 -0400 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) 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=m9Yw3aj9Nqm2hrzzwS78en1aiC2ySJwHeWXOmmSiYk8=; b=UV8psYqNYmlzYaiv6KUNxpvyTSHW5KaXQ/3CBv5pipprh3pIKOPyDjZBvQ/O4x4SI6 4g/7z5ZRmqBUexdsuyLxbV5y0S3fFNUOa3WlURTAyWUvsnp7Iig0smfdF5N8az3k1oT5 TqOdmnGC8SCm5EWwijn7uN3PV/BmrDXQg4GxkLsfyN+CDTatUU4cfxZC8rbSy5rBa2pp FFCvyJkGVR9hRUAdkCI81kYV5qP4RKk+NSeQWyIHqzfFNAJKaiB6y2U0/V8sp53f/c3V wbf5feHEdPSfYZjsPbug2jTXQqXPkPKKUDgcSKr88opBadB8M3ZQNYk5fZD+epaJy8rw /iGw== X-Gm-Message-State: ALoCoQnMrHRW04253mMvpu3W8GYOH4/UMljt4GN+iLMMOja2djCi3vYrxZaQQgoaqY60r/rfy9b1 X-Received: by 10.194.5.35 with SMTP id p3mr2940847wjp.47.1379010238659; Thu, 12 Sep 2013 11:23:58 -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 ey4sm6345335wic.11.1969.12.31.16.00.00 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Thu, 12 Sep 2013 11:23:57 -0700 (PDT) From: Damien Millescamps To: qemu-devel@nongnu.org Date: Thu, 12 Sep 2013 20:23:48 +0200 Message-Id: <1379010228-15324-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.212.174 Cc: qemu-trivial@nongnu.org Subject: [Qemu-devel] [PATCH] 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 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) {