Skip to contentSkip to conversation

drm/sysfs: fix hotplug regression since lifetime changes

PATCH In review Dave Airlie 4 participants 10 messages Nov 21, 2013

Subsystems (2)
lore
Share & tools
lore

Dave Airlie

author maintainer
#0 lore raw

PATCH 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
index 1a35ea5..c6a3902 100644
@@ -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
#1 lore raw
Quoted 15 lines · Dave Airlie

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 +0 -0
index 1a35ea5..c6a3902 100644

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
author maintainer
#2 lore raw
Quoted 11 lines · Daniel Vetter
Quoted 10 lines · Dave Airlie

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(+)
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
index 1a35ea5..c6a3902 100644
@@ -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().

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_minor type 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.

#3 lore raw

Hi

Quoted 26 lines · Dave Airlie
Quoted 11 lines · Daniel Vetter
Quoted 10 lines · Dave Airlie

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(+)
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
index 1a35ea5..c6a3902 100644
@@ -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().

Quoted 4 lines

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.

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_minor type 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

author maintainer
#4 lore raw
Quoted 29 lines · David Herrmann

Hi

Quoted 26 lines · Dave Airlie
Quoted 24 lines · Daniel Vetter
Quoted 15 lines · Dave Airlie

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 +0 -0
index 1a35ea5..c6a3902 100644

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

Quoted 9 lines
Quoted 4 lines

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.

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.

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.

#5 lore raw

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

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(+)
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
index 1a35ea5..c6a3902 100644
@@ -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().

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 8 lines
Quoted 4 lines

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.

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
index 1a35ea5..cb951b2 100644
@@ -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;
 }
 
 /**
#6 lore raw
In reply to Dave Airlie
Quoted 31 lines · Dave Airlie
Quoted 11 lines · Daniel Vetter
Quoted 10 lines · Dave Airlie

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(+)
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
index 1a35ea5..c6a3902 100644
@@ -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().

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 1 line
Quoted 7 lines
Quoted 4 lines

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

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
#7 lore raw
In reply to Daniel Vetter
Quoted 25 lines · Daniel Vetter
Quoted 15 lines · Dave Airlie

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 +0 -0
index 1a35ea5..c6a3902 100644

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

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

#8 lore raw

Hi

Quoted 28 lines · Greg KH
Quoted 25 lines · Daniel Vetter
Quoted 15 lines · Dave Airlie

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 +0 -0
index 1a35ea5..c6a3902 100644

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

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 at usb_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

#9 lore raw
Quoted 39 lines · David Herrmann

Hi

Quoted 28 lines · Greg KH
Quoted 25 lines · Daniel Vetter
Quoted 15 lines · Dave Airlie

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 +0 -0
index 1a35ea5..c6a3902 100644

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

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 at usb_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=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.

Ah, that makes sense, nice fix.

greg k-h