From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D176AC56201 for ; Thu, 19 Nov 2020 15:35:10 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B42B24695 for ; Thu, 19 Nov 2020 15:35:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Mgu6Nwc3"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="f7CSg0tW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B42B24695 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JrdDtzQ+3D9dchvGw28IJWzWs42l+NS5QeBn7VhobBg=; b=Mgu6Nwc3piNm8eylLEyeOHDrG ByJbaoaJ/Yo6pL/fhM3CTftSaGQE2tBdH2Q8m7S2k33MzlaOAnl+T6W+e7GjU6MAk9p/vB0wtGWf/ EMN2feQ18MTch3pETmIkZzFiD6MhoVuqF41FKKQGdW+NNPFvYAVzdKzS+dQcUxMPTs7vUYaIOHsaM 0fFEffjyu92tq1ZYdsKDDQB643Jx8tTUnk+Pn4pRPt5TKbqJq/Px8RSVmVeeOzQMiV4uolkrmfWff s9Dr9Fc3qSr6xJRz6fJ/BBIQbVajmPUOdcNdfUQ3GBDk5Ll15RYvD9M9vSGvStRfQ+vQKyQP1tJ5X c6QHHWokg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kflwv-0008HJ-1U; Thu, 19 Nov 2020 15:34:17 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kflv6-0007Qg-MM for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 15:32:29 +0000 Received: by mail-wm1-x341.google.com with SMTP id c198so5699914wmd.0 for ; Thu, 19 Nov 2020 07:32:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9CA+u5v5MZQU0Cijf9R85vpRjl6SxHe21W1/7WviTBk=; b=f7CSg0tWAXzvTAeyAFBNH9vEwhiuVjR8rw2/sZS0eOqH937OSEWC/G9VBfrmYJvjft CqBVjE1kOFjDO4vETUj9EgsGpFuw0uIRevPv+ctpLRG0YXn3NndDtKvytBswJ4OOy+sq k5+TZzH9gDjY8bHZ1auf5AD8D0rBR6B/l1mAM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9CA+u5v5MZQU0Cijf9R85vpRjl6SxHe21W1/7WviTBk=; b=AIhc2oDL4YqDJUODAKULqV1NiSziV4kPldLZoHf+9VK/bJOtvUCm0/CcSuV5Jj5sgH q+RPNACnSeaW2Dkws8ykKawnoFUIn4NhZcGFAHIrufvWATJk9zzZbGNB6P7eJ6FYgKSp +IjGMkE8Xw2iCILwGd95znYWIklFy2aAFZG6OgNSWJ8dGZ7IgPZIehhkOTcfqqCCsnig mys5VIW2dp/thYCZRMJDjxwvidsFZRh35ZctWEgRKu40zJCNTJaRDyGB0A6Jjto16dl2 +0D1KcoBCim175xFeCy5HMT+V//qFl9Ku1xbsO6q4PX2boCd4LHHh4hbu5Y3UpEtaJV/ wkww== X-Gm-Message-State: AOAM530QQYeN6ROx+X6GY6PS3AFUn3o/OIWTfWglO4tyvu/ycNA75sS0 rVNEvjCBUhtbZUSm3hT17ZPS/Q== X-Google-Smtp-Source: ABdhPJw5zyTkZhzThU4ihl8uYdd68wZVmR45jaD/HluopOoNQerVBtPGyp1aO3HR7AxM0ZUZ27sbZw== X-Received: by 2002:a1c:5f83:: with SMTP id t125mr5105057wmb.82.1605799940246; Thu, 19 Nov 2020 07:32:20 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id c2sm103857wrf.68.2020.11.19.07.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 07:32:19 -0800 (PST) Date: Thu, 19 Nov 2020 16:32:17 +0100 From: Daniel Vetter To: Thomas Zimmermann Subject: Re: [PATCH 1/8] drm: Introduce an atomic_commit_setup function Message-ID: <20201119153217.GE401619@phenom.ffwll.local> References: <20201113152956.139663-1-maxime@cerno.tech> <20201113152956.139663-2-maxime@cerno.tech> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Operating-System: Linux phenom 5.7.0-1-amd64 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201119_103224_819355_9F9B10CF X-CRM114-Status: GOOD ( 37.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Tim Gover , Dave Stevenson , David Airlie , Daniel Vetter , Maarten Lankhorst , dri-devel@lists.freedesktop.org, Eric Anholt , Rob Herring , bcm-kernel-feedback-list@broadcom.com, Maxime Ripard , Daniel Vetter , Frank Rowand , Phil Elwell , linux-arm-kernel@lists.infradead.org, linux-rpi-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Nov 19, 2020 at 10:59:42AM +0100, Thomas Zimmermann wrote: > Hi > > Am 13.11.20 um 16:29 schrieb Maxime Ripard: > > Private objects storing a state shared across all CRTCs need to be > > carefully handled to avoid a use-after-free issue. > > > > The proper way to do this to track all the commits using that shared > > state and wait for the previous commits to be done before going on with > > the current one to avoid the reordering of commits that could occur. > > > > However, this commit setup needs to be done after > > drm_atomic_helper_setup_commit(), because before the CRTC commit > > structure hasn't been allocated before, and before the workqueue is > > scheduled, because we would be potentially reordered already otherwise. > > > > That means that drivers currently have to roll their own > > drm_atomic_helper_commit() function, even though it would be identical > > if not for the commit setup. > > > > Let's introduce a hook to do so that would be called as part of > > drm_atomic_helper_commit, allowing us to reuse the atomic helpers. > > > > Suggested-by: Daniel Vetter > > Signed-off-by: Maxime Ripard > > --- > > drivers/gpu/drm/drm_atomic_helper.c | 6 ++++++ > > include/drm/drm_modeset_helper_vtables.h | 18 ++++++++++++++++++ > > 2 files changed, 24 insertions(+) > > > > diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c > > index ddd0e3239150..7d69c7844dfc 100644 > > --- a/drivers/gpu/drm/drm_atomic_helper.c > > +++ b/drivers/gpu/drm/drm_atomic_helper.c > > @@ -2083,8 +2083,11 @@ int drm_atomic_helper_setup_commit(struct drm_atomic_state *state, > > struct drm_plane *plane; > > struct drm_plane_state *old_plane_state, *new_plane_state; > > struct drm_crtc_commit *commit; > > + const struct drm_mode_config_helper_funcs *funcs; > > int i, ret; > > + funcs = state->dev->mode_config.helper_private; > > + > > for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { > > commit = kzalloc(sizeof(*commit), GFP_KERNEL); > > if (!commit) > > @@ -2169,6 +2172,9 @@ int drm_atomic_helper_setup_commit(struct drm_atomic_state *state, > > new_plane_state->commit = drm_crtc_commit_get(commit); > > } > > + if (funcs && funcs->atomic_commit_setup) > > + return funcs->atomic_commit_setup(state); > > + > > return 0; > > } > > EXPORT_SYMBOL(drm_atomic_helper_setup_commit); > > diff --git a/include/drm/drm_modeset_helper_vtables.h b/include/drm/drm_modeset_helper_vtables.h > > index f2de050085be..56470baf0513 100644 > > --- a/include/drm/drm_modeset_helper_vtables.h > > +++ b/include/drm/drm_modeset_helper_vtables.h > > @@ -1396,6 +1396,24 @@ struct drm_mode_config_helper_funcs { > > * drm_atomic_helper_commit_tail(). > > */ > > void (*atomic_commit_tail)(struct drm_atomic_state *state); > > + > > + /** > > + * @atomic_commit_setup: > > + * > > + * This hook is used by the default atomic_commit() hook implemented in > > + * drm_atomic_helper_commit() together with the nonblocking helpers (see > > + * drm_atomic_helper_setup_commit()) to extend the DRM commit setup. It > > + * is not used by the atomic helpers. > > + * > > + * This function is called at the end of > > + * drm_atomic_helper_setup_commit(), so once the commit has been > > + * properly setup across the generic DRM object states. It allows > > + * drivers to do some additional commit tracking that isn't related to a > > + * CRTC, plane or connector, typically a private object. > > + * > > + * This hook is optional. > > + */ > > + int (*atomic_commit_setup)(struct drm_atomic_state *state); > > It feels hacky and screwed-on to me. I'd suggest to add an > atomic_commit_prepare callback that is called by drm_atomic_helper where it > currently calls drm_atomic_helper_setup_commit(). The default implementation > would include setup_commit and prepare_planes. Some example code for > drm_atomic_helper.c > > static int commit_prepare(state) > { > drm_atomic_helper_setup_commit(state) > > drm_atomic_helper_prepare_planes(state) > } > > int drm_atomic_helper_commit() > { > if (async_update) { > ... > } > > if (funcs->atomic_commit_prepare) > funcs->atomic_commit_prepare(state) > else > commit_prepare(state) > > /* the rest of the current function below */ > INIT_WORK(&state->commit_work, commit_work); > ... > } > > Drivers that implement atomic_commit_prepare would be expected to call > drm_atomic_helper_setup_commit() and drm_atomic_helper_prepare_planes() or > their own implementation of them. > > The whole construct mimics how commit tails work. Yeah what I suggested is a bit much midlayer, but we've done what you suggested above with all drivers rolling their own atomic_commit. It wasn't pretty. There's still drivers like vc4 which haven't switched, and which have their own locking and synchronization. Hence why I think the callback approach here is better, gives drivers less excuses to roll their own and make a mess. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel