stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, "Maíra Canal" <mcanal@igalia.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Sasha Levin" <sashal@kernel.org>
Subject: [PATCH 6.1 29/83] drm/vc4: dont check if plane->state->fb == state->fb
Date: Thu, 11 Apr 2024 11:57:01 +0200	[thread overview]
Message-ID: <20240411095413.554170983@linuxfoundation.org> (raw)
In-Reply-To: <20240411095412.671665933@linuxfoundation.org>

6.1-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Maíra Canal <mcanal@igalia.com>

[ Upstream commit 5ee0d47dcf33efd8950b347dcf4d20bab12a3fa9 ]

Currently, when using non-blocking commits, we can see the following
kernel warning:

[  110.908514] ------------[ cut here ]------------
[  110.908529] refcount_t: underflow; use-after-free.
[  110.908620] WARNING: CPU: 0 PID: 1866 at lib/refcount.c:87 refcount_dec_not_one+0xb8/0xc0
[  110.908664] Modules linked in: rfcomm snd_seq_dummy snd_hrtimer snd_seq snd_seq_device cmac algif_hash aes_arm64 aes_generic algif_skcipher af_alg bnep hid_logitech_hidpp vc4 brcmfmac hci_uart btbcm brcmutil bluetooth snd_soc_hdmi_codec cfg80211 cec drm_display_helper drm_dma_helper drm_kms_helper snd_soc_core snd_compress snd_pcm_dmaengine fb_sys_fops sysimgblt syscopyarea sysfillrect raspberrypi_hwmon ecdh_generic ecc rfkill libaes i2c_bcm2835 binfmt_misc joydev snd_bcm2835(C) bcm2835_codec(C) bcm2835_isp(C) v4l2_mem2mem videobuf2_dma_contig snd_pcm bcm2835_v4l2(C) raspberrypi_gpiomem bcm2835_mmal_vchiq(C) videobuf2_v4l2 snd_timer videobuf2_vmalloc videobuf2_memops videobuf2_common snd videodev vc_sm_cma(C) mc hid_logitech_dj uio_pdrv_genirq uio i2c_dev drm fuse dm_mod drm_panel_orientation_quirks backlight ip_tables x_tables ipv6
[  110.909086] CPU: 0 PID: 1866 Comm: kodi.bin Tainted: G         C         6.1.66-v8+ #32
[  110.909104] Hardware name: Raspberry Pi 3 Model B Rev 1.2 (DT)
[  110.909114] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[  110.909132] pc : refcount_dec_not_one+0xb8/0xc0
[  110.909152] lr : refcount_dec_not_one+0xb4/0xc0
[  110.909170] sp : ffffffc00913b9c0
[  110.909177] x29: ffffffc00913b9c0 x28: 000000556969bbb0 x27: 000000556990df60
[  110.909205] x26: 0000000000000002 x25: 0000000000000004 x24: ffffff8004448480
[  110.909230] x23: ffffff800570b500 x22: ffffff802e03a7bc x21: ffffffecfca68c78
[  110.909257] x20: ffffff8002b42000 x19: ffffff802e03a600 x18: 0000000000000000
[  110.909283] x17: 0000000000000011 x16: ffffffffffffffff x15: 0000000000000004
[  110.909308] x14: 0000000000000fff x13: ffffffed577e47e0 x12: 0000000000000003
[  110.909333] x11: 0000000000000000 x10: 0000000000000027 x9 : c912d0d083728c00
[  110.909359] x8 : c912d0d083728c00 x7 : 65646e75203a745f x6 : 746e756f63666572
[  110.909384] x5 : ffffffed579f62ee x4 : ffffffed579eb01e x3 : 0000000000000000
[  110.909409] x2 : 0000000000000000 x1 : ffffffc00913b750 x0 : 0000000000000001
[  110.909434] Call trace:
[  110.909441]  refcount_dec_not_one+0xb8/0xc0
[  110.909461]  vc4_bo_dec_usecnt+0x4c/0x1b0 [vc4]
[  110.909903]  vc4_cleanup_fb+0x44/0x50 [vc4]
[  110.910315]  drm_atomic_helper_cleanup_planes+0x88/0xa4 [drm_kms_helper]
[  110.910669]  vc4_atomic_commit_tail+0x390/0x9dc [vc4]
[  110.911079]  commit_tail+0xb0/0x164 [drm_kms_helper]
[  110.911397]  drm_atomic_helper_commit+0x1d0/0x1f0 [drm_kms_helper]
[  110.911716]  drm_atomic_commit+0xb0/0xdc [drm]
[  110.912569]  drm_mode_atomic_ioctl+0x348/0x4b8 [drm]
[  110.913330]  drm_ioctl_kernel+0xec/0x15c [drm]
[  110.914091]  drm_ioctl+0x24c/0x3b0 [drm]
[  110.914850]  __arm64_sys_ioctl+0x9c/0xd4
[  110.914873]  invoke_syscall+0x4c/0x114
[  110.914897]  el0_svc_common+0xd0/0x118
[  110.914917]  do_el0_svc+0x38/0xd0
[  110.914936]  el0_svc+0x30/0x8c
[  110.914958]  el0t_64_sync_handler+0x84/0xf0
[  110.914979]  el0t_64_sync+0x18c/0x190
[  110.914996] ---[ end trace 0000000000000000 ]---

