From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED2ED1427A; Thu, 28 May 2026 13:19:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.2 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779974358; cv=none; b=ioI2xOt2sAjHdQsOspCu4KGTNKFPUh9V0JVJk8Bxn23kZbExqlBHutceZyoWuoKnH0uttZKl/gciM9QmRhDIMU58kAHlxdpPrb0t2XQIIdi+n2zArhzHFPwQsFEbUCTMX3AD8bI++TZGSzUG2Yl4jRUv+HFfxwmTnv6KihiobuQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779974358; c=relaxed/simple; bh=ehkATJoTyNmcxa0ascaG2q6KHG4mrVYTfyx04r/OzSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kuXQF1L5uGmN0/FecORB5zRdBynP9VLrzTgDWcBUdhnedZQIDqEx3HjqWQSwJc7izSiup5+hy6Jxq6V6OROeByhixgpIFpzGuglUTME0cYMRV6UOBNIei95IBJqDrWy95nckUrPgXOTseC+jxpCwpyy3FJyJNj7n1jCeoJI/Tro= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=d+mF7kLD; arc=none smtp.client-ip=220.197.31.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="d+mF7kLD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=5p gYK/c6yag7oUDNjB7BB4xzOjsTGZrrPSqPB/w4kuc=; b=d+mF7kLDMSPHVOx4ac 9At9SR0dImadwnBqzVBea+cwFkKbGVatTvcfEPvqQ/2UJiDWd637lsozUEiDDMS/ A8p+h2VJZFI2nfU3OIhu4lDe/dCCL8ejedvK3fs4/JfRElk404KZ7RYTSHpN93LA SMB6NAjUMB4pABhtV2yDBe2ug= Received: from China-163-team (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wD373KaQBhq1y1jAA--.16331S3; Thu, 28 May 2026 21:18:25 +0800 (CST) From: Wenshan Lan To: gregkh@linuxfoundation.org, sashal@kernel.org, stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Thomas Zimmermann , Javier Martinez Canillas , Alex Deucher , dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Wenshan Lan Subject: [PATCH 6.6.y 2/2] drm, fbcon, vga_switcheroo: Avoid race condition in fbcon setup Date: Thu, 28 May 2026 21:18:17 +0800 Message-ID: <20260528131817.59900-2-jetlan9@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260528131817.59900-1-jetlan9@163.com> References: <20260528131817.59900-1-jetlan9@163.com> Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wD373KaQBhq1y1jAA--.16331S3 X-Coremail-Antispam: 1Uf129KBjvJXoW3Ary7AF13Cry7ZrWxXw4fXwb_yoW7Xw1kpF sIkFW5KrZ5JF4ruw1Dua12ya43Aan7Cry8XrWxG3WYvw12yryF9Fs5Ary5u345Grs7Jr1j q34Syw18uryDCaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pt2NR_UUUUU= X-CM-SenderInfo: xmhwztjqz6il2tof0z/xtbC6wLYoWoYQKLvZgAA3J From: Thomas Zimmermann [ Upstream commit eb76d0f5553575599561010f24c277cc5b31d003 ] Protect vga_switcheroo_client_fb_set() with console lock. Avoids OOB access in fbcon_remap_all(). Without holding the console lock the call races with switching outputs. VGA switcheroo calls fbcon_remap_all() when switching clients. The fbcon function uses struct fb_info.node, which is set by register_framebuffer(). As the fb-helper code currently sets up VGA switcheroo before registering the framebuffer, the value of node is -1 and therefore not a legal value. For example, fbcon uses the value within set_con2fb_map() [1] as an index into an array. Moving vga_switcheroo_client_fb_set() after register_framebuffer() can result in VGA switching that does not switch fbcon correctly. Therefore move vga_switcheroo_client_fb_set() under fbcon_fb_registered(), which already holds the console lock. Fbdev calls fbcon_fb_registered() from within register_framebuffer(). Serializes the helper with VGA switcheroo's call to fbcon_remap_all(). Although vga_switcheroo_client_fb_set() takes an instance of struct fb_info as parameter, it really only needs the contained fbcon state. Moving the call to fbcon initialization is therefore cleaner than before. Only amdgpu, i915, nouveau and radeon support vga_switcheroo. For all other drivers, this change does nothing. Signed-off-by: Thomas Zimmermann Link: https://elixir.bootlin.com/linux/v6.17/source/drivers/video/fbdev/core/fbcon.c#L2942 # [1] Fixes: 6a9ee8af344e ("vga_switcheroo: initial implementation (v15)") Acked-by: Javier Martinez Canillas Acked-by: Alex Deucher Cc: dri-devel@lists.freedesktop.org Cc: nouveau@lists.freedesktop.org Cc: amd-gfx@lists.freedesktop.org Cc: linux-fbdev@vger.kernel.org Cc: # v2.6.34+ Link: https://patch.msgid.link/20251105161549.98836-1-tzimmermann@suse.de [ Minor context conflict resolved. ] Signed-off-by: Wenshan Lan --- drivers/gpu/drm/drm_fb_helper.c | 14 -------------- drivers/video/fbdev/core/fbcon.c | 9 +++++++++ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index eee7b56d441f..9691c93f19a0 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -30,9 +30,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include -#include #include -#include #include #include @@ -575,11 +573,6 @@ EXPORT_SYMBOL(drm_fb_helper_release_info); */ void drm_fb_helper_unregister_info(struct drm_fb_helper *fb_helper) { - struct fb_info *info = fb_helper->info; - struct device *dev = info->device; - - if (dev_is_pci(dev)) - vga_switcheroo_client_fb_set(to_pci_dev(dev), NULL); unregister_framebuffer(fb_helper->info); } EXPORT_SYMBOL(drm_fb_helper_unregister_info); @@ -1673,7 +1666,6 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper) { struct drm_client_dev *client = &fb_helper->client; struct drm_fb_helper_surface_size sizes; - struct fb_info *info; int ret; ret = drm_fb_helper_find_sizes(fb_helper, &sizes); @@ -1691,12 +1683,6 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper) strcpy(fb_helper->fb->comm, "[fbcon]"); - info = fb_helper->info; - - /* Set the fb info for vgaswitcheroo clients. Does nothing otherwise. */ - if (dev_is_pci(info->device)) - vga_switcheroo_client_fb_set(to_pci_dev(info->device), info); - return 0; } diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c index 703c4e851612..d1ac4e45eea6 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +76,7 @@ #include #include /* For counting font checksums */ #include +#include #include #include "fbcon.h" @@ -2914,6 +2916,9 @@ void fbcon_fb_unregistered(struct fb_info *info) console_lock(); + if (info->device && dev_is_pci(info->device)) + vga_switcheroo_client_fb_set(to_pci_dev(info->device), NULL); + fbcon_registered_fb[info->node] = NULL; fbcon_num_registered_fb--; @@ -3047,6 +3052,10 @@ static int do_fb_registered(struct fb_info *info) } } + /* Set the fb info for vga_switcheroo clients. Does nothing otherwise. */ + if (info->device && dev_is_pci(info->device)) + vga_switcheroo_client_fb_set(to_pci_dev(info->device), info); + return ret; } -- 2.43.0