Re: [PATCH 1/2] workqueue: Allow to expose ordered workqueues via sysfs

From: Sebastian Andrzej Siewior

Date: Thu Feb 05 2026 - 08:43:05 EST


On 2026-02-05 12:55:58 [+0100], To linux-efi@xxxxxxxxxxxxxxx wrote:
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -7097,6 +7097,13 @@ static ssize_t max_active_store(struct device *dev,
> struct workqueue_struct *wq = dev_to_wq(dev);
> int val;
>
> + /*
> + * Adjusting max_active breaks ordering guarantee. Changing it has no
> + * effect on BH worker.
> + */
> + if (wq->flags & (WQ_BH | __WQ_ORDERED))
> + return -EACCES;
> +
> if (sscanf(buf, "%d", &val) != 1 || val <= 0)
> return -EINVAL;

I have been informed that instead of this -EACCES I could do the
following and exposing only the max_active (and per_cpu) attribute as
RO instead.

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 625ee8cc47f40..793b59ce99edb 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -7097,13 +7097,6 @@ static ssize_t max_active_store(struct device *dev,
struct workqueue_struct *wq = dev_to_wq(dev);
int val;

- /*
- * Adjusting max_active breaks ordering guarantee. Changing it has no
- * effect on BH worker.
- */
- if (wq->flags & (WQ_BH | __WQ_ORDERED))
- return -EACCES;
-
if (sscanf(buf, "%d", &val) != 1 || val <= 0)
return -EINVAL;

@@ -7117,7 +7110,26 @@ static struct attribute *wq_sysfs_attrs[] = {
&dev_attr_max_active.attr,
NULL,
};
-ATTRIBUTE_GROUPS(wq_sysfs);
+
+static umode_t wq_sysfs_is_visible(struct kobject *kobj, struct attribute *a, int n)
+{
+ struct device *dev = kobj_to_dev(kobj);
+ struct workqueue_struct *wq = dev_to_wq(dev);
+
+ /*
+ * Adjusting max_active breaks ordering guarantee. Changing it has no
+ * effect on BH worker. Limit max_active to RO in such case.
+ */
+ if (wq->flags & (WQ_BH | __WQ_ORDERED))
+ return 0444;
+ return a->mode;
+}
+
+static const struct attribute_group wq_sysfs_group = {
+ .is_visible = wq_sysfs_is_visible,
+ .attrs = wq_sysfs_attrs,
+};
+__ATTRIBUTE_GROUPS(wq_sysfs);

static ssize_t wq_nice_show(struct device *dev, struct device_attribute *attr,
char *buf)