public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Daniel Thompson <daniel.thompson@linaro.org>
To: Daniel Vetter <daniel.vetter@ffwll.ch>,
	DRI Development <dri-devel@lists.freedesktop.org>
Cc: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Subject: Re: [PATCH 15/17] drm/atomic-helpers: functions for state duplicate/destroy/reset
Date: Mon, 03 Nov 2014 14:45:28 +0000	[thread overview]
Message-ID: <54579508.1030404@linaro.org> (raw)
In-Reply-To: <1414934370-11924-16-git-send-email-daniel.vetter@ffwll.ch>

On 02/11/14 13:19, Daniel Vetter wrote:> The atomic users and helpers
assume that there is always a obj->state
> structure around. Which means drivers need to somehow create that at
> driver load time. Also it should obviously reset hardware state, so
> needs to be reset upon resume.
>
> Finally the destroy/duplicate_state functions are an awful lot of
> boilerplate if the driver doesn't need anything beyond the default
> state objects.
>
> So add helper functions for all of this.
>
> v2: Somehow the plane/connector versions got lost in the first
> version.
>
> v3: Add kerneldoc.
>
> v4: Make duplicate_state functions a bit more robust, which is useful
> for debugging state tracking issues when transitioning to atomic.
>
> v5: Clear temporary variables in the crtc state when duplicating it,
> like ->mode_changed or ->planes_changed. If we don't do this stale
> values for these might pollute the next atomic modeset.
>
> v6: Also clear crtc_state->event in case the driver didn't (yet) clear
> this out.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/drm_atomic_helper.c | 154
+++++++++++++++++++++++++++++++++++-
>  include/drm/drm_atomic_helper.h     |  19 +++++
>  2 files changed, 170 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic_helper.c
b/drivers/gpu/drm/drm_atomic_helper.c
> index 70bd67cf86e3..bd38df3cbe55 100644
> --- a/drivers/gpu/drm/drm_atomic_helper.c
> +++ b/drivers/gpu/drm/drm_atomic_helper.c
> @@ -1429,7 +1429,7 @@ EXPORT_SYMBOL(drm_atomic_helper_set_config);
>  /**
>   * drm_atomic_helper_crtc_set_property - helper for crtc prorties
>   * @crtc: DRM crtc
> - * @prorty: DRM property
> + * @property: DRM property

This looks like a bad fixup (should be in patch 11).


>   * @val: value of property
>   *
>   * Provides a default plane disablle handler using the atomic driver
interface.
> @@ -1493,7 +1493,7 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_set_property);
>  /**
>   * drm_atomic_helper_plane_set_property - helper for plane prorties
>   * @plane: DRM plane
> - * @prorty: DRM property
> + * @property: DRM property

+1


>   * @val: value of property
>   *
>   * Provides a default plane disable handler using the atomic driver
interface.
> @@ -1557,7 +1557,7 @@ EXPORT_SYMBOL(drm_atomic_helper_plane_set_property);
>  /**
>   * drm_atomic_helper_connector_set_property - helper for connector
prorties
>   * @connector: DRM connector
> - * @prorty: DRM property
> + * @property: DRM property

+1


>   * @val: value of property
>   *
>   * Provides a default plane disablle handler using the atomic driver
interface.
> @@ -1707,3 +1707,151 @@ backoff:
>  	goto retry;
>  }
>  EXPORT_SYMBOL(drm_atomic_helper_page_flip);
> +
> +/**
> + * drm_atomic_helper_crtc_reset - default ->reset hook for CRTCs
> + * @crtc: drm CRTC
> + *
> + * Resets the atomic state for @crtc by freeing the state pointer and
allocating
> + * a new empty state object.
> + */
> +void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
> +{
> +	kfree(crtc->state);
> +	crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL);

This code looks semantically equivalent to a memset() although it may
result in a change to the pointer value. Is this code trying to flush
out uses-after-free?

I can't find this free/alloc pattern in delivered code anywhere else in
the drm code base. Should this need to be replaced with memset() before
merging (or at least commenting)?


