From patchwork Tue Apr 12 11:55:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 8809751 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 830C69F39A for ; Tue, 12 Apr 2016 11:58:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D542B20148 for ; Tue, 12 Apr 2016 11:58:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 35170200C1 for ; Tue, 12 Apr 2016 11:58:17 +0000 (UTC) Received: from localhost ([::1]:47899 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwxU-0000vK-MS for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Apr 2016 07:58:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwvE-0004rQ-HW for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1apwvC-0008QI-JA for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:56 -0400 Received: from mail-qg0-x230.google.com ([2607:f8b0:400d:c04::230]:36516) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwvC-0008QE-9F for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:54 -0400 Received: by mail-qg0-x230.google.com with SMTP id f52so13034850qga.3 for ; Tue, 12 Apr 2016 04:55:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=igVk4lu/XrN7UhGXEOI753v84Sy6IwbKMSiey1dbLWk=; b=LynuFnomP+smW4i/BYm4WcFg7/7Tnr51XlNRtAdoftWkZATnh+vguIJVZ5VTcdskLK lvQ7ypeNPmTXCcHrb/co6GzAtf6YURhxqZn1j+0IR0KEK5gJlDyXP3xgUslweCNHCIyb MZqowaQf52HhiajvewUaO2xfNfki7noYMUm85K+LAFnolCJreWPHbFjZ8RVAWpW5vCMt oW9yPB+kPClIbrW2XZlPa27S/YrNJfP1FPRKTsbpC17GZSvTKzgBR6M0N+NT2y9WlW/7 IkzB7rtdyYC7YtnoSBShQRPRp1q12os8gs8G0CU39u6iFvyzv0HdDKQoH8Q4sBNfUtVQ NP7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=igVk4lu/XrN7UhGXEOI753v84Sy6IwbKMSiey1dbLWk=; b=P6aA1srBi2zaASXlwe4YR8KBYDYlstRtEPTA5cBJaATwMjI+z8Kow5KzECvZIpUQ6b LxSW0H7ZKQoUNuqbcJ1/e1myrdmoQH9/qffgHsqK3X9XZPA4/22q3b8rOVWw9Xyqs2BY JeleyMmwm5c8dRdrEoyWphHSvdQQBFP98wSGj90g6B7l/R3kufazdnhfE1AY+O3jsubV 0KJG+qU8YEXiTMAEdNnWD1m/wDuLoM6beeYbTReXPyUmeJ48ewgsZurAp8DXJSVnaPKQ D3yDO/iPciaHX8QAIqgSQ4NwECp6ktCOFFicMfuIhcm8RCkVf1zDFn+KJA+kNGAxgOsz PWdg== X-Gm-Message-State: AOPr4FU1xilBOBZqDwB61aXf+uu5F9umrOQiodMwjd2mNr6NVX0YiTzjAZ0n7EYQCwJPhg== X-Received: by 10.140.32.203 with SMTP id h69mr3155638qgh.55.1460462153389; Tue, 12 Apr 2016 04:55:53 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id 9sm12299249qgk.2.2016.04.12.04.55.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Apr 2016 04:55:52 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Tue, 12 Apr 2016 13:55:27 +0200 Message-Id: <1460462129-17363-8-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1460462129-17363-1-git-send-email-marcandre.lureau@redhat.com> References: <1460462129-17363-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c04::230 Subject: [Qemu-devel] [PATCH 7/9] memfd: split qemu_memfd_alloc() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau Signed-off-by: Marc-André Lureau --- include/qemu/memfd.h | 1 + util/memfd.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h index 745a8c5..41c24d8 100644 --- a/include/qemu/memfd.h +++ b/include/qemu/memfd.h @@ -16,6 +16,7 @@ #define F_SEAL_WRITE 0x0008 /* prevent writes */ #endif +int qemu_memfd_create(const char *name, size_t size, unsigned int seals); void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals, int *fd); void qemu_memfd_free(void *ptr, size_t size, int fd); diff --git a/util/memfd.c b/util/memfd.c index 7c40691..31aaced 100644 --- a/util/memfd.c +++ b/util/memfd.c @@ -64,14 +64,10 @@ static int memfd_create(const char *name, unsigned int flags) * memfd with sealing, but may fallback on other methods without * sealing. */ -void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals, - int *fd) +int qemu_memfd_create(const char *name, size_t size, unsigned int seals) { - void *ptr; int mfd = -1; - *fd = -1; - #ifdef CONFIG_LINUX if (seals) { mfd = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC); @@ -117,6 +113,19 @@ void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals, } } + return mfd; +} + +void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals, + int *fd) +{ + void *ptr; + int mfd = qemu_memfd_create(name, size, seals); + + if (mfd == -1) { + return NULL; + } + ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0); if (ptr == MAP_FAILED) { perror("mmap");