drm: Use full allocated minor range for DRM
Subsystems (2)
v2 cover drm: Use full allocated minor range for DRM
64 DRM device nodes is not enough for everyone. Upgrade it to ~341K (which definitely is more than enough). Additionally - one minor tweak around minor IDR locking.
v1 -> v2:
Don't touch DRM_MINOR_CONTROL and its range (Simon Ser)
Michał Winiarski (2):
drm: Expand max DRM device number to full MINORBITS
drm: Use mutex for minors
drivers/gpu/drm/drm_drv.c | 45 ++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 24 deletions(-)
Signature · 1 line
2.37.2
PATCH v2 1/2 drm: Expand max DRM device number to full MINORBITS
Having a limit of 64 DRM devices is not good enough for modern world where we have multi-GPU servers, SR-IOV virtual functions and virtual devices used for testing.
Let's utilize full minor range for DRM devices.
To avoid regressing the existing userspace, we're still maintaining the numbering scheme where 0-63 is used for primary, 64-127 is reserved (formerly for control) and 128-191 is used for render.
This is continued for minors >= 192 (192-255 for primary, 256-319 reserved, 320-383 for render, and so on).
--- drivers/gpu/drm/drm_drv.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
drivers/gpu/drm/drm_drv.c +14 -10
@@ -113,7 +113,7 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) {struct drm_minor *minor;unsigned long flags; -int r; +int r, start, end; minor =drmm_kzalloc (dev,sizeof (*minor),GFP_KERNEL );if (!minor)
@@ -122,15 +122,19 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) minor->type = type; minor->dev = dev; -idr_preload (GFP_KERNEL ); -spin_lock_irqsave (&drm_minor_lock, flags); - r =idr_alloc (&drm_minors_idr, -NULL , -64 * type, -64 * (type +1 ), -GFP_NOWAIT ); -spin_unlock_irqrestore (&drm_minor_lock, flags); -idr_preload_end (); + start =64 * type; + end =64 * (type +1 ); + +do { +idr_preload (GFP_KERNEL ); +spin_lock_irqsave (&drm_minor_lock, flags); + r =idr_alloc (&drm_minors_idr,NULL , start, end,GFP_NOWAIT ); +spin_unlock_irqrestore (&drm_minor_lock, flags); +idr_preload_end (); + + start +=192 ; + end +=192 ; + }while ((r == -ENOSPC ) && end <= (1 <<MINORBITS ));if (r <0 )return r;
Signature · 1 line
2.37.2
Re: [PATCH v2 1/2] drm: Expand max DRM device number to full MINORBITS
This approach will not break existing user-space AFAIK.
PATCH v2 2/2 drm: Use mutex for minors
In reply to Michał WiniarskiOperating on drm minor is not done in IRQ context, which means that we could safely downgrade to regular non-irq spinlock.
But we can also go further and drop the idr_preload tricks by just using a mutex.
--- drivers/gpu/drm/drm_drv.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-)
drivers/gpu/drm/drm_drv.c +12 -19
@@ -53,7 +53,7 @@ MODULE_AUTHOR("Gareth Hughes, Leif Delgass, José Fonseca, Jon Smirl");MODULE_DESCRIPTION ("DRM shared core routines" );MODULE_LICENSE ("GPL and additional rights" ); -static DEFINE_SPINLOCK (drm_minor_lock); +static DEFINE_MUTEX (drm_minor_lock);static struct idr drm_minors_idr;/*
@@ -98,21 +98,19 @@ static struct drm_minor **drm_minor_get_slot(struct drm_device *dev,static void drm_minor_alloc_release (struct drm_device *dev,void *data) {struct drm_minor *minor = data; -unsigned long flags;WARN_ON (dev != minor->dev);put_device (minor->kdev); -spin_lock_irqsave (&drm_minor_lock, flags); +mutex_lock (&drm_minor_lock);idr_remove (&drm_minors_idr, minor->index); -spin_unlock_irqrestore (&drm_minor_lock, flags); +mutex_unlock (&drm_minor_lock); }static int drm_minor_alloc (struct drm_device *dev,unsigned int type) {struct drm_minor *minor; -unsigned long flags;int r, start, end; minor =drmm_kzalloc (dev,sizeof (*minor),GFP_KERNEL );
@@ -126,11 +124,9 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) end =64 * (type +1 ); do { - idr_preload(GFP_KERNEL); - spin_lock_irqsave(&drm_minor_lock, flags); - r = idr_alloc(&drm_minors_idr, NULL, start, end, GFP_NOWAIT); - spin_unlock_irqrestore(&drm_minor_lock, flags); - idr_preload_end(); + mutex_lock(&drm_minor_lock); + r = idr_alloc(&drm_minors_idr, NULL, start, end, GFP_KERNEL); + mutex_unlock(&drm_minor_lock); start += 192; end += 192;
@@ -156,7 +152,6 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type)static int drm_minor_register (struct drm_device *dev,unsigned int type) {struct drm_minor *minor; -unsigned long flags;int ret;DRM_DEBUG ("\n" );
@@ -176,9 +171,9 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) goto err_debugfs;/* replace NULL with @minor so lookups will succeed from now on */ -spin_lock_irqsave (&drm_minor_lock, flags); +mutex_lock (&drm_minor_lock);idr_replace (&drm_minors_idr, minor, minor->index); -spin_unlock_irqrestore (&drm_minor_lock, flags); +mutex_unlock (&drm_minor_lock);DRM_DEBUG ("new minor registered %d\n" , minor->index);return 0 ;
@@ -191,16 +186,15 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type)static void drm_minor_unregister (struct drm_device *dev,unsigned int type) {struct drm_minor *minor; -unsigned long flags; minor = *drm_minor_get_slot (dev, type);if (!minor || !device_is_registered (minor->kdev))return ;/* replace @minor with NULL so lookups will fail from now on */ -spin_lock_irqsave (&drm_minor_lock, flags); +mutex_lock (&drm_minor_lock);idr_replace (&drm_minors_idr,NULL , minor->index); -spin_unlock_irqrestore (&drm_minor_lock, flags); +mutex_unlock (&drm_minor_lock);device_del (minor->kdev);dev_set_drvdata (minor->kdev,NULL );/* safety belt */
@@ -219,13 +213,12 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type)struct drm_minor *drm_minor_acquire (unsigned int minor_id) {struct drm_minor *minor; -unsigned long flags; -spin_lock_irqsave (&drm_minor_lock, flags); +mutex_lock (&drm_minor_lock); minor =idr_find (&drm_minors_idr, minor_id);if (minor)drm_dev_get (minor->dev); -spin_unlock_irqrestore (&drm_minor_lock, flags); +mutex_unlock (&drm_minor_lock);if (!minor) {return ERR_PTR (-ENODEV );
Signature · 1 line
2.37.2