dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] drm: handle kernel fences in drm_gem_plane_helper_prepare_fb v2
@ 2022-04-29 13:42 Christian König
  2022-04-29 13:42 ` [PATCH 2/4] drm/amdgpu: switch DM to atomic fence helpers Christian König
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Christian König @ 2022-04-29 13:42 UTC (permalink / raw)
  To: daniel.vetter, dri-devel; +Cc: Christian König, Thomas Zimmermann

drm_gem_plane_helper_prepare_fb() was using
drm_atomic_set_fence_for_plane() which ignores all implicit fences when an
explicit fence is already set. That's rather unfortunate when the fb still
has a kernel fence we need to wait for to avoid presenting garbage on the
screen.

So instead update the fence in the plane state directly. While at it also
take care of all potential GEM objects and not just the first one.

Also remove the now unused drm_atomic_set_fence_for_plane() function, new
drivers should probably use the atomic helpers directly.

v2: improve kerneldoc, use local variable and num_planes, WARN_ON_ONCE
    on missing planes.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> (v1)
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_atomic_uapi.c       | 47 ++--------------
 drivers/gpu/drm/drm_gem_atomic_helper.c | 73 +++++++++++++++++++------
 include/drm/drm_atomic_uapi.h           |  2 -
 include/drm/drm_plane.h                 |  4 +-
 4 files changed, 62 insertions(+), 64 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c
index c6394ba13b24..434f3d4cb8a2 100644
--- a/drivers/gpu/drm/drm_atomic_uapi.c
+++ b/drivers/gpu/drm/drm_atomic_uapi.c
@@ -254,43 +254,6 @@ drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
 }
 EXPORT_SYMBOL(drm_atomic_set_fb_for_plane);
 
-/**
- * drm_atomic_set_fence_for_plane - set fence for plane
- * @plane_state: atomic state object for the plane
- * @fence: dma_fence to use for the plane
- *
- * Helper to setup the plane_state fence in case it is not set yet.
- * By using this drivers doesn't need to worry if the user choose
- * implicit or explicit fencing.
- *
- * This function will not set the fence to the state if it was set
- * via explicit fencing interfaces on the atomic ioctl. In that case it will
- * drop the reference to the fence as we are not storing it anywhere.
- * Otherwise, if &drm_plane_state.fence is not set this function we just set it
- * with the received implicit fence. In both cases this function consumes a
- * reference for @fence.
- *
- * This way explicit fencing can be used to overrule implicit fencing, which is
- * important to make explicit fencing use-cases work: One example is using one
- * buffer for 2 screens with different refresh rates. Implicit fencing will
- * clamp rendering to the refresh rate of the slower screen, whereas explicit
- * fence allows 2 independent render and display loops on a single buffer. If a
- * driver allows obeys both implicit and explicit fences for plane updates, then
- * it will break all the benefits of explicit fencing.
- */
-void
-drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,
-			       struct dma_fence *fence)
-{
-	if (plane_state->fence) {
-		dma_fence_put(fence);
-		return;
-	}
-
-	plane_state->fence = fence;
-}
-EXPORT_SYMBOL(drm_atomic_set_fence_for_plane);
-
 /**
  * drm_atomic_set_crtc_for_connector - set CRTC for connector
  * @conn_state: atomic state object for the connector
@@ -1077,10 +1040,10 @@ int drm_atomic_set_property(struct drm_atomic_state *state,
  *
  * As a contrast, with implicit fencing the kernel keeps track of any
  * ongoing rendering, and automatically ensures that the atomic update waits
- * for any pending rendering to complete. For shared buffers represented with
- * a &struct dma_buf this is tracked in &struct dma_resv.
- * Implicit syncing is how Linux traditionally worked (e.g. DRI2/3 on X.org),
- * whereas explicit fencing is what Android wants.
+ * for any pending rendering to complete. This is usually tracked in &struct
+ * dma_resv which can also contain mandatory kernel fences. Implicit syncing
+ * is how Linux traditionally worked (e.g. DRI2/3 on X.org), whereas explicit
+ * fencing is what Android wants.
  *
  * "IN_FENCE_FD”:
  *	Use this property to pass a fence that DRM should wait on before
@@ -1095,7 +1058,7 @@ int drm_atomic_set_property(struct drm_atomic_state *state,
  *
  *	On the driver side the fence is stored on the @fence parameter of
  *	&struct drm_plane_state. Drivers which also support implicit fencing
- *	should set the implicit fence using drm_atomic_set_fence_for_plane(),
+ *	should extract the implicit fence using drm_gem_plane_helper_prepare_fb(),
  *	to make sure there's consistent behaviour between drivers in precedence
  *	of implicit vs. explicit fencing.
  *
diff --git a/drivers/gpu/drm/drm_gem_atomic_helper.c b/drivers/gpu/drm/drm_gem_atomic_helper.c
index a6d89aed0bda..a5026f617739 100644
--- a/drivers/gpu/drm/drm_gem_atomic_helper.c
+++ b/drivers/gpu/drm/drm_gem_atomic_helper.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
 #include <linux/dma-resv.h>
+#include <linux/dma-fence-chain.h>
 
 #include <drm/drm_atomic_state_helper.h>
 #include <drm/drm_atomic_uapi.h>
@@ -137,29 +138,67 @@
  *
  * This function is the default implementation for GEM drivers of
  * &drm_plane_helper_funcs.prepare_fb if no callback is provided.
- *
- * See drm_atomic_set_fence_for_plane() for a discussion of implicit and
- * explicit fencing in atomic modeset updates.
  */
-int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state)
+int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane,
+				    struct drm_plane_state *state)
 {
-	struct drm_gem_object *obj;
-	struct dma_fence *fence;
+	struct dma_fence *fence = dma_fence_get(state->fence);
+	enum dma_resv_usage usage;
+	size_t i;
 	int ret;
 
 	if (!state->fb)
 		return 0;
 
-	obj = drm_gem_fb_get_obj(state->fb, 0);
-	ret = dma_resv_get_singleton(obj->resv, DMA_RESV_USAGE_WRITE, &fence);
-	if (ret)
-		return ret;
-
-	/* TODO: drm_atomic_set_fence_for_plane() should be changed to be able
-	 * to handle more fences in general for multiple BOs per fb.
+	/*
+	 * Only add the kernel fences here if there is already a fence set via
+	 * explicit fencing interfaces on the atomic ioctl.
+	 *
+	 * This way explicit fencing can be used to overrule implicit fencing,
+	 * which is important to make explicit fencing use-cases work: One
+	 * example is using one buffer for 2 screens with different refresh
+	 * rates. Implicit fencing will clamp rendering to the refresh rate of
+	 * the slower screen, whereas explicit fence allows 2 independent
+	 * render and display loops on a single buffer. If a driver allows
+	 * obeys both implicit and explicit fences for plane updates, then it
+	 * will break all the benefits of explicit fencing.
 	 */
-	drm_atomic_set_fence_for_plane(state, fence);
+	usage = fence ? DMA_RESV_USAGE_KERNEL : DMA_RESV_USAGE_WRITE;
+
+	for (i = 0; i < state->fb->format->num_planes; ++i) {
+		struct drm_gem_object *obj = drm_gem_fb_get_obj(state->fb, i);
+		struct dma_fence *new;
+
+		if (WARN_ON_ONCE(!obj))
+			continue;
+
+		ret = dma_resv_get_singleton(obj->resv, usage, &new);
+		if (ret)
+			goto error;
+
+		if (new && fence) {
+			struct dma_fence_chain *chain = dma_fence_chain_alloc();
+
+			if (!chain) {
+				ret = -ENOMEM;
+				goto error;
+			}
+
+			dma_fence_chain_init(chain, fence, new, 1);
+			fence = &chain->base;
+
+		} else if (new) {
+			fence = new;
+		}
+	}
+
+	dma_fence_put(state->fence);
+	state->fence = fence;
 	return 0;
+
+error:
+	dma_fence_put(fence);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(drm_gem_plane_helper_prepare_fb);
 
@@ -168,13 +207,13 @@ EXPORT_SYMBOL_GPL(drm_gem_plane_helper_prepare_fb);
  * @pipe: Simple display pipe
  * @plane_state: Plane state
  *
- * This function uses drm_gem_plane_helper_prepare_fb() to extract the exclusive fence
- * from &drm_gem_object.resv and attaches it to plane state for the atomic
+ * This function uses drm_gem_plane_helper_prepare_fb() to extract the fences
+ * from &drm_gem_object.resv and attaches them to the plane state for the atomic
  * helper to wait on. This is necessary to correctly implement implicit
  * synchronization for any buffers shared as a struct &dma_buf. Drivers can use
  * this as their &drm_simple_display_pipe_funcs.prepare_fb callback.
  *
- * See drm_atomic_set_fence_for_plane() for a discussion of implicit and
+ * See drm_gem_plane_helper_prepare_fb() for a discussion of implicit and
  * explicit fencing in atomic modeset updates.
  */
 int drm_gem_simple_display_pipe_prepare_fb(struct drm_simple_display_pipe *pipe,
diff --git a/include/drm/drm_atomic_uapi.h b/include/drm/drm_atomic_uapi.h
index 8cec52ad1277..4c6d39d7bdb2 100644
--- a/include/drm/drm_atomic_uapi.h
+++ b/include/drm/drm_atomic_uapi.h
@@ -49,8 +49,6 @@ drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
 			      struct drm_crtc *crtc);
 void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
 				 struct drm_framebuffer *fb);
-void drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,
-				    struct dma_fence *fence);
 int __must_check
 drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
 				  struct drm_crtc *crtc);
diff --git a/include/drm/drm_plane.h b/include/drm/drm_plane.h
index 2628c7cde2da..89ea54652e87 100644
--- a/include/drm/drm_plane.h
+++ b/include/drm/drm_plane.h
@@ -74,9 +74,7 @@ struct drm_plane_state {
 	 *
 	 * Optional fence to wait for before scanning out @fb. The core atomic
 	 * code will set this when userspace is using explicit fencing. Do not
-	 * write this field directly for a driver's implicit fence, use
-	 * drm_atomic_set_fence_for_plane() to ensure that an explicit fence is
-	 * preserved.
+	 * write this field directly for a driver's implicit fence.
 	 *
 	 * Drivers should store any implicit fence in this from their
 	 * &drm_plane_helper_funcs.prepare_fb callback. See drm_gem_plane_helper_prepare_fb()
-- 
2.25.1


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

* [PATCH 2/4] drm/amdgpu: switch DM to atomic fence helpers
  2022-04-29 13:42 [PATCH 1/4] drm: handle kernel fences in drm_gem_plane_helper_prepare_fb v2 Christian König
@ 2022-04-29 13:42 ` Christian König
  2022-05-05 10:14   ` Christian König
  2022-05-05 12:09   ` Daniel Vetter
  2022-04-29 13:42 ` [PATCH 3/4] drm/nouveau: use drm_gem_plane_helper_prepare_fb Christian König
  2022-04-29 13:42 ` [PATCH 4/4] drm/qxl: add drm_gem_plane_helper_prepare_fb Christian König
  2 siblings, 2 replies; 8+ messages in thread
