Skip to content

Commit 5b9c132

Browse files
Nikola CornijSasha Levin
authored andcommitted
drm/amd/display: Reject too small viewport size when validating plane
[ Upstream commit 40d916a ] [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: 374c9fa ("drm/amd/display: Fix null check for pipe_ctx->plane_state in resource_build_scaling_params") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 7d47ea1 commit 5b9c132

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6066,8 +6066,33 @@ static int dm_plane_helper_check_state(struct drm_plane_state *state,
60666066
int min_scale = 0;
60676067
int max_scale = INT_MAX;
60686068

6069-
/* Plane enabled? Get min/max allowed scaling factors from plane caps. */
6069+
/* Plane enabled? Validate viewport and get scaling factors from plane caps. */
60706070
if (fb && state->crtc) {
6071+
/* Validate viewport to cover the case when only the position changes */
6072+
if (state->plane->type != DRM_PLANE_TYPE_CURSOR) {
6073+
int viewport_width = state->crtc_w;
6074+
int viewport_height = state->crtc_h;
6075+
6076+
if (state->crtc_x < 0)
6077+
viewport_width += state->crtc_x;
6078+
else if (state->crtc_x + state->crtc_w > new_crtc_state->mode.crtc_hdisplay)
6079+
viewport_width = new_crtc_state->mode.crtc_hdisplay - state->crtc_x;
6080+
6081+
if (state->crtc_y < 0)
6082+
viewport_height += state->crtc_y;
6083+
else if (state->crtc_y + state->crtc_h > new_crtc_state->mode.crtc_vdisplay)
6084+
viewport_height = new_crtc_state->mode.crtc_vdisplay - state->crtc_y;
6085+
6086+
/* If completely outside of screen, viewport_width and/or viewport_height will be negative,
6087+
* which is still OK to satisfy the condition below, thereby also covering these cases
6088+
* (when plane is completely outside of screen).
6089+
* x2 for width is because of pipe-split.
6090+
*/
6091+
if (viewport_width < MIN_VIEWPORT_SIZE*2 || viewport_height < MIN_VIEWPORT_SIZE)
6092+
return -EINVAL;
6093+
}
6094+
6095+
/* Get min/max allowed scaling factors from plane caps. */
60716096
get_min_max_dc_plane_scaling(state->crtc->dev, fb,
60726097
&min_downscale, &max_upscale);
60736098
/*

drivers/gpu/drm/amd/display/dc/core/dc_resource.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,8 +1144,8 @@ bool resource_build_scaling_params(struct pipe_ctx *pipe_ctx)
11441144

11451145
calculate_viewport(pipe_ctx);
11461146

1147-
if (pipe_ctx->plane_res.scl_data.viewport.height < 12 ||
1148-
pipe_ctx->plane_res.scl_data.viewport.width < 12) {
1147+
if (pipe_ctx->plane_res.scl_data.viewport.height < MIN_VIEWPORT_SIZE ||
1148+
pipe_ctx->plane_res.scl_data.viewport.width < MIN_VIEWPORT_SIZE) {
11491149
if (store_h_border_left) {
11501150
restore_border_left_from_dst(pipe_ctx,
11511151
store_h_border_left);

drivers/gpu/drm/amd/display/dc/dc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#define MAX_PLANES 6
4949
#define MAX_STREAMS 6
5050
#define MAX_SINKS_PER_LINK 4
51+
#define MIN_VIEWPORT_SIZE 12
5152

5253
/*******************************************************************************
5354
* Display Core Interfaces

0 commit comments

Comments
 (0)