Skip to contentSkip to conversation

drm/msm: use orig_nents to iterate over scatterlist with per-process tables

PATCH In review Jonathan Marek 2 participants 2 messages Mar 28, 2022 – Apr 5, 2022

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

PATCH 1/1 drm/msm: use orig_nents to iterate over scatterlist with per-process tables

This matches the implementation of iommu_map_sgtable() used for the non-per-process page tables path.

This works around the dma_map_sgtable() call (used to invalidate cache) overwriting sgt->nents with 1 (which is probably a separate issue).

Fixes b145c6e65eb0 ("drm/msm: Add support to create a local pagetable")
---
 drivers/gpu/drm/msm/msm_iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/msm_iommu.c +1 -1
index bcaddbba564df..22935ef26a3a1 100644
@@ -58,7 +58,7 @@ static int msm_iommu_pagetable_map(struct msm_mmu *mmu, u64 iova,
 	u64 addr = iova;
 	unsigned int i;
 
-	for_each_sg(sgt->sgl, sg, sgt->nents, i) {
+	for_each_sg(sgt->sgl, sg, sgt->orig_nents, i) {
 		size_t size = sg->length;
 		phys_addr_t phys = sg_phys(sg);
 
Signature · 1 line
2.26.1
#1 lore raw
Quoted 5 lines · Jonathan Marek

This matches the implementation of iommu_map_sgtable() used for the non-per-process page tables path.

This works around the dma_map_sgtable() call (used to invalidate cache) overwriting sgt->nents with 1 (which is probably a separate issue).

FWIW that's expected behaviour. The sgtable APIs use nents to keep track of the number of DMA segments, while orig_nents represents the physical segments. IIUC you're not actually using the DMA mapping, just relying on its side-effects, so it's still the physical segments that you care about for your private IOMMU mapping here.

Quoted 11 lines
Fixes b145c6e65eb0 ("drm/msm: Add support to create a local pagetable")
---
  drivers/gpu/drm/msm/msm_iommu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/msm_iommu.c +0 -0
index bcaddbba564df..22935ef26a3a1 100644

drivers/gpu/drm/msm/msm_iommu.c static int msm_iommu_pagetable_map(struct msm_mmu *mmu, u64 iova, · line 61

Quoted 5 lines
drivers/gpu/drm/msm/msm_iommu.c +1 -1
@@ -58,7 +58,7 @@ static int msm_iommu_pagetable_map(struct msm_mmu *mmu, u64 iova,
  	u64 addr = iova;
  	unsigned int i;
 
-	for_each_sg(sgt->sgl, sg, sgt->nents, i) {
+	for_each_sg(sgt->sgl, sg, sgt->orig_nents, i) {

Even better would be to use for_each_sgtable_sg(), which exists primarily for the sake of avoiding this exact confusion.

Robin.

Quoted 3 lines
drivers/gpu/drm/msm/msm_iommu.c +0 -0
  		size_t size = sg->length;
  		phys_addr_t phys = sg_phys(sg);