> +}
> +EXPORT_SYMBOL(drm_atomic_helper_crtc_reset);
> +
> +/**
> + * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook
> + * @crtc: drm CRTC
> + *
> + * Default CRTC state duplicate hook for drivers which don't have
their own
> + * subclassed CRTC state structure.
> + */
> +struct drm_crtc_state *
> +drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc)
> +{
> +	struct drm_crtc_state *state;
> +
> +	if (WARN_ON(!crtc->state))
> +		return NULL;
> +
> +	state = kmemdup(crtc->state, sizeof(*crtc->state), GFP_KERNEL);
> +
> +	if (state) {
> +		state->mode_changed = false;
> +		state->planes_changed = false;
> +		state->event = NULL;
> +	}
> +
> +	return state;
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
> +
> +/**
> + * drm_atomic_helper_crtc_destroy_state - default state destroy hook
> + * @crtc: drm CRTC
> + * @state: CRTC state object to release
> + *
> + * Default CRTC state destroy hook for drivers which don't have their own
> + * subclassed CRTC state structure.
> + */
> +void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
> +					  struct drm_crtc_state *state)
> +{
> +	kfree(state);
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
> +
> +/**
> + * drm_atomic_helper_plane_reset - default ->reset hook for planes
> + * @plane: drm plane
> + *
> + * Resets the atomic state for @plane by freeing the state pointer and
> + * allocating a new empty state object.
> + */
> +void drm_atomic_helper_plane_reset(struct drm_plane *plane)
> +{
> +	kfree(plane->state);
> +	plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);

+1


> +}
> +EXPORT_SYMBOL(drm_atomic_helper_plane_reset);
> +
> +/**
> + * drm_atomic_helper_plane_duplicate_state - default state duplicate hook
> + * @plane: drm plane
> + *
> + * Default plane state duplicate hook for drivers which don't have
their own
> + * subclassed plane state structure.
> + */
> +struct drm_plane_state *
> +drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane)
> +{
> +	if (WARN_ON(!plane->state))
> +		return NULL;
> +
> +	return kmemdup(plane->state, sizeof(*plane->state), GFP_KERNEL);
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state);
> +
> +/**
> + * drm_atomic_helper_plane_destroy_state - default state destroy hook
> + * @plane: drm plane
> + * @state: plane state object to release
> + *
> + * Default plane state destroy hook for drivers which don't have
their own
> + * subclassed plane state structure.
> + */
> +void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
> +					  struct drm_plane_state *state)
> +{
> +	kfree(state);
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state);
> +
> +/**
> + * drm_atomic_helper_connector_reset - default ->reset hook for
connectors
> + * @connector: drm connector
> + *
> + * Resets the atomic state for @connector by freeing the state
pointer and
> + * allocating a new empty state object.
> + */
> +void drm_atomic_helper_connector_reset(struct drm_connector *connector)
> +{
> +	kfree(connector->state);
> +	connector->state = kzalloc(sizeof(*connector->state), GFP_KERNEL);

+1


> +}
> +EXPORT_SYMBOL(drm_atomic_helper_connector_reset);
> +
> +/**
> + * drm_atomic_helper_connector_duplicate_state - default state
duplicate hook
> + * @connector: drm connector
> + *
> + * Default connector state duplicate hook for drivers which don't
have their own
> + * subclassed connector state structure.
> + */
> +struct drm_connector_state *
> +drm_atomic_helper_connector_duplicate_state(struct drm_connector
*connector)
> +{
> +	if (WARN_ON(!connector->state))
> +		return NULL;
> +
> +	return kmemdup(connector->state, sizeof(*connector->state), GFP_KERNEL);
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
> +
> +/**
> + * drm_atomic_helper_connector_destroy_state - default state destroy hook
> + * @connector: drm connector
> + * @state: connector state object to release
> + *
> + * Default connector state destroy hook for drivers which don't have
their own
> + * subclassed connector state structure.
> + */
> +void drm_atomic_helper_connector_destroy_state(struct drm_connector
*connector,
> +					  struct drm_connector_state *state)
> +{
> +	kfree(state);
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);
> diff --git a/include/drm/drm_atomic_helper.h
b/include/drm/drm_atomic_helper.h
> index 28a2f3a815fd..67e3c4645ae0 100644
> --- a/include/drm/drm_atomic_helper.h
> +++ b/include/drm/drm_atomic_helper.h
> @@ -74,5 +74,24 @@ int drm_atomic_helper_page_flip(struct drm_crtc *crtc,
>  				struct drm_pending_vblank_event *event,
>  				uint32_t flags);
>
> +/* default implementations for state handling */
> +void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc);
> +struct drm_crtc_state *
> +drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc);
> +void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
> +					  struct drm_crtc_state *state);
> +
> +void drm_atomic_helper_plane_reset(struct drm_plane *plane);
> +struct drm_plane_state *
> +drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane);
> +void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
> +					  struct drm_plane_state *state);
> +
> +void drm_atomic_helper_connector_reset(struct drm_connector *connector);
> +struct drm_connector_state *
> +drm_atomic_helper_connector_duplicate_state(struct drm_connector
*connector);
> +void drm_atomic_helper_connector_destroy_state(struct drm_connector
*connector,
> +					  struct drm_connector_state *state);
> +
>
>  #endif /* DRM_ATOMIC_HELPER_H_ */
>


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2014-11-03 14:45 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-02 13:19 [PATCH 00/17] atomic modeset core<->driver interfaces and helpers Daniel Vetter
2014-11-02 13:19 ` [PATCH 01/17] drm: Move drm_crtc_init from drm_crtc.h to drm_plane_helper.h Daniel Vetter
2014-11-04 20:31   ` Sean Paul
2014-11-02 13:19 ` [PATCH 02/17] drm: Pull drm_crtc.h into the kerneldoc template Daniel Vetter
2014-11-02 19:18   ` [PATCH] " Daniel Vetter
2014-11-03  3:04     ` Thierry Reding
2014-11-02 13:19 ` [PATCH 03/17] drm: fixup kerneldoc in drm_crtc.h Daniel Vetter
2014-11-02 19:19   ` Daniel Vetter
2014-11-02 13:19 ` [PATCH 04/17] drm/modeset_lock: document trylock_only in kerneldoc Daniel Vetter
2014-11-04 20:31   ` Sean Paul
2014-11-05 16:18   ` Thierry Reding
2014-11-02 13:19 ` [PATCH 05/17] drm: Add atomic driver interface definitions for objects Daniel Vetter
2014-11-04 20:31   ` Sean Paul
2014-11-05 16:26   ` Thierry Reding
2014-11-05 17:04     ` Daniel Vetter
2014-11-05 17:16       ` [Intel-gfx] " Damien Lespiau
2014-11-02 13:19 ` [PATCH 06/17] drm: Global atomic state handling Daniel Vetter
2014-11-03 23:41   ` Matt Roper
2014-11-04  8:40     ` Daniel Vetter
2014-11-04 20:31   ` Sean Paul
2014-11-04 21:30     ` Daniel Vetter
2014-11-04 21:41       ` Daniel Vetter
2014-11-04 21:37   ` [PATCH] " Daniel Vetter
2014-11-04 22:07     ` Daniel Vetter
2014-11-04 22:32       ` Sean Paul
2014-11-05 13:06       ` Ander Conselvan de Oliveira
2014-11-05 13:45       ` Daniel Vetter
2014-11-05 14:22         ` Daniel Vetter
2014-11-05 17:06           ` Daniel Vetter
2015-02-06  9:58             ` [Intel-gfx] " Jani Nikula
2015-02-06 21:14               ` Daniel Vetter
2014-11-02 13:19 ` [PATCH 07/17] drm: Add atomic/plane helpers Daniel Vetter
2014-11-04 22:30   ` Sean Paul
2014-11-04 23:16     ` Daniel Vetter
2014-11-02 13:19 ` [PATCH 08/17] drm/plane-helper: transitional atomic plane helpers Daniel Vetter
2014-11-05 16:45   ` Sean Paul
2014-11-05 16:51     ` Daniel Vetter
2014-11-05 16:59   ` [PATCH] " Daniel Vetter
2014-11-02 13:19 ` [PATCH 09/17] drm/crtc-helper: Transitional functions using " Daniel Vetter
2014-11-05 17:42   ` Sean Paul
2014-11-02 13:19 ` [PATCH 10/17] drm: Atomic crtc/connector updates using crtc/plane helper interfaces Daniel Vetter
2014-11-05 18:53   ` Sean Paul
2014-11-05 21:44     ` Daniel Vetter
2014-11-06 18:28       ` Sean Paul
2014-11-02 13:19 ` [PATCH 11/17] drm/atomic-helper: implementatations for legacy interfaces Daniel Vetter
2014-11-04 22:08   ` [PATCH] " Daniel Vetter
2014-11-05 13:46     ` Daniel Vetter
2014-11-05 19:48       ` Sean Paul
2014-11-05 22:01         ` Daniel Vetter
2014-11-06 18:31           ` Sean Paul
2014-11-02 13:19 ` [PATCH 12/17] drm/atomic: Integrate fence support Daniel Vetter
2014-11-06 17:43   ` [Intel-gfx] " Sean Paul
2014-11-02 13:19 ` [PATCH 13/17] drm/atomic-helpers: document how to implement async commit Daniel Vetter
2014-11-06 17:43   ` Sean Paul
2014-11-02 13:19 ` [PATCH 14/17] drm/atomic-helper: implement ->page_flip Daniel Vetter
2014-11-04 22:09   ` [PATCH] " Daniel Vetter
2014-11-05 11:35     ` Daniel Thompson
2014-11-05 13:46     ` Daniel Vetter
2014-11-06 17:43   ` [PATCH 14/17] " Sean Paul
2014-11-06 18:13     ` Daniel Vetter
2014-11-06 18:53       ` Sean Paul
2014-11-02 13:19 ` [PATCH 15/17] drm/atomic-helpers: functions for state duplicate/destroy/reset Daniel Vetter
2014-11-03 14:45   ` Daniel Thompson [this message]
2014-11-03 14:53     ` Daniel Vetter
2014-11-03 15:06       ` Daniel Thompson
2014-11-03 15:11         ` Daniel Vetter
2014-11-06 17:43   ` Sean Paul
2014-11-06 19:57     ` Daniel Vetter
2014-11-06 20:01       ` Sean Paul
2014-11-06 19:55   ` [PATCH] " Daniel Vetter
2014-11-02 13:19 ` [PATCH 16/17] drm: Docbook integration and over sections for all the new helpers Daniel Vetter
2014-11-06 17:43   ` Sean Paul
2014-11-06 20:00   ` [PATCH] " Daniel Vetter
2014-11-06 20:02     ` Sean Paul
2014-11-02 13:19 ` [PATCH 17/17] drm/atomic: Refcounting for plane_state->fb Daniel Vetter
2014-11-04 21:57   ` [PATCH] " Daniel Vetter
2014-11-06 17:44   ` [PATCH 17/17] " Sean Paul

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=54579508.1030404@linaro.org \
    --to=daniel.thompson@linaro.org \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    /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