From nobody Thu Apr 2 17:11:20 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E6CF30AD0A for ; Fri, 27 Mar 2026 07:30:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774596628; cv=none; b=ks/FBXxdhZnz0TGTvwzr/OpycDLZ4G0c9xnz3hM602RWgw18+J9CZcx2Z9FsQ2FSwt1I/x4j3/06aIJGdX+f26JhuyUIvNo1XI5CUHBd+UwgNt4pEP54sh/hsp5i0q6uYp/dfSmYo2gZfciimUu5kGMOpK40EaE5udzB/KK7ayQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774596628; c=relaxed/simple; bh=yeZn4oPo/+LJTCbsFB/TqdDumle/llrWbGbkBPfPS2I=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=q0LvzSDumxfKTjoymJNOuFYz6A1pAY+iXPakDgpPLygpOhGQDrwmwNw5SMSX7mtIw9iCftlyTq825GZt9K7VYjsrxk2/QFGBRmTLq5EHw09IP1FJJn60LcA9GAqQFJW2q2cqb63pEPIOJZKenRN1XLYp9N/UFQHcF+EmUYfzSn8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: c889efe829ae11f1a21c59e7364eecb8-20260327 X-CID-CACHE: Type:Local,Time:202603271525+08,HitQuantity:1 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.11,REQID:be0db876-6104-422b-b8b6-0170c22a8c6a,IP:0,U RL:0,TC:0,Content:-25,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:0 X-CID-META: VersionHash:89c9d04,CLOUDID:f2eafafdf1b0941191d667152db4c53b,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:102|850|898,TC:nil,Content:0|15|50,EDM:5 ,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV :0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: c889efe829ae11f1a21c59e7364eecb8-20260327 Received: from localhost [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 586952287; Fri, 27 Mar 2026 15:30:09 +0800 From: Yu Peng To: tj@kernel.org, peterz@infradead.org, mingo@redhat.com Cc: juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, jiangshanlai@gmail.com, linux-kernel@vger.kernel.org, Yu Peng Subject: [PATCH] sched,workqueue: Use READ_ONCE()/WRITE_ONCE() for wake_cpu accesses Date: Fri, 27 Mar 2026 15:30:07 +0800 Message-Id: <20260327073007.254673-1-pengyu@kylinos.cn> X-Mailer: git-send-email 2.25.1 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" task_struct->wake_cpu is used as a wake placement hint by scheduler code and workqueue's non-strict affinity repatriation path. These accesses are intentionally lockless and stale values are tolerated, affecting only wakeup placement. Use READ_ONCE()/WRITE_ONCE() to document that contract and constrain compiler optimizations on the shared accesses. No functional change intended. Signed-off-by: Yu Peng --- kernel/sched/core.c | 6 +++--- kernel/sched/sched.h | 2 +- kernel/workqueue.c | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 496dff740dcaf..8a7f46cf30fda 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2567,7 +2567,7 @@ static int migration_cpu_stop(void *data) update_rq_clock(rq); rq =3D __migrate_task(rq, &rf, p, arg->dest_cpu); } else { - p->wake_cpu =3D arg->dest_cpu; + WRITE_ONCE(p->wake_cpu, arg->dest_cpu); } =20 /* @@ -3318,7 +3318,7 @@ static void __migrate_swap_task(struct task_struct *p= , int cpu) * it before it went to sleep. This means on wakeup we make the * previous CPU our target instead of where it really is. */ - p->wake_cpu =3D cpu; + WRITE_ONCE(p->wake_cpu, cpu); } } =20 @@ -4227,7 +4227,7 @@ int try_to_wake_up(struct task_struct *p, unsigned in= t state, int wake_flags) */ smp_cond_load_acquire(&p->on_cpu, !VAL); =20 - cpu =3D select_task_rq(p, p->wake_cpu, &wake_flags); + cpu =3D select_task_rq(p, READ_ONCE(p->wake_cpu), &wake_flags); if (task_cpu(p) !=3D cpu) { if (p->in_iowait) { delayacct_blkio_end(p); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 43bbf0693cca4..127be762e8567 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2294,7 +2294,7 @@ static inline void __set_task_cpu(struct task_struct = *p, unsigned int cpu) */ smp_wmb(); WRITE_ONCE(task_thread_info(p)->cpu, cpu); - p->wake_cpu =3D cpu; + WRITE_ONCE(p->wake_cpu, cpu); rseq_sched_set_ids_changed(p); #endif /* CONFIG_SMP */ } diff --git a/kernel/workqueue.c b/kernel/workqueue.c index b77119d71641a..b5f542d53105d 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1284,13 +1284,14 @@ static bool kick_pool(struct worker_pool *pool) * its affinity scope. Repatriate. */ if (!pool->attrs->affn_strict && - !cpumask_test_cpu(p->wake_cpu, pool->attrs->__pod_cpumask)) { + !cpumask_test_cpu(READ_ONCE(p->wake_cpu), + pool->attrs->__pod_cpumask)) { struct work_struct *work =3D list_first_entry(&pool->worklist, struct work_struct, entry); int wake_cpu =3D cpumask_any_and_distribute(pool->attrs->__pod_cpumask, cpu_online_mask); if (wake_cpu < nr_cpu_ids) { - p->wake_cpu =3D wake_cpu; + WRITE_ONCE(p->wake_cpu, wake_cpu); get_work_pwq(work)->stats[PWQ_STAT_REPATRIATED]++; } } --=20 2.43.0