Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2382994ybi; Sun, 9 Jun 2019 10:21:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqvdOAEu6A+ZxrjL1ObvF3yuNsBgW1IptFXyeOQFYYtMVZBgpYVlfOtPhLIHpdMArdjrqy X-Received: by 2002:a63:6cc5:: with SMTP id h188mr12288086pgc.105.1560100868163; Sun, 09 Jun 2019 10:21:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560100868; cv=none; d=google.com; s=arc-20160816; b=SW1WjwJKULtXocABIDCqL8cj+10Y0T4Qe6JHXpqED8Vrjx69XbZPJureEFKKUE0GaA Vjfuj/EtxiAbWJqMtcJcOQuYp2VKipT9xbR9D0oj2CMGRsOhRn/50G7nXgQh1dwgJc5E 3zB1RlID0nLmiojJrZZryKe5NCeIRhKHNj8YTsEMo7Kpm93CrlKuA+IKsfPETlm0Ik27 wq38cSn38BoRYPmg6XO2gQxI21jvQwfW+EiZ2tB/yMWO2dxdtsgXrgeF8YTk6F5JFKZ3 jzfDvX0qjbdMULpLVdnGyoBpcDu8H32dbrt/pDabasR4LaAFQ7kvxywEkbHgPVpvp8cN wJPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UgLRL6xOGqDWeNkCU70HmPQsrqb7um5X/LLr7u2Q+Ts=; b=Eb3cHGtj9XTL52Kl+mx4DAm1unxkb57H36A+1sNaJ99M7vWHAIIbD5AJDZvok6K8uT 4Vv6orRoMrdTysmVi8K6+dsaFD6iiyECGAFeK54eGaVuMb7SHiB2rBsnXx8MyxwHb/cI 9JSUrRl98UdLUE39BM9R6ijhkAzCtDre5vv0Zk70SpkDIupT+NeOOmSNrsl3LdPlpLNo 3iQkRGYFAN2TyBYnJV+PJ0uGEiYLyEC2B9+ZsY7l08sj5ikm2+ur/SpWs/Y/1DvS9tgp M9YVFJWblO9+L7ZTVxzoQagtqW7lGFBtTpz65yYkjBmZqzjtcSTrnALgaLZaOZp+AOCZ aa4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tu+33DG9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w15si7319395ply.68.2019.06.09.10.20.52; Sun, 09 Jun 2019 10:21:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tu+33DG9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731435AbfFIQtR (ORCPT + 99 others); Sun, 9 Jun 2019 12:49:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:48632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731390AbfFIQtP (ORCPT ); Sun, 9 Jun 2019 12:49:15 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 99346206DF; Sun, 9 Jun 2019 16:49:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560098954; bh=gcCgrMDtogtv9S02H5nZ1BGnkLNi/H29ZWVzYhJvc4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tu+33DG9jMIcuBceM49/1tysMdDK4Dl+6O3xBlY2KPOtl1hrp6bZSR8TLTP8S/ypJ Cihxv1eclND3UPOqrIQtrP7glQSkSRVnqvVxvT/o06R5K3bH4ORyhWl9WeGMGXEjtf /FSyuZt0zv07mc0tYXqEIhSPIkDZtu8SQ5GYTsF8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Boris Brezillon , Helen Koike , Nicholas Kazlauskas Subject: [PATCH 4.19 49/51] drm: dont block fb changes for async plane updates Date: Sun, 9 Jun 2019 18:42:30 +0200 Message-Id: <20190609164130.817119906@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164127.123076536@linuxfoundation.org> References: <20190609164127.123076536@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Helen Koike commit 89a4aac0ab0e6f5eea10d7bf4869dd15c3de2cd4 upstream. In the case of a normal sync update, the preparation of framebuffers (be it calling drm_atomic_helper_prepare_planes() or doing setups with drm_framebuffer_get()) are performed in the new_state and the respective cleanups are performed in the old_state. In the case of async updates, the preparation is also done in the new_state but the cleanups are done in the new_state (because updates are performed in place, i.e. in the current state). The current code blocks async udpates when the fb is changed, turning async updates into sync updates, slowing down cursor updates and introducing regressions in igt tests with errors of type: "CRITICAL: completed 97 cursor updated in a period of 30 flips, we expect to complete approximately 15360 updates, with the threshold set at 7680" Fb changes in async updates were prevented to avoid the following scenario: - Async update, oldfb = NULL, newfb = fb1, prepare fb1, cleanup fb1 - Async update, oldfb = fb1, newfb = fb2, prepare fb2, cleanup fb2 - Non-async commit, oldfb = fb2, newfb = fb1, prepare fb1, cleanup fb2 (wrong) Where we have a single call to prepare fb2 but double cleanup call to fb2. To solve the above problems, instead of blocking async fb changes, we place the old framebuffer in the new_state object, so when the code performs cleanups in the new_state it will cleanup the old_fb and we will have the following scenario instead: - Async update, oldfb = NULL, newfb = fb1, prepare fb1, no cleanup - Async update, oldfb = fb1, newfb = fb2, prepare fb2, cleanup fb1 - Non-async commit, oldfb = fb2, newfb = fb1, prepare fb1, cleanup fb2 Where calls to prepare/cleanup are balanced. Cc: # v4.14+ Fixes: 25dc194b34dd ("drm: Block fb changes for async plane updates") Suggested-by: Boris Brezillon Signed-off-by: Helen Koike Reviewed-by: Boris Brezillon Reviewed-by: Nicholas Kazlauskas Signed-off-by: Boris Brezillon Link: https://patchwork.freedesktop.org/patch/msgid/20190603165610.24614-6-helen.koike@collabora.com Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/drm_atomic_helper.c | 22 ++++++++++++---------- include/drm/drm_modeset_helper_vtables.h | 8 ++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -1573,15 +1573,6 @@ int drm_atomic_helper_async_check(struct if (old_plane_state->fb != new_plane_state->fb) return -EINVAL; - /* - * FIXME: Since prepare_fb and cleanup_fb are always called on - * the new_plane_state for async updates we need to block framebuffer - * changes. This prevents use of a fb that's been cleaned up and - * double cleanups from occuring. - */ - if (old_plane_state->fb != new_plane_state->fb) - return -EINVAL; - funcs = plane->helper_private; if (!funcs->atomic_async_update) return -EINVAL; @@ -1612,6 +1603,8 @@ EXPORT_SYMBOL(drm_atomic_helper_async_ch * drm_atomic_async_check() succeeds. Async commits are not supposed to swap * the states like normal sync commits, but just do in-place changes on the * current state. + * + * TODO: Implement full swap instead of doing in-place changes. */ void drm_atomic_helper_async_commit(struct drm_device *dev, struct drm_atomic_state *state) @@ -1622,6 +1615,9 @@ void drm_atomic_helper_async_commit(stru int i; for_each_new_plane_in_state(state, plane, plane_state, i) { + struct drm_framebuffer *new_fb = plane_state->fb; + struct drm_framebuffer *old_fb = plane->state->fb; + funcs = plane->helper_private; funcs->atomic_async_update(plane, plane_state); @@ -1630,11 +1626,17 @@ void drm_atomic_helper_async_commit(stru * plane->state in-place, make sure at least common * properties have been properly updated. */ - WARN_ON_ONCE(plane->state->fb != plane_state->fb); + WARN_ON_ONCE(plane->state->fb != new_fb); WARN_ON_ONCE(plane->state->crtc_x != plane_state->crtc_x); WARN_ON_ONCE(plane->state->crtc_y != plane_state->crtc_y); WARN_ON_ONCE(plane->state->src_x != plane_state->src_x); WARN_ON_ONCE(plane->state->src_y != plane_state->src_y); + + /* + * Make sure the FBs have been swapped so that cleanups in the + * new_state performs a cleanup in the old FB. + */ + WARN_ON_ONCE(plane_state->fb != old_fb); } } EXPORT_SYMBOL(drm_atomic_helper_async_commit); --- a/include/drm/drm_modeset_helper_vtables.h +++ b/include/drm/drm_modeset_helper_vtables.h @@ -1174,6 +1174,14 @@ struct drm_plane_helper_funcs { * current one with the new plane configurations in the new * plane_state. * + * Drivers should also swap the framebuffers between current plane + * state (&drm_plane.state) and new_state. + * This is required since cleanup for async commits is performed on + * the new state, rather than old state like for traditional commits. + * Since we want to give up the reference on the current (old) fb + * instead of our brand new one, swap them in the driver during the + * async commit. + * * FIXME: * - It only works for single plane updates * - Async Pageflips are not supported yet