From nobody Wed Nov 5 02:31:22 2025 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; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 153733888570024.94073917006574; Tue, 18 Sep 2018 23:34:45 -0700 (PDT) Received: from localhost ([::1]:43872 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2W4K-0001QC-0P for importer@patchew.org; Wed, 19 Sep 2018 02:34:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2Vzo-0006ep-S8 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-0002fg-TN 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-JQ for qemu-devel@nongnu.org; Wed, 19 Sep 2018 02:29:55 -0400 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 Received: from btwcube1.sh.intel.com ([10.67.104.151]) by fmsmga007.fm.intel.com with ESMTP; 18 Sep 2018 23:29:46 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,392,1531810800"; d="scan'208";a="71164034" 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:34 +0800 Message-Id: <20180919062834.30103-5-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 4/4] vhost-user-bridge: 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch introduces the VFIO container message support in vhost-user-bridge. A new option (-G) is added to set the VFIO container for the vhost device. This is mainly used to test the VFIO container message implementation in vhost user. Signed-off-by: Tiwei Bie --- tests/vhost-user-bridge.c | 63 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c index 0884294141..b668462b49 100644 --- a/tests/vhost-user-bridge.c +++ b/tests/vhost-user-bridge.c @@ -35,6 +35,9 @@ #include "standard-headers/linux/virtio_net.h" #include "contrib/libvhost-user/libvhost-user.h" =20 +#include +#include + #define VHOST_USER_BRIDGE_DEBUG 1 =20 #define DPRINT(...) \ @@ -71,6 +74,8 @@ typedef struct VubrDev { void *addr; pthread_t thread; } notifier; + int vfio_container; + int vfio_group; } VubrDev; =20 static void @@ -467,6 +472,12 @@ vubr_queue_set_started(VuDev *dev, int qidx, bool star= ted) qidx * getpagesize()); } =20 + /* We can test setting VFIO container multiple times + * by doing this in queue start */ + if (started && vubr->vfio_container >=3D 0) { + vu_set_vfio_container(dev, vubr->vfio_container); + } + if (qidx % 2 =3D=3D 1) { vu_set_queue_handler(dev, vq, started ? vubr_handle_tx : NULL); } @@ -537,6 +548,7 @@ vubr_new(const char *path, bool client) } =20 dev->notifier.fd =3D -1; + dev->vfio_container =3D -1; =20 un.sun_family =3D AF_UNIX; strcpy(un.sun_path, path); @@ -642,6 +654,43 @@ vubr_host_notifier_setup(VubrDev *dev) dev->notifier.thread =3D thread; } =20 +static void +vubr_vfio_container_setup(VubrDev *dev, const char *vfio_group) +{ + int container_fd; + int group_fd; + + container_fd =3D open("/dev/vfio/vfio", O_RDWR); + if (container_fd < 0) { + vubr_die("open(/dev/vfio/vfio)"); + } + + group_fd =3D open(vfio_group, O_RDWR); + if (group_fd < 0) { + vubr_die(vfio_group); + } + + if (ioctl(group_fd, VFIO_GROUP_SET_CONTAINER, &container_fd) < 0) { + vubr_die("ioctl(VFIO_GROUP_SET_CONTAINER)"); + } + + if (ioctl(container_fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) || + ioctl(container_fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1v2_IOMMU)) { + bool v2 =3D !!ioctl(container_fd, VFIO_CHECK_EXTENSION, + VFIO_TYPE1v2_IOMMU); + + if (ioctl(container_fd, VFIO_SET_IOMMU, v2 ? VFIO_TYPE1v2_IOMMU : + VFIO_TYPE1_IOMMU) < 0) { + vubr_die("ioctl(VFIO_SET_IOMMU)"); + } + } else { + vubr_die("No available IOMMU models"); + } + + dev->vfio_container =3D container_fd; + dev->vfio_group =3D group_fd; +} + static void vubr_set_host(struct sockaddr_in *saddr, const char *host) { @@ -757,8 +806,9 @@ main(int argc, char *argv[]) int opt; bool client =3D false; bool host_notifier =3D false; + char *vfio_group =3D NULL; =20 - while ((opt =3D getopt(argc, argv, "l:r:u:cH")) !=3D -1) { + while ((opt =3D getopt(argc, argv, "l:r:u:cHG:")) !=3D -1) { =20 switch (opt) { case 'l': @@ -780,6 +830,9 @@ main(int argc, char *argv[]) case 'H': host_notifier =3D true; break; + case 'G': + vfio_group =3D optarg; + break; default: goto out; } @@ -799,6 +852,10 @@ main(int argc, char *argv[]) vubr_host_notifier_setup(dev); } =20 + if (vfio_group) { + vubr_vfio_container_setup(dev, vfio_group); + } + vubr_backend_udp_setup(dev, lhost, lport, rhost, rport); vubr_run(dev); =20 @@ -808,7 +865,8 @@ main(int argc, char *argv[]) =20 out: fprintf(stderr, "Usage: %s ", argv[0]); - fprintf(stderr, "[-c] [-H] [-u ud_socket_path] [-l lhost:lport] [-r rh= ost:rport]\n"); + fprintf(stderr, "[-c] [-H] [-u ud_socket_path] [-l lhost:lport]\n"); + fprintf(stderr, "\t\t[-r rhost:rport] [-G /dev/vfio/GROUP]\n"); fprintf(stderr, "\t-u path to unix doman socket. default: %s\n", DEFAULT_UD_SOCKET); fprintf(stderr, "\t-l local host and port. default: %s:%s\n", @@ -817,6 +875,7 @@ out: DEFAULT_RHOST, DEFAULT_RPORT); fprintf(stderr, "\t-c client mode\n"); fprintf(stderr, "\t-H use host notifier\n"); + fprintf(stderr, "\t-G VFIO group path.\n"); =20 return 1; } --=20 2.18.0