]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/amd/display: Reject too small viewport size when validating plane
authorNikola Cornij <nikola.cornij@amd.com>
Fri, 22 Jan 2021 03:35:54 +0000 (22:35 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Apr 2025 12:30:52 +0000 (14:30 +0200)
[ Upstream commit 40d916a2602c8920e0f04a49abfd1ff7c1e54e91 ]

[why]
Overlay won't move to a new positon if viewport size is smaller than
what can be handled. It'd either disappear or stay at the old
position. This condition is for example hit if overlay is moved too
much outside of left or top edge of the screen, but it applies to
any non-cursor plane type.

[how]
Reject this contidion at validation time. This gives the calling
level a chance to handle this gracefully and avoid inconsistent
behaivor.

Signed-off-by: Nikola Cornij <nikola.cornij@amd.com>
Reviewed-by: Nicholas Kazlauskas <Nicholas.Kazlauskas@amd.com>
Acked-by: Anson Jacob <Anson.Jacob@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Stable-dep-of: 374c9faac5a7 ("drm/amd/display: Fix null check for pipe_ctx->plane_state in resource_build_scaling_params")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
drivers/gpu/drm/amd/display/dc/core/dc_resource.c
drivers/gpu/drm/amd/display/dc/dc.h

index 4b4de1751c53f4d2428fdf8bf29a4febbbf6b22f..786cd892f1797c54e636850f68896cb8bcdf0f6f 100644 (file)
@@ -6066,8 +6066,33 @@ static int dm_plane_helper_check_state(struct drm_plane_state *state,
        int min_scale = 0;
        int max_scale = INT_MAX;
 
-       /* Plane enabled? Get min/max allowed scaling factors from plane caps. */
+       /* Plane enabled? Validate viewport and get scaling factors from plane caps. */
        if (fb && state->crtc) {
+               /* Validate viewport to cover the case when only the position changes */
+               if (state->plane->type != DRM_PLANE_TYPE_CURSOR) {
+                       int viewport_width = state->crtc_w;
+                       int viewport_height = state->crtc_h;
+
+                       if (state->crtc_x < 0)
+                               viewport_width += state->crtc_x;
+                       else if (state->crtc_x + state->crtc_w > new_crtc_state->mode.crtc_hdisplay)
+                               viewport_width = new_crtc_state->mode.crtc_hdisplay - state->crtc_x;
+
+                       if (state->crtc_y < 0)
+                               viewport_height += state->crtc_y;
+                       else if (state->crtc_y + state->crtc_h > new_crtc_state->mode.crtc_vdisplay)
+                               viewport_height = new_crtc_state->mode.crtc_vdisplay - state->crtc_y;
+
+                       /* If completely outside of screen, viewport_width and/or viewport_height will be negative,
+                        * which is still OK to satisfy the condition below, thereby also covering these cases
+                        * (when plane is completely outside of screen).
+                        * x2 for width is because of pipe-split.
+                        */
+                       if (viewport_width < MIN_VIEWPORT_SIZE*2 || viewport_height < MIN_VIEWPORT_SIZE)
+                               return -EINVAL;
+               }
+
+               /* Get min/max allowed scaling factors from plane caps. */
                get_min_max_dc_plane_scaling(state->crtc->dev, fb,
                                             &min_downscale, &max_upscale);
                /*
index 5dc6840cea2482dbfef1f18108f789fb230ce575..d77001b2e106b199882791fc9ab263046232e572 100644 (file)
@@ -1144,8 +1144,8 @@ bool resource_build_scaling_params(struct pipe_ctx *pipe_ctx)
 
        calculate_viewport(pipe_ctx);
 
-       if (pipe_ctx->plane_res.scl_data.viewport.height < 12 ||
-               pipe_ctx->plane_res.scl_data.viewport.width < 12) {
+       if (pipe_ctx->plane_res.scl_data.viewport.height < MIN_VIEWPORT_SIZE ||
+               pipe_ctx->plane_res.scl_data.viewport.width < MIN_VIEWPORT_SIZE) {
                if (store_h_border_left) {
                        restore_border_left_from_dst(pipe_ctx,
                                store_h_border_left);
index 1df7c49ac8d77afaff4ec38141eae6234072d6ab..d3a4a55f3f1fa7755ebe1c432b1e271734bf8765 100644 (file)
@@ -48,6 +48,7 @@
 #define MAX_PLANES 6
 #define MAX_STREAMS 6
 #define MAX_SINKS_PER_LINK 4
+#define MIN_VIEWPORT_SIZE 12
 
 /*******************************************************************************
  * Display Core Interfaces