* [PATCH v1] workqueue: annotate data-races around pwq->stats
@ 2025-04-23 12:53 Jiayuan Chen
2025-04-23 15:30 ` Tejun Heo
0 siblings, 1 reply; 3+ messages in thread
From: Jiayuan Chen @ 2025-04-23 12:53 UTC (permalink / raw)
To: linux-kernel
Cc: mrpre, mkoutny, Jiayuan Chen, syzbot+01affb1491750534256d,
Tejun Heo, Lai Jiangshan
Suppress warning by annotating these accesses using
READ_ONCE() / WRITE_ONCE().
Reported-by: syzbot+01affb1491750534256d@syzkaller.appspotmail.com
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
kernel/workqueue.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index cf6203282737..d78640b5d188 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3241,7 +3241,7 @@ __acquires(&pool->lock)
* point will only record its address.
*/
trace_workqueue_execute_end(work, worker->current_func);
- pwq->stats[PWQ_STAT_COMPLETED]++;
+ WRITE_ONCE(pwq->stats[PWQ_STAT_COMPLETED], READ_ONCE(pwq->stats[PWQ_STAT_COMPLETED]) + 1);
lock_map_release(&lockdep_map);
if (!bh_draining)
lock_map_release(pwq->wq->lockdep_map);
--
2.47.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1] workqueue: annotate data-races around pwq->stats
2025-04-23 12:53 [PATCH v1] workqueue: annotate data-races around pwq->stats Jiayuan Chen
@ 2025-04-23 15:30 ` Tejun Heo
2025-04-23 15:48 ` Jiayuan Chen
0 siblings, 1 reply; 3+ messages in thread
From: Tejun Heo @ 2025-04-23 15:30 UTC (permalink / raw)
To: Jiayuan Chen
Cc: linux-kernel, mrpre, mkoutny, syzbot+01affb1491750534256d,
Lai Jiangshan
On Wed, Apr 23, 2025 at 08:53:41PM +0800, Jiayuan Chen wrote:
> Suppress warning by annotating these accesses using
> READ_ONCE() / WRITE_ONCE().
>
> Reported-by: syzbot+01affb1491750534256d@syzkaller.appspotmail.com
> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> ---
> kernel/workqueue.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index cf6203282737..d78640b5d188 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -3241,7 +3241,7 @@ __acquires(&pool->lock)
> * point will only record its address.
> */
> trace_workqueue_execute_end(work, worker->current_func);
> - pwq->stats[PWQ_STAT_COMPLETED]++;
> + WRITE_ONCE(pwq->stats[PWQ_STAT_COMPLETED], READ_ONCE(pwq->stats[PWQ_STAT_COMPLETED]) + 1);
The function acquires pool->lock down below. Can you move it down inside the
locked region instead of adding READ/WRITE_ONCE()?
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] workqueue: annotate data-races around pwq->stats
2025-04-23 15:30 ` Tejun Heo
@ 2025-04-23 15:48 ` Jiayuan Chen
0 siblings, 0 replies; 3+ messages in thread
From: Jiayuan Chen @ 2025-04-23 15:48 UTC (permalink / raw)
To: Tejun Heo
Cc: linux-kernel, mrpre, mkoutny, syzbot+01affb1491750534256d,
Lai Jiangshan
April 23, 2025 at 23:30, "Tejun Heo" <tj@kernel.org> wrote:
>
> On Wed, Apr 23, 2025 at 08:53:41PM +0800, Jiayuan Chen wrote:
>
> >
> > Suppress warning by annotating these accesses using
> >
> > READ_ONCE() / WRITE_ONCE().
> >
> >
> >
> > Reported-by: syzbot+01affb1491750534256d@syzkaller.appspotmail.com
> >
> > Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> >
> > ---
> >
> > kernel/workqueue.c | 2 +-
> >
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >
> >
> > diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> >
> > index cf6203282737..d78640b5d188 100644
> >
> > --- a/kernel/workqueue.c
> >
> > +++ b/kernel/workqueue.c
> >
> > @@ -3241,7 +3241,7 @@ __acquires(&pool->lock)
> >
> > * point will only record its address.
> >
> > */
> >
> > trace_workqueue_execute_end(work, worker->current_func);
> >
> > - pwq->stats[PWQ_STAT_COMPLETED]++;
> >
> > + WRITE_ONCE(pwq->stats[PWQ_STAT_COMPLETED], READ_ONCE(pwq->stats[PWQ_STAT_COMPLETED]) + 1);
> >
>
> The function acquires pool->lock down below. Can you move it down inside the
>
> locked region instead of adding READ/WRITE_ONCE()?
>
> Thanks.
>
> --
>
> tejun
>
Thanks, I can do that.
Previously, I thought it was for performance considerations that the
metrics calculation is out of the lock's scope...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-23 15:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-23 12:53 [PATCH v1] workqueue: annotate data-races around pwq->stats Jiayuan Chen
2025-04-23 15:30 ` Tejun Heo
2025-04-23 15:48 ` Jiayuan Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox