Skip to content

Commit c4a62ca

Browse files
committed
reiserfs: Warn on lock relax if taken recursively
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>
1 parent 0719d34 commit c4a62ca

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎fs/reiserfs/lock.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,12 @@ void reiserfs_check_lock_depth(struct super_block *sb, char *caller)
8686
reiserfs_panic(sb, "%s called without kernel lock held %d",
8787
caller);
8888
}
89+
90+
#ifdef CONFIG_REISERFS_CHECK
91+
void reiserfs_lock_check_recursive(struct super_block *sb)
92+
{
93+
struct reiserfs_sb_info *sb_i = REISERFS_SB(sb);
94+
95+
WARN_ONCE((sb_i->lock_depth > 0), "Unwanted recursive reiserfs lock!\n");
96+
}
97+
#endif

‎include/linux/reiserfs_fs.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ void reiserfs_write_unlock(struct super_block *s);
6262
int reiserfs_write_lock_once(struct super_block *s);
6363
void reiserfs_write_unlock_once(struct super_block *s, int lock_depth);
6464

65+
#ifdef CONFIG_REISERFS_CHECK
66+
void reiserfs_lock_check_recursive(struct super_block *s);
67+
#else
68+
static inline void reiserfs_lock_check_recursive(struct super_block *s) { }
69+
#endif
70+
6571
/*
6672
* Several mutexes depend on the write lock.
6773
* 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);
9298
static inline void reiserfs_mutex_lock_safe(struct mutex *m,
9399
struct super_block *s)
94100
{
101+
reiserfs_lock_check_recursive(s);
95102
reiserfs_write_unlock(s);
96103
mutex_lock(m);
97104
reiserfs_write_lock(s);
@@ -101,6 +108,7 @@ static inline void
101108
reiserfs_mutex_lock_nested_safe(struct mutex *m, unsigned int subclass,
102109
struct super_block *s)
103110
{
111+
reiserfs_lock_check_recursive(s);
104112
reiserfs_write_unlock(s);
105113
mutex_lock_nested(m, subclass);
106114
reiserfs_write_lock(s);
@@ -109,6 +117,7 @@ reiserfs_mutex_lock_nested_safe(struct mutex *m, unsigned int subclass,
109117
static inline void
110118
reiserfs_down_read_safe(struct rw_semaphore *sem, struct super_block *s)
111119
{
120+
reiserfs_lock_check_recursive(s);
112121
reiserfs_write_unlock(s);
113122
down_read(sem);
114123
reiserfs_write_lock(s);

0 commit comments

Comments
 (0)