mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Christian Kujau <lists@nerdbynature.de>,
	Yinghai Lu <yinghai@kernel.org>,
	Alexander Beregalov <a.beregalov@gmail.com>,
	Chris Mason <chris.mason@oracle.com>, Ingo Molnar <mingo@elte.hu>
Subject: [PATCH 2/4] reiserfs: Warn on lock relax if taken recursively
Date: Wed, 30 Dec 2009 06:21:29 +0100	[thread overview]
Message-ID: <1262150491-9983-3-git-send-regression-fweisbec@gmail.com> (raw)
In-Reply-To: <1262150491-9983-1-git-send-regression-fweisbec@gmail.com>

When we relax the reiserfs lock to avoid creating unwanted
dependencies against others locks while grabbing these,
we want to ensure it has not been taken recursively, otherwise
the lock won't be really relaxed. Only its depth will be decreased.
The unwanted dependency would then actually happen.

To prevent from that, add a reiserfs_lock_check_recursive() call
in the places that need it.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Alexander Beregalov <a.beregalov@gmail.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Ingo Molnar <mingo@elte.hu>
---
 fs/reiserfs/lock.c          |    9 +++++++++
 include/linux/reiserfs_fs.h |    9 +++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/fs/reiserfs/lock.c b/fs/reiserfs/lock.c
index ee2cfc0..b87aa2c 100644
--- a/fs/reiserfs/lock.c
+++ b/fs/reiserfs/lock.c
@@ -86,3 +86,12 @@ void reiserfs_check_lock_depth(struct super_block *sb, char *caller)
 		reiserfs_panic(sb, "%s called without kernel lock held %d",
 			       caller);
 }
+
+#ifdef CONFIG_REISERFS_CHECK
+void reiserfs_lock_check_recursive(struct super_block *sb)
+{
+	struct reiserfs_sb_info *sb_i = REISERFS_SB(sb);
+
+	WARN_ONCE((sb_i->lock_depth > 0), "Unwanted recursive reiserfs lock!\n");
+}
+#endif
diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
index 35d3f45..793bf83 100644
--- a/include/linux/reiserfs_fs.h
+++ b/include/linux/reiserfs_fs.h
@@ -62,6 +62,12 @@ void reiserfs_write_unlock(struct super_block *s);
 int reiserfs_write_lock_once(struct super_block *s);
 void reiserfs_write_unlock_once(struct super_block *s, int lock_depth);
 
+#ifdef CONFIG_REISERFS_CHECK
+void reiserfs_lock_check_recursive(struct super_block *s);
+#else
+static inline void reiserfs_lock_check_recursive(struct super_block *s) { }
+#endif
+
 /*
  * Several mutexes depend on the write lock.
  * However sometimes we want to relax the write lock while we hold
@@ -92,6 +98,7 @@ void reiserfs_write_unlock_once(struct super_block *s, int lock_depth);
 static inline void reiserfs_mutex_lock_safe(struct mutex *m,
 			       struct super_block *s)
 {
+	reiserfs_lock_check_recursive(s);
 	reiserfs_write_unlock(s);
 	mutex_lock(m);
 	reiserfs_write_lock(s);
@@ -101,6 +108,7 @@ static inline void
 reiserfs_mutex_lock_nested_safe(struct mutex *m, unsigned int subclass,
 			       struct super_block *s)
 {
+	reiserfs_lock_check_recursive(s);
 	reiserfs_write_unlock(s);
 	mutex_lock_nested(m, subclass);
 	reiserfs_write_lock(s);
@@ -109,6 +117,7 @@ reiserfs_mutex_lock_nested_safe(struct mutex *m, unsigned int subclass,
 static inline void
 reiserfs_down_read_safe(struct rw_semaphore *sem, struct super_block *s)
 {
+	reiserfs_lock_check_recursive(s);
 	reiserfs_write_unlock(s);
 	down_read(sem);
 	reiserfs_write_lock(s);
-- 
1.6.2.3


  parent reply	other threads:[~2009-12-30  5:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-30  5:21 [PATCH 0/4] Some reiserfs fixes Frederic Weisbecker
2009-12-30  5:21 ` [PATCH 1/4] reiserfs: Fix reiserfs lock <-> i_xattr_sem dependency inversion Frederic Weisbecker
2009-12-30  5:21 ` Frederic Weisbecker [this message]
2009-12-30  5:21 ` [PATCH 3/4] reiserfs: Fix reiserfs lock <-> i_mutex dependency inversion on xattr Frederic Weisbecker
2009-12-30 20:27   ` [PATCH 3/4 v2] " Frederic Weisbecker
2009-12-30  5:21 ` [PATCH 4/4] reiserfs: Relax reiserfs lock while freeing the journal Frederic Weisbecker
2009-12-30  6:53 ` [PATCH 0/4] Some reiserfs fixes Frederic Weisbecker
2009-12-30 20:42 ` [PATCH 0/5] reiserfs lock inversion fixes on xattr Frederic Weisbecker
2009-12-31  6:32   ` Christian Kujau
2010-01-01  9:29     ` Ingo Molnar
2010-01-02  3:52       ` Frederic Weisbecker
2010-01-02  1:40     ` Frederic Weisbecker
2009-12-30 20:42 ` [PATCH 1/5] reiserfs: Relax lock before open xattr dir in reiserfs_xattr_set_handle() Frederic Weisbecker
2009-12-30 20:42 ` [PATCH 2/5] reiserfs: Fix unwanted recursive reiserfs lock in reiserfs_unlink() Frederic Weisbecker
2009-12-30 20:42 ` [PATCH 3/5] reiserfs: Fix journal mutex <-> inode mutex lock inversion Frederic Weisbecker
2009-12-30 20:42 ` [PATCH 4/5] reiserfs: Safely acquire i_mutex from reiserfs_for_each_xattr Frederic Weisbecker
2009-12-30 20:42 ` [PATCH 5/5] reiserfs: Safely acquire i_mutex from xattr_rmdir Frederic Weisbecker

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=1262150491-9983-3-git-send-regression-fweisbec@gmail.com \
    --to=fweisbec@gmail.com \
    --cc=a.beregalov@gmail.com \
    --cc=chris.mason@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lists@nerdbynature.de \
    --cc=mingo@elte.hu \
    --cc=yinghai@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

Powered by JetHome