Skip to contentSkip to conversation

iommu/dma: Use DMA ops setter instead of direct assignment

PATCH In review Andy Shevchenko 3 participants 4 messages Feb 7, 2022 – Feb 9, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 iommu/dma: Use DMA ops setter instead of direct assignment

Use DMA ops setter instead of direct assignment. Even we know that this module doesn't perform access to the dma_ops member of struct device, it's better to use setter to avoid potential problems in the future.

---
v2: rebased on top of the latest codebase

 drivers/iommu/dma-iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/dma-iommu.c +1 -1
index d85d54f2b549..b585a3fdbc56 100644
@@ -1482,7 +1482,7 @@ void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 dma_limit)
 	if (iommu_is_dma_domain(domain)) {
 		if (iommu_dma_init_domain(domain, dma_base, dma_limit, dev))
 			goto out_err;
-		dev->dma_ops = &iommu_dma_ops;
+		set_dma_ops(dev, &iommu_dma_ops);
 	}
 
 	return;
Signature · 6 lines
2.34.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
maintainer
#1 lore raw
Quoted 3 lines · Andy Shevchenko

Use DMA ops setter instead of direct assignment. Even we know that this module doesn't perform access to the dma_ops member of struct device, it's better to use setter to avoid potential problems in the future.

What potential problems are you imagining? This whole file is a DMA ops implementation, not driver code (and definitely not a module); if anyone removes the "select DMA_OPS" from CONFIG_IOMMU_DMA they deserve whatever breakage they get.

I concur that there's no major harm in using the helper here, but I also see no point in pretending that there's any value to abstracting the operation in this particular context.

Thanks,
Robin.

Quoted 11 lines

---
v2: rebased on top of the latest codebase

  drivers/iommu/dma-iommu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/dma-iommu.c +0 -0
index d85d54f2b549..b585a3fdbc56 100644

drivers/iommu/dma-iommu.c void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 dma_limit) · line 1488

Quoted 8 lines
drivers/iommu/dma-iommu.c +1 -1
@@ -1482,7 +1482,7 @@ void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 dma_limit)
  	if (iommu_is_dma_domain(domain)) {
  		if (iommu_dma_init_domain(domain, dma_base, dma_limit, dev))
  			goto out_err;
-		dev->dma_ops = &iommu_dma_ops;
+		set_dma_ops(dev, &iommu_dma_ops);
  	}
 
  	return;

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#2 lore raw
Quoted 5 lines · Robin Murphy
Quoted 3 lines · Andy Shevchenko

Use DMA ops setter instead of direct assignment. Even we know that this module doesn't perform access to the dma_ops member of struct device, it's better to use setter to avoid potential problems in the future.

Quoted 8 lines

What potential problems are you imagining? This whole file is a DMA ops implementation, not driver code (and definitely not a module); if anyone removes the "select DMA_OPS" from CONFIG_IOMMU_DMA they deserve whatever breakage they get.

I concur that there's no major harm in using the helper here, but I also see no point in pretending that there's any value to abstracting the operation in this particular context.

Yeah. Killing off the the wrapper is actually on my todo list, mostly because it leads to people doing completely broken things like the VDPA private dma ops that should not exist.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#3 lore raw
Quoted 11 lines · Christoph Hellwig
Quoted 10 lines · Robin Murphy
Quoted 3 lines · Andy Shevchenko

Use DMA ops setter instead of direct assignment. Even we know that this module doesn't perform access to the dma_ops member of struct device, it's better to use setter to avoid potential problems in the future.

What potential problems are you imagining? This whole file is a DMA ops implementation, not driver code (and definitely not a module); if anyone removes the "select DMA_OPS" from CONFIG_IOMMU_DMA they deserve whatever breakage they get.

Quoted 7 lines
Quoted 3 lines

I concur that there's no major harm in using the helper here, but I also see no point in pretending that there's any value to abstracting the operation in this particular context.

Yeah. Killing off the the wrapper is actually on my todo list, mostly because it leads to people doing completely broken things like the VDPA private dma ops that should not exist.

Let's abandon this change. (I see that it's kinda 50/50 of the users with API and without)

Signature · 8 lines
With Best Regards,
Andy Shevchenko


_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu