linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 5.15 01/69] fbdev: Restart conflicting fb removal loop when unregistering devices
@ 2022-08-11 15:55 Sasha Levin
  2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 02/69] drm/r128: Fix undefined behavior due to shift overflowing the constant Sasha Levin
                   ` (61 more replies)
  0 siblings, 62 replies; 63+ messages in thread
From: Sasha Levin @ 2022-08-11 15:55 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Javier Martinez Canillas, Daniel Vetter, Sasha Levin, daniel,
	deller, tzimmermann, sam, alexander.deucher, deng.changcheng,
	linux-fbdev, dri-devel

From: Javier Martinez Canillas <javierm@redhat.com>

[ Upstream commit 3367aa7d74d240261de2543ddb35531ccad9d884 ]

Drivers that want to remove registered conflicting framebuffers prior to
register their own framebuffer, call to remove_conflicting_framebuffers().

This function takes the registration_lock mutex, to prevent a race when
drivers register framebuffer devices. But if a conflicting framebuffer
device is found, the underlaying platform device is unregistered and this
will lead to the platform driver .remove callback to be called. Which in
turn will call to unregister_framebuffer() that takes the same lock.

To prevent this, a struct fb_info.forced_out field was used as indication
to unregister_framebuffer() whether the mutex has to be grabbed or not.

But this could be unsafe, since the fbdev core is making assumptions about
what drivers may or may not do in their .remove callbacks. Allowing to run
these callbacks with the registration_lock held can cause deadlocks, since
the fbdev core has no control over what drivers do in their removal path.

A better solution is to drop the lock before platform_device_unregister(),
so unregister_framebuffer() can take it when called from the fbdev driver.
The lock is acquired again after the device has been unregistered and at
this point the removal loop can be restarted.

Since the conflicting framebuffer device has already been removed, the
loop would just finish when no more conflicting framebuffers are found.

Suggested-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20220511113039.1252432-1-javierm@redhat.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/video/fbdev/core/fbmem.c | 22 +++++++++++++++-------
 include/linux/fb.h               |  1 -
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
index 528c87ff14d8..619d82e20d4e 100644
--- a/drivers/video/fbdev/core/fbmem.c
+++ b/drivers/video/fbdev/core/fbmem.c
@@ -1568,6 +1568,7 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
 {
 	int i;
 
+restart_removal:
 	/* check all firmware fbs and kick off if the base addr overlaps */
 	for_each_registered_fb(i) {
 		struct apertures_struct *gen_aper;
@@ -1602,12 +1603,23 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
 				 */
 				do_unregister_framebuffer(registered_fb[i]);
 			} else if (dev_is_platform(device)) {
-				registered_fb[i]->forced_out = true;
+				/*
+				 * Drop the lock because if the device is unregistered, its
+				 * driver will call to unregister_framebuffer(), that takes
+				 * this lock.
+				 */
+				mutex_unlock(&registration_lock);
 				platform_device_unregister(to_platform_device(device));
+				mutex_lock(&registration_lock);
 			} else {
 				pr_warn("fb%d: cannot remove device\n", i);
 				do_unregister_framebuffer(registered_fb[i]);
 			}
+			/*
+			 * Restart the removal loop now that the device has been
+			 * unregistered and its associated framebuffer gone.
+			 */
+			goto restart_removal;
 		}
 	}
 }
@@ -1945,13 +1957,9 @@ EXPORT_SYMBOL(register_framebuffer);
 void
 unregister_framebuffer(struct fb_info *fb_info)
 {
-	bool forced_out = fb_info->forced_out;
-
-	if (!forced_out)
-		mutex_lock(&registration_lock);
+	mutex_lock(&registration_lock);
 	do_unregister_framebuffer(fb_info);
-	if (!forced_out)
-		mutex_unlock(&registration_lock);
+	mutex_unlock(&registration_lock);
 }
 EXPORT_SYMBOL(unregister_framebuffer);
 
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 3d7306c9a706..02f362c661c8 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -502,7 +502,6 @@ struct fb_info {
 	} *apertures;
 
 	bool skip_vt_switch; /* no VT switch on suspend/resume required */
-	bool forced_out; /* set when being removed by another driver */
 };
 
 static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 63+ messages in thread

end of thread, other threads:[~2022-08-11 16:22 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-11 15:55 [PATCH AUTOSEL 5.15 01/69] fbdev: Restart conflicting fb removal loop when unregistering devices Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 02/69] drm/r128: Fix undefined behavior due to shift overflowing the constant Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 03/69] ath10k: htt_tx: do not interpret Eth frames as WiFi Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 04/69] ath10k: fix misreported tx bandwidth for 160Mhz Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 05/69] drm/nouveau: clear output poll workers before nouveau_fbcon_destroy() Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 06/69] drm/panfrost: Handle HW_ISSUE_TTRX_2968_TTRX_3162 Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 07/69] drm/panfrost: Don't set L2_MMU_CONFIG quirks Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 08/69] drm/panfrost: Add arm,mali-valhall-jm compatible Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 09/69] ath10k: fix regdomain info of iw reg set/get Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 10/69] bpf, sockmap: Fix sk->sk_forward_alloc warn_on in sk_stream_kill_queues Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 11/69] drm/amd/display: fix system hang when PSR exits Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 12/69] drm/amd/display: Detect dpcd_rev when hotplug mst monitor Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 13/69] drm/probe-helper: Default to 640x480 if no EDID on DP Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 14/69] libbpf: Fix an error in 64bit relocation value computation Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 15/69] drm/amd/display: Fix dpp dto for disabled pipes Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 16/69] drm/radeon: integer overflow in radeon_mode_dumb_create() Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 17/69] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 18/69] udmabuf: Set the DMA mask for the udmabuf device (v2) Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 19/69] net/mlx5: Add HW definitions of vport debug counters Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 20/69] drm/amd/display: Fix monitor flash issue Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 21/69] net: phy: marvell-88x2222: set proper phydev->port Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 22/69] selftests: mlxsw: resource_scale: Allow skipping a test Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 23/69] net: stmmac: make mdio register skips PHY scanning for fixed-link Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 24/69] net: dsa: ar9331: fix potential dead lock on mdio access Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 25/69] media: davinci: vpif: add missing of_node_put() in vpif_probe() Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 26/69] media: mediatek: vcodec: prevent kernel crash when scp ipi timeout Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 27/69] media: airspy: respect the DMA coherency rules Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 28/69] media: pvrusb2: fix memory leak in pvr_probe Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 29/69] rcu: Apply noinstr to rcu_idle_enter() and rcu_idle_exit() Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 30/69] drm/bridge/tc358775: Fix DSI clock division for vsync delay calculation Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 31/69] uprobe: gate bpf call behind BPF_EVENTS Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 32/69] rcutorture: Fix memory leak in rcu_test_debug_objects() Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 33/69] rcuscale: Fix smp_processor_id()-in-preemptible warnings Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 34/69] refscale: Convert test_lock spinlock to raw_spinlock Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 35/69] mlxsw: cmd: Increase 'config_profile.flood_mode' length Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 36/69] amdgpu/pm: Fix possible array out-of-bounds if SCLK levels != 2 Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 37/69] media: mediatek: vcodec: return EINVAL if plane is too small Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 38/69] media: atmel: atmel-isc-base: allow wb ctrls to be changed when isc is not configured Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 39/69] kselftests: Enable the echo command to print newlines in Makefile Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 40/69] ipv6/addrconf: fix timing bug in tempaddr regen Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 41/69] drm/amdgpu/display/dc: Fix null pointer exception Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 42/69] scripts: get_feat.pl: use /usr/bin/env to find perl Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 43/69] drm/amdgpu: skip whole ras bad page framework on sriov Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 44/69] drm/amd/display: Guard against ddc_pin being NULL for AUX Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 45/69] iov_iter_get_pages{,_alloc}(): cap the maxsize with MAX_RW_COUNT Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 46/69] drm/msm/gem: Drop obj lock in msm_gem_free_object() Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 47/69] scripts: sphinx-pre-install: fix venv version check logic Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 48/69] crypto: vmx - Fix warning on p8_ghash_alg Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 49/69] libbpf: Disable SEC pragma macro on GCC Sasha Levin
2022-08-11 15:55 ` [PATCH AUTOSEL 5.15 50/69] drm/nouveau/nvkm: use list_add_tail() when building object tree Sasha Levin
2022-08-11 15:56 ` [PATCH AUTOSEL 5.15 51/69] crypto: ccree - Add missing clk_disable_unprepare() in cc_pm_resume() Sasha Levin
2022-08-11 15:56 ` [PATCH AUTOSEL 5.15 52/69] bpf: Fix check against plain integer v 'NULL' Sasha Levin
2022-08-11 15:56 ` [PATCH AUTOSEL 5.15 53/69] media: rkisp1: Disable runtime PM in probe error path Sasha Levin
2022-08-11 15:56 ` [PATCH AUTOSEL 5.15 54/69] bpf: Don't redirect packets with invalid pkt_len Sasha Levin
2022-08-11 15:56 ` [PATCH AUTOSEL 5.15 55/69] can: sja1000: Add Quirk for RZ/N1 SJA1000 CAN controller Sasha Levin
2022-08-11 15:56 ` [PATCH AUTOSEL 5.15 56/69] net/cdc_ncm: Increase NTB max RX/TX values to 64kb Sasha Levin
2022-08-11 15:56 ` [PATCH AUTOSEL 5.15 57/69] Bluetooth: hci_bcm: Add BCM4349B1 variant Sasha Levin
2022-08-11 15:56 ` [PATCH AUTOSEL 5.15 58/69] Bluetooth: Collect kcov coverage from hci_rx_work Sasha Levin
2022-08-11 15:56 ` [PATCH AUTOSEL 5.15 59/69] bpf/selftests: Fix couldn't retrieve pinned program in xdp veth test Sasha Levin
2022-08-11 15:56 ` [PATCH AUTOSEL 5.15 60/69] drm/amdkfd: Correct mmu_notifier_get failure handling Sasha Levin
2022-08-11 15:56 ` [PATCH AUTOSEL 5.15 61/69] btrfs: output mirror number for bad metadata Sasha Levin
2022-08-11 15:56 ` [PATCH AUTOSEL 5.15 62/69] net: ethernet: stmicro: stmmac: first disable all queues and disconnect in release Sasha Levin
2022-08-11 15:56 ` [PATCH AUTOSEL 5.15 63/69] wifi: rtl8xxxu: Fix the error handling of the probe function Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).