Skip to contentSkip to conversation

drm: Move page_flip fb lookup earlier

PATCH New Ville Syrjala 2 participants 6 messages Jul 13, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 drm: Move page_flip fb lookup earlier

From: Ville Syrjälä <[email protected]>

No reason that I can see to delay the fb lookup this late. Moving it earlier allows us to keep it outside of the lock retry loop. This makes error handling and whatnot simpler.

---
 drivers/gpu/drm/drm_plane.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
drivers/gpu/drm/drm_plane.c +15 -14
index 6153cbda239f..924830071307 100644
@@ -1009,7 +1009,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
 	struct drm_mode_crtc_page_flip_target *page_flip = data;
 	struct drm_crtc *crtc;
 	struct drm_plane *plane;
-	struct drm_framebuffer *fb = NULL, *old_fb;
+	struct drm_framebuffer *fb, *old_fb;
 	struct drm_pending_vblank_event *e = NULL;
 	u32 target_vblank = page_flip->sequence;
 	struct drm_modeset_acquire_ctx ctx;
@@ -1055,16 +1055,16 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
 				DRM_DEBUG("Invalid absolute flip target %u, "
 					  "must be <= %u\n", target_vblank,
 					  current_vblank + 1);
-				drm_crtc_vblank_put(crtc);
-				return -EINVAL;
+				ret = -EINVAL;
+				goto put_vblank;
 			}
 			break;
 		case DRM_MODE_PAGE_FLIP_TARGET_RELATIVE:
 			if (target_vblank != 0 && target_vblank != 1) {
 				DRM_DEBUG("Invalid relative flip target %u, "
 					  "must be 0 or 1\n", target_vblank);
-				drm_crtc_vblank_put(crtc);
-				return -EINVAL;
+				ret = -EINVAL;
+				goto put_vblank;
 			}
 			target_vblank += current_vblank;
 			break;
@@ -1075,7 +1075,14 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
 		}
 	} else if (crtc->funcs->page_flip == NULL ||
 		   (page_flip->flags & DRM_MODE_PAGE_FLIP_TARGET)) {
-		return -EINVAL;
+		ret = -EINVAL;
+		goto put_vblank;
+	}
+
+	fb = drm_framebuffer_lookup(dev, file_priv, page_flip->fb_id);
+	if (!fb) {
+		ret = -ENOENT;
+		goto put_vblank;
 	}
 
 	drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
@@ -1101,12 +1108,6 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
 		goto out;
 	}
 
-	fb = drm_framebuffer_lookup(dev, file_priv, page_flip->fb_id);
-	if (!fb) {
-		ret = -ENOENT;
-		goto out;
-	}
-
 	if (plane->state) {
 		const struct drm_plane_state *state = plane->state;
 
@@ -1170,8 +1171,6 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
 	}
 
 out:
-	if (fb)
-		drm_framebuffer_put(fb);
 	if (plane->old_fb)
 		drm_framebuffer_put(plane->old_fb);
 	plane->old_fb = NULL;
@@ -1185,6 +1184,8 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
 	drm_modeset_drop_locks(&ctx);
 	drm_modeset_acquire_fini(&ctx);
 
+	drm_framebuffer_put(fb);
+put_vblank:
 	if (ret && crtc->funcs->page_flip_target)
 		drm_crtc_vblank_put(crtc);
 
Signature · 6 lines
2.16.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 2/4 drm: Allocate the page flip event earlier

From: Ville Syrjälä <[email protected]>

Can't see why we need to delay the page flip event allocation until the last moment. Move it earlier to simplify error handling.

---
 drivers/gpu/drm/drm_plane.c | 45 +++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 22 deletions(-)
drivers/gpu/drm/drm_plane.c +23 -22
index 924830071307..d269231d63c5 100644
@@ -1085,6 +1085,26 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
 		goto put_vblank;
 	}
 
