Skip to content

sched/treewide: Clean up various racy task affinity issues

Thomas Gleixner linux-acpi linux-crypto linux-ia64 linux-pm linuxppc-dev lkml sparclinux 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest13 patches 17 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13ia64/topology: Remove cpus_allowed manipulationarch/ia64/kernel/topology.c+0 -60 replies
2/13workqueue: Provide work_on_cpu_safe()include/linux/workqueue.h kernel/workqueue.c+28 -06 replies
3/13ia64/salinfo: Replace racy task affinity logicarch/ia64/kernel/salinfo.c+12 -190 replies
4/13ia64/sn/hwperf: Replace racy task affinity logicarch/ia64/sn/kernel/sn2/sn_hwperf.c+9 -70 replies
4/13ia64/sn/hwperf: Replace racy task affinity logicarch/ia64/sn/kernel/sn2/sn_hwperf.c+9 -80 replies
5/13powerpc/smp: Replace open coded task affinity logicarch/powerpc/kernel/smp.c+11 -151 reply
6/13sparc/sysfs: Replace racy task affinity logicarch/sparc/kernel/sysfs.c+9 -272 replies
7/13ACPI/processor: Fix error handling in __acpi_processor_start()drivers/acpi/processor_driver.c+3 -00 replies
8/13ACPI/processor: Replace racy task affinity logic.drivers/acpi/processor_driver.c drivers/acpi/processor_throttling.c+19 -193 replies
9/13cpufreq/ia64: Replace racy task affinity logicdrivers/cpufreq/ia64-acpi-cpufreq.c+38 -532 replies
10/13cpufreq/sh: Replace racy task affinity logicdrivers/cpufreq/sh-cpufreq.c+27 -181 reply
11/13cpufreq/sparc-us3: Replace racy task affinity logicdrivers/cpufreq/sparc-us3-cpufreq.c+16 -301 reply
12/13cpufreq/sparc-us2e: Replace racy task affinity logicdrivers/cpufreq/sparc-us2e-cpufreq.c+21 -244 replies
13/13crypto: n2 - Replace racy task affinity logicdrivers/crypto/n2_core.c+16 -153 replies

Reviews trailers per patch

8 of 14 patches have a Reviewed-by or Acked-by.

PatchDavid S. MillerViresh KumarHerbert XuMichael EllermanTejun Heo
1/13
2/13A-b
3/13
4/13
4/13
5/13A-b
6/13A-b A-b
7/13
8/13
9/13A-b
10/13A-b
11/13A-b
12/13A-b A-b A-b A-b
13/13A-b A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v1 thread

Cover letter [patch 00/13] sched/treewide: Clean up various racy task affinity issues

While dealing with the fallout of the scheduler cleanups on RT, we found several racy usage sites of the following scheme:

	cpumask_copy(&save_cpus_allowed, &current->cpus_allowed);
	set_cpus_allowed_ptr(current, cpumask_of(cpu));
	do_stuff();
	set_cpus_allowed_ptr(current, &save_cpus_allowed);

That's racy in two aspects:

1) Nothing prevents the CPU from being unplugged after the temporary affinity setting is in place. This results on code being executed on the wrong CPU(s).

2) Nothing prevents a concurrent affinity setting from user space. That also results in code being executed on the wrong CPU(s) and the restore of the previous affinity setting overwrites the new one.

Various variants of cleanups:

- Removal, because the calling thread is already guaranteed to run on the correct CPU.

- Conversion to smp function calls (simple register read/write)

- Conversion to work_on_cpu(). There were even files containing comments to that effect.

- The rest needs seperate hotplug protection for work_on_cpu(). To avoid open coding the

	get_online_cpus();
	if (cpu_online(cpu))
		ret = do_stuff();
	else
		ret = -ENODEV;
	put_online_cpus();

scheme this series provides a new helper function work_on_cpu_safe() which implements the above.

Aside of fixing these races this allows to restrict the access to current->cpus_allowed with a follow up series.

Thanks,

tglx

---
 arch/ia64/kernel/salinfo.c           |   31 ++++-------
 arch/ia64/kernel/topology.c          |    6 --
 arch/ia64/sn/kernel/sn2/sn_hwperf.c  |   16 +++---
 arch/powerpc/kernel/smp.c            |   26 ++++------
 arch/sparc/kernel/sysfs.c            |   36 +++----------
 drivers/acpi/processor_driver.c      |   10 +++
 drivers/acpi/processor_throttling.c  |   31 +++++------
 drivers/cpufreq/ia64-acpi-cpufreq.c  |   91 ++++++++++++++---------------------
 drivers/cpufreq/sh-cpufreq.c         |   45 ++++++++++-------
 drivers/cpufreq/sparc-us2e-cpufreq.c |   45 ++++++++---------
 drivers/cpufreq/sparc-us3-cpufreq.c  |   46 ++++++-----------
 drivers/crypto/n2_core.c             |   31 ++++++-----
 include/linux/workqueue.h            |    5 +
 kernel/workqueue.c                   |   23 ++++++++
 14 files changed, 209 insertions(+), 233 deletions(-)