From: Christian König @ 2022-04-29 13:42 UTC (permalink / raw)
  To: daniel.vetter, dri-devel
  Cc: Jude Shih, Qingqing Zhuo, Rodrigo Siqueira, Roman Li,
	Nicholas Kazlauskas, Wayne Lin, Christian König

This gives us the standard atomic implicit and explicit fencing rules.

Signed-off-by: Christian König <christian.koenig@amd.com>
Cc: Harry Wentland <harry.wentland@amd.com>
Cc: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
Cc: Roman Li <Roman.Li@amd.com>
Cc: Qingqing Zhuo <qingqing.zhuo@amd.com>
Cc: Jude Shih <shenshih@amd.com>
Cc: Wayne Lin <Wayne.Lin@amd.com>
Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 23 ++++++++-----------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 2ade82cfb1ac..c5b2417adcc6 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -83,6 +83,7 @@
 #include <drm/drm_edid.h>
 #include <drm/drm_vblank.h>
 #include <drm/drm_audio_component.h>
+#include <drm/drm_gem_atomic_helper.h>
 
 #if defined(CONFIG_DRM_AMD_DC_DCN)
 #include "ivsrcid/dcn/irqsrcs_dcn_1_0.h"
@@ -7627,6 +7628,10 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane,
 		goto error_unpin;
 	}
 
+	r = drm_gem_plane_helper_prepare_fb(plane, new_state);
+	if (unlikely(r != 0))
+		goto error_unpin;
+
 	amdgpu_bo_unreserve(rbo);
 
 	afb->address = amdgpu_bo_gpu_offset(rbo);
@@ -9160,7 +9165,6 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
 	struct dm_crtc_state *dm_old_crtc_state =
 			to_dm_crtc_state(drm_atomic_get_old_crtc_state(state, pcrtc));
 	int planes_count = 0, vpos, hpos;
-	long r;
 	unsigned long flags;
 	struct amdgpu_bo *abo;
 	uint32_t target_vblank, last_flip_vblank;
@@ -9173,6 +9177,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
 		struct dc_flip_addrs flip_addrs[MAX_SURFACES];
 		struct dc_stream_update stream_update;
 	} *bundle;
+	int r;
 
 	bundle = kzalloc(sizeof(*bundle), GFP_KERNEL);
 
@@ -9181,6 +9186,10 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
 		goto cleanup;
 	}
 
+	r = drm_atomic_helper_wait_for_fences(dev, state, false);
+	if (unlikely(r))
+		DRM_ERROR("Waiting for fences timed out!");
+
 	/*
 	 * Disable the cursor first if we're disabling all the planes.
 	 * It'll remain on the screen after the planes are re-enabled
@@ -9235,18 +9244,6 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
 		}
 
 		abo = gem_to_amdgpu_bo(fb->obj[0]);
-
-		/*
-		 * Wait for all fences on this FB. Do limited wait to avoid
-		 * deadlock during GPU reset when this fence will not signal
-		 * but we hold reservation lock for the BO.
-		 */
-		r = dma_resv_wait_timeout(abo->tbo.base.resv,
-					  DMA_RESV_USAGE_WRITE, false,
-					  msecs_to_jiffies(5000));
-		if (unlikely(r <= 0))
-			DRM_ERROR("Waiting for fences timed out!");
-
 		fill_dc_plane_info_and_addr(
 			dm->adev, new_plane_state,
 			afb->tiling_flags,
-- 
2.25.1


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

* [PATCH 3/4] drm/nouveau: use drm_gem_plane_helper_prepare_fb
  2022-04-29 13:42 [PATCH 1/4] drm: handle kernel fences in drm_gem_plane_helper_prepare_fb v2 Christian König
  2022-04-29 13:42 ` [PATCH 2/4] drm/amdgpu: switch DM to atomic fence helpers Christian König
@ 2022-04-29 13:42 ` Christian König
  2022-04-29 20:04   ` Lyude Paul
  2022-04-29 13:42 ` [PATCH 4/4] drm/qxl: add drm_gem_plane_helper_prepare_fb Christian König
  2 siblings, 1 reply; 8+ messages in thread
From: Christian König @ 2022-04-29 13:42 UTC (permalink / raw)
  To: daniel.vetter, dri-devel
  Cc: Maxime Ripard, Christian König, Karol Herbst, Ben Skeggs

Instead of manually adjusting the plane state.

Signed-off-by: Christian König <christian.koenig@amd.com>
Cc: Karol Herbst <kherbst@redhat.com>
Cc: Lyude Paul <lyude@redhat.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: Maxime Ripard <maxime@cerno.tech>
---
 drivers/gpu/drm/nouveau/dispnv50/wndw.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/dispnv50/wndw.c b/drivers/gpu/drm/nouveau/dispnv50/wndw.c
index 8642b84ea20c..bb8a4601e0d9 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/wndw.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/wndw.c
@@ -32,6 +32,7 @@
 
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
+#include <drm/drm_gem_atomic_helper.h>
 #include <drm/drm_fourcc.h>
 
 #include "nouveau_bo.h"
@@ -558,9 +559,7 @@ nv50_wndw_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state)
 			asyw->image.handle[0] = ctxdma->object.handle;
 	}
 
