From: Sidhartha Kumar <sidhartha.kumar@oracle.com>
To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org
Cc: maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch,
willy@infradead.org, sidhartha.kumar@oracle.com
Subject: [PATCH 2/6] drm: Convert object_name_idr to XArray
Date: Mon, 18 Aug 2025 19:00:42 +0000 [thread overview]
Message-ID: <20250818190046.157962-3-sidhartha.kumar@oracle.com> (raw)
In-Reply-To: <20250818190046.157962-1-sidhartha.kumar@oracle.com>
From: Matthew Wilcox <willy@infradead.org>
It's not possible to replace object_name_lock as it protects more
code than should be reasonably be run under a spinlock, so the xa_lock
is nested under the object_name_lock.
Signed-off-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
drivers/gpu/drm/drm_debugfs.c | 19 ++++++-------------
drivers/gpu/drm/drm_gem.c | 11 +++++------
include/drm/drm_device.h | 4 ++--
3 files changed, 13 insertions(+), 21 deletions(-)
diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 3dfd8b34dceb..2d37ee7f70fb 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -117,27 +117,20 @@ static int drm_clients_info(struct seq_file *m, void *data)
return 0;
}
-static int drm_gem_one_name_info(int id, void *ptr, void *data)
-{
- struct drm_gem_object *obj = ptr;
- struct seq_file *m = data;
-
- seq_printf(m, "%6d %8zd %7d %8d\n",
- obj->name, obj->size,
- obj->handle_count,
- kref_read(&obj->refcount));
- return 0;
-}
-
static int drm_gem_name_info(struct seq_file *m, void *data)
{
struct drm_debugfs_entry *entry = m->private;
struct drm_device *dev = entry->dev;
+ struct drm_gem_object *obj;
+ unsigned long index;
seq_printf(m, " name size handles refcount\n");
mutex_lock(&dev->object_name_lock);
- idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m);
+ xa_for_each(&dev->object_names, index, obj) {
+ seq_printf(m, "%6d %8zd %7d %8d\n", obj->name, obj->size,
+ obj->handle_count, kref_read(&obj->refcount));
+ }
mutex_unlock(&dev->object_name_lock);
return 0;
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 4bf0a76bb35e..27a7069d819d 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -96,7 +96,7 @@ drm_gem_init(struct drm_device *dev)
struct drm_vma_offset_manager *vma_offset_manager;
mutex_init(&dev->object_name_lock);
- idr_init_base(&dev->object_name_idr, 1);
+ xa_init_flags(&dev->object_names, XA_FLAGS_ALLOC1);
vma_offset_manager = drmm_kzalloc(dev, sizeof(*vma_offset_manager),
GFP_KERNEL);
@@ -257,7 +257,7 @@ static void drm_gem_object_handle_free(struct drm_gem_object *obj)
/* Remove any name for this object */
if (obj->name) {
- idr_remove(&dev->object_name_idr, obj->name);
+ xa_erase(&dev->object_names, obj->name);
obj->name = 0;
}
}
@@ -908,11 +908,10 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data,
}
if (!obj->name) {
- ret = idr_alloc(&dev->object_name_idr, obj, 1, 0, GFP_KERNEL);
+ ret = xa_alloc(&dev->object_names, &obj->name, obj,
+ xa_limit_32b, GFP_KERNEL);
if (ret < 0)
goto err;
-
- obj->name = ret;
}
args->name = (uint64_t) obj->name;
@@ -948,7 +947,7 @@ drm_gem_open_ioctl(struct drm_device *dev, void *data,
return -EOPNOTSUPP;
mutex_lock(&dev->object_name_lock);
- obj = idr_find(&dev->object_name_idr, (int) args->name);
+ obj = xa_load(&dev->object_names, (int) args->name);
if (obj) {
drm_gem_object_get(obj);
} else {
diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h
index e2f894f1b90a..7d8244078d51 100644
--- a/include/drm/drm_device.h
+++ b/include/drm/drm_device.h
@@ -314,8 +314,8 @@ struct drm_device {
/** @object_name_lock: GEM information */
struct mutex object_name_lock;
- /** @object_name_idr: GEM information */
- struct idr object_name_idr;
+ /** @object_names: GEM information */
+ struct xarray object_names;
/** @vma_offset_manager: GEM information */
struct drm_vma_offset_manager *vma_offset_manager;
--
2.43.0
next prev parent reply other threads:[~2025-08-18 19:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-18 19:00 [PATCH 0/6] DRM IDR to Xarray conversions Sidhartha Kumar
2025-08-18 19:00 ` [PATCH 1/6] drm: Convert aux_idr to XArray Sidhartha Kumar
2025-08-19 10:35 ` kernel test robot
2025-08-18 19:00 ` Sidhartha Kumar [this message]
2025-08-18 19:00 ` [PATCH 3/6] drm: Convert syncobj_idr " Sidhartha Kumar
2025-08-18 19:00 ` [PATCH 4/6] drm: Convert magic_map " Sidhartha Kumar
2025-08-18 19:00 ` [PATCH 5/6] drm: Convert lessee_idr " Sidhartha Kumar
2025-08-18 19:00 ` [PATCH 6/6] drm: Convert tile_idr " Sidhartha Kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250818190046.157962-3-sidhartha.kumar@oracle.com \
--to=sidhartha.kumar@oracle.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®