From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796380708; b=qizsGQioJsPSuA+KeCj/LcOikf/0RChp06mezBKU5+a3B8ipzjsURoP+v1UivEcQcGtv GWp4jIlrWMhRrn5Y8E0YyUKnRWLNfY7JtQXN8ahKcE+Hs+9kSttWu7IeGwDOFQF+i2RQ/ mSt18KigNGpQq1338x8WcORjllXujpnA70PhuOGxXeZymyeAnk5Tupt8UnpouDqn+gns0 QNKvBnSL7C5ENZQAgIigYmUZXICmQ7/K9ju3WsnhgU9q09E7cn0v9fQgM963qTzDqRFqG GzvH9tGSafcP/iQXFV9+1GISPUpmuH9sAhmKWHzpvmbOzLEHAJ31RcCt98r+mjVSVkA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380708; 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=SWb/M9tXXXx9o4a/ahj7n5N183K/9V7us7lstNWbFAk=; b=DrV8fUhdBRgDJQ8T8jm57lxXl5Ww/IQy5LImXPU+CA+DvQvW8kHjXEH3UKc97NT3j/LR B0gL5MPU8rIrPDzw3ZsI5FIjlEjVCI8jZL9RewAuBPt1aqbMx+ob9u/8WGGBIoafRyn4j r4mvHJ/BBaZkZAC/BCJ6Pd6hetjPvbEZ2p8Z23KFPR3VZKjmidq7WikW3IxJ2MUtdum3q Ga7p7BaczXoH6aYdfKlWJYR6gwBAZD4OFOn2tU1gHpxTjXrGaOXGr/LFfMnQxVQbzqFJQ E76YcsWI10D2Tn6BCTMS30/hpnUp1xkC0xbSdtW8TMnRxrrUwtpOCjswunLE9A3Jgkg== 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=Eb7aAJsd; 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 3FBAB606A322; Fri, 4 Dec 2026 10:38:28 +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=Eb7aAJsd Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7C621F0092C; Fri, 4 Dec 2026 10:38:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380708; bh=SWb/M9tXXXx9o4a/ahj7n5N183K/9V7us7lstNWbFAk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Eb7aAJsdDABZrUi6z7uKV0h2iJ/Hoh3JDpKKNyTts4irrTkXpvyp+jP6szjvvST16 bpXOz7zjZ0X1bJK7DdVkctks0Q+hPP9JOmPhFkxsUNO7ys3wp71IvmTQfTdLH5psa0 CVsJvD6hF+Vl4ZuiQvRhpLEY3XKX0WDTMu7boq+0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alex Deucher , Jiaming Fan Subject: [PATCH 7.3 389/742] drm/amdgpu: unwind module init on failure Date: Fri, 4 Dec 2026 19:04:13 +0900 Message-ID: <20261204100645.422808557@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org 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: Jiaming Fan commit be94997dd5558a0e53bee97306d659e9327dcab9 upstream. amdgpu_init() registers the ATPX handler with vga_switcheroo and allocates the ACPI XCC/NUMA info before it initializes KFD, but its error paths do not undo any of that: - when amdgpu_amdkfd_init() fails, only amdgpu_sync_fini() is called; - when pci_register_driver() fails, its result is returned as is, so KFD, the ATPX handler, the ACPI info and the sync slab cache are all left behind. A failed module init frees the module, so vga_switcheroo keeps a pointer to a handler in freed memory and /dev/kfd keeps file operations that point into it. A later amdgpu load cannot register its own ATPX handler, and vga_switcheroo_enable() calls into the stale one. The KFD path is easy to reach since KFD init failures are no longer ignored: kfd_init() returns -EINVAL for an out of range sched_policy or max_num_of_queues_per_device module parameter. Unwind in the reverse order of initialization, starting from the last step that succeeded, with the same calls and in the same order as amdgpu_exit(). amdgpu_amdkfd_fini() is a no-op when KFD was not initialized, which covers the ignored -ENOENT case, and amdgpu_unregister_atpx_handler() only removes a handler that amdgpu registered itself. Fixes: 4259a25341ab ("amdkfd: Only ignore -ENOENT for KFD init failuires") Fixes: d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)") Reviewed-by: Alex Deucher Signed-off-by: Jiaming Fan Signed-off-by: Alex Deucher (cherry picked from commit c2c34905fb40d3bddae0d2539830975781715e25) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -3194,7 +3194,7 @@ static int __init amdgpu_init(void) /* Ignore KFD init failures when CONFIG_HSA_AMD is not set. */ r = amdgpu_amdkfd_init(); if (r && r != -ENOENT) - goto error_fini_sync; + goto error_release_acpi; if (amdgpu_pp_feature_mask & PP_OVERDRIVE_MASK) { add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); @@ -3203,9 +3203,17 @@ static int __init amdgpu_init(void) } /* let modprobe override vga console setting */ - return pci_register_driver(&amdgpu_kms_pci_driver); + r = pci_register_driver(&amdgpu_kms_pci_driver); + if (r) + goto error_fini_kfd; -error_fini_sync: + return 0; + +error_fini_kfd: + amdgpu_amdkfd_fini(); +error_release_acpi: + amdgpu_acpi_release(); + amdgpu_unregister_atpx_handler(); amdgpu_sync_fini(); return r; }