diff mbox series

[v2,1/2] drm: Expand max DRM device number to full MINORBITS

Message ID 20220823210612.296922-2-michal.winiarski@intel.com (mailing list archive)
State New, archived
Headers show
Series drm: Use full allocated minor range for DRM | expand

Commit Message

Michał Winiarski Aug. 23, 2022, 9:06 p.m. UTC
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).

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
---
 drivers/gpu/drm/drm_drv.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

Comments

Simon Ser Aug. 24, 2022, 8:02 a.m. UTC | #1
This approach will not break existing user-space AFAIK.

Acked-by: Simon Ser <contact@emersion.fr>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 8214a0b1ab7f..b64b5c45cd80 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -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;