+	if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
+		e = kzalloc(sizeof *e, GFP_KERNEL);
+		if (!e) {
+			ret = -ENOMEM;
+			goto put_fb;
+		}
+
+		e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
+		e->event.base.length = sizeof(e->event);
+		e->event.vbl.user_data = page_flip->user_data;
+		e->event.vbl.crtc_id = crtc->base.id;
+
+		ret = drm_event_reserve_init(dev, file_priv, &e->base, &e->event.base);
+		if (ret) {
+			kfree(e);
+			e = NULL;
+			goto put_fb;
+		}
+	}
+
 	drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
 retry:
 	ret = drm_modeset_lock(&crtc->mutex, &ctx);
@@ -1129,26 +1149,6 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
 		goto out;
 	}
 
-	if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
-		e = kzalloc(sizeof *e, GFP_KERNEL);
-		if (!e) {
-			ret = -ENOMEM;
-			goto out;
-		}
-
-		e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
-		e->event.base.length = sizeof(e->event);
-		e->event.vbl.user_data = page_flip->user_data;
-		e->event.vbl.crtc_id = crtc->base.id;
-
-		ret = drm_event_reserve_init(dev, file_priv, &e->base, &e->event.base);
-		if (ret) {
-			kfree(e);
-			e = NULL;
-			goto out;
-		}
-	}
-
 	plane->old_fb = plane->fb;
 	if (crtc->funcs->page_flip_target)
 		ret = crtc->funcs->page_flip_target(crtc, fb, e,
@@ -1159,8 +1159,6 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
 		ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags,
 					     &ctx);
 	if (ret) {
-		if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT)
-			drm_event_cancel_free(dev, &e->base);
 		/* Keep the old fb, don't unref it. */
 		plane->old_fb = NULL;
 	} else {
@@ -1184,6 +1182,9 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
 	drm_modeset_drop_locks(&ctx);
 	drm_modeset_acquire_fini(&ctx);
 
+	if (ret && e)
+		drm_event_cancel_free(dev, &e->base);
+put_fb:
 	drm_framebuffer_put(fb);
 put_vblank:
 	if (ret && crtc->funcs->page_flip_target)
Signature · 6 lines
2.16.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH 3/4 drm: Extract page_flip_{internal, atomic}()

In reply to Ville Syrjala

From: Ville Syrjälä <[email protected]>

Yank out the code for the plane->fb/old_fb/crtc handling from the page flip path into page_flip_internal(), and provide a simpler variant for atomic drivers.

We'll also move the fb vs. src viewport checks into the new functions as they are slightly different between the two paths. If the atomic .page_flip() implementations are guaranteed to call drm_atomic_plane_check() we could even drop the check entirely from page_flip_atomic(). For now toss in a FIXME.

---
 drivers/gpu/drm/drm_plane.c | 162 ++++++++++++++++++++++++++++----------------
 1 file changed, 105 insertions(+), 57 deletions(-)
drivers/gpu/drm/drm_plane.c +105 -57
index d269231d63c5..e3f2ddf7deae 100644
@@ -1003,13 +1003,112 @@ int drm_mode_cursor2_ioctl(struct drm_device *dev,
 	return drm_mode_cursor_common(dev, req, file_priv);
 }
 
+static int page_flip_check_fbs(const struct drm_framebuffer *fb,
+			       const struct drm_framebuffer *old_fb)
+{
+	/* The framebuffer is currently unbound, presumably
+	 * due to a hotplug event, that userspace has not
+	 * yet discovered.
+	 */
+	if (!old_fb)
+		return -EBUSY;
+
+	if (old_fb->format != fb->format) {
+		DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int page_flip_internal(struct drm_crtc *crtc,
+			      struct drm_framebuffer *fb,
+			      struct drm_pending_vblank_event *e,
+			      u32 flags,
+			      u32 target_vblank,
+			      struct drm_modeset_acquire_ctx *ctx)
+{
+	struct drm_plane *plane = crtc->primary;
+	int ret;
+
+	WARN_ON(drm_drv_uses_atomic_modeset(crtc->dev));
+
+	ret = drm_crtc_check_viewport(crtc, crtc->x, crtc->y,
+				      &crtc->mode, fb);
+	if (ret)
+		return ret;
+
+	ret = page_flip_check_fbs(fb, plane->fb);
+	if (ret)
+		return ret;
+
+	plane->old_fb = plane->fb;
+
+	if (crtc->funcs->page_flip_target)
+		ret = crtc->funcs->page_flip_target(crtc, fb, e, flags,
+						    target_vblank, ctx);
+	else
+		ret = crtc->funcs->page_flip(crtc, fb, e, flags, ctx);
+
+	if (ret) {
+		/* Keep the old fb, don't unref it. */
+		plane->old_fb = NULL;
+	} else {
+		plane->fb = fb;
+		drm_framebuffer_get(plane->fb);
+	}
+
+	if (plane->old_fb)
+		drm_framebuffer_put(plane->old_fb);
+	plane->old_fb = NULL;
+
+	return ret;
+}
+
+static int page_flip_atomic(struct drm_crtc *crtc,
+			    struct drm_framebuffer *fb,
+			    struct drm_pending_vblank_event *e,
+			    u32 flags,
+			    u32 target_vblank,
+			    struct drm_modeset_acquire_ctx *ctx)
+{
+	struct drm_plane *plane = crtc->primary;
+	struct drm_plane_state *plane_state = plane->state;
+	int ret;
+
+	WARN_ON(!drm_drv_uses_atomic_modeset(crtc->dev));
+
+	/*
+	 * FIXME: Can we assume all drivers end up calling
+	 * drm_atomic_plane_check() in their page flip paths?
+	 * If so we could remove this.
+	 */
+	ret = drm_framebuffer_check_src_coords(plane_state->src_x,
+					       plane_state->src_y,
+					       plane_state->src_w,
+					       plane_state->src_h,
+					       fb);
+	if (ret)
+		return ret;
+
+	ret = page_flip_check_fbs(fb, plane_state->fb);
+	if (ret)
+		return ret;
+
+	if (crtc->funcs->page_flip_target)
+		return crtc->funcs->page_flip_target(crtc, fb, e, flags,
+						     target_vblank, ctx);
+	else
+		return crtc->funcs->page_flip(crtc, fb, e, flags, ctx);
+}
+
 int drm_mode_page_flip_ioctl(struct drm_device *dev,
 			     void *data, struct drm_file *file_priv)
 {
 	struct drm_mode_crtc_page_flip_target *page_flip = data;
 	struct drm_crtc *crtc;
 	struct drm_plane *plane;
-	struct drm_framebuffer *fb, *old_fb;
+	struct drm_framebuffer *fb;
 	struct drm_pending_vblank_event *e = NULL;
 	u32 target_vblank = page_flip->sequence;
 	struct drm_modeset_acquire_ctx ctx;
@@ -1114,65 +1213,14 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
 	if (ret)
 		goto out;
 
-	if (plane->state)
-		old_fb = plane->state->fb;
-	else
-		old_fb = plane->fb;
-
-	if (old_fb == NULL) {
-		/* The framebuffer is currently unbound, presumably
-		 * due to a hotplug event, that userspace has not
-		 * yet discovered.
-		 */
-		ret = -EBUSY;
-		goto out;
-	}
-
-	if (plane->state) {
-		const struct drm_plane_state *state = plane->state;
-
-		ret = drm_framebuffer_check_src_coords(state->src_x,
-						       state->src_y,
-						       state->src_w,
-						       state->src_h,
-						       fb);
-	} else {
-		ret = drm_crtc_check_viewport(crtc, crtc->x, crtc->y,
-					      &crtc->mode, fb);
-	}
-	if (ret)
-		goto out;
-
-	if (old_fb->format != fb->format) {
-		DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n");
-		ret = -EINVAL;
-		goto out;
-	}
-
-	plane->old_fb = plane->fb;
-	if (crtc->funcs->page_flip_target)
-		ret = crtc->funcs->page_flip_target(crtc, fb, e,
-						    page_flip->flags,
-						    target_vblank,
-						    &ctx);
+	if (drm_drv_uses_atomic_modeset(dev))
+		ret = page_flip_atomic(crtc, fb, e, page_flip->flags,
+				       target_vblank, &ctx);
 	else
-		ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags,
-					     &ctx);
-	if (ret) {
-		/* Keep the old fb, don't unref it. */
-		plane->old_fb = NULL;
-	} else {
-		if (!plane->state) {
-			plane->fb = fb;
-			drm_framebuffer_get(fb);
-		}
-	}
+		ret = page_flip_internal(crtc, fb, e, page_flip->flags,
+					 target_vblank, &ctx);
 
 out:
-	if (plane->old_fb)
-		drm_framebuffer_put(plane->old_fb);
-	plane->old_fb = NULL;
-
 	if (ret == -EDEADLK) {
 		ret = drm_modeset_backoff(&ctx);
 		if (!ret)
Signature · 6 lines
2.16.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

PATCH 4/4 drm: Simplify the setplane/pageflip old_fb handling further

In reply to Ville Syrjala

From: Ville Syrjälä <[email protected]>

Instead of doing the things in a convoluted way with the failure and success paths mixed up let's just clear old_fb when we encounter an error and bail out immediately.

---
 drivers/gpu/drm/drm_plane.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)
drivers/gpu/drm/drm_plane.c +17 -15
index e3f2ddf7deae..406f11281d61 100644
@@ -655,12 +655,13 @@ static int __setplane_internal(struct drm_plane *plane,
 	if (!fb) {
 		plane->old_fb = plane->fb;
 		ret = plane->funcs->disable_plane(plane, ctx);
-		if (!ret) {
-			plane->crtc = NULL;
-			plane->fb = NULL;
-		} else {
+		if (ret) {
 			plane->old_fb = NULL;
+			return ret;
 		}
+
+		plane->crtc = NULL;
+		plane->fb = NULL;
 		goto out;
 	}
 
@@ -668,20 +669,22 @@ static int __setplane_internal(struct drm_plane *plane,
 			       crtc_x, crtc_y, crtc_w, crtc_h,
 			       src_x, src_y, src_w, src_h);
 	if (ret)
-		goto out;
+		return ret;
 
 	plane->old_fb = plane->fb;
+
 	ret = plane->funcs->update_plane(plane, crtc, fb,
 					 crtc_x, crtc_y, crtc_w, crtc_h,
 					 src_x, src_y, src_w, src_h, ctx);
-	if (!ret) {
-		plane->crtc = crtc;
-		plane->fb = fb;
-		drm_framebuffer_get(plane->fb);
-	} else {
+	if (ret) {
 		plane->old_fb = NULL;
+		return ret;
 	}
 
+	plane->crtc = crtc;
+	plane->fb = fb;
+	drm_framebuffer_get(plane->fb);
+
 out:
 	if (plane->old_fb)
 		drm_framebuffer_put(plane->old_fb);
@@ -1049,15 +1052,14 @@ static int page_flip_internal(struct drm_crtc *crtc,
 						    target_vblank, ctx);
 	else
 		ret = crtc->funcs->page_flip(crtc, fb, e, flags, ctx);
-
 	if (ret) {
-		/* Keep the old fb, don't unref it. */
 		plane->old_fb = NULL;
-	} else {
-		plane->fb = fb;
-		drm_framebuffer_get(plane->fb);
+		return ret;
 	}
 
+	plane->fb = fb;
+	drm_framebuffer_get(plane->fb);
+
 	if (plane->old_fb)
 		drm_framebuffer_put(plane->old_fb);
 	plane->old_fb = NULL;
Signature · 6 lines
2.16.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

✗ Fi.CI.CHECKPATCH: warning for series starting with [1/4] drm: Move page_flip fb lookup earlier

In reply to Ville Syrjala
== Series Details ==

== Series Details ==

Series: series starting with [1/4] drm: Move page_flip fb lookup earlier
URL : https://patchwork.freedesktop.org/series/46494/
State : warning

== Summary ==

$ dim checkpatch origin/drm-tip
01d1f2a2abaa drm: Move page_flip fb lookup earlier
7f5dae95e6b4 drm: Allocate the page flip event earlier
-:23: WARNING:SIZEOF_PARENTHESIS: sizeof *e should be sizeof(*e)
#23: FILE: drivers/gpu/drm/drm_plane.c:1089:
+		e = kzalloc(sizeof *e, GFP_KERNEL);

total: 0 errors, 1 warnings, 0 checks, 69 lines checked e4881da74fb4 drm: Extract page_flip_{internal, atomic}() 5984836e3cf6 drm: Simplify the setplane/pageflip old_fb handling further

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw

✓ Fi.CI.BAT: success for series starting with [1/4] drm: Move page_flip fb lookup earlier

In reply to Ville Syrjala
== Series Details ==

== Series Details ==

Series: series starting with [1/4] drm: Move page_flip fb lookup earlier
URL : https://patchwork.freedesktop.org/series/46494/
State : success

== Summary ==

= CI Bug Log - changes from CI_DRM_4486 -> Patchwork_9649 =

== Summary - SUCCESS ==

No regressions found.

External URL: https://patchwork.freedesktop.org/api/1.0/series/46494/revisions/1/mbox/

== Known issues ==

Here are the changes found in Patchwork_9649 that come from known issues:

=== IGT changes ===

    ==== Issues hit ====

    igt@gem_exec_suspend@basic-s3:
      {fi-cfl-8109u}:     PASS -> INCOMPLETE (fdo#107187)

    igt@gem_mmap_gtt@basic-copy:
      {fi-kbl-8809g}:     NOTRUN -> DMESG-WARN (fdo#107222) +1

    igt@gem_mmap_gtt@basic-wc:
      {fi-kbl-8809g}:     NOTRUN -> DMESG-WARN (fdo#107221) +7

    igt@gem_ringfill@basic-default-hang:
      {fi-kbl-8809g}:     NOTRUN -> DMESG-WARN (fdo#107221, fdo#107222)

    igt@kms_flip@basic-flip-vs-dpms:
      fi-skl-6700hq:      PASS -> DMESG-WARN (fdo#105998)

    
    ==== Warnings ====

    igt@gem_exec_suspend@basic-s4-devices:
      {fi-kbl-8809g}:     INCOMPLETE (fdo#107139) -> DMESG-WARN (fdo#107139)

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

fdo#105998 https://bugs.freedesktop.org/show_bug.cgi?id=105998
fdo#107139 https://bugs.freedesktop.org/show_bug.cgi?id=107139
fdo#107187 https://bugs.freedesktop.org/show_bug.cgi?id=107187
fdo#107221 https://bugs.freedesktop.org/show_bug.cgi?id=107221
fdo#107222 https://bugs.freedesktop.org/show_bug.cgi?id=107222

== Participating hosts (45 -> 42) ==

Additional (1): fi-bxt-dsi
Missing (4): fi-ilk-m540 fi-byt-squawks fi-bsw-cyan fi-hsw-4200u

== Build changes ==

* Linux: CI_DRM_4486 -> Patchwork_9649

CI_DRM_4486: 9c869b6ff78481dd5789d007bbee989129b67af4 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4556: caea9c5b3aa1191c0152d7c0f22a94efca4fd048 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_9649: 5984836e3cf6f81e407a15d1c3390dd9d4822d1b @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

5984836e3cf6 drm: Simplify the setplane/pageflip old_fb handling further e4881da74fb4 drm: Extract page_flip_{internal, atomic}() 7f5dae95e6b4 drm: Allocate the page flip event earlier 01d1f2a2abaa drm: Move page_flip fb lookup earlier

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_9649/issues.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx