[PATCH v3 02/20] iommu/apple-dart: Remove detach_dev callback

Lu Baolu posted 20 patches 2 years, 9 months ago
There is a newer version of this series
[PATCH v3 02/20] iommu/apple-dart: Remove detach_dev callback
Posted by Lu Baolu 2 years, 9 months ago
The IOMMU driver supports default domain, so the detach_dev op will never
be called. Remove it to avoid dead code.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/apple-dart.c | 17 -----------------
 1 file changed, 17 deletions(-)

diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
index 4f4a323be0d0..6fbe6b275c79 100644
--- a/drivers/iommu/apple-dart.c
+++ b/drivers/iommu/apple-dart.c
@@ -535,22 +535,6 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
 	return ret;
 }
 
-static void apple_dart_detach_dev(struct iommu_domain *domain,
-				  struct device *dev)
-{
-	int i;
-	struct apple_dart_stream_map *stream_map;
-	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
-	struct apple_dart_domain *dart_domain = to_dart_domain(domain);
-
-	for_each_stream_map(i, cfg, stream_map)
-		apple_dart_hw_disable_dma(stream_map);
-
-	if (domain->type == IOMMU_DOMAIN_DMA ||
-	    domain->type == IOMMU_DOMAIN_UNMANAGED)
-		apple_dart_domain_remove_streams(dart_domain, cfg);
-}
-
 static struct iommu_device *apple_dart_probe_device(struct device *dev)
 {
 	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
@@ -780,7 +764,6 @@ static const struct iommu_ops apple_dart_iommu_ops = {
 	.owner = THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= apple_dart_attach_dev,
-		.detach_dev	= apple_dart_detach_dev,
 		.map_pages	= apple_dart_map_pages,
 		.unmap_pages	= apple_dart_unmap_pages,
 		.flush_iotlb_all = apple_dart_flush_iotlb_all,
-- 
2.34.1
Re: [PATCH v3 02/20] iommu/apple-dart: Remove detach_dev callback
Posted by Sven Peter 2 years, 9 months ago
Hi,

On Mon, Nov 28, 2022, at 07:46, Lu Baolu wrote:
> The IOMMU driver supports default domain, so the detach_dev op will never
> be called. Remove it to avoid dead code.
>
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> ---

Reviewed-by: Sven Peter <sven@svenpeter.dev>

>  drivers/iommu/apple-dart.c | 17 -----------------
>  1 file changed, 17 deletions(-)
>
> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
> index 4f4a323be0d0..6fbe6b275c79 100644
> --- a/drivers/iommu/apple-dart.c
> +++ b/drivers/iommu/apple-dart.c
> @@ -535,22 +535,6 @@ static int apple_dart_attach_dev(struct 
> iommu_domain *domain,
>  	return ret;
>  }
> 
> -static void apple_dart_detach_dev(struct iommu_domain *domain,
> -				  struct device *dev)
> -{

Thanks for cleaning this entire API up!

It actually turns out that this is slightly broken because I assumed that
detach_dev would always be called for any attach_dev. I think the only
consequence for a device that used to be assigned to domain A and is now moved to
domain B is that any TLB flushes required for A will still flush the TLB for that
device.

That's not a big deal but I'll eventually send a fix.

> -	int i;
> -	struct apple_dart_stream_map *stream_map;
> -	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
> -	struct apple_dart_domain *dart_domain = to_dart_domain(domain);
> -
> -	for_each_stream_map(i, cfg, stream_map)
> -		apple_dart_hw_disable_dma(stream_map);
> -
> -	if (domain->type == IOMMU_DOMAIN_DMA ||
> -	    domain->type == IOMMU_DOMAIN_UNMANAGED)
> -		apple_dart_domain_remove_streams(dart_domain, cfg);

Something might complain about unused apple_dart_domain_remove_streams now.
Might make sense to drop that for now as well.



Best,

Sven
Re: [PATCH v3 02/20] iommu/apple-dart: Remove detach_dev callback
Posted by Baolu Lu 2 years, 9 months ago
On 2022/12/1 1:00, Sven Peter wrote:
> On Mon, Nov 28, 2022, at 07:46, Lu Baolu wrote:
>> The IOMMU driver supports default domain, so the detach_dev op will never
>> be called. Remove it to avoid dead code.
>>
>> Signed-off-by: Lu Baolu<baolu.lu@linux.intel.com>
>> ---
> Reviewed-by: Sven Peter<sven@svenpeter.dev>
> 
>>   drivers/iommu/apple-dart.c | 17 -----------------
>>   1 file changed, 17 deletions(-)
>>
>> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
>> index 4f4a323be0d0..6fbe6b275c79 100644
>> --- a/drivers/iommu/apple-dart.c
>> +++ b/drivers/iommu/apple-dart.c
>> @@ -535,22 +535,6 @@ static int apple_dart_attach_dev(struct
>> iommu_domain *domain,
>>   	return ret;
>>   }
>>
>> -static void apple_dart_detach_dev(struct iommu_domain *domain,
>> -				  struct device *dev)
>> -{
> Thanks for cleaning this entire API up!
> 
> It actually turns out that this is slightly broken because I assumed that
> detach_dev would always be called for any attach_dev. I think the only
> consequence for a device that used to be assigned to domain A and is now moved to
> domain B is that any TLB flushes required for A will still flush the TLB for that
> device.
> 
> That's not a big deal but I'll eventually send a fix.
> 
>> -	int i;
>> -	struct apple_dart_stream_map *stream_map;
>> -	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
>> -	struct apple_dart_domain *dart_domain = to_dart_domain(domain);
>> -
>> -	for_each_stream_map(i, cfg, stream_map)
>> -		apple_dart_hw_disable_dma(stream_map);
>> -
>> -	if (domain->type == IOMMU_DOMAIN_DMA ||
>> -	    domain->type == IOMMU_DOMAIN_UNMANAGED)
>> -		apple_dart_domain_remove_streams(dart_domain, cfg);
> Something might complain about unused apple_dart_domain_remove_streams now.
> Might make sense to drop that for now as well.

Done. Thanks!

Best regards,
baolu
Re: [PATCH v3 02/20] iommu/apple-dart: Remove detach_dev callback
Posted by Jason Gunthorpe 2 years, 9 months ago
On Mon, Nov 28, 2022 at 02:46:30PM +0800, Lu Baolu wrote:
> The IOMMU driver supports default domain, so the detach_dev op will never
> be called. Remove it to avoid dead code.
> 
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> ---
>  drivers/iommu/apple-dart.c | 17 -----------------
>  1 file changed, 17 deletions(-)

I suspect this is doing the blocking domain behavior..

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Jason