workqueue: Allow to expose ordered workqueues via sysfs

JIRA: https://redhat.atlassian.net/browse/RHEL-175657

commit a4aa8d94f24317338cf6f62eb3267ad99a2ff7f7
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date:   Fri Feb 27 18:01:02 2026 +0100

    workqueue: Allow to expose ordered workqueues via sysfs

    Ordered workqueues are not exposed via sysfs because the 'max_active'
    attribute changes the number actives worker. More than one active worker
    can break ordering guarantees.

    This can be avoided by forbidding writes the file for ordered
    workqueues. Exposing it via sysfs allows to alter other attributes such
    as the cpumask on which CPU the worker can run.

    The 'max_active' value shouldn't be changed for BH worker because the
    core never spawns additional worker and the worker itself can not be
    preempted. So this make no sense.

    Allow to expose ordered workqueues via sysfs if requested and forbid
    changing 'max_active' value for ordered and BH worker.

    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Acked-by: Tejun Heo <tj@kernel.org>
    Acked-by: Ard Biesheuvel <ardb@kernel.org>
    Signed-off-by: Tejun Heo <tj@kernel.org>

Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
This commit is contained in:
Luis Claudio R. Goncalves
2026-05-13 09:38:07 -03:00
parent bbf7cf4002
commit eb3c98b0b8
+20 -8
View File
@@ -7147,7 +7147,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 void apply_wqattrs_lock(void)
{
@@ -7468,13 +7487,6 @@ int workqueue_sysfs_register(struct workqueue_struct *wq)
struct wq_device *wq_dev;
int ret;
/*
* Adjusting max_active breaks ordering guarantee. Disallow exposing
* ordered workqueues.
*/
if (WARN_ON(wq->flags & __WQ_ORDERED))
return -EINVAL;
wq->wq_dev = wq_dev = kzalloc(sizeof(*wq_dev), GFP_KERNEL);
if (!wq_dev)
return -ENOMEM;