* [PATCH 3/3] drm/syncobj: Add a fast path to drm_syncobj_array_find
2025-11-06 13:26 [PATCH 0/3] DRM syncobj wait fast path Tvrtko Ursulin
@ 2025-11-06 13:26 ` Tvrtko Ursulin
0 siblings, 0 replies; 11+ messages in thread
From: Tvrtko Ursulin @ 2025-11-06 13:26 UTC (permalink / raw)
To: dri-devel; +Cc: kernel-dev, Tvrtko Ursulin, Maíra Canal
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
---
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.
---
drivers/gpu/drm/drm_syncobj.c | 92 +++++++++++++++++++++++++++--------
1 file changed, 73 insertions(+), 19 deletions(-)
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index 99aada85865d..ba64119a664c 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -1310,21 +1310,33 @@ 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;
struct drm_syncobj **syncobjs;
int ret;
- handles = memdup_array_user(user_handles, count_handles,
- sizeof(*handles));
- if (IS_ERR(handles))
- return PTR_ERR(handles);
+ if (count_handles > stack_count) {
+ handles = memdup_array_user(user_handles, count_handles,
+ sizeof(*handles));
+ if (IS_ERR(handles))
+ return PTR_ERR(handles);
- syncobjs = kmalloc_array(count_handles, sizeof(*syncobjs), GFP_KERNEL);
- if (syncobjs == NULL) {
- ret = -ENOMEM;
- goto err_free_handles;
+ syncobjs = kmalloc_array(count_handles, sizeof(*syncobjs),
+ GFP_KERNEL);
+ 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++) {
@@ -1335,34 +1347,42 @@ static int drm_syncobj_array_find(struct drm_file *file_private,
}
}
- kfree(handles);
+ if (handles != stack_handles)
+ kfree(handles);
*syncobjs_out = syncobjs;
return 0;
err_put_syncobjs:
while (i-- > 0)
drm_syncobj_put(syncobjs[i]);
- kfree(syncobjs);
+ if (syncobjs != stack_syncobjs)
+ kfree(syncobjs);
err_free_handles:
- kfree(handles);
+ if (handles != stack_handles)
+ kfree(handles);
return ret;
}
static void drm_syncobj_array_free(struct drm_syncobj **syncobjs,
- uint32_t count)
+ uint32_t count,
+ bool free_container)
{
uint32_t i;
for (i = 0; i < count; i++)
drm_syncobj_put(syncobjs[i]);
- kfree(syncobjs);
+
+ if (free_container)
+ kfree(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;
@@ -1385,6 +1405,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;
@@ -1397,7 +1420,8 @@ 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,
+ syncobjs != stack_syncobjs);
return ret;
}
@@ -1406,6 +1430,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;
@@ -1429,6 +1455,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;
@@ -1441,7 +1470,8 @@ 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,
+ syncobjs != stack_syncobjs);
return ret;
}
@@ -1553,6 +1583,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;
@@ -1570,6 +1602,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;
@@ -1577,7 +1612,8 @@ 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,
+ syncobjs != stack_syncobjs);
return 0;
}
@@ -1586,6 +1622,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;
@@ -1603,6 +1641,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;
@@ -1613,7 +1654,8 @@ 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,
+ syncobjs != stack_syncobjs);
return ret;
}
@@ -1622,6 +1664,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;
@@ -1641,6 +1685,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;
@@ -1686,7 +1733,8 @@ drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
err_points:
kfree(points);
out:
- drm_syncobj_array_free(syncobjs, args->count_handles);
+ drm_syncobj_array_free(syncobjs, args->count_handles,
+ syncobjs != stack_syncobjs);
return ret;
}
@@ -1694,6 +1742,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);
@@ -1712,6 +1762,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;
@@ -1755,7 +1808,8 @@ 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,
+ syncobjs != stack_syncobjs);
return ret;
}
--
2.48.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 3/3] drm/syncobj: Add a fast path to drm_syncobj_array_find
@ 2025-11-10 15:11 kernel test robot
0 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2025-11-10 15:11 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp, Dan Carpenter
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20251106132645.28208-4-tvrtko.ursulin@igalia.com>
References: <20251106132645.28208-4-tvrtko.ursulin@igalia.com>
TO: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
TO: dri-devel@lists.freedesktop.org
CC: kernel-dev@igalia.com
CC: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
CC: "Maíra Canal" <mcanal@igalia.com>
Hi Tvrtko,
kernel test robot noticed the following build warnings:
[auto build test WARNING on drm/drm-next]
[also build test WARNING on drm-exynos/exynos-drm-next drm-intel/for-linux-next drm-intel/for-linux-next-fixes drm-misc/drm-misc-next drm-tip/drm-tip linus/master v6.18-rc5 next-20251110]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Tvrtko-Ursulin/drm-syncobj-Use-vmemdup_array_user-in-drm_syncobj_array_find/20251106-212904
base: git://anongit.freedesktop.org/drm/drm drm-next
patch link: https://lore.kernel.org/r/20251106132645.28208-4-tvrtko.ursulin%40igalia.com
patch subject: [PATCH 3/3] drm/syncobj: Add a fast path to drm_syncobj_array_find
:::::: branch date: 4 days ago
:::::: commit date: 4 days ago
config: i386-randconfig-141-20251110 (https://download.01.org/0day-ci/archive/20251110/202511102233.GPoKgaPv-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202511102233.GPoKgaPv-lkp@intel.com/
smatch warnings:
drivers/gpu/drm/drm_syncobj.c:1339 drm_syncobj_array_find() warn: missing unwind goto?
vim +1339 drivers/gpu/drm/drm_syncobj.c
5e60a10eaebab9 Dave Airlie 2017-08-25 1309
3e6fb72d6cef6a Faith Ekstrand 2017-08-25 1310 static int drm_syncobj_array_find(struct drm_file *file_private,
9e5544627339ec Ville Syrjälä 2017-09-01 1311 void __user *user_handles,
9e5544627339ec Ville Syrjälä 2017-09-01 1312 uint32_t count_handles,
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1313 uint32_t *stack_handles,
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1314 struct drm_syncobj **stack_syncobjs,
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1315 u32 stack_count,
3e6fb72d6cef6a Faith Ekstrand 2017-08-25 1316 struct drm_syncobj ***syncobjs_out)
5e60a10eaebab9 Dave Airlie 2017-08-25 1317 {
3e6fb72d6cef6a Faith Ekstrand 2017-08-25 1318 uint32_t i, *handles;
e7aca5031a2fb5 Faith Ekstrand 2017-08-25 1319 struct drm_syncobj **syncobjs;
3e6fb72d6cef6a Faith Ekstrand 2017-08-25 1320 int ret;
5e60a10eaebab9 Dave Airlie 2017-08-25 1321
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1322 if (count_handles > stack_count) {
b4ebe6f6bf86ff Tvrtko Ursulin 2025-11-06 1323 handles = memdup_array_user(user_handles, count_handles,
b4ebe6f6bf86ff Tvrtko Ursulin 2025-11-06 1324 sizeof(*handles));
b4ebe6f6bf86ff Tvrtko Ursulin 2025-11-06 1325 if (IS_ERR(handles))
b4ebe6f6bf86ff Tvrtko Ursulin 2025-11-06 1326 return PTR_ERR(handles);
5e60a10eaebab9 Dave Airlie 2017-08-25 1327
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1328 syncobjs = kmalloc_array(count_handles, sizeof(*syncobjs),
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1329 GFP_KERNEL);
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1330 if (!syncobjs) {
5e60a10eaebab9 Dave Airlie 2017-08-25 1331 ret = -ENOMEM;
5e60a10eaebab9 Dave Airlie 2017-08-25 1332 goto err_free_handles;
5e60a10eaebab9 Dave Airlie 2017-08-25 1333 }
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1334 } else {
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1335 handles = stack_handles;
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1336 syncobjs = stack_syncobjs;
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1337 if (copy_from_user(handles, user_handles,
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1338 count_handles * sizeof(*handles)))
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 @1339 return -EFAULT;
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1340 }
5e60a10eaebab9 Dave Airlie 2017-08-25 1341
3e6fb72d6cef6a Faith Ekstrand 2017-08-25 1342 for (i = 0; i < count_handles; i++) {
e7aca5031a2fb5 Faith Ekstrand 2017-08-25 1343 syncobjs[i] = drm_syncobj_find(file_private, handles[i]);
e7aca5031a2fb5 Faith Ekstrand 2017-08-25 1344 if (!syncobjs[i]) {
e7aca5031a2fb5 Faith Ekstrand 2017-08-25 1345 ret = -ENOENT;
3e6fb72d6cef6a Faith Ekstrand 2017-08-25 1346 goto err_put_syncobjs;
5e60a10eaebab9 Dave Airlie 2017-08-25 1347 }
e7aca5031a2fb5 Faith Ekstrand 2017-08-25 1348 }
5e60a10eaebab9 Dave Airlie 2017-08-25 1349
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1350 if (handles != stack_handles)
3e6fb72d6cef6a Faith Ekstrand 2017-08-25 1351 kfree(handles);
3e6fb72d6cef6a Faith Ekstrand 2017-08-25 1352 *syncobjs_out = syncobjs;
3e6fb72d6cef6a Faith Ekstrand 2017-08-25 1353 return 0;
5e60a10eaebab9 Dave Airlie 2017-08-25 1354
3e6fb72d6cef6a Faith Ekstrand 2017-08-25 1355 err_put_syncobjs:
e7aca5031a2fb5 Faith Ekstrand 2017-08-25 1356 while (i-- > 0)
e7aca5031a2fb5 Faith Ekstrand 2017-08-25 1357 drm_syncobj_put(syncobjs[i]);
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1358 if (syncobjs != stack_syncobjs)
e7aca5031a2fb5 Faith Ekstrand 2017-08-25 1359 kfree(syncobjs);
5e60a10eaebab9 Dave Airlie 2017-08-25 1360 err_free_handles:
6cbb5aa2c8c162 Tvrtko Ursulin 2025-11-06 1361 if (handles != stack_handles)
5e60a10eaebab9 Dave Airlie 2017-08-25 1362 kfree(handles);
5e60a10eaebab9 Dave Airlie 2017-08-25 1363
5e60a10eaebab9 Dave Airlie 2017-08-25 1364 return ret;
5e60a10eaebab9 Dave Airlie 2017-08-25 1365 }
3e6fb72d6cef6a Faith Ekstrand 2017-08-25 1366
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 11+ messages in thread
* [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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ messages in thread
end of thread, other threads:[~2026-11-18 8:01 UTC | newest]
Thread overview: 11+ 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
-- strict thread matches above, loose matches on Subject: below --
2025-11-10 15:11 [PATCH 3/3] drm/syncobj: Add a fast path to drm_syncobj_array_find kernel test robot
2025-11-06 13:26 [PATCH 0/3] DRM syncobj wait fast path Tvrtko Ursulin
2025-11-06 13:26 ` [PATCH 3/3] drm/syncobj: Add a fast path to drm_syncobj_array_find Tvrtko Ursulin
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.