From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org,
linux-rt-users <linux-rt-users@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Carsten Emde <C.Emde@osadl.org>, John Kacur <jkacur@redhat.com>
Subject: [PATCH RT 5/8] rt: rwsem/rwlock: lockdep annotations
Date: Thu, 11 Oct 2012 21:20:29 -0400 [thread overview]
Message-ID: <20121012012126.374055723@goodmis.org> (raw)
In-Reply-To: 20121012012024.056658930@goodmis.org
[-- Attachment #1: 0005-rt-rwsem-rwlock-lockdep-annotations.patch --]
[-- Type: text/plain, Size: 3247 bytes --]
From: Thomas Gleixner <tglx@linutronix.de>
rwlocks and rwsems on RT do not allow multiple readers. Annotate the
lockdep acquire functions accordingly.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable-rt@vger.kernel.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/rt.c | 46 +++++++++++++++++++++++++---------------------
1 file changed, 25 insertions(+), 21 deletions(-)
diff --git a/kernel/rt.c b/kernel/rt.c
index 092d6b3..aa10504 100644
--- a/kernel/rt.c
+++ b/kernel/rt.c
@@ -216,15 +216,17 @@ int __lockfunc rt_read_trylock(rwlock_t *rwlock)
* write locked.
*/
migrate_disable();
- if (rt_mutex_owner(lock) != current)
+ if (rt_mutex_owner(lock) != current) {
ret = rt_mutex_trylock(lock);
- else if (!rwlock->read_depth)
+ if (ret)
+ rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_);
+ } else if (!rwlock->read_depth) {
ret = 0;
+ }
- if (ret) {
+ if (ret)
rwlock->read_depth++;
- rwlock_acquire_read(&rwlock->dep_map, 0, 1, _RET_IP_);
- } else
+ else
migrate_enable();
return ret;
@@ -242,13 +244,13 @@ void __lockfunc rt_read_lock(rwlock_t *rwlock)
{
struct rt_mutex *lock = &rwlock->lock;
- rwlock_acquire_read(&rwlock->dep_map, 0, 0, _RET_IP_);
-
/*
* recursive read locks succeed when current owns the lock
*/
- if (rt_mutex_owner(lock) != current)
+ if (rt_mutex_owner(lock) != current) {
+ rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_);
__rt_spin_lock(lock);
+ }
rwlock->read_depth++;
}
@@ -264,11 +266,11 @@ EXPORT_SYMBOL(rt_write_unlock);
void __lockfunc rt_read_unlock(rwlock_t *rwlock)
{
- rwlock_release(&rwlock->dep_map, 1, _RET_IP_);
-
/* Release the lock only when read_depth is down to 0 */
- if (--rwlock->read_depth == 0)
+ if (--rwlock->read_depth == 0) {
+ rwlock_release(&rwlock->dep_map, 1, _RET_IP_);
__rt_spin_unlock(&rwlock->lock);
+ }
}
EXPORT_SYMBOL(rt_read_unlock);
@@ -315,9 +317,10 @@ EXPORT_SYMBOL(rt_up_write);
void rt_up_read(struct rw_semaphore *rwsem)
{
- rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
- if (--rwsem->read_depth == 0)
+ if (--rwsem->read_depth == 0) {
+ rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
rt_mutex_unlock(&rwsem->lock);
+ }
}
EXPORT_SYMBOL(rt_up_read);
@@ -366,15 +369,16 @@ int rt_down_read_trylock(struct rw_semaphore *rwsem)
* but not when read_depth == 0 which means that the rwsem is
* write locked.
*/
- if (rt_mutex_owner(lock) != current)
+ if (rt_mutex_owner(lock) != current) {
ret = rt_mutex_trylock(&rwsem->lock);
- else if (!rwsem->read_depth)
+ if (ret)
+ rwsem_acquire(&rwsem->dep_map, 0, 1, _RET_IP_);
+ } else if (!rwsem->read_depth) {
ret = 0;
+ }
- if (ret) {
+ if (ret)
rwsem->read_depth++;
- rwsem_acquire(&rwsem->dep_map, 0, 1, _RET_IP_);
- }
return ret;
}
EXPORT_SYMBOL(rt_down_read_trylock);
@@ -383,10 +387,10 @@ static void __rt_down_read(struct rw_semaphore *rwsem, int subclass)
{
struct rt_mutex *lock = &rwsem->lock;
- rwsem_acquire_read(&rwsem->dep_map, subclass, 0, _RET_IP_);
-
- if (rt_mutex_owner(lock) != current)
+ if (rt_mutex_owner(lock) != current) {
+ rwsem_acquire(&rwsem->dep_map, subclass, 0, _RET_IP_);
rt_mutex_lock(&rwsem->lock);
+ }
rwsem->read_depth++;
}
--
1.7.10.4
next prev parent reply other threads:[~2012-10-12 1:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-12 1:20 [PATCH RT 0/8] [ANNOUNCE] 3.2.31-rt47-rc1 stable review Steven Rostedt
2012-10-12 1:20 ` [PATCH RT 1/8] random: Make it work on rt Steven Rostedt
2012-10-12 1:20 ` [PATCH RT 2/8] softirq: Init softirq local lock after per cpu section is set up Steven Rostedt
2012-10-12 1:20 ` [PATCH RT 3/8] mm: slab: Fix potential deadlock Steven Rostedt
2012-10-12 1:20 ` [PATCH RT 4/8] mm: page_alloc: Use local_lock_on() instead of plain spinlock Steven Rostedt
2012-10-12 1:20 ` Steven Rostedt [this message]
2012-10-12 1:20 ` [PATCH RT 6/8] sched: Better debug output for might sleep Steven Rostedt
2012-10-12 1:20 ` [PATCH RT 7/8] stomp_machine: Use mutex_trylock when called from inactive cpu Steven Rostedt
2012-10-12 1:20 ` [PATCH RT 8/8] Linux 3.2.31-rt47-rc1 Steven Rostedt
-- strict thread matches above, loose matches on Subject: below --
2012-10-10 13:34 [PATCH RT 0/8] [ANNOUNCE] 3.4.13-rt22-rc1 stable review Steven Rostedt
2012-10-10 13:34 ` [PATCH RT 5/8] rt: rwsem/rwlock: lockdep annotations Steven Rostedt
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=20121012012126.374055723@goodmis.org \
--to=rostedt@goodmis.org \
--cc=C.Emde@osadl.org \
--cc=jkacur@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=tglx@linutronix.de \
/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).