From patchwork Fri Oct 9 15:17:34 2015 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: 528375 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:4830:134:3::10]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0C5CB14030B for ; Sat, 10 Oct 2015 05:15:51 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=ONMutsoT; dkim-atps=neutral Received: from lists.gnu.org ([208.118.235.17]:53775) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkcCq-00073t-KG for incoming@patchwork.ozlabs.org; Fri, 09 Oct 2015 14:15:48 -0400 Received: from localhost ([::1]:41038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkcCp-0006cr-JH for incoming@patchwork.ozlabs.org; Fri, 09 Oct 2015 14:15:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36640) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkZRZ-0001yO-PZ for qemu-devel@nongnu.org; Fri, 09 Oct 2015 11:18:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZkZRY-00083q-Su for qemu-devel@nongnu.org; Fri, 09 Oct 2015 11:18:49 -0400 Received: from mail-qg0-x232.google.com ([2607:f8b0:400d:c04::232]:33917) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkZRY-00083k-Oi for qemu-devel@nongnu.org; Fri, 09 Oct 2015 11:18:48 -0400 Received: by qgez77 with SMTP id z77so71539431qge.1 for ; Fri, 09 Oct 2015 08:18:48 -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-type:content-transfer-encoding; bh=TK9dOk9+asGeHM6zVX+WreC2Wdy3ELCYums5ux1nR04=; b=ONMutsoTgFi/IlrnPcJU/zzB+irxc6LJLYLo84qmU2uIuLvJqKHBbhqBFwDZRTCo3C XUCrsBKWyRhXmGS9SvQKDMyghpRM9Q6SfjLzWGz3pLb7gfKZB1YFhbrctZRNfWoHvEm/ WLIFvbaqRUrELCk/lgyrL9UWgcgeSgvpAFdEfGcq+X0Tukgl1NZVc3MzlatUsearOE47 d7OzA3VE1Je7uVjh2u9IpC7yJxEKXAdhaixnnhgR7VXwVpn7EMst49RtUGi4KCskj3oy lbhVtrWGGOEV0u3MB/7pfkiTTQCwZ7i/tUmePVGPbIKkpmKki2Hb13BUjbm8yUe9jAO7 yRCQ== X-Received: by 10.140.20.209 with SMTP id 75mr15629322qgj.13.1444403928439; Fri, 09 Oct 2015 08:18:48 -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 z196sm822977qhd.22.2015.10.09.08.18.47 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Oct 2015 08:18:47 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Fri, 9 Oct 2015 17:17:34 +0200 Message-Id: <1444403861-3240-21-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1444403861-3240-1-git-send-email-marcandre.lureau@redhat.com> References: <1444403861-3240-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c04::232 Cc: haifeng.lin@huawei.com, mst@redhat.com, thibaut.collet@6wind.com, jasowang@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [Qemu-devel] [PATCH v8 20/27] vhost: add migration block if memfd failed 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 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x From: Marc-André Lureau Signed-off-by: Marc-André Lureau --- hw/virtio/vhost.c | 3 +++ include/qemu/memfd.h | 2 ++ util/memfd.c | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 1e8ee76..eaf8117 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -994,6 +994,9 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, 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 memory"); } } 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 #include "config-host.h" +#include #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); #endif /* QEMU_MEMFD_H */ 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 = MEMFD_TODO; + + if (memfd_check == MEMFD_TODO) { + int fd; + void *ptr; + + ptr = qemu_memfd_alloc("test", 4096, 0, &fd); + memfd_check = ptr ? MEMFD_OK : MEMFD_KO; + qemu_memfd_free(ptr, 4096, fd); + } + + return memfd_check == MEMFD_OK; +}