Skip to content

Commit 533445c

Browse files
osandovIngo Molnar
authored andcommitted
sched/core: Fix regression in cpuset_cpu_inactive() for suspend
Commit 3c18d44 ("sched/core: Check for available DL bandwidth in cpuset_cpu_inactive()"), a SCHED_DEADLINE bugfix, had a logic error that caused a regression in setting a CPU inactive during suspend. I ran into this when a program was failing pthread_setaffinity_np() with EINVAL after a suspend+wake up. A simple reproducer: $ ./a.out sched_setaffinity: Success $ systemctl suspend $ ./a.out sched_setaffinity: Invalid argument ... where ./a.out is: #define _GNU_SOURCE #include <errno.h> #include <sched.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(void) { long num_cores; cpu_set_t cpu_set; int ret; num_cores = sysconf(_SC_NPROCESSORS_ONLN); CPU_ZERO(&cpu_set); CPU_SET(num_cores - 1, &cpu_set); errno = 0; ret = sched_setaffinity(getpid(), sizeof(cpu_set), &cpu_set); perror("sched_setaffinity"); return ret ? EXIT_FAILURE : EXIT_SUCCESS; } The mistake is that suspend is handled in the action == CPU_DOWN_PREPARE_FROZEN case of the switch statement in cpuset_cpu_inactive(). However, the commit in question masked out CPU_TASKS_FROZEN from the action, making this case dead. The fix is straightforward. Signed-off-by: Omar Sandoval <osandov@osandov.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Borislav Petkov <bp@alien8.de> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Juri Lelli <juri.lelli@arm.com> Cc: Thomas Gleixner <tglx@linutronix.de> Fixes: 3c18d44 ("sched/core: Check for available DL bandwidth in cpuset_cpu_inactive()") Link: http://lkml.kernel.org/r/1cb5ecb3d6543c38cce5790387f336f54ec8e2bc.1430733960.git.osandov@osandov.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 0782e63 commit 533445c

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

kernel/sched/core.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6999,27 +6999,23 @@ static int cpuset_cpu_inactive(struct notifier_block *nfb, unsigned long action,
69996999
unsigned long flags;
70007000
long cpu = (long)hcpu;
70017001
struct dl_bw *dl_b;
7002+
bool overflow;
7003+
int cpus;
70027004

7003-
switch (action & ~CPU_TASKS_FROZEN) {
7005+
switch (action) {
70047006
case CPU_DOWN_PREPARE:
7005-
/* explicitly allow suspend */
7006-
if (!(action & CPU_TASKS_FROZEN)) {
7007-
bool overflow;
7008-
int cpus;
7009-
7010-
rcu_read_lock_sched();
7011-
dl_b = dl_bw_of(cpu);
7007+
rcu_read_lock_sched();
7008+
dl_b = dl_bw_of(cpu);
70127009

7013-
raw_spin_lock_irqsave(&dl_b->lock, flags);
7014-
cpus = dl_bw_cpus(cpu);
7015-
overflow = __dl_overflow(dl_b, cpus, 0, 0);
7016-
raw_spin_unlock_irqrestore(&dl_b->lock, flags);
7010+
raw_spin_lock_irqsave(&dl_b->lock, flags);
7011+
cpus = dl_bw_cpus(cpu);
7012+
overflow = __dl_overflow(dl_b, cpus, 0, 0);
7013+
raw_spin_unlock_irqrestore(&dl_b->lock, flags);
70177014

7018-
rcu_read_unlock_sched();
7015+
rcu_read_unlock_sched();
70197016

7020-
if (overflow)
7021-
return notifier_from_errno(-EBUSY);
7022-
}
7017+
if (overflow)
7018+
return notifier_from_errno(-EBUSY);
70237019
cpuset_update_active_cpus(false);
70247020
break;
70257021
case CPU_DOWN_PREPARE_FROZEN:

0 commit comments

Comments
 (0)