From: Qinxin Xia <xiaqinxin@huawei.com>
To: <ben.horgan@arm.com>, <zhangzhanpeng.jasper@bytedance.com>,
<joro@8bytes.org>, <palmer@dabbelt.com>, <tony.luck@intel.com>,
<reinette.chatre@intel.com>, <tomasz.jeznach@linux.dev>,
<zengheng4@huawei.com>, <fustini@kernel.org>,
<cuiyunhui@bytedance.com>, <wangzhou1@hisilicon.com>,
<xiaqinxin@huawei.com>
Cc: <will@kernel.org>, <robin.murphy@arm.com>, <pjw@kernel.org>,
<aou@eecs.berkeley.edu>, <alex@ghiti.fr>, <Dave.Martin@arm.com>,
<james.morse@arm.com>, <babu.moger@amd.com>, <corbet@lwn.net>,
<shuah@kernel.org>, <jgg@ziepe.ca>, <kevin.tian@intel.com>,
<yuanzhu@bytedance.com>, <iommu@lists.linux.dev>,
<linuxarm@huawei.com>, <baolin.wang@linux.alibaba.com>
Subject: [RFC PATCH 5/5] fs/resctrl: Add a "devices" file to assign devices to groups
Date: Tue, 1 Sep 2026 22:08:02 +0800 [thread overview]
Message-ID: <20260901140802.1215508-6-xiaqinxin@huawei.com> (raw)
In-Reply-To: <20260901140802.1215508-1-xiaqinxin@huawei.com>
Expose the device QoS tracking through a new "devices" file. Writing a
device name assigns it to the group, tagging its DMA with the group's QoS
IDs.
The file is only shown where an IOMMU can tag device DMA.
Signed-off-by: Qinxin Xia <xiaqinxin@huawei.com>
---
Documentation/filesystems/resctrl.rst | 18 ++++-
fs/resctrl/rdtgroup.c | 101 ++++++++++++++++++++++++++
2 files changed, 117 insertions(+), 2 deletions(-)
diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesystems/resctrl.rst
index e4b66af55ffb..aa205ccaabf6 100644
--- a/Documentation/filesystems/resctrl.rst
+++ b/Documentation/filesystems/resctrl.rst
@@ -546,8 +546,8 @@ directories can be created to monitor subsets of tasks in the CTRL_MON
group that is their ancestor. These are called "MON" groups in the rest
of this document.
-Removing a directory will move all tasks and cpus owned by the group it
-represents to the parent. Removing one of the created CTRL_MON groups
+Removing a directory will move all tasks, cpus and devices owned by the
+group it represents to the parent. Removing one of the created CTRL_MON groups
will automatically remove all MON groups below it.
Moving MON group directories to a new parent CTRL_MON group is supported
@@ -581,6 +581,20 @@ All groups contain the following files:
idle tasks. Instead, a CPU's idle task is always considered as a
member of the group owning the CPU.
+"devices":
+ Reading this file shows the list of all devices that belong to
+ this group. Writing a device name to the file will add a device to
+ the group, tagging its DMA with the group's QoS IDs. Multiple
+ devices can be added by separating the names with commas. A single
+ failure encountered while attempting to assign a device will cause
+ the operation to abort and already added devices before the failure
+ will remain in the group. Failures will be logged to
+ /sys/fs/resctrl/info/last_cmd_status.
+
+ The device name is the one listed under
+ /sys/kernel/iommu_groups/<id>/devices/. This file is only present
+ when an IOMMU can tag the DMA of devices behind it with a QoS class.
+
"cpus":
Reading this file shows a bitmask of the logical CPUs owned by
this group. Writing a mask to this file will add and remove
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index c33891ead788..3633b3521941 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -985,6 +985,92 @@ static const struct iommu_qos_device_ops rdtgroup_qos_device_ops = {
.remove = rdtgroup_remove_device,
};
+static ssize_t rdtgroup_devices_write(struct kernfs_open_file *of,
+ char *buf, size_t nbytes, loff_t off)
+{
+ struct rdtgroup *rdtgrp;
+ char *token;
+ int ret = 0;
+
+ if (!buf)
+ return -EINVAL;
+
+ rdtgrp = rdtgroup_kn_lock_live(of->kn);
+ if (!rdtgrp) {
+ rdtgroup_kn_unlock(of->kn);
+ return -ENOENT;
+ }
+ rdt_last_cmd_clear();
+
+ if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED ||
+ rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
+ ret = -EINVAL;
+ rdt_last_cmd_puts("Pseudo-locking in progress\n");
+ goto unlock;
+ }
+
+ while ((token = strsep(&buf, ","))) {
+ struct device *dev;
+
+ token = strim(token);
+ if (!*token) {
+ rdt_last_cmd_puts("Device list parsing error\n");
+ ret = -EINVAL;
+ break;
+ }
+
+ dev = iommu_group_find_device_by_name(token);
+ if (!dev) {
+ rdt_last_cmd_printf("No device %s\n", token);
+ ret = -ENODEV;
+ break;
+ }
+
+ ret = rdtgroup_set_device(dev, rdtgrp);
+ if (ret == -EOPNOTSUPP)
+ rdt_last_cmd_printf("Device %s does not support QoS\n",
+ token);
+ else if (ret)
+ rdt_last_cmd_printf("Error while processing device %s\n",
+ token);
+ /*
+ * rdtgroup_set_device() takes its own reference on a new
+ * rdtdev; drop the temporary reference returned by the
+ * lookup regardless of the outcome.
+ */
+ put_device(dev);
+ if (ret)
+ break;
+ }
+
+unlock:
+ rdtgroup_kn_unlock(of->kn);
+ return ret ?: nbytes;
+}
+
+static int rdtgroup_devices_show(struct kernfs_open_file *of,
+ struct seq_file *s, void *v)
+{
+ struct rdtgroup *rdtgrp;
+ struct rdtdev *rdtdev;
+
+ rdtgrp = rdtgroup_kn_lock_live(of->kn);
+ if (!rdtgrp) {
+ rdtgroup_kn_unlock(of->kn);
+ return -ENOENT;
+ }
+
+ mutex_lock(&rdtdev_mutex);
+ list_for_each_entry(rdtdev, &rdtdev_list, node)
+ if (is_rmid_match_dev(rdtdev, rdtgrp) ||
+ is_closid_match_dev(rdtdev, rdtgrp))
+ seq_printf(s, "%s\n", kobject_name(&rdtdev->dev->kobj));
+ mutex_unlock(&rdtdev_mutex);
+
+ rdtgroup_kn_unlock(of->kn);
+ return 0;
+}
+
static void rdt_move_group_devices(struct rdtgroup *from, struct rdtgroup *to)
{
struct rdtdev *rdtdev;
@@ -2295,6 +2381,14 @@ static struct rftype res_common_files[] = {
.seq_show = rdtgroup_tasks_show,
.fflags = RFTYPE_BASE,
},
+ {
+ .name = "devices",
+ .mode = 0644,
+ .kf_ops = &rdtgroup_kf_single_ops,
+ .write = rdtgroup_devices_write,
+ .seq_show = rdtgroup_devices_show,
+ .fflags = RFTYPE_BASE,
+ },
{
.name = "mon_hw_id",
.mode = 0444,
@@ -2363,6 +2457,13 @@ static int rdtgroup_add_files(struct kernfs_node *kn, unsigned long fflags)
for (rft = rfts; rft < rfts + len; rft++) {
if (rft->fflags && ((fflags & rft->fflags) == rft->fflags)) {
+ if (!strcmp(rft->name, "devices") &&
+ (!resctrl_arch_devices_supported() ||
+ ((fflags & RFTYPE_CTRL) &&
+ !resctrl_arch_alloc_capable()) ||
+ ((fflags & RFTYPE_MON) &&
+ !resctrl_arch_mon_capable())))
+ continue;
ret = rdtgroup_add_file(kn, rft);
if (ret)
goto error;
--
2.33.0
next prev parent reply other threads:[~2026-09-01 14:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 14:07 [RFC PATCH 0/5] resctrl: Assign devices to resource groups via IOMMU DMA QoS tagging Qinxin Xia
2026-09-01 14:07 ` [RFC PATCH 1/5] iommu: Add per-device requestor QoS tagging and lookup helpers Qinxin Xia
2026-09-01 14:07 ` [RFC PATCH 2/5] arm_mpam: resctrl: Add arch query for device DMA QoS support Qinxin Xia
2026-09-01 14:08 ` [RFC PATCH 3/5] iommu/arm-smmu-v3: Support MPAM device DMA QoS tagging Qinxin Xia
2026-09-01 14:08 ` [RFC PATCH 4/5] fs/resctrl: Add device-to-group QoS tracking infrastructure Qinxin Xia
2026-09-01 14:08 ` Qinxin Xia [this message]
2026-09-10 10:24 ` [RFC PATCH 5/5] fs/resctrl: Add a "devices" file to assign devices to groups Ben Horgan
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=20260901140802.1215508-6-xiaqinxin@huawei.com \
--to=xiaqinxin@huawei.com \
--cc=Dave.Martin@arm.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=babu.moger@amd.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=ben.horgan@arm.com \
--cc=corbet@lwn.net \
--cc=cuiyunhui@bytedance.com \
--cc=fustini@kernel.org \
--cc=iommu@lists.linux.dev \
--cc=james.morse@arm.com \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linuxarm@huawei.com \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=reinette.chatre@intel.com \
--cc=robin.murphy@arm.com \
--cc=shuah@kernel.org \
--cc=tomasz.jeznach@linux.dev \
--cc=tony.luck@intel.com \
--cc=wangzhou1@hisilicon.com \
--cc=will@kernel.org \
--cc=yuanzhu@bytedance.com \
--cc=zengheng4@huawei.com \
--cc=zhangzhanpeng.jasper@bytedance.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 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.