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=1796386508; b=GvOQ2qr0tMARzbNs74XTaHPc4sQt8SiTziX/8my9o/IDIEIQ+3njq3F/7GcXi3uRFMI4 XKit6VJtxSj8NJOCLDu0QdjKCuAf/vvP8cWOJp/8W1sXm0EuqmRsjQk7kicPaZ2muJ6yn UKSOgf533w0seBSoNSIEz954B1JZILwUOhoOKUyERBOoYzM+5RatX/bzLrzaw7mvE3Tdp 5RIV0yJvjxOD2hhPCM3sjq/agsvAjqqN76vrtlBd0PCTFI3Yvbd+rQRNiLE3jzWPr/GvK VnOZ9l8eQYYE3WArgKFCvc1Ebw6/OMfnbDDzRKGEp1XGDPWIxL7IfFJGLw4r3qiJOfA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386508; 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=uqXywxy/5Ni4fg/S0dLmT1o2IGJXrEK5kd1wXSJQhjo=; b=5CZa5HN7pz5Eb9R6hLwJnvtPxt0mBNbRI+NsVrnjqdIKfBn7ptrlUmDhKiJD2Gc42tR0 4hLPbJzqAqbs67a2ryUbf6BI2V9a2x39Q1pFMViNJH010FQwI7zJH9yOMRLqm2pHrvNU+ PJ+TN43hNwscjjw5iDyBCixVp98LL7lINaD8zcOXuIa6G79YZa1m559Ayb+mT2Bj4p0FT W80BNOISPCoAi+Cv9ULirusgbpNjXA4Hg9wAIhTsp531EF9YzB0zAt6TL7zdVfnGwjzQF I/ckiZmxGmuTg7Df0o2zfl3HP3bt2xc2GB28YNKIPXCpFIWKm8uCkDCnRKr+VIRCorw== 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=gUu7IKs2; 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 2226A606A339; Fri, 4 Dec 2026 12:15:08 +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=gUu7IKs2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C05F1F000C2; Fri, 4 Dec 2026 12:15:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386508; bh=uqXywxy/5Ni4fg/S0dLmT1o2IGJXrEK5kd1wXSJQhjo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gUu7IKs2+JgTV9YRd5KCrz8d0/DEMB11VbvCHMDA6c2Vfb0jF7LB4R8hUrjihBSFw cr6AfNRLD/EjA+yg8SKqWYkbJoKtIfkfz/VULTdzRbfC3m+EY0YLPbhEirVNSOW2BP 8+YyABuDwDkvmujXLJi4rZb4QKLlDPLAf1M+JHuY= 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 0993/1167] drm/amdgpu: only unregister the ATPX handler if we registered it Date: Fri, 4 Dec 2026 19:07:00 +0900 Message-ID: <20261204100728.068499195@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: 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.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiaming Fan commit 53fc1be11892a8e695937fdbc24db2699d23dabf upstream. amdgpu_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. amdgpu_unregister_atpx_handler() calls vga_switcheroo_unregister_handler() in either case, and that clears the slot no matter who set it. So unloading amdgpu removes a handler registered by another driver, such as apple-gmux. No AMD GPU is needed for this; loading and unloading amdgpu is enough. 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. Fixes: d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)") Reviewed-by: Alex Deucher Signed-off-by: Jiaming Fan Signed-off-by: Alex Deucher (cherry picked from commit fbb6ebeff9d5327e8d06a83a3f7daa88422c9127) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c @@ -45,6 +45,7 @@ struct amdgpu_atpx { static struct amdgpu_atpx_priv { bool atpx_detected; bool bridge_pm_usable; + bool handler_registered; unsigned int quirks; /* handle for device - and atpx */ acpi_handle dhandle; @@ -666,7 +667,8 @@ void amdgpu_register_atpx_handler(void) if (!r) return; - vga_switcheroo_register_handler(&amdgpu_atpx_handler, handler_flags); + if (!vga_switcheroo_register_handler(&amdgpu_atpx_handler, handler_flags)) + amdgpu_atpx_priv.handler_registered = true; } /** @@ -676,5 +678,14 @@ void amdgpu_register_atpx_handler(void) */ void amdgpu_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 apple-gmux, in place. + */ + if (!amdgpu_atpx_priv.handler_registered) + return; + vga_switcheroo_unregister_handler(); + amdgpu_atpx_priv.handler_registered = false; }