From: Wei Huang <wei.huang2@amd.com>
To: <dmaengine@vger.kernel.org>
Cc: <vkoul@kernel.org>, <Frank.Li@kernel.org>, <shuah@kernel.org>,
<nathan.lynch@amd.com>, <wei.huang2@amd.com>,
<mario.limonciello@amd.com>, <Stephen.Bates@amd.com>,
<tycho@kernel.org>, <suravee.suthikulpanit@amd.com>,
<rientjes@google.com>, <John.Kariuki@amd.com>, <jic23@kernel.org>,
<weixugc@google.com>, <bhelgaas@google.com>,
<Shyam.Iyer@dell.com>, <linux-kernel@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <linux-pci@vger.kernel.org>
Subject: [PATCH v1 23/44] dmaengine: sdxi: implement typed vendor admin transport
Date: Thu, 19 Nov 2026 14:22:59 -0600 [thread overview]
Message-ID: <20261119202321.1734355-24-wei.huang2@amd.com> (raw)
In-Reply-To: <20261119202321.1734355-1-wei.huang2@amd.com>
SDXI allows vendors to define vendor-specific descriptors. Add a
module-pinned GUID handler registry and a typed vendor ioctl that never
accepts raw descriptors from userspace. It probes the vendor's opcode
through SDXI discovery, delegates authorization to the registered
handler, and keeps execution on the kernel-owned admin context.
Signed-off-by: Wei Huang <wei.huang2@amd.com>
---
drivers/dma/sdxi/Makefile | 3 +-
drivers/dma/sdxi/ioctl.c | 107 +++++++++++++++++++++++------
drivers/dma/sdxi/vendor.c | 138 ++++++++++++++++++++++++++++++++++++++
drivers/dma/sdxi/vendor.h | 42 ++++++++++++
4 files changed, 270 insertions(+), 20 deletions(-)
create mode 100644 drivers/dma/sdxi/vendor.c
create mode 100644 drivers/dma/sdxi/vendor.h
diff --git a/drivers/dma/sdxi/Makefile b/drivers/dma/sdxi/Makefile
index a9eaf01df4aa..253398a45c74 100644
--- a/drivers/dma/sdxi/Makefile
+++ b/drivers/dma/sdxi/Makefile
@@ -12,7 +12,8 @@ sdxi-core-y := \
ioctl.o \
keys.o \
process.o \
- ring.o
+ ring.o \
+ vendor.o
obj-$(CONFIG_SDXI_PCI) += sdxi-pci.o
sdxi-pci-y := pci.o
diff --git a/drivers/dma/sdxi/ioctl.c b/drivers/dma/sdxi/ioctl.c
index 80648bed0e87..feef322a005e 100644
--- a/drivers/dma/sdxi/ioctl.c
+++ b/drivers/dma/sdxi/ioctl.c
@@ -36,6 +36,7 @@
#include "mmio.h"
#include "process.h"
#include "sdxi.h"
+#include "vendor.h"
#define SDXI_MAX_MINORS 256
@@ -75,12 +76,6 @@ static int sdxi_file_check_owner(const struct sdxi_process *process)
return 0;
}
-static int sdxi_ioctl_unsupported(struct file *file, struct sdxi_file *sf,
- void *data)
-{
- return -EOPNOTSUPP;
-}
-
static int sdxi_ioctl_get_uapi_info(struct file *file, struct sdxi_file *sf,
void *data)
{
@@ -101,7 +96,8 @@ static int sdxi_ioctl_get_uapi_info(struct file *file, struct sdxi_file *sf,
SDXI_UAPI_CAP_CXT_CREATE |
SDXI_UAPI_CAP_CXT_EVENTFD |
SDXI_UAPI_CAP_AKEY_MGMT |
- SDXI_UAPI_CAP_ADMIN_DISC,
+ SDXI_UAPI_CAP_ADMIN_DISC |
+ SDXI_UAPI_CAP_ADMIN_VENDOR,
},
};
@@ -721,6 +717,59 @@ static int sdxi_ioctl_admin_disc(struct file *file, struct sdxi_file *sf,
return ret;
}
+static bool
+sdxi_admin_vendor_reserved_zero(const struct sdxi_admin_vendor_args *args)
+{
+ return !args->flags && !args->rsvd0 && !args->rsvd1 &&
+ sdxi_u32_array_zero(args->rsvd2, ARRAY_SIZE(args->rsvd2));
+}
+
+static unsigned int sdxi_admin_timeout(u32 timeout_ms)
+{
+ return clamp_val(timeout_ms ?: 5000U, 1U, 60000U);
+}
+
+static int sdxi_ioctl_admin_vendor(struct file *file, struct sdxi_file *sf,
+ void *data)
+{
+ struct sdxi_admin_vendor_args *args = data;
+ const struct sdxi_vendor_handler *handler;
+ struct sdxi_dev *sdxi = sf->process->sdxi;
+ unsigned int timeout_ms;
+ u16 opcode_type;
+ int ret;
+
+ if (args->argsz < sizeof(*args) ||
+ !sdxi_admin_vendor_reserved_zero(args))
+ return -EINVAL;
+
+ args->argsz = sizeof(*args);
+ args->cst_flags = 0;
+ timeout_ms = sdxi_admin_timeout(args->timeout_ms);
+
+ ret = sdxi_vendor_get(args->guid, &handler);
+ if (ret)
+ return ret;
+
+ ret = sdxi_vendor_find_opcode_type(sdxi, args->guid, timeout_ms,
+ &opcode_type);
+ if (ret)
+ goto put_handler;
+
+ if (args->op == SDXI_ADMIN_VENDOR_PROBE) {
+ if (args->in_size || args->in_uptr ||
+ args->out_size || args->out_uptr)
+ ret = -EINVAL;
+ goto put_handler;
+ }
+
+ ret = handler->ops->exec(sdxi, opcode_type, args, timeout_ms);
+
+put_handler:
+ sdxi_vendor_put(handler);
+ return ret;
+}
+
#define SDXI_IOCTL_DEF(_nr, _cmd, _func, _files, _access) \
[_nr] = { \
.cmd = (_cmd), \
@@ -759,25 +808,41 @@ static const struct sdxi_ioctl_desc sdxi_ioctls[] = {
SDXI_IOCTL_F_CONTEXT, SDXI_IOCTL_A_CONTEXT_OWNER),
SDXI_IOCTL_DEF(0x0d, SDXI_ADMIN_DISC, sdxi_ioctl_admin_disc,
SDXI_IOCTL_F_DEVICE, SDXI_IOCTL_A_PUBLIC_DEVICE),
- SDXI_IOCTL_DEF(0x0e, SDXI_ADMIN_VENDOR, sdxi_ioctl_unsupported,
+ SDXI_IOCTL_DEF(0x0e, SDXI_ADMIN_VENDOR, sdxi_ioctl_admin_vendor,
SDXI_IOCTL_F_DEVICE, SDXI_IOCTL_A_VENDOR_HANDLER),
SDXI_IOCTL_DEF(0x0f, SDXI_QUIESCE_CXT, sdxi_ioctl_quiesce_cxt,
SDXI_IOCTL_F_CONTEXT, SDXI_IOCTL_A_CONTEXT_OWNER),
};
-static int sdxi_ioctl_permit(const struct sdxi_ioctl_desc *desc)
+static int sdxi_ioctl_pre_permit(const struct sdxi_ioctl_desc *desc)
{
- switch (desc->access) {
- case SDXI_IOCTL_A_PUBLIC_DEVICE:
- case SDXI_IOCTL_A_CONTEXT_OWNER:
- return 0;
- case SDXI_IOCTL_A_ADMIN_DEVICE:
+ if (desc->access == SDXI_IOCTL_A_ADMIN_DEVICE)
return capable(CAP_SYS_ADMIN) ? 0 : -EPERM;
- case SDXI_IOCTL_A_VENDOR_HANDLER:
- return -EOPNOTSUPP;
- }
- return -EINVAL;
+ return 0;
+}
+
+static int sdxi_ioctl_permit(const struct sdxi_ioctl_desc *desc,
+ struct sdxi_file *sf, void *data)
+{
+ const struct sdxi_vendor_handler *handler;
+ struct sdxi_admin_vendor_args *args;
+ int ret;
+
+ if (desc->access != SDXI_IOCTL_A_VENDOR_HANDLER)
+ return 0;
+
+ args = data;
+ if (!args || args->argsz < sizeof(*args) ||
+ !sdxi_admin_vendor_reserved_zero(args))
+ return -EINVAL;
+
+ ret = sdxi_vendor_get(args->guid, &handler);
+ if (ret)
+ return ret;
+ ret = handler->ops->authorize(sf->process->sdxi, args);
+ sdxi_vendor_put(handler);
+ return ret;
}
static bool sdxi_ioctl_has_trailing_payload(unsigned int cmd)
@@ -900,7 +965,7 @@ static long sdxi_ioctl_live(struct file *file, unsigned int cmd,
if (!allowed)
return -ENOTTY;
- ret = sdxi_ioctl_permit(desc);
+ ret = sdxi_ioctl_pre_permit(desc);
if (ret)
return ret;
@@ -959,6 +1024,10 @@ static long sdxi_ioctl_live(struct file *file, unsigned int cmd,
}
}
+ ret = sdxi_ioctl_permit(desc, sf, data);
+ if (ret)
+ goto out;
+
ret = desc->func(file, sf, data);
if (ret == -ENOSPC && sdxi_key_list_cmd(desc->cmd))
diff --git a/drivers/dma/sdxi/vendor.c b/drivers/dma/sdxi/vendor.c
new file mode 100644
index 000000000000..6fb5967b0052
--- /dev/null
+++ b/drivers/dma/sdxi/vendor.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * SDXI vendor operation handler registry.
+ *
+ * Copyright Advanced Micro Devices, Inc.
+ */
+
+#include <linux/dma-mapping.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/string.h>
+
+#include "admin.h"
+#include "sdxi.h"
+#include "vendor.h"
+
+static LIST_HEAD(sdxi_vendor_handlers);
+static DEFINE_MUTEX(sdxi_vendor_lock);
+
+int sdxi_vendor_register(struct sdxi_vendor_handler *handler)
+{
+ struct sdxi_vendor_handler *iter;
+ int ret = 0;
+
+ if (!handler || !handler->name || !handler->guid || !handler->ops ||
+ !handler->ops->authorize || !handler->ops->exec)
+ return -EINVAL;
+
+ if (!handler->entry.next)
+ INIT_LIST_HEAD(&handler->entry);
+
+ mutex_lock(&sdxi_vendor_lock);
+ if (!list_empty(&handler->entry)) {
+ ret = -EBUSY;
+ goto out_unlock;
+ }
+
+ list_for_each_entry(iter, &sdxi_vendor_handlers, entry) {
+ if (!memcmp(iter->guid, handler->guid, 16)) {
+ ret = -EEXIST;
+ goto out_unlock;
+ }
+ }
+
+ list_add_tail(&handler->entry, &sdxi_vendor_handlers);
+
+out_unlock:
+ mutex_unlock(&sdxi_vendor_lock);
+ return ret;
+}
+EXPORT_SYMBOL_NS_GPL(sdxi_vendor_register, "SDXI");
+
+void sdxi_vendor_unregister(struct sdxi_vendor_handler *handler)
+{
+ if (!handler)
+ return;
+ if (!handler->entry.next)
+ INIT_LIST_HEAD(&handler->entry);
+
+ mutex_lock(&sdxi_vendor_lock);
+ if (!list_empty(&handler->entry))
+ list_del_init(&handler->entry);
+ mutex_unlock(&sdxi_vendor_lock);
+}
+EXPORT_SYMBOL_NS_GPL(sdxi_vendor_unregister, "SDXI");
+
+int sdxi_vendor_get(const u8 guid[16],
+ const struct sdxi_vendor_handler **handler_out)
+{
+ const struct sdxi_vendor_handler *handler;
+ int ret = -EOPNOTSUPP;
+
+ if (!guid || !handler_out)
+ return -EINVAL;
+
+ mutex_lock(&sdxi_vendor_lock);
+ list_for_each_entry(handler, &sdxi_vendor_handlers, entry) {
+ if (memcmp(handler->guid, guid, 16))
+ continue;
+ if (!try_module_get(handler->owner))
+ break;
+
+ *handler_out = handler;
+ ret = 0;
+ break;
+ }
+ mutex_unlock(&sdxi_vendor_lock);
+
+ return ret;
+}
+
+void sdxi_vendor_put(const struct sdxi_vendor_handler *handler)
+{
+ if (handler)
+ module_put(handler->owner);
+}
+
+int sdxi_vendor_find_opcode_type(struct sdxi_dev *sdxi, const u8 guid[16],
+ unsigned int timeout_ms, u16 *opcode_type)
+{
+ const u16 first = 1;
+ const u16 last = 2047;
+ const size_t record_size = 16;
+ const size_t size = (last - first + 1) * record_size;
+ dma_addr_t dma;
+ u8 *records;
+ u16 index;
+ int ret;
+
+ if (!sdxi || !guid || !opcode_type)
+ return -EINVAL;
+ if (!sdxi_dev_compatible(sdxi, SDXI_VERSION_1_1))
+ return -EOPNOTSUPP;
+
+ records = dma_alloc_coherent(sdxi->dev, size, &dma, GFP_KERNEL);
+ if (!records)
+ return -ENOMEM;
+
+ ret = sdxi_adm_disc(sdxi, first, last, dma, timeout_ms, NULL);
+ if (ret)
+ goto free_records;
+
+ dma_rmb();
+ for (index = first; index <= last; index++) {
+ const u8 *record = records + (index - first) * record_size;
+
+ if (!memcmp(record, guid, record_size)) {
+ *opcode_type = index;
+ ret = 0;
+ goto free_records;
+ }
+ }
+ ret = -EOPNOTSUPP;
+
+free_records:
+ dma_free_coherent(sdxi->dev, size, records, dma);
+ return ret;
+}
diff --git a/drivers/dma/sdxi/vendor.h b/drivers/dma/sdxi/vendor.h
new file mode 100644
index 000000000000..2a4e4582b21b
--- /dev/null
+++ b/drivers/dma/sdxi/vendor.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * SDXI vendor operation handler registry.
+ *
+ * Copyright Advanced Micro Devices, Inc.
+ */
+
+#ifndef DMA_SDXI_VENDOR_H
+#define DMA_SDXI_VENDOR_H
+
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/types.h>
+
+struct sdxi_admin_vendor_args;
+struct sdxi_dev;
+
+struct sdxi_vendor_handler_ops {
+ int (*authorize)(struct sdxi_dev *sdxi,
+ const struct sdxi_admin_vendor_args *args);
+ int (*exec)(struct sdxi_dev *sdxi, u16 opcode_type,
+ struct sdxi_admin_vendor_args *args,
+ unsigned int timeout_ms);
+};
+
+struct sdxi_vendor_handler {
+ struct list_head entry;
+ const char *name;
+ const u8 *guid;
+ struct module *owner;
+ const struct sdxi_vendor_handler_ops *ops;
+};
+
+int sdxi_vendor_register(struct sdxi_vendor_handler *handler);
+void sdxi_vendor_unregister(struct sdxi_vendor_handler *handler);
+int sdxi_vendor_get(const u8 guid[16],
+ const struct sdxi_vendor_handler **handler);
+void sdxi_vendor_put(const struct sdxi_vendor_handler *handler);
+int sdxi_vendor_find_opcode_type(struct sdxi_dev *sdxi, const u8 guid[16],
+ unsigned int timeout_ms, u16 *opcode_type);
+
+#endif /* DMA_SDXI_VENDOR_H */
--
2.56.1
next prev parent reply other threads:[~2026-11-19 20:28 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 20:22 [PATCH v1 00/44] dmaengine: sdxi: add userspace control and management support Wei Huang
2026-11-19 20:22 ` [PATCH v1 01/44] dmaengine: sdxi: cache hardware version for feature gating Wei Huang
2026-11-19 20:22 ` [PATCH v1 02/44] dmaengine: sdxi: define key and error MMIO registers Wei Huang
2026-11-19 20:22 ` [PATCH v1 03/44] dmaengine: sdxi: define SDXI hardware layouts Wei Huang
2026-11-19 20:22 ` [PATCH v1 04/44] dmaengine: sdxi: encode admin descriptors Wei Huang
2026-11-19 20:22 ` [PATCH v1 05/44] dmaengine: sdxi: support timeout-aware completion waits Wei Huang
2026-11-19 20:22 ` [PATCH v1 06/44] dmaengine: sdxi: support the full context table hierarchy Wei Huang
2026-11-19 20:22 ` [PATCH v1 07/44] dmaengine: sdxi: implement synchronous admin operations Wei Huang
2026-11-19 20:22 ` [PATCH v1 08/44] dmaengine: sdxi: add core RKey table management Wei Huang
2026-11-19 20:22 ` [PATCH v1 09/44] dmaengine: sdxi: handle hardware error logs Wei Huang
2026-11-19 20:22 ` [PATCH v1 10/44] dmaengine: sdxi: separate context and submission resources Wei Huang
2026-11-19 20:22 ` [PATCH v1 11/44] dmaengine: sdxi: support userspace context lifetimes Wei Huang
2026-11-19 20:22 ` [PATCH v1 12/44] dmaengine: sdxi: route context interrupts to eventfd Wei Huang
2026-11-19 20:22 ` [PATCH v1 13/44] dmaengine: sdxi: kill user contexts on fatal errors Wei Huang
2026-11-19 20:22 ` [PATCH v1 14/44] dmaengine: sdxi: define the ioctl UAPI surface Wei Huang
2026-11-19 20:22 ` [PATCH v1 15/44] dmaengine: sdxi: add internal ioctl definitions Wei Huang
2026-11-19 20:22 ` [PATCH v1 16/44] dmaengine: sdxi: register core character devices Wei Huang
2026-11-19 20:22 ` [PATCH v1 17/44] dmaengine: sdxi: implement fixed-size ioctl dispatch Wei Huang
2026-11-19 20:22 ` [PATCH v1 18/44] dmaengine: sdxi: implement userspace context file operations Wei Huang
2026-11-19 20:22 ` [PATCH v1 19/44] dmaengine: sdxi: validate and copy key ioctl payloads Wei Huang
2026-11-19 20:22 ` [PATCH v1 20/44] dmaengine: sdxi: implement RKey management ioctls Wei Huang
2026-11-19 20:22 ` [PATCH v1 21/44] dmaengine: sdxi: implement AKey " Wei Huang
2026-11-19 20:22 ` [PATCH v1 22/44] dmaengine: sdxi: expose operation-group discovery Wei Huang
2026-11-19 20:22 ` Wei Huang [this message]
2026-11-19 20:23 ` [PATCH v1 24/44] dmaengine: sdxi: expose character device attributes Wei Huang
2026-11-19 20:23 ` [PATCH v1 25/44] dmaengine: sdxi: add PF and VF device naming Wei Huang
2026-11-19 20:23 ` [PATCH v1 26/44] dmaengine: sdxi: add SDXI trace events Wei Huang
2026-11-19 20:23 ` [PATCH v1 27/44] dmaengine: sdxi: support suspend and resume Wei Huang
2026-11-19 20:23 ` [PATCH v1 28/44] dmaengine: sdxi: amd: define QoS request formats Wei Huang
2026-11-19 20:23 ` [PATCH v1 29/44] dmaengine: sdxi: amd: add QoS validation scaffolding Wei Huang
2026-11-19 20:23 ` [PATCH v1 30/44] dmaengine: sdxi: amd: build QoS admin descriptors Wei Huang
2026-11-19 20:23 ` [PATCH v1 31/44] dmaengine: sdxi: amd: prevalidate QoS operations Wei Huang
2026-11-19 20:23 ` [PATCH v1 32/44] dmaengine: sdxi: amd: execute QoS vendor operations Wei Huang
2026-11-19 20:23 ` [PATCH v1 33/44] dmaengine: sdxi: amd: register QoS vendor handler Wei Huang
2026-11-19 20:23 ` [PATCH v1 34/44] dmaengine: sdxi: amd: test QoS validation with KUnit Wei Huang
2026-11-19 20:23 ` [PATCH v1 35/44] selftests: sdxi: add build scaffold Wei Huang
2026-11-19 20:23 ` [PATCH v1 36/44] selftests: sdxi: add shared descriptor and context helpers Wei Huang
2026-11-19 20:23 ` [PATCH v1 37/44] selftests: sdxi: test context creation Wei Huang
2026-11-19 20:23 ` [PATCH v1 38/44] selftests: sdxi: test NOP descriptor submission Wei Huang
2026-11-19 20:23 ` [PATCH v1 39/44] selftests: sdxi: test copy submission and ring wrap Wei Huang
2026-11-19 20:23 ` [PATCH v1 40/44] selftests: sdxi: exercise dataplane error paths Wei Huang
2026-11-19 20:23 ` [PATCH v1 41/44] selftests: sdxi: test device ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 42/44] selftests: sdxi: test vendor admin ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 43/44] selftests: sdxi: test RKey ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 44/44] MAINTAINERS: cover SDXI UAPI, vendor files, and selftests Wei Huang
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=20261119202321.1734355-24-wei.huang2@amd.com \
--to=wei.huang2@amd.com \
--cc=Frank.Li@kernel.org \
--cc=John.Kariuki@amd.com \
--cc=Shyam.Iyer@dell.com \
--cc=Stephen.Bates@amd.com \
--cc=bhelgaas@google.com \
--cc=dmaengine@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=nathan.lynch@amd.com \
--cc=rientjes@google.com \
--cc=shuah@kernel.org \
--cc=suravee.suthikulpanit@amd.com \
--cc=tycho@kernel.org \
--cc=vkoul@kernel.org \
--cc=weixugc@google.com \
/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®