This happens because, although `prepare_fb` and `cleanup_fb` are
perfectly balanced, we cannot guarantee consistency in the check
plane->state->fb == state->fb. This means that sometimes we can increase
the refcount in `prepare_fb` and don't decrease it in `cleanup_fb`. The
opposite can also be true.

In fact, the struct drm_plane .state shouldn't be accessed directly
but instead, the `drm_atomic_get_new_plane_state()` helper function should
be used. So, we could stick to this check, but using
`drm_atomic_get_new_plane_state()`. But actually, this check is not really
needed. We can increase and decrease the refcount symmetrically without
problems.

This is going to make the code more simple and consistent.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
Acked-by: Maxime Ripard <mripard@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240105175908.242000-1-mcanal@igalia.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/gpu/drm/vc4/vc4_plane.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_plane.c b/drivers/gpu/drm/vc4/vc4_plane.c
index eb08020154f30..7e6648b277b25 100644
--- a/drivers/gpu/drm/vc4/vc4_plane.c
+++ b/drivers/gpu/drm/vc4/vc4_plane.c
@@ -1415,9 +1415,6 @@ static int vc4_prepare_fb(struct drm_plane *plane,
 
 	drm_gem_plane_helper_prepare_fb(plane, state);
 
-	if (plane->state->fb == state->fb)
-		return 0;
-
 	return vc4_bo_inc_usecnt(bo);
 }
 
