Skip to content

Commit aa00d89

Browse files
tang-chentorvalds
authored andcommitted
sched: do not use cpu_to_node() to find an offlined cpu's node.
If a cpu is offline, its nid will be set to -1, and cpu_to_node(cpu) will return -1. As a result, cpumask_of_node(nid) will return NULL. In this case, find_next_bit() in for_each_cpu will get a NULL pointer and cause panic. Here is a call trace: Call Trace: <IRQ> select_fallback_rq+0x71/0x190 try_to_wake_up+0x2cb/0x2f0 wake_up_process+0x15/0x20 hrtimer_wakeup+0x22/0x30 __run_hrtimer+0x83/0x320 hrtimer_interrupt+0x106/0x280 smp_apic_timer_interrupt+0x69/0x99 apic_timer_interrupt+0x6f/0x80 There is a hrtimer process sleeping, whose cpu has already been offlined. When it is waken up, it tries to find another cpu to run, and get a -1 nid. As a result, cpumask_of_node(-1) returns NULL, and causes ernel panic. This patch fixes this problem by judging if the nid is -1. If nid is not -1, a cpu on the same node will be picked. Else, a online cpu on another node will be picked. Signed-off-by: Tang Chen <[email protected]> Signed-off-by: Wen Congyang <[email protected]> Cc: Yasuaki Ishimatsu <[email protected]> Cc: David Rientjes <[email protected]> Cc: Jiang Liu <[email protected]> Cc: Minchan Kim <[email protected]> Cc: KOSAKI Motohiro <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Peter Zijlstra <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent e13fe86 commit aa00d89

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

kernel/sched/core.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,18 +1132,28 @@ EXPORT_SYMBOL_GPL(kick_process);
11321132
*/
11331133
static int select_fallback_rq(int cpu, struct task_struct *p)
11341134
{
1135-
const struct cpumask *nodemask = cpumask_of_node(cpu_to_node(cpu));
1135+
int nid = cpu_to_node(cpu);
1136+
const struct cpumask *nodemask = NULL;
11361137
enum { cpuset, possible, fail } state = cpuset;
11371138
int dest_cpu;
11381139

1139-
/* Look for allowed, online CPU in same node. */
1140-
for_each_cpu(dest_cpu, nodemask) {
1141-
if (!cpu_online(dest_cpu))
1142-
continue;
1143-
if (!cpu_active(dest_cpu))
1144-
continue;
1145-
if (cpumask_test_cpu(dest_cpu, tsk_cpus_allowed(p)))
1146-
return dest_cpu;
1140+
/*
1141+
* If the node that the cpu is on has been offlined, cpu_to_node()
1142+
* will return -1. There is no cpu on the node, and we should
1143+
* select the cpu on the other node.
1144+
*/
1145+
if (nid != -1) {
1146+
nodemask = cpumask_of_node(nid);
1147+
1148+
/* Look for allowed, online CPU in same node. */
1149+
for_each_cpu(dest_cpu, nodemask) {
1150+
if (!cpu_online(dest_cpu))
1151+
continue;
1152+
if (!cpu_active(dest_cpu))
1153+
continue;
1154+
if (cpumask_test_cpu(dest_cpu, tsk_cpus_allowed(p)))
1155+
return dest_cpu;
1156+
}
11471157
}
11481158

11491159
for (;;) {

0 commit comments

Comments
 (0)