stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/i915: Reject < 1x1 pixel plane source size
@ 2023-01-12 15:21 Ville Syrjala
  2023-01-12 18:29 ` Ville Syrjälä
  0 siblings, 1 reply; 2+ messages in thread
From: Ville Syrjala @ 2023-01-12 15:21 UTC (permalink / raw)
  To: intel-gfx; +Cc: stable, Juha-Pekka Heikkila, Drew Davenport

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

We don't have proper sub-pixel coordinate support (some platforms
simply can't do it, for others we've not implemented it). This
can cause us to treat a < 1 pixel source width/height as zero
which is not valid for the hardware, and can also cause a div
by zero in some cases.

Refuse < 1x1 plane source size to avoid these problems.

Cc: stable@vger.kernel.org
Cc: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
Reported-by: Drew Davenport <ddavenport@chromium.org>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
The other option would be to clamp the source size to >=1x1 pixels,
but dunno if that has any real benefits.

 drivers/gpu/drm/i915/display/intel_atomic_plane.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/gpu/drm/i915/display/intel_atomic_plane.c b/drivers/gpu/drm/i915/display/intel_atomic_plane.c
index 10e1fc9d0698..c6e43d684458 100644
--- a/drivers/gpu/drm/i915/display/intel_atomic_plane.c
+++ b/drivers/gpu/drm/i915/display/intel_atomic_plane.c
@@ -921,6 +921,21 @@ int intel_atomic_plane_check_clipping(struct intel_plane_state *plane_state,
 	 */
 	plane_state->uapi.visible = drm_rect_clip_scaled(src, dst, clip);
 
+	/*
+	 * Avoid zero source size when we later
+	 * discard the fractional coords.
+	 *
+	 * FIXME add proper sub-pixel coordinate handling
+	 * for platforms/planes that support it.
+	 */
+	if (plane_state->uapi.visible &&
+	    (drm_rect_width(src) < 0x10000 || drm_rect_height(src) < 0x10000)) {
+		drm_dbg_kms(&i915->drm, "Plane source must be at least 1x1 pixels\n");
+		drm_rect_debug_print("src: ", src, true);
+		drm_rect_debug_print("dst: ", dst, false);
+		return -EINVAL;
+	}
+
 	drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, rotation);
 
 	if (!can_position && plane_state->uapi.visible &&
-- 
2.38.2


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

* Re: [PATCH] drm/i915: Reject < 1x1 pixel plane source size
  2023-01-12 15:21 [PATCH] drm/i915: Reject < 1x1 pixel plane source size Ville Syrjala
@ 2023-01-12 18:29 ` Ville Syrjälä
  0 siblings, 0 replies; 2+ messages in thread
From: Ville Syrjälä @ 2023-01-12 18:29 UTC (permalink / raw)
  To: intel-gfx; +Cc: stable, Juha-Pekka Heikkila, Drew Davenport

On Thu, Jan 12, 2023 at 05:21:45PM +0200, Ville Syrjala wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> We don't have proper sub-pixel coordinate support (some platforms
> simply can't do it, for others we've not implemented it). This
> can cause us to treat a < 1 pixel source width/height as zero
> which is not valid for the hardware, and can also cause a div
> by zero in some cases.
> 
> Refuse < 1x1 plane source size to avoid these problems.
> 
> Cc: stable@vger.kernel.org
> Cc: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
> Reported-by: Drew Davenport <ddavenport@chromium.org>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
> The other option would be to clamp the source size to >=1x1 pixels,
> but dunno if that has any real benefits.
> 
>  drivers/gpu/drm/i915/display/intel_atomic_plane.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_atomic_plane.c b/drivers/gpu/drm/i915/display/intel_atomic_plane.c
> index 10e1fc9d0698..c6e43d684458 100644
> --- a/drivers/gpu/drm/i915/display/intel_atomic_plane.c
> +++ b/drivers/gpu/drm/i915/display/intel_atomic_plane.c
> @@ -921,6 +921,21 @@ int intel_atomic_plane_check_clipping(struct intel_plane_state *plane_state,
>  	 */
>  	plane_state->uapi.visible = drm_rect_clip_scaled(src, dst, clip);
>  
> +	/*
> +	 * Avoid zero source size when we later
> +	 * discard the fractional coords.
> +	 *
> +	 * FIXME add proper sub-pixel coordinate handling
> +	 * for platforms/planes that support it.
> +	 */
> +	if (plane_state->uapi.visible &&
> +	    (drm_rect_width(src) < 0x10000 || drm_rect_height(src) < 0x10000)) {
> +		drm_dbg_kms(&i915->drm, "Plane source must be at least 1x1 pixels\n");
> +		drm_rect_debug_print("src: ", src, true);
> +		drm_rect_debug_print("dst: ", dst, false);
> +		return -EINVAL;
> +	}

Scratch that. Went with Drew's original patch instead.

> +
>  	drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, rotation);
>  
>  	if (!can_position && plane_state->uapi.visible &&
> -- 
> 2.38.2

-- 
Ville Syrjälä
Intel

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

end of thread, other threads:[~2023-01-12 18:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-12 15:21 [PATCH] drm/i915: Reject < 1x1 pixel plane source size Ville Syrjala
2023-01-12 18:29 ` Ville Syrjälä

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