From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=DATE_IN_PAST_24_48, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C158C0650E for ; Sat, 6 Jul 2019 11:19:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4FB5F21670 for ; Sat, 6 Jul 2019 11:19:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726867AbfGFLTO (ORCPT ); Sat, 6 Jul 2019 07:19:14 -0400 Received: from mga12.intel.com ([192.55.52.136]:5514 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726702AbfGFLTO (ORCPT ); Sat, 6 Jul 2019 07:19:14 -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 fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2019 04:19:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,458,1557212400"; d="scan'208";a="363355011" 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 From: Liu Yi L To: qemu-devel@nongnu.org, mst@redhat.com, pbonzini@redhat.com, alex.williamson@redhat.com, peterx@redhat.com Cc: eric.auger@redhat.com, david@gibson.dropbear.id.au, tianyu.lan@intel.com, kevin.tian@intel.com, yi.l.liu@intel.com, jun.j.tian@intel.com, yi.y.sun@intel.com, kvm@vger.kernel.org, Jacob Pan , Yi Sun Subject: [RFC v1 08/18] vfio/pci: add vfio bind/unbind_gpasid implementation 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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; } +static void vfio_pci_device_bind_gpasid(PCIBus *bus, int32_t devfn, + struct gpasid_bind_data *g_bind_data) +{ + PCIDevice *pdev = bus->devices[devfn]; + VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOContainer *container = vdev->vbasedev.group->container; + struct vfio_iommu_type1_bind *bind; + struct vfio_iommu_type1_bind_guest_pasid *bind_guest_pasid; + unsigned long argsz; + + argsz = sizeof(*bind) + sizeof(*bind_guest_pasid); + bind = g_malloc0(argsz); + bind->argsz = argsz; + bind->bind_type = VFIO_IOMMU_BIND_GUEST_PASID; + bind_guest_pasid = (struct vfio_iommu_type1_bind_guest_pasid *) &bind->data; + bind_guest_pasid->bind_data = *g_bind_data; + + rcu_read_lock(); + if (ioctl(container->fd, VFIO_IOMMU_BIND, bind) != 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 = bus->devices[devfn]; + VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOContainer *container = vdev->vbasedev.group->container; + struct vfio_iommu_type1_bind *bind; + struct vfio_iommu_type1_bind_guest_pasid *bind_guest_pasid; + unsigned long argsz; + + argsz = sizeof(*bind) + sizeof(*bind_guest_pasid); + bind = g_malloc0(argsz); + bind->argsz = argsz; + bind->bind_type = VFIO_IOMMU_BIND_GUEST_PASID; + bind_guest_pasid = (struct vfio_iommu_type1_bind_guest_pasid *) &bind->data; + bind_guest_pasid->bind_data = *g_bind_data; + + rcu_read_lock(); + if (ioctl(container->fd, VFIO_IOMMU_UNBIND, bind) != 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 = { .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, }; static void vfio_realize(PCIDevice *pdev, Error **errp) -- 2.7.4