From: Jozef Wludzik <[email protected]>

Unmapping a BO only invalidates leaf PTEs in its reserved VA range. The
caller serializes access to that range and keeps the context and VA node
alive until unmapping completes. Intermediate page tables remain
allocated until context teardown.

Remove the context mutex from scatter-gather unmapping and use
WRITE_ONCE() for leaf PTE invalidation. Keep the write barrier and TLB
invalidation, as well as the existing locking for mapping, page-table
allocation and drm_mm updates.

Signed-off-by: Jozef Wludzik <[email protected]>
Signed-off-by: Dawid Osuchowski <[email protected]>
---
 drivers/accel/ivpu/ivpu_mmu_context.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/accel/ivpu/ivpu_mmu_context.c 
b/drivers/accel/ivpu/ivpu_mmu_context.c
index bb3ca81838e3..6429cddf968f 100644
--- a/drivers/accel/ivpu/ivpu_mmu_context.c
+++ b/drivers/accel/ivpu/ivpu_mmu_context.c
@@ -303,7 +303,8 @@ static void ivpu_mmu_context_unmap_page(struct 
ivpu_mmu_context *ctx, u64 vpu_ad
        int pte_idx = FIELD_GET(IVPU_MMU_PTE_INDEX_MASK, vpu_addr);
 
        /* Update PTE with dummy physical address and clear flags */
-       ctx->pgtable.pte_ptrs[pgd_idx][pud_idx][pmd_idx][pte_idx] = 
IVPU_MMU_ENTRY_INVALID;
+       WRITE_ONCE(ctx->pgtable.pte_ptrs[pgd_idx][pud_idx][pmd_idx][pte_idx],
+                  IVPU_MMU_ENTRY_INVALID);
 }
 
 static int
@@ -523,8 +524,6 @@ ivpu_mmu_context_unmap_sgt(struct ivpu_device *vdev, struct 
ivpu_mmu_context *ct
        if (drm_WARN_ON(&vdev->drm, !ctx))
                return;
 
-       mutex_lock(&ctx->lock);
-
        for_each_sgtable_dma_sg(sgt, sg, i) {
                dma_addr_t dma_addr = sg_dma_address(sg) - sg->offset;
                size_t size = sg_dma_len(sg) + sg->offset;
@@ -539,8 +538,6 @@ ivpu_mmu_context_unmap_sgt(struct ivpu_device *vdev, struct 
ivpu_mmu_context *ct
        /* Ensure page table modifications are flushed from wc buffers to 
memory */
        wmb();
 
-       mutex_unlock(&ctx->lock);
-
        ret = ivpu_mmu_invalidate_tlb(vdev, ctx->id);
        if (ret)
                ivpu_warn_ratelimited(vdev, "Failed to invalidate TLB for ctx 
%u: %d\n",
-- 
2.43.0

Reply via email to