Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4428852ybx; Mon, 4 Nov 2019 13:13:56 -0800 (PST) X-Google-Smtp-Source: APXvYqyWAmKMsHTj686/2zzpjkHzZOuQLOs9crds4jVj9uZTCFRp/NkB2pQzIQGqW52cvb6/FN1K X-Received: by 2002:a50:d55b:: with SMTP id f27mr32433307edj.302.1572902036505; Mon, 04 Nov 2019 13:13:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572902036; cv=none; d=google.com; s=arc-20160816; b=TpMHwr25cBIVd4wja6kWcnvixmoqLqDJtGa88p8b7qP/8LEaDfQpaWkOm0WZe9zVKw bnWEoCUHABYvVj3Nw0T7Ty/5BeNhhw1T3wjyQBJ34UmxmODGewf5KN0ib2lmGHii95td H1b5jK3AtzDeXhVPo8vXNgVnhIFNGHZA370rG/SPBEiXfvYCqHK4+oWr2Qy4UEvxWusC G/qxfVrLP3RY7YT5+Wk42WZKsClzGxfvYK6pWj2fqi2dDOr06VgxLIBFT37iNIuUshEM UbcQpRFQpBDOJ+LH1ENZq3XLtFkxYXrxD9mwlF99ULWp5OZAEn9cJyf7Nzkn5JTf/wzU ameg== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=QJX38fPH4Wmm+NgS8n4DnoBmgQALP+GtwdgAD3lH8MI=; b=BlPI8Ux5Uga2kzS6L+hWeavdhsWNJZTtcueu2n4CF5h7b8UeJQWCuJCihe30zJkVdD lST7QOAm0eCFFkSSZXQzWK8yHlVlLaEI/+PElhXnlE7fLKJPx19jw3bO+MXp0QvN5z/q 931OnJ/sfltbz5Dwa9TyGDWoARTgCP58ztDOJGJqnktblGErdwnFZyarFSZy2Yvzpxkg OfFBP79XCJzfPBFDxWdgKToGKH9koyMiPRyUNJ3YDfug+h1gUuyS0mjU30UmE6/Tf9eU /OyuqerI5gwsmezPowZmw+VEtM5e00XbawgYzivhh8J66yqY8hShzrmm1OtOW4Wh00dm U6gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=F59FOw5E; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j11si8451429edj.43.2019.11.04.13.13.32; Mon, 04 Nov 2019 13:13:56 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=F59FOw5E; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728766AbfKDVMA (ORCPT + 99 others); Mon, 4 Nov 2019 16:12:00 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:39709 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728377AbfKDVMA (ORCPT ); Mon, 4 Nov 2019 16:12:00 -0500 Received: by mail-ed1-f68.google.com with SMTP id l25so14330682edt.6 for ; Mon, 04 Nov 2019 13:11:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=QJX38fPH4Wmm+NgS8n4DnoBmgQALP+GtwdgAD3lH8MI=; b=F59FOw5EM0G/b4mEvS1yY4BDvYP7j8S7tBalF1rIUni4dl8Q8CQqso54n3xO9DKZ30 +PXvdbSv4VqiRSSbgq5bCFRCbX2+4N77CSpCXhhYJpOn1EeURCz7yKZAU9mzXGbI9QiF USTGaD89RJTIW0TPqEdFyCErU+7KG1VWqF6IqNktxqloX1o0qb8VH5vD/7B9xxt+MF1t ninKOgHxYsGFQYLAx+Fmh3kPes2u1JJ2JV4UJbOGGYgGLeP6ba8qABe28QZI6IP1nrH+ x7k33ZTE3LM2z2XaIkakFGud8Xlhw8andNAKKJx/by6TSVPwAb14DHrfhhEHDhBy4l+y uIIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=QJX38fPH4Wmm+NgS8n4DnoBmgQALP+GtwdgAD3lH8MI=; b=Kf3szDr0uLqzXJulmyOC1B2qGlEzcAqjxwCFXDNvfAwqqwVnpRm7FTVA41ah/NorLc GqL1wrzHT78oMvL0jae8Zx6dLhhjQU/J5X0fezOKa/rkD/E6GZufvuy5QM/fOduWLI5l UTT/Y57HDm9I01SOcIuyvVnhHE9m3k8o/eiX7eEcO+lMR1A0mpGnsFhpft8A+1xZvZfE 4Fwt+o7UyDFUI4qQQLKUPdcVhFF2XFf9gkqQdndO4HUjCxKxX7uq71nhOdhMScLlBy91 B4F2TgU/4rQ1m6uHZo1pbk/WnY5dhUGQ228JmcjKTSqIJUS5/HvZNj/y+L8cO4mfE0oK gmYQ== X-Gm-Message-State: APjAAAUEVQw13vC1it94p+Tput2xf4yEAhA3wCZ99ML82u1iQ0inOl02 x74QQwSfw6nX9naZf9gpLt8RBYfMDevsqL8PJKw= X-Received: by 2002:a17:906:a44:: with SMTP id x4mr25620544ejf.64.1572901917757; Mon, 04 Nov 2019 13:11:57 -0800 (PST) MIME-Version: 1.0 References: <20191101180713.5470-1-robdclark@gmail.com> <20191101180713.5470-2-robdclark@gmail.com> <20191101192458.GI1208@intel.com> <20191101214431.GJ1208@intel.com> <20191104184156.GL1208@intel.com> <20191104205010.GM1208@intel.com> In-Reply-To: <20191104205010.GM1208@intel.com> From: Rob Clark Date: Mon, 4 Nov 2019 13:11:46 -0800 Message-ID: Subject: Re: [PATCH 2/2] drm/atomic: clear new_state pointers at hw_done To: =?UTF-8?B?VmlsbGUgU3lyasOkbMOk?= Cc: Rob Clark , dri-devel , David Airlie , open list , Sean Paul , Sean Paul Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 4, 2019 at 12:50 PM Ville Syrj=C3=A4l=C3=A4 wrote: > > On Mon, Nov 04, 2019 at 11:13:59AM -0800, Rob Clark wrote: > > On Mon, Nov 4, 2019 at 10:42 AM Ville Syrj=C3=A4l=C3=A4 > > wrote: > > > > > > On Fri, Nov 01, 2019 at 03:14:09PM -0700, Rob Clark wrote: > > > > On Fri, Nov 1, 2019 at 2:44 PM Ville Syrj=C3=A4l=C3=A4 > > > > wrote: > > > > > > > > > > On Fri, Nov 01, 2019 at 12:49:02PM -0700, Rob Clark wrote: > > > > > > On Fri, Nov 1, 2019 at 12:25 PM Ville Syrj=C3=A4l=C3=A4 > > > > > > wrote: > > > > > > > > > > > > > > On Fri, Nov 01, 2019 at 11:07:13AM -0700, Rob Clark wrote: > > > > > > > > From: Rob Clark > > > > > > > > > > > > > > > > The new state should not be accessed after this point. Cle= ar the > > > > > > > > pointers to make that explicit. > > > > > > > > > > > > > > > > This makes the error corrected in the previous patch more o= bvious. > > > > > > > > > > > > > > > > Signed-off-by: Rob Clark > > > > > > > > --- > > > > > > > > drivers/gpu/drm/drm_atomic_helper.c | 29 +++++++++++++++++= ++++++++++++ > > > > > > > > 1 file changed, 29 insertions(+) > > > > > > > > > > > > > > > > diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/= gpu/drm/drm_atomic_helper.c > > > > > > > > index 732bd0ce9241..176831df8163 100644 > > > > > > > > --- a/drivers/gpu/drm/drm_atomic_helper.c > > > > > > > > +++ b/drivers/gpu/drm/drm_atomic_helper.c > > > > > > > > @@ -2234,13 +2234,42 @@ EXPORT_SYMBOL(drm_atomic_helper_fak= e_vblank); > > > > > > > > */ > > > > > > > > void drm_atomic_helper_commit_hw_done(struct drm_atomic_st= ate *old_state) > > > > > > > > { > > > > > > > > + struct drm_connector *connector; > > > > > > > > + struct drm_connector_state *old_conn_state, *new_conn= _state; > > > > > > > > struct drm_crtc *crtc; > > > > > > > > struct drm_crtc_state *old_crtc_state, *new_crtc_stat= e; > > > > > > > > + struct drm_plane *plane; > > > > > > > > + struct drm_plane_state *old_plane_state, *new_plane_s= tate; > > > > > > > > struct drm_crtc_commit *commit; > > > > > > > > + struct drm_private_obj *obj; > > > > > > > > + struct drm_private_state *old_obj_state, *new_obj_sta= te; > > > > > > > > int i; > > > > > > > > > > > > > > > > + /* > > > > > > > > + * After this point, drivers should not access the pe= rmanent modeset > > > > > > > > + * state, so we also clear the new_state pointers to = make this > > > > > > > > + * restriction explicit. > > > > > > > > + * > > > > > > > > + * For the CRTC state, we do this in the same loop wh= ere we signal > > > > > > > > + * hw_done, since we still need to new_crtc_state to = fish out the > > > > > > > > + * commit. > > > > > > > > + */ > > > > > > > > + > > > > > > > > + for_each_oldnew_connector_in_state(old_state, connect= or, old_conn_state, new_conn_state, i) { > > > > > > > > + old_state->connectors[i].new_state =3D NULL; > > > > > > > > + } > > > > > > > > + > > > > > > > > + for_each_oldnew_plane_in_state(old_state, plane, old_= plane_state, new_plane_state, i) { > > > > > > > > + old_state->planes[i].new_state =3D NULL; > > > > > > > > + } > > > > > > > > + > > > > > > > > + for_each_oldnew_private_obj_in_state(old_state, obj, = old_obj_state, new_obj_state, i) { > > > > > > > > + old_state->private_objs[i].new_state =3D NULL= ; > > > > > > > > + } > > > > > > > > + > > > > > > > > for_each_oldnew_crtc_in_state(old_state, crtc, old_cr= tc_state, new_crtc_state, i) { > > > > > > > > old_state->crtcs[i].new_self_refresh_active = =3D new_crtc_state->self_refresh_active; > > > > > > > > + old_state->crtcs[i].new_state =3D NULL; > > > > > > > > > > > > > > That's going to be a real PITA when doing programming after t= he fact from > > > > > > > a vblank worker. It's already a pain that the new_crtc_state-= >state is > > > > > > > getting NULLed somewhere. > > > > > > > > > > > > > > > > > > > I think you already have that problem, this just makes it expli= cit. > > > > > > > > > > I don't yet. Except on a branch where I have my vblank workers. > > > > > And I think the only problem is having the helpers/core clobber > > > > > the pointers when it should not. I don't see why it can't just > > > > > leave them be and let me use them. > > > > > > > > > > > > > I guess it comes down to what assumptions you can make in driver > > > > backend. But if you can, for example, move planes between crtcs, I > > > > think you can't make assumptions about the order in which things > > > > complete even if you don't have commits overtaking each other on a > > > > single crtc.. > > > > > > IMO this whole notion of accessing new_crtc_state & co. being unsafe > > > for some reason is wrong. I think as long as I have the drm_atomic_st= ate > > > I should be able to look at the new/old states within. > > > > > > > accessing new state only works if you can guarantee the order in which > > commits complete, which I don't think you can do in the general sense. > > Doesn't feel like it should take a lot of rocket science to guarantee > the states get freed in the right order. > I agree, reference counting is not rocket science. But that isn't the way drm core handles per-object state currently. Refcnt'ing is probably the approach that I'd recommend if someone wanted to lift this restriction about accessing new-state later. BR, -R