From nobody Mon Feb 9 12:26:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1562412328; cv=none; d=zoho.com; s=zohoarc; b=T5yuvKpQ7IiQ9HvmTyEZnjHIsYOCN9eieWw79BFoE4jEsyFcnMdu2XKHWlSwkWRXeUe2N4PwGt/k1r1p9iqFB2vdY6Dy4skEhHCyJLTx+w6auZ5BflNavqe0D2NOUO06zVbmtr9Ui7+mLXYuU2//8EPVAReHdZQw+HXNs1pXDaU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562412328; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=nl9JGVhtsejVwnNqLAXlOlpsfgBOpPP4zdZLZ7qllzA=; b=EkuzhyiX+IAtYUqIA9TepDcY2dpuUqj2/ycw72YQ3A0YhI2iE+RnOjDIILlFJIVOjRPBV3TU23Qh0IS2qJNol5CNOENYHankoXRWZ4zU0Vx9dXU9W0w0iytftOPpebMk6G/O0tvXZZa0DdgJkmjG+rJL196IlUG24nkpbJGsHnY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562412328176138.8148489272479; Sat, 6 Jul 2019 04:25:28 -0700 (PDT) Received: from localhost ([::1]:58782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjiop-0008Kr-7G for importer@patchew.org; Sat, 06 Jul 2019 07:25:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52424) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjiiv-00036Y-EF for qemu-devel@nongnu.org; Sat, 06 Jul 2019 07:19:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hjiir-0005wo-4j for qemu-devel@nongnu.org; Sat, 06 Jul 2019 07:19:20 -0400 Received: from mga14.intel.com ([192.55.52.115]:2961) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hjiip-0005e0-Sx for qemu-devel@nongnu.org; Sat, 06 Jul 2019 07:19:17 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2019 04:19:13 -0700 Received: from yiliu-dev.bj.intel.com ([10.238.156.139]) by fmsmga005.fm.intel.com with ESMTP; 06 Jul 2019 04:19:11 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,458,1557212400"; d="scan'208";a="363355011" From: Liu Yi L To: qemu-devel@nongnu.org, mst@redhat.com, pbonzini@redhat.com, alex.williamson@redhat.com, peterx@redhat.com Date: Fri, 5 Jul 2019 19:01:41 +0800 Message-Id: <1562324511-2910-9-git-send-email-yi.l.liu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1562324511-2910-1-git-send-email-yi.l.liu@intel.com> References: <1562324511-2910-1-git-send-email-yi.l.liu@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.115 Subject: [Qemu-devel] [RFC v1 08/18] vfio/pci: add vfio bind/unbind_gpasid implementation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tianyu.lan@intel.com, kevin.tian@intel.com, yi.l.liu@intel.com, Yi Sun , kvm@vger.kernel.org, jun.j.tian@intel.com, eric.auger@redhat.com, yi.y.sun@intel.com, Jacob Pan , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds vfio implementation PCIPASIDOps.bind_gpasid/unbind_pasid(). These two functions are used to propagate guest pasid bind and unbind requests to host via vfio container ioctl. Cc: Kevin Tian Cc: Jacob Pan Cc: Peter Xu Cc: Eric Auger Cc: Yi Sun Cc: David Gibson Signed-off-by: Liu Yi L --- hw/vfio/pci.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index ab184ad..892b46c 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2744,9 +2744,63 @@ static int vfio_pci_device_request_pasid_free(PCIBus= *bus, return ret; } =20 +static void vfio_pci_device_bind_gpasid(PCIBus *bus, int32_t devfn, + struct gpasid_bind_data *g_bind_data) +{ + PCIDevice *pdev =3D bus->devices[devfn]; + VFIOPCIDevice *vdev =3D DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOContainer *container =3D vdev->vbasedev.group->container; + struct vfio_iommu_type1_bind *bind; + struct vfio_iommu_type1_bind_guest_pasid *bind_guest_pasid; + unsigned long argsz; + + argsz =3D sizeof(*bind) + sizeof(*bind_guest_pasid); + bind =3D g_malloc0(argsz); + bind->argsz =3D argsz; + bind->bind_type =3D VFIO_IOMMU_BIND_GUEST_PASID; + bind_guest_pasid =3D (struct vfio_iommu_type1_bind_guest_pasid *) &bin= d->data; + bind_guest_pasid->bind_data =3D *g_bind_data; + + rcu_read_lock(); + if (ioctl(container->fd, VFIO_IOMMU_BIND, bind) !=3D 0) { + error_report("vfio_pci_device_bind_gpasid:" + " bind failed, contanier: %p", container); + } + rcu_read_unlock(); + g_free(bind); +} + +static void vfio_pci_device_unbind_gpasid(PCIBus *bus, int32_t devfn, + struct gpasid_bind_data *g_bind_data) +{ + PCIDevice *pdev =3D bus->devices[devfn]; + VFIOPCIDevice *vdev =3D DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOContainer *container =3D vdev->vbasedev.group->container; + struct vfio_iommu_type1_bind *bind; + struct vfio_iommu_type1_bind_guest_pasid *bind_guest_pasid; + unsigned long argsz; + + argsz =3D sizeof(*bind) + sizeof(*bind_guest_pasid); + bind =3D g_malloc0(argsz); + bind->argsz =3D argsz; + bind->bind_type =3D VFIO_IOMMU_BIND_GUEST_PASID; + bind_guest_pasid =3D (struct vfio_iommu_type1_bind_guest_pasid *) &bin= d->data; + bind_guest_pasid->bind_data =3D *g_bind_data; + + rcu_read_lock(); + if (ioctl(container->fd, VFIO_IOMMU_UNBIND, bind) !=3D 0) { + error_report("vfio_pci_device_unbind_gpasid:" + " unbind failed, contanier: %p", container); + } + rcu_read_unlock(); + g_free(bind); +} + static PCIPASIDOps vfio_pci_pasid_ops =3D { .alloc_pasid =3D vfio_pci_device_request_pasid_alloc, .free_pasid =3D vfio_pci_device_request_pasid_free, + .bind_gpasid =3D vfio_pci_device_bind_gpasid, + .unbind_gpasid =3D vfio_pci_device_unbind_gpasid, }; =20 static void vfio_realize(PCIDevice *pdev, Error **errp) --=20 2.7.4