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=1796386588; b=NSfwjLxRGos0W4qf0otVmFRhTmatrEl57673obon2Mzv2HT8bHBYvRJy/cO+WmK+L2DY lT2O8uyaE03c/0XkFEiUXixiydwXYYhcrP+d1HXrJ2iKi/XlZla7nnQjzUvmySLjTCPRq gr7gsfxCh/peejfT9Kf4Ylz0TeX1vgPhVk5jbnpnpmdAMXhRVmid1c7A5wlZmRCQZetCV HjprAKERb46nhzHVItLi5ibu6nlGuUY2M3mSM09IC7mYR4eK0QyuvDZCTjeFQ3j64Phnf goXB9e0WeLr4eaB79tWS/ZvxYVolUa6AP5bomqdaBsfHwDbJM6CBtCIhuOhK3OAZAOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386588; 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=ZLYURupBLiytMjwcWkaGaO8flHEZlu5JHLYd3dYhJWk=; b=grF2o9xXMm1DW88Br/fR4lFRZitYVhk0ktdyvJgHRORqZadeWE724xKsWI1fS4ImHAAM x656mX76+cnBFKKWPa8edOJU4QmHGypthDVMXlvWBd3HRcGBh4De0w3uJVhHK6iyK598U AbBPZjgFMSr7l1oniCfbBSWYXxl+4d2+0VyMDuHTCl7mAqAzcEdM1FlS+VqV+GMyR2WOl yCzL9/2VSUuhKSGBhMmLKrj23VfKR8vkjOdJATblGDjJ+xnLhdxQXTV4SIYx8/FTKhFy9 4XqaxzG5dxqsMK2MfW+rmoD0WXHo/0F6pZSJ1+Bo7lpWHDzIORO+asl0bkWX0yH0Ibw== 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=nPNp+w4s; 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 6EA24606A330; Fri, 4 Dec 2026 12:16: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=nPNp+w4s Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4E6E1F00935; Fri, 4 Dec 2026 12:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386588; bh=ZLYURupBLiytMjwcWkaGaO8flHEZlu5JHLYd3dYhJWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nPNp+w4sTcNqCZE4fPZxU1NRukb3GN0LeIL4SXD0cxrzikidrl9MZBOsznZ+YhWWR kyWrxuBmvcXkyahjFolynIHk/E5OXux7p2N2RTCnvNrBQBiWp4CDJYhPBqAB8ANQM9 1qGUP9UHzj/5hLIcFTLNMPAap0SW4XWa0Kc1v2zU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alex Deucher , Jiaming Fan Subject: [PATCH 6.6 0987/1167] drm/radeon: only unregister the ATPX handler if we registered it Date: Fri, 4 Dec 2026 19:06:54 +0900 Message-ID: <20261204100727.910572259@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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 6.6-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; @@ -601,7 +602,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; } /** @@ -611,5 +613,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; }