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=1796382193; b=ZXFsW+qSquP95Hgt74kRgxtE9MyT7VIcDqI5GRoLtQ0v+iA/FoP/lUVpNrrz0HZ7lSEh uvRJEEgZPlZkrZiS4CH4OHs7iDW4jsZKnoA/CeTIjpCzjueFQG+BpI5W5ix9fsNLGqiE6 O8WBNyUcOqJquqzgc3At8ejPVheMTyMKbjDhjU4Jl4ttnqWIg1f+wloMqhA8zTnzNIqy/ FIo97RD2NwtFr9pxocmaJ5S/mYxd67kWgHQQX9KS75JrEvKP+XIWjR7wW3hqyinKRD+xE Dk7l/+50tKZKynA8y6OwEW6ewd4mvx+XjdXoL1Mc9Lv5u8N6zXQ+Kb/uJqiXnkOBtBw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382193; 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=55o99u10CjXHMi/rFwtzyhY1oBoHYLtTPYDbD7KwwJI=; b=lY3+Ac1pTCdaenI61crMSyG3ENK3K2d/p/JnIAK6E7WMxdAYimPhhKl/cbeXYh0e+zHO 42O9eDAJGjrzGxKKx3D7qYTvP6toiM9HVHauCjpY+6M1pyh706YJTEw7U3f934bMSt9da HOKzDhcwZaz2pJg188cEg3YyvjgATZbdEYIu7Bu6+0goSNZ6JbW9FucIvl+NvWJnsA1Ra e4VdpnB7OT2WTocmFX/JhPzzp9uaM1PWJsVFDEw0lDQcoac7eAttM1Wcm87sz89WM6HOc 4sgbS7TMHkK2xRfeZCO78u7GdcnLxLN9xt63aK86QqYmQIoNrs1qnHGZVD+hV0zIuRQ== 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=gtg47Jx8; 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 DA2CF606A322; Fri, 4 Dec 2026 11:03:13 +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=gtg47Jx8 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55C851F000C2; Fri, 4 Dec 2026 11:03:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382193; bh=55o99u10CjXHMi/rFwtzyhY1oBoHYLtTPYDbD7KwwJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gtg47Jx8hbciBSSG32S4/8NQbHjwu5Ma5Q/Lh1DYyWiUPp5YxD1BSxFgmIDExosc1 7FeksRNXIJP0tePfhg97hl52+6/UK3SSRqWZVokR2LTrhQC8C1itlCAdkAX1LsoHoj B+x4ccza5ZT5Ar72EUBx778oEZrC2wOiLn/kpvKs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alex Deucher , Jiaming Fan Subject: [PATCH 6.18 348/703] drm/radeon: only unregister the ATPX handler if we registered it Date: Fri, 4 Dec 2026 19:04:07 +0900 Message-ID: <20261204100637.050049500@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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; }