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=1796380703; b=dTOlRMtyyluT34gtgFkrSCJZD5PMSKrN4iEze3x6lqhkM9FJ0NxfUsEDqbvn5qYdDfPG /gaMRCNAxtwBg+uZ3BH+l9ptBMVa0jufExJ2YBsK0kviLjwMZ8V83g6GXjzIYECc6SfbT Q5be5arerMQlMCPSD7qStnLcOQcmE5kPC8Js9Je0Y/DmmK+aQoYQi9QtVPr6swR6fUQK9 dyO/LnWIBbvM82Oh/NibO8X8h37af6PkVklGPFsO7uHg8EVC+oB5uIuvg5HnzGuB1upfj FQVQHpuxUfhJA+bfYm+SUWKk4kQkVlD/QllWilaaSm+lpSV01J8c+EwlyIPnAIk0pVg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380703; 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=9OmxnouUwLHAmVw/k4EutydMwItsu8/Ql0sqGe2xf7s=; b=hBaoM0iRHIVWkAg+eeCANsu5ABiEN7U/Iar4lzDcUzQPomUy2xVB8DhMx1AbT8DONwLe AmuVmG0UIEvq+AjWDRWxbT1DBVGCeswJetXuO2BlboCS3dLAeix67Zc++hHTzpf7RgaAl QcQ/A1t35JeB0J0H2LLTbiiBwuv3mI0XWCYQSaAI0+KabkxYwx1XJDogS3yw0gecgzbHv hC7ImVc4jsTkBCWJ51vFcVwgBXuc71MU7tQepZ68zCtoofjTd6wxXp6u5Jumq7ANo3jvj xvAWmEiR17+6Eo6WfKmwsRwIYmM8R3DukASIwr3yMoUrM6SJOrG24r692VKBJT9fZCQ== 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=LD75kaDo; 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 ACF03606A32D; Fri, 4 Dec 2026 10:38:23 +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=LD75kaDo Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A5C51F00936; Fri, 4 Dec 2026 10:38:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380703; bh=9OmxnouUwLHAmVw/k4EutydMwItsu8/Ql0sqGe2xf7s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LD75kaDo0C4mU7flXt0/1O9kzTpzF/WrRlyGozIRjSCh2u3jf3g3N+uDMTEpcF6w6 8xsIFtd5dfb2sepjW+CIrYg3sHSNodLPwO+bYymYMGn/pKXo+1jUIAMNvtl19lYeAf +41HWnYq7rLVpYourLJ1951iv/evdX0MMzrG1U4k= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alex Deucher , Jiaming Fan Subject: [PATCH 7.3 387/742] drm/amdgpu: only unregister the ATPX handler if we registered it Date: Fri, 4 Dec 2026 19:04:11 +0900 Message-ID: <20261204100645.364459851@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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; }