mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 22/44] dmaengine: sdxi: expose operation-group discovery
Date: Thu, 19 Nov 2026 14:22:58 -0600	[thread overview]
Message-ID: <20261119202321.1734355-23-wei.huang2@amd.com> (raw)
In-Reply-To: <20261119202321.1734355-1-wei.huang2@amd.com>

Expose read-only SDXI 1.1 discovery on device fds and use discovered
GUIDs to authorize raw opb_000 requests for user contexts. For security
reasons, deny unknown and admin-only groups. It also enables atomic
groups only when PCI requester support is available.

Signed-off-by: Wei Huang <wei.huang2@amd.com>
---
 drivers/dma/sdxi/ioctl.c | 177 ++++++++++++++++++++++++++++++++++++++-
 drivers/dma/sdxi/pci.c   |  12 +++
 drivers/dma/sdxi/sdxi.h  |   1 +
 3 files changed, 186 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/sdxi/ioctl.c b/drivers/dma/sdxi/ioctl.c
index f0b298b92430..80648bed0e87 100644
--- a/drivers/dma/sdxi/ioctl.c
+++ b/drivers/dma/sdxi/ioctl.c
@@ -25,6 +25,7 @@
 #include <linux/sizes.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <linux/uuid.h>
 #include <uapi/linux/sdxi.h>
 
 #include "admin.h"
@@ -99,7 +100,8 @@ static int sdxi_ioctl_get_uapi_info(struct file *file, struct sdxi_file *sf,
 			SDXI_UAPI_CAP_RKEY_MGMT |
 			SDXI_UAPI_CAP_CXT_CREATE |
 			SDXI_UAPI_CAP_CXT_EVENTFD |
-			SDXI_UAPI_CAP_AKEY_MGMT,
+			SDXI_UAPI_CAP_AKEY_MGMT |
+			SDXI_UAPI_CAP_ADMIN_DISC,
 		},
 	};
 
@@ -321,22 +323,134 @@ static bool sdxi_u32_array_zero(const u32 *values, size_t count)
 	return true;
 }
 
