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=1796383753; b=YYtS4T1VsK4ql6p7J5UUmF+hE0iKhK9lZsXHb7g/m6jbE1Gou7kecTtbvkrhOJYil/Zs WkLoDW2KP/AdcGHdQKD2WSxBLoPACU6Hv4AQVlYSlQ+pumzZaarxOVChfrv6k5v9QXHQU 8x5dwvFnR65b13ouKXuwGp1H1duW2I96ngMJ3ve3RhsEEA26uORdUc6F2O0Vdbh1NY5F1 MdPYuGKt9A02zXH4ympkACVQ1uF/XjjRW9Wn7nL73ZHBLZAnUupPyWrd5oBK4qt7TVg84 Yx4vQWqu4ylVQU92bYTFN/bIhXJvIKW4Q5Q2Mc9DqpO/9SxHLJ42JHgSn1/DmPX6uGA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383753; 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=VqNPPHqsh564akbL5mkaAg3bqweyDC8jhnzhxYReOR0=; b=rsPwgZjnAjNx5GDhvcQ/5SczZvwZjgy2NBs5GeZKwOM3d9EtL3+a6MKdGJcYd5QkJGkf QLXjtmOQ9aFoz+5CAV3DZCB1Jwj9ohwzo1gI2VYQ2VQtdCBjtzZvIrbG3t70wjiZV3HJH 8wi+Vaj3A7SEr1lvFvLHqMW7u/Qu/eqHvHJRTs3iq4gvypsE3gzqRrDXwaWyQw8yJvQ5E cgDeZAK//imxDnSY63fiy3zdwXcrd5vGBhvNYScdFZOqXVHla8S+kNkiOmnoX56UYbgEH QkH4PClkCgRm2o3SGL0tdWxKVSRzg4ugYKPEt1WpYvDz+Tc738WriSuk+a2hl7LOqcQ== 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=dTYcl62p; 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 B3241606A322; Fri, 4 Dec 2026 11:29: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=dTYcl62p Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D6971F000C2; Fri, 4 Dec 2026 11:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383753; bh=VqNPPHqsh564akbL5mkaAg3bqweyDC8jhnzhxYReOR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dTYcl62ptCpwiIJiw7+sc0nxHoZRtYxz2Go1lmmXlTuplj+FcQwRvgA5aw4lVGWHd RRmzs6JszbIwI4/0Z5Wv1h2ztxrS09etRYU+OFUdNBR420ufJqxQLIoUh90Og+9uzl i6xFo8DqWFWHCbyBPQs4FHNyJKr9cPwxnZYTriZA= 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 327/555] drm/radeon: only unregister the ATPX handler if we registered it Date: Fri, 4 Dec 2026 19:06:10 +0900 Message-ID: <20261204100622.348636308@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 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; }