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=1796383807; b=07VujH4ZZVh0mo3m4afCYJ9nF+Ufw6vjdruOP0UfyHl0QQH60Nv9bl6baONtyf8Mp97J GEbfQWLqs9QuxG8TSPeXWHPhM+nT4H8n1uiyuebCT8ve32/PGqKWR1wEO+LaJTngp+LxP 2S075SO/Sucmqw2N0EVWPZZK88XRYCBORfc3BP8jJF/z8B+/QM0PLZeEIWav0YzYh/XbR BnnyBlIN4Fb66v4dT1US3EKT8FEswDTXe5RXg6Llxf6cYDImmrcG1wm/jHmdfBbbnAyD8 wjb7v18lh1fubHNiH9Kt7aunGo6bEkD4njbJXTtolYi4sWt//DIsIP5c402OB5SDbyg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383807; 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=z3lxo+3q0sIYwX24T3Oecob8k/6XVvGiBZGc/5zxoN0=; b=c21tHW0YT/6R9UwgBsoZ36XIAfmmDoziyZq6YgDLlh7M7x7dVJyt4TLlPeh+i0JIGs03 3SykpB1lx4KGL8mt+jXE7K4F2ONOtcqt1j5nrnNhSF88L1i/9l2vShkVz7DHWP11IbQcR +urrtFWZ4QaJHj4qirHnpGGU0u1TSrpFv9lnkGfpw++c8XpboEyPuPn34WsV6tGmVQXts R0VyImoCzRaLx+vh2wqs9RBm2AvMUodmC60FbENyFQSRE0SRNpFlbRW2H0yZ6mdcBvVvS 4zpy00cPxhRGYcQmTQpXR4WkhqmcdjKRAcjWvcaIGCpLLoY2zKmRg89NibnofqZAaiA== 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=gFxwrYVE; 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 45DA3606A332; Fri, 4 Dec 2026 11:30:07 +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=gFxwrYVE Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77E8F1F000C2; Fri, 4 Dec 2026 11:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383806; bh=z3lxo+3q0sIYwX24T3Oecob8k/6XVvGiBZGc/5zxoN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gFxwrYVEj6r2r6zXOBSsznWXmPaRImWcUIzdwPir8/yrUa1A9zOeLq59Jc+UXAkh2 pXIoHr4atin1MLzKkD8Nm7lLDI9WFSJM7bVO12F/F4ptsyUItOtKzo7dt9xwozDkwf /FQG+eyC5t5gjCHMCwys63m6YiFjB4GlIO/eqF5U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alex Deucher , Jiaming Fan Subject: [PATCH 6.12 333/555] drm/amdgpu: only unregister the ATPX handler if we registered it Date: Fri, 4 Dec 2026 19:06:16 +0900 Message-ID: <20261204100622.595482664@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiaming Fan commit 53fc1be11892a8e695937fdbc24db2699d23dabf upstream. amdgpu_register_atpx_handler() registers the ATPX handler with vga_switcheroo only when ATPX is detected, and ignores the result: vga_switcheroo has a single handler slot and refuses a second handler with -EINVAL. amdgpu_unregister_atpx_handler() calls vga_switcheroo_unregister_handler() in either case, and that clears the slot no matter who set it. So unloading amdgpu removes a handler registered by another driver, such as apple-gmux. No AMD GPU is needed for this; loading and unloading amdgpu is enough. Afterwards vga_switcheroo can no longer switch outputs, and a client that uses the vga_switcheroo runtime PM domain, such as nouveau on a non-Optimus machine with a v1 DSM, can dereference the now NULL handler during runtime suspend. Record whether the registration succeeded and unregister only in that case. 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 fbb6ebeff9d5327e8d06a83a3f7daa88422c9127) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c @@ -45,6 +45,7 @@ struct amdgpu_atpx { static struct amdgpu_atpx_priv { bool atpx_detected; bool bridge_pm_usable; + bool handler_registered; unsigned int quirks; /* handle for device - and atpx */ acpi_handle dhandle; @@ -666,7 +667,8 @@ void amdgpu_register_atpx_handler(void) if (!r) return; - vga_switcheroo_register_handler(&amdgpu_atpx_handler, handler_flags); + if (!vga_switcheroo_register_handler(&amdgpu_atpx_handler, handler_flags)) + amdgpu_atpx_priv.handler_registered = true; } /** @@ -676,5 +678,14 @@ void amdgpu_register_atpx_handler(void) */ void amdgpu_unregister_atpx_handler(void) { + /* + * vga_switcheroo has a single handler slot and unregistering clears it + * no matter who set it, so leave a handler registered by another + * driver, such as apple-gmux, in place. + */ + if (!amdgpu_atpx_priv.handler_registered) + return; + vga_switcheroo_unregister_handler(); + amdgpu_atpx_priv.handler_registered = false; }