diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
index da87385683ccc6f3de8f6deb57a820ad59c6f9ce..e4d4483fd617bc1ce3d3dadf95e2a4d8b92aae3f 100644
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -1389,6 +1389,8 @@ static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flag
 
 				if (candidate == -1 || candidate == cpu) {
 					for_each_cpu(i, sched_domain_span(tmp)) {
+						if (!cpumask_test_cpu(i, &p->cpus_allowed))
+							continue;
 						if (!cpu_rq(i)->cfs.nr_running) {
 							candidate = i;
 							break;