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 E2CAA3C01; Tue, 27 May 2025 17:34:34 +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=1748367276; cv=none; b=C1OczsX7+Ct4iRhTtDOmxuycN6C4pCpFQybCwML3OoiVzGL9FJ8uhS2w0EHGZ1iQHFycKWL11HARiYZoJgn7t7AXg5VeJS/LDEDGLeSdx8A5Ur/7lqAmSB71AgeQPInoWejcqlTwqNhLUNMX6f+4gjm3LvhBti6A3EGDJsvFtNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748367276; c=relaxed/simple; bh=aQSJUEX8vP1ghxnCYKfvystoWuKhAQBGMS6P0JdCzJI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UoUPIWO6IKdPz4LXEVZG9VcpYwdaIdntgBF+En1Fw+GoaIyv7Ygm4p6dMce5jTXGCSbR3YpmhP+0lNGTSK07Q0Yi1snuGDEEGcOfDhAJ7gjma3u7gbizGXgXZwC0o8x+BywnDIdb5g87ajVp2t55oDFWotG9H/8EiscD7uv1pAM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=pwo/RJdW; 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="pwo/RJdW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6CA1C4CEEA; Tue, 27 May 2025 17:34:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1748367274; bh=aQSJUEX8vP1ghxnCYKfvystoWuKhAQBGMS6P0JdCzJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pwo/RJdW0Uw6z5vM5mnS9guWhcTRUne4WEzK5V/H7zcnolD7t7tkaUs3NED8+sxe7 6M1NFzfRCTvQ/7QdlI4H2hmvxgdmnx+mGD28c1+tXmMYjYrqy5NxFzOQWJpvRJfydT iRazAPIwh/Mo7qtBUnN6qQ+rI/HpaFHdm2n66SJQ= 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 6.14 334/783] drm/amdkfd: KFD release_work possible circular locking Date: Tue, 27 May 2025 18:22:11 +0200 Message-ID: <20250527162526.661949385@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527162513.035720581@linuxfoundation.org> References: <20250527162513.035720581@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.14-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 c3f2c0428e013..c9cbc0ecd9cb2 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -842,6 +842,14 @@ struct kfd_process *kfd_create_process(struct task_struct *thread) 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 @@ -862,14 +870,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread) 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