Re: [Intel-gfx] [PATCH] drm/kms: Catch mode_object lifetime errors

2019-08-20 Thread Daniel Vetter
On Tue, Aug 20, 2019 at 11:28 AM Jani Nikula  wrote:
>
> On Tue, 20 Aug 2019, Daniel Vetter  wrote:
> > On Sat, Aug 17, 2019 at 12:42 AM Souza, Jose  wrote:
> >> On Sat, 2019-06-29 at 17:39 +0200, Daniel Vetter wrote:
> >> > On Fri, Jun 28, 2019 at 7:24 PM Sean Paul  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 
> >> > > > ---
> >> > > >  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.
> >
> > Uh yeah this is bad. I guess we need to preemptively create all
> > possible bpc properties, so that we can only do an attach. Those
> > really can't be hotplugged.
>
> Should we plan to make all objects dynamic and refcounted in the long
> run? It's kind of silly that we've made connectors dynamic yet can't
> dynamically allocate properties for them. (Except blob properties which
> are special dynamic snowflakes.)

Need to make sure userspace is ok with that. Plus given that it took
us years to make drm_connector refcounting not be a pure fireworks
show (and Lyude is still busy) I'm not too enthusiastic about this.

Also even with the objects which have been dynamic since forever (edid
blobs) userspace mixed things up since we reuse ids. It's a mess.

> > We might also want to revert
> >
> > commit 5ca0ef8a56b8c4812ed78ef9ca53052191dab6e7
> > Author: Ville Syrjälä 
> > Date:   Tue Mar 26 16:25:54 2019 +0200
> >
> > drm/i915: Add max_bpc property for DP MST
> >
> > as an interim solution. Adding Ville and Jani.
>
> I think we'll want the fixed, pre-created DP MST max BPC property,
> shoved in dev_priv, as an interim solution before we have everything
> dynamic. This shouldn't really be more than 50-100 

Re: [Intel-gfx] [PATCH] drm/kms: Catch mode_object lifetime errors

2019-08-20 Thread Jani Nikula
On Tue, 20 Aug 2019, Daniel Vetter  wrote:
> On Sat, Aug 17, 2019 at 12:42 AM Souza, Jose  wrote:
>> On Sat, 2019-06-29 at 17:39 +0200, Daniel Vetter wrote:
>> > On Fri, Jun 28, 2019 at 7:24 PM Sean Paul  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 
>> > > > ---
>> > > >  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.
>
> Uh yeah this is bad. I guess we need to preemptively create all
> possible bpc properties, so that we can only do an attach. Those
> really can't be hotplugged.

Should we plan to make all objects dynamic and refcounted in the long
run? It's kind of silly that we've made connectors dynamic yet can't
dynamically allocate properties for them. (Except blob properties which
are special dynamic snowflakes.)

> We might also want to revert
>
> commit 5ca0ef8a56b8c4812ed78ef9ca53052191dab6e7
> Author: Ville Syrjälä 
> Date:   Tue Mar 26 16:25:54 2019 +0200
>
> drm/i915: Add max_bpc property for DP MST
>
> as an interim solution. Adding Ville and Jani.

I think we'll want the fixed, pre-created DP MST max BPC property,
shoved in dev_priv, as an interim solution before we have everything
dynamic. This shouldn't really be more than 50-100 lines, especially
given that we'll only need the 6-12 BPC range for MST connectors, and
the rest can use the usual methods.

Whether we need the revert as an interim solution before the interim
solution, I'll leave it up to Ville. How quick do you think you'd get to
fixing this?

Other than that, ugh. Just ugh.

BR,
Jani.


> -Daniel
>
>> > >
>> > > 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 

Re: [Intel-gfx] [PATCH] drm/kms: Catch mode_object lifetime errors

2019-08-20 Thread Daniel Vetter
On Sat, Aug 17, 2019 at 12:42 AM Souza, Jose  wrote:
> On Sat, 2019-06-29 at 17:39 +0200, Daniel Vetter wrote:
> > On Fri, Jun 28, 2019 at 7:24 PM Sean Paul  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 
> > > > ---
> > > >  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.

Uh yeah this is bad. I guess we need to preemptively create all
possible bpc properties, so that we can only do an attach. Those
really can't be hotplugged.

We might also want to revert

commit 5ca0ef8a56b8c4812ed78ef9ca53052191dab6e7
Author: Ville Syrjälä 
Date:   Tue Mar 26 16:25:54 2019 +0200

drm/i915: Add max_bpc property for DP MST

as an interim solution. Adding Ville and Jani.
-Daniel

> > >
> > > 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 
> > >
> > >
> > > > +
> > > >   mutex_lock(>mode_config.idr_mutex);
> > > >   ret = idr_alloc(>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(>mode_config.idr_mutex);
> > > >   if (object->id) {
> > > >   idr_remove(>mode_config.object_idr, object-
> > > > 

Re: [Intel-gfx] [PATCH] drm/kms: Catch mode_object lifetime errors

2019-08-16 Thread Souza, Jose
On Sat, 2019-06-29 at 17:39 +0200, Daniel Vetter wrote:
> On Fri, Jun 28, 2019 at 7:24 PM Sean Paul  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 
> > > ---
> > >  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 
> > 
> > 
> > > +
> > >   mutex_lock(>mode_config.idr_mutex);
> > >   ret = idr_alloc(>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(>mode_config.idr_mutex);
> > >   if (object->id) {
> > >   idr_remove(>mode_config.object_idr, object-
> > > >id);
> > > --
> > > 2.20.1
> > > 
> > > ___
> > > dri-devel mailing list
> > > dri-de...@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

Re: [Intel-gfx] [PATCH] drm/kms: Catch mode_object lifetime errors

2019-06-29 Thread Daniel Vetter
On Fri, Jun 28, 2019 at 7:24 PM Sean Paul  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 
> > ---
> >  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);
>
> 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 
>
>
> > +
> >   mutex_lock(>mode_config.idr_mutex);
> >   ret = idr_alloc(>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(>mode_config.idr_mutex);
> >   if (object->id) {
> >   idr_remove(>mode_config.object_idr, object->id);
> > --
> > 2.20.1
> >
> > ___
> > dri-devel mailing list
> > dri-de...@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
>
> --
> Sean Paul, Software Engineer, Google / Chromium OS



-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [PATCH] drm/kms: Catch mode_object lifetime errors

2019-06-28 Thread Sean Paul
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?

> Signed-off-by: Daniel Vetter 
> ---
>  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);

These should probably have a comment above them giving some guidance to the
driver developer.

With some comments, this is:

Reviewed-by: Sean Paul 


> +
>   mutex_lock(>mode_config.idr_mutex);
>   ret = idr_alloc(>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(>mode_config.idr_mutex);
>   if (object->id) {
>   idr_remove(>mode_config.object_idr, object->id);
> -- 
> 2.20.1
> 
> ___
> dri-devel mailing list
> dri-de...@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