Skip to content

Commit

Permalink
f2fs: Restore rwsem lockdep support
Browse files Browse the repository at this point in the history
Lockdep uses lock class keys in its analysis. init_rwsem() instantiates
one lock class key with each init_rwsem() user as follows:

 #define init_rwsem(sem)                                        \
 do {                                                           \
         static struct lock_class_key __key;                    \
                                                                \
         __init_rwsem((sem), #sem, &__key);                     \
 } while (0)

Commit e4544b6 ("f2fs: move f2fs to use reader-unfair rwsems") reduced
the number of lock class keys from one per init_rwsem() user to one per
file in which init_f2fs_rwsem() is used. This causes the same lock class key
to be associated with multiple f2fs rwsems and also triggers a number of
false positive lockdep deadlock reports. Fix this by again instantiating one
lock class key with each init_f2fs_rwsem() caller.

Cc: Tim Murray <[email protected]>
Reported-by: [email protected]
Fixes: e4544b6 ("f2fs: move f2fs to use reader-unfair rwsems")
Signed-off-by: Bart Van Assche <[email protected]>
Signed-off-by: Jaegeuk Kim <[email protected]>
  • Loading branch information
bvanassche authored and Jaegeuk Kim committed Feb 25, 2022
1 parent 2fef99b commit c7f91bd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions fs/f2fs/f2fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2115,9 +2115,17 @@ static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
spin_unlock_irqrestore(&sbi->cp_lock, flags);
}

static inline void init_f2fs_rwsem(struct f2fs_rwsem *sem)
#define init_f2fs_rwsem(sem) \
do { \
static struct lock_class_key __key; \
\
__init_f2fs_rwsem((sem), #sem, &__key); \
} while (0)

static inline void __init_f2fs_rwsem(struct f2fs_rwsem *sem,
const char *sem_name, struct lock_class_key *key)
{
init_rwsem(&sem->internal_rwsem);
__init_rwsem(&sem->internal_rwsem, sem_name, key);
init_waitqueue_head(&sem->read_waiters);
}

Expand Down

0 comments on commit c7f91bd

Please sign in to comment.