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
Subject: [PATCH 1/4] locking/rwsem: Add missing ACQUIRE to read_slowpath exit when queue is empty
Date: Thu, 18 Jul 2019 15:49:55 +0200 [thread overview]
Message-ID: <20190718135205.916241783@infradead.org> (raw)
In-Reply-To: 20190718134954.496297975@infradead.org
From: Jan Stancek <jstancek@redhat.com>
LTP mtest06 has been observed to occasionally hit "still mapped when
deleted" and following BUG_ON on arm64.
The extra mapcount originated from pagefault handler, which handled
pagefault for vma that has already been detached. vma is detached
under mmap_sem write lock by detach_vmas_to_be_unmapped(), which
also invalidates vmacache.
When the pagefault handler (under mmap_sem read lock) calls
find_vma(), vmacache_valid() wrongly reports vmacache as valid.
After rwsem down_read() returns via 'queue empty' path (as of v5.2),
it does so without an ACQUIRE on sem->count:
down_read()
__down_read()
rwsem_down_read_failed()
__rwsem_down_read_failed_common()
raw_spin_lock_irq(&sem->wait_lock);
if (list_empty(&sem->wait_list)) {
if (atomic_long_read(&sem->count) >= 0) {
raw_spin_unlock_irq(&sem->wait_lock);
return sem;
The problem can be reproduced by running LTP mtest06 in a loop and
building the kernel (-j $NCPUS) in parallel. It does reproduces since
v4.20 on arm64 HPE Apollo 70 (224 CPUs, 256GB RAM, 2 nodes). It
triggers reliably in about an hour.
The patched kernel ran fine for 10+ hours.
Cc: dbueso@suse.de
Cc: mingo@redhat.com
Fixes: 4b486b535c33 ("locking/rwsem: Exit read lock slowpath if queue empty & no writer")
Signed-off-by: Jan Stancek <jstancek@redhat.com>
Reviewed-by: Will Deacon <will@kernel.org>
Acked-by: Waiman Long <longman@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/50b8914e20d1d62bb2dee42d342836c2c16ebee7.1563438048.git.jstancek@redhat.com
---
kernel/locking/rwsem.c | 2 ++
1 file changed, 2 insertions(+)
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -1032,6 +1032,8 @@ rwsem_down_read_slowpath(struct rw_semap
*/
if (adjustment && !(atomic_long_read(&sem->count) &
(RWSEM_WRITER_MASK | RWSEM_FLAG_HANDOFF))) {
+ /* Provide lock ACQUIRE */
+ smp_acquire__after_ctrl_dep();
raw_spin_unlock_irq(&sem->wait_lock);
rwsem_set_reader_owned(sem);
lockevent_inc(rwsem_rlock_fast);
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 ` Peter Zijlstra [this message]
2019-07-19 8:49 ` [PATCH 1/4] locking/rwsem: Add missing ACQUIRE to read_slowpath exit when queue is empty 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 ` [PATCH 3/4] tty/ldsem: Add missing ACQUIRE to read_failed " Peter Zijlstra
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=20190718135205.916241783@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=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).