From: Peter Zijlstra <peterz@infradead.org>
To: Will Deacon <will@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Jan Stancek <jstancek@redhat.com>,
Waiman Long <longman@redhat.com>,
dbueso@suse.de, mingo@redhat.com, jade.alglave@arm.com,
paulmck@linux.vnet.ibm.com,
Peter Hurley <peter@hurleysoftware.com>
Subject: [PATCH 3/4] tty/ldsem: Add missing ACQUIRE to read_failed sleep loop
Date: Thu, 18 Jul 2019 15:49:57 +0200 [thread overview]
Message-ID: <20190718135206.123357505@infradead.org> (raw)
In-Reply-To: 20190718134954.496297975@infradead.org
While reviewing rwsem down_slowpath, Will noticed ldsem had a copy of
a bug we just found for rwsem.
X = 0;
CPU0 CPU1
rwsem_down_read()
for (;;) {
set_current_state(TASK_UNINTERRUPTIBLE);
X = 1;
rwsem_up_write();
rwsem_mark_wake()
atomic_long_add(adjustment, &sem->count);
smp_store_release(&waiter->task, NULL);
if (!waiter.task)
break;
...
}
r = X;
Allows 'r == 0'.
Cc: Peter Hurley <peter@hurleysoftware.com>
Fixes: 4898e640caf0 ("tty: Add timed, writer-prioritized rw semaphore")
Reported-by: Will Deacon <will@kernel.org>
Acked-by: Will Deacon <will@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
drivers/tty/tty_ldsem.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
--- a/drivers/tty/tty_ldsem.c
+++ b/drivers/tty/tty_ldsem.c
@@ -93,8 +93,7 @@ static void __ldsem_wake_readers(struct
list_for_each_entry_safe(waiter, next, &sem->read_wait, list) {
tsk = waiter->task;
- smp_mb();
- waiter->task = NULL;
+ smp_store_release(&waiter->task, NULL);
wake_up_process(tsk);
put_task_struct(tsk);
}
@@ -194,7 +193,7 @@ down_read_failed(struct ld_semaphore *se
for (;;) {
set_current_state(TASK_UNINTERRUPTIBLE);
- if (!waiter.task)
+ if (!smp_load_acquire(&waiter.task))
break;
if (!timeout)
break;
next prev parent reply other threads:[~2019-07-18 13:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-18 13:49 [PATCH 0/4] Various rwsem ACQUIRE fixes Peter Zijlstra
2019-07-18 13:49 ` [PATCH 1/4] locking/rwsem: Add missing ACQUIRE to read_slowpath exit when queue is empty Peter Zijlstra
2019-07-19 8:49 ` Andrea Parri
2019-07-29 15:24 ` Peter Zijlstra
2019-07-18 13:49 ` [PATCH 2/4] rwsem: Add missing ACQUIRE to read_slowpath sleep loop Peter Zijlstra
2019-07-18 17:13 ` Waiman Long
2019-07-18 13:49 ` Peter Zijlstra [this message]
2019-07-18 13:49 ` [PATCH 4/4] rwsem: Add ACQUIRE comments Peter Zijlstra
2019-07-29 15:18 ` [PATCH 0/4] Various rwsem ACQUIRE fixes Davidlohr Bueso
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=20190718135206.123357505@infradead.org \
--to=peterz@infradead.org \
--cc=dbueso@suse.de \
--cc=jade.alglave@arm.com \
--cc=jstancek@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peter@hurleysoftware.com \
--cc=will@kernel.org \
/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).