-	ret = dma_resv_get_singleton(nvbo->bo.base.resv,
-				     DMA_RESV_USAGE_WRITE,
-				     &asyw->state.fence);
+	ret = drm_gem_plane_helper_prepare_fb(plane, state);
 	if (ret)
 		return ret;
 
-- 
2.25.1


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

* [PATCH 4/4] drm/qxl: add drm_gem_plane_helper_prepare_fb
  2022-04-29 13:42 [PATCH 1/4] drm: handle kernel fences in drm_gem_plane_helper_prepare_fb v2 Christian König
  2022-04-29 13:42 ` [PATCH 2/4] drm/amdgpu: switch DM to atomic fence helpers Christian König
  2022-04-29 13:42 ` [PATCH 3/4] drm/nouveau: use drm_gem_plane_helper_prepare_fb Christian König
@ 2022-04-29 13:42 ` Christian König
  2022-05-04  9:27   ` Daniel Vetter
  2 siblings, 1 reply; 8+ messages in thread
From: Christian König @ 2022-04-29 13:42 UTC (permalink / raw)
  To: daniel.vetter, dri-devel
  Cc: spice-devel, Dave Airlie, virtualization, Christian König,
	Gerd Hoffmann

We could need to wait for the pin to complete here.

Signed-off-by: Christian König <christian.koenig@amd.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: virtualization@lists.linux-foundation.org
Cc: spice-devel@lists.freedesktop.org
---
 drivers/gpu/drm/qxl/qxl_display.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/qxl/qxl_display.c b/drivers/gpu/drm/qxl/qxl_display.c