@@ -1426,7 +1423,7 @@ static void vc4_cleanup_fb(struct drm_plane *plane,
 {
 	struct vc4_bo *bo;
 
-	if (plane->state->fb == state->fb || !state->fb)
+	if (!state->fb)
 		return;
 
 	bo = to_vc4_bo(&drm_fb_dma_get_gem_obj(state->fb, 0)->base);
-- 
2.43.0




  parent reply	other threads:[~2024-04-11 10:46 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11  9:56 [PATCH 6.1 00/83] 6.1.86-rc1 review Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 01/83] wifi: ath9k: fix LNA selection in ath_ant_try_scan() Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 02/83] bnx2x: Fix firmware version string character counts Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 03/83] batman-adv: Return directly after a failed batadv_dat_select_candidates() in batadv_dat_forward_data() Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 04/83] batman-adv: Improve exception handling in batadv_throw_uevent() Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 05/83] wifi: rtw89: pci: enlarge RX DMA buffer to consider size of RX descriptor Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 06/83] VMCI: Fix memcpy() run-time warning in dg_dispatch_as_host() Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 07/83] wifi: iwlwifi: pcie: Add the PCI device id for new hardware Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 08/83] panic: Flush kernel log buffer at the end Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 09/83] cpuidle: Avoid potential overflow in integer multiplication Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 10/83] arm64: dts: rockchip: fix rk3328 hdmi ports node Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 11/83] arm64: dts: rockchip: fix rk3399 " Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 12/83] ionic: set adminq irq affinity Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 13/83] net: skbuff: add overflow debug check to pull/push helpers Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 14/83] firmware: tegra: bpmp: Return directly after a failed kzalloc() in get_filename() Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 15/83] wifi: brcmfmac: Add DMI nvram filename quirk for ACEPC W5 Pro Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 16/83] pstore/zone: Add a null pointer check to the psz_kmsg_read Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 17/83] tools/power x86_energy_perf_policy: Fix file leak in get_pkg_num() Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 18/83] net: pcs: xpcs: Return EINVAL in the internal methods Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 19/83] dma-direct: Leak pages on dma_set_decrypted() failure Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 20/83] wifi: ath11k: decrease MHI channel buffer length to 8KB Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 21/83] cpufreq: Dont unregister cpufreq cooling on CPU hotplug Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 22/83] btrfs: handle chunk tree lookup error in btrfs_relocate_sys_chunks() Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 23/83] btrfs: export: handle invalid inode or root reference in btrfs_get_parent() Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 24/83] btrfs: send: handle path ref underflow in header iterate_inode_ref() Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 25/83] ice: use relative VSI index for VFs instead of PF VSI number Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 26/83] net/smc: reduce rtnl pressure in smc_pnet_create_pnetids_list() Greg Kroah-Hartman
