linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Antipov <dmantipov@yandex.ru>
To: Jan Kara <jack@suse.cz>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>,
	linux-fsdevel@vger.kernel.org
Subject: Re: On possible data race in pollwake() / poll_schedule_timeout()
Date: Wed, 18 Jun 2025 20:08:22 +0300	[thread overview]
Message-ID: <d2bd4e09-40d8-4b53-abf7-c20b4f81e095@yandex.ru> (raw)
In-Reply-To: <bwx72orsztfjx6aoftzzkl7wle3hi4syvusuwc7x36nw6t235e@bjwrosehblty>

On 6/18/25 6:20 PM, Jan Kara wrote:

> So KCSAN is really trigger-happy about issues like this. There's no
> practical issue here because it is hard to imagine how the compiler could
> compile the above code using some intermediate values stored into
> 'triggered' or multiple fetches from 'triggered'. But for the cleanliness
> of code and silencing of KCSAN your changes make sense.

Thanks. Surely I've read Documentation/memory-barriers.txt more than
once, but, just for this particual case: is _ONCE() pair from the above
expected to work in the same way as:

diff --git a/fs/select.c b/fs/select.c
index 9fb650d03d52..1a4096fd3a95 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -191,8 +191,7 @@ static int __pollwake(wait_queue_entry_t *wait, unsigned mode, int sync, void *k
          * smp_wmb() is equivalent to smp_wmb() in try_to_wake_up()
          * and is paired with smp_store_mb() in poll_schedule_timeout.
          */
-       smp_wmb();
-       pwq->triggered = 1;
+       smp_store_release(&pwq->triggered, 1);

         /*
          * Perform the default wake up operation using a dummy
@@ -237,7 +236,7 @@ static int poll_schedule_timeout(struct poll_wqueues *pwq, int state,
         int rc = -EINTR;

         set_current_state(state);
-       if (!pwq->triggered)
+       if (!smp_load_acquire(&pwq->triggered))
                 rc = schedule_hrtimeout_range(expires, slack, HRTIMER_MODE_ABS);
         __set_current_state(TASK_RUNNING);

@@ -252,7 +251,7 @@ static int poll_schedule_timeout(struct poll_wqueues *pwq, int state,
          * this problem doesn't exist for the first iteration as
          * add_wait_queue() has full barrier semantics.
          */
-       smp_store_mb(pwq->triggered, 0);
+       smp_store_release(&pwq->triggered, 0);

         return rc;
  }

Dmitry


  reply	other threads:[~2025-06-18 17:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-17 11:04 On possible data race in pollwake() / poll_schedule_timeout() Dmitry Antipov
2025-06-18 15:20 ` Jan Kara
2025-06-18 17:08   ` Dmitry Antipov [this message]
2025-06-19  8:44     ` Jan Kara
2025-06-19 10:05     ` Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d2bd4e09-40d8-4b53-abf7-c20b4f81e095@yandex.ru \
    --to=dmantipov@yandex.ru \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).