index 9a9c29b1d3e1..9a64fa4c7530 100644
--- a/drivers/gpu/drm/qxl/qxl_display.c
+++ b/drivers/gpu/drm/qxl/qxl_display.c
@@ -34,6 +34,7 @@
 #include <drm/drm_plane_helper.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_simple_kms_helper.h>
+#include <drm/drm_gem_atomic_helper.h>
 
 #include "qxl_drv.h"
 #include "qxl_object.h"
@@ -829,6 +830,7 @@ static int qxl_plane_prepare_fb(struct drm_plane *plane,
 	struct qxl_device *qdev = to_qxl(plane->dev);
 	struct drm_gem_object *obj;
 	struct qxl_bo *user_bo;
+	int ret;
 
 	if (!new_state->fb)
 		return 0;
@@ -852,7 +854,11 @@ static int qxl_plane_prepare_fb(struct drm_plane *plane,
 		qxl_free_cursor(old_cursor_bo);
 	}
 
-	return qxl_bo_pin(user_bo);
+	ret = qxl_bo_pin(user_bo);
+	if (ret)
+		return ret;
+
+	return drm_gem_plane_helper_prepare_fb(plane, new_state);
 }
 
 static void qxl_plane_cleanup_fb(struct drm_plane *plane,
-- 
2.25.1


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

* Re: [PATCH 3/4] drm/nouveau: use drm_gem_plane_helper_prepare_fb
  2022-04-29 13:42 ` [PATCH 3/4] drm/nouveau: use drm_gem_plane_helper_prepare_fb Christian König
@ 2022-04-29 20:04   ` Lyude Paul
  0 siblings, 0 replies; 8+ messages in thread
From: Lyude Paul @ 2022-04-29 20:04 UTC (permalink / raw)
  To: Christian König, daniel.vetter, dri-devel
  Cc: Maxime Ripard, Christian König, Karol Herbst, Ben Skeggs

Reviewed-by: Lyude Paul <lyude@redhat.com>

Also consider this as permission to push this to drm-misc-next

On Fri, 2022-04-29 at 15:42 +0200, Christian König wrote:
> Instead of manually adjusting the plane state.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> Cc: Karol Herbst <kherbst@redhat.com>
> Cc: Lyude Paul <lyude@redhat.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: Maxime Ripard <maxime@cerno.tech>
> ---
>  drivers/gpu/drm/nouveau/dispnv50/wndw.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/dispnv50/wndw.c
> b/drivers/gpu/drm/nouveau/dispnv50/wndw.c
> index 8642b84ea20c..bb8a4601e0d9 100644
> --- a/drivers/gpu/drm/nouveau/dispnv50/wndw.c
> +++ b/drivers/gpu/drm/nouveau/dispnv50/wndw.c
> @@ -32,6 +32,7 @@
>  
>  #include <drm/drm_atomic.h>
>  #include <drm/drm_atomic_helper.h>
> +#include <drm/drm_gem_atomic_helper.h>
>  #include <drm/drm_fourcc.h>
>  
>  #include "nouveau_bo.h"
> @@ -558,9 +559,7 @@ nv50_wndw_prepare_fb(struct drm_plane *plane, struct
> drm_plane_state *state)
>                         asyw->image.handle[0] = ctxdma->object.handle;
>         }
>  
> -       ret = dma_resv_get_singleton(nvbo->bo.base.resv,
> -                                    DMA_RESV_USAGE_WRITE,
> -                                    &asyw->state.fence);
> +       ret = drm_gem_plane_helper_prepare_fb(plane, state);
>         if (ret)
>                 return ret;
>  

-- 
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat


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

* Re: [PATCH 4/4] drm/qxl: add drm_gem_plane_helper_prepare_fb
  2022-04-29 13:42 ` [PATCH 4/4] drm/qxl: add drm_gem_plane_helper_prepare_fb Christian König
@ 2022-05-04  9:27   ` Daniel Vetter
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Vetter @ 2022-05-04  9:27 UTC (permalink / raw)
  To: Christian König
  Cc: daniel.vetter, dri-devel, virtualization, Gerd Hoffmann,
	spice-devel, Dave Airlie, Christian König

On Fri, Apr 29, 2022 at 03:42:30PM +0200, Christian König wrote:
> We could need to wait for the pin to complete here.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> Cc: Dave Airlie <airlied@redhat.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: virtualization@lists.linux-foundation.org
> Cc: spice-devel@lists.freedesktop.org

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

> ---
>  drivers/gpu/drm/qxl/qxl_display.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/qxl/qxl_display.c b/drivers/gpu/drm/qxl/qxl_display.c
> index 9a9c29b1d3e1..9a64fa4c7530 100644
> --- a/drivers/gpu/drm/qxl/qxl_display.c
> +++ b/drivers/gpu/drm/qxl/qxl_display.c
> @@ -34,6 +34,7 @@
>  #include <drm/drm_plane_helper.h>
>  #include <drm/drm_probe_helper.h>
>  #include <drm/drm_simple_kms_helper.h>
> +#include <drm/drm_gem_atomic_helper.h>
>  
>  #include "qxl_drv.h"
>  #include "qxl_object.h"
> @@ -829,6 +830,7 @@ static int qxl_plane_prepare_fb(struct drm_plane *plane,
>  	struct qxl_device *qdev = to_qxl(plane->dev);
>  	struct drm_gem_object *obj;
>  	struct qxl_bo *user_bo;
> +	int ret;
>  
>  	if (!new_state->fb)
>  		return 0;
> @@ -852,7 +854,11 @@ static int qxl_plane_prepare_fb(struct drm_plane *plane,
>  		qxl_free_cursor(old_cursor_bo);
>  	}
>  
> -	return qxl_bo_pin(user_bo);
> +	ret = qxl_bo_pin(user_bo);
> +	if (ret)
> +		return ret;
> +
> +	return drm_gem_plane_helper_prepare_fb(plane, new_state);
>  }
>  
>  static void qxl_plane_cleanup_fb(struct drm_plane *plane,
> -- 
> 2.25.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

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

* Re: [PATCH 2/4] drm/amdgpu: switch DM to atomic fence helpers
  2022-04-29 13:42 ` [PATCH 2/4] drm/amdgpu: switch DM to atomic fence helpers Christian König
@ 2022-05-05 10:14   ` Christian König
  2022-05-05 12:09   ` Daniel Vetter
  1 sibling, 0 replies; 8+ messages in thread
From: Christian König @ 2022-05-05 10:14 UTC (permalink / raw)
  To: dri-devel, Harry Wentland, Nicholas Kazlauskas
  Cc: daniel.vetter, Qingqing Zhuo, Wayne Lin, Rodrigo Siqueira,
	Roman Li, Jude Shih

Just a gentle ping on this.

Harry, Nicholas any comments or can I push this through drm-misc-next?

Thanks,
Christian.

Am 29.04.22 um 15:42 schrieb Christian König:
> This gives us the standard atomic implicit and explicit fencing rules.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> Cc: Harry Wentland <harry.wentland@amd.com>
> Cc: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
> Cc: Roman Li <Roman.Li@amd.com>
> Cc: Qingqing Zhuo <qingqing.zhuo@amd.com>
> Cc: Jude Shih <shenshih@amd.com>
> Cc: Wayne Lin <Wayne.Lin@amd.com>
> Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
> ---
>   .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 23 ++++++++-----------
>   1 file changed, 10 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index 2ade82cfb1ac..c5b2417adcc6 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -83,6 +83,7 @@
>   #include <drm/drm_edid.h>
>   #include <drm/drm_vblank.h>
>   #include <drm/drm_audio_component.h>
> +#include <drm/drm_gem_atomic_helper.h>
>   
>   #if defined(CONFIG_DRM_AMD_DC_DCN)
>   #include "ivsrcid/dcn/irqsrcs_dcn_1_0.h"
> @@ -7627,6 +7628,10 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane,
>   		goto error_unpin;
>   	}
>   
> +	r = drm_gem_plane_helper_prepare_fb(plane, new_state);
> +	if (unlikely(r != 0))
> +		goto error_unpin;
> +
>   	amdgpu_bo_unreserve(rbo);
>   
>   	afb->address = amdgpu_bo_gpu_offset(rbo);
> @@ -9160,7 +9165,6 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
>   	struct dm_crtc_state *dm_old_crtc_state =
>   			to_dm_crtc_state(drm_atomic_get_old_crtc_state(state, pcrtc));
>   	int planes_count = 0, vpos, hpos;
> -	long r;
>   	unsigned long flags;
>   	struct amdgpu_bo *abo;
>   	uint32_t target_vblank, last_flip_vblank;
> @@ -9173,6 +9177,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
>   		struct dc_flip_addrs flip_addrs[MAX_SURFACES];
>   		struct dc_stream_update stream_update;
>   	} *bundle;
> +	int r;
>   
>   	bundle = kzalloc(sizeof(*bundle), GFP_KERNEL);
>   
> @@ -9181,6 +9186,10 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
>   		goto cleanup;
>   	}
>   
> +	r = drm_atomic_helper_wait_for_fences(dev, state, false);
> +	if (unlikely(r))
> +		DRM_ERROR("Waiting for fences timed out!");
> +
>   	/*
>   	 * Disable the cursor first if we're disabling all the planes.
>   	 * It'll remain on the screen after the planes are re-enabled
> @@ -9235,18 +9244,6 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
>   		}
>   
>   		abo = gem_to_amdgpu_bo(fb->obj[0]);
> -
> -		/*
> -		 * Wait for all fences on this FB. Do limited wait to avoid
> -		 * deadlock during GPU reset when this fence will not signal
> -		 * but we hold reservation lock for the BO.
> -		 */
> -		r = dma_resv_wait_timeout(abo->tbo.base.resv,
> -					  DMA_RESV_USAGE_WRITE, false,
> -					  msecs_to_jiffies(5000));
> -		if (unlikely(r <= 0))
> -			DRM_ERROR("Waiting for fences timed out!");
> -
>   		fill_dc_plane_info_and_addr(
>   			dm->adev, new_plane_state,
>   			afb->tiling_flags,


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

* Re: [PATCH 2/4] drm/amdgpu: switch DM to atomic fence helpers
  2022-04-29 13:42 ` [PATCH 2/4] drm/amdgpu: switch DM to atomic fence helpers Christian König
  2022-05-05 10:14   ` Christian König
@ 2022-05-05 12:09   ` Daniel Vetter
  1 sibling, 0 replies; 8+ messages in thread
From: Daniel Vetter @ 2022-05-05 12:09 UTC (permalink / raw)
  To: Christian König
  Cc: daniel.vetter, Qingqing Zhuo, Wayne Lin, Rodrigo Siqueira,
	Roman Li, dri-devel, Nicholas Kazlauskas, Jude Shih,
	Christian König

On Fri, Apr 29, 2022 at 03:42:28PM +0200, Christian König wrote:
> This gives us the standard atomic implicit and explicit fencing rules.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> Cc: Harry Wentland <harry.wentland@amd.com>
> Cc: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
> Cc: Roman Li <Roman.Li@amd.com>
> Cc: Qingqing Zhuo <qingqing.zhuo@amd.com>
> Cc: Jude Shih <shenshih@amd.com>
> Cc: Wayne Lin <Wayne.Lin@amd.com>
> Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
> ---
>  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 23 ++++++++-----------
>  1 file changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index 2ade82cfb1ac..c5b2417adcc6 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -83,6 +83,7 @@
>  #include <drm/drm_edid.h>
>  #include <drm/drm_vblank.h>
>  #include <drm/drm_audio_component.h>
> +#include <drm/drm_gem_atomic_helper.h>
>  
>  #if defined(CONFIG_DRM_AMD_DC_DCN)
>  #include "ivsrcid/dcn/irqsrcs_dcn_1_0.h"
> @@ -7627,6 +7628,10 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane,
>  		goto error_unpin;
>  	}
>  
> +	r = drm_gem_plane_helper_prepare_fb(plane, new_state);
> +	if (unlikely(r != 0))
> +		goto error_unpin;
> +
>  	amdgpu_bo_unreserve(rbo);
>  
>  	afb->address = amdgpu_bo_gpu_offset(rbo);
> @@ -9160,7 +9165,6 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
>  	struct dm_crtc_state *dm_old_crtc_state =
>  			to_dm_crtc_state(drm_atomic_get_old_crtc_state(state, pcrtc));
>  	int planes_count = 0, vpos, hpos;
> -	long r;
>  	unsigned long flags;
>  	struct amdgpu_bo *abo;
>  	uint32_t target_vblank, last_flip_vblank;
> @@ -9173,6 +9177,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
>  		struct dc_flip_addrs flip_addrs[MAX_SURFACES];
>  		struct dc_stream_update stream_update;
>  	} *bundle;
> +	int r;
>  
>  	bundle = kzalloc(sizeof(*bundle), GFP_KERNEL);
>  
> @@ -9181,6 +9186,10 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
>  		goto cleanup;
>  	}
>  
> +	r = drm_atomic_helper_wait_for_fences(dev, state, false);

