From nobody Thu Apr 2 22:22:21 2026 Received: from mail-dl1-f48.google.com (mail-dl1-f48.google.com [74.125.82.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06AF5248880 for ; Sat, 14 Feb 2026 10:20:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771064420; cv=none; b=WPf3waQr/HH6wHtriTv7r5xMtlSDvaqBRQOfBcqzyTgTujAt9qq7h8ykiH2KrWIzP+rx1fR6FLcgH90x7LzFDxshPc5Ye4KfG9hidKozDjEnvcKslNSnAH/yqKijfKHvNu/pFa0Btk62Su03ZlEnuFwjC27Lm6HdSHiFxFx5CzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771064420; c=relaxed/simple; bh=7kpNh99AToG/vTQK0WBVKOZg3twB9gDz48MBmJUiCVQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hVwijEt0Off6TGEuztW4QkhreltvFP/wur9ZQjegNQc9bK9Qu2QQVNK2TLyM3pRTYuMNXWGQwOqEtJanP7Eta2UFjE5oqkpglFrIOdL/ruH+TmP7QMIQu4x5WFNoaqrbHNahLXF3G0bquLEHMV3XqgWm/puFoBBG16d/JYh5osc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CPAPObzU; arc=none smtp.client-ip=74.125.82.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CPAPObzU" Received: by mail-dl1-f48.google.com with SMTP id a92af1059eb24-1270ac5d3efso1685915c88.1 for ; Sat, 14 Feb 2026 02:20:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771064418; x=1771669218; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=byrtd/ubLay3CAsg8BBm3ST0N7GyC7ok0dhlgBs7r74=; b=CPAPObzU+yxhv1PBEEpEBujES1MqXMJLRMYuTvQXnLYjQ0X/YfMoXbr7FzjruYMqRs MQugMXQFZTff8a5yf1YT0xayCgrfSDU1MMGlWKDDAiQ/6YLoetopWb7UIi1CzODSCygD Y81OZ+/tvRkcmoVzrFD2rTbynjIJirXM3vtzRA99Dx4ssVammXYEDbQ5c2J+H2foZ0BX 5ZiA/e3FAHlhW1Bq1g7JrdT9vkXKgIZEd5HrycRMEdCcmA7dG9LQs0iEFm1Za9sdShEz SfNTFTjYsqdBpEsE7a3na0LNdSypflA7nWBSzc6xP0Uy9g7ZXLrJS8PHaBZtjuuA2EHx FsOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771064418; x=1771669218; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=byrtd/ubLay3CAsg8BBm3ST0N7GyC7ok0dhlgBs7r74=; b=eAurdR9Hh5RqbDiEpo+FeYt6nIwXvfsy09wf0UUHsTrp1wNco4cBJbqf6jRTOgML4t Igc1trfCP26W2LWdtrtYnxbma+1MyhzPJgU3bMb2S91Djgf4ABPBk3FAxDWYXTUO0Vci ed5IXqheSyqUl7lyPiID+8kkr4X//2uKR5iH4kI0/cRmG+jQIU1WFpEbRXgJ/9JzkA/a /veHAKjRvCT5L3epB/GcFSIf4hfJZ+Dh5xNL0M/aHYo4aS8CLjh3jAaQp1QhzIcS11K7 oX3d3MN4CaQe7pNpE2TJf+tFH9rYgY7idO4ZDy3jvGC1GKqEkcfFsJUbN4tWRB6O31dB HT4A== X-Forwarded-Encrypted: i=1; AJvYcCXshjTes9lVkqzhwWG4gVfeS0jpyLHs4inmFWj+PqVEef4HQ8LR1BRCAzkLmPoyJwT1hURVqHfDM7ItI/k=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1vt+IdHZC2wzhS/fqhLB+aVzE4E4bHFrzWcZkU3ARqdA/dXGZ UyZ11+dJ8eCWI5bLdtoHXg9GPUQLhXRhtzk+l+mDN+toDN91KwxGTD2u X-Gm-Gg: AZuq6aJtY8SX/jdyugKEhar6islmVJNFnZ8kXs8PcyXwtYl2iuHzV3ZqqeD4wwAvpGX lciZIB6kxVBP+t9l1+paUJgdr7gzCP3ehUsQJhztHve7WvSHd6i3rwTAInjo6k6KOPNbiCxBB3S LELcIZGVsK1ygL8GqsKsXF/VLU0U5JT2K6lLGnQrPh5tFy8dd6FRy5yPjzmnjIAE0vj0n9T0t+X O7PubRqMJEuCRezc12BfRhEU8ro+rWQKzpaJDglbKWe491tO+JpUuZ9Ibf4NK16+PkcpKoWm8dy VrOEy1s+imCLFW6nC8MSyFepGPbLeoe1RzcN7liNLcVdbFW9IkOr+MeT8OMuDCUkZ/II5Ey0c81 kD/w/yfRrYHdAsbPa9o3uErdR0kqojnGbGoDHKGO6ecq35rG1HAR8R03qP96xk5gxB2kZ3E2cfy ytD1p946PILbui5M1aDPsP+2wLocIh5FUjqb+lJn+SiUIyq69X+tkQuuRSIzw1pifrUPJ7lDmeK J+bUepWngz754mucSSNYd/8t9pJW+Xxyw== X-Received: by 2002:a05:7022:238d:b0:11b:95fe:beed with SMTP id a92af1059eb24-12741bd1088mr795303c88.38.1771064417927; Sat, 14 Feb 2026 02:20:17 -0800 (PST) Received: from localhost.localdomain (108-214-96-168.lightspeed.sntcca.sbcglobal.net. [108.214.96.168]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12742aff32asm2032277c88.0.2026.02.14.02.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Feb 2026 02:20:17 -0800 (PST) From: Sun Jian To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org Cc: dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, nathan@kernel.org, nick.desaulniers+lkml@gmail.com, morbo@google.com, justinstitt@google.com, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sun Jian Subject: [PATCH] sched: rcu: fix rq->{curr,donor} address space annotations Date: Sat, 14 Feb 2026 18:20:05 +0800 Message-ID: <20260214102005.1398306-1-sun.jian.kdev@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With CONFIG_SCHED_PROXY_EXEC, struct rq::curr and rq::donor are annotated as __rcu. Several call sites access these pointers as plain struct task_struct * even while the relevant rq lock is held, which triggers address space warnings from static checkers. Fix these sites by: - using rcu_dereference_protected() under rq locks and then reusing a local pointer; and - using rcu_access_pointer() for address-only comparisons. No functional change intended. Note: the __schedule() prev assignment cleanup is intentionally left out and will be handled separately. Build/verify: make -j$(nproc) O=3D../out/full-clang-x86_64 LLVM=3D1 kernel/sched/core.o make -j$(nproc) O=3D../out/full-clang-x86_64 LLVM=3D1 C=3D2 CHECK=3Dspars= e \ kernel/sched/core.o Signed-off-by: Sun Jian --- kernel/sched/core.c | 73 +++++++++++++++++++++++++++++++------------- kernel/sched/pelt.h | 5 ++- kernel/sched/sched.h | 19 ++++++------ 3 files changed, 64 insertions(+), 33 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 759777694c78..a1a3b2816a46 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -330,7 +330,8 @@ void sched_core_dequeue(struct rq *rq, struct task_stru= ct *p, int flags) * and re-examine whether the core is still in forced idle state. */ if (!(flags & DEQUEUE_SAVE) && rq->nr_running =3D=3D 1 && - rq->core->core_forceidle_count && rq->curr =3D=3D rq->idle) + rq->core->core_forceidle_count && + rcu_access_pointer(rq->curr) =3D=3D rq->idle) resched_curr(rq); } =20 @@ -891,7 +892,12 @@ static enum hrtimer_restart hrtick(struct hrtimer *tim= er) =20 rq_lock(rq, &rf); update_rq_clock(rq); - rq->donor->sched_class->task_tick(rq, rq->donor, 1); + { + struct task_struct *donor =3D + rcu_dereference_protected(rq->donor, + lockdep_is_held(__rq_lockp(rq))); + donor->sched_class->task_tick(rq, donor, 1); + } rq_unlock(rq, &rf); =20 return HRTIMER_NORESTART; @@ -1111,7 +1117,9 @@ void wake_up_q(struct wake_q_head *head) */ static void __resched_curr(struct rq *rq, int tif) { - struct task_struct *curr =3D rq->curr; + struct task_struct *curr =3D + rcu_dereference_protected(rq->curr, + lockdep_is_held(__rq_lockp(rq))); struct thread_info *cti =3D task_thread_info(curr); int cpu; =20 @@ -1218,7 +1226,8 @@ int get_nohz_timer_target(void) =20 guard(rcu)(); =20 - for_each_domain(cpu, sd) { + sd =3D rcu_dereference(cpu_rq(cpu)->sd); + for (; sd; sd =3D rcu_dereference(sd->parent)) { for_each_cpu_and(i, sched_domain_span(sd), hk_mask) { if (cpu =3D=3D i) continue; @@ -2179,12 +2188,15 @@ static void block_task(struct rq *rq, struct task_s= truct *p, int flags) */ inline int task_curr(const struct task_struct *p) { - return cpu_curr(task_cpu(p)) =3D=3D p; + return rcu_access_pointer(cpu_curr(task_cpu(p))) =3D=3D p; } =20 void wakeup_preempt(struct rq *rq, struct task_struct *p, int flags) { - struct task_struct *donor =3D rq->donor; + struct task_struct *donor =3D + rcu_dereference_protected(rq->donor, lockdep_is_held(__rq_lockp(rq))); + struct task_struct *curr =3D + rcu_dereference_protected(rq->curr, lockdep_is_held(__rq_lockp(rq))); =20 if (p->sched_class =3D=3D rq->next_class) { rq->next_class->wakeup_preempt(rq, p, flags); @@ -2199,7 +2211,7 @@ void wakeup_preempt(struct rq *rq, struct task_struct= *p, int flags) * A queue event has occurred, and we're going to schedule. In * this case, we can save a useless back to back clock update. */ - if (task_on_rq_queued(donor) && test_tsk_need_resched(rq->curr)) + if (task_on_rq_queued(donor) && test_tsk_need_resched(curr)) rq_clock_skip_update(rq); } =20 @@ -3604,7 +3616,9 @@ ttwu_stat(struct task_struct *p, int cpu, int wake_fl= ags) __schedstat_inc(p->stats.nr_wakeups_remote); =20 guard(rcu)(); - for_each_domain(rq->cpu, sd) { + + sd =3D rcu_dereference(rq->sd); + for (; sd; sd =3D rcu_dereference(sd->parent)) { if (cpumask_test_cpu(cpu, sched_domain_span(sd))) { __schedstat_inc(sd->ttwu_wake_remote); break; @@ -3809,7 +3823,8 @@ void wake_up_if_idle(int cpu) guard(rcu)(); if (is_idle_task(rcu_dereference(rq->curr))) { guard(rq_lock_irqsave)(rq); - if (is_idle_task(rq->curr)) + if (is_idle_task(rcu_dereference_protected(rq->curr, + lockdep_is_held(__rq_lockp(rq))))) resched_curr(rq); } } @@ -5556,7 +5571,8 @@ void sched_tick(void) sched_clock_tick(); =20 rq_lock(rq, &rf); - donor =3D rq->donor; + donor =3D rcu_dereference_protected(rq->donor, + lockdep_is_held(__rq_lockp(rq))); =20 psi_account_irqtime(rq, donor, NULL); =20 @@ -5644,7 +5660,10 @@ static void sched_tick_remote(struct work_struct *wo= rk) */ if (tick_nohz_tick_stopped_cpu(cpu)) { guard(rq_lock_irq)(rq); - struct task_struct *curr =3D rq->curr; + struct task_struct *curr =3D + rcu_dereference_protected(rq->curr, lockdep_is_held(__rq_lockp(rq))); + struct task_struct *donor =3D + rcu_dereference_protected(rq->donor, lockdep_is_held(__rq_lockp(rq))); =20 if (cpu_online(cpu)) { /* @@ -5652,7 +5671,7 @@ static void sched_tick_remote(struct work_struct *wor= k) * we are always sure that there is no proxy (only a * single task is running). */ - WARN_ON_ONCE(rq->curr !=3D rq->donor); + WARN_ON_ONCE(curr !=3D donor); update_rq_clock(rq); =20 if (!is_idle_task(curr)) { @@ -6845,7 +6864,12 @@ static void __sched notrace __schedule(int sched_mod= e) } =20 pick_again: - next =3D pick_next_task(rq, rq->donor, &rf); + { + struct task_struct *donor =3D + rcu_dereference_protected(rq->donor, + lockdep_is_held(__rq_lockp(rq))); + next =3D pick_next_task(rq, donor, &rf); + } rq_set_donor(rq, next); rq->next_class =3D next->sched_class; if (unlikely(task_is_blocked(next))) { @@ -7352,7 +7376,7 @@ void rt_mutex_setprio(struct task_struct *p, struct t= ask_struct *pi_task) * real need to boost. */ if (unlikely(p =3D=3D rq->idle)) { - WARN_ON(p !=3D rq->curr); + WARN_ON(p !=3D rcu_access_pointer(rq->curr)); WARN_ON(p->pi_blocked_on); goto out_unlock; } @@ -8116,7 +8140,9 @@ static DEFINE_PER_CPU(struct cpu_stop_work, push_work= ); static void balance_push(struct rq *rq) __must_hold(__rq_lockp(rq)) { - struct task_struct *push_task =3D rq->curr; + struct task_struct *push_task =3D + rcu_dereference_protected(rq->curr, + lockdep_is_held(__rq_lockp(rq))); =20 lockdep_assert_rq_held(rq); =20 @@ -10272,7 +10298,7 @@ void dump_cpu_task(int cpu) return; =20 pr_info("Task dump for CPU %d:\n", cpu); - sched_show_task(cpu_curr(cpu)); + sched_show_task(rcu_access_pointer(cpu_curr(cpu))); } =20 /* @@ -10583,24 +10609,27 @@ static void mm_cid_fixup_cpus_to_tasks(struct mm_= struct *mm) =20 /* Remote access to mm::mm_cid::pcpu requires rq_lock */ guard(rq_lock_irq)(rq); + + struct task_struct *curr =3D + rcu_dereference_protected(rq->curr, lockdep_is_held(__rq_lockp(rq))); /* Is the CID still owned by the CPU? */ if (cid_on_cpu(pcp->cid)) { /* * If rq->curr has @mm, transfer it with the * transition bit set. Otherwise drop it. */ - if (rq->curr->mm =3D=3D mm && rq->curr->mm_cid.active) - mm_cid_transit_to_task(rq->curr, pcp); + if (curr->mm =3D=3D mm && curr->mm_cid.active) + mm_cid_transit_to_task(curr, pcp); else mm_drop_cid_on_cpu(mm, pcp); =20 - } else if (rq->curr->mm =3D=3D mm && rq->curr->mm_cid.active) { - unsigned int cid =3D rq->curr->mm_cid.cid; + } else if (curr->mm =3D=3D mm && curr->mm_cid.active) { + unsigned int cid =3D curr->mm_cid.cid; =20 /* Ensure it has the transition bit set */ if (!cid_in_transit(cid)) { cid =3D cid_to_transit_cid(cid); - rq->curr->mm_cid.cid =3D cid; + curr->mm_cid.cid =3D cid; pcp->cid =3D cid; } } @@ -10625,7 +10654,7 @@ static bool mm_cid_fixup_task_to_cpu(struct task_st= ruct *t, struct mm_struct *mm return false; if (cid_on_task(t->mm_cid.cid)) { /* If running on the CPU, put the CID in transit mode, otherwise drop it= */ - if (task_rq(t)->curr =3D=3D t) + if (rcu_access_pointer(task_rq(t)->curr) =3D=3D t) mm_cid_transit_to_cpu(t, per_cpu_ptr(mm->mm_cid.pcpu, task_cpu(t))); else mm_unset_cid_on_task(t); diff --git a/kernel/sched/pelt.h b/kernel/sched/pelt.h index f921302dc40f..eb84e92d717c 100644 --- a/kernel/sched/pelt.h +++ b/kernel/sched/pelt.h @@ -99,7 +99,10 @@ static inline void _update_idle_rq_clock_pelt(struct rq = *rq) */ static inline void update_rq_clock_pelt(struct rq *rq, s64 delta) { - if (unlikely(is_idle_task(rq->curr))) { + struct task_struct *curr =3D + rcu_dereference_protected(rq->curr, + lockdep_is_held(__rq_lockp(rq))); + if (unlikely(is_idle_task(curr))) { _update_idle_rq_clock_pelt(rq); return; } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index b82fb70a9d54..ed0134e2df55 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1387,12 +1387,13 @@ static __always_inline struct rq *__this_rq(void) #define cpu_rq(cpu) (&per_cpu(runqueues, (cpu))) #define this_rq() __this_rq() #define task_rq(p) cpu_rq(task_cpu(p)) -#define cpu_curr(cpu) (cpu_rq(cpu)->curr) +#define cpu_curr(cpu) ((cpu_rq(cpu)->curr)) #define raw_rq() raw_cpu_ptr(&runqueues) =20 static inline bool idle_rq(struct rq *rq) { - return rq->curr =3D=3D rq->idle && !rq->nr_running && !rq->ttwu_pending; + return rcu_access_pointer(rq->curr) =3D=3D rq->idle && + !rq->nr_running && !rq->ttwu_pending; } =20 /** @@ -2360,7 +2361,7 @@ static inline u64 global_rt_runtime(void) */ static inline int task_current(struct rq *rq, struct task_struct *p) { - return rq->curr =3D=3D p; + return rcu_access_pointer(rq->curr) =3D=3D p; } =20 /* @@ -2371,7 +2372,7 @@ static inline int task_current(struct rq *rq, struct = task_struct *p) */ static inline int task_current_donor(struct rq *rq, struct task_struct *p) { - return rq->donor =3D=3D p; + return rcu_access_pointer(rq->donor) =3D=3D p; } =20 static inline bool task_is_blocked(struct task_struct *p) @@ -2659,7 +2660,7 @@ struct sched_class { =20 static inline void put_prev_task(struct rq *rq, struct task_struct *prev) { - WARN_ON_ONCE(rq->donor !=3D prev); + WARN_ON_ONCE(rcu_access_pointer(rq->donor) !=3D prev); prev->sched_class->put_prev_task(rq, prev, NULL); } =20 @@ -2670,8 +2671,7 @@ static inline void set_next_task(struct rq *rq, struc= t task_struct *next) =20 static inline void __put_prev_set_next_dl_server(struct rq *rq, - struct task_struct *prev, - struct task_struct *next) + struct task_struct *prev, struct task_struct *next) { prev->dl_server =3D NULL; next->dl_server =3D rq->dl_server; @@ -2679,10 +2679,9 @@ __put_prev_set_next_dl_server(struct rq *rq, } =20 static inline void put_prev_set_next_task(struct rq *rq, - struct task_struct *prev, - struct task_struct *next) + struct task_struct *prev, struct task_struct *next) { - WARN_ON_ONCE(rq->donor !=3D prev); + WARN_ON_ONCE(rcu_access_pointer(rq->donor) !=3D prev); =20 __put_prev_set_next_dl_server(rq, prev, next); =20 --=20 2.43.0