Skip to contentSkip to conversation

kernel/sched/core.c:5262 pick_next_task() error: we previously assumed 'next' could be null (see line 5258)

PATCH New Dan Carpenter 1 participant 1 message Jan 11, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 10/11 kernel/sched/core.c:5262 pick_next_task() error: we previously assumed 'next' could be null (see line 5258)

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git sched/core-sched
head:   ead81f232b5b31ab6240a719ff3bad564c3f0e4c
commit: 6f7eefbb382e8c5fa56180f8cd5becb5f882a3d6 [10/11] sched/fair: Snapshot the min_vruntime of CPUs on force idle
config: x86_64-randconfig-m001-20210108 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate

smatch warnings:
kernel/sched/core.c:5262 pick_next_task() error: we previously assumed 'next' could be null (see line 5258)

vim +/next +5262 kernel/sched/core.c

2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5225  
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5226  	put_prev_task_balance(rq, prev, rf);
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5227  
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5228  	smt_mask = cpu_smt_mask(cpu);
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5229) 	need_sync = !!rq->core->core_cookie;
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5230) 
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5231) 	/* reset state */
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5232) 	rq->core->core_cookie = 0UL;
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5233) 	if (rq->core->core_forceidle) {
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5234) 		need_sync = true;
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5235) 		fi_before = true;
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5236) 		rq->core->core_forceidle = false;
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5237) 	}
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5238  
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5239  	/*
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5240  	 * core->core_task_seq, core->core_pick_seq, rq->core_sched_seq
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5241  	 *
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5242  	 * @task_seq guards the task state ({en,de}queues)
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5243  	 * @pick_seq is the @task_seq we did a selection on
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5244  	 * @sched_seq is the @pick_seq we scheduled
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5245  	 *
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5246  	 * However, preemptions can cause multiple picks on the same task set.
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5247  	 * 'Fix' this by also increasing @task_seq for every pick.
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5248  	 */
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5249  	rq->core->core_task_seq++;
2d8ac06b6ca3a0f Peter Zijlstra          2020-11-17  5250  
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5251) 	/*
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5252) 	 * Optimize for common case where this CPU has no cookies
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5253) 	 * and there are no cookied tasks running on siblings.
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5254) 	 */
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5255) 	if (!need_sync) {
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5256) 		for_each_class(class) {
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5257) 			next = class->pick_task(rq);
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17 @5258) 			if (next)
                                                                                    ^^^^

Will we always find a valid "next"?

d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5259) 				break;
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5260) 		}
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5261) 
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17 @5262) 		if (!next->core_cookie) {
                                                                             ^^^^^^^^^^^^^^^^^

Unchecked dereference.

d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5263) 			rq->core_pick = NULL;
6f7eefbb382e8c5 Joel Fernandes (Google  2020-11-17  5264) 			/*
6f7eefbb382e8c5 Joel Fernandes (Google  2020-11-17  5265) 			 * For robustness, update the min_vruntime_fi for
6f7eefbb382e8c5 Joel Fernandes (Google  2020-11-17  5266) 			 * unconstrained picks as well.
6f7eefbb382e8c5 Joel Fernandes (Google  2020-11-17  5267) 			 */
6f7eefbb382e8c5 Joel Fernandes (Google  2020-11-17  5268) 			WARN_ON_ONCE(fi_before);
6f7eefbb382e8c5 Joel Fernandes (Google  2020-11-17  5269) 			task_vruntime_update(rq, next, false);
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5270) 			goto done;
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5271) 		}
651b592b4b80bae Vineeth Pillai          2020-11-17  5272  	}
d7bbf5f9ab91135 Joel Fernandes (Google  2020-11-17  5273) 

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org