From patchwork Thu Jan 6 02:20:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 12705016 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68D6DC433EF for ; Thu, 6 Jan 2022 02:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344693AbiAFCV6 (ORCPT ); Wed, 5 Jan 2022 21:21:58 -0500 Received: from mga06.intel.com ([134.134.136.31]:40628 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231945AbiAFCV4 (ORCPT ); Wed, 5 Jan 2022 21:21:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641435716; x=1672971716; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xKGR4J0OSP6uicbqMFdEjKsyZ291es72vzJYC31FqCM=; b=UkzgLYhy0TijKNKyTDtiI2dE0qGRgt5YTi76pCMYmUqIzW+qDjzRpAUV hCNCSs6aL/rBBQsP/saXwlPy5qunFDVGNGQ6apI3nlXifovcqBi2PqlGg a2kuXWp7lMjo78gn9VeURfIFNIwHIlQnpb+vMaS5Z7VPPVE97LBp4XxRV xEGNTZklolXVEnlzn7M0z4qZXTavfycOu0pI0rX/QgNSW6IXdhhDWEOjN z8E4w7qAnJxYyzouByw8FXuNvMbWfwh4TqVNX8O8uLCBj+Hc7CsIkl+7i 37aIQtT7YeB99vG7ZRMnlmKRuhzTNFOvuHGt9xC6yISXLTHHytWhMwqpI w==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="303325586" X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="303325586" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 18:21:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="526794284" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga008.jf.intel.com with ESMTP; 05 Jan 2022 18:21:49 -0800 From: Lu Baolu To: Joerg Roedel , Alex Williamson , Robin Murphy , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj Cc: Greg Kroah-Hartman , Bjorn Helgaas , Will Deacon , Dan Williams , rafael@kernel.org, Diana Craciun , Cornelia Huck , Eric Auger , Liu Yi L , Jacob jun Pan , Chaitanya Kulkarni , Stuart Yoder , Laurentiu Tudor , Thierry Reding , David Airlie , Daniel Vetter , Jonathan Hunter , Li Yang , Dmitry Osipenko , iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v1 1/8] iommu: Add iommu_group_replace_domain() Date: Thu, 6 Jan 2022 10:20:46 +0800 Message-Id: <20220106022053.2406748-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106022053.2406748-1-baolu.lu@linux.intel.com> References: <20220106022053.2406748-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Expose an interface to replace the domain of an iommu group for frameworks like vfio which claims the ownership of the whole iommu group. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 10 ++++++++++ drivers/iommu/iommu.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 408a6d2b3034..66ebce3d1e11 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -677,6 +677,9 @@ void iommu_device_unuse_dma_api(struct device *dev); int iommu_group_set_dma_owner(struct iommu_group *group, void *owner); void iommu_group_release_dma_owner(struct iommu_group *group); bool iommu_group_dma_owner_claimed(struct iommu_group *group); +int iommu_group_replace_domain(struct iommu_group *group, + struct iommu_domain *old, + struct iommu_domain *new); #else /* CONFIG_IOMMU_API */ @@ -1090,6 +1093,13 @@ static inline bool iommu_group_dma_owner_claimed(struct iommu_group *group) { return false; } + +static inline int +iommu_group_replace_domain(struct iommu_group *group, struct iommu_domain *old, + struct iommu_domain *new) +{ + return -ENODEV; +} #endif /* CONFIG_IOMMU_API */ /** diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 72a95dea688e..ab8ab95969f5 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3431,3 +3431,40 @@ bool iommu_group_dma_owner_claimed(struct iommu_group *group) return user; } EXPORT_SYMBOL_GPL(iommu_group_dma_owner_claimed); + +/** + * iommu_group_replace_domain() - Replace group's domain + * @group: The group. + * @old: The previous attached domain. NULL for none. + * @new: The new domain about to be attached. + * + * This is to support backward compatibility for vfio which manages the dma + * ownership in iommu_group level. + */ +int iommu_group_replace_domain(struct iommu_group *group, + struct iommu_domain *old, + struct iommu_domain *new) +{ + int ret = 0; + + mutex_lock(&group->mutex); + if (!group->owner || group->domain != old) { + ret = -EPERM; + goto unlock_out; + } + + if (old) + __iommu_detach_group(old, group); + + if (new) { + ret = __iommu_attach_group(new, group); + if (ret && old) + __iommu_attach_group(old, group); + } + +unlock_out: + mutex_unlock(&group->mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(iommu_group_replace_domain); From patchwork Thu Jan 6 02:20:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 12705017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68DB3C4332F for ; Thu, 6 Jan 2022 02:22:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344703AbiAFCWG (ORCPT ); Wed, 5 Jan 2022 21:22:06 -0500 Received: from mga18.intel.com ([134.134.136.126]:45646 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231945AbiAFCWD (ORCPT ); Wed, 5 Jan 2022 21:22:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641435723; x=1672971723; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6YLQxZeVjKNGLWHBhbTA2BZXJ8CXUGVnJDAzUyu/JQ8=; b=dOXqKwqh645TYN6QVRP1EvlzKn3p/ZxwzbGR1je8o52TWuj9c6JGh4Bp LOJSaDkAsUfcmqJ/LvYwHqKKDmOzsvOeEe6b41tHBIgQpe1zaf7bm4ZbC gVWIyt+cm/379z5QpOvJtDBnx9wZI00MRvo5F5N40gXAwL0diuhIfHtPH u/CULbfEknDes6fH25QxGT3kr76zkRMTtyQ7Tch8AAVKVywsxI52wl1Wq yHwg5JAKMiL+I5mPSWuNBPywD/+lA0ocEUPNQ9S2P5Sds8LtIszk66ts9 qkmfO1OWqrckuv7Er00IdoEr8aN5MFMN8swYX2Q52SCESbIjG+Yr8AEpx A==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="229389174" X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="229389174" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 18:22:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="526794313" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga008.jf.intel.com with ESMTP; 05 Jan 2022 18:21:56 -0800 From: Lu Baolu To: Joerg Roedel , Alex Williamson , Robin Murphy , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj Cc: Greg Kroah-Hartman , Bjorn Helgaas , Will Deacon , Dan Williams , rafael@kernel.org, Diana Craciun , Cornelia Huck , Eric Auger , Liu Yi L , Jacob jun Pan , Chaitanya Kulkarni , Stuart Yoder , Laurentiu Tudor , Thierry Reding , David Airlie , Daniel Vetter , Jonathan Hunter , Li Yang , Dmitry Osipenko , iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v1 2/8] vfio/type1: Use iommu_group_replace_domain() Date: Thu, 6 Jan 2022 10:20:47 +0800 Message-Id: <20220106022053.2406748-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106022053.2406748-1-baolu.lu@linux.intel.com> References: <20220106022053.2406748-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org After an IOMMU group is placed in a vfio container, the domain attachment may be deferred. During this process, other kernel modules can attach another domain simply in the following way: group = iommu_group_get(dev); iommu_attach_group(domain, group); Replace the iommu_attach/detach_group() with iommu_group_replace_domain() and prohibit use of iommu_attach/detach_group() in other kernel drivers can solve this problem. Suggested-by: Jason Gunthorpe Signed-off-by: Lu Baolu --- drivers/vfio/vfio_iommu_type1.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index f17490ab238f..25276a5db737 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -2213,7 +2213,8 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, goto out_domain; } - ret = iommu_attach_group(domain->domain, group->iommu_group); + ret = iommu_group_replace_domain(group->iommu_group, NULL, + domain->domain); if (ret) goto out_domain; @@ -2280,19 +2281,14 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, list_for_each_entry(d, &iommu->domain_list, next) { if (d->domain->ops == domain->domain->ops && d->prot == domain->prot) { - iommu_detach_group(domain->domain, group->iommu_group); - if (!iommu_attach_group(d->domain, - group->iommu_group)) { + if (!iommu_group_replace_domain(group->iommu_group, + domain->domain, + d->domain)) { list_add(&group->next, &d->group_list); iommu_domain_free(domain->domain); kfree(domain); goto done; } - - ret = iommu_attach_group(domain->domain, - group->iommu_group); - if (ret) - goto out_domain; } } @@ -2327,7 +2323,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, return 0; out_detach: - iommu_detach_group(domain->domain, group->iommu_group); + iommu_group_replace_domain(group->iommu_group, domain->domain, NULL); out_domain: iommu_domain_free(domain->domain); vfio_iommu_iova_free(&iova_copy); @@ -2488,7 +2484,8 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, if (!group) continue; - iommu_detach_group(domain->domain, group->iommu_group); + iommu_group_replace_domain(group->iommu_group, + domain->domain, NULL); update_dirty_scope = !group->pinned_page_dirty_scope; list_del(&group->next); kfree(group); @@ -2577,7 +2574,8 @@ static void vfio_release_domain(struct vfio_domain *domain) list_for_each_entry_safe(group, group_tmp, &domain->group_list, next) { - iommu_detach_group(domain->domain, group->iommu_group); + iommu_group_replace_domain(group->iommu_group, + domain->domain, NULL); list_del(&group->next); kfree(group); } From patchwork Thu Jan 6 02:20:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 12705019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BA83C433F5 for ; Thu, 6 Jan 2022 02:22:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344739AbiAFCW2 (ORCPT ); Wed, 5 Jan 2022 21:22:28 -0500 Received: from mga06.intel.com ([134.134.136.31]:40662 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231945AbiAFCWU (ORCPT ); Wed, 5 Jan 2022 21:22:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641435740; x=1672971740; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=clG1gjGvOL9BSMyPbqgYNxozZZwO9e7BVS3UogrjHAs=; b=Jl0YoOAKf3sWnyc7zprPr4I4kHkE3GmrJBwxEa/36P/JBFpSzXChAQb5 J5sS4WGGyfgbAkpVG+KXkBPD4UCqfkbjTw2ogvxOObPZi9jYLwwt9kncI ieCYQH7V9ExNqlS6S8CP2jhz0oDZGEZcTtQmgUF+SqAn472NBa9iwVlF5 Em7JWOmiXhMfgDFM3HHN/e6VFywaDhJGMABLEAKu1/DVUOKMqLC37o4rh UUF+oXVud4J2joYN95NKr2qPHHPWZYlAuD7wJ3DGLKZbyFjnqQdUSeh+v GJ1iUhFpI6zWs8ekSsHDU7YXguV4JmyfPb1hsB5IDEsD9P/PWxeBGxH/F g==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="303325620" X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="303325620" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 18:22:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="526794333" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga008.jf.intel.com with ESMTP; 05 Jan 2022 18:22:03 -0800 From: Lu Baolu To: Joerg Roedel , Alex Williamson , Robin Murphy , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj Cc: Greg Kroah-Hartman , Bjorn Helgaas , Will Deacon , Dan Williams , rafael@kernel.org, Diana Craciun , Cornelia Huck , Eric Auger , Liu Yi L , Jacob jun Pan , Chaitanya Kulkarni , Stuart Yoder , Laurentiu Tudor , Thierry Reding , David Airlie , Daniel Vetter , Jonathan Hunter , Li Yang , Dmitry Osipenko , iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v1 3/8] iommu: Extend iommu_at[de]tach_device() for multi-device groups Date: Thu, 6 Jan 2022 10:20:48 +0800 Message-Id: <20220106022053.2406748-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106022053.2406748-1-baolu.lu@linux.intel.com> References: <20220106022053.2406748-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The iommu_attach/detach_device() interfaces were exposed for the device drivers to attach/detach their own domains. The commit <426a273834eae> ("iommu: Limit iommu_attach/detach_device to device with their own group") restricted them to singleton groups to avoid different device in a group attaching different domain. As we've introduced device DMA ownership into the iommu core. We can now extend these interfaces for muliple-device groups, and "all devices are in the same address space" is still guaranteed. For multiple devices belonging to a same group, iommu_device_use_dma_api() and iommu_attach_device() are exclusive. Therefore, when drivers decide to use iommu_attach_domain(), they cannot call iommu_device_use_dma_api() at the same time. Signed-off-by: Jason Gunthorpe Signed-off-by: Lu Baolu --- drivers/iommu/iommu.c | 79 +++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index ab8ab95969f5..2c9efd85e447 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -47,6 +47,7 @@ struct iommu_group { struct iommu_domain *domain; struct list_head entry; unsigned int owner_cnt; + unsigned int attach_cnt; void *owner; }; @@ -1921,27 +1922,59 @@ static int __iommu_attach_device(struct iommu_domain *domain, return ret; } +/** + * iommu_attach_device() - attach external or UNMANAGED domain to device + * @domain: the domain about to attach + * @dev: the device about to be attached + * + * For devices belonging to the same group, iommu_device_use_dma_api() and + * iommu_attach_device() are exclusive. Therefore, when drivers decide to + * use iommu_attach_domain(), they cannot call iommu_device_use_dma_api() + * at the same time. + */ int iommu_attach_device(struct iommu_domain *domain, struct device *dev) { struct iommu_group *group; - int ret; + int ret = 0; + + if (domain->type != IOMMU_DOMAIN_UNMANAGED) + return -EINVAL; group = iommu_group_get(dev); if (!group) return -ENODEV; - /* - * Lock the group to make sure the device-count doesn't - * change while we are attaching - */ mutex_lock(&group->mutex); - ret = -EINVAL; - if (iommu_group_device_count(group) != 1) - goto out_unlock; + if (group->owner_cnt) { + /* + * Group has been used for kernel-api dma or claimed explicitly + * for exclusive occupation. For backward compatibility, device + * in a singleton group is allowed to ignore setting the + * drv.no_kernel_api_dma field. + */ + if ((group->domain == group->default_domain && + iommu_group_device_count(group) != 1) || + group->owner) { + ret = -EBUSY; + goto unlock_out; + } + } - ret = __iommu_attach_group(domain, group); + if (!group->attach_cnt) { + ret = __iommu_attach_group(domain, group); + if (ret) + goto unlock_out; + } else { + if (group->domain != domain) { + ret = -EPERM; + goto unlock_out; + } + } -out_unlock: + group->owner_cnt++; + group->attach_cnt++; + +unlock_out: mutex_unlock(&group->mutex); iommu_group_put(group); @@ -2182,23 +2215,35 @@ static void __iommu_detach_device(struct iommu_domain *domain, trace_detach_device_from_domain(dev); } +/** + * iommu_detach_device() - detach external or UNMANAGED domain from device + * @domain: the domain about to detach + * @dev: the device about to be detached + * + * Paired with iommu_attach_device(), it detaches the domain from the device. + */ void iommu_detach_device(struct iommu_domain *domain, struct device *dev) { struct iommu_group *group; + if (WARN_ON(domain->type != IOMMU_DOMAIN_UNMANAGED)) + return; + group = iommu_group_get(dev); - if (!group) + if (WARN_ON(!group)) return; mutex_lock(&group->mutex); - if (iommu_group_device_count(group) != 1) { - WARN_ON(1); - goto out_unlock; - } + if (WARN_ON(!group->attach_cnt || !group->owner_cnt || + group->domain != domain)) + goto unlock_out; - __iommu_detach_group(domain, group); + group->attach_cnt--; + group->owner_cnt--; + if (!group->attach_cnt) + __iommu_detach_group(domain, group); -out_unlock: +unlock_out: mutex_unlock(&group->mutex); iommu_group_put(group); } From patchwork Thu Jan 6 02:20:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 12705018 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 346CDC433FE for ; Thu, 6 Jan 2022 02:22:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344702AbiAFCWX (ORCPT ); Wed, 5 Jan 2022 21:22:23 -0500 Received: from mga09.intel.com ([134.134.136.24]:10004 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344746AbiAFCWT (ORCPT ); Wed, 5 Jan 2022 21:22:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641435738; x=1672971738; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8AHskV6R7ecHOW1ezHMh2nWxqBL3edvB+iZHHwk5/6w=; b=iN5SikttukiMicRQj1Uxxjy6lm0BTFGMQCLc5BXckzclicyrF6HNAGGx W9CIYt3WN4seYw76YZRouttcjFcvhzdw46LHPbEAT6Sjwfj79FpTgf8sz 5vxu+9d2R0f+RIHXsuNB8+chyVSttEjvwJC6Qkf1p67OdLBqm9PUweD6q wg7wQxBfwAUhBpPshzjbb29UvxPSA5Bud8+YOz7kWttnwL0W8dxa6zjb4 X9rJFRpkOGSpidiP11mWe7QklhJCR5jpP5OFyGuKIEs5QYp7hc2q4Rhmb 0d8Ig34k7dvQWDA3Wcz0DVobm/FgL2jVkd6LU10LiHdApOf+Bm4VPi5cp Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="242371376" X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="242371376" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 18:22:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="526794374" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga008.jf.intel.com with ESMTP; 05 Jan 2022 18:22:10 -0800 From: Lu Baolu To: Joerg Roedel , Alex Williamson , Robin Murphy , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj Cc: Greg Kroah-Hartman , Bjorn Helgaas , Will Deacon , Dan Williams , rafael@kernel.org, Diana Craciun , Cornelia Huck , Eric Auger , Liu Yi L , Jacob jun Pan , Chaitanya Kulkarni , Stuart Yoder , Laurentiu Tudor , Thierry Reding , David Airlie , Daniel Vetter , Jonathan Hunter , Li Yang , Dmitry Osipenko , iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v1 4/8] drm/tegra: Use iommu_attach/detatch_device() Date: Thu, 6 Jan 2022 10:20:49 +0800 Message-Id: <20220106022053.2406748-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106022053.2406748-1-baolu.lu@linux.intel.com> References: <20220106022053.2406748-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Jason Gunthorpe Tegra joins many platform devices onto the same iommu_domain and builds sort-of a DMA API on top of it. Given that iommu_attach/detatch_device() has supported this usage model, each device that wants to use the special domain could set the no_kernel_api_dma field of the driver structure and call iommu_attach/detach_device() directly which will use dma owner framework to lock out other usages of the group and refcount the domain attachment. When the last device calls detatch the domain will be disconnected. Signed-off-by: Jason Gunthorpe Signed-off-by: Lu Baolu --- drivers/gpu/drm/tegra/dc.c | 1 + drivers/gpu/drm/tegra/drm.c | 47 ++++++++++++------------------------ drivers/gpu/drm/tegra/gr2d.c | 1 + drivers/gpu/drm/tegra/gr3d.c | 1 + drivers/gpu/drm/tegra/vic.c | 1 + 5 files changed, 20 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c index a29d64f87563..0da50b39ce00 100644 --- a/drivers/gpu/drm/tegra/dc.c +++ b/drivers/gpu/drm/tegra/dc.c @@ -3111,4 +3111,5 @@ struct platform_driver tegra_dc_driver = { }, .probe = tegra_dc_probe, .remove = tegra_dc_remove, + .no_kernel_api_dma = true, }; diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c index 8d37d6b00562..d6c57a40b772 100644 --- a/drivers/gpu/drm/tegra/drm.c +++ b/drivers/gpu/drm/tegra/drm.c @@ -928,12 +928,15 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra, return 0; } +/* + * Clients which use this function must set suppress_auto_claim_dma_owner in + * their platform_driver's device_driver struct. + */ int host1x_client_iommu_attach(struct host1x_client *client) { struct iommu_domain *domain = iommu_get_domain_for_dev(client->dev); struct drm_device *drm = dev_get_drvdata(client->host); struct tegra_drm *tegra = drm->dev_private; - struct iommu_group *group = NULL; int err; /* @@ -941,48 +944,30 @@ int host1x_client_iommu_attach(struct host1x_client *client) * not the shared IOMMU domain, don't try to attach it to a different * domain. This allows using the IOMMU-backed DMA API. */ - if (domain && domain != tegra->domain) - return 0; - - if (tegra->domain) { - group = iommu_group_get(client->dev); - if (!group) - return -ENODEV; - - if (domain != tegra->domain) { - err = iommu_attach_group(tegra->domain, group); - if (err < 0) { - iommu_group_put(group); - return err; - } - } - - tegra->use_explicit_iommu = true; - } + client->group = NULL; + if (!client->dev->iommu_group || (domain && domain != tegra->domain)) + return iommu_device_use_dma_api(client->dev); - client->group = group; + err = iommu_attach_device(tegra->domain, client->dev); + if (err) + return err; + tegra->use_explicit_iommu = true; + client->group = client->dev->iommu_group; return 0; } void host1x_client_iommu_detach(struct host1x_client *client) { + struct iommu_domain *domain = iommu_get_domain_for_dev(client->dev); struct drm_device *drm = dev_get_drvdata(client->host); struct tegra_drm *tegra = drm->dev_private; - struct iommu_domain *domain; if (client->group) { - /* - * Devices that are part of the same group may no longer be - * attached to a domain at this point because their group may - * have been detached by an earlier client. - */ - domain = iommu_get_domain_for_dev(client->dev); - if (domain) - iommu_detach_group(tegra->domain, client->group); - - iommu_group_put(client->group); + iommu_detach_device(tegra->domain, client->dev); client->group = NULL; + } else { + iommu_device_unuse_dma_api(client->dev); } } diff --git a/drivers/gpu/drm/tegra/gr2d.c b/drivers/gpu/drm/tegra/gr2d.c index de288cba3905..6fd502c1cdbf 100644 --- a/drivers/gpu/drm/tegra/gr2d.c +++ b/drivers/gpu/drm/tegra/gr2d.c @@ -271,4 +271,5 @@ struct platform_driver tegra_gr2d_driver = { }, .probe = gr2d_probe, .remove = gr2d_remove, + .no_kernel_api_dma = true, }; diff --git a/drivers/gpu/drm/tegra/gr3d.c b/drivers/gpu/drm/tegra/gr3d.c index 24442ade0da3..d47794b6394f 100644 --- a/drivers/gpu/drm/tegra/gr3d.c +++ b/drivers/gpu/drm/tegra/gr3d.c @@ -400,4 +400,5 @@ struct platform_driver tegra_gr3d_driver = { }, .probe = gr3d_probe, .remove = gr3d_remove, + .no_kernel_api_dma = true, }; diff --git a/drivers/gpu/drm/tegra/vic.c b/drivers/gpu/drm/tegra/vic.c index c02010ff2b7f..167de5509c3b 100644 --- a/drivers/gpu/drm/tegra/vic.c +++ b/drivers/gpu/drm/tegra/vic.c @@ -527,6 +527,7 @@ struct platform_driver tegra_vic_driver = { }, .probe = vic_probe, .remove = vic_remove, + .no_kernel_api_dma = true, }; #if IS_ENABLED(CONFIG_ARCH_TEGRA_124_SOC) From patchwork Thu Jan 6 02:20:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 12705020 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F30A6C433EF for ; Thu, 6 Jan 2022 02:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344770AbiAFCWi (ORCPT ); Wed, 5 Jan 2022 21:22:38 -0500 Received: from mga06.intel.com ([134.134.136.31]:40662 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344734AbiAFCW0 (ORCPT ); Wed, 5 Jan 2022 21:22:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641435746; x=1672971746; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rk6a+5igN4LBX3L4wUsmQbl/BtWrVs0e5Y+7ihAeHL8=; b=hVTBORazkuSD8onwYqW6Nk/Pkdvi2sKvgBb9QSPtil4MfBavvbbUQ/vl x5PxpNpOGNc5MwQVVztcio5hLdZL6cmKysAnAE50LseYT8ZMT0leXfVe8 4bqqbL3A9gy9n8nHW8RjXdGJ8HegV0bmEQbXKBl6jTTGJ2JHKwZeeDPAd kQj6uCJjqzWH9FozI29oOYHYtdejAuheT1eclwVIsS9Mv9/UzX+JIEouo 7IHzXJk42S3tBbXBtcYtqD1ELoin5ixoN5DPI/CRphGvLTyPWGXTmrvUz OoB0/5OdWoDN6p5GKOGbQL+BhrszAWCUlxpT3xG//12+RxX4WSkqG3Lp2 g==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="303325635" X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="303325635" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 18:22:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="526794416" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga008.jf.intel.com with ESMTP; 05 Jan 2022 18:22:17 -0800 From: Lu Baolu To: Joerg Roedel , Alex Williamson , Robin Murphy , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj Cc: Greg Kroah-Hartman , Bjorn Helgaas , Will Deacon , Dan Williams , rafael@kernel.org, Diana Craciun , Cornelia Huck , Eric Auger , Liu Yi L , Jacob jun Pan , Chaitanya Kulkarni , Stuart Yoder , Laurentiu Tudor , Thierry Reding , David Airlie , Daniel Vetter , Jonathan Hunter , Li Yang , Dmitry Osipenko , iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v1 5/8] iommu/amd: Use iommu_attach/detach_device() Date: Thu, 6 Jan 2022 10:20:50 +0800 Message-Id: <20220106022053.2406748-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106022053.2406748-1-baolu.lu@linux.intel.com> References: <20220106022053.2406748-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The individual device driver should use iommu_attach/detach_device() for domain attachment/detachment. Signed-off-by: Lu Baolu --- drivers/iommu/amd/iommu_v2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/amd/iommu_v2.c b/drivers/iommu/amd/iommu_v2.c index 58da08cc3d01..7d9d0fe89064 100644 --- a/drivers/iommu/amd/iommu_v2.c +++ b/drivers/iommu/amd/iommu_v2.c @@ -133,7 +133,7 @@ static void free_device_state(struct device_state *dev_state) if (WARN_ON(!group)) return; - iommu_detach_group(dev_state->domain, group); + iommu_detach_device(dev_state->domain, &dev_state->pdev->dev); iommu_group_put(group); @@ -791,7 +791,7 @@ int amd_iommu_init_device(struct pci_dev *pdev, int pasids) goto out_free_domain; } - ret = iommu_attach_group(dev_state->domain, group); + ret = iommu_attach_device(dev_state->domain, &pdev->dev); if (ret != 0) goto out_drop_group; From patchwork Thu Jan 6 02:20:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 12705021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60246C433F5 for ; Thu, 6 Jan 2022 02:23:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344843AbiAFCXD (ORCPT ); Wed, 5 Jan 2022 21:23:03 -0500 Received: from mga18.intel.com ([134.134.136.126]:45674 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344750AbiAFCWc (ORCPT ); Wed, 5 Jan 2022 21:22:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641435751; x=1672971751; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GDCUJufXvlu7Z20AypZ4GsZd9L9C8y8eFXL56cSyTrE=; b=A93kSzd8hs2KrJ8Tk8sCxIHEXc7epR5IYy2mOhdMLX9k69XP3KYD6lS1 NABwp+FaDCxcxJv8zF5wvqnEwLxi5NzGI3glW/idGSFxk17QCh8dHwPZC QVqs9e/aewY4qOIbVak4ikSUTAcypB3OqugDd2U5xvhHj/xUYXJpfRz/e 12mvzQgzUFHUgBeQCDvuNhdhwx+Dzc1vpdM3rg0soNBtsTiMperI2HvLa tOSuZxXOVaeD/0+k5F3bDiJl45Iglz7ARsoGq0iGpz91R5VRu8RVbbgN/ Pj5zTEI2RQM9kT4RZaIzUzw9Rj37QvbyATBUFCCXCy2e/pBQRZACU+3Df A==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="229389218" X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="229389218" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 18:22:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="526794466" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga008.jf.intel.com with ESMTP; 05 Jan 2022 18:22:24 -0800 From: Lu Baolu To: Joerg Roedel , Alex Williamson , Robin Murphy , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj Cc: Greg Kroah-Hartman , Bjorn Helgaas , Will Deacon , Dan Williams , rafael@kernel.org, Diana Craciun , Cornelia Huck , Eric Auger , Liu Yi L , Jacob jun Pan , Chaitanya Kulkarni , Stuart Yoder , Laurentiu Tudor , Thierry Reding , David Airlie , Daniel Vetter , Jonathan Hunter , Li Yang , Dmitry Osipenko , iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v1 6/8] gpu/host1x: Use iommu_attach/detach_device() Date: Thu, 6 Jan 2022 10:20:51 +0800 Message-Id: <20220106022053.2406748-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106022053.2406748-1-baolu.lu@linux.intel.com> References: <20220106022053.2406748-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Ordinary drivers should use iommu_attach/detach_device() for domain attaching and detaching. Signed-off-by: Lu Baolu --- drivers/gpu/host1x/dev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c index fbb6447b8659..6e08cb6202cc 100644 --- a/drivers/gpu/host1x/dev.c +++ b/drivers/gpu/host1x/dev.c @@ -265,7 +265,7 @@ static struct iommu_domain *host1x_iommu_attach(struct host1x *host) goto put_cache; } - err = iommu_attach_group(host->domain, host->group); + err = iommu_attach_device(host->domain, host->dev); if (err) { if (err == -ENODEV) err = 0; @@ -335,7 +335,7 @@ static void host1x_iommu_exit(struct host1x *host) { if (host->domain) { put_iova_domain(&host->iova); - iommu_detach_group(host->domain, host->group); + iommu_detach_device(host->domain, host->dev); iommu_domain_free(host->domain); host->domain = NULL; From patchwork Thu Jan 6 02:20:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 12705031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF36BC433EF for ; Thu, 6 Jan 2022 02:24:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344905AbiAFCX7 (ORCPT ); Wed, 5 Jan 2022 21:23:59 -0500 Received: from mga12.intel.com ([192.55.52.136]:3335 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344796AbiAFCWu (ORCPT ); Wed, 5 Jan 2022 21:22:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641435770; x=1672971770; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rJCHc+7rEGzzzZ26n+LFYyMzqMy4eMF/FP0CIBhFlrQ=; b=SGfXpxd5qSC07R+OUutcwmIaPCNy4ucqI2ie6pYbWnnzpW+HcXllrlpF svEqf77IByGegIly9V3oYs0w5h6JZRa//VQq7Q0JE45qyNBCTf7Z0RU1I 8n4HMATaqIc8JB7RES+k8KYRjX7GknjbVnK8W6iOAERVdBcMD2LgdgGDS nFCTwyRqBPslNHzJQqrJsi0f9ihX9nAKExJph0vCb7QrI6pITivT3/ozY X93bjBpJF8aG7wjh9Gz/6HnCgNTQdFJsMRa0F8TTiasv6ZjoSEwmNqOZV by3StD86ajQGv/jNXqlVwnadXhDYNP6wML/+aJb9cUYMHWAFygD18/oxD w==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="222571003" X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="222571003" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 18:22:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="526794519" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga008.jf.intel.com with ESMTP; 05 Jan 2022 18:22:31 -0800 From: Lu Baolu To: Joerg Roedel , Alex Williamson , Robin Murphy , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj Cc: Greg Kroah-Hartman , Bjorn Helgaas , Will Deacon , Dan Williams , rafael@kernel.org, Diana Craciun , Cornelia Huck , Eric Auger , Liu Yi L , Jacob jun Pan , Chaitanya Kulkarni , Stuart Yoder , Laurentiu Tudor , Thierry Reding , David Airlie , Daniel Vetter , Jonathan Hunter , Li Yang , Dmitry Osipenko , iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v1 7/8] media: staging: media: tegra-vde: Use iommu_attach/detach_device() Date: Thu, 6 Jan 2022 10:20:52 +0800 Message-Id: <20220106022053.2406748-8-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106022053.2406748-1-baolu.lu@linux.intel.com> References: <20220106022053.2406748-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Ordinary drivers should use iommu_attach/detach_device() for domain attaching and detaching. Signed-off-by: Lu Baolu --- drivers/staging/media/tegra-vde/iommu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/staging/media/tegra-vde/iommu.c b/drivers/staging/media/tegra-vde/iommu.c index adf8dc7ee25c..a6e6eb28f1e3 100644 --- a/drivers/staging/media/tegra-vde/iommu.c +++ b/drivers/staging/media/tegra-vde/iommu.c @@ -91,7 +91,7 @@ int tegra_vde_iommu_init(struct tegra_vde *vde) order = __ffs(vde->domain->pgsize_bitmap); init_iova_domain(&vde->iova, 1UL << order, 0); - err = iommu_attach_group(vde->domain, vde->group); + err = iommu_attach_device(vde->domain, dev); if (err) goto put_iova; @@ -129,7 +129,7 @@ int tegra_vde_iommu_init(struct tegra_vde *vde) unreserve_iova: __free_iova(&vde->iova, vde->iova_resv_static_addresses); detach_group: - iommu_detach_group(vde->domain, vde->group); + iommu_detach_device(vde->domain, dev); put_iova: put_iova_domain(&vde->iova); iova_cache_put(); @@ -146,7 +146,7 @@ void tegra_vde_iommu_deinit(struct tegra_vde *vde) if (vde->domain) { __free_iova(&vde->iova, vde->iova_resv_last_page); __free_iova(&vde->iova, vde->iova_resv_static_addresses); - iommu_detach_group(vde->domain, vde->group); + iommu_detach_device(vde->domain, vde->miscdev.parent); put_iova_domain(&vde->iova); iova_cache_put(); iommu_domain_free(vde->domain); From patchwork Thu Jan 6 02:20:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 12705032 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 403F8C433F5 for ; Thu, 6 Jan 2022 02:24:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344916AbiAFCYE (ORCPT ); Wed, 5 Jan 2022 21:24:04 -0500 Received: from mga12.intel.com ([192.55.52.136]:3337 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344722AbiAFCWv (ORCPT ); Wed, 5 Jan 2022 21:22:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641435771; x=1672971771; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AR5i2NMwGfSOdi+HLgKnhlt3tjHftmsXmPOft4wFOHU=; b=goOwz0FsPCDiwKiIIRNd6XvrIt+KHMOZuKcd5wpTo3Fpo/ZrRFpiseln aifPXPlKhCWy034PriWEDuE3hBwdjCLM99DSYNYAh2nAydLqcUdD2EXI1 ak7U4h35oU3PYjaDW9dQW0N/JVyXX6NgiHSJuU0MBbsNWTW//A9YgXLMa AZ7uOG1T3iIyhAx9bM1sG5yN85WTRMEvfHlKlFsEIU7t3vvzzucD6rTfp EH5dgsXLGVcDhqKQ6ce3Es213mVkJjJ6S3sYaKsKpxTcK7gWdUrWgvbwT L9DtOribYaY3aCJj+/jolE2guCSWdZ0rR2eLoUarzJ71iXy60NmAfuLPi w==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="222571011" X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="222571011" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 18:22:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,265,1635231600"; d="scan'208";a="526794556" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga008.jf.intel.com with ESMTP; 05 Jan 2022 18:22:40 -0800 From: Lu Baolu To: Joerg Roedel , Alex Williamson , Robin Murphy , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj Cc: Greg Kroah-Hartman , Bjorn Helgaas , Will Deacon , Dan Williams , rafael@kernel.org, Diana Craciun , Cornelia Huck , Eric Auger , Liu Yi L , Jacob jun Pan , Chaitanya Kulkarni , Stuart Yoder , Laurentiu Tudor , Thierry Reding , David Airlie , Daniel Vetter , Jonathan Hunter , Li Yang , Dmitry Osipenko , iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v1 8/8] iommu: Remove iommu_attach/detach_group() Date: Thu, 6 Jan 2022 10:20:53 +0800 Message-Id: <20220106022053.2406748-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106022053.2406748-1-baolu.lu@linux.intel.com> References: <20220106022053.2406748-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The iommu_attach/detach_group() interfaces have no reference in the tree anymore. Remove them to avoid dead code. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 15 --------------- drivers/iommu/iommu.c | 20 -------------------- 2 files changed, 35 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 66ebce3d1e11..2568ab0d0872 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -457,10 +457,6 @@ iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot, extern int iommu_get_group_resv_regions(struct iommu_group *group, struct list_head *head); -extern int iommu_attach_group(struct iommu_domain *domain, - struct iommu_group *group); -extern void iommu_detach_group(struct iommu_domain *domain, - struct iommu_group *group); extern struct iommu_group *iommu_group_alloc(void); extern void *iommu_group_get_iommudata(struct iommu_group *group); extern void iommu_group_set_iommudata(struct iommu_group *group, @@ -818,17 +814,6 @@ static inline bool iommu_default_passthrough(void) return true; } -static inline int iommu_attach_group(struct iommu_domain *domain, - struct iommu_group *group) -{ - return -ENODEV; -} - -static inline void iommu_detach_group(struct iommu_domain *domain, - struct iommu_group *group) -{ -} - static inline struct iommu_group *iommu_group_alloc(void) { return ERR_PTR(-ENODEV); diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 2c9efd85e447..33f7027e677f 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2308,18 +2308,6 @@ static int __iommu_attach_group(struct iommu_domain *domain, return ret; } -int iommu_attach_group(struct iommu_domain *domain, struct iommu_group *group) -{ - int ret; - - mutex_lock(&group->mutex); - ret = __iommu_attach_group(domain, group); - mutex_unlock(&group->mutex); - - return ret; -} -EXPORT_SYMBOL_GPL(iommu_attach_group); - static int iommu_group_do_detach_device(struct device *dev, void *data) { struct iommu_domain *domain = data; @@ -2357,14 +2345,6 @@ static void __iommu_detach_group(struct iommu_domain *domain, group->domain = group->default_domain; } -void iommu_detach_group(struct iommu_domain *domain, struct iommu_group *group) -{ - mutex_lock(&group->mutex); - __iommu_detach_group(domain, group); - mutex_unlock(&group->mutex); -} -EXPORT_SYMBOL_GPL(iommu_detach_group); - phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova) { if (domain->type == IOMMU_DOMAIN_IDENTITY)