From nobody Sat May 4 10:59:03 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508752888763588.3134271989749; Mon, 23 Oct 2017 03:01:28 -0700 (PDT) Received: from localhost ([::1]:37788 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6ZXj-0006bV-VQ for importer@patchew.org; Mon, 23 Oct 2017 06:01:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44900) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6ZVx-0005L5-2J for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6ZVw-0002w3-5w for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36798) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6ZVv-0002vr-Sk for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC0CB5F7BE for ; Mon, 23 Oct 2017 09:59:18 +0000 (UTC) Received: from localhost (unknown [10.41.1.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3891960A98; Mon, 23 Oct 2017 09:59:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BC0CB5F7BE Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 10:59:05 +0100 Message-Id: <20171023095910.23202-2-marcandre.lureau@redhat.com> In-Reply-To: <20171023095910.23202-1-marcandre.lureau@redhat.com> References: <20171023095910.23202-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 23 Oct 2017 09:59:18 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v5 1/6] 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, ehabkost@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a function to only create a memfd, without mmap. The function is used in the following memory backend. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/memfd.h | 1 + util/memfd.c | 61 +++++++++++++++++++++++++++++++-----------------= ---- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h index 745a8c501e..41c24d807c 100644 --- a/include/qemu/memfd.h +++ b/include/qemu/memfd.h @@ -16,6 +16,7 @@ #define F_SEAL_WRITE 0x0008 /* prevent writes */ #endif =20 +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 4571d1aba8..e9c1a0e700 100644 --- a/util/memfd.c +++ b/util/memfd.c @@ -55,6 +55,38 @@ static int memfd_create(const char *name, unsigned int f= lags) #define MFD_ALLOW_SEALING 0x0002U #endif =20 +int qemu_memfd_create(const char *name, size_t size, unsigned int seals) +{ + int mfd =3D -1; + +#ifdef CONFIG_LINUX + unsigned int flags =3D MFD_CLOEXEC; + + if (seals) { + flags |=3D MFD_ALLOW_SEALING; + } + + mfd =3D memfd_create(name, flags); + if (mfd < 0) { + return -1; + } + + if (ftruncate(mfd, size) =3D=3D -1) { + perror("ftruncate"); + close(mfd); + return -1; + } + + if (seals && fcntl(mfd, F_ADD_SEALS, seals) =3D=3D -1) { + perror("fcntl"); + close(mfd); + return -1; + } +#endif + + return mfd; +} + /* * This is a best-effort helper for shared memory allocation, with * optional sealing. The helper will do his best to allocate using @@ -65,35 +97,14 @@ void *qemu_memfd_alloc(const char *name, size_t size, u= nsigned int seals, int *fd) { void *ptr; - int mfd =3D -1; - - *fd =3D -1; - -#ifdef CONFIG_LINUX - if (seals) { - mfd =3D memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC); - } + int mfd =3D qemu_memfd_create(name, size, seals); =20 + /* some systems have memfd without sealing */ if (mfd =3D=3D -1) { - /* some systems have memfd without sealing */ - mfd =3D memfd_create(name, MFD_CLOEXEC); - seals =3D 0; + mfd =3D qemu_memfd_create(name, size, 0); } -#endif - - if (mfd !=3D -1) { - if (ftruncate(mfd, size) =3D=3D -1) { - perror("ftruncate"); - close(mfd); - return NULL; - } =20 - if (seals && fcntl(mfd, F_ADD_SEALS, seals) =3D=3D -1) { - perror("fcntl"); - close(mfd); - return NULL; - } - } else { + if (mfd =3D=3D -1) { const char *tmpdir =3D g_get_tmp_dir(); gchar *fname; =20 --=20 2.15.0.rc0.40.gaefcc5f6f From nobody Sat May 4 10:59:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508752888010527.5178778196603; Mon, 23 Oct 2017 03:01:28 -0700 (PDT) Received: from localhost ([::1]:37791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6ZXv-0006kI-6i for importer@patchew.org; Mon, 23 Oct 2017 06:01:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6ZW4-0005Qh-J1 for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6ZVz-0002wt-7T for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36170) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6ZVz-0002wj-2j for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:23 -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 07B385D9E1 for ; Mon, 23 Oct 2017 09:59:22 +0000 (UTC) Received: from localhost (unknown [10.41.1.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id A55B85054E; Mon, 23 Oct 2017 09:59:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 07B385D9E1 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 10:59:06 +0100 Message-Id: <20171023095910.23202-3-marcandre.lureau@redhat.com> In-Reply-To: <20171023095910.23202-1-marcandre.lureau@redhat.com> References: <20171023095910.23202-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.25]); Mon, 23 Oct 2017 09:59:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v5 2/6] memfd: remove needless include 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=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- util/memfd.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/util/memfd.c b/util/memfd.c index e9c1a0e700..b5b7a41347 100644 --- a/util/memfd.c +++ b/util/memfd.c @@ -27,8 +27,6 @@ =20 #include "qemu/osdep.h" =20 -#include - #include "qemu/memfd.h" =20 #ifdef CONFIG_MEMFD --=20 2.15.0.rc0.40.gaefcc5f6f From nobody Sat May 4 10:59:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508752976070584.0111123020821; Mon, 23 Oct 2017 03:02:56 -0700 (PDT) Received: from localhost ([::1]:37801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6ZZK-00080K-3N for importer@patchew.org; Mon, 23 Oct 2017 06:02:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44941) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6ZW7-0005So-5n for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6ZW4-0002xs-4C for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36954) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6ZW3-0002xh-RI for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFA9E5F7BE for ; Mon, 23 Oct 2017 09:59:26 +0000 (UTC) Received: from localhost (unknown [10.41.1.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBB6D5D6B2; Mon, 23 Oct 2017 09:59:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CFA9E5F7BE Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 10:59:07 +0100 Message-Id: <20171023095910.23202-4-marcandre.lureau@redhat.com> In-Reply-To: <20171023095910.23202-1-marcandre.lureau@redhat.com> References: <20171023095910.23202-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 23 Oct 2017 09:59:26 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v5 3/6] memfd: add error argument, instead of perror() 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, "Michael S. Tsirkin" , ehabkost@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This will allow callers to silence error report when the call is allowed to failed. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/qemu/memfd.h | 5 +++-- hw/virtio/vhost.c | 8 +++++++- util/memfd.c | 57 +++++++++++++++++++++++++++---------------------= ---- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h index 41c24d807c..b9d09873b5 100644 --- a/include/qemu/memfd.h +++ b/include/qemu/memfd.h @@ -16,9 +16,10 @@ #define F_SEAL_WRITE 0x0008 /* prevent writes */ #endif =20 -int qemu_memfd_create(const char *name, size_t size, unsigned int seals); +int qemu_memfd_create(const char *name, size_t size, unsigned int seals, + Error **errp); void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals, - int *fd); + int *fd, Error **errp); void qemu_memfd_free(void *ptr, size_t size, int fd); bool qemu_memfd_check(void); =20 diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index ddc42f0f93..63ec0e8315 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -329,6 +329,7 @@ static uint64_t vhost_get_log_size(struct vhost_dev *de= v) =20 static struct vhost_log *vhost_log_alloc(uint64_t size, bool share) { + Error *err =3D NULL; struct vhost_log *log; uint64_t logsize =3D size * sizeof(*(log->log)); int fd =3D -1; @@ -337,7 +338,12 @@ static struct vhost_log *vhost_log_alloc(uint64_t size= , bool share) if (share) { log->log =3D qemu_memfd_alloc("vhost-log", logsize, F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_S= EAL, - &fd); + &fd, &err); + if (err) { + error_report_err(err); + g_free(log); + return NULL; + } memset(log->log, 0, logsize); } else { log->log =3D g_malloc0(logsize); diff --git a/util/memfd.c b/util/memfd.c index b5b7a41347..f890976a0e 100644 --- a/util/memfd.c +++ b/util/memfd.c @@ -27,6 +27,7 @@ =20 #include "qemu/osdep.h" =20 +#include "qapi/error.h" #include "qemu/memfd.h" =20 #ifdef CONFIG_MEMFD @@ -53,11 +54,11 @@ static int memfd_create(const char *name, unsigned int = flags) #define MFD_ALLOW_SEALING 0x0002U #endif =20 -int qemu_memfd_create(const char *name, size_t size, unsigned int seals) +int qemu_memfd_create(const char *name, size_t size, + unsigned int seals, Error **errp) { - int mfd =3D -1; - #ifdef CONFIG_LINUX + int mfd =3D -1; unsigned int flags =3D MFD_CLOEXEC; =20 if (seals) { @@ -66,23 +67,26 @@ int qemu_memfd_create(const char *name, size_t size, un= signed int seals) =20 mfd =3D memfd_create(name, flags); if (mfd < 0) { - return -1; + goto err; } =20 if (ftruncate(mfd, size) =3D=3D -1) { - perror("ftruncate"); - close(mfd); - return -1; + goto err; } =20 if (seals && fcntl(mfd, F_ADD_SEALS, seals) =3D=3D -1) { - perror("fcntl"); - close(mfd); - return -1; + goto err; } -#endif =20 return mfd; + +err: + if (mfd >=3D 0) { + close(mfd); + } +#endif + error_setg_errno(errp, errno, "failed to create memfd"); + return -1; } =20 /* @@ -92,14 +96,14 @@ int qemu_memfd_create(const char *name, size_t size, un= signed int seals) * sealing. */ void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals, - int *fd) + int *fd, Error **errp) { void *ptr; - int mfd =3D qemu_memfd_create(name, size, seals); + int mfd =3D qemu_memfd_create(name, size, seals, NULL); =20 /* some systems have memfd without sealing */ if (mfd =3D=3D -1) { - mfd =3D qemu_memfd_create(name, size, 0); + mfd =3D qemu_memfd_create(name, size, 0, NULL); } =20 if (mfd =3D=3D -1) { @@ -111,27 +115,26 @@ void *qemu_memfd_alloc(const char *name, size_t size,= unsigned int seals, unlink(fname); g_free(fname); =20 - if (mfd =3D=3D -1) { - perror("mkstemp"); - return NULL; - } - - if (ftruncate(mfd, size) =3D=3D -1) { - perror("ftruncate"); - close(mfd); - return NULL; + if (mfd =3D=3D -1 || + ftruncate(mfd, size) =3D=3D -1) { + goto err; } } =20 ptr =3D mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0); if (ptr =3D=3D MAP_FAILED) { - perror("mmap"); - close(mfd); - return NULL; + goto err; } =20 *fd =3D mfd; return ptr; + +err: + error_setg_errno(errp, errno, "failed to allocate shared memory"); + if (mfd >=3D 0) { + close(mfd); + } + return NULL; } =20 void qemu_memfd_free(void *ptr, size_t size, int fd) @@ -159,7 +162,7 @@ bool qemu_memfd_check(void) int fd; void *ptr; =20 - ptr =3D qemu_memfd_alloc("test", 4096, 0, &fd); + ptr =3D qemu_memfd_alloc("test", 4096, 0, &fd, NULL); memfd_check =3D ptr ? MEMFD_OK : MEMFD_KO; qemu_memfd_free(ptr, 4096, fd); } --=20 2.15.0.rc0.40.gaefcc5f6f From nobody Sat May 4 10:59:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508753040835354.89448797712964; Mon, 23 Oct 2017 03:04:00 -0700 (PDT) Received: from localhost ([::1]:37803 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6ZaG-0000Ge-Ek for importer@patchew.org; Mon, 23 Oct 2017 06:03:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6ZW7-0005Sm-5N for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6ZW6-0002z2-7O for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36988) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6ZW5-0002yt-UI for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E39C45F7BE for ; Mon, 23 Oct 2017 09:59:28 +0000 (UTC) Received: from localhost (unknown [10.41.1.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB76E5D6B2; Mon, 23 Oct 2017 09:59:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E39C45F7BE Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 10:59:08 +0100 Message-Id: <20171023095910.23202-5-marcandre.lureau@redhat.com> In-Reply-To: <20171023095910.23202-1-marcandre.lureau@redhat.com> References: <20171023095910.23202-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 23 Oct 2017 09:59:29 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v5 4/6] memfd: add hugetlb support 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=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Linux commit 749df87bd7bee5a79cef073f5d032ddb2b211de8 (v4.14-rc1) added a new flag MFD_HUGETLB to memfd_create() that specify the file to be created resides in the hugetlbfs filesystem. This is the generic hugetlbfs filesystem not associated with any specific mount point. hugetlbfs does not support sealing operations, therefore specifying MFD_ALLOW_SEALING with MFD_HUGETLB will result in EINVAL. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/qemu/memfd.h | 4 ++-- util/memfd.c | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h index b9d09873b5..1d3ecc7458 100644 --- a/include/qemu/memfd.h +++ b/include/qemu/memfd.h @@ -16,8 +16,8 @@ #define F_SEAL_WRITE 0x0008 /* prevent writes */ #endif =20 -int qemu_memfd_create(const char *name, size_t size, unsigned int seals, - Error **errp); +int qemu_memfd_create(const char *name, size_t size, bool hugetlb, + 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 f890976a0e..98294e84de 100644 --- a/util/memfd.c +++ b/util/memfd.c @@ -54,7 +54,11 @@ static int memfd_create(const char *name, unsigned int f= lags) #define MFD_ALLOW_SEALING 0x0002U #endif =20 -int qemu_memfd_create(const char *name, size_t size, +#ifndef MFD_HUGETLB +#define MFD_HUGETLB 0x0004U +#endif + +int qemu_memfd_create(const char *name, size_t size, bool hugetlb, unsigned int seals, Error **errp) { #ifdef CONFIG_LINUX @@ -64,6 +68,9 @@ int qemu_memfd_create(const char *name, size_t size, if (seals) { flags |=3D MFD_ALLOW_SEALING; } + if (hugetlb) { + flags |=3D MFD_HUGETLB; + } =20 mfd =3D memfd_create(name, flags); if (mfd < 0) { @@ -99,11 +106,11 @@ void *qemu_memfd_alloc(const char *name, size_t size, = unsigned int seals, int *fd, Error **errp) { void *ptr; - int mfd =3D qemu_memfd_create(name, size, seals, NULL); + int mfd =3D qemu_memfd_create(name, size, false, seals, NULL); =20 /* some systems have memfd without sealing */ if (mfd =3D=3D -1) { - mfd =3D qemu_memfd_create(name, size, 0, NULL); + mfd =3D qemu_memfd_create(name, size, false, 0, NULL); } =20 if (mfd =3D=3D -1) { --=20 2.15.0.rc0.40.gaefcc5f6f From nobody Sat May 4 10:59:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508753031050465.9380926487529; Mon, 23 Oct 2017 03:03:51 -0700 (PDT) Received: from localhost ([::1]:37802 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6Za9-0000B8-6j for importer@patchew.org; Mon, 23 Oct 2017 06:03:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44959) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6ZW8-0005UT-QR for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6ZW7-0002zb-Ho for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60922) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6ZW7-0002zC-9S for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 37AF236809 for ; Mon, 23 Oct 2017 09:59:30 +0000 (UTC) Received: from localhost (unknown [10.41.1.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id D105E60A98; Mon, 23 Oct 2017 09:59:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 37AF236809 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 10:59:09 +0100 Message-Id: <20171023095910.23202-6-marcandre.lureau@redhat.com> In-Reply-To: <20171023095910.23202-1-marcandre.lureau@redhat.com> References: <20171023095910.23202-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 23 Oct 2017 09:59:30 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v5 5/6] Add memfd based hostmem 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, Igor Mammedov , ehabkost@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a new memory backend, similar to hostmem-file, except that it doesn't need to create files. It also enforces memory sealing. This backend is mainly useful for sharing the memory with other processes. Note that Linux supports transparent huge-pages of shmem/memfd memory since 4.8. It is relatively easier to set up THP than a dedicate hugepage mount point by using "madvise" in /sys/kernel/mm/transparent_hugepage/shmem_enabled. Since 4.14, memfd allows to set hugetlb requirement explicitly. Usage: -object memory-backend-memfd,id=3Dmem1,size=3D1G Signed-off-by: Marc-Andr=C3=A9 Lureau --- backends/hostmem-memfd.c | 124 +++++++++++++++++++++++++++++++++++++++++++= ++++ tests/vhost-user-test.c | 2 +- backends/Makefile.objs | 2 + qemu-options.hx | 15 ++++++ 4 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 backends/hostmem-memfd.c diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c new file mode 100644 index 0000000000..448591556a --- /dev/null +++ b/backends/hostmem-memfd.c @@ -0,0 +1,124 @@ +/* + * QEMU host memfd memory backend + * + * Copyright (C) 2016 Red Hat Inc + * + * Authors: + * Marc-Andr=C3=A9 Lureau + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "sysemu/hostmem.h" +#include "sysemu/sysemu.h" +#include "qom/object_interfaces.h" +#include "qemu/memfd.h" +#include "qapi/error.h" + +#define TYPE_MEMORY_BACKEND_MEMFD "memory-backend-memfd" + +#define MEMORY_BACKEND_MEMFD(obj) \ + OBJECT_CHECK(HostMemoryBackendMemfd, (obj), TYPE_MEMORY_BACKEND_MEMFD) + +typedef struct HostMemoryBackendMemfd HostMemoryBackendMemfd; + +struct HostMemoryBackendMemfd { + HostMemoryBackend parent_obj; + + bool hugetlb; + bool seal; +}; + +static void +memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) +{ + HostMemoryBackendMemfd *m =3D MEMORY_BACKEND_MEMFD(backend); + int fd; + + if (!backend->size) { + error_setg(errp, "can't create backend with size 0"); + return; + } + + if (host_memory_backend_mr_inited(backend)) { + return; + } + + backend->force_prealloc =3D mem_prealloc; + fd =3D qemu_memfd_create(TYPE_MEMORY_BACKEND_MEMFD, backend->size, + m->hugetlb, m->seal ? + F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL : 0, + errp); + if (fd =3D=3D -1) { + return; + } + + memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), + object_get_canonical_path(OBJECT(backen= d)), + backend->size, true, fd, errp); +} + +static bool memfd_backend_get_hugetlb(Object *o, Error **errp) +{ + return MEMORY_BACKEND_MEMFD(o)->hugetlb; +} + +static void memfd_backend_set_hugetlb(Object *o, bool value, + Error **errp) +{ + MEMORY_BACKEND_MEMFD(o)->hugetlb =3D value; +} + +static bool memfd_backend_get_seal(Object *o, Error **errp) +{ + return MEMORY_BACKEND_MEMFD(o)->seal; +} + +static void memfd_backend_set_seal(Object *o, bool value, + Error **errp) +{ + MEMORY_BACKEND_MEMFD(o)->seal =3D value; +} + +static void +memfd_backend_instance_init(Object *obj) +{ + HostMemoryBackendMemfd *m =3D MEMORY_BACKEND_MEMFD(obj); + + /* default to sealed file */ + m->seal =3D true; +} + +static void +memfd_backend_class_init(ObjectClass *oc, void *data) +{ + HostMemoryBackendClass *bc =3D MEMORY_BACKEND_CLASS(oc); + + bc->alloc =3D memfd_backend_memory_alloc; + + object_class_property_add_bool(oc, "hugetlb", + memfd_backend_get_hugetlb, + memfd_backend_set_hugetlb, + &error_abort); + object_class_property_add_bool(oc, "seal", + memfd_backend_get_seal, + memfd_backend_set_seal, + &error_abort); +} + +static const TypeInfo memfd_backend_info =3D { + .name =3D TYPE_MEMORY_BACKEND_MEMFD, + .parent =3D TYPE_MEMORY_BACKEND, + .instance_init =3D memfd_backend_instance_init, + .class_init =3D memfd_backend_class_init, + .instance_size =3D sizeof(HostMemoryBackendMemfd), +}; + +static void register_types(void) +{ + type_register_static(&memfd_backend_info); +} + +type_init(register_types); diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index 4b98018478..830f1e4026 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -31,7 +31,7 @@ #include #include =20 -#define VHOST_USER_NET_TESTS_WORKING 0 /* broken as of 2.10.0 */ +#define VHOST_USER_NET_TESTS_WORKING 1 /* broken as of 2.10.0 */ =20 /* GLIB version compatibility flags */ #if !GLIB_CHECK_VERSION(2, 26, 0) diff --git a/backends/Makefile.objs b/backends/Makefile.objs index 0400799efd..67eeeba5fc 100644 --- a/backends/Makefile.objs +++ b/backends/Makefile.objs @@ -8,3 +8,5 @@ common-obj-$(CONFIG_LINUX) +=3D hostmem-file.o =20 common-obj-y +=3D cryptodev.o common-obj-y +=3D cryptodev-builtin.o + +common-obj-$(CONFIG_LINUX) +=3D hostmem-memfd.o diff --git a/qemu-options.hx b/qemu-options.hx index 3728e9b4dd..5828caefeb 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4208,6 +4208,21 @@ that @option{discard-data} is only an optimization, = and QEMU might not discard file contents if it aborts unexpectedly or is terminated using SIGKILL. =20 +@item -object memory-backend-memfd,id=3D@var{id},size=3D@var{size},seal=3D= @var{on|off},hugetlb=3D@var{on|off} + +Creates an anonymous memory file backend object, which allows QEMU to +share the memory with an external process in some cases (e.g. when +using vhost-user). The memory is allocated with memfd and optional +sealing. (Linux only) + +The @option{id} parameter is a unique ID that will be used to +reference this memory region when configuring the @option{-numa} +argument. The @option{size} option provides the size of the memory +region, and accepts common suffixes, eg @option{500M}. The +@option{seal} option creates a sealed-file, that will block further +resizing the memory ('on' by default). The @option{hugetlb} option +specify the file to be created resides in the hugetlbfs filesystem. + @item -object rng-random,id=3D@var{id},filename=3D@var{/dev/random} =20 Creates a random number generator backend which obtains entropy from --=20 2.15.0.rc0.40.gaefcc5f6f From nobody Sat May 4 10:59:03 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508753160656218.55366170973684; Mon, 23 Oct 2017 03:06:00 -0700 (PDT) Received: from localhost ([::1]:37815 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6Zc8-0001uM-FG for importer@patchew.org; Mon, 23 Oct 2017 06:05:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6ZWA-0005W4-BA for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6ZW8-00030W-UW for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43596) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6ZW8-0002zl-Gn for qemu-devel@nongnu.org; Mon, 23 Oct 2017 05:59:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7763C7E425 for ; Mon, 23 Oct 2017 09:59:31 +0000 (UTC) Received: from localhost (unknown [10.41.1.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 194F05D6B2; Mon, 23 Oct 2017 09:59:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7763C7E425 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 10:59:10 +0100 Message-Id: <20171023095910.23202-7-marcandre.lureau@redhat.com> In-Reply-To: <20171023095910.23202-1-marcandre.lureau@redhat.com> References: <20171023095910.23202-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 23 Oct 2017 09:59:31 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v5 6/6] tests: use memfd in vhost-user-test 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=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This will exercise the memfd memory backend and should generally be better for testing than memory-backend-file (thanks to anonymous files and sealing). Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/vhost-user-test.c | 68 ++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index 830f1e4026..58682f0871 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -17,6 +17,7 @@ #include "qemu/range.h" #include "qemu/sockets.h" #include "chardev/char-fe.h" +#include "qemu/memfd.h" #include "sysemu/sysemu.h" #include "libqos/libqos.h" #include "libqos/pci-pc.h" @@ -42,15 +43,14 @@ #define HAVE_MONOTONIC_TIME #endif =20 -#define QEMU_CMD_MEM " -m %d -object memory-backend-file,id=3Dmem,size= =3D%dM,"\ +#define QEMU_CMD_MEM " -m %d -object memory-backend-file,id=3Dmem,size= =3D%dM," \ "mem-path=3D%s,share=3Don -numa node,memdev=3Dmem" +#define QEMU_CMD_MEMFD " -m %d -object memory-backend-memfd,id=3Dmem,size= =3D%dM," \ + " -numa node,memdev=3Dmem" #define QEMU_CMD_CHR " -chardev socket,id=3D%s,path=3D%s%s" #define QEMU_CMD_NETDEV " -netdev vhost-user,id=3Dnet0,chardev=3D%s,vhostf= orce" #define QEMU_CMD_NET " -device virtio-net-pci,netdev=3Dnet0" =20 -#define QEMU_CMD QEMU_CMD_MEM QEMU_CMD_CHR \ - QEMU_CMD_NETDEV QEMU_CMD_NET - #define HUGETLBFS_MAGIC 0x958458f6 =20 /*********** FROM hw/virtio/vhost-user.c *********************************= ****/ @@ -161,6 +161,22 @@ typedef struct TestServer { static const char *tmpfs; static const char *root; =20 +static char *get_qemu_cmd(TestServer *s, int mem, const char *mem_path, + const char *chr_opts, const char *extra) +{ + if (qemu_memfd_check()) { + return g_strdup_printf(QEMU_CMD_MEMFD QEMU_CMD_CHR + QEMU_CMD_NETDEV QEMU_CMD_NET "%s", mem, mem, + s->chr_name, s->socket_path, + chr_opts, s->chr_name, extra); + } else { + return g_strdup_printf(QEMU_CMD_MEM QEMU_CMD_CHR + QEMU_CMD_NETDEV QEMU_CMD_NET "%s", mem, mem, + mem_path, s->chr_name, s->socket_path, + chr_opts, s->chr_name, extra); + } +} + static void init_virtio_dev(TestServer *s) { QVirtioPCIDevice *dev; @@ -474,14 +490,6 @@ static void test_server_listen(TestServer *server) test_server_create_chr(server, ",server,nowait"); } =20 -#define GET_QEMU_CMD(s) \ - g_strdup_printf(QEMU_CMD, 512, 512, (root), (s)->chr_name, \ - (s)->socket_path, "", (s)->chr_name) - -#define GET_QEMU_CMDE(s, mem, chr_opts, extra, ...) \ - g_strdup_printf(QEMU_CMD extra, (mem), (mem), (root), (s)->chr_name, \ - (s)->socket_path, (chr_opts), (s)->chr_name, ##__VA_AR= GS__) - static gboolean _test_server_free(TestServer *server) { int i; @@ -625,7 +633,7 @@ static void test_migrate(void) char *uri =3D g_strdup_printf("%s%s", "unix:", dest->mig_path); QTestState *global =3D global_qtest, *from, *to; GSource *source; - gchar *cmd; + gchar *cmd, *tmp; QDict *rsp; guint8 *log; guint64 size; @@ -633,7 +641,7 @@ static void test_migrate(void) test_server_listen(s); test_server_listen(dest); =20 - cmd =3D GET_QEMU_CMDE(s, 2, "", ""); + cmd =3D get_qemu_cmd(s, 2, root, "", ""); from =3D qtest_start(cmd); g_free(cmd); =20 @@ -642,7 +650,9 @@ static void test_migrate(void) size =3D get_log_size(s); g_assert_cmpint(size, =3D=3D, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8)= ); =20 - cmd =3D GET_QEMU_CMDE(dest, 2, "", " -incoming %s", uri); + tmp =3D g_strdup_printf(" -incoming %s", uri); + cmd =3D get_qemu_cmd(dest, 2, root, "", tmp); + g_free(tmp); to =3D qtest_init(cmd); g_free(cmd); =20 @@ -753,7 +763,7 @@ static void test_reconnect_subprocess(void) char *cmd; =20 g_thread_new("connect", connect_thread, s); - cmd =3D GET_QEMU_CMDE(s, 2, ",server", ""); + cmd =3D get_qemu_cmd(s, 2, root, ",server", ""); qtest_start(cmd); g_free(cmd); =20 @@ -789,7 +799,7 @@ static void test_connect_fail_subprocess(void) =20 s->test_fail =3D true; g_thread_new("connect", connect_thread, s); - cmd =3D GET_QEMU_CMDE(s, 2, ",server", ""); + cmd =3D get_qemu_cmd(s, 2, root, ",server", ""); qtest_start(cmd); g_free(cmd); =20 @@ -817,7 +827,7 @@ static void test_flags_mismatch_subprocess(void) =20 s->test_flags =3D TEST_FLAGS_DISCONNECT; g_thread_new("connect", connect_thread, s); - cmd =3D GET_QEMU_CMDE(s, 2, ",server", ""); + cmd =3D get_qemu_cmd(s, 2, root, ",server", ""); qtest_start(cmd); g_free(cmd); =20 @@ -885,11 +895,21 @@ static void test_multiqueue(void) s->queues =3D queues; test_server_listen(s); =20 - cmd =3D g_strdup_printf(QEMU_CMD_MEM QEMU_CMD_CHR QEMU_CMD_NETDEV ",qu= eues=3D%d " - "-device virtio-net-pci,netdev=3Dnet0,mq=3Don,ve= ctors=3D%d", - 512, 512, root, s->chr_name, - s->socket_path, "", s->chr_name, - queues, queues * 2 + 2); + if (qemu_memfd_check()) { + cmd =3D g_strdup_printf( + QEMU_CMD_MEMFD QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=3D%d " + "-device virtio-net-pci,netdev=3Dnet0,mq=3Don,vectors=3D%d", + 512, 512, s->chr_name, + s->socket_path, "", s->chr_name, + queues, queues * 2 + 2); + } else { + cmd =3D g_strdup_printf( + QEMU_CMD_MEM QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=3D%d " + "-device virtio-net-pci,netdev=3Dnet0,mq=3Don,vectors=3D%d", + 512, 512, root, s->chr_name, + s->socket_path, "", s->chr_name, + queues, queues * 2 + 2); + } qtest_start(cmd); g_free(cmd); =20 @@ -955,7 +975,7 @@ int main(int argc, char **argv) /* run the main loop thread so the chardev may operate */ thread =3D g_thread_new(NULL, thread_function, loop); =20 - qemu_cmd =3D GET_QEMU_CMD(server); + qemu_cmd =3D get_qemu_cmd(server, 512, root, "", ""); =20 s =3D qtest_start(qemu_cmd); g_free(qemu_cmd); --=20 2.15.0.rc0.40.gaefcc5f6f