From: "Souza, Jose" <jose.souza@intel.com>
To: "daniel.vetter@ffwll.ch" <daniel.vetter@ffwll.ch>,
"sean@poorly.run" <sean@poorly.run>
Cc: "Vetter, Daniel" <daniel.vetter@intel.com>,
"intel-gfx@lists.freedesktop.org"
<intel-gfx@lists.freedesktop.org>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH] drm/kms: Catch mode_object lifetime errors
Date: Fri, 16 Aug 2019 22:42:50 +0000 [thread overview]
Message-ID: <ba059a111a630e06ad79ce49e08830078bb91edd.camel@intel.com> (raw)
In-Reply-To: <CAKMK7uEhXK1JNfF95-aNAj4ph8Vk8B6wynJE=BCEpfJQZRbpdg@mail.gmail.com>
On Sat, 2019-06-29 at 17:39 +0200, Daniel Vetter wrote:
> On Fri, Jun 28, 2019 at 7:24 PM Sean Paul <sean@poorly.run> wrote:
> > On Fri, Jun 14, 2019 at 08:17:23AM +0200, Daniel Vetter wrote:
> > > Only dynamic mode objects, i.e. those which are refcounted and
> > > have a free
> > > callback, can be added while the overall drm_device is visible to
> > > userspace. All others must be added before drm_dev_register and
> > > removed after drm_dev_unregister.
> > >
> > > Small issue around drivers still using the load/unload callbacks,
> > > we
> > > need to make sure we set dev->registered so that load/unload code
> > > in
> > > these callbacks doesn't trigger false warnings. Only a small
> > > adjustement in drm_dev_register was needed.
> > >
> > > Motivated by some irc discussions about object ids of dynamic
> > > objects
> > > like blobs become invalid, and me going on a bit an audit spree.
> > >
> >
> > Seems like a very worthwhile change, any idea how many drivers are
> > going
> > to be sad after this change?
>
> None I think/hope, really just defense WARN_ON just in case. The main
> ones that would be sad are all the ones that have a ->load callback,
> but I'm taking care of them. Everyone else does things correctly and
> calls drm_dev_register last in their probe function (or around where
> they set up fbdev, which is also register the driver at least to the
> fbdev world, so really the same).
>
> > > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > > ---
> > > drivers/gpu/drm/drm_drv.c | 4 ++--
> > > drivers/gpu/drm/drm_mode_object.c | 4 ++++
> > > 2 files changed, 6 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/drm_drv.c
> > > b/drivers/gpu/drm/drm_drv.c
> > > index cb6f0245de7c..48c84e3e1931 100644
> > > --- a/drivers/gpu/drm/drm_drv.c
> > > +++ b/drivers/gpu/drm/drm_drv.c
> > > @@ -997,14 +997,14 @@ int drm_dev_register(struct drm_device
> > > *dev, unsigned long flags)
> > > if (ret)
> > > goto err_minors;
> > >
> > > - dev->registered = true;
> > > -
> > > if (dev->driver->load) {
> > > ret = dev->driver->load(dev, flags);
> > > if (ret)
> > > goto err_minors;
> > > }
> > >
> > > + dev->registered = true;
> > > +
> > > if (drm_core_check_feature(dev, DRIVER_MODESET))
> > > drm_modeset_register_all(dev);
> > >
> > > diff --git a/drivers/gpu/drm/drm_mode_object.c
> > > b/drivers/gpu/drm/drm_mode_object.c
> > > index 1c6e51135962..c355ba8e6d5d 100644
> > > --- a/drivers/gpu/drm/drm_mode_object.c
> > > +++ b/drivers/gpu/drm/drm_mode_object.c
> > > @@ -42,6 +42,8 @@ int __drm_mode_object_add(struct drm_device
> > > *dev, struct drm_mode_object *obj,
> > > {
> > > int ret;
> > >
> > > + WARN_ON(dev->registered && !obj_free_cb);
Getting warnings on i915 with MST, we add fake MST connectors when a
sink with MST support is connected;
intel_dp_add_mst_connector()->drm_connector_attach_max_bpc_property()
Not sure how to fix that, add a global i915 device property like we do
for "audio" and "Broadcast RGB" don't look the right approach here.
Any tips?
We definitely need a platform with a MST sink on our CI.
> >
> > These should probably have a comment above them giving some
> > guidance to the
> > driver developer.
> >
> > With some comments, this is:
>
> What comment do you expect here? drm_dev_register explains what you
> should do already, and I expect driver developers to find that one
> pretty quickly. From there: "This should be done last in the device
> initialization sequence to make sure userspace can't access an
> inconsistent state."
> -Daniel
>
> > Reviewed-by: Sean Paul <sean@poorly.run>
> >
> >
> > > +
> > > mutex_lock(&dev->mode_config.idr_mutex);
> > > ret = idr_alloc(&dev->mode_config.object_idr, register_obj
> > > ? obj : NULL,
> > > 1, 0, GFP_KERNEL);
> > > @@ -102,6 +104,8 @@ void drm_mode_object_register(struct
> > > drm_device *dev,
> > > void drm_mode_object_unregister(struct drm_device *dev,
> > > struct drm_mode_object *object)
> > > {
> > > + WARN_ON(dev->registered && !object->free_cb);
> > > +
> > > mutex_lock(&dev->mode_config.idr_mutex);
> > > if (object->id) {
> > > idr_remove(&dev->mode_config.object_idr, object-
> > > >id);
> > > --
> > > 2.20.1
> > >
> > > _______________________________________________
> > > dri-devel mailing list
> > > dri-devel@lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> >
> > --
> > Sean Paul, Software Engineer, Google / Chromium OS
>
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2019-08-16 22:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-14 6:17 [PATCH] drm/kms: Catch mode_object lifetime errors Daniel Vetter
2019-06-14 6:28 ` ✗ Fi.CI.CHECKPATCH: warning for " Patchwork
2019-06-14 18:14 ` ✓ Fi.CI.BAT: success " Patchwork
2019-06-15 11:12 ` ✓ Fi.CI.IGT: " Patchwork
2019-06-28 17:24 ` [PATCH] " Sean Paul
2019-06-29 15:39 ` Daniel Vetter
2019-08-16 22:42 ` Souza, Jose [this message]
2019-08-20 7:53 ` Daniel Vetter
2019-08-20 9:28 ` Jani Nikula
2019-08-20 9:40 ` 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=ba059a111a630e06ad79ce49e08830078bb91edd.camel@intel.com \
--to=jose.souza@intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=daniel.vetter@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=sean@poorly.run \
/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