Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp241561pxj; Thu, 20 May 2021 08:24:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFuHdBxr6xTdSBF8Qb/FxCcaxfwVl7cW5SJc12hhPC2KdXeKueFwiv2SmsEjh0x89WoX6U X-Received: by 2002:a05:6e02:490:: with SMTP id b16mr5992189ils.213.1621524267015; Thu, 20 May 2021 08:24:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621524267; cv=none; d=google.com; s=arc-20160816; b=yQo+qN46aGAwX2tWyyu1U8kP1x+Oj+LM3jsBCVQ9IpMQJvJ1Ztt3Z3+vycls9JKElg W6U91DoSa0KQPzUwlc3ZVIsbHCtl9QOHjxIiU8HgNPIuvRTI5G5R5lWbCq7VbmJ4jWAm jv8nD+P0PBgaMETQ3dSBp3rEN0UdLDVudUvc8rHYNws0saPuaPfHkrMhCyQJtPI8jAOp 5eYg4JJst9Po1+kTmlDGTLPfTIWpcP4Oj9yB/u7USF7MGmsPB5rWOKwqWCsSHvgDAEOE 6OKrOToA1KxiwHs3tdCelYnqFolM0rj07T8ujSMNuDXVSbgi6yscTXWrxZDWCR8pklEc hnAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=D8CfyNJy0lIH7p57nTjm0PqBqUT57aYm7b3rS/06buU=; b=q0mMONc6z+NlygETfqYTsE/Bs2aYt6D6UVt0BTNKbhAXF/dCZRsSYPmOQGS6Hl3Pxk bbQHvINbHL5LpPIEZPi2nKjWYiK1jwY6z92Om0L7f9UodH8OEgQPbyhZEerqhJlqVY4q CRWpqSc8KYsdgPCQm9TGStfB82e83BOF/DGVwfE8a22vvCOethsJ5s7t1CLqhZPc2W62 zISxk3aGmDNusKuZzqxuxvSUqKKtoJddQeAG4sGaKqASX9tIqKUrMpSRKH8JZ7gc57eC rHUNIucT72pfF61TO9c6mgqSJfU4uUlWkvSYfsFK/7UPEpDQnHFjKbdD0sOFkpecatl9 pU/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LZnfY2N3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r2si2475690jak.13.2021.05.20.08.24.14; Thu, 20 May 2021 08:24:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LZnfY2N3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232518AbhETJf0 (ORCPT + 99 others); Thu, 20 May 2021 05:35:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:34688 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232079AbhETJdA (ORCPT ); Thu, 20 May 2021 05:33:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CE73E613C8; Thu, 20 May 2021 09:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621502918; bh=qXf9dMn+pdTerdsr4+e6uiturQDh574qQv8TP/9iI1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LZnfY2N3FMdhREI+GByU7OXDWSW7c11Qhu2c+6tb4LkRl5i3hVnQ91RVmuoBKpOOi Pd3rog6M+/To5zt7xZqwdukD7M/0oZvrLEDrcj9ugimCfK7YRa3g7shtGuTTPCzhsQ 4D+aNcexFM1blpwdJfD5CF6ON7+UkIxSG5rzBRZs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Louis Li , Nicholas Kazlauskas , Harry Wentland , Hersen Wu , Sean Paul , Rodrigo Siqueira , Harry Wentland , Alex Deucher , Sasha Levin Subject: [PATCH 5.4 25/37] drm/amd/display: Fix two cursor duplication when using overlay Date: Thu, 20 May 2021 11:22:46 +0200 Message-Id: <20210520092053.101471857@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092052.265851579@linuxfoundation.org> References: <20210520092052.265851579@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rodrigo Siqueira [ Upstream commit 16e9b3e58bc3fce7391539e0eb3fd167cbf9951f ] Our driver supports overlay planes, and as expected, some userspace compositor takes advantage of these features. If the userspace is not enabling the cursor, they can use multiple planes as they please. Nevertheless, we start to have constraints when userspace tries to enable hardware cursor with various planes. Basically, we cannot draw the cursor at the same size and position on two separated pipes since it uses extra bandwidth and DML only run with one cursor. For those reasons, when we enable hardware cursor and multiple planes, our driver should accept variations like the ones described below: +-------------+ +--------------+ | +---------+ | | | | |Primary | | | Primary | | | | | | Overlay | | +---------+ | | | |Overlay | | | +-------------+ +--------------+ In this scenario, we can have the desktop UI in the overlay and some other framebuffer attached to the primary plane (e.g., video). However, userspace needs to obey some rules and avoid scenarios like the ones described below (when enabling hw cursor): +--------+ |Overlay | +-------------+ +-----+-------+ +-| |--+ | +--------+ | +--------+ | | +--------+ | | |Overlay | | |Overlay | | | | | | | | | | | | | | +--------+ | +--------+ | | | | Primary | | Primary | | Primary | +-------------+ +-------------+ +-------------+ +-------------+ +-------------+ | +--------+ | Primary | | |Overlay | | | | | | | | | +--------+ | +--------+ | | Primary | | |Overlay | | +-------------+ +-| |--+ +--------+ If the userspace violates some of the above scenarios, our driver needs to reject the commit; otherwise, we can have unexpected behavior. Since we don't have a proper driver validation for the above case, we can see some problems like a duplicate cursor in applications that use multiple planes. This commit fixes the cursor issue and others by adding adequate verification for multiple planes. Change since V1 (Harry and Sean): - Remove cursor verification from the equation. Cc: Louis Li Cc: Nicholas Kazlauskas Cc: Harry Wentland Cc: Hersen Wu Cc: Sean Paul Signed-off-by: Rodrigo Siqueira Reviewed-by: Harry Wentland Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) 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 82f1d5434b82..6e31e899192c 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -7267,6 +7267,53 @@ static int add_affected_mst_dsc_crtcs(struct drm_atomic_state *state, struct drm } #endif +static int validate_overlay(struct drm_atomic_state *state) +{ + int i; + struct drm_plane *plane; + struct drm_plane_state *old_plane_state, *new_plane_state; + struct drm_plane_state *primary_state, *overlay_state = NULL; + + /* Check if primary plane is contained inside overlay */ + for_each_oldnew_plane_in_state_reverse(state, plane, old_plane_state, new_plane_state, i) { + if (plane->type == DRM_PLANE_TYPE_OVERLAY) { + if (drm_atomic_plane_disabling(plane->state, new_plane_state)) + return 0; + + overlay_state = new_plane_state; + continue; + } + } + + /* check if we're making changes to the overlay plane */ + if (!overlay_state) + return 0; + + /* check if overlay plane is enabled */ + if (!overlay_state->crtc) + return 0; + + /* find the primary plane for the CRTC that the overlay is enabled on */ + primary_state = drm_atomic_get_plane_state(state, overlay_state->crtc->primary); + if (IS_ERR(primary_state)) + return PTR_ERR(primary_state); + + /* check if primary plane is enabled */ + if (!primary_state->crtc) + return 0; + + /* Perform the bounds check to ensure the overlay plane covers the primary */ + if (primary_state->crtc_x < overlay_state->crtc_x || + primary_state->crtc_y < overlay_state->crtc_y || + primary_state->crtc_x + primary_state->crtc_w > overlay_state->crtc_x + overlay_state->crtc_w || + primary_state->crtc_y + primary_state->crtc_h > overlay_state->crtc_y + overlay_state->crtc_h) { + DRM_DEBUG_ATOMIC("Overlay plane is enabled with hardware cursor but does not fully cover primary plane\n"); + return -EINVAL; + } + + return 0; +} + /** * amdgpu_dm_atomic_check() - Atomic check implementation for AMDgpu DM. * @dev: The DRM device @@ -7440,6 +7487,10 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev, goto fail; } + ret = validate_overlay(state); + if (ret) + goto fail; + /* Add new/modified planes */ for_each_oldnew_plane_in_state_reverse(state, plane, old_plane_state, new_plane_state, i) { ret = dm_update_plane_state(dc, state, plane, -- 2.30.2