* [PATCH 0/3] drm/syncobj: Allocation avoiding fast path
@ 2026-11-17 10:39 Tvrtko Ursulin
2026-11-17 10:39 ` [PATCH 1/3] drm/syncobj: Use vmemdup_array_user in drm_syncobj_array_find Tvrtko Ursulin
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Tvrtko Ursulin @ 2026-11-17 10:39 UTC (permalink / raw)
To: dri-devel
Cc: kernel-dev, Tvrtko Ursulin, Maíra Canal, Fei Yu,
Christian König
In practice there are multiple DRM syncobj operations (and/or ioctls) per
rendered frame, and vast majority of them operates on a just a couple of
handles, or timeline points.
This series adds a fast path to avoid the temporary allocations for those cases.
Cc: Maíra Canal <mcanal@igalia.com>
Cc: Fei Yu <fei.yu@intel.com>
Cc: Christian König <christian.koenig@amd.com>
Tvrtko Ursulin (3):
drm/syncobj: Use vmemdup_array_user in drm_syncobj_array_find
drm/syncobj: Add a fast path to drm_syncobj_array_wait_timeout
drm/syncobj: Add a fast path to drm_syncobj_array_find
drivers/gpu/drm/drm_syncobj.c | 134 +++++++++++++++++++++++++---------
1 file changed, 99 insertions(+), 35 deletions(-)
--
2.56.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/3] drm/syncobj: Use vmemdup_array_user in drm_syncobj_array_find
2026-11-17 10:39 [PATCH 0/3] drm/syncobj: Allocation avoiding fast path Tvrtko Ursulin
@ 2026-11-17 10:39 ` Tvrtko Ursulin
2026-11-17 12:57 ` Maíra Canal
2026-11-17 13:23 ` Christian König
2026-11-17 10:39 ` [PATCH 2/3] drm/syncobj: Add a fast path to drm_syncobj_array_wait_timeout Tvrtko Ursulin
` (2 subsequent siblings)
3 siblings, 2 replies; 9+ messages in thread
From: Tvrtko Ursulin @ 2026-11-17 10:39 UTC (permalink / raw)
To: dri-devel; +Cc: kernel-dev, Tvrtko Ursulin, Fei Yu, Christian König
Using a helper shrinks the code and separating the user and kernel slabs
is more secure.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Cc: Fei Yu <fei.yu@intel.com>
Cc: Christian König <christian.koenig@amd.com>
---
drivers/gpu/drm/drm_syncobj.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index 6cc654641183..663d6cb8dbf8 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -1252,15 +1252,10 @@ static int drm_syncobj_array_find(struct drm_file *file_private,
if (count_handles > DRM_SYNCOBJ_MAX_HANDLES)
return -EINVAL;
- handles = kvmalloc_objs(*handles, count_handles);
- if (handles == NULL)
- return -ENOMEM;
-
- if (copy_from_user(handles, user_handles,
- sizeof(uint32_t) * count_handles)) {
- ret = -EFAULT;
- goto err_free_handles;
- }
+ handles = vmemdup_array_user(user_handles, count_handles,
+ sizeof(*handles));
+ if (IS_ERR(handles))
+ return PTR_ERR(handles);
syncobjs = kvmalloc_objs(*syncobjs, count_handles);
if (syncobjs == NULL) {
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] drm/syncobj: Add a fast path to drm_syncobj_array_wait_timeout
2026-11-17 10:39 [PATCH 0/3] drm/syncobj: Allocation avoiding fast path Tvrtko Ursulin
2026-11-17 10:39 ` [PATCH 1/3] drm/syncobj: Use vmemdup_array_user in drm_syncobj_array_find Tvrtko Ursulin
@ 2026-11-17 10:39 ` Tvrtko Ursulin
2026-11-18 8:06 ` Yu, Fei
2026-11-17 10:39 ` [PATCH 3/3] drm/syncobj: Add a fast path to drm_syncobj_array_find Tvrtko Ursulin
2026-11-18 8:06 ` [PATCH 0/3] drm/syncobj: Allocation avoiding fast path Yu, Fei
3 siblings, 1 reply; 9+ messages in thread
From: Tvrtko Ursulin @ 2026-11-17 10:39 UTC (permalink / raw)
To: dri-devel
Cc: kernel-dev, Tvrtko Ursulin, Maíra Canal, Fei Yu,
Christian König
Running the Cyberpunk 2077 benchmark we can observe that waiting on DRM
sycobjs is relatively hot, but the 96% of the calls are for a single
object. (~4% for two points, and never more than three points. While
a more trivial workload like vkmark under Plasma is even more skewed
to single point waits.)
Therefore lets add a fast path to bypass the kcalloc/kfree and use a pre-
allocated stack array for those cases.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reviewed-by: Maíra Canal <mcanal@igalia.com> # v3
Cc: Fei Yu <fei.yu@intel.com>
Cc: Christian König <christian.koenig@amd.com>
---
v2:
* Document rationale for stack array in a comment.
v3:
* Added DRM_SYNCOBJ_FAST_PATH_ENTRIES to avoid hardcoding fast path array
size.
v4:
* Rebased to be standalone.
v5:
* Rebased for kzalloc_objs.
v6:
* Rebased for kvmalloc_objs and kvzalloc_objs.
---
drivers/gpu/drm/drm_syncobj.c | 44 ++++++++++++++++++++++++++---------
1 file changed, 33 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index 663d6cb8dbf8..b76b957b1fff 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -248,6 +248,14 @@ static void
syncobj_eventfd_entry_func(struct drm_syncobj *syncobj,
struct syncobj_eventfd_entry *entry);
+/*
+ * Empirically vast majority of ioctls pass in a single syncobj (96%) and never
+ * more than three points. Therefore implement a fast path with a small stack
+ * array to avoid going into the allocator sometimes several times per
+ * userspace rendered frame.
+ */
+#define DRM_SYNCOBJ_FAST_PATH_ENTRIES 4
+
/**
* drm_syncobj_find - lookup and reference a sync object.
* @file_private: drm file private pointer
@@ -1051,10 +1059,12 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
uint32_t *idx,
ktime_t *deadline)
{
+ struct syncobj_wait_entry stack_entries[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
+ u64 stack_points[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
struct syncobj_wait_entry *entries;
struct dma_fence *fence;
- uint64_t *points;
uint32_t signaled_count, i;
+ uint64_t *points;
if (flags & (DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT |
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE)) {
@@ -1062,24 +1072,33 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
lockdep_assert_none_held_once();
}
- points = kvmalloc_objs(*points, count);
- if (points == NULL)
- return -ENOMEM;
+ if (count > ARRAY_SIZE(stack_points)) {
+ points = kvmalloc_objs(*points, count);
+ if (!points)
+ return -ENOMEM;
+ } else {
+ points = stack_points;
+ }
if (!user_points) {
memset(points, 0, count * sizeof(uint64_t));
-
} else if (copy_from_user(points, user_points,
sizeof(uint64_t) * count)) {
timeout = -EFAULT;
goto err_free_points;
}
- entries = kvzalloc_objs(*entries, count);
- if (!entries) {
- timeout = -ENOMEM;
- goto err_free_points;
+ if (count > ARRAY_SIZE(stack_entries)) {
+ entries = kvzalloc_objs(*entries, count);
+ if (!entries) {
+ timeout = -ENOMEM;
+ goto err_free_points;
+ }
+ } else {
+ memset(stack_entries, 0, sizeof(stack_entries));
+ entries = stack_entries;
}
+
/* Walk the list of sync objects and initialize entries. We do
* this up-front so that we can properly return -EINVAL if there is
* a syncobj with a missing fence and then never have the chance of
@@ -1196,10 +1215,13 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
&entries[i].fence_cb);
dma_fence_put(entries[i].fence);
}
- kvfree(entries);
+
+ if (entries != stack_entries)
+ kvfree(entries);
err_free_points:
- kvfree(points);
+ if (points != stack_points)
+ kvfree(points);
return timeout;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] drm/syncobj: Add a fast path to drm_syncobj_array_find
2026-11-17 10:39 [PATCH 0/3] drm/syncobj: Allocation avoiding fast path Tvrtko Ursulin
2026-11-17 10:39 ` [PATCH 1/3] drm/syncobj: Use vmemdup_array_user in drm_syncobj_array_find Tvrtko Ursulin
2026-11-17 10:39 ` [PATCH 2/3] drm/syncobj: Add a fast path to drm_syncobj_array_wait_timeout Tvrtko Ursulin
@ 2026-11-17 10:39 ` Tvrtko Ursulin
2026-11-18 8:06 ` Yu, Fei
2026-11-18 8:06 ` [PATCH 0/3] drm/syncobj: Allocation avoiding fast path Yu, Fei
3 siblings, 1 reply; 9+ messages in thread
From: Tvrtko Ursulin @ 2026-11-17 10:39 UTC (permalink / raw)
To: dri-devel
Cc: kernel-dev, Tvrtko Ursulin, Maíra Canal, Fei Yu,
Christian König
Running the Cyberpunk 2077 benchmark we can observe that the lookup helper
is relatively hot, but the 97% of the calls are for a single object. (~3%
for two points, and never more than three points. While a more trivial
workload like vkmark under Plasma is even more skewed to single point
lookups.)
Therefore lets add a fast path to bypass the kmalloc_array/kfree and use a
pre-allocated stack array for those cases.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reviewed-by: Maíra Canal <mcanal@igalia.com> # v2
Cc: Fei Yu <fei.yu@intel.com>
Cc: Christian König <christian.koenig@amd.com>
---
v2:
* Added comments describing how the fast path arrays were sized.
* Make container freeing criteria clearer by using a boolean.
v3:
* Rebased to be standalone.
v4:
* Rebased for kmalloc_objs.
v5:
* Rebased for vmemdup_array_user and kvmalloc_objs.
---
drivers/gpu/drm/drm_syncobj.c | 85 +++++++++++++++++++++++++++--------
1 file changed, 66 insertions(+), 19 deletions(-)
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index b76b957b1fff..c4514f186d50 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -1265,6 +1265,9 @@ static int drm_syncobj_array_wait(struct drm_device *dev,
static int drm_syncobj_array_find(struct drm_file *file_private,
void __user *user_handles,
uint32_t count_handles,
+ uint32_t *stack_handles,
+ struct drm_syncobj **stack_syncobjs,
+ u32 stack_count,
struct drm_syncobj ***syncobjs_out)
{
uint32_t i, *handles;
@@ -1274,15 +1277,23 @@ static int drm_syncobj_array_find(struct drm_file *file_private,
if (count_handles > DRM_SYNCOBJ_MAX_HANDLES)
return -EINVAL;
- handles = vmemdup_array_user(user_handles, count_handles,
- sizeof(*handles));
- if (IS_ERR(handles))
- return PTR_ERR(handles);
+ if (count_handles > stack_count) {
+ handles = vmemdup_array_user(user_handles, count_handles,
+ sizeof(*handles));
+ if (IS_ERR(handles))
+ return PTR_ERR(handles);
- syncobjs = kvmalloc_objs(*syncobjs, count_handles);
- if (syncobjs == NULL) {
- ret = -ENOMEM;
- goto err_free_handles;
+ syncobjs = kvmalloc_objs(*syncobjs, count_handles);;
+ if (!syncobjs) {
+ ret = -ENOMEM;
+ goto err_free_handles;
+ }
+ } else {
+ handles = stack_handles;
+ syncobjs = stack_syncobjs;
+ if (copy_from_user(handles, user_handles,
+ count_handles * sizeof(*handles)))
+ return -EFAULT;
}
for (i = 0; i < count_handles; i++) {
@@ -1293,34 +1304,42 @@ static int drm_syncobj_array_find(struct drm_file *file_private,
}
}
- kvfree(handles);
+ if (handles != stack_handles)
+ kvfree(handles);
*syncobjs_out = syncobjs;
return 0;
err_put_syncobjs:
while (i-- > 0)
drm_syncobj_put(syncobjs[i]);
- kvfree(syncobjs);
+ if (syncobjs != stack_syncobjs)
+ kvfree(syncobjs);
err_free_handles:
- kvfree(handles);
+ if (handles != stack_handles)
+ kvfree(handles);
return ret;
}
static void drm_syncobj_array_free(struct drm_syncobj **syncobjs,
- uint32_t count)
+ uint32_t count,
+ struct drm_syncobj **stack_syncobjs)
{
uint32_t i;
for (i = 0; i < count; i++)
drm_syncobj_put(syncobjs[i]);
- kvfree(syncobjs);
+
+ if (syncobjs != stack_syncobjs)
+ kvfree(syncobjs);
}
int
drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_private)
{
+ struct drm_syncobj *stack_syncobjs[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
+ uint32_t stack_handles[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
struct drm_syncobj_wait *args = data;
struct drm_syncobj **syncobjs;
unsigned int possible_flags;
@@ -1343,6 +1362,9 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
ret = drm_syncobj_array_find(file_private,
u64_to_user_ptr(args->handles),
args->count_handles,
+ stack_handles,
+ stack_syncobjs,
+ ARRAY_SIZE(stack_syncobjs),
&syncobjs);
if (ret < 0)
return ret;
@@ -1355,7 +1377,7 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
ret = drm_syncobj_array_wait(dev, file_private,
args, NULL, syncobjs, false, tp);
- drm_syncobj_array_free(syncobjs, args->count_handles);
+ drm_syncobj_array_free(syncobjs, args->count_handles, stack_syncobjs);
return ret;
}
@@ -1364,6 +1386,8 @@ int
drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_private)
{
+ struct drm_syncobj *stack_syncobjs[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
+ uint32_t stack_handles[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
struct drm_syncobj_timeline_wait *args = data;
struct drm_syncobj **syncobjs;
unsigned int possible_flags;
@@ -1387,6 +1411,9 @@ drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
ret = drm_syncobj_array_find(file_private,
u64_to_user_ptr(args->handles),
args->count_handles,
+ stack_handles,
+ stack_syncobjs,
+ ARRAY_SIZE(stack_syncobjs),
&syncobjs);
if (ret < 0)
return ret;
@@ -1399,7 +1426,7 @@ drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
ret = drm_syncobj_array_wait(dev, file_private,
NULL, args, syncobjs, true, tp);
- drm_syncobj_array_free(syncobjs, args->count_handles);
+ drm_syncobj_array_free(syncobjs, args->count_handles, stack_syncobjs);
return ret;
}
@@ -1511,6 +1538,8 @@ int
drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_private)
{
+ struct drm_syncobj *stack_syncobjs[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
+ uint32_t stack_handles[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
struct drm_syncobj_array *args = data;
struct drm_syncobj **syncobjs;
uint32_t i;
@@ -1528,6 +1557,9 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
ret = drm_syncobj_array_find(file_private,
u64_to_user_ptr(args->handles),
args->count_handles,
+ stack_handles,
+ stack_syncobjs,
+ ARRAY_SIZE(stack_syncobjs),
&syncobjs);
if (ret < 0)
return ret;
@@ -1535,7 +1567,7 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
for (i = 0; i < args->count_handles; i++)
drm_syncobj_replace_fence(syncobjs[i], NULL);
- drm_syncobj_array_free(syncobjs, args->count_handles);
+ drm_syncobj_array_free(syncobjs, args->count_handles, stack_syncobjs);
return 0;
}
@@ -1544,6 +1576,8 @@ int
drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_private)
{
+ struct drm_syncobj *stack_syncobjs[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
+ uint32_t stack_handles[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
struct drm_syncobj_array *args = data;
struct drm_syncobj **syncobjs;
uint32_t i;
@@ -1561,6 +1595,9 @@ drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
ret = drm_syncobj_array_find(file_private,
u64_to_user_ptr(args->handles),
args->count_handles,
+ stack_handles,
+ stack_syncobjs,
+ ARRAY_SIZE(stack_syncobjs),
&syncobjs);
if (ret < 0)
return ret;
@@ -1571,7 +1608,7 @@ drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
break;
}
- drm_syncobj_array_free(syncobjs, args->count_handles);
+ drm_syncobj_array_free(syncobjs, args->count_handles, stack_syncobjs);
return ret;
}
@@ -1580,6 +1617,8 @@ int
drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_private)
{
+ struct drm_syncobj *stack_syncobjs[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
+ uint32_t stack_handles[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
struct drm_syncobj_timeline_array *args = data;
struct drm_syncobj **syncobjs;
struct dma_fence_chain **chains;
@@ -1599,6 +1638,9 @@ drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
ret = drm_syncobj_array_find(file_private,
u64_to_user_ptr(args->handles),
args->count_handles,
+ stack_handles,
+ stack_syncobjs,
+ ARRAY_SIZE(stack_syncobjs),
&syncobjs);
if (ret < 0)
return ret;
@@ -1643,7 +1685,7 @@ drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
err_points:
kvfree(points);
out:
- drm_syncobj_array_free(syncobjs, args->count_handles);
+ drm_syncobj_array_free(syncobjs, args->count_handles, stack_syncobjs);
return ret;
}
@@ -1651,6 +1693,8 @@ drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_private)
{
+ struct drm_syncobj *stack_syncobjs[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
+ uint32_t stack_handles[DRM_SYNCOBJ_FAST_PATH_ENTRIES];
struct drm_syncobj_timeline_array *args = data;
struct drm_syncobj **syncobjs;
uint64_t __user *points = u64_to_user_ptr(args->points);
@@ -1669,6 +1713,9 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
ret = drm_syncobj_array_find(file_private,
u64_to_user_ptr(args->handles),
args->count_handles,
+ stack_handles,
+ stack_syncobjs,
+ ARRAY_SIZE(stack_syncobjs),
&syncobjs);
if (ret < 0)
return ret;
@@ -1712,7 +1759,7 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
if (ret)
break;
}
- drm_syncobj_array_free(syncobjs, args->count_handles);
+ drm_syncobj_array_free(syncobjs, args->count_handles, stack_syncobjs);
return ret;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] drm/syncobj: Use vmemdup_array_user in drm_syncobj_array_find
2026-11-17 10:39 ` [PATCH 1/3] drm/syncobj: Use vmemdup_array_user in drm_syncobj_array_find Tvrtko Ursulin
@ 2026-11-17 12:57 ` Maíra Canal
2026-11-17 13:23 ` Christian König
1 sibling, 0 replies; 9+ messages in thread
From: Maíra Canal @ 2026-11-17 12:57 UTC (permalink / raw)
To: Tvrtko Ursulin, dri-devel; +Cc: kernel-dev, Fei Yu, Christian König
On 17/11/26 07:39, Tvrtko Ursulin wrote:
> Using a helper shrinks the code and separating the user and kernel slabs
> is more secure.
>
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reviewed-by: Maíra Canal <mcanal@igalia.com>
Best regards,
- Maíra
> Cc: Fei Yu <fei.yu@intel.com>
> Cc: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/drm/drm_syncobj.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
> index 6cc654641183..663d6cb8dbf8 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c
> @@ -1252,15 +1252,10 @@ static int drm_syncobj_array_find(struct drm_file *file_private,
> if (count_handles > DRM_SYNCOBJ_MAX_HANDLES)
> return -EINVAL;
>
> - handles = kvmalloc_objs(*handles, count_handles);
> - if (handles == NULL)
> - return -ENOMEM;
> -
> - if (copy_from_user(handles, user_handles,
> - sizeof(uint32_t) * count_handles)) {
> - ret = -EFAULT;
> - goto err_free_handles;
> - }
> + handles = vmemdup_array_user(user_handles, count_handles,
> + sizeof(*handles));
> + if (IS_ERR(handles))
> + return PTR_ERR(handles);
>
> syncobjs = kvmalloc_objs(*syncobjs, count_handles);
> if (syncobjs == NULL) {
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] drm/syncobj: Use vmemdup_array_user in drm_syncobj_array_find
2026-11-17 10:39 ` [PATCH 1/3] drm/syncobj: Use vmemdup_array_user in drm_syncobj_array_find Tvrtko Ursulin
2026-11-17 12:57 ` Maíra Canal
@ 2026-11-17 13:23 ` Christian König
1 sibling, 0 replies; 9+ messages in thread
From: Christian König @ 2026-11-17 13:23 UTC (permalink / raw)
To: Tvrtko Ursulin, dri-devel; +Cc: kernel-dev, Fei Yu
On 11/17/26 11:39, Tvrtko Ursulin wrote:
> Using a helper shrinks the code and separating the user and kernel slabs
> is more secure.
>
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
> Cc: Fei Yu <fei.yu@intel.com>
> Cc: Christian König <christian.koenig@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/drm/drm_syncobj.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
> index 6cc654641183..663d6cb8dbf8 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c
> @@ -1252,15 +1252,10 @@ static int drm_syncobj_array_find(struct drm_file *file_private,
> if (count_handles > DRM_SYNCOBJ_MAX_HANDLES)
> return -EINVAL;
>
> - handles = kvmalloc_objs(*handles, count_handles);
> - if (handles == NULL)
> - return -ENOMEM;
> -
> - if (copy_from_user(handles, user_handles,
> - sizeof(uint32_t) * count_handles)) {
> - ret = -EFAULT;
> - goto err_free_handles;
> - }
> + handles = vmemdup_array_user(user_handles, count_handles,
> + sizeof(*handles));
> + if (IS_ERR(handles))
> + return PTR_ERR(handles);
>
> syncobjs = kvmalloc_objs(*syncobjs, count_handles);
> if (syncobjs == NULL) {
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/3] drm/syncobj: Allocation avoiding fast path
2026-11-17 10:39 [PATCH 0/3] drm/syncobj: Allocation avoiding fast path Tvrtko Ursulin
` (2 preceding siblings ...)
2026-11-17 10:39 ` [PATCH 3/3] drm/syncobj: Add a fast path to drm_syncobj_array_find Tvrtko Ursulin
@ 2026-11-18 8:06 ` Yu, Fei
3 siblings, 0 replies; 9+ messages in thread
From: Yu, Fei @ 2026-11-18 8:06 UTC (permalink / raw)
To: tvrtko.ursulin; +Cc: dri-devel, kernel-dev, mcanal, christian.koenig, fei.yu
From: Fei Yu <fei.yu@intel.com>
On 11/17/26 10:39, Tvrtko Ursulin wrote:
> In practice there are multiple DRM syncobj operations (and/or ioctls) per
> rendered frame, and vast majority of them operates on a just a couple of
> handles, or timeline points.
>
> This series adds a fast path to avoid the temporary allocations for those cases.
Tested on next-20261117 (x86_64, KASAN + KASAN_STACK, lockdep,
kmemleak, virtio-gpu in QEMU), base and patched with the same config:
- IGT syncobj_basic, syncobj_wait, syncobj_timeline: 202/202 on both,
identical per subtest, dmesg clean.
- A targeted test for 1..8 handles (both sides of
DRM_SYNCOBJ_FAST_PATH_ENTRIES) on all six array ioctls: success,
-ENOENT with the bad handle at every position, -EFAULT for bad /
partially unmapped handle and point arrays, refcounts balanced;
wait-all / wait-any woken by sw_sync fence callbacks and by
WAIT_FOR_SUBMIT; -ETIME and -EINTR followed by signalling the
fences afterwards (nothing left on the stack entries); 20 s
wait vs. reset/signal/query stress. All pass, no splats, kmemleak
clean.
- The 1M handle limit still holds: 1M real syncobjs succeed on all
six ioctls, 1M + 1 returns -EINVAL.
- Every patch builds with W=1 and sparse clean, i386 too.
Note the series depends on 6ca87397aeeb ("drm/syncobj: Limit the
number of handles and use kvmalloc for user-sized arrays"), which is
in drm-misc-fixes only, so it doesn't apply to drm-misc-next yet.
Reviewed-by: Fei Yu <fei.yu@intel.com>
Tested-by: Fei Yu <fei.yu@intel.com>
Thanks,
Fei
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/3] drm/syncobj: Add a fast path to drm_syncobj_array_wait_timeout
2026-11-17 10:39 ` [PATCH 2/3] drm/syncobj: Add a fast path to drm_syncobj_array_wait_timeout Tvrtko Ursulin
@ 2026-11-18 8:06 ` Yu, Fei
0 siblings, 0 replies; 9+ messages in thread
From: Yu, Fei @ 2026-11-18 8:06 UTC (permalink / raw)
To: tvrtko.ursulin; +Cc: dri-devel, kernel-dev, mcanal, christian.koenig, fei.yu
From: Fei Yu <fei.yu@intel.com>
On 11/17/26 10:39, Tvrtko Ursulin wrote:
> Running the Cyberpunk 2077 benchmark we can observe that waiting on DRM
> sycobjs is relatively hot, but the 96% of the calls are for a single
Nit: "sycobjs" -> "syncobjs".
> Therefore lets add a fast path to bypass the kcalloc/kfree and use a pre-
> allocated stack array for those cases.
These are kvmalloc_objs()/kvzalloc_objs() and kvfree() by now.
The stack entries are always unlinked in cleanup_entries before the
function returns, so their lifetime is the same as the kvfree'd array
before.
Reviewed-by: Fei Yu <fei.yu@intel.com>
Thanks,
Fei
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] drm/syncobj: Add a fast path to drm_syncobj_array_find
2026-11-17 10:39 ` [PATCH 3/3] drm/syncobj: Add a fast path to drm_syncobj_array_find Tvrtko Ursulin
@ 2026-11-18 8:06 ` Yu, Fei
0 siblings, 0 replies; 9+ messages in thread
From: Yu, Fei @ 2026-11-18 8:06 UTC (permalink / raw)
To: tvrtko.ursulin; +Cc: dri-devel, kernel-dev, mcanal, christian.koenig, fei.yu
From: Fei Yu <fei.yu@intel.com>
On 11/17/26 10:39, Tvrtko Ursulin wrote:
> Therefore lets add a fast path to bypass the kmalloc_array/kfree and use a
> pre-allocated stack array for those cases.
Same as in 2/3, it's vmemdup_array_user()/kvmalloc_objs() now.
> @@ -1265,6 +1265,9 @@ static int drm_syncobj_array_wait(struct drm_device *dev,
> static int drm_syncobj_array_find(struct drm_file *file_private,
> void __user *user_handles,
> uint32_t count_handles,
> + uint32_t *stack_handles,
> + struct drm_syncobj **stack_syncobjs,
> + u32 stack_count,
> struct drm_syncobj ***syncobjs_out)
The handles array is freed before drm_syncobj_array_find() returns,
so the callers don't need to provide it. A local
"u32 stack_handles[DRM_SYNCOBJ_FAST_PATH_ENTRIES]" in
drm_syncobj_array_find() would do, and the six callers would only
declare and pass stack_syncobjs. Not a must, but it saves some
boilerplate. (Also u32 vs. uint32_t is mixed here.)
> - syncobjs = kvmalloc_objs(*syncobjs, count_handles);
> - if (syncobjs == NULL) {
> - ret = -ENOMEM;
> - goto err_free_handles;
> + syncobjs = kvmalloc_objs(*syncobjs, count_handles);;
Double semicolon (checkpatch warns).
The DRM_SYNCOBJ_MAX_HANDLES check stays in front of the fast/slow
split, good. With the ";;" fixed:
Reviewed-by: Fei Yu <fei.yu@intel.com>
Thanks,
Fei
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-18 8:01 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 10:39 [PATCH 0/3] drm/syncobj: Allocation avoiding fast path Tvrtko Ursulin
2026-11-17 10:39 ` [PATCH 1/3] drm/syncobj: Use vmemdup_array_user in drm_syncobj_array_find Tvrtko Ursulin
2026-11-17 12:57 ` Maíra Canal
2026-11-17 13:23 ` Christian König
2026-11-17 10:39 ` [PATCH 2/3] drm/syncobj: Add a fast path to drm_syncobj_array_wait_timeout Tvrtko Ursulin
2026-11-18 8:06 ` Yu, Fei
2026-11-17 10:39 ` [PATCH 3/3] drm/syncobj: Add a fast path to drm_syncobj_array_find Tvrtko Ursulin
2026-11-18 8:06 ` Yu, Fei
2026-11-18 8:06 ` [PATCH 0/3] drm/syncobj: Allocation avoiding fast path Yu, Fei
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.