Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28492606A320 for ; Tue, 1 Dec 2026 15:09:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=ZqQ4RIAi Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 71D1010F9D1; Tue, 1 Dec 2026 15:08:59 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 473D310F9CE for ; Tue, 1 Dec 2026 15:08:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796137733; x=1827673733; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/SUQqJeWQXgNuaFeX41V9JDqUv0ewXfxVluTPNQp1Rs=; b=ZqQ4RIAinB1gal/apDcuXo5ZcoQabfkos6YTQQWlj5cwxb0SV4WK525m DC29F4Wz1G820aNKzzimaGzTKYhrJFnYH7Qdx/2xuVsv1mUZuh/EtnJ5N MEPMYvaj5UjHDliTP91w+Pedc6QEoxc3DkLhM9kEUfzxXrXnxQXiHR/sp X+1mxN1Ry+yfz+XWFik0I5ucv9NqxPz1Y6Booobkb76OF8KWm397KdyBK eFNVUdxAFNGIjHjfTc2FhbS3G8ZRiWrwnFx81FMKR+SeZ6j4dVbIUF7/3 1cIV4ctItCfgr0kiZ983E8jne0JOt52ge6q9biYO5GLNdcpaSNVuZLkY2 A==; X-CSE-ConnectionGUID: iSnAReYmTeCMpufd17JYLA== X-CSE-MsgGUID: hrfbAta+TQmCcbGrFyk1Cw== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="4928262" X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="4928262" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 07:08:53 -0800 X-CSE-ConnectionGUID: kZbl9ocXR/Oc/D6Xe3VAxA== X-CSE-MsgGUID: x7d0vDEcQVqIYccF+0Nmjg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="13078325" Received: from try2-8594.igk.intel.com ([10.91.220.58]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 07:08:49 -0800 From: Dawid Osuchowski 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 Subject: [PATCH 2/3] accel/ivpu: Separate VA allocator locking from page-table locking Date: Tue, 1 Dec 2026 16:01:49 +0100 Message-ID: <20261201150150.653061-3-dawid.osuchowski@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261201150150.653061-1-dawid.osuchowski@linux.intel.com> References: <20261201150150.653061-1-dawid.osuchowski@linux.intel.com> X-Archived-By: MIME-Version: 1.0 Organization: Intel Technology Poland sp. z o.o. - ul. Slowackiego 173, 80-298 Gdansk - KRS 101882 - NIP 957-07-52-31 Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "dri-devel" X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Jozef Wludzik 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 Signed-off-by: Dawid Osuchowski --- 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 + #include 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