Commit a4aa8d94 authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Tejun Heo
Browse files

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: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Acked-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent 4a91a33f
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -7176,7 +7176,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)
@@ -7479,13 +7498,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_obj(*wq_dev);
	if (!wq_dev)
		return -ENOMEM;