All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Paul <seanpaul@chromium.org>
To: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Daniel Vetter <daniel.vetter@intel.com>,
	Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
	DRI Development <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 08/13] drm: prevent double-(un)registration for connectors
Date: Fri, 16 Dec 2016 10:03:26 -0500	[thread overview]
Message-ID: <CAOw6vbKv3JkQ=K2S6f-z_uH-G+hT_VLG2MAdBdRkqDLfwrKG9w@mail.gmail.com> (raw)
In-Reply-To: <20161213230814.19598-9-daniel.vetter@ffwll.ch>

On Tue, Dec 13, 2016 at 6:08 PM, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> If we're unlucky then the registration from a hotplugged connector
> might race with the final registration step on driver load. And since
> MST topology discover is asynchronous that's even somewhat likely.
>
> v2: Also update the kerneldoc for @registered!
>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Reported-by: Chris Wilson <chris@chris-wilson.co.uk>


With Chris' suggested improvements

Reviewed-by: Sean Paul <seanpaul@chromium.org>

> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
>  drivers/gpu/drm/drm_connector.c | 18 +++++++++++++-----
>  include/drm/drm_connector.h     | 12 +++++++++++-
>  2 files changed, 24 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
> index b33334e09b00..0d4728704099 100644
> --- a/drivers/gpu/drm/drm_connector.c
> +++ b/drivers/gpu/drm/drm_connector.c
> @@ -223,6 +223,7 @@ int drm_connector_init(struct drm_device *dev,
>
>         INIT_LIST_HEAD(&connector->probed_modes);
>         INIT_LIST_HEAD(&connector->modes);
> +       mutex_init(&connector->mutex);
>         connector->edid_blob_ptr = NULL;
>         connector->status = connector_status_unknown;
>
> @@ -373,14 +374,15 @@ EXPORT_SYMBOL(drm_connector_cleanup);
>   */
>  int drm_connector_register(struct drm_connector *connector)
>  {
> -       int ret;
> +       int ret = 0;
>
> +       mutex_lock(&connector->mutex);
>         if (connector->registered)
> -               return 0;
> +               goto unlock;
>
>         ret = drm_sysfs_connector_add(connector);
>         if (ret)
> -               return ret;
> +               goto unlock;
>
>         ret = drm_debugfs_connector_add(connector);
>         if (ret) {
> @@ -396,12 +398,14 @@ int drm_connector_register(struct drm_connector *connector)
>         drm_mode_object_register(connector->dev, &connector->base);
>
>         connector->registered = true;
> -       return 0;
> +       goto unlock;
>
>  err_debugfs:
>         drm_debugfs_connector_remove(connector);
>  err_sysfs:
>         drm_sysfs_connector_remove(connector);
> +unlock:
> +       mutex_unlock(&connector->mutex);
>         return ret;
>  }
>  EXPORT_SYMBOL(drm_connector_register);
> @@ -414,8 +418,11 @@ EXPORT_SYMBOL(drm_connector_register);
>   */
>  void drm_connector_unregister(struct drm_connector *connector)
>  {
> -       if (!connector->registered)
> +       mutex_lock(&connector->mutex);
> +       if (!connector->registered) {
> +               mutex_unlock(&connector->mutex);
>                 return;
> +       }
>
>         if (connector->funcs->early_unregister)
>                 connector->funcs->early_unregister(connector);
> @@ -424,6 +431,7 @@ void drm_connector_unregister(struct drm_connector *connector)
>         drm_debugfs_connector_remove(connector);
>
>         connector->registered = false;
> +       mutex_unlock(&connector->mutex);
>  }
>  EXPORT_SYMBOL(drm_connector_unregister);
>
> diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
> index 0e41a2e184a9..a24559ef8bb7 100644
> --- a/include/drm/drm_connector.h
> +++ b/include/drm/drm_connector.h
> @@ -559,7 +559,6 @@ struct drm_cmdline_mode {
>   * @interlace_allowed: can this connector handle interlaced modes?
>   * @doublescan_allowed: can this connector handle doublescan?
>   * @stereo_allowed: can this connector handle stereo modes?
> - * @registered: is this connector exposed (registered) with userspace?
>   * @modes: modes available on this connector (from fill_modes() + user)
>   * @status: one of the drm_connector_status enums (connected, not, or unknown)
>   * @probed_modes: list of modes derived directly from the display
> @@ -608,6 +607,13 @@ struct drm_connector {
>         char *name;
>
>         /**
> +        * @mutex: Lock for general connector state, but currently only protects
> +        * @registered. Most of the connector state is still protected by the
> +        * mutex in &drm_mode_config.
> +        */
> +       struct mutex mutex;
> +
> +       /**
>          * @index: Compacted connector index, which matches the position inside
>          * the mode_config.list for drivers not supporting hot-add/removing. Can
>          * be used as an array index. It is invariant over the lifetime of the
> @@ -620,6 +626,10 @@ struct drm_connector {
>         bool interlace_allowed;
>         bool doublescan_allowed;
>         bool stereo_allowed;
> +       /**
> +        * @registered: Is this connector exposed (registered) with userspace?
> +        * Protected by @mutex.
> +        */
>         bool registered;
>         struct list_head modes; /* list of modes on this connector */
>
> --
> 2.11.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel



-- 
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2016-12-16 15:03 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-13 23:08 [PATCH 00/13] some stuff, and then connector_list locking Daniel Vetter
2016-12-13 23:08 ` [PATCH 01/13] drm/irq: drm_legacy_ prefix for legacy ioctls Daniel Vetter
2016-12-16 15:02   ` Sean Paul
2016-12-13 23:08 ` [PATCH 02/13] drm: Move atomic debugfs functions into drm_crtc_internal.h Daniel Vetter
2016-12-16 15:02   ` Sean Paul
2016-12-13 23:08 ` [PATCH 03/13] drm/radeon|amdgpu: Remove redundant num_connectors check Daniel Vetter
2016-12-14 16:59   ` Alex Deucher
2016-12-13 23:08 ` [PATCH 04/13] drm: Drop locking cargo-cult from drm_mode_config_init Daniel Vetter
2016-12-14  9:23   ` [Intel-gfx] " Daniel Stone
2016-12-16 15:03   ` Sean Paul
2016-12-13 23:08 ` [PATCH 05/13] drm: locking&new iterators for connector_list Daniel Vetter
2016-12-14  8:35   ` Chris Wilson
2016-12-14 11:22   ` Jani Nikula
2016-12-14 12:26     ` Daniel Vetter
2016-12-14 15:04       ` [Intel-gfx] " Jani Nikula
2016-12-16 15:03   ` Sean Paul
2016-12-13 23:08 ` [PATCH 06/13] drm: Convert all helpers to drm_connector_list_iter Daniel Vetter
2016-12-15 14:34   ` Harry Wentland
2016-12-15 15:58   ` [PATCH] " Daniel Vetter
2016-12-15 16:32     ` Harry Wentland
2016-12-15 22:47     ` kbuild test robot
2016-12-15 22:59     ` kbuild test robot
2016-12-16  7:29       ` Daniel Vetter
2016-12-16  7:41         ` [kbuild-all] " Fengguang Wu
2016-12-18 18:04           ` Ye Xiaolong
2016-12-16 15:03     ` Sean Paul
2016-12-13 23:08 ` [PATCH 07/13] drm: Clean up connectors by unreferencing them Daniel Vetter
2016-12-15 15:45   ` Harry Wentland
2016-12-16 15:03   ` Sean Paul
2016-12-13 23:08 ` [PATCH 08/13] drm: prevent double-(un)registration for connectors Daniel Vetter
2016-12-13 23:52   ` Chris Wilson
2016-12-16 15:03   ` Sean Paul [this message]
2016-12-13 23:08 ` [PATCH 09/13] drm: Tighten locking in drm_mode_getconnector Daniel Vetter
2016-12-16 15:03   ` Sean Paul
2016-12-18 13:40     ` Daniel Vetter
2016-12-13 23:08 ` [PATCH 10/13] drm/i915: Use drm_connector_list_iter in debugfs Daniel Vetter
2016-12-14 14:44   ` Jani Nikula
2016-12-14 14:51     ` [Intel-gfx] " Daniel Vetter
2016-12-13 23:08 ` [PATCH 11/13] drm/i915: use drm_connector_list_iter in intel_hotplug.c Daniel Vetter
2016-12-13 23:08 ` [PATCH 12/13] drm/i915: use drm_connector_list_iter in intel_opregion.c Daniel Vetter
2016-12-13 23:08 ` [PATCH 13/13] drm/i915: Make intel_get_pipe_from_connector atomic Daniel Vetter

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='CAOw6vbKv3JkQ=K2S6f-z_uH-G+hT_VLG2MAdBdRkqDLfwrKG9w@mail.gmail.com' \
    --to=seanpaul@chromium.org \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.