From patchwork Wed Sep 19 06:28:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiwei Bie X-Patchwork-Id: 10605375 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA4A4112B for ; Wed, 19 Sep 2018 06:34:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B99062B649 for ; Wed, 19 Sep 2018 06:34:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE0C02B64E; Wed, 19 Sep 2018 06:34:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 554802B649 for ; Wed, 19 Sep 2018 06:34:15 +0000 (UTC) Received: from localhost ([::1]:43873 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2W3y-0001Rs-LS for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Sep 2018 02:34:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2Vzo-0006eY-8D for qemu-devel@nongnu.org; Wed, 19 Sep 2018 02:29:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2Vzn-0002fJ-Ck for qemu-devel@nongnu.org; Wed, 19 Sep 2018 02:29:56 -0400 Received: from mga11.intel.com ([192.55.52.93]:1984) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2Vzn-0002dt-4X for qemu-devel@nongnu.org; Wed, 19 Sep 2018 02:29:55 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Sep 2018 23:29:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,392,1531810800"; d="scan'208";a="71164029" Received: from btwcube1.sh.intel.com ([10.67.104.151]) by fmsmga007.fm.intel.com with ESMTP; 18 Sep 2018 23:29:44 -0700 From: Tiwei Bie To: mst@redhat.com, alex.williamson@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 14:28:33 +0800 Message-Id: <20180919062834.30103-4-tiwei.bie@intel.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180919062834.30103-1-tiwei.bie@intel.com> References: <20180919062834.30103-1-tiwei.bie@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [RFC v2 3/4] libvhost-user: support VFIO container message 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: tiwei.bie@intel.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces the VFIO container message support in libvhost-user. A new API is added to support setting the VFIO container for the vhost device. Signed-off-by: Tiwei Bie --- contrib/libvhost-user/libvhost-user.c | 29 ++++++++++++++++++++++++++- contrib/libvhost-user/libvhost-user.h | 12 +++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c index a6b46cdc03..b960449f9e 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -979,6 +979,32 @@ bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd, return vu_process_message_reply(dev, &vmsg); } +bool vu_set_vfio_container(VuDev *dev, int fd) +{ + int fd_num = 0; + VhostUserMsg vmsg = { + .request = VHOST_USER_SLAVE_VFIO_CONTAINER_MSG, + .flags = VHOST_USER_VERSION | VHOST_USER_NEED_REPLY_MASK, + .size = 0, + }; + + if (fd != -1) { + vmsg.fds[fd_num++] = fd; + } + + vmsg.fd_num = fd_num; + + if ((dev->protocol_features & VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) == 0) { + return false; + } + + if (!vu_message_write(dev, dev->slave_fd, &vmsg)) { + return false; + } + + return vu_process_message_reply(dev, &vmsg); +} + static bool vu_set_vring_call_exec(VuDev *dev, VhostUserMsg *vmsg) { @@ -1033,7 +1059,8 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg) uint64_t features = 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD | 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ | 1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER | - 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD; + 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD | + 1ULL << VHOST_USER_PROTOCOL_F_VFIO_CONTAINER; if (have_userfault()) { features |= 1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT; diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/libvhost-user.h index 4aa55b4d2d..5232bd85ab 100644 --- a/contrib/libvhost-user/libvhost-user.h +++ b/contrib/libvhost-user/libvhost-user.h @@ -53,6 +53,7 @@ enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_CONFIG = 9, VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD = 10, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11, + VHOST_USER_PROTOCOL_F_VFIO_CONTAINER = 12, VHOST_USER_PROTOCOL_F_MAX }; @@ -99,6 +100,7 @@ typedef enum VhostUserSlaveRequest { VHOST_USER_SLAVE_IOTLB_MSG = 1, VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2, VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3, + VHOST_USER_SLAVE_VFIO_CONTAINER_MSG = 4, VHOST_USER_SLAVE_MAX } VhostUserSlaveRequest; @@ -401,6 +403,16 @@ void vu_set_queue_handler(VuDev *dev, VuVirtq *vq, bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd, int size, int offset); +/** + * vu_set_vfio_container: + * @dev: a VuDev context + * @fd: a VFIO container file descriptor + * + * Set device's VFIO container file descriptor. If called with + * -1 @fd, the container is destroyed. + */ +bool vu_set_vfio_container(VuDev *dev, int fd); + /** * vu_queue_set_notification: * @dev: a VuDev context