From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E84033679CC; Mon, 5 May 2025 23:10:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746486610; cv=none; b=AZQ3Df6AJ33cMJdMseos6xgRDse4auJRQR6XV1aCl5qs5vofPbDXghjeJGklY/8sji4lthkw2L3LEBVPW9uxDJ7O0YJXTiUVfEu28EZ5b3fCUNlr8VxSC3kV4e5eKJWwcXEN9xuRGAGEKsfEEXmDnJpS26J4km7LZorcr4Z+MB4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746486610; c=relaxed/simple; bh=xou4g1oJL/WA4+vI123J22a41hUlk6RefTCXVERYYUs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DtTgFe5cq/7Yho8GoLR2sUOSCYv/dIV/a+Kehj/oWzXVA7SLFRJi80ZBqvbkeGtK0n+5Cx3yx0ZBFJ6hQSA2ZrlYY+r92rcclZpIHSypIuFlhElvP9UJr/pSSjla0LmNT37/Dx62yKp+/3hr+w/xhPVXGx3JEsGlx2mq6Y/+Yk0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UOjIxaE3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UOjIxaE3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85E27C4CEF3; Mon, 5 May 2025 23:10:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746486608; bh=xou4g1oJL/WA4+vI123J22a41hUlk6RefTCXVERYYUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UOjIxaE3IOBMXI1+zglPNb9ZEGwSlWIH8Wt4hhRrymJrcuPG6UKFTcjtE4vDBal1H IyLnDnh9pAkvouDhB6RmJHex9qYMSq5RgfJBne3SRm3iLpsJRnc7poKwRFxmZVlNcM aXP3hY8QK0YyVtsCp8bT+JLFfC0O7Z/mOJ0RN4Op99qYEqpEZAg8wErPWrjaCBgIin PJNe99tL2SgEw7/Zq4Lc4sBMmYjzPjXVXlm6qpAmEi4DxSL+H/VM6kXaxx3+YbINIU LWfH75dFaOYBsJA3luw2ZaFrg+6r+oUD9Xu7bwzkyiUhCbCKIxJMSXhCCSy/KVeKa/ yNLAxHe7gb1gg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Philip Yang , Felix Kuehling , Alex Deucher , Sasha Levin , Felix.Kuehling@amd.com, christian.koenig@amd.com, airlied@gmail.com, simona@ffwll.ch, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 6.1 116/212] drm/amdkfd: KFD release_work possible circular locking Date: Mon, 5 May 2025 19:04:48 -0400 Message-Id: <20250505230624.2692522-116-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250505230624.2692522-1-sashal@kernel.org> References: <20250505230624.2692522-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.136 Content-Transfer-Encoding: 8bit From: Philip Yang [ Upstream commit 1b9366c601039d60546794c63fbb83ce8e53b978 ] If waiting for gpu reset done in KFD release_work, thers is WARNING: possible circular locking dependency detected #2 kfd_create_process kfd_process_mutex flush kfd release work #1 kfd release work wait for amdgpu reset work #0 amdgpu_device_gpu_reset kgd2kfd_pre_reset kfd_process_mutex Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock((work_completion)(&p->release_work)); lock((wq_completion)kfd_process_wq); lock((work_completion)(&p->release_work)); lock((wq_completion)amdgpu-reset-dev); To fix this, KFD create process move flush release work outside kfd_process_mutex. Signed-off-by: Philip Yang Reviewed-by: Felix Kuehling Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c index bc01c5173ab9a..fd7fecaa9254b 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -813,6 +813,14 @@ struct kfd_process *kfd_create_process(struct file *filep) if (thread->group_leader->mm != thread->mm) return ERR_PTR(-EINVAL); + /* If the process just called exec(3), it is possible that the + * cleanup of the kfd_process (following the release of the mm + * of the old process image) is still in the cleanup work queue. + * Make sure to drain any job before trying to recreate any + * resource for this process. + */ + flush_workqueue(kfd_process_wq); + /* * take kfd processes mutex before starting of process creation * so there won't be a case where two threads of the same process @@ -825,14 +833,6 @@ struct kfd_process *kfd_create_process(struct file *filep) if (process) { pr_debug("Process already found\n"); } else { - /* If the process just called exec(3), it is possible that the - * cleanup of the kfd_process (following the release of the mm - * of the old process image) is still in the cleanup work queue. - * Make sure to drain any job before trying to recreate any - * resource for this process. - */ - flush_workqueue(kfd_process_wq); - process = create_process(thread); if (IS_ERR(process)) goto out; -- 2.39.5