From patchwork Mon Oct 23 14:18:11 2017 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: 829312 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3yLJWf0zk9z9tX8 for ; Tue, 24 Oct 2017 01:22:22 +1100 (AEDT) Received: from localhost ([::1]:39018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6dcS-0003NP-7a for incoming@patchwork.ozlabs.org; Mon, 23 Oct 2017 10:22:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6dZ0-00015J-UE for qemu-devel@nongnu.org; Mon, 23 Oct 2017 10:18:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6dYz-0000ac-Ty for qemu-devel@nongnu.org; Mon, 23 Oct 2017 10:18:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6dYz-0000aE-Lg for qemu-devel@nongnu.org; Mon, 23 Oct 2017 10:18:45 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1F12C0587CD for ; Mon, 23 Oct 2017 14:18:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C1F12C0587CD Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com Received: from localhost (unknown [10.41.1.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CA7360E3B; Mon, 23 Oct 2017 14:18:39 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 15:18:11 +0100 Message-Id: <20171023141815.17709-6-marcandre.lureau@redhat.com> In-Reply-To: <20171023141815.17709-1-marcandre.lureau@redhat.com> References: <20171023141815.17709-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 23 Oct 2017 14:18:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 5/9] memfd: add hugetlbsize argument 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, ehabkost@redhat.com, =?utf-8?q?Marc-Andr=C3=A9_Lu?= =?utf-8?q?reau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Learn to specificy hugetlb size as qemu_memfd_create() argument. Signed-off-by: Marc-André Lureau --- include/qemu/memfd.h | 2 +- util/memfd.c | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h index 1d3ecc7458..de10198ed6 100644 --- a/include/qemu/memfd.h +++ b/include/qemu/memfd.h @@ -17,7 +17,7 @@ #endif int qemu_memfd_create(const char *name, size_t size, bool hugetlb, - unsigned int seals, Error **errp); + uint64_t hugetlbsize, unsigned int seals, Error **errp); void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals, int *fd, Error **errp); void qemu_memfd_free(void *ptr, size_t size, int fd); diff --git a/util/memfd.c b/util/memfd.c index 98294e84de..0144acd476 100644 --- a/util/memfd.c +++ b/util/memfd.c @@ -29,6 +29,7 @@ #include "qapi/error.h" #include "qemu/memfd.h" +#include "qemu/host-utils.h" #ifdef CONFIG_MEMFD #include @@ -58,9 +59,22 @@ static int memfd_create(const char *name, unsigned int flags) #define MFD_HUGETLB 0x0004U #endif +#ifndef MFD_HUGE_SHIFT +#define MFD_HUGE_SHIFT 26 +#endif + int qemu_memfd_create(const char *name, size_t size, bool hugetlb, - unsigned int seals, Error **errp) + uint64_t hugetlbsize, unsigned int seals, Error **errp) { + int htsize = hugetlbsize ? ctz64(hugetlbsize) : 0; + + if (htsize && 1 << htsize != hugetlbsize) { + error_setg(errp, "Hugepage size must be a power of 2"); + return -1; + } + + htsize = htsize << MFD_HUGE_SHIFT; + #ifdef CONFIG_LINUX int mfd = -1; unsigned int flags = MFD_CLOEXEC; @@ -70,8 +84,8 @@ int qemu_memfd_create(const char *name, size_t size, bool hugetlb, } if (hugetlb) { flags |= MFD_HUGETLB; + flags |= htsize; } - mfd = memfd_create(name, flags); if (mfd < 0) { goto err; @@ -106,11 +120,11 @@ void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals, int *fd, Error **errp) { void *ptr; - int mfd = qemu_memfd_create(name, size, false, seals, NULL); + int mfd = qemu_memfd_create(name, size, false, 0, seals, NULL); /* some systems have memfd without sealing */ if (mfd == -1) { - mfd = qemu_memfd_create(name, size, false, 0, NULL); + mfd = qemu_memfd_create(name, size, false, 0, 0, NULL); } if (mfd == -1) {