lib/smp_processor_id: Use is_percpu_thread() instead of nr_cpus_allowed
authorYejune Deng <yejune.deng@gmail.com>
Mon, 10 May 2021 15:10:24 +0000 (16:10 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 19 May 2021 08:51:40 +0000 (10:51 +0200)
is_percpu_thread() more elegantly handles SMP vs UP, and further checks the
presence of PF_NO_SETAFFINITY. This lets us catch cases where
check_preemption_disabled() can race with a concurrent sched_setaffinity().

Signed-off-by: Yejune Deng <yejune.deng@gmail.com>
[Amended changelog]
Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210510151024.2448573-3-valentin.schneider@arm.com
lib/smp_processor_id.c

index 1c1dbd3003257a618c7420d7286cf78668cc4051..046ac6297c7811ad66e35cb271dabb5ceb015c4d 100644 (file)
@@ -19,11 +19,7 @@ unsigned int check_preemption_disabled(const char *what1, const char *what2)
        if (irqs_disabled())
                goto out;
 
-       /*
-        * Kernel threads bound to a single CPU can safely use
-        * smp_processor_id():
-        */
-       if (current->nr_cpus_allowed == 1)
+       if (is_percpu_thread())
                goto out;
 
 #ifdef CONFIG_SMP