diff mbox series

drm/kms: Catch mode_object lifetime errors

Message ID 20190614061723.1173-1-daniel.vetter@ffwll.ch (mailing list archive)
State New, archived
Headers show
Series drm/kms: Catch mode_object lifetime errors | expand

Commit Message

Daniel Vetter June 14, 2019, 6:17 a.m. UTC
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.

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(-)

Comments

Sean Paul June 28, 2019, 5:24 p.m. UTC | #1
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 <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);

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

With some comments, this is:

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
Daniel Vetter June 29, 2019, 3:39 p.m. UTC | #2
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);
>
> 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
Souza, Jose Aug. 16, 2019, 10:42 p.m. UTC | #3
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
> 
>
Daniel Vetter Aug. 20, 2019, 7:53 a.m. UTC | #4
On Sat, Aug 17, 2019 at 12:42 AM Souza, Jose <jose.souza@intel.com> wrote:
> 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.

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ä <ville.syrjala@linux.intel.com>
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 <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
> >
> >
Jani Nikula Aug. 20, 2019, 9:28 a.m. UTC | #5
On Tue, 20 Aug 2019, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> On Sat, Aug 17, 2019 at 12:42 AM Souza, Jose <jose.souza@intel.com> wrote:
>> 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.
>
> 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ä <ville.syrjala@linux.intel.com>
> 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 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
>> >
>> >
Daniel Vetter Aug. 20, 2019, 9:40 a.m. UTC | #6
On Tue, Aug 20, 2019 at 11:28 AM Jani Nikula <jani.nikula@intel.com> wrote:
>
> On Tue, 20 Aug 2019, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> > On Sat, Aug 17, 2019 at 12:42 AM Souza, Jose <jose.souza@intel.com> wrote:
> >> 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.
> >
> > 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ä <ville.syrjala@linux.intel.com>
> > 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.

Agreed on that :-/
-Daniel

>
> 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 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
> >> >
> >> >
>
> --
> Jani Nikula, Intel Open Source Graphics Center
diff mbox series

Patch

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);
+
 	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);