2024-04-11  9:56 ` [PATCH 6.1 27/83] Bluetooth: btintel: Fix null ptr deref in btintel_read_version Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 28/83] Bluetooth: btmtk: Add MODULE_FIRMWARE() for MT7922 Greg Kroah-Hartman
2024-04-11  9:57 ` Greg Kroah-Hartman [this message]
2024-04-11  9:57 ` [PATCH 6.1 30/83] Input: synaptics-rmi4 - fail probing if memory allocation for "phys" fails Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 31/83] drm: panel-orientation-quirks: Add quirk for GPD Win Mini Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 32/83] pinctrl: renesas: checker: Limit cfg reg enum checks to provided IDs Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 33/83] sysv: dont call sb_bread() with pointers_lock held Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 34/83] scsi: lpfc: Fix possible memory leak in lpfc_rcv_padisc() Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 35/83] isofs: handle CDs with bad root inode but good Joliet root directory Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 36/83] ASoC: Intel: common: DMI remap for rebranded Intel NUC M15 (LAPRC710) laptops Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 37/83] rcu-tasks: Repair RCU Tasks Trace quiescence check Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 38/83] Julia Lawall reported this null pointer dereference, this should fix it Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 39/83] media: sta2x11: fix irq handler cast Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 40/83] ALSA: firewire-lib: handle quirk to calculate payload quadlets as data block counter Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 41/83] ext4: add a hint for block bitmap corrupt state in mb_groups Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 42/83] ext4: forbid commit inconsistent quota data when errors=remount-ro Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 43/83] drm/amd/display: Fix nanosec stat overflow Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 44/83] drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init() Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 45/83] SUNRPC: increase size of rpc_wait_queue.qlen from unsigned short to unsigned int Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 46/83] Revert "ACPI: PM: Block ASUS B1400CEAE from suspend to idle by default" Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 47/83] libperf evlist: Avoid out-of-bounds access Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 48/83] input/touchscreen: imagis: Correct the maximum touch area value Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 49/83] block: prevent division by zero in blk_rq_stat_sum() Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 50/83] RDMA/cm: add timeout to cm_destroy_id wait Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 51/83] Input: imagis - use FIELD_GET where applicable Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 52/83] Input: allocate keycode for Display refresh rate toggle Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 53/83] platform/x86: touchscreen_dmi: Add an extra entry for a variant of the Chuwi Vi8 tablet Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 54/83] perf/x86/amd/lbr: Discard erroneous branch entries Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 55/83] ktest: force $buildonly = 1 for make_warnings_file test type Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 56/83] ring-buffer: use READ_ONCE() to read cpu_buffer->commit_page in concurrent environment Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 57/83] tools: iio: replace seekdir() in iio_generic_buffer Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 58/83] bus: mhi: host: Add MHI_PM_SYS_ERR_FAIL state Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 59/83] usb: gadget: uvc: mark incomplete frames with UVC_STREAM_ERR Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 60/83] thunderbolt: Keep the domain powered when USB4 port is in redrive mode Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 61/83] usb: typec: tcpci: add generic tcpci fallback compatible Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 62/83] usb: sl811-hcd: only defined function checkdone if QUIRK2 is defined Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 63/83] thermal/of: Assume polling-delay(-passive) 0 when absent Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 64/83] ASoC: soc-core.c: Skip dummy codec when adding platforms Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 65/83] fbdev: viafb: fix typo in hw_bitblt_1 and hw_bitblt_2 Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 66/83] io_uring: clear opcode specific data for an early failure Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 67/83] drivers/nvme: Add quirks for device 126f:2262 Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 68/83] fbmon: prevent division by zero in fb_videomode_from_videomode() Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 69/83] netfilter: nf_tables: release batch on table validation from abort path Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 70/83] netfilter: nf_tables: release mutex after nft_gc_seq_end " Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 71/83] netfilter: nf_tables: discard table flag update with pending basechain deletion Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 72/83] tty: n_gsm: require CAP_NET_ADMIN to attach N_GSM0710 ldisc Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 73/83] gcc-plugins/stackleak: Avoid .head.text section Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 74/83] Revert "scsi: sd: usb_storage: uas: Access media prior to querying device properties" Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 75/83] Revert "scsi: core: Add struct for args to execution functions" Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 76/83] scsi: sd: usb_storage: uas: Access media prior to querying device properties Greg Kroah-Hartman
2024-04-11 11:30   ` Cyril Brulebois
2024-04-11  9:57 ` [PATCH 6.1 77/83] virtio: reenable config if freezing device failed Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 78/83] randomize_kstack: Improve entropy diffusion Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 79/83] platform/x86: intel-vbtn: Update tablet mode switch at end of probe Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 80/83] Bluetooth: btintel: Fixe build regression Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 81/83] net: mpls: error out if inner headers are not set Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 82/83] VMCI: Fix possible memcpy() run-time warning in vmci_datagram_invoke_guest_handler() Greg Kroah-Hartman
2024-04-11  9:57 ` [PATCH 6.1 83/83] Revert "drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init()" Greg Kroah-Hartman
2024-04-11 11:59 ` [PATCH 6.1 00/83] 6.1.86-rc1 review Pavel Machek
2024-04-11 14:15   ` Greg Kroah-Hartman
2024-04-12 19:31     ` Pavel Machek
2024-04-11 12:04 ` Pavel Machek
2024-04-11 17:13 ` SeongJae Park
2024-04-11 19:29 ` Florian Fainelli
2024-04-11 23:43 ` Shuah Khan
2024-04-12  6:38 ` Shreeya Patel
2024-04-12  7:25 ` Ron Economos
2024-04-12  8:04 ` Jon Hunter
2024-04-12 15:14 ` Naresh Kamboju
2024-04-12 20:15 ` Mateusz Jończyk
2024-04-12 22:23 ` Kelsey Steele

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240411095413.554170983@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=mcanal@igalia.com \
    --cc=mripard@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).