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=1796389198; b=NUhNS4ZvYg5h4l7uUcbDTaJVuveOho3+5D9vW50lf1Wa0eUZ1tD4+GdF9s/VOFL+oLW1 GfFA3vpHwtfJj5wJqo186htyj8SjNI0HcHVXUehQShGpSCAJuu4QKja7yzvGSxnCUhtbl 6lkBDOagPYp1dahwZ9CgUZUB4rQW2PXZN7w2cYYxpKHydOi+O3XEiEfpwdVTgKPIV5gt1 IP59whme/ipmRvwljodGc4OZxjhTyuIV0FDmmeApmpkuuRl2EghaxZSB2pQ9s3MeWNfvQ Ff7mzfHGLY8GDrd65Ee+HuYkUWVmuO3gdzIahhNONMpZ7818NH26hRZ+9A1EwfCvgsg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389198; 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=kNHmbDL95kvtDY1Q27nAul4u/01TSv/Ukt+KfdhvP6o=; b=4c+k+KPaIb0FKsbpc9WcvkZbikfKWtpPn7ZU7jJB5lCyfOPf+DZinWtUOU88hLjxeoFR sD6ry6AZDZ1/3Lt2JEbzxEsf4tPd9ZewETjwQMdYr7wbr68lalBY47MIKbV9HrSVA81p8 nYAcUO565nstrPekfWmP/1owinbefPeK4bv3GA5FGyF1ZUgrqgn2GcIbEUwQluvyIsZoq oLJLDeDQy5DFJ+GbkOC4Z1ouYZDsN/s36ZfZN/VbL2XreulXpmPAlBcdJdnZSA7AwF/DJ lG9phuqGbJjbNXEtvNz51BoNsedzmQDbpN0dkfMoCPDGV08iHVW7L2+pAIsOOS5Qm2w== 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=zU48cU6m; 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 C1C64606A322; Fri, 4 Dec 2026 12:59:58 +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=zU48cU6m Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3ABC51F000C2; Fri, 4 Dec 2026 12:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389198; bh=kNHmbDL95kvtDY1Q27nAul4u/01TSv/Ukt+KfdhvP6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zU48cU6mUC9J5uwKj9I+wcLZ8DBjORbZp7Yib6X4HWQxcIVTvXuTfIk5dNTxTVqEt Rra/X2XwzHd+a/WqbzkPm13tJljU66ofhMlZgnUpOz+npQDLbYKp2tsFuf7pnf92hK 8TLID20gWnWB2alSADkcvOVwZqPkKR4AEoFblXVc= 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 0902/1059] drm/amdgpu: only unregister the ATPX handler if we registered it Date: Fri, 4 Dec 2026 19:07:13 +0900 Message-ID: <20261204100707.380938862@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: 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.1-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; @@ -661,7 +662,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; } /** @@ -671,5 +673,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; }