+enum sdxi_op_group_policy {
+	SDXI_OP_GROUP_UNKNOWN,
+	SDXI_OP_GROUP_USER,
+	SDXI_OP_GROUP_ADMIN_ONLY,
+};
+
+struct sdxi_op_group_policy_entry {
+	guid_t guid;
+	enum sdxi_op_group_policy policy;
+};
+
+static const struct sdxi_op_group_policy_entry sdxi_op_group_policy[] = {
+	{ GUID_INIT(0x193259fe, 0x150b, 0x4008, 0xa8, 0x3f, 0x6f, 0xaf, 0x59,
+		    0xf5, 0x27, 0x2a), SDXI_OP_GROUP_USER },
+	{ GUID_INIT(0xd9bc29a1, 0x91dc, 0x4243, 0x97, 0x51, 0xb6, 0xb0, 0x32,
+		    0x9d, 0xaf, 0xe1), SDXI_OP_GROUP_USER },
+	{ GUID_INIT(0x3ac7630e, 0x7009, 0x424b, 0x82, 0x99, 0x20, 0xe2, 0x90,
+		    0x1e, 0xcc, 0x5e), SDXI_OP_GROUP_USER },
+	{ GUID_INIT(0x7fb16347, 0x4c3a, 0x4d16, 0x84, 0x42, 0xcb, 0xa5, 0x1e,
+		    0x34, 0x08, 0x80), SDXI_OP_GROUP_USER },
+	{ GUID_INIT(0x0af23293, 0x7595, 0x4939, 0xb0, 0x8a, 0x1c, 0x72, 0x93,
+		    0xc2, 0xe9, 0x75), SDXI_OP_GROUP_USER },
+	{ GUID_INIT(0x989b9a64, 0x28d9, 0x4294, 0x9c, 0x7b, 0x9a, 0x3f, 0x27,
+		    0xaf, 0xaf, 0x5c), SDXI_OP_GROUP_USER },
+	{ GUID_INIT(0x15114db9, 0x4a7e, 0x47ab, 0x97, 0xdd, 0xea, 0x86, 0xed,
+		    0xa1, 0x0b, 0x6e), SDXI_OP_GROUP_USER },
+	{ GUID_INIT(0xb3e551a3, 0xf1a9, 0x4c9a, 0x82, 0x52, 0xda, 0xf5, 0xc0,
+		    0xd9, 0x1a, 0x44), SDXI_OP_GROUP_USER },
+	{ GUID_INIT(0x2595c4dc, 0x6fac, 0x49d2, 0xa3, 0x31, 0xb1, 0x40, 0x0a,
+		    0x7f, 0x69, 0x0f), SDXI_OP_GROUP_USER },
+	{ GUID_INIT(0xf5b7610b, 0x0dc6, 0x4c03, 0xab, 0x79, 0x65, 0xf1, 0xf4,
+		    0xef, 0xcf, 0x4c), SDXI_OP_GROUP_ADMIN_ONLY },
+};
+
+static enum sdxi_op_group_policy
+sdxi_op_group_lookup(const guid_t *guid)
+{
+	size_t i;
+
+	if (guid_is_null(guid))
+		return SDXI_OP_GROUP_UNKNOWN;
+
+	for (i = 0; i < ARRAY_SIZE(sdxi_op_group_policy); i++)
+		if (guid_equal(guid, &sdxi_op_group_policy[i].guid))
+			return sdxi_op_group_policy[i].policy;
+
+	return SDXI_OP_GROUP_UNKNOWN;
+}
+
+#define SDXI_DISC_TIMEOUT_MS	5000U
+
+static int sdxi_discover_user_op_groups(struct sdxi_dev *sdxi, u32 available,
+					u32 *allowed, u32 *denied)
+{
+	const u16 first = 1;
+	const u16 last = 31;
+	const size_t record_size = sizeof(guid_t);
+	const size_t size = (last - first + 1) * record_size;
+	dma_addr_t dma;
+	u8 *records;
+	u16 index;
+	int ret;
+
+	if (!sdxi_dev_compatible(sdxi, SDXI_VERSION_1_1) ||
+	    !(available & SDXI_OPB_000_DISC_MASK))
+		return 0;
+
+	records = dma_alloc_coherent(sdxi->dev, size, &dma, GFP_KERNEL);
+	if (!records)
+		return -ENOMEM;
+
+	ret = sdxi_adm_disc(sdxi, first, last, dma, SDXI_DISC_TIMEOUT_MS,
+			    NULL);
+	if (ret)
+		goto free_records;
+
+	dma_rmb();
+	for (index = first; index <= last; index++) {
+		enum sdxi_op_group_policy policy;
+		guid_t guid;
+		u32 bit = BIT(index);
+
+		if (!(available & bit))
+			continue;
+
+		import_guid(&guid, records + (index - first) * record_size);
+		policy = sdxi_op_group_lookup(&guid);
+		if (policy == SDXI_OP_GROUP_USER)
+			*allowed |= bit;
+		else if (policy == SDXI_OP_GROUP_ADMIN_ONLY)
+			*denied |= bit;
+	}
+
+free_records:
+	dma_free_coherent(sdxi->dev, size, records, dma);
+	return ret;
+}
+
 static int sdxi_user_op_groups(struct sdxi_dev *sdxi, u32 requested,
 			       u32 *applied)
 {
 	u32 available;
 	u32 allowed;
+	u32 denied = SDXI_OPB_000_ADMIN;
+	bool use_default = !requested;
+	int ret;
 
 	available = FIELD_GET(SDXI_MMIO_CTL2_OPB_000_AVL,
 			      sdxi_read64(sdxi, SDXI_MMIO_CTL2));
 	allowed = available & SDXI_OPB_000_INTR;
+	if (sdxi->atomic_ops_enabled)
+		allowed |= available & SDXI_OPB_000_ATOMIC;
+
+	ret = sdxi_discover_user_op_groups(sdxi, available, &allowed,
+					   &denied);
+	if (ret && !use_default &&
+	    (requested & SDXI_OPB_000_DISC_MASK))
+		return ret;
 
-	if (!requested)
+	if (use_default)
 		requested = allowed;
-	if (requested & SDXI_OPB_000_ADMIN)
+	if (requested & denied)
 		return -EPERM;
 	if (requested & ~available)
 		return -EINVAL;
+	if ((requested & SDXI_OPB_000_ATOMIC) &&
+	    !sdxi->atomic_ops_enabled)
+		return -EOPNOTSUPP;
 	if (requested & ~allowed)
 		return -EOPNOTSUPP;
 
@@ -552,6 +666,61 @@ static int sdxi_ioctl_quiesce_cxt(struct file *file, struct sdxi_file *sf,
 	return ret;
 }
 
+static int sdxi_ioctl_admin_disc(struct file *file, struct sdxi_file *sf,
+				 void *data)
+{
+	struct sdxi_admin_disc_args *args = data;
+	size_t required;
+	dma_addr_t dma;
+	void *buffer;
+	u16 start;
+	u16 end;
+	u32 timeout_ms;
+	int ret;
+
+	if (args->argsz < sizeof(*args) || args->flags ||
+	    !sdxi_u32_array_zero(args->rsvd0, ARRAY_SIZE(args->rsvd0)))
+		return -EINVAL;
+	if (!sdxi_dev_compatible(sf->process->sdxi, SDXI_VERSION_1_1))
+		return -EOPNOTSUPP;
+
+	start = args->index.start;
+	end = args->index.end;
+	if (start > end || end > 2047)
+		return -EINVAL;
+
+	required = (size_t)(end - start + 1) * sizeof(guid_t);
+	args->argsz = sizeof(*args);
+	args->cst_flags = 0;
+	if (args->buf_size < required) {
+		args->buf_size = required;
+		return -ENOSPC;
+	}
+	if (!args->buf_uptr)
+		return -EINVAL;
+
+	buffer = dma_alloc_coherent(sf->process->sdxi->dev, required, &dma,
+				    GFP_KERNEL);
+	if (!buffer)
+		return -ENOMEM;
+
+	timeout_ms = args->timeout_ms ?: SDXI_DISC_TIMEOUT_MS;
+	if (!capable(CAP_SYS_ADMIN))
+		timeout_ms = min(timeout_ms, SDXI_DISC_TIMEOUT_MS);
+	ret = sdxi_adm_disc(sf->process->sdxi, start, end, dma,
+			    timeout_ms, &args->cst_flags);
+	if (!ret) {
+		dma_rmb();
+		if (copy_to_user(u64_to_user_ptr(args->buf_uptr), buffer,
+				 required))
+			ret = -EFAULT;
+	}
+
+	dma_free_coherent(sf->process->sdxi->dev, required, buffer, dma);
+	args->buf_size = required;
+	return ret;
+}
+
 #define SDXI_IOCTL_DEF(_nr, _cmd, _func, _files, _access)	\
 	[_nr] = {						\
 		.cmd = (_cmd),					\
@@ -588,7 +757,7 @@ static const struct sdxi_ioctl_desc sdxi_ioctls[] = {
 		       SDXI_IOCTL_F_CONTEXT, SDXI_IOCTL_A_CONTEXT_OWNER),
 	SDXI_IOCTL_DEF(0x0c, SDXI_SET_AKEYS, sdxi_ioctl_set_akeys,
 		       SDXI_IOCTL_F_CONTEXT, SDXI_IOCTL_A_CONTEXT_OWNER),
-	SDXI_IOCTL_DEF(0x0d, SDXI_ADMIN_DISC, sdxi_ioctl_unsupported,
+	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_F_DEVICE, SDXI_IOCTL_A_VENDOR_HANDLER),
diff --git a/drivers/dma/sdxi/pci.c b/drivers/dma/sdxi/pci.c
index 010ed2c6ad74..52bdaeda08ff 100644
--- a/drivers/dma/sdxi/pci.c
+++ b/drivers/dma/sdxi/pci.c
@@ -14,6 +14,7 @@
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/overflow.h>
+#include <linux/pci-ats.h>
 #include <linux/pci.h>
 
 #include "context.h"
@@ -68,6 +69,17 @@ static int sdxi_pci_init(struct sdxi_dev *sdxi)
 	sdxi->has_mailbox = pdev->is_virtfn ||
 		pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
 
+	/*
+	 * PCIe defines AtomicOp Requester Enable as a PF-owned control that
+	 * also applies to its VFs. Configure the physical function so VF
+	 * contexts inherit the transport capability correctly.
+	 */
+	ret = pci_enable_atomic_ops_to_root(pci_physfn(pdev),
+					    PCI_EXP_DEVCAP2_ATOMIC_COMP32 |
+					    PCI_EXP_DEVCAP2_ATOMIC_COMP64);
+	if (!ret)
+		sdxi->atomic_ops_enabled = true;
+
 	/*
 	 * Allocate the minimum required set of vectors plus one for
 	 * each client context supported by the function.
diff --git a/drivers/dma/sdxi/sdxi.h b/drivers/dma/sdxi/sdxi.h
index 0f7a63d6fc4b..55ca853d6d1c 100644
--- a/drivers/dma/sdxi/sdxi.h
+++ b/drivers/dma/sdxi/sdxi.h
@@ -135,6 +135,7 @@ struct sdxi_dev {
 	struct cdev cdev;
 	struct device chardev;
 	int minor;
+	bool atomic_ops_enabled;
 	bool online;
 	struct rw_semaphore state_lock;	/* online state and user operations */
 
-- 
2.56.1


  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 ` Wei Huang [this message]
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 ` [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-23-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®