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=1796382338; b=yzV3+cUWvM9EDsgpAWhfnzXr9AQ9ifPaK3K8sdpUuNwzzdTT3T/5LdoUe421wqX3WD83 XG5e79Jh07hGWKYcBFfHQExNbeLzDUPX+JPndiuYXrp9oIs0lXNKFeTbPwB+EA6mvZWMN IJCgqFgJW0c62fnYd3LNcQoCGfmzJniw65DFq9aOFgiiNDUx1XeWDkiNvnE0CrlMvp/0l rC4JAe4/prATJlyohDzGrOeSX9xtnGz5kjEzxfynyI34nd6JsJon5fRhPs/Qjot/JPsjB ZxjONqDB4TddJirFg79e7Gu1xpaBIHcIUd28oQElx0Jk7JM6Ne3wPOhWJ4tIQ1zoTcg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382338; 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=I/BF2kH5aGzmSyS6v+NtWnCixJtsA00226Nn3PfEgvA=; b=175QN6FwYkOdqxg7AT/jsSR0+Kfx41oQHG15xfqQrVgkvPBE2Ms4lpumCspScdp6piUC gHnTTx1Ld82TPUIyB2q646IHCfiirM7QqWHAneWd61LdYdt0Z+CZ+FjFWj599AKx3XysC Ap78vrw6xVdZWFA5lBuF/NCjlrX3EgM16uy6sEi5aG2K54dEovLp9M2BHRzwPksh/OJoL MxmwPVA2Y0HU4vw0mq++yUrTDPQjEL71ZcQZPxxN3tuWC5uK0p9cnXK3SX+qleJbJQboB 7aIxtYAeBlz/LWtIi7Nf/ADcDzOZhPGuvrVJXUXED7rSjSpG35bUSfW66WCtHOkcIJg== 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=wIXJeWYV; 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 D2A7A606A337; Fri, 4 Dec 2026 11:05:38 +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=wIXJeWYV Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14F141F000C2; Fri, 4 Dec 2026 11:05:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382338; bh=I/BF2kH5aGzmSyS6v+NtWnCixJtsA00226Nn3PfEgvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wIXJeWYVAHe35J1uc0xzpvkhSlgF5qdrh9NlEcR++UtGm/yYKzaQYm/TvhXockBBc gsjxzPqMPpWTpUu9MZpSxLNBqtJcbQoNZOWPtPWt9cmzzG84Cj+pYOnAEJ3D8wmqik df2xCXxIci5+LrHyJj+uGXSmniPw9ijLZ9vXIIUA= 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 360/703] drm/amdgpu: only unregister the ATPX handler if we registered it Date: Fri, 4 Dec 2026 19:04:19 +0900 Message-ID: <20261204100637.388894271@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: 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.18-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; @@ -663,7 +664,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; } /** @@ -673,5 +675,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; }