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 41/44] selftests: sdxi: test device ioctls
Date: Thu, 19 Nov 2026 14:23:17 -0600 [thread overview]
Message-ID: <20261119202321.1734355-42-wei.huang2@amd.com> (raw)
In-Reply-To: <20261119202321.1734355-1-wei.huang2@amd.com>
Add coverage for UAPI discovery, device information and device
attribute ioctls to SDXI selftest suite.
Co-developed-by: Wei Huang <wei.huang2@amd.com>
Signed-off-by: Wei Huang <wei.huang2@amd.com>
Signed-off-by: Nathan Lynch <nathan.lynch@amd.com>
---
tools/testing/selftests/sdxi/.gitignore | 1 +
tools/testing/selftests/sdxi/Makefile | 2 +-
tools/testing/selftests/sdxi/device.c | 245 ++++++++++++++++++++++++
3 files changed, 247 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/sdxi/device.c
diff --git a/tools/testing/selftests/sdxi/.gitignore b/tools/testing/selftests/sdxi/.gitignore
index d891f7a24c40..17855ea86222 100644
--- a/tools/testing/selftests/sdxi/.gitignore
+++ b/tools/testing/selftests/sdxi/.gitignore
@@ -2,3 +2,4 @@
/nop
/copy
/error
+/device
diff --git a/tools/testing/selftests/sdxi/Makefile b/tools/testing/selftests/sdxi/Makefile
index c05390cb9d86..88e51b08f468 100644
--- a/tools/testing/selftests/sdxi/Makefile
+++ b/tools/testing/selftests/sdxi/Makefile
@@ -2,7 +2,7 @@ werror := -Werror
CFLAGS += -std=gnu17 -Og -Wall -Wextra $(werror) $(TOOLS_INCLUDES) $(KHDR_INCLUDES)
CPPFLAGS += -I../../../include/ -Ilib/
-TEST_GEN_PROGS := context nop copy error
+TEST_GEN_PROGS := context nop copy error device
include ../lib.mk
diff --git a/tools/testing/selftests/sdxi/device.c b/tools/testing/selftests/sdxi/device.c
new file mode 100644
index 000000000000..2fdec79e6bf5
--- /dev/null
+++ b/tools/testing/selftests/sdxi/device.c
@@ -0,0 +1,245 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * SDXI device ioctl selftests.
+ *
+ * Copyright (C) 2026 Advanced Micro Devices, Inc.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+#include <linux/sdxi.h>
+
+#include "lib.h"
+#include "lib/fixture-device.h"
+#include "../kselftest_harness.h"
+
+TEST_F(dev_sdxi, open_and_close_device)
+{
+ // Just run the fixture setup and teardown
+}
+
+TEST_F(dev_sdxi, get_uapi_info)
+{
+ struct sdxi_uapi_info_args info = {};
+
+ info.argsz = sizeof(info);
+
+ ASSERT_EQ(ioctl(self->fd, SDXI_GET_UAPI_INFO, &info), 0);
+ EXPECT_EQ(info.uapi_major, SDXI_UAPI_MAJOR);
+ EXPECT_EQ(info.uapi_minor, SDXI_UAPI_MINOR);
+ EXPECT_GT(info.cap_words, 0);
+ EXPECT_LE(info.cap_words, SDXI_UAPI_CAP_WORDS);
+ EXPECT_EQ(info.rsvd0, 0);
+ /* The driver must publish at least one capability bit. */
+ EXPECT_NE(info.caps[0], 0ULL);
+ EXPECT_NE(info.caps[0] & SDXI_UAPI_CAP_ADMIN_VENDOR, 0ULL);
+ EXPECT_NE(info.caps[0] & SDXI_UAPI_CAP_CXT_EVENTFD, 0ULL);
+}
+
+TEST_F(dev_sdxi, get_uapi_info_rejects_flags)
+{
+ struct sdxi_uapi_info_args info = {};
+
+ info.argsz = sizeof(info);
+ info.flags = 1;
+
+ errno = 0;
+ EXPECT_EQ(ioctl(self->fd, SDXI_GET_UAPI_INFO, &info), -1);
+ EXPECT_EQ(errno, EINVAL);
+}
+
+TEST_F(dev_sdxi, get_dev_info)
+{
+ struct sdxi_dev_info_args info = {};
+
+ info.argsz = sizeof(info);
+
+ ASSERT_EQ(ioctl(self->fd, SDXI_GET_DEV_INFO, &info), 0);
+ EXPECT_EQ(info.argsz, sizeof(info));
+ /* SDXI 1.x devices report a non-zero major version. */
+ EXPECT_GE(info.hw_major, 1);
+ EXPECT_EQ(info.rsvd0, 0U);
+ EXPECT_EQ(info.rsvd1[0], 0ULL);
+ EXPECT_EQ(info.rsvd1[1], 0ULL);
+ EXPECT_EQ(info.rsvd1[2], 0ULL);
+ EXPECT_EQ(info.rsvd1[3], 0ULL);
+}
+
+TEST_F(dev_sdxi, get_dev_info_rejects_flags)
+{
+ struct sdxi_dev_info_args info = {};
+
+ info.argsz = sizeof(info);
+ info.flags = 1;
+
+ errno = 0;
+ EXPECT_EQ(ioctl(self->fd, SDXI_GET_DEV_INFO, &info), -1);
+ EXPECT_EQ(errno, EINVAL);
+}
+
+TEST_F(dev_sdxi, get_dev_info_rejects_short_argsz)
+{
+ struct sdxi_dev_info_args info = {};
+
+ info.argsz = sizeof(info) - 1;
+
+ errno = 0;
+ EXPECT_EQ(ioctl(self->fd, SDXI_GET_DEV_INFO, &info), -1);
+ EXPECT_EQ(errno, EINVAL);
+}
+
+static int sdxi_get_dev_attr(int fd, uint64_t attr, uint64_t *out)
+{
+ struct sdxi_dev_attr_args args = {};
+ int rc;
+
+ args.argsz = sizeof(args);
+ args.attr = attr;
+
+ rc = ioctl(fd, SDXI_GET_DEV_ATTR, &args);
+ if (rc == 0 && out)
+ *out = args.val;
+ return rc;
+}
+
+TEST_F(dev_sdxi, get_dev_attr)
+{
+ uint64_t val;
+
+ ASSERT_EQ(sdxi_get_dev_attr(self->fd, SDXI_DEV_ATTR_MAX_BUFFER, &val), 0);
+ EXPECT_LE(val, 11U);
+
+ ASSERT_EQ(sdxi_get_dev_attr(self->fd, SDXI_DEV_ATTR_MAX_AKEY_SZ, &val), 0);
+ EXPECT_LE(val, 8U);
+
+ ASSERT_EQ(sdxi_get_dev_attr(self->fd, SDXI_DEV_ATTR_MAX_CXT, &val), 0);
+ EXPECT_GT(val, 0U);
+
+ /* MAX_RKEY_SZ is read-only and may be 0 if RKEY isn't supported. */
+ EXPECT_EQ(sdxi_get_dev_attr(self->fd, SDXI_DEV_ATTR_MAX_RKEY_SZ, &val), 0);
+}
+
+TEST_F(dev_sdxi, get_dev_attr_rejects_unknown)
+{
+ struct sdxi_dev_attr_args args = {};
+
+ args.argsz = sizeof(args);
+ args.attr = 0;
+ errno = 0;
+ EXPECT_EQ(ioctl(self->fd, SDXI_GET_DEV_ATTR, &args), -1);
+ EXPECT_EQ(errno, EOPNOTSUPP);
+
+ args.attr = 0xffff;
+ errno = 0;
+ EXPECT_EQ(ioctl(self->fd, SDXI_GET_DEV_ATTR, &args), -1);
+ EXPECT_EQ(errno, EOPNOTSUPP);
+}
+
+TEST_F(dev_sdxi, get_dev_attr_rejects_flags)
+{
+ struct sdxi_dev_attr_args args = {};
+
+ args.argsz = sizeof(args);
+ args.attr = SDXI_DEV_ATTR_MAX_BUFFER;
+ args.flags = 1;
+
+ errno = 0;
+ EXPECT_EQ(ioctl(self->fd, SDXI_GET_DEV_ATTR, &args), -1);
+ EXPECT_EQ(errno, EINVAL);
+}
+
+TEST_F(dev_sdxi, set_dev_attr_requires_admin)
+{
+ struct sdxi_dev_attr_args args = {};
+ uint64_t cur;
+ int rc;
+
+ if (geteuid() == 0)
+ SKIP(return, "needs non-root");
+
+ ASSERT_EQ(sdxi_get_dev_attr(self->fd, SDXI_DEV_ATTR_GRP_ID, &cur), 0);
+
+ args.argsz = sizeof(args);
+ args.attr = SDXI_DEV_ATTR_GRP_ID;
+ args.val = cur;
+
+ errno = 0;
+ rc = ioctl(self->fd, SDXI_SET_DEV_ATTR, &args);
+ EXPECT_EQ(rc, -1);
+ EXPECT_EQ(errno, EPERM);
+}
+
+TEST_F(dev_sdxi, set_dev_attr_round_trip)
+{
+ struct sdxi_dev_attr_args args = {};
+ uint64_t orig, applied;
+
+ if (geteuid() != 0)
+ SKIP(return, "requires root");
+
+ ASSERT_EQ(sdxi_get_dev_attr(self->fd, SDXI_DEV_ATTR_GRP_ID, &orig), 0);
+
+ args.argsz = sizeof(args);
+ args.attr = SDXI_DEV_ATTR_GRP_ID;
+ args.val = orig;
+
+ ASSERT_EQ(ioctl(self->fd, SDXI_SET_DEV_ATTR, &args), 0);
+ EXPECT_EQ(args.argsz, sizeof(args));
+ EXPECT_EQ(args.val, orig);
+
+ ASSERT_EQ(sdxi_get_dev_attr(self->fd, SDXI_DEV_ATTR_GRP_ID, &applied), 0);
+ EXPECT_EQ(applied, orig);
+}
+
+TEST_F(dev_sdxi, set_dev_attr_rejects_exceeding_caps)
+{
+ struct sdxi_dev_info_args info = {};
+ struct sdxi_dev_attr_args args = {};
+ uint64_t cap_max_buffer;
+ int rc;
+
+ if (geteuid() != 0)
+ SKIP(return, "requires root");
+
+ info.argsz = sizeof(info);
+ ASSERT_EQ(ioctl(self->fd, SDXI_GET_DEV_INFO, &info), 0);
+
+ cap_max_buffer = info.cap1 & 0xf;
+ if (cap_max_buffer == 0xf)
+ SKIP(return, "cap1.max_buffer already saturates the field");
+
+ args.argsz = sizeof(args);
+ args.attr = SDXI_DEV_ATTR_MAX_BUFFER;
+ args.val = cap_max_buffer + 1;
+
+ errno = 0;
+ rc = ioctl(self->fd, SDXI_SET_DEV_ATTR, &args);
+ EXPECT_EQ(rc, -1);
+ EXPECT_EQ(errno, EINVAL);
+}
+
+TEST_F(dev_sdxi, set_dev_attr_rejects_read_only)
+{
+ struct sdxi_dev_attr_args args = {};
+ int rc;
+
+ if (geteuid() != 0)
+ SKIP(return, "requires root");
+
+ args.argsz = sizeof(args);
+ args.attr = SDXI_DEV_ATTR_MAX_RKEY_SZ;
+ args.val = 0;
+
+ errno = 0;
+ rc = ioctl(self->fd, SDXI_SET_DEV_ATTR, &args);
+ EXPECT_EQ(rc, -1);
+ EXPECT_EQ(errno, EOPNOTSUPP);
+}
+
+TEST_HARNESS_MAIN
--
2.56.1
next prev parent reply other threads:[~2026-11-19 20:32 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 ` [PATCH v1 23/44] dmaengine: sdxi: implement typed vendor admin transport Wei Huang
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 ` Wei Huang [this message]
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-42-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®