Skip to content

Commit 1fc65fa

Browse files
kwachowsjlawryno
authored andcommitted
accel/ivpu: Unmap partially mapped BOs in case of errors
Ensure that all buffers that were created only partially through allocated scatter-gather table are unmapped from MMU600 in case of errors. Signed-off-by: Karol Wachowski <[email protected]> Reviewed-by: Jacek Lawrynowicz <[email protected]> Reviewed-by: Jeffrey Hugo <[email protected]> Signed-off-by: Jacek Lawrynowicz <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent add38f8 commit 1fc65fa

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/accel/ivpu/ivpu_mmu_context.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ int
432432
ivpu_mmu_context_map_sgt(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
433433
u64 vpu_addr, struct sg_table *sgt, bool llc_coherent)
434434
{
435+
size_t start_vpu_addr = vpu_addr;
435436
struct scatterlist *sg;
436437
int ret;
437438
u64 prot;
@@ -462,7 +463,7 @@ ivpu_mmu_context_map_sgt(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
462463
ret = ivpu_mmu_context_map_pages(vdev, ctx, vpu_addr, dma_addr, size, prot);
463464
if (ret) {
464465
ivpu_err(vdev, "Failed to map context pages\n");
465-
goto err_unlock;
466+
goto err_unmap_pages;
466467
}
467468
vpu_addr += size;
468469
}
@@ -472,25 +473,27 @@ ivpu_mmu_context_map_sgt(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
472473
if (ret) {
473474
ivpu_err(vdev, "Failed to set context descriptor for context %u: %d\n",
474475
ctx->id, ret);
475-
goto err_unlock;
476+
goto err_unmap_pages;
476477
}
477478
ctx->is_cd_valid = true;
478479
}
479480

480481
/* Ensure page table modifications are flushed from wc buffers to memory */
481482
wmb();
482483

483-
mutex_unlock(&ctx->lock);
484-
485484
ret = ivpu_mmu_invalidate_tlb(vdev, ctx->id);
486-
if (ret)
485+
if (ret) {
487486
ivpu_err(vdev, "Failed to invalidate TLB for ctx %u: %d\n", ctx->id, ret);
488-
return ret;
487+
goto err_unmap_pages;
488+
}
489489

490-
err_unlock:
491490
mutex_unlock(&ctx->lock);
492-
return ret;
491+
return 0;
493492

493+
err_unmap_pages:
494+
ivpu_mmu_context_unmap_pages(ctx, start_vpu_addr, vpu_addr - start_vpu_addr);
495+
mutex_unlock(&ctx->lock);
496+
return ret;
494497
}
495498

496499
void

0 commit comments

Comments
 (0)