This already waits for all fences over all planes, I think the call
should be put somewhere in amdgpu_dm_atomic_commit_tail() instead. In
helpers it's at the top before we start doing anything, but I guess you
can also put it right before the plane commit loop.

While reviewing I also noticed that the legacy kms path's various
mode_set_base implementations don't wait for fences after calling
amdgpu_bo_pin(), e.g. in dce_v10_0_crtc_do_set_base(). The page flip path
is already updated, but might be good to fix this one here too. That stuff
is a bit copypasta gallore (atomic is a lot nicer) but not too tricky to
fix. Maybe separate patch.

With the wait_for_fences call moved:

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
-Daniel


> +	if (unlikely(r))
> +		DRM_ERROR("Waiting for fences timed out!");
> +
>  	/*
>  	 * Disable the cursor first if we're disabling all the planes.
>  	 * It'll remain on the screen after the planes are re-enabled
> @@ -9235,18 +9244,6 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
>  		}
>  
>  		abo = gem_to_amdgpu_bo(fb->obj[0]);
> -
> -		/*
> -		 * Wait for all fences on this FB. Do limited wait to avoid
> -		 * deadlock during GPU reset when this fence will not signal
> -		 * but we hold reservation lock for the BO.
> -		 */
> -		r = dma_resv_wait_timeout(abo->tbo.base.resv,
> -					  DMA_RESV_USAGE_WRITE, false,
> -					  msecs_to_jiffies(5000));
> -		if (unlikely(r <= 0))
> -			DRM_ERROR("Waiting for fences timed out!");
> -
>  		fill_dc_plane_info_and_addr(
>  			dm->adev, new_plane_state,
>  			afb->tiling_flags,
> -- 
> 2.25.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

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

end of thread, other threads:[~2022-05-05 12:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29 13:42 [PATCH 1/4] drm: handle kernel fences in drm_gem_plane_helper_prepare_fb v2 Christian König
2022-04-29 13:42 ` [PATCH 2/4] drm/amdgpu: switch DM to atomic fence helpers Christian König
2022-05-05 10:14   ` Christian König
2022-05-05 12:09   ` Daniel Vetter
2022-04-29 13:42 ` [PATCH 3/4] drm/nouveau: use drm_gem_plane_helper_prepare_fb Christian König
2022-04-29 20:04   ` Lyude Paul
2022-04-29 13:42 ` [PATCH 4/4] drm/qxl: add drm_gem_plane_helper_prepare_fb Christian König
2022-05-04  9:27   ` Daniel Vetter

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).