From: Dawid Osuchowski <dawid.osuchowski@linux.intel.com>
To: dri-devel@lists.freedesktop.org
Cc: oded.gabbay@gmail.com, jeff.hugo@oss.qualcomm.com,
karol.wachowski@linux.intel.com, lizhi.hou@amd.com,
andrzej.kacprowski@linux.intel.com,
dawid.osuchowski@linux.intel.com,
Jozef Wludzik <jozef.wludzik@linux.intel.com>
Subject: [PATCH 2/3] accel/ivpu: Separate VA allocator locking from page-table locking
Date: Tue, 1 Dec 2026 16:01:49 +0100 [thread overview]
Message-ID: <20261201150150.653061-3-dawid.osuchowski@linux.intel.com> (raw)
In-Reply-To: <20261201150150.653061-1-dawid.osuchowski@linux.intel.com>
From: Jozef Wludzik <jozef.wludzik@linux.intel.com>
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 <jozef.wludzik@linux.intel.com>
Signed-off-by: Dawid Osuchowski <dawid.osuchowski@linux.intel.com>
---
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
next prev parent reply other threads:[~2026-12-01 15:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 15:01 [PATCH 0/3] accel/ivpu: Remove ctx->lock on MMU context unmap Dawid Osuchowski
2026-12-01 15:01 ` [PATCH 1/3] accel/ivpu: Avoid taking the context lock when unmapping pages Dawid Osuchowski
2026-12-02 13:42 ` Andrzej Kacprowski
2026-12-01 15:01 ` Dawid Osuchowski [this message]
2026-12-02 13:43 ` [PATCH 2/3] accel/ivpu: Separate VA allocator locking from page-table locking Andrzej Kacprowski
2026-12-01 15:01 ` [PATCH 3/3] accel/ivpu: Shorten bo_list_lock hold time in BO free Dawid Osuchowski
2026-12-02 13:44 ` Andrzej Kacprowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201150150.653061-3-dawid.osuchowski@linux.intel.com \
--to=dawid.osuchowski@linux.intel.com \
--cc=andrzej.kacprowski@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jeff.hugo@oss.qualcomm.com \
--cc=jozef.wludzik@linux.intel.com \
--cc=karol.wachowski@linux.intel.com \
--cc=lizhi.hou@amd.com \
--cc=oded.gabbay@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.