Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794065483; b=Rjc+up8QcK3tniH79yIMEB3D2tS8kpXU24wi9qYdAC328k/6m0mRLz54iU5nGVClGTaR EeFy5fYqmfj4fVBsm7ELuyCxXV+0KDtHU5Oe5UZ1fs2/NFRV1xJswrZrVNi0g/FGUzqIh RxdpKOIwbECXDPVwUhyi6TkOWNBaJ889Z00oakdrnNxh0CW3LwFAWCP+bhXVh1DCp4+VG KsPDUrXPPHo69fVS7T/VER7a8UEzJbk87l5DPWnvS+V294bAK2fQ/Uk4vxcM27XMhLmmk OrZ5sRb8y6mVRsGiBfRDRot80TH596yO9l0Epaguoni5kcm+b5HdTIoQEHA7ATI5iWQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794065483; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=cuIg1BefOu5MM3r7In6klNJMG28pLJzdBRo0nkqwRxQ=; b=pZFbyHzaF2QZ/qd3nDpio6mfW5mvp6H1isB/wPTG9Spog/AWoyt7f964xLcXOOz9qj3f 3adlI8I2C1ack1maMypO3ySHgc2TKU5yka8ktPIrY/B9C4mVkeWEzk96u6Yk+lgC7d1vN tg6xgFr8EQkWbV9FBozRlUpAsAzpgv9LS+9abgnDMvywAcUn23+CNCnmNbH3PLpTt9EKI LsvXy3QpzmzaN5matfjux4a5Xi+m32N1Dk12F8wvfLzipk5ppoiHRwua6aPDeC6/JbPAy C1NPWmgzVmTK7y73xwYdGdXPQnz7KDGK7wFt8xjebR1sw7LMQD0aa0mZHoso2W442+g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="BJsjIlY/"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C5BB606A33D; Sat, 7 Nov 2026 15:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=BJsjIlY/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D37E1F0089F; Sat, 7 Nov 2026 15:31:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794065483; bh=cuIg1BefOu5MM3r7In6klNJMG28pLJzdBRo0nkqwRxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BJsjIlY/CCDRPLZ+F6U5JrragTiohxU/gD8xuBT03I5v946FfGLUC46CnC0SOEX6O eqr7HIhvjsAzTX1Omv+K/TMZEurqW+Ulerzr5mP334A1w3RY0SeuKv62CEZXKRomEx BUWOwX9mWX7gVWNC+En1Ay661FmvLQTb55Ez+SVM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Xiaogang Chen , Olivier Kaloudoff , Felix Kuehling , Alex Deucher , Sasha Levin Subject: [PATCH 7.3 1177/1257] drm/amdkfd: tear down KFD processes before early fini_sw on disconnect Date: Sat, 7 Nov 2026 08:57:53 -0500 Message-ID: <20261107135011.684382319@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107134939.434104957@linuxfoundation.org> References: <20261107134939.434104957@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Olivier Kaloudoff [ Upstream commit 1233dd17f99c75787a31035656ecfeff80522421 ] On surprise removal, amdgpu_device_fini_hw() calls amdgpu_amdkfd_device_fini_sw() when pci_dev_is_disconnected() is true. fini_sw frees kfd.dev, but KFD processes may still be alive and hold references to it: kfd_process_destroy() dereferences kfd.dev via kfd_processes_remove(), and svm_range_list_fini() / kfd_process_free_outstanding_kfd_bos() touch per-device SVM state. The kfd_processes_count wait only happens later in kgd2kfd_teardown_processes(), called from the top-half remove path well after fini_sw. In the observed failure the killed KFD process (SIGBUS on unplug) stuck in D state on its exit path, so kfd_processes_count never drained and the PCIe removal thread wedged permanently in cond_resched(), producing soft-lockup and hung-task splats. Tear KFD processes down before freeing kfd.dev on the disconnect path, and guard kgd2kfd_teardown_processes() against kfd.dev already being gone when it runs a second time. Cc: Xiaogang Chen Signed-off-by: Olivier Kaloudoff Signed-off-by: Felix Kuehling Reviewed-by: Felix Kuehling Signed-off-by: Alex Deucher (cherry picked from commit 836f44ba87ed7b1d83e2b7bfc788f8c6437b03a7) Cc: stable@vger.kernel.org Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 ++++- drivers/gpu/drm/amd/amdkfd/kfd_device.c | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index e55367ca3e951..5b72e4afb650f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -4319,8 +4319,11 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev) * before ip_fini_early to prevent kfd locking refcount issues by calling * amdgpu_amdkfd_suspend() */ - if (pci_dev_is_disconnected(adev->pdev)) + if (pci_dev_is_disconnected(adev->pdev)) { + /* Drain KFD processes while kfd.dev is still valid */ + amdgpu_amdkfd_teardown_processes(adev); amdgpu_amdkfd_device_fini_sw(adev); + } amdgpu_coredump_fini(adev); amdgpu_device_ip_fini_early(adev); diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c index 586e640f13dce..43029b2022c02 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c @@ -1801,7 +1801,14 @@ void kgd2kfd_teardown_processes(struct amdgpu_device *adev) mutex_unlock(&kfd_processes_mutex); - /* wait all kfd processes use adev terminate */ + /* kfd.dev may already be freed on surprise removal */ + if (!adev->kfd.dev) + return; + + /* + * Wait for all KFD processes using adev to terminate. Must be + * unbounded: device state is freed once they are gone. + */ while (!!atomic_read(&adev->kfd.dev->kfd_processes_count)) cond_resched(); } -- 2.53.0