Skip to contentSkip to conversation

efi: Expose the runtime-services workqueue via sysfs

PATCH Applied Sebastian Andrzej Siewior 3 participants 9 messages Feb 27

Subsystems (3)
lore
Share & tools
lore

Sebastian Andrzej Siewior

author maintainer
#0 lore raw

v2 cover efi: Expose the runtime-services workqueue via sysfs

EFI runtime services are disabled on PREEMPT_RT by default which can be overwritten on the boot command line. For native EFI, an invocation requires to disable preemption an x86 while a call is made into EFI. Even if it does not (as it is the case on arm64) the EFI function can disable interrupts. This makes the time spent in EFI is not deterministic.
While accessing the efi-rtc device can be avoided by using a native driver, accessing the "variables" is important and there is no second path.

The "runtime-wrappers" is wrapping access to the EFI callback via a workqueue. On a SMP system one CPU could be declared as housekeeping/ not-realtime-capable and force all EFI invocation to be performed on this CPU. This could be achieved by setting workqueue.unbound_cpus or
/sys/devices/virtual/workqueue/cpumask

at runtime. This however will affect all workqueues and might not be desired. With an explicit setting such as
/sys/devices/virtual/workqueue/efi_runtime/cpumask

it looks like an official way to limit the CPUs involved here.

With this in place I was wondering if EFI_DISABLE_RUNTIME could be lifted at runtime on SMP systems. But given the unbound_cpus option and the auto-config based on NOHZ-full it might not be wise to add yet another smart option here. Also it needs to be a subset of root cpumask or it won't be effective.

v1…v2: https://lore.kernel.org/all/[email protected]/
- For BH and WQ_ORDERED worker make the max_active RO.

Sebastian Andrzej Siewior (2):
workqueue: Allow to expose ordered workqueues via sysfs
efi: Allow to expose the workqueue via sysfs

 drivers/firmware/efi/efi.c |  2 +-
 kernel/workqueue.c         | 28 ++++++++++++++++++++--------
 2 files changed, 21 insertions(+), 9 deletions(-)
Signature · 1 line
2.51.0
author maintainer
#1 lore raw

PATCH v2 1/2 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.

---
 kernel/workqueue.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
kernel/workqueue.c +20 -8
index aeaec79bc09c4..2f95cb0d2f1b8 100644
@@ -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;
Signature · 1 line
2.51.0
maintainer Acked-by on v2 1/2
#2 lore raw

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

Quoted 8 lines · Sebastian Andrzej Siewior

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.

Quoted 8 lines

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.

I can apply this to wq/for-7.1. Would that work?

Thanks.

Signature · 1 line
tejun
author maintainer
#3 lore raw

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

Quoted 1 line · Tejun Heo

Thank.

Quoted 1 line

I can apply this to wq/for-7.1. Would that work?

I think you need to take both since 2/2 can't be applied independently. Maybe Ard is going to give his blessing ;)

Quoted 1 line

Thanks.

Sebastian

maintainer
#4 lore raw

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

Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 1 line · Tejun Heo

Thank.

Quoted 1 line

I can apply this to wq/for-7.1. Would that work?

I think you need to take both since 2/2 can't be applied independently. Maybe Ard is going to give his blessing ;)

iIRC I already acked v1.

maintainer
#5 lore raw

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

Quoted 7 lines · Ard Biesheuvel
Quoted 4 lines · Sebastian Andrzej Siewior
Quoted 1 line · Tejun Heo

Thank.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

I can apply this to wq/for-7.1. Would that work?

I think you need to take both since 2/2 can't be applied independently. Maybe Ard is going to give his blessing ;)

iIRC I already acked v1.

Ard, do you want me to take both patches or wann pull from wq/for-7.1?

Thanks.

Signature · 1 line
tejun
maintainer
#6 lore raw

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

Quoted 10 lines · Tejun Heo
Quoted 9 lines · Ard Biesheuvel
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 1 line · Tejun Heo

Thank.

Quoted 1 line

I can apply this to wq/for-7.1. Would that work?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I think you need to take both since 2/2 can't be applied independently. Maybe Ard is going to give his blessing ;)

iIRC I already acked v1.

Ard, do you want me to take both patches or wann pull from wq/for-7.1?

Please take both - thanks.

author maintainer
#7 lore raw

PATCH v2 2/2 efi: Allow to expose the workqueue via sysfs

In reply to Sebastian Andrzej Siewior

Exposing the efi_rts_wq workqueue via sysfs provides an easy mechanism to restrict EFI firmware invocation to certain CPU(s).
This can be used to restrict EFI invocations to specific CPUs while allowing other workqueue to use the remaning CPUs.

Expose the workqueue via sysfs. Change the name to efi_runtime which is what will be visible under sysfs.

---
 drivers/firmware/efi/efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/efi.c +1 -1
index b2fb92a4bbd11..3dab284a7754d 100644
@@ -423,7 +423,7 @@ static int __init efisubsys_init(void)
 		 * ordered workqueue (which creates only one execution context)
 		 * should suffice for all our needs.
 		 */
-		efi_rts_wq = alloc_ordered_workqueue("efi_rts_wq", 0);
+		efi_rts_wq = alloc_ordered_workqueue("efi_runtime", WQ_SYSFS);
 		if (!efi_rts_wq) {
 			pr_err("Creating efi_rts_wq failed, EFI runtime services disabled.\n");
 			clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
Signature · 1 line
2.51.0