mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Trojanowski <bart@jukie.net>
To: linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Bart Trojanowski <bart@jukie.net>
Subject: [PATCH] make lock_super recursive to simulate BKL
Date: Tue, 19 Aug 2008 18:06:30 -0400	[thread overview]
Message-ID: <1219183590-19529-1-git-send-email-bart@jukie.net> (raw)
In-Reply-To: <20080819220311.GA28029@jukie.net>

This fixes a regression introduced when BKL was removed from the
vfat driver in commit 8f5934278d1d86590244c2791b28f77d67466007.

With vfat, the unlink syscall would result in the following call chain
that caused deadlock.

        - do_unlinkat
          - vfs_unlink
            - vfat_unlink
              * lock_super
              - fat_remove_entries
                - fat_sync_inode
                  - fat_write_inode
                    * lock_super

This is not the ideal fix, but it should reverse some regressions
caused by BKL removal in code that depended on BKL being recursive.

Signed-off-by: Bart Trojanowski <bart@jukie.net>
---
 fs/super.c         |   20 ++++++++++++++++++--
 include/linux/fs.h |    2 ++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/fs/super.c b/fs/super.c
index e931ae9..8f813db 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -73,6 +73,8 @@ static struct super_block *alloc_super(struct file_system_type *type)
 		INIT_LIST_HEAD(&s->s_dentry_lru);
 		init_rwsem(&s->s_umount);
 		mutex_init(&s->s_lock);
+		s->s_lock_cookie = NULL;
+		s->s_lock_refcnt = 0;
 		lockdep_set_class(&s->s_umount, &type->s_umount_key);
 		/*
 		 * The locking rules for s_lock are up to the
@@ -227,14 +229,28 @@ static int grab_super(struct super_block *s) __releases(sb_lock)
  */
 void lock_super(struct super_block * sb)
 {
+	if (sb->s_lock_heldby == current) {
+		sb->s_lock_refcnt ++;
+		return;
+	}
+
 	get_fs_excl();
 	mutex_lock(&sb->s_lock);
+
+	sb->s_lock_heldby = current;
+	sb->s_lock_refcnt = 1;
 }
 
 void unlock_super(struct super_block * sb)
 {
-	put_fs_excl();
-	mutex_unlock(&sb->s_lock);
+	BUG_ON(sb->s_lock_heldby != current);
+
+	if (! -- sb->s_lock_refcnt) {
+		sb->s_lock_heldby = NULL;
+
+		put_fs_excl();
+		mutex_unlock(&sb->s_lock);
+	}
 }
 
 EXPORT_SYMBOL(lock_super);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 580b513..d88178e 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1076,6 +1076,8 @@ struct super_block {
 	struct dentry		*s_root;
 	struct rw_semaphore	s_umount;
 	struct mutex		s_lock;
+	void			*s_lock_heldby;
+	u32			s_lock_refcnt;
 	int			s_count;
 	int			s_syncing;
 	int			s_need_sync_fs;
-- 
1.5.6.2.221.g3c6e79


  reply	other threads:[~2008-08-19 22:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-19 22:03 vfat BKL/lock_super regression in v2.6.26-rc3-g8f59342 Bart Trojanowski
2008-08-19 22:06 ` Bart Trojanowski [this message]
2008-08-19 22:21   ` [PATCH] make lock_super recursive to simulate BKL Linus Torvalds
2008-08-20  1:14     ` Bart Trojanowski
2008-08-19 22:17 ` vfat BKL/lock_super regression in v2.6.26-rc3-g8f59342 Linus Torvalds
2008-08-20  0:03   ` Bart Trojanowski
2008-08-20  0:11     ` Linus Torvalds
2008-08-20  0:24       ` Bart Trojanowski
2008-08-20  0:18   ` Bart Trojanowski
2008-08-20  0:43     ` Linus Torvalds
2008-08-20  0:56       ` Linus Torvalds
2008-08-20  2:27         ` Bart Trojanowski
2008-08-20 21:23           ` Diego Calleja
2008-08-23  0:54           ` [PATCH] document additional vfat mount options Bart Trojanowski
2008-08-23  2:33             ` Grant Coady
2008-08-23  3:12               ` Bart Trojanowski
2008-08-23  3:14                 ` Bart Trojanowski
2008-08-23  3:27                   ` OGAWA Hirofumi
2008-08-23 13:11                     ` Bart Trojanowski
2008-08-23 14:47                       ` OGAWA Hirofumi
2008-08-23  3:10             ` OGAWA Hirofumi

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=1219183590-19529-1-git-send-email-bart@jukie.net \
    --to=bart@jukie.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®