From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zoqcq-0006F1-To for qemu-devel@nongnu.org; Wed, 21 Oct 2015 06:28:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zoqcp-0006SU-Ok for qemu-devel@nongnu.org; Wed, 21 Oct 2015 06:28:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54770) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zoqcp-0006SJ-JU for qemu-devel@nongnu.org; Wed, 21 Oct 2015 06:28:07 -0400 Date: Wed, 21 Oct 2015 13:28:04 +0300 From: "Michael S. Tsirkin" Message-ID: <1445423133-5119-28-git-send-email-mst@redhat.com> References: <1445423133-5119-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1445423133-5119-1-git-send-email-mst@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 27/38] vhost: add migration block if memfd failed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Thibaut Collet , =?us-ascii?B?PT9VVEYtOD9xP01hcmMtQW5kcj1DMz1BOT0yMEx1cmVhdT89?= From: Marc-Andr=E9 Lureau Signed-off-by: Marc-Andr=E9 Lureau Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Tested-by: Thibaut Collet --- include/qemu/memfd.h | 2 ++ hw/virtio/vhost.c | 3 +++ util/memfd.c | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h index 950fb88..53858ed 100644 --- a/include/qemu/memfd.h +++ b/include/qemu/memfd.h @@ -2,6 +2,7 @@ #define QEMU_MEMFD_H =20 #include "config-host.h" +#include =20 #ifndef F_LINUX_SPECIFIC_BASE #define F_LINUX_SPECIFIC_BASE 1024 @@ -20,5 +21,6 @@ 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); +bool qemu_memfd_check(void); =20 #endif /* QEMU_MEMFD_H */ diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 2e78e4b..feeaaa4 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1019,6 +1019,9 @@ int vhost_dev_init(struct vhost_dev *hdev, void *op= aque, if (!(hdev->features & (0x1ULL << VHOST_F_LOG_ALL))) { error_setg(&hdev->migration_blocker, "Migration disabled: vhost lacks VHOST_F_LOG_ALL = feature."); + } else if (!qemu_memfd_check()) { + error_setg(&hdev->migration_blocker, + "Migration disabled: failed to allocate shared me= mory"); } } =20 diff --git a/util/memfd.c b/util/memfd.c index 4b23765..7c40691 100644 --- a/util/memfd.c +++ b/util/memfd.c @@ -138,3 +138,25 @@ void qemu_memfd_free(void *ptr, size_t size, int fd) close(fd); } } + +enum { + MEMFD_KO, + MEMFD_OK, + MEMFD_TODO +}; + +bool qemu_memfd_check(void) +{ + static int memfd_check =3D MEMFD_TODO; + + if (memfd_check =3D=3D MEMFD_TODO) { + int fd; + void *ptr; + + ptr =3D qemu_memfd_alloc("test", 4096, 0, &fd); + memfd_check =3D ptr ? MEMFD_OK : MEMFD_KO; + qemu_memfd_free(ptr, 4096, fd); + } + + return memfd_check =3D=3D MEMFD_OK; +} --=20 MST