From patchwork Fri Jul 5 11:01:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 11033737 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 802BC912 for ; Sat, 6 Jul 2019 11:42:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6454728684 for ; Sat, 6 Jul 2019 11:42:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D679286C8; Sat, 6 Jul 2019 11:42: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=-3.9 required=2.0 tests=BAYES_00,DATE_IN_PAST_24_48, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C904428684 for ; Sat, 6 Jul 2019 11:42:14 +0000 (UTC) Received: from localhost ([::1]:58886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjj54-0004je-35 for patchwork-qemu-devel@patchwork.kernel.org; Sat, 06 Jul 2019 07:42:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52594) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjijT-0003M7-KP for qemu-devel@nongnu.org; Sat, 06 Jul 2019 07:19:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hjijQ-0006Ec-H3 for qemu-devel@nongnu.org; Sat, 06 Jul 2019 07:19:55 -0400 Received: from mga14.intel.com ([192.55.52.115]:2989) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hjijM-00060B-KF for qemu-devel@nongnu.org; Sat, 06 Jul 2019 07:19:49 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False 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:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,458,1557212400"; d="scan'208";a="363355053" Received: from yiliu-dev.bj.intel.com ([10.238.156.139]) by fmsmga005.fm.intel.com with ESMTP; 06 Jul 2019 04:19:31 -0700 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:48 +0800 Message-Id: <1562324511-2910-16-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 15/18] vfio/pci: adds support for PASID-based iotlb flush 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for propagating guest PASID-based iotlb flush 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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 892b46c..d8b84a5 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2796,11 +2796,34 @@ static void vfio_pci_device_unbind_gpasid(PCIBus *bus, int32_t devfn, g_free(bind); } +static void vfio_pci_device_flush_pasid_iotlb(PCIBus *bus, int32_t devfn, + struct iommu_cache_invalidate_info *info) +{ + PCIDevice *pdev = bus->devices[devfn]; + VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOContainer *container = vdev->vbasedev.group->container; + struct vfio_iommu_type1_cache_invalidate cache_inv; + unsigned long argsz; + + argsz = sizeof(cache_inv); + cache_inv.argsz = argsz; + cache_inv.info = *info; + cache_inv.flags = 0x0; + + rcu_read_lock(); + if (ioctl(container->fd, VFIO_IOMMU_CACHE_INVALIDATE, &cache_inv) != 0) { + error_report("vfio_pci_device_flush_pasid_iotlb:" + " cache invalidation failed, contanier: %p", container); + } + rcu_read_unlock(); +} + static PCIPASIDOps vfio_pci_pasid_ops = { .alloc_pasid = vfio_pci_device_request_pasid_alloc, .free_pasid = vfio_pci_device_request_pasid_free, .bind_gpasid = vfio_pci_device_bind_gpasid, .unbind_gpasid = vfio_pci_device_unbind_gpasid, + .flush_pasid_iotlb = vfio_pci_device_flush_pasid_iotlb, }; static void vfio_realize(PCIDevice *pdev, Error **errp)