[PATCH] sched: drop unused variable cpumask in mm_cid_get()

André Draszik posted 1 patch 2 months, 2 weeks ago
kernel/sched/sched.h | 2 --
1 file changed, 2 deletions(-)
[PATCH] sched: drop unused variable cpumask in mm_cid_get()
Posted by André Draszik 2 months, 2 weeks ago
When compiling with W=1, we get the following warning:

In file included from kernel/sched/rq-offsets.c:5:
kernel/sched/sched.h:3743:18: error: variable 'cpumask' set but not used [-Werror,-Wunused-but-set-variable]
 3743 |         struct cpumask *cpumask;
      |                         ^
1 error generated.

Simply drop the variable.

Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
 kernel/sched/sched.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 1f5d07067f60a3195c11b0bfe203e027ebc3e3c5..361f9101cef97cde2b4cae963c3eed6e745283c8 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3740,11 +3740,9 @@ static inline int mm_cid_get(struct rq *rq, struct task_struct *t,
 			     struct mm_struct *mm)
 {
 	struct mm_cid __percpu *pcpu_cid = mm->pcpu_cid;
-	struct cpumask *cpumask;
 	int cid;
 
 	lockdep_assert_rq_held(rq);
-	cpumask = mm_cidmask(mm);
 	cid = __this_cpu_read(pcpu_cid->cid);
 	if (mm_cid_is_valid(cid)) {
 		mm_cid_snapshot_time(rq, mm);

---
base-commit: 3b9b1f8df454caa453c7fb07689064edb2eda90a
change-id: 20251002-sched-w1-c45c284e1775

Best regards,
-- 
André Draszik <andre.draszik@linaro.org>

Re: [PATCH] sched: drop unused variable cpumask in mm_cid_get()
Posted by Dan Carpenter 2 months, 2 weeks ago
Hi André,

kernel test robot noticed the following build warnings:

url:    https://github.com/intel-lab-lkp/linux/commits/Andr-Draszik/sched-drop-unused-variable-cpumask-in-mm_cid_get/20251002-192448
base:   3b9b1f8df454caa453c7fb07689064edb2eda90a
patch link:    https://lore.kernel.org/r/20251002-sched-w1-v1-1-a6fdf549d179%40linaro.org
patch subject: [PATCH] sched: drop unused variable cpumask in mm_cid_get()
config: i386-randconfig-141-20251004 (https://download.01.org/0day-ci/archive/20251004/202510041546.DvhFLp2x-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202510041546.DvhFLp2x-lkp@intel.com/

smatch warnings:
kernel/sched/sched.h:3810 switch_mm_cid() error: we previously assumed 'next->mm' could be null (see line 3772)

vim +3810 kernel/sched/sched.h

223baf9d17f25e Mathieu Desnoyers 2023-04-20  3762  static inline void switch_mm_cid(struct rq *rq,
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3763  				 struct task_struct *prev,
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3764  				 struct task_struct *next)
af7f588d8f7355 Mathieu Desnoyers 2022-11-22  3765  {
af7f588d8f7355 Mathieu Desnoyers 2022-11-22  3766  	/*
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3767  	 * Provide a memory barrier between rq->curr store and load of
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3768  	 * {prev,next}->mm->pcpu_cid[cpu] on rq->curr->mm transition.
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3769  	 *
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3770  	 * Should be adapted if context_switch() is modified.
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3771  	 */
223baf9d17f25e Mathieu Desnoyers 2023-04-20 @3772  	if (!next->mm) {                                // to kernel

Can ->mm_cid_active be true when next->mm is false?  I don't know.
If so then it's fine.  I suspect it's fine...

223baf9d17f25e Mathieu Desnoyers 2023-04-20  3773  		/*
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3774  		 * user -> kernel transition does not guarantee a barrier, but
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3775  		 * we can use the fact that it performs an atomic operation in
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3776  		 * mmgrab().
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3777  		 */
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3778  		if (prev->mm)                           // from user
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3779  			smp_mb__after_mmgrab();
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3780  		/*
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3781  		 * kernel -> kernel transition does not change rq->curr->mm
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3782  		 * state. It stays NULL.
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3783  		 */
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3784  	} else {                                        // to user
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3785  		/*
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3786  		 * kernel -> user transition does not provide a barrier
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3787  		 * between rq->curr store and load of {prev,next}->mm->pcpu_cid[cpu].
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3788  		 * Provide it here.
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3789  		 */
fe90f3967bdb3e Mathieu Desnoyers 2024-04-15  3790  		if (!prev->mm) {                        // from kernel
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3791  			smp_mb();
fe90f3967bdb3e Mathieu Desnoyers 2024-04-15  3792  		} else {				// from user
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3793  			/*
fe90f3967bdb3e Mathieu Desnoyers 2024-04-15  3794  			 * user->user transition relies on an implicit
fe90f3967bdb3e Mathieu Desnoyers 2024-04-15  3795  			 * memory barrier in switch_mm() when
fe90f3967bdb3e Mathieu Desnoyers 2024-04-15  3796  			 * current->mm changes. If the architecture
fe90f3967bdb3e Mathieu Desnoyers 2024-04-15  3797  			 * switch_mm() does not have an implicit memory
fe90f3967bdb3e Mathieu Desnoyers 2024-04-15  3798  			 * barrier, it is emitted here.  If current->mm
fe90f3967bdb3e Mathieu Desnoyers 2024-04-15  3799  			 * is unchanged, no barrier is needed.
af7f588d8f7355 Mathieu Desnoyers 2022-11-22  3800  			 */
fe90f3967bdb3e Mathieu Desnoyers 2024-04-15  3801  			smp_mb__after_switch_mm();
fe90f3967bdb3e Mathieu Desnoyers 2024-04-15  3802  		}
af7f588d8f7355 Mathieu Desnoyers 2022-11-22  3803  	}
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3804  	if (prev->mm_cid_active) {
223baf9d17f25e Mathieu Desnoyers 2023-04-20  3805  		mm_cid_snapshot_time(rq, prev->mm);

Same thing for "prev->mm".

223baf9d17f25e Mathieu Desnoyers 2023-04-20  3806  		mm_cid_put_lazy(prev);
af7f588d8f7355 Mathieu Desnoyers 2022-11-22  3807  		prev->mm_cid = -1;
af7f588d8f7355 Mathieu Desnoyers 2022-11-22  3808  	}
af7f588d8f7355 Mathieu Desnoyers 2022-11-22  3809  	if (next->mm_cid_active)
7e019dcc470f27 Mathieu Desnoyers 2024-10-09 @3810  		next->last_mm_cid = next->mm_cid = mm_cid_get(rq, next, next->mm);
                                                                                                                        ^^^^^^^^
Unchecked dereference.

af7f588d8f7355 Mathieu Desnoyers 2022-11-22  3811  }

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki