From: Jozef Wludzik <[email protected]> The context mutex is held across reclaimable page-table allocations. Taking the same mutex to remove a VA node during BO destruction can deadlock when destruction runs in direct reclaim.
Protect drm_mm insertion and removal with a dedicated spinlock instead. These operations use preallocated nodes and do not sleep. Keep both alignment attempts under the same lock and retain the context mutex for page-table mapping, allocation and context descriptor updates. Signed-off-by: Jozef Wludzik <[email protected]> Signed-off-by: Dawid Osuchowski <[email protected]> --- drivers/accel/ivpu/ivpu_mmu_context.c | 15 ++++++--------- drivers/accel/ivpu/ivpu_mmu_context.h | 5 ++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/accel/ivpu/ivpu_mmu_context.c b/drivers/accel/ivpu/ivpu_mmu_context.c index 6429cddf968f..13e5dc455ad6 100644 --- a/drivers/accel/ivpu/ivpu_mmu_context.c +++ b/drivers/accel/ivpu/ivpu_mmu_context.c @@ -552,27 +552,23 @@ ivpu_mmu_context_insert_node(struct ivpu_mmu_context *ctx, const struct ivpu_add WARN_ON(!range); - mutex_lock(&ctx->lock); + guard(spinlock)(&ctx->mm_lock); if (!ivpu_disable_mmu_cont_pages && size >= IVPU_MMU_CONT_PAGES_SIZE) { ret = drm_mm_insert_node_in_range(&ctx->mm, node, size, IVPU_MMU_CONT_PAGES_SIZE, 0, range->start, range->end, DRM_MM_INSERT_BEST); if (!ret) - goto unlock; + return 0; } - ret = drm_mm_insert_node_in_range(&ctx->mm, node, size, IVPU_MMU_PAGE_SIZE, 0, - range->start, range->end, DRM_MM_INSERT_BEST); -unlock: - mutex_unlock(&ctx->lock); - return ret; + return drm_mm_insert_node_in_range(&ctx->mm, node, size, IVPU_MMU_PAGE_SIZE, 0, + range->start, range->end, DRM_MM_INSERT_BEST); } void ivpu_mmu_context_remove_node(struct ivpu_mmu_context *ctx, struct drm_mm_node *node) { - mutex_lock(&ctx->lock); + guard(spinlock)(&ctx->mm_lock); drm_mm_remove_node(node); - mutex_unlock(&ctx->lock); } void ivpu_mmu_context_init(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx, u32 context_id) @@ -580,6 +576,7 @@ void ivpu_mmu_context_init(struct ivpu_device *vdev, struct ivpu_mmu_context *ct u64 start, end; mutex_init(&ctx->lock); + spin_lock_init(&ctx->mm_lock); if (!context_id) { start = vdev->hw->ranges.runtime.start; diff --git a/drivers/accel/ivpu/ivpu_mmu_context.h b/drivers/accel/ivpu/ivpu_mmu_context.h index cc02e7bab04e..9040d216ff2e 100644 --- a/drivers/accel/ivpu/ivpu_mmu_context.h +++ b/drivers/accel/ivpu/ivpu_mmu_context.h @@ -6,6 +6,8 @@ #ifndef __IVPU_MMU_CONTEXT_H__ #define __IVPU_MMU_CONTEXT_H__ +#include <linux/spinlock.h> + #include <drm/drm_mm.h> struct ivpu_device; @@ -23,7 +25,8 @@ struct ivpu_mmu_pgtable { }; struct ivpu_mmu_context { - struct mutex lock; /* Protects: mm, pgtable, is_cd_valid */ + struct mutex lock; /* Protects: pgtable allocation and mapping, is_cd_valid */ + spinlock_t mm_lock; /* Protects: mm */ struct drm_mm mm; struct ivpu_mmu_pgtable pgtable; bool is_cd_valid; -- 2.43.0
