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 AB6A81A2547; Mon, 2 Jun 2025 14:57:29 +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=1748876249; cv=none; b=bgAcMNJLY/Cj+Iu0BjwwrYU8pH2YspiX8wOl74DdhVEnLRySfuPu/PyVvBsebqiaSorKDqrYj6+MwIXSnJjyv1Vgsb9u+EqHckWgYpLhABGcaQYNCHBTBkWPDvg4F5aqF4/Xoe9HP9v21zD7YCh9x4XmRXo5FNy0zAaaQyQ0z9o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748876249; c=relaxed/simple; bh=SD9BCYvrmAjLCYZqpizdQoiykKHEFezgbdHkBuM4k/U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EFulz5RJjwAK9plov1eB+fV3eCXF6nJuoNmYGV1ArLFeCSOB1Euuyz20Y6O0ersWS55bCH6vBZbVcrTvv27h1R9X9zdSFbEltLqffBQhsxqVx3OjAqq7zgkqAL6xwWNdH4Y/pRU6N8neLQ083DdT7X43ArG9tf7rq/H1qa2dCTQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=eWUcvrwg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="eWUcvrwg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CFDEC4CEF4; Mon, 2 Jun 2025 14:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1748876249; bh=SD9BCYvrmAjLCYZqpizdQoiykKHEFezgbdHkBuM4k/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eWUcvrwgadAPWuaiZu2rOvb6X/lH1b1YAIQ3+1CTQenPZGrduQw0orcyNA2QEvo+E Gv7amZITdcTUrGGTkAvSFwyLLm8TDHaGp4bVxSz1PmnxIZgW7MoVPLhbiUdZtjgJIA 0+F8U5GpGF/89U4NO+iOvxb0kzLGQ7U7V1dB+9l0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Philip Yang , Felix Kuehling , Alex Deucher , Sasha Levin Subject: [PATCH 5.15 089/207] drm/amdkfd: KFD release_work possible circular locking Date: Mon, 2 Jun 2025 15:47:41 +0200 Message-ID: <20250602134302.224305796@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250602134258.769974467@linuxfoundation.org> References: <20250602134258.769974467@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ 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 49810642bc2b8..7ef6e61aa0431 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -807,6 +807,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 @@ -819,14 +827,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