drm/sysfs: fix hotplug regression since lifetime changes
Subsystems (2)
Dave Airlie
maintainerPATCH 1/1 drm/sysfs: fix hotplug regression since lifetime changes
5bdebb183c9702a8c57a01dff09337be3de337a6 changed the lifetimes, but it also meant we no longer set the device_type field properly, so the hotplug events in userspace weren't fully formed enough for drivers to care.
--- drivers/gpu/drm/drm_sysfs.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_sysfs.c +1 -0
@@ -516,6 +516,7 @@ int drm_sysfs_device_add(struct drm_minor *minor)DRM_ERROR ("device create failed %ld\n" ,PTR_ERR (minor->kdev));return PTR_ERR (minor->kdev); } + minor->kdev->type = &drm_sysfs_device_minor;return 0 ; }
Signature · 1 line
1.8.4.2
Quoted 15 lines · Dave Airlie
5bdebb183c9702a8c57a01dff09337be3de337a6changed the lifetimes, but it also meant we no longer set thedevice_typefield properly, so the hotplug events in userspace weren't fully formed enough for drivers to care.Reported-by Jesse Barnes <[email protected]>Signed-off-by Dave Airlie <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/drm_sysfs.c +0
-0
drivers/gpu/drm/drm_sysfs.c int drm_sysfs_device_add(struct drm_minor *minor) · line 519
Quoted 4 lines
drivers/gpu/drm/drm_sysfs.c +1
-0@@ -516,6 +516,7 @@ int drm_sysfs_device_add(struct drm_minor *minor)DRM_ERROR ("device create failed %ld\n" ,PTR_ERR (minor->kdev));return PTR_ERR (minor->kdev); } + minor->kdev->type = &drm_sysfs_device_minor;
Isn't this one of the sysfs races Greg is fighting against? At least from a cursor read through the driver core it looks like we'd better set the dev->type before we set it up with device_create().
Cc'ing Greg for insight.
Aside: I wonder whether we could get rid of our drm_minor type and use it for something more useful like the render node vs legacy node split ... -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Dave Airlie
maintainerQuoted 11 lines · Daniel Vetter
Quoted 10 lines · Dave Airlie
5bdebb183c9702a8c57a01dff09337be3de337a6changed the lifetimes, but it also meant we no longer set thedevice_typefield properly, so the hotplug events in userspace weren't fully formed enough for drivers to care.Reported-by Jesse Barnes <[email protected]>Signed-off-by Dave Airlie <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 1 + 1 file changed, 1 insertion(+)
Quoted 13 lines
drivers/gpu/drm/drm_sysfs.c int drm_sysfs_device_add(struct drm_minor *minor) · line 519
Quoted 9 lines
drivers/gpu/drm/drm_sysfs.c +1
-0@@ -516,6 +516,7 @@ int drm_sysfs_device_add(struct drm_minor *minor)DRM_ERROR ("device create failed %ld\n" ,PTR_ERR (minor->kdev));return PTR_ERR (minor->kdev); } + minor->kdev->type = &drm_sysfs_device_minor;Isn't this one of the sysfs races Greg is fighting against? At least from a cursor read through the driver core it looks like we'd better set the
dev->typebefore we set it up withdevice_create().
Possibly but how can we do that? since minor->kdev is something we just created 2 lines earlier
unless there is another create function I should be calling, I don't see a device_create_with_type.
Quoted 5 lines
Cc'ing Greg for insight.
Aside: I wonder whether we could get rid of our
drm_minortype and use it for something more useful like the render node vs legacy node split ...
Its ABI now. all the userspace drivers need it in the uevents for hotplug to keep working.
Dave.
Hi
Quoted 26 lines · Dave Airlie
Quoted 11 lines · Daniel Vetter
Quoted 10 lines · Dave Airlie
5bdebb183c9702a8c57a01dff09337be3de337a6changed the lifetimes, but it also meant we no longer set thedevice_typefield properly, so the hotplug events in userspace weren't fully formed enough for drivers to care.Reported-by Jesse Barnes <[email protected]>Signed-off-by Dave Airlie <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 1 + 1 file changed, 1 insertion(+)Quoted 13 lines
drivers/gpu/drm/drm_sysfs.c int drm_sysfs_device_add(struct drm_minor *minor) · line 519
Quoted 9 lines
drivers/gpu/drm/drm_sysfs.c +1
-0@@ -516,6 +516,7 @@ int drm_sysfs_device_add(struct drm_minor *minor)DRM_ERROR ("device create failed %ld\n" ,PTR_ERR (minor->kdev));return PTR_ERR (minor->kdev); } + minor->kdev->type = &drm_sysfs_device_minor;Isn't this one of the sysfs races Greg is fighting against? At least from a cursor read through the driver core it looks like we'd better set the
dev->typebefore we set it up withdevice_create().
Quoted 4 lines
Possibly but how can we do that? since
minor->kdevis something we just created 2 lines earlier
unless there is another create function I should be calling, I don't see adevice_create_with_type.
See device_create_groups_vargs() in drivers/base/core.c. Just copy the code from it and do device initialization yourself. device_create() is only a wrapper around kzalloc()+device_register() anyway.
Thanks
David
Quoted 13 lines
Quoted 4 lines
Cc'ing Greg for insight.
Aside: I wonder whether we could get rid of our
drm_minortype and use it for something more useful like the render node vs legacy node split ...Its ABI now. all the userspace drivers need it in the uevents for hotplug to keep working.
Dave.
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Dave Airlie
maintainerQuoted 29 lines · David Herrmann
Hi
Quoted 26 lines · Dave Airlie
Quoted 24 lines · Daniel Vetter
Quoted 15 lines · Dave Airlie
5bdebb183c9702a8c57a01dff09337be3de337a6changed the lifetimes, but it also meant we no longer set thedevice_typefield properly, so the hotplug events in userspace weren't fully formed enough for drivers to care.Reported-by Jesse Barnes <[email protected]>Signed-off-by Dave Airlie <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/drm_sysfs.c +0
-0drivers/gpu/drm/drm_sysfs.c int drm_sysfs_device_add(struct drm_minor *minor) · line 519
Quoted 4 lines
drivers/gpu/drm/drm_sysfs.c +1
-0@@ -516,6 +516,7 @@ int drm_sysfs_device_add(struct drm_minor *minor)DRM_ERROR ("device create failed %ld\n" ,PTR_ERR (minor->kdev));return PTR_ERR (minor->kdev); } + minor->kdev->type = &drm_sysfs_device_minor;Isn't this one of the sysfs races Greg is fighting against? At least from a cursor read through the driver core it looks like we'd better set the
dev->typebefore we set it up withdevice_create().
Quoted 9 lines
Quoted 4 lines
Possibly but how can we do that? since
minor->kdevis something we just created 2 lines earlier
unless there is another create function I should be calling, I don't see adevice_create_with_type.See
device_create_groups_vargs()indrivers/base/core.c. Just copy the code from it and do device initialization yourself.device_create()is only a wrapper around kzalloc()+device_register() anyway.
It does seem a bit like cut-n-paste magic to me to do that,
It does however seem to be the accepted norm.
Dave.
Hi
Quoted 35 lines · Dave Airlie
Quoted 34 lines · David Herrmann
Hi
Quoted 30 lines · Dave Airlie
Quoted 11 lines · Daniel Vetter
Quoted 10 lines · Dave Airlie
5bdebb183c9702a8c57a01dff09337be3de337a6changed the lifetimes, but it also meant we no longer set thedevice_typefield properly, so the hotplug events in userspace weren't fully formed enough for drivers to care.Reported-by Jesse Barnes <[email protected]>Signed-off-by Dave Airlie <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 1 + 1 file changed, 1 insertion(+)Quoted 13 lines
drivers/gpu/drm/drm_sysfs.c int drm_sysfs_device_add(struct drm_minor *minor) · line 519
Quoted 9 lines
drivers/gpu/drm/drm_sysfs.c +1
-0@@ -516,6 +516,7 @@ int drm_sysfs_device_add(struct drm_minor *minor)DRM_ERROR ("device create failed %ld\n" ,PTR_ERR (minor->kdev));return PTR_ERR (minor->kdev); } + minor->kdev->type = &drm_sysfs_device_minor;Isn't this one of the sysfs races Greg is fighting against? At least from a cursor read through the driver core it looks like we'd better set the
dev->typebefore we set it up withdevice_create().Possibly but how can we do that? since
minor->kdevis something we just created 2 lines earlier
unless there is another create function I should be calling, I don't see adevice_create_with_type.
Quoted 8 lines
Quoted 4 lines
See
device_create_groups_vargs()indrivers/base/core.c. Just copy the code from it and do device initialization yourself.device_create()is only a wrapper around kzalloc()+device_register() anyway.It does seem a bit like cut-n-paste magic to me to do that,
It does however seem to be the accepted norm.
This should do it (untested!):
drivers/gpu/drm/drm_sysfs.c +33 -6
@@ -489,6 +489,11 @@ void drm_sysfs_hotplug_event(struct drm_device *dev) }EXPORT_SYMBOL (drm_sysfs_hotplug_event); +static void drm_sysfs_release (struct device *dev) +{ +kfree (dev); +} +/** * drm_sysfs_device_add - adds a class device to sysfs for a character driver * @dev: DRM device to be added
@@ -501,6 +506,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);int drm_sysfs_device_add (struct drm_minor *minor) {char *minor_str; +int r;if (minor->type ==DRM_MINOR_CONTROL ) minor_str ="controlD%d" ;
@@ -509,14 +515,35 @@ int drm_sysfs_device_add(struct drm_minor *minor)else minor_str ="card%d" ; - minor->kdev =device_create (drm_class, minor->dev->dev, -MKDEV (DRM_MAJOR , minor->index), - minor, minor_str, minor->index); -if (IS_ERR (minor->kdev)) { -DRM_ERROR ("device create failed %ld\n" ,PTR_ERR (minor->kdev)); -return PTR_ERR (minor->kdev); + minor->kdev =kzalloc (sizeof (*minor->kdev),GFP_KERNEL ); +if (!minor->dev) { + r = -ENOMEM ; + goto error; } + +device_initialize (minor->kdev); + minor->kdev->devt =MKDEV (DRM_MAJOR , minor->index); + minor->kdev->class = drm_class; + minor->kdev->type = &drm_sysfs_device_minor; + minor->kdev->parent = minor->dev->dev; + minor->kdev->groups =NULL ; + minor->kdev->release = drm_sysfs_release; +dev_set_drvdata (minor->kdev, minor); + + r =dev_set_name (minor->kdev, minor_str, minor->index); +if (r <0 ) + goto error; + + r =device_add (minor->kdev); +if (r <0 ) + goto error; +return 0 ; + +error: +DRM_ERROR ("device create failed %ld\n" ,PTR_ERR (minor->kdev)); +put_device (minor->kdev); +return r; }/**
Quoted 31 lines · Dave Airlie
Quoted 11 lines · Daniel Vetter
Quoted 10 lines · Dave Airlie
5bdebb183c9702a8c57a01dff09337be3de337a6changed the lifetimes, but it also meant we no longer set thedevice_typefield properly, so the hotplug events in userspace weren't fully formed enough for drivers to care.Reported-by Jesse Barnes <[email protected]>Signed-off-by Dave Airlie <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 1 + 1 file changed, 1 insertion(+)Quoted 13 lines
drivers/gpu/drm/drm_sysfs.c int drm_sysfs_device_add(struct drm_minor *minor) · line 519
Quoted 9 lines
drivers/gpu/drm/drm_sysfs.c +1
-0@@ -516,6 +516,7 @@ int drm_sysfs_device_add(struct drm_minor *minor)DRM_ERROR ("device create failed %ld\n" ,PTR_ERR (minor->kdev));return PTR_ERR (minor->kdev); } + minor->kdev->type = &drm_sysfs_device_minor;Isn't this one of the sysfs races Greg is fighting against? At least from a cursor read through the driver core it looks like we'd better set the
dev->typebefore we set it up withdevice_create().Possibly but how can we do that? since
minor->kdevis something we just created 2 lines earlier
unless there is another create function I should be calling, I don't see adevice_create_with_type.Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Cc'ing Greg for insight.
Aside: I wonder whether we could get rid of our
drm_minortype and use it for something more useful like the render node vs legacy node split ...Its ABI now. all the userspace drivers need it in the uevents for hotplug to keep working.
Yeah I know that the drm_minor is abi now on legacy node. More thought of a drm_render type for the render nodes. Could help with finding them through udev (e.g. for headless usage in transcode jobs or for opencl).
I think we should waste a few braincycles on this before making rendernodes official.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 25 lines · Daniel Vetter
Quoted 15 lines · Dave Airlie
5bdebb183c9702a8c57a01dff09337be3de337a6changed the lifetimes, but it also meant we no longer set thedevice_typefield properly, so the hotplug events in userspace weren't fully formed enough for drivers to care.Reported-by Jesse Barnes <[email protected]>Signed-off-by Dave Airlie <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/drm_sysfs.c +0
-0drivers/gpu/drm/drm_sysfs.c int drm_sysfs_device_add(struct drm_minor *minor) · line 519
Quoted 4 lines
drivers/gpu/drm/drm_sysfs.c +1
-0@@ -516,6 +516,7 @@ int drm_sysfs_device_add(struct drm_minor *minor)DRM_ERROR ("device create failed %ld\n" ,PTR_ERR (minor->kdev));return PTR_ERR (minor->kdev); } + minor->kdev->type = &drm_sysfs_device_minor;Isn't this one of the sysfs races Greg is fighting against? At least from a cursor read through the driver core it looks like we'd better set the
dev->typebefore we set it up withdevice_create().
Quoted 1 line
Cc'ing Greg for insight.
No, setting the type at this point is fine, I don't see the race, care to explain what I'm missing?
But, if you want to be "correct" you can just create the device structure yourself, set the fields (including the type) and then call device_register() yourself. Look at usb_create_ep_devs() for an example of how to do this.
thanks,
greg k-h
Hi
Quoted 28 lines · Greg KH
Quoted 25 lines · Daniel Vetter
Quoted 15 lines · Dave Airlie
5bdebb183c9702a8c57a01dff09337be3de337a6changed the lifetimes, but it also meant we no longer set thedevice_typefield properly, so the hotplug events in userspace weren't fully formed enough for drivers to care.Reported-by Jesse Barnes <[email protected]>Signed-off-by Dave Airlie <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/drm_sysfs.c +0
-0drivers/gpu/drm/drm_sysfs.c int drm_sysfs_device_add(struct drm_minor *minor) · line 519
Quoted 4 lines
drivers/gpu/drm/drm_sysfs.c +1
-0@@ -516,6 +516,7 @@ int drm_sysfs_device_add(struct drm_minor *minor)DRM_ERROR ("device create failed %ld\n" ,PTR_ERR (minor->kdev));return PTR_ERR (minor->kdev); } + minor->kdev->type = &drm_sysfs_device_minor;Isn't this one of the sysfs races Greg is fighting against? At least from a cursor read through the driver core it looks like we'd better set the
dev->typebefore we set it up withdevice_create().Quoted 1 line
Cc'ing Greg for insight.
Quoted 7 lines
No, setting the type at this point is fine, I don't see the race, care to explain what I'm missing?
But, if you want to be "correct" you can just create the device structure yourself, set the fields (including the type) and then call
device_register()yourself. Look atusb_create_ep_devs()for an example of how to do this.
We already pushed a fix:
http://cgit.freedesktop.org/~airlied/linux/commit/?h=drm-fixes&id=760c960bd6880cf22a57c0af9ff60c96250aad39
The race is the same as with sysfs attributes. If we set the device type _after_ device_add(), the initial uevent might not have DEVTYPE=drm_minor set, thus, slip through any udev_*_match_subsystem_devtype() filters.
Thanks
David
Quoted 39 lines · David Herrmann
Hi
Quoted 28 lines · Greg KH
Quoted 25 lines · Daniel Vetter
Quoted 15 lines · Dave Airlie
5bdebb183c9702a8c57a01dff09337be3de337a6changed the lifetimes, but it also meant we no longer set thedevice_typefield properly, so the hotplug events in userspace weren't fully formed enough for drivers to care.Reported-by Jesse Barnes <[email protected]>Signed-off-by Dave Airlie <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/drm_sysfs.c +0
-0drivers/gpu/drm/drm_sysfs.c int drm_sysfs_device_add(struct drm_minor *minor) · line 519
Quoted 4 lines
drivers/gpu/drm/drm_sysfs.c +1
-0@@ -516,6 +516,7 @@ int drm_sysfs_device_add(struct drm_minor *minor)DRM_ERROR ("device create failed %ld\n" ,PTR_ERR (minor->kdev));return PTR_ERR (minor->kdev); } + minor->kdev->type = &drm_sysfs_device_minor;Isn't this one of the sysfs races Greg is fighting against? At least from a cursor read through the driver core it looks like we'd better set the
dev->typebefore we set it up withdevice_create().Quoted 1 line
Cc'ing Greg for insight.
Quoted 7 lines
No, setting the type at this point is fine, I don't see the race, care to explain what I'm missing?
But, if you want to be "correct" you can just create the device structure yourself, set the fields (including the type) and then call
device_register()yourself. Look atusb_create_ep_devs()for an example of how to do this.
Quoted 7 lines
We already pushed a fix:
http://cgit.freedesktop.org/~airlied/linux/commit/?h=drm-fixes&id=760c960bd6880cf22a57c0af9ff60c96250aad39The race is the same as with sysfs attributes. If we set the device type _after_
device_add(), the initial uevent might not have DEVTYPE=drm_minor set, thus, slip through any udev_*_match_subsystem_devtype() filters.
Ah, that makes sense, nice fix.
greg k-h