linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org,
	Boris Brezillon <boris.brezillon@collabora.com>,
	Helen Koike <helen.koike@collabora.com>,
	Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
Subject: [PATCH 5.1 67/70] drm: dont block fb changes for async plane updates
Date: Sun,  9 Jun 2019 18:42:18 +0200	[thread overview]
Message-ID: <20190609164133.034738995@linuxfoundation.org> (raw)
In-Reply-To: <20190609164127.541128197@linuxfoundation.org>

From: Helen Koike <helen.koike@collabora.com>

commit 89a4aac0ab0e6f5eea10d7bf4869dd15c3de2cd4 upstream.

In the case of a normal sync update, the preparation of framebuffers (be
it calling drm_atomic_helper_prepare_planes() or doing setups with
drm_framebuffer_get()) are performed in the new_state and the respective
cleanups are performed in the old_state.

In the case of async updates, the preparation is also done in the
new_state but the cleanups are done in the new_state (because updates
are performed in place, i.e. in the current state).

The current code blocks async udpates when the fb is changed, turning
async updates into sync updates, slowing down cursor updates and
introducing regressions in igt tests with errors of type:

"CRITICAL: completed 97 cursor updated in a period of 30 flips, we
expect to complete approximately 15360 updates, with the threshold set
at 7680"

Fb changes in async updates were prevented to avoid the following scenario:

- Async update, oldfb = NULL, newfb = fb1, prepare fb1, cleanup fb1
- Async update, oldfb = fb1, newfb = fb2, prepare fb2, cleanup fb2
- Non-async commit, oldfb = fb2, newfb = fb1, prepare fb1, cleanup fb2 (wrong)
Where we have a single call to prepare fb2 but double cleanup call to fb2.

To solve the above problems, instead of blocking async fb changes, we
place the old framebuffer in the new_state object, so when the code
performs cleanups in the new_state it will cleanup the old_fb and we
will have the following scenario instead:

- Async update, oldfb = NULL, newfb = fb1, prepare fb1, no cleanup
- Async update, oldfb = fb1, newfb = fb2, prepare fb2, cleanup fb1
- Non-async commit, oldfb = fb2, newfb = fb1, prepare fb1, cleanup fb2

Where calls to prepare/cleanup are balanced.

Cc: <stable@vger.kernel.org> # v4.14+
Fixes: 25dc194b34dd ("drm: Block fb changes for async plane updates")
Suggested-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Helen Koike <helen.koike@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190603165610.24614-6-helen.koike@collabora.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/gpu/drm/drm_atomic_helper.c      |   22 ++++++++++++----------
 include/drm/drm_modeset_helper_vtables.h |    8 ++++++++
 2 files changed, 20 insertions(+), 10 deletions(-)

--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -1607,15 +1607,6 @@ int drm_atomic_helper_async_check(struct
 	    old_plane_state->crtc != new_plane_state->crtc)
 		return -EINVAL;
 
-	/*
-	 * FIXME: Since prepare_fb and cleanup_fb are always called on
-	 * the new_plane_state for async updates we need to block framebuffer
-	 * changes. This prevents use of a fb that's been cleaned up and
-	 * double cleanups from occuring.
-	 */
-	if (old_plane_state->fb != new_plane_state->fb)
-		return -EINVAL;
-
 	funcs = plane->helper_private;
 	if (!funcs->atomic_async_update)
 		return -EINVAL;
