From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 D94D4361955 for ; Tue, 11 Aug 2026 19:15:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786475752; cv=none; b=B6dxLrU9B5VgAvUNkXJbU/563RU1X+uidYZACi7jvDhH4eLpiXcUD9mfjpjZQVCIPKM5JrWR5W4ao44FVu+b5RgoT6tM57C6YoHlEESB949KU5A1IwInFAEOMmovQQkn+/DO0uw5DfwvmIH6B8aaSoKGk4vNU54W2BHqWZlGrW0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786475752; c=relaxed/simple; bh=g2+jHSvRMWEN6CViCLS/fTziC28YM+DDQmAyvmD9sto=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Iz4FNfTMkonuXG1dQpKUx8KLPN36nwkWnFJG3sKaqqJQDvRoYoWpJWj11NzGCC8WEVEg15ouzdRQy/lXX/JmBPX7Ekup9ipg61Pfe4t6t1c1/Ix7vuvy48sQ6vB6EnaL8TNk0OVLDJkN1dwks1mzuuYNLMI0KwE5E+58fNoIoEM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ATWMlFMS; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ATWMlFMS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5A901F000E9; Tue, 11 Aug 2026 19:15:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786475751; bh=poLMnTKVY9qHkQ26nbaQpx027HskNHAmvS8x/LlsdWA=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To; b=ATWMlFMSuZ/H44wY+Q5OKHos8hKFZgvvGsHERNokj1pEcDF6DOdksQFAJHyXy02/s qFVCz3uESaNTMJEpAVspAuNk0w2JRi3uXbHaZQ8n9Qh8KSpwLch4aTl9LMkEOSBQUf 6RxNE0I1kbQUXMk212VmJZTNaWqnGrvVNNmyZA++kdUySFyuGnRS74eF/JnW+lxVyx tNSo4AkFLCpgjT4fDbh2rfjiX8bsGj4+42hTHLKw0PKjvhvpVO7svQUXRD3PntJCnU eFpYYgpl8Y8c1fRcPq1pfW8N5KBkQrVVr9EPgeOql7RDuYld5Qrn2zPXbJziD1tOZm taQQsWEhNB6Mg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 6FF1CCE17BC; Tue, 11 Aug 2026 12:15:51 -0700 (PDT) Date: Tue, 11 Aug 2026 12:15:51 -0700 From: "Paul E. McKenney" To: Thomas Gleixner Cc: Anna-Maria Behnsen , Frederic Weisbecker , "Peter Zijlstra (Intel)" , linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: Re: [PATCH RFC 1/9] hrtimer: Mark data-racy accesses to hrtimer_sleeper ->task field Message-ID: <4d29bdd1-c0a2-4fce-a983-daa7231d04cd@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20260731004019.3530210-1-paulmck@kernel.org> <87jypwn5k0.ffs@fw13> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87jypwn5k0.ffs@fw13> On Tue, Aug 11, 2026 at 03:35:27PM +0200, Thomas Gleixner wrote: > On Thu, Jul 30 2026 at 17:40, Paul E. McKenney wrote: > > static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer) > > { > > struct hrtimer_sleeper *t = container_of(timer, struct hrtimer_sleeper, timer); > > - struct task_struct *task = t->task; > > + struct task_struct *task = hrtimer_sleeper_task_get(t); > > > > - t->task = NULL; > > + hrtimer_sleeper_task_set(t, NULL); > > To be honest, I find these helper functions more confusing that > useful unless you make the task member private at the very end of the > series once everything is converted over. Good point, and thank you for the reminder. As shown below? > If not, then what's wrong with a plain READ/WRITE_ONCE()? Nothing wrong with a good READ_ONCE() or WRITE_ONCE() as far as I am concerned! ;-) Thanx, Paul ------------------------------------------------------------------------ commit cff6e1c78dbf97f50d19613266aa22d4b7588e95 Author: Paul E. McKenney Date: Tue Aug 11 12:11:32 2026 -0700 hrtimer: Mark the hrtimer_sleeper structure's ->task field __private The hrtimer_sleeper structure's ->task field is now used only by the hrtimer_sleeper_task_get() and hrtimer_sleeper_task_set() functions, and there is no reason for it to be directly accessed anywhere else. Therefore, mark this field __private and use ACCESS_PRIVATE() in hrtimer_sleeper_task_get() and hrtimer_sleeper_task_set(). Suggested-by: Thomas Gleixner Signed-off-by: Paul E. McKenney diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h index 3ad2ab0443af71..5c04423e8e900b 100644 --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h @@ -73,7 +73,7 @@ enum hrtimer_mode { */ struct hrtimer_sleeper { struct hrtimer timer; - struct task_struct *task; + struct task_struct __private *task; }; static inline void hrtimer_set_expires(struct hrtimer *timer, ktime_t time) @@ -352,11 +352,11 @@ extern int schedule_hrtimeout_range_clock(ktime_t *expires, extern int schedule_hrtimeout(ktime_t *expires, const enum hrtimer_mode mode); static inline struct task_struct *hrtimer_sleeper_task_get(struct hrtimer_sleeper *sl) { - return READ_ONCE(sl->task); + return READ_ONCE(ACCESS_PRIVATE(sl, task)); } static inline void hrtimer_sleeper_task_set(struct hrtimer_sleeper *sl, struct task_struct *t) { - WRITE_ONCE(sl->task, t); + WRITE_ONCE(ACCESS_PRIVATE(sl, task), t); } /* Soft interrupt function to run the hrtimer queues: */