From: Daniel Vetter <daniel@ffwll.ch>
To: Maxime Ripard <maxime@cerno.tech>
Cc: Mark Rutland <mark.rutland@arm.com>,
devicetree@vger.kernel.org, Tim Gover <tim.gover@raspberrypi.com>,
Dave Stevenson <dave.stevenson@raspberrypi.com>,
David Airlie <airlied@linux.ie>,
dri-devel@lists.freedesktop.org, Rob Herring <robh+dt@kernel.org>,
bcm-kernel-feedback-list@broadcom.com,
linux-rpi-kernel@lists.infradead.org,
Thomas Zimmermann <tzimmermann@suse.de>,
Daniel Vetter <daniel.vetter@intel.com>,
Frank Rowand <frowand.list@gmail.com>,
Phil Elwell <phil@raspberrypi.com>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 2/8] drm: Document use-after-free gotcha with private objects
Date: Thu, 19 Nov 2020 16:38:23 +0100 [thread overview]
Message-ID: <20201119153823.GF401619@phenom.ffwll.local> (raw)
In-Reply-To: <20201113152956.139663-3-maxime@cerno.tech>
On Fri, Nov 13, 2020 at 04:29:50PM +0100, Maxime Ripard wrote:
> The private objects have a gotcha that could result in a use-after-free,
> make sure it's properly documented.
>
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
> ---
> include/drm/drm_atomic.h | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
> index 413fd0ca56a8..24b52b3a459f 100644
> --- a/include/drm/drm_atomic.h
> +++ b/include/drm/drm_atomic.h
> @@ -248,6 +248,24 @@ struct drm_private_state_funcs {
> * drm_dev_register()
> * 2/ all calls to drm_atomic_private_obj_fini() must be done after calling
> * drm_dev_unregister()
> + *
> + * If that private object is used to store a state shared my multiple
s/my/by/
> + * CRTCs, proper care must be taken to ensure that non-blocking commits are
> + * properly ordered to avoid a use-after-free issue.
> + *
> + * Indeed, assuming a sequence of two non-blocking commits on two different
> + * CRTCs using different planes and connectors, so with no resources shared,
> + * there's no guarantee on which commit is going to happen first. However, the
> + * second commit will consider the first private state its old state, and will
> + * be in charge of freeing it whenever the second commit is done.
> + *
> + * If the first commit happens after it, it will consider its private state the
> + * new state and will be likely to access it, resulting in an access to a freed
> + * memory region. A way to circumvent this is to store (and get a reference to)
s/A way to circumvent/Driver should/
And maybe make the paragraph break here and remove the previous one in the
middle of your example.
> + * the crtc commit in our private state in
&struct drm_crtc_commit so it's linked properly
> + * &drm_mode_config_helper_funcs.atomic_commit_setup, and then wait for that
> + * commit to complete as part of
s/as part of/as the first step of/
> + * &drm_mode_config_helper_funcs.atomic_commit_tail.
And maybe add "... similar to drm_atomic_helper_wait_for_dependencies()"
With the nits addressed:
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> */
> struct drm_private_obj {
> /**
> --
> 2.28.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-11-19 15:38 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-13 15:29 [PATCH 0/8] vc4: Convert to drm_atomic_helper_commit Maxime Ripard
2020-11-13 15:29 ` [PATCH 1/8] drm: Introduce an atomic_commit_setup function Maxime Ripard
2020-11-13 21:02 ` Daniel Vetter
2020-11-20 13:34 ` Maxime Ripard
2020-11-20 14:50 ` Daniel Vetter
2020-11-19 9:59 ` Thomas Zimmermann
2020-11-19 15:32 ` Daniel Vetter
2020-11-20 8:38 ` Thomas Zimmermann
2020-11-20 9:29 ` Daniel Vetter
2020-11-13 15:29 ` [PATCH 2/8] drm: Document use-after-free gotcha with private objects Maxime Ripard
2020-11-19 15:38 ` Daniel Vetter [this message]
2020-11-13 15:29 ` [PATCH 3/8] drm/vc4: kms: Move HVS state helpers around Maxime Ripard
2020-11-19 9:26 ` Thomas Zimmermann
2020-11-13 15:29 ` [PATCH 4/8] drm/vc4: kms: Simplify a bit the private obj state hooks Maxime Ripard
2020-11-19 9:27 ` Thomas Zimmermann
2020-11-13 15:29 ` [PATCH 5/8] drm/vc4: Simplify a bit the global atomic_check Maxime Ripard
2020-11-19 9:32 ` Thomas Zimmermann
2020-11-13 15:29 ` [PATCH 6/8] drm/vc4: kms: Wait on previous FIFO users before a commit Maxime Ripard
2020-11-20 13:19 ` Thomas Zimmermann
2020-12-01 17:06 ` Maxime Ripard
2020-11-13 15:29 ` [PATCH 7/8] drm/vc4: kms: Remove async modeset semaphore Maxime Ripard
2020-11-20 14:03 ` Thomas Zimmermann
2020-11-13 15:29 ` [PATCH 8/8] drm/vc4: kms: Convert to atomic helpers Maxime Ripard
2020-11-20 14:08 ` Thomas Zimmermann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201119153823.GF401619@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=airlied@linux.ie \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=daniel.vetter@intel.com \
--cc=dave.stevenson@raspberrypi.com \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=frowand.list@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=maxime@cerno.tech \
--cc=phil@raspberrypi.com \
--cc=robh+dt@kernel.org \
--cc=tim.gover@raspberrypi.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).