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=1796389186; b=t+7w/EWujKqQfQVOc97Bx4wSkWCFZBqm4L+/C+T7KCUy4S06Cvczo1mTISrqDgBJwhEq 4cyaUu4oCZIDxuePGXR2TJnFPz2WBpfrd999wGGKfLgZ4MJt/ZhMlMFSGDP2M0q8Ef+nF 8PU8yDqSvpZyrpqW8Sfmkd9KTbpr/qJ36j2EvG1/WGSeA+ISGS5mPwWuWzuYNDVMAcBfv OLsci6tYzC7T5KN/kycvmCa7Gu2IJoZnmmFNJ++fPKbl09VclPj4eKxvwKO5ntb9z/wqy YYXsONnu5lMvZAgKK9ft9d6nn2ll4Sdz5QC2uWzjy7KByNUxt8iglhLNTCFT8Etlelg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389186; 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=KwkHtoDhrQ1lwcCc35scUk2BVbJUHiwHJjM0qaQ8zR4=; b=ZGoSfuRQjJOe7rF2MxFYtbeKtQm2FT5VDvAqQfzpGUCcNGMlJ7yGK+i0EBYjq8gUskTV j5vv5j5kzMs6F7p9qwi3hHi46eryrntRrjbEj59/R0vcPQoJXlQ+1ttJtIZVlHBpAAm5v tx3TB0RARMPyw3VLlHffwRwa/VZV1KS3ZtXcEmw1y16NF8YcjpvMIgHlXAF5h+Cy7KBTU 2kOlQRRLSc+3ZrKQPFbeOAGvxA/lJ34UQtslzTK0H787JpoNk7ASENXO8n9p6xfApAllM 5S+kbqcxOkdU/guLSXnBQeEMiZ6aPuko2PzV5QQq8rXAXcHPuXUMc+gEdd5RhHJ9JVQ== 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="uS/y7s0Z"; 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 60218606A32F; Fri, 4 Dec 2026 12:59:46 +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=uS/y7s0Z Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BA811F0092C; Fri, 4 Dec 2026 12:59:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389185; bh=KwkHtoDhrQ1lwcCc35scUk2BVbJUHiwHJjM0qaQ8zR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=uS/y7s0ZSkBXveMgD6ei76EbEEOi+U3ubuSrQuyn+W3O6bnRv6IJJiPqU6NSjVlCc tr3DLZWW9UAOYDxL+zsb6ntBLW0N+cgkapYTr6ba9q5ZzUE2X0jJhxoK0Rn63TJt6P cHUpU2k6N72tzBecwrTWK3J0pIpdhSZlwOGIvK/Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alex Deucher , Jiaming Fan Subject: [PATCH 6.1 0897/1059] drm/radeon: only unregister the ATPX handler if we registered it Date: Fri, 4 Dec 2026 19:07:08 +0900 Message-ID: <20261204100707.248024715@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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; }