* [RFC PATCH] drm: Add support for io_uring's uring_cmd in DRM/accel
@ 2025-06-06 18:08 Zack McKevitt
2025-06-07 3:52 ` kernel test robot
2025-06-07 6:18 ` kernel test robot
0 siblings, 2 replies; 4+ messages in thread
From: Zack McKevitt @ 2025-06-06 18:08 UTC (permalink / raw)
To: airlied, simona, dri-devel; +Cc: jeff.hugo, Liviu.Dudau, Zack McKevitt
Add a callback function for uring_cmd to support the io_uring
interface in DRM devices. The drm_uring_cmd() function allows
for dispatching ioctls to DRM devices. If the uring_cmd
callback is specified in the device's file_operations structure,
the SQE cmd_op field can be set to DRM_URING_CMD_IOCTL to issue
ioctls to that device from the ring.
Additionally, create a 16 byte drm_uring_cmd_ioctl struct that
contains traditional ioctl argument values, such as the device
specific ioctl command and an optional argument pointer, that
can be passed directly to the callback function through the SQE's
16 byte command field. This design allows io_uring to handle
ioctls seamlessly for DRM/accel devices without requiring any
updates to existing drivers.
Initial benchmarks on our Qualcomm Cloud AI 100 device show
speedups of 50% in ioctl execution time in the best case for
large batches of ioctls (128) issued together via drm_uring_cmd()
compared to issuing these ioctls directly.
Signed-off-by: Zack McKevitt <zachary.mckevitt@oss.qualcomm.com>
---
When issuing a batch of ioctl commands to a device, many context
switches are performed. To minimize this overhead, we propose using
io_uring to submit large batches of ioctl commands to a device all
at once. Instead of calling ioctls directly, io_uring provides a
uring_cmd calback that may be specified within any file or device's
file_operations structure that may be invoked by the ring.
For DRM devices that may need to issue large amounts of ioctls, we
believe performance can be improved by placing uring_cmds to issue
these ioctls in the ring and submitting them all at once.
This patch does not update the file_operations to include the
uring_cmd callback function for all DRM devices. However, this may
be easily done in the future without requiring modifications to
existing drivers. Furthermore, this design could be extended
to define new op codes within the drm_uring_cmd() callback which
would allow for more customized handling, assuming individual
driver support.
This patch was inspired by the talk "io_uring for DRM" at XDC 2024.
Thanks in advance for any feedback.
Zack
drivers/gpu/drm/drm_ioctl.c | 30 ++++++++++++++++++++++++++++++
include/drm/drm_accel.h | 3 ++-
include/drm/drm_ioctl.h | 3 +++
include/uapi/drm/drm.h | 22 ++++++++++++++++++++++
4 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index f593dc569d31..c57c21cc16ec 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -39,6 +39,7 @@
#include <drm/drm_file.h>
#include <drm/drm_ioctl.h>
#include <drm/drm_print.h>
+#include <uapi/drm/drm.h>
#include "drm_crtc_internal.h"
#include "drm_internal.h"
@@ -936,3 +937,32 @@ bool drm_ioctl_flags(unsigned int nr, unsigned int *flags)
return true;
}
EXPORT_SYMBOL(drm_ioctl_flags);
+
+/**
+ * drm_uring_cmd - Implement uring_cmd callback for io_uring
+ * @cmd: pointer to io_uring_cmd struct
+ * @issue_flags: flags specified by io_uring's issue implementation
+ *
+ * This function implements the uring_cmd file operation to incorporate
+ * arbitrary io_uring functionality for drm. Currently, it acts as a way
+ * for io_uring to issue ioctls to a drm device, so this function
+ * dispatches ioctls to the standard drm ioctl interface.
+ *
+ * Returns:
+ * Zero on success, negative error code on failure.
+ */
+int drm_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
+{
+ switch (cmd->cmd_op) {
+ case DRM_URING_CMD_IOCTL:
+ const struct drm_uring_cmd_ioctl *drm_cmd = io_uring_sqe_cmd(cmd->sqe);
+ unsigned int ioctl_cmd = drm_cmd->ioctl_cmd;
+ unsigned long ioctl_arg = drm_cmd->arg;
+ struct file *filp = cmd->file;
+
+ return drm_ioctl(filp, ioctl_cmd, ioctl_arg);
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+EXPORT_SYMBOL(drm_uring_cmd);
diff --git a/include/drm/drm_accel.h b/include/drm/drm_accel.h
index 038ccb02f9a3..4f923e101a06 100644
--- a/include/drm/drm_accel.h
+++ b/include/drm/drm_accel.h
@@ -29,7 +29,8 @@
.read = drm_read,\
.llseek = noop_llseek, \
.mmap = drm_gem_mmap, \
- .fop_flags = FOP_UNSIGNED_OFFSET
+ .fop_flags = FOP_UNSIGNED_OFFSET, \
+ .uring_cmd = drm_uring_cmd
/**
* DEFINE_DRM_ACCEL_FOPS() - macro to generate file operations for accelerators drivers
diff --git a/include/drm/drm_ioctl.h b/include/drm/drm_ioctl.h
index 171760b6c4a1..cbb474254e1c 100644
--- a/include/drm/drm_ioctl.h
+++ b/include/drm/drm_ioctl.h
@@ -34,6 +34,7 @@
#include <linux/types.h>
#include <linux/bitops.h>
+#include <linux/io_uring/cmd.h>
#include <asm/ioctl.h>
@@ -171,4 +172,6 @@ int drm_noop(struct drm_device *dev, void *data,
int drm_invalid_op(struct drm_device *dev, void *data,
struct drm_file *file_priv);
+int drm_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags);
+
#endif /* _DRM_IOCTL_H_ */
diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index e63a71d3c607..9316470f1286 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -1385,6 +1385,28 @@ struct drm_event_crtc_sequence {
__u64 sequence;
};
+/**
+ * enum drm_uring_cmd_op - Opcodes for io_uring based drm_uring_cmd callback
+ * DRM_URING_CMD_IOCTL - issue DRM ioctl from drm_uring_cmd
+ */
+enum drm_uring_cmd_op {
+ DRM_URING_CMD_IOCTL = 1,
+};
+
+/**
+ * struct drm_uring_cmd_ioctl - arguments for DRM_URING_CMD_IOCTL
+ */
+struct drm_uring_cmd_ioctl {
+ /* Device specific ioctl number */
+ __u32 ioctl_cmd;
+
+ /* Pad to 16 byte SQE cmd */
+ __u32 pad;
+
+ /* Opaque ioctl argument pointer */
+ __u64 arg;
+};
+
/* typedef area */
#ifndef __KERNEL__
typedef struct drm_clip_rect drm_clip_rect_t;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC PATCH] drm: Add support for io_uring's uring_cmd in DRM/accel
2025-06-06 18:08 [RFC PATCH] drm: Add support for io_uring's uring_cmd in DRM/accel Zack McKevitt
@ 2025-06-07 3:52 ` kernel test robot
2025-06-07 6:18 ` kernel test robot
1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2025-06-07 3:52 UTC (permalink / raw)
To: Zack McKevitt; +Cc: llvm, oe-kbuild-all
Hi Zack,
[This is a private test report for your RFC patch.]
kernel test robot noticed the following build warnings:
[auto build test WARNING on drm-exynos/exynos-drm-next]
[also build test WARNING on linus/master v6.15 next-20250606]
[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/Zack-McKevitt/drm-Add-support-for-io_uring-s-uring_cmd-in-DRM-accel/20250607-021118
base: https://git.kernel.org/pub/scm/linux/kernel/git/daeinki/drm-exynos.git exynos-drm-next
patch link: https://lore.kernel.org/r/20250606180806.2193463-1-zachary.mckevitt%40oss.qualcomm.com
patch subject: [RFC PATCH] drm: Add support for io_uring's uring_cmd in DRM/accel
config: x86_64-buildonly-randconfig-001-20250607 (https://download.01.org/0day-ci/archive/20250607/202506071127.wjaerC3q-lkp@intel.com/config)
compiler: clang version 20.1.2 (https://github.com/llvm/llvm-project 58df0ef89dd64126512e4ee27b4ac3fd8ddf6247)
rustc: rustc 1.78.0 (9b00956e5 2024-04-29)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250607/202506071127.wjaerC3q-lkp@intel.com/reproduce)
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>
| Closes: https://lore.kernel.org/oe-kbuild-all/202506071127.wjaerC3q-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> drivers/gpu/drm/drm_ioctl.c:958:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
958 | const struct drm_uring_cmd_ioctl *drm_cmd = io_uring_sqe_cmd(cmd->sqe);
| ^
1 warning generated.
vim +958 drivers/gpu/drm/drm_ioctl.c
940
941 /**
942 * drm_uring_cmd - Implement uring_cmd callback for io_uring
943 * @cmd: pointer to io_uring_cmd struct
944 * @issue_flags: flags specified by io_uring's issue implementation
945 *
946 * This function implements the uring_cmd file operation to incorporate
947 * arbitrary io_uring functionality for drm. Currently, it acts as a way
948 * for io_uring to issue ioctls to a drm device, so this function
949 * dispatches ioctls to the standard drm ioctl interface.
950 *
951 * Returns:
952 * Zero on success, negative error code on failure.
953 */
954 int drm_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
955 {
956 switch (cmd->cmd_op) {
957 case DRM_URING_CMD_IOCTL:
> 958 const struct drm_uring_cmd_ioctl *drm_cmd = io_uring_sqe_cmd(cmd->sqe);
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC PATCH] drm: Add support for io_uring's uring_cmd in DRM/accel
2025-06-06 18:08 [RFC PATCH] drm: Add support for io_uring's uring_cmd in DRM/accel Zack McKevitt
2025-06-07 3:52 ` kernel test robot
@ 2025-06-07 6:18 ` kernel test robot
1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2025-06-07 6:18 UTC (permalink / raw)
To: Zack McKevitt; +Cc: llvm, oe-kbuild-all
Hi Zack,
[This is a private test report for your RFC patch.]
kernel test robot noticed the following build errors:
[auto build test ERROR on drm-exynos/exynos-drm-next]
[also build test ERROR on linus/master v6.15 next-20250606]
[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/Zack-McKevitt/drm-Add-support-for-io_uring-s-uring_cmd-in-DRM-accel/20250607-021118
base: https://git.kernel.org/pub/scm/linux/kernel/git/daeinki/drm-exynos.git exynos-drm-next
patch link: https://lore.kernel.org/r/20250606180806.2193463-1-zachary.mckevitt%40oss.qualcomm.com
patch subject: [RFC PATCH] drm: Add support for io_uring's uring_cmd in DRM/accel
config: riscv-randconfig-002-20250607 (https://download.01.org/0day-ci/archive/20250607/202506071421.2BsXneKu-lkp@intel.com/config)
compiler: clang version 16.0.6 (https://github.com/llvm/llvm-project 7cbf1a2591520c2491aa35339f227775f4d3adf6)
rustc: rustc 1.78.0 (9b00956e5 2024-04-29)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250607/202506071421.2BsXneKu-lkp@intel.com/reproduce)
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>
| Closes: https://lore.kernel.org/oe-kbuild-all/202506071421.2BsXneKu-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/gpu/drm/drm_ioctl.c:958:3: error: expected expression
const struct drm_uring_cmd_ioctl *drm_cmd = io_uring_sqe_cmd(cmd->sqe);
^
>> drivers/gpu/drm/drm_ioctl.c:959:28: error: use of undeclared identifier 'drm_cmd'
unsigned int ioctl_cmd = drm_cmd->ioctl_cmd;
^
drivers/gpu/drm/drm_ioctl.c:960:29: error: use of undeclared identifier 'drm_cmd'
unsigned long ioctl_arg = drm_cmd->arg;
^
3 errors generated.
vim +958 drivers/gpu/drm/drm_ioctl.c
940
941 /**
942 * drm_uring_cmd - Implement uring_cmd callback for io_uring
943 * @cmd: pointer to io_uring_cmd struct
944 * @issue_flags: flags specified by io_uring's issue implementation
945 *
946 * This function implements the uring_cmd file operation to incorporate
947 * arbitrary io_uring functionality for drm. Currently, it acts as a way
948 * for io_uring to issue ioctls to a drm device, so this function
949 * dispatches ioctls to the standard drm ioctl interface.
950 *
951 * Returns:
952 * Zero on success, negative error code on failure.
953 */
954 int drm_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
955 {
956 switch (cmd->cmd_op) {
957 case DRM_URING_CMD_IOCTL:
> 958 const struct drm_uring_cmd_ioctl *drm_cmd = io_uring_sqe_cmd(cmd->sqe);
> 959 unsigned int ioctl_cmd = drm_cmd->ioctl_cmd;
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC PATCH] drm: Add support for io_uring's uring_cmd in DRM/accel
@ 2025-06-07 19:34 kernel test robot
0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2025-06-07 19:34 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp, Dan Carpenter
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20250606180806.2193463-1-zachary.mckevitt@oss.qualcomm.com>
References: <20250606180806.2193463-1-zachary.mckevitt@oss.qualcomm.com>
TO: Zack McKevitt <zachary.mckevitt@oss.qualcomm.com>
Hi Zack,
[This is a private test report for your RFC patch.]
kernel test robot noticed the following build warnings:
[auto build test WARNING on drm-exynos/exynos-drm-next]
[also build test WARNING on linus/master v6.15 next-20250606]
[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/Zack-McKevitt/drm-Add-support-for-io_uring-s-uring_cmd-in-DRM-accel/20250607-021118
base: https://git.kernel.org/pub/scm/linux/kernel/git/daeinki/drm-exynos.git exynos-drm-next
patch link: https://lore.kernel.org/r/20250606180806.2193463-1-zachary.mckevitt%40oss.qualcomm.com
patch subject: [RFC PATCH] drm: Add support for io_uring's uring_cmd in DRM/accel
:::::: branch date: 25 hours ago
:::::: commit date: 25 hours ago
config: x86_64-randconfig-161-20250607 (https://download.01.org/0day-ci/archive/20250608/202506080322.Lsc4bCGT-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
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/202506080322.Lsc4bCGT-lkp@intel.com/
smatch warnings:
drivers/gpu/drm/drm_ioctl.c:958 drm_uring_cmd() warn: statement has no effect 'const'
vim +/const +958 drivers/gpu/drm/drm_ioctl.c
09504f8ef576ed Zack McKevitt 2025-06-06 940
09504f8ef576ed Zack McKevitt 2025-06-06 941 /**
09504f8ef576ed Zack McKevitt 2025-06-06 942 * drm_uring_cmd - Implement uring_cmd callback for io_uring
09504f8ef576ed Zack McKevitt 2025-06-06 943 * @cmd: pointer to io_uring_cmd struct
09504f8ef576ed Zack McKevitt 2025-06-06 944 * @issue_flags: flags specified by io_uring's issue implementation
09504f8ef576ed Zack McKevitt 2025-06-06 945 *
09504f8ef576ed Zack McKevitt 2025-06-06 946 * This function implements the uring_cmd file operation to incorporate
09504f8ef576ed Zack McKevitt 2025-06-06 947 * arbitrary io_uring functionality for drm. Currently, it acts as a way
09504f8ef576ed Zack McKevitt 2025-06-06 948 * for io_uring to issue ioctls to a drm device, so this function
09504f8ef576ed Zack McKevitt 2025-06-06 949 * dispatches ioctls to the standard drm ioctl interface.
09504f8ef576ed Zack McKevitt 2025-06-06 950 *
09504f8ef576ed Zack McKevitt 2025-06-06 951 * Returns:
09504f8ef576ed Zack McKevitt 2025-06-06 952 * Zero on success, negative error code on failure.
09504f8ef576ed Zack McKevitt 2025-06-06 953 */
09504f8ef576ed Zack McKevitt 2025-06-06 954 int drm_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
09504f8ef576ed Zack McKevitt 2025-06-06 955 {
09504f8ef576ed Zack McKevitt 2025-06-06 956 switch (cmd->cmd_op) {
09504f8ef576ed Zack McKevitt 2025-06-06 957 case DRM_URING_CMD_IOCTL:
09504f8ef576ed Zack McKevitt 2025-06-06 @958 const struct drm_uring_cmd_ioctl *drm_cmd = io_uring_sqe_cmd(cmd->sqe);
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-07 19:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-06 18:08 [RFC PATCH] drm: Add support for io_uring's uring_cmd in DRM/accel Zack McKevitt
2025-06-07 3:52 ` kernel test robot
2025-06-07 6:18 ` kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2025-06-07 19:34 kernel test robot
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.