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=1796380716; b=P9G+hxSl1ZHJO//ah+CApbml53hocxjrP/1HiSIy0aHGf9Cu2++lRscayySgBex4n1op xx4CR+IkUHniPWm0R8vHzSd/v653jdvsDimtxlC3lRsqk7K+yNlZqUKW7QONviLyKRFSo TbtnZgOH8R/wpeI2kHWzcdrrErRP43PuL9Dw2uqxvO4qawcGkocie4r+b7EYAybaOjRRt iz3KjIdJMAtPXUYcoc0KvR6a1AJBgkueeXiizJV5lXYao89HJ7/2mXf2/5Up1kZdg9WyO The3QTXuCBYCVtsLWB3Mfxk4IqzCBlU9b88V5wmytRaUrBTRtyz7aMOtDMJOho4VONQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380716; 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=ElojNgq3ZLbH8gC40KvHzXhAXPpjr3ROKmsM8XnnlB0=; b=kJ32dT6dR573IAA5zNERaK/7Pr1LRI0I6FJeRuZ/bmslCqgxpI17pHO8xMvs2GmtzSoA FcfLr9z7paWPf1VkOTtT9BCtEVSXu/TC0dkDRjnx3exuVstzRgqrC23mqOLRmk6lWFp5Y vCEScKRPw7I0jyqWE9DbeznsFdBaQJ3wPdUB3CV/gyBM8rkFy6IFOi1cjRGod1DwnBNiQ 17VuVUH+YQBDImYbBrr15EWt7YZzUUrM3S6eI7cv6KEdLgYLJ26FfsRMc/WDusyxNDofb BAjaoD/ri8lbN2E0EO44gW8b8tZF20wz0N5QpVZDAhSc70rFRrTwiiWm+Xtys1Ubh7g== 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=SaZqiP8D; 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 10D5E606A322; Fri, 4 Dec 2026 10:38:36 +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=SaZqiP8D Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7950E1F000CE; Fri, 4 Dec 2026 10:38:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380715; bh=ElojNgq3ZLbH8gC40KvHzXhAXPpjr3ROKmsM8XnnlB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SaZqiP8D9e9JuncMos0vfrK50hBDwAIKmKfmTxhwtodjVnyMngNiAuYRkOQwlTbwR T7lBV/FIRI4zsJvDvk0JJBVfDGDrNslyAsR7UumnAnP1hTx7wUUV+LLdSrpItBeyib ByZzyF+fKrCRy1QdUaCcrHDvpH6KH9dXhMFnWu/o= 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 356/742] drm/radeon: only unregister the ATPX handler if we registered it Date: Fri, 4 Dec 2026 19:03:40 +0900 Message-ID: <20261204100644.535880537@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: 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: Jiaming Fan commit 83876755d089321e426a58f365a31b27b2c77f3b upstream. radeon_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. radeon_unregister_atpx_handler() calls vga_switcheroo_unregister_handler() in either case, and that clears the slot no matter who set it. So unloading radeon removes a handler registered by another driver, such as apple-gmux. No Radeon GPU is needed for this; loading and unloading radeon is enough. amdgpu is another such driver: when radeon and amdgpu are both loaded and both detect ATPX, only the first one gets the slot, and unloading the other one clears it. 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. amdgpu has the same problem and gets the same fix. Fixes: 6a9ee8af344e ("vga_switcheroo: initial implementation (v15)") Reviewed-by: Alex Deucher Signed-off-by: Jiaming Fan Signed-off-by: Alex Deucher (cherry picked from commit f90ef5de500fa47d8e2371d429700f0275e0b88d) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/radeon/radeon_atpx_handler.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) --- a/drivers/gpu/drm/radeon/radeon_atpx_handler.c +++ b/drivers/gpu/drm/radeon/radeon_atpx_handler.c @@ -34,6 +34,7 @@ struct radeon_atpx { static struct radeon_atpx_priv { bool atpx_detected; bool bridge_pm_usable; + bool handler_registered; /* handle for device - and atpx */ acpi_handle dhandle; struct radeon_atpx atpx; @@ -605,7 +606,8 @@ void radeon_register_atpx_handler(void) if (!r) return; - vga_switcheroo_register_handler(&radeon_atpx_handler, handler_flags); + if (!vga_switcheroo_register_handler(&radeon_atpx_handler, handler_flags)) + radeon_atpx_priv.handler_registered = true; } /** @@ -615,5 +617,14 @@ void radeon_register_atpx_handler(void) */ void radeon_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 amdgpu or apple-gmux, in place. + */ + if (!radeon_atpx_priv.handler_registered) + return; + vga_switcheroo_unregister_handler(); + radeon_atpx_priv.handler_registered = false; }