@@ -1646,6 +1637,8 @@ EXPORT_SYMBOL(drm_atomic_helper_async_ch
  * drm_atomic_async_check() succeeds. Async commits are not supposed to swap
  * the states like normal sync commits, but just do in-place changes on the
  * current state.
+ *
+ * TODO: Implement full swap instead of doing in-place changes.
  */
 void drm_atomic_helper_async_commit(struct drm_device *dev,
 				    struct drm_atomic_state *state)
@@ -1656,6 +1649,9 @@ void drm_atomic_helper_async_commit(stru
 	int i;
 
 	for_each_new_plane_in_state(state, plane, plane_state, i) {
+		struct drm_framebuffer *new_fb = plane_state->fb;
+		struct drm_framebuffer *old_fb = plane->state->fb;
+
 		funcs = plane->helper_private;
 		funcs->atomic_async_update(plane, plane_state);
 
@@ -1664,11 +1660,17 @@ void drm_atomic_helper_async_commit(stru
 		 * plane->state in-place, make sure at least common
 		 * properties have been properly updated.
 		 */
-		WARN_ON_ONCE(plane->state->fb != plane_state->fb);
+		WARN_ON_ONCE(plane->state->fb != new_fb);
 		WARN_ON_ONCE(plane->state->crtc_x != plane_state->crtc_x);
 		WARN_ON_ONCE(plane->state->crtc_y != plane_state->crtc_y);
 		WARN_ON_ONCE(plane->state->src_x != plane_state->src_x);
 		WARN_ON_ONCE(plane->state->src_y != plane_state->src_y);
+
+		/*
+		 * Make sure the FBs have been swapped so that cleanups in the
+		 * new_state performs a cleanup in the old FB.
+		 */
+		WARN_ON_ONCE(plane_state->fb != old_fb);
 	}
 }
 EXPORT_SYMBOL(drm_atomic_helper_async_commit);
--- a/include/drm/drm_modeset_helper_vtables.h
+++ b/include/drm/drm_modeset_helper_vtables.h
@@ -1178,6 +1178,14 @@ struct drm_plane_helper_funcs {
 	 * current one with the new plane configurations in the new
 	 * plane_state.
 	 *
+	 * Drivers should also swap the framebuffers between current plane
+	 * state (&drm_plane.state) and new_state.
+	 * This is required since cleanup for async commits is performed on
+	 * the new state, rather than old state like for traditional commits.
+	 * Since we want to give up the reference on the current (old) fb
+	 * instead of our brand new one, swap them in the driver during the
+	 * async commit.
+	 *
 	 * FIXME:
 	 *  - It only works for single plane updates
 	 *  - Async Pageflips are not supported yet



  parent reply	other threads:[~2019-06-09 16:46 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-09 16:41 [PATCH 5.1 00/70] 5.1.9-stable review Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 01/70] ethtool: fix potential userspace buffer overflow Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 02/70] Fix memory leak in sctp_process_init Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 03/70] ipv4: not do cache for local delivery if bc_forwarding is enabled Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 04/70] ipv6: fix the check before getting the cookie in rt6_get_cookie Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 05/70] net: ethernet: ti: cpsw_ethtool: fix ethtool ring param set Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 06/70] net: mvpp2: Use strscpy to handle stat strings Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 07/70] net: rds: fix memory leak in rds_ib_flush_mr_pool Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 08/70] net: sfp: read eeprom in maximum 16 byte increments Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 09/70] packet: unconditionally free po->rollover Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 10/70] pktgen: do not sleep with the thread lock held Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 11/70] Revert "fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied" Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 12/70] udp: only choose unbound UDP socket for multicast when not in a VRF Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 13/70] ipv6: use READ_ONCE() for inet->hdrincl as in ipv4 Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 14/70] ipv6: fix EFAULT on sendto with icmpv6 and hdrincl Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 15/70] net: aquantia: fix wol configuration not applied sometimes Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 16/70] neighbor: Reset gc_entries counter if new entry is released before insert Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 17/70] neighbor: Call __ipv4_neigh_lookup_noref in neigh_xmit Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 18/70] cls_matchall: avoid panic when receiving a packet before filter set Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 19/70] ipmr_base: Do not reset index in mr_table_dump Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 20/70] net/mlx4_en: ethtool, Remove unsupported SFP EEPROM high pages query Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 21/70] net/tls: replace the sleeping lock around RX resync with a bit lock Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 22/70] rcu: locking and unlocking need to always be at least barriers Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 23/70] habanalabs: fix debugfs code Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 24/70] ARC: mm: SIGSEGV userspace trying to access kernel virtual memory Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 25/70] parisc: Use implicit space register selection for loading the coherence index of I/O pdirs Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 26/70] parisc: Fix crash due alternative coding for NP iopdir_fdc bit Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 27/70] SUNRPC fix regression in umount of a secure mount Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 28/70] SUNRPC: Fix a use after free when a server rejects the RPCSEC_GSS credential Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 29/70] NFSv4.1: Again fix a race where CB_NOTIFY_LOCK fails to wake a waiter Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 30/70] NFSv4.1: Fix bug only first CB_NOTIFY_LOCK is handled Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 31/70] fuse: fallocate: fix return with locked inode Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 32/70] fuse: fix copy_file_range() in the writeback case Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 33/70] pstore: Set tfm to NULL on free_buf_for_compression Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 34/70] pstore/ram: Run without kernel crash dump region Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 35/70] kbuild: use more portable command -v for cc-cross-prefix Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 36/70] memstick: mspro_block: Fix an error code in mspro_block_issue_req() Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 37/70] mmc: tmio: fix SCC error handling to avoid false positive CRC error Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 38/70] mmc: sdhci_am654: Fix SLOTTYPE write Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 39/70] x86/power: Fix nosmt vs hibernation triple fault during resume Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 40/70] x86/insn-eval: Fix use-after-free access to LDT entry Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 41/70] i2c: xiic: Add max_read_len quirk Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 42/70] s390/mm: fix address space detection in exception handling Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 43/70] nvme-rdma: fix queue mapping when queue count is limited Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 44/70] xen-blkfront: switch kcalloc to kvcalloc for large array allocation Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 45/70] MIPS: Bounds check virt_addr_valid Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 46/70] MIPS: pistachio: Build uImage.gz by default Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 47/70] genwqe: Prevent an integer overflow in the ioctl Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 5.1 48/70] test_firmware: Use correct snprintf() limit Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 49/70] drm/rockchip: fix fb references in async update Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 50/70] drm/vc4: " Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 51/70] drm/gma500/cdv: Check vbt config bits when detecting lvds panels Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 52/70] drm/msm: fix fb references in async update Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 53/70] drm: add non-desktop quirk for Valve HMDs Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 54/70] drm/nouveau: add kconfig option to turn off nouveau legacy contexts. (v3) Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 55/70] drm: add non-desktop quirks to Sensics and OSVR headsets Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 56/70] drm: Fix timestamp docs for variable refresh properties Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 57/70] drm/amdgpu/psp: move psp version specific function pointers to early_init Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 58/70] drm/radeon: prefer lower reference dividers Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 59/70] drm/amdgpu: remove ATPX_DGPU_REQ_POWER_FOR_DISPLAYS check when hotplug-in Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 60/70] drm/i915: Fix I915_EXEC_RING_MASK Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 61/70] drm/amdgpu/soc15: skip reset on init Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 62/70] drm/amd/display: Add ASICREV_IS_PICASSO Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 63/70] drm/amdgpu: fix ring test failure issue during s3 in vce 3.0 (V2) Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 64/70] drm/i915/fbc: disable framebuffer compression on GeminiLake Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 65/70] drm/i915/gvt: emit init breadcrumb for gvt request Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 66/70] drm/i915: Maintain consistent documentation subsection ordering Greg Kroah-Hartman
2019-06-09 16:42 ` Greg Kroah-Hartman [this message]
2019-06-09 16:42 ` [PATCH 5.1 68/70] drm/i915/gvt: Initialize intel_gvt_gtt_entry in stack Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 69/70] drm/amd: fix fb references in async update Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 5.1 70/70] TTY: serial_core, add ->install Greg Kroah-Hartman
2019-06-09 22:37 ` [PATCH 5.1 00/70] 5.1.9-stable review Jiunn Chang
2019-06-10  5:57   ` Greg Kroah-Hartman
2019-06-10  6:03 ` Naresh Kamboju
2019-06-10 14:26   ` Greg Kroah-Hartman
2019-06-10  8:52 ` Jon Hunter
2019-06-10 14:25   ` Greg Kroah-Hartman
2019-06-10 14:45 ` Guenter Roeck
2019-06-10 14:51   ` Greg Kroah-Hartman
2019-06-10 22:01 ` shuah
2019-06-11  7:21   ` Greg Kroah-Hartman

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=20190609164133.034738995@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=boris.brezillon@collabora.com \
    --cc=helen.koike@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicholas.kazlauskas@amd.com \
    --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).