Skip to contentSkip to conversation

drm/etnaviv: Trivial mmu map and ummap cleanups

PATCH Superseded Sui Jingfeng 1 participant 4 messages Nov 4, 2024

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover drm/etnaviv: Trivial mmu map and ummap cleanups

The 'offset' data member of the 'struct scatterlist' denotes the offset into a SG entry in bytes. But it seems that nearly all helper functions we are using will hardcode it to ZERO. Under such a case, it seems that take the 'offset' into accounts are just intoduce extra overhead. Waste CPU circles, then is it correct and safe for us do some simplification now?

v1 -> v2
* Reword and fix typos and mistakes

v1 Link: https://patchwork.freedesktop.org/series/140589/

Sui Jingfeng (3):
drm/etnaviv: Drop offset in page manipulation drm/etnaviv: Fix the debug log of the etnaviv_iommu_map() drm/etnaviv: Improve VA, PA, SIZE alignment checking

 drivers/gpu/drm/etnaviv/etnaviv_mmu.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/3 drm/etnaviv: Drop offset in page manipulation

The 'offset' data member of the 'struct scatterlist' denotes the offset into a SG entry in bytes. But under drm subsystem, there has nearly NO drivers that actually tough the 'offset' data member of SG anymore. Especially for drivers that could contact with drm/etnaviv. This means that all DMA addresses that sg_dma_address() gives us will be PAGE_SIZE aligned, in other words, sg->offset will always equal to 0.

Drop those compulations about the offset of SG entries can save some extra overhead.

---
 drivers/gpu/drm/etnaviv/etnaviv_mmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_mmu.c +2 -2
index 8f33f111f9e8..ddb536d84c58 100644
@@ -82,8 +82,8 @@ static int etnaviv_iommu_map(struct etnaviv_iommu_context *context,
 		return -EINVAL;
 
 	for_each_sgtable_dma_sg(sgt, sg, i) {
-		phys_addr_t pa = sg_dma_address(sg) - sg->offset;
-		unsigned int da_len = sg_dma_len(sg) + sg->offset;
+		phys_addr_t pa = sg_dma_address(sg);
+		unsigned int da_len = sg_dma_len(sg);
 		unsigned int bytes = min_t(unsigned int, da_len, va_len);
 
 		VERB("map[%d]: %08x %pap(%x)", i, iova, &pa, bytes);
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/3 drm/etnaviv: Fix the debug log of the etnaviv_iommu_map()

In reply to Sui Jingfeng

The value of the 'iova' variable is the base GPU virtual address that is going to be mapped, its value won't get updated when etnaviv_context_map() is running under the "for_each_sgtable_dma_sg(sgt, sg, i) {}" loop.

Replace it with the 'da' variable, reflect the actual status that GPUVA is being mapped.

---
 drivers/gpu/drm/etnaviv/etnaviv_mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/etnaviv/etnaviv_mmu.c +1 -1
index ddb536d84c58..05021848126e 100644
@@ -86,7 +86,7 @@ static int etnaviv_iommu_map(struct etnaviv_iommu_context *context,
 		unsigned int da_len = sg_dma_len(sg);
 		unsigned int bytes = min_t(unsigned int, da_len, va_len);
 
-		VERB("map[%d]: %08x %pap(%x)", i, iova, &pa, bytes);
+		VERB("map[%d]: %08x %pap(%x)", i, da, &pa, bytes);
 
 		ret = etnaviv_context_map(context, da, pa, bytes, prot);
 		if (ret)
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 3/3 drm/etnaviv: Improve VA, PA, SIZE alignment checking

In reply to Sui Jingfeng

We only need checking the alignment on the upper caller function, if those address and/or sizes are pass the check. Those address will certainly pass the same test under the etnaviv_context_unmap() function.

Remove redundant alignment tests in etnaviv_context_unmap() and move the alignment tests to the upper caller etnaviv_iommu_map() function. Which reduce some extra overhead.

---
 drivers/gpu/drm/etnaviv/etnaviv_mmu.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_mmu.c +8 -12
index 05021848126e..56ae2de76e15 100644
@@ -19,12 +19,6 @@ static void etnaviv_context_unmap(struct etnaviv_iommu_context *context,
 	size_t unmapped_page, unmapped = 0;
 	size_t pgsize = SZ_4K;
 
-	if (!IS_ALIGNED(iova | size, pgsize)) {
-		pr_err("unaligned: iova 0x%lx size 0x%zx min_pagesz 0x%zx\n",
-		       iova, size, pgsize);
-		return;
-	}
-
 	while (unmapped < size) {
 		unmapped_page = context->global->ops->unmap(context, iova,
 							    pgsize);
@@ -45,12 +39,6 @@ static int etnaviv_context_map(struct etnaviv_iommu_context *context,
 	size_t orig_size = size;
 	int ret = 0;
 
-	if (!IS_ALIGNED(iova | paddr | size, pgsize)) {
-		pr_err("unaligned: iova 0x%lx pa %pa size 0x%zx min_pagesz 0x%zx\n",
-		       iova, &paddr, size, pgsize);
-		return -EINVAL;
-	}
-
 	while (size) {
 		ret = context->global->ops->map(context, iova, paddr, pgsize,
 						prot);
@@ -88,6 +76,14 @@ static int etnaviv_iommu_map(struct etnaviv_iommu_context *context,
 
 		VERB("map[%d]: %08x %pap(%x)", i, da, &pa, bytes);
 
+		if (!IS_ALIGNED(iova | pa | bytes, SZ_4K)) {
+			dev_err(context->global->dev,
+				"unaligned: iova 0x%x pa %pa size 0x%x\n",
+				iova, &pa, bytes);
+			ret = -EINVAL;
+			goto fail;
+		}
+
 		ret = etnaviv_context_map(context, da, pa, bytes, prot);
 		if (ret)
 			goto fail;
Signature · 1 line
2.34.1