Skip to content

Commit 4a6a449

Browse files
author
Jonathan Corbet
committed
Fix a lockdep warning in fasync_helper()
Lockdep gripes if file->f_lock is taken in a no-IRQ situation, since that is not always the case. We don't really want to disable IRQs for every acquisition of f_lock; instead, just move it outside of fasync_lock. Reported-by: Bartlomiej Zolnierkiewicz <[email protected]> Reported-by: Larry Finger <[email protected]> Reported-by: Wu Fengguang <[email protected]> Signed-off-by: Jonathan Corbet <[email protected]>
1 parent 996ff68 commit 4a6a449

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

fs/fcntl.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,12 @@ int fasync_helper(int fd, struct file * filp, int on, struct fasync_struct **fap
531531
if (!new)
532532
return -ENOMEM;
533533
}
534+
535+
/*
536+
* We need to take f_lock first since it's not an IRQ-safe
537+
* lock.
538+
*/
539+
spin_lock(&filp->f_lock);
534540
write_lock_irq(&fasync_lock);
535541
for (fp = fapp; (fa = *fp) != NULL; fp = &fa->fa_next) {
536542
if (fa->fa_file == filp) {
@@ -555,14 +561,12 @@ int fasync_helper(int fd, struct file * filp, int on, struct fasync_struct **fap
555561
result = 1;
556562
}
557563
out:
558-
/* Fix up FASYNC bit while still holding fasync_lock */
559-
spin_lock(&filp->f_lock);
560564
if (on)
561565
filp->f_flags |= FASYNC;
562566
else
563567
filp->f_flags &= ~FASYNC;
564-
spin_unlock(&filp->f_lock);
565568
write_unlock_irq(&fasync_lock);
569+
spin_unlock(&filp->f_lock);
566570
return result;
567571
}
568572

include/linux/fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ struct file {
848848
#define f_dentry f_path.dentry
849849
#define f_vfsmnt f_path.mnt
850850
const struct file_operations *f_op;
851-
spinlock_t f_lock; /* f_ep_links, f_flags */
851+
spinlock_t f_lock; /* f_ep_links, f_flags, no IRQ */
852852
atomic_long_t f_count;
853853
unsigned int f_flags;
854854
fmode_t f_mode;

0 commit comments

Comments
 (0)