Skip to contentSkip to conversation

Fix deadlock with suspend & quotas

PATCH Superseded Jan Kara 4 participants 11 messages Feb 7, 2012 – Feb 10, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

cover Fix deadlock with suspend & quotas

Hello Al,

This is my attempt to fix deadlock in quota code when filesystem is
suspended and someone tries to modify quota e.g. via Q_SETQUOTA command. I added a VFS function to get a superblock reference and return only after the filesystem is thawed. Is that what you had in mind? Can you merge these patches? Thanks.

Honza

author reviewer
#1 lore raw

PATCH 1/2 vfs: Provide function to get superblock and wait for it to thaw

In quota code we need to find a superblock corresponding to a device and wait for superblock to be unfrozen. However this waiting has to happen without s_umount semaphore because that is required for superblock to thaw. So provide a function in VFS for this to keep dances with s_umount where they belong.

---
 fs/super.c         |   47 +++++++++++++++++++++++++++++++++++------------
 include/linux/fs.h |    1 +
 2 files changed, 36 insertions(+), 12 deletions(-)
fs/super.c +35 -12
index 6015c02..e320239 100644
@@ -593,15 +593,7 @@ void iterate_supers_type(struct file_system_type *type,
 
 EXPORT_SYMBOL(iterate_supers_type);
 
-/**
- *	get_super - get the superblock of a device
- *	@bdev: device to get the superblock for
- *	
- *	Scans the superblock list and finds the superblock of the file system
- *	mounted on the device given. %NULL is returned if no match is found.
- */
-
-struct super_block *get_super(struct block_device *bdev)
+static struct super_block *__get_super(struct block_device *bdev, bool thawed)
 {
 	struct super_block *sb;
 
@@ -618,9 +610,13 @@ rescan:
 			spin_unlock(&sb_lock);
 			down_read(&sb->s_umount);
 			/* still alive? */
-			if (sb->s_root && (sb->s_flags & MS_BORN))
-				return sb;
-			up_read(&sb->s_umount);
+			if (sb->s_root && (sb->s_flags & MS_BORN)) {
+				if (sb->s_frozen == SB_UNFROZEN)
+					return sb;
+				up_read(&sb->s_umount);
+				vfs_check_frozen(sb, SB_FREEZE_WRITE);
+			} else
+				up_read(&sb->s_umount);
 			/* nope, got unmounted */
 			spin_lock(&sb_lock);
 			__put_super(sb);
@@ -631,9 +627,36 @@ rescan:
 	return NULL;
 }
 
+/**
+ *	get_super - get the superblock of a device
+ *	@bdev: device to get the superblock for
+ *
+ *	Scans the superblock list and finds the superblock of the file system
+ *	mounted on the device given. %NULL is returned if no match is found.
+ */
+
+struct super_block *get_super(struct block_device *bdev)
+{
+	return __get_super(bdev, false);
+}
 EXPORT_SYMBOL(get_super);
 
 /**
+ *	get_super_thawed - get thawed superblock of a device
+ *	@bdev: device to get the superblock for
+ *
+ *	Scans the superblock list and finds the superblock of the file system
+ *	mounted on the device given once the superblock is thawed. %NULL is
+ *	returned if no match is found.
+ */
+
+struct super_block *get_super_thawed(struct block_device *bdev)
+{
+	return __get_super(bdev, true);
+}
+EXPORT_SYMBOL(get_super_thawed);
+
+/**
  * get_active_super - get an active reference to the superblock of a device
  * @bdev: device to get the superblock for
  *
include/linux/fs.h +1 -0
index 386da09..69cd5bb 100644
@@ -2496,6 +2496,7 @@ extern void get_filesystem(struct file_system_type *fs);
 extern void put_filesystem(struct file_system_type *fs);
 extern struct file_system_type *get_fs_type(const char *name);
 extern struct super_block *get_super(struct block_device *);
+extern struct super_block *get_super_thawed(struct block_device *);
 extern struct super_block *get_active_super(struct block_device *bdev);
 extern void drop_super(struct super_block *sb);
 extern void iterate_supers(void (*)(struct super_block *, void *), void *);
Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw

Quoted 50 lines · Jan Kara

In quota code we need to find a superblock corresponding to a device and wait for superblock to be unfrozen. However this waiting has to happen without s_umount semaphore because that is required for superblock to thaw. So provide a function in VFS for this to keep dances with s_umount where they belong.

---
 fs/super.c         |   47 +++++++++++++++++++++++++++++++++++------------
 include/linux/fs.h |    1 +
 2 files changed, 36 insertions(+), 12 deletions(-)
fs/super.c +8 -12
index 6015c02..e320239 100644
@@ -593,15 +593,7 @@ void iterate_supers_type(struct file_system_type *type,
 
 EXPORT_SYMBOL(iterate_supers_type);
 
-/**
- *	get_super - get the superblock of a device
- *	@bdev: device to get the superblock for
- *	
- *	Scans the superblock list and finds the superblock of the file system
- *	mounted on the device given. %NULL is returned if no match is found.
- */
-
-struct super_block *get_super(struct block_device *bdev)
+static struct super_block *__get_super(struct block_device *bdev, bool thawed)
 {
 	struct super_block *sb;
 
@@ -618,9 +610,13 @@ rescan:
 			spin_unlock(&sb_lock);
 			down_read(&sb->s_umount);
 			/* still alive? */
-			if (sb->s_root && (sb->s_flags & MS_BORN))
-				return sb;
-			up_read(&sb->s_umount);
+			if (sb->s_root && (sb->s_flags & MS_BORN)) {
+				if (sb->s_frozen == SB_UNFROZEN)
+					return sb;
+				up_read(&sb->s_umount);
+				vfs_check_frozen(sb, SB_FREEZE_WRITE);
+			} else
+				up_read(&sb->s_umount);
 			/* nope, got unmounted */
 			spin_lock(&sb_lock);
 			__put_super(sb);

fs/super.c rescan: · line 628

Quoted 2 lines
fs/super.c +0 -0
@@ -631,9 +627,36 @@ rescan:
 	return NULL;
 }

The thawed parameter appears to be unused and the waiting for frozen filesystems appears to happen for all callers. Is this intentional?

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
author reviewer
#3 lore raw

Re: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw

Quoted 48 lines · Dave Chinner
Quoted 47 lines · Jan Kara

In quota code we need to find a superblock corresponding to a device and wait for superblock to be unfrozen. However this waiting has to happen without s_umount semaphore because that is required for superblock to thaw. So provide a function in VFS for this to keep dances with s_umount where they belong.

---
 fs/super.c         |   47 +++++++++++++++++++++++++++++++++++------------
 include/linux/fs.h |    1 +
 2 files changed, 36 insertions(+), 12 deletions(-)
fs/super.c +8 -12
index 6015c02..e320239 100644
@@ -593,15 +593,7 @@ void iterate_supers_type(struct file_system_type *type,
 
 EXPORT_SYMBOL(iterate_supers_type);
 
-/**
- *	get_super - get the superblock of a device
- *	@bdev: device to get the superblock for
- *	
- *	Scans the superblock list and finds the superblock of the file system
- *	mounted on the device given. %NULL is returned if no match is found.
- */
-
-struct super_block *get_super(struct block_device *bdev)
+static struct super_block *__get_super(struct block_device *bdev, bool thawed)
 {
 	struct super_block *sb;
 
@@ -618,9 +610,13 @@ rescan:
 			spin_unlock(&sb_lock);
 			down_read(&sb->s_umount);
 			/* still alive? */
-			if (sb->s_root && (sb->s_flags & MS_BORN))
-				return sb;
-			up_read(&sb->s_umount);
+			if (sb->s_root && (sb->s_flags & MS_BORN)) {
+				if (sb->s_frozen == SB_UNFROZEN)
+					return sb;
+				up_read(&sb->s_umount);
+				vfs_check_frozen(sb, SB_FREEZE_WRITE);
+			} else
+				up_read(&sb->s_umount);
 			/* nope, got unmounted */
Quoted 8 lines

fs/super.c rescan: · line 628

Quoted 5 lines
fs/super.c +0 -0
 			spin_lock(&sb_lock);
 			__put_super(sb);
@@ -631,9 +627,36 @@ rescan:
 	return NULL;
 }

The thawed parameter appears to be unused and the waiting for frozen filesystems appears to happen for all callers. Is this intentional?

Ah, sorry. Obviously that's a bug. Thanks for spotting it. I'll fix it
up.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author reviewer
#4 lore raw

Re: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw

Quoted 57 lines · Jan Kara
Quoted 48 lines · Dave Chinner
Quoted 47 lines · Jan Kara

In quota code we need to find a superblock corresponding to a device and wait for superblock to be unfrozen. However this waiting has to happen without s_umount semaphore because that is required for superblock to thaw. So provide a function in VFS for this to keep dances with s_umount where they belong.

---
 fs/super.c         |   47 +++++++++++++++++++++++++++++++++++------------
 include/linux/fs.h |    1 +
 2 files changed, 36 insertions(+), 12 deletions(-)
fs/super.c +8 -12
index 6015c02..e320239 100644
@@ -593,15 +593,7 @@ void iterate_supers_type(struct file_system_type *type,
 
 EXPORT_SYMBOL(iterate_supers_type);
 
-/**
- *	get_super - get the superblock of a device
- *	@bdev: device to get the superblock for
- *	
- *	Scans the superblock list and finds the superblock of the file system
- *	mounted on the device given. %NULL is returned if no match is found.
- */
-
-struct super_block *get_super(struct block_device *bdev)
+static struct super_block *__get_super(struct block_device *bdev, bool thawed)
 {
 	struct super_block *sb;
 
@@ -618,9 +610,13 @@ rescan:
 			spin_unlock(&sb_lock);
 			down_read(&sb->s_umount);
 			/* still alive? */
-			if (sb->s_root && (sb->s_flags & MS_BORN))
-				return sb;
-			up_read(&sb->s_umount);
+			if (sb->s_root && (sb->s_flags & MS_BORN)) {
+				if (sb->s_frozen == SB_UNFROZEN)
+					return sb;
+				up_read(&sb->s_umount);
+				vfs_check_frozen(sb, SB_FREEZE_WRITE);
+			} else
+				up_read(&sb->s_umount);
 			/* nope, got unmounted */
Quoted 8 lines

fs/super.c rescan: · line 628

Quoted 5 lines
fs/super.c +0 -0
 			spin_lock(&sb_lock);
 			__put_super(sb);
@@ -631,9 +627,36 @@ rescan:
 	return NULL;
 }

The thawed parameter appears to be unused and the waiting for frozen filesystems appears to happen for all callers. Is this intentional?

Quoted 2 lines

Ah, sorry. Obviously that's a bug. Thanks for spotting it. I'll fix it
up.

Attached is a fixed version.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
Quoted 1 line

From 5dce7adb0c281612a14fa3dd8c8d5ef3f5eb3666 Mon Sep 17 00:00:00 2001

From: Jan Kara <[email protected]>
Date: Tue, 7 Feb 2012 22:59:06 +0100
Subject: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw

In quota code we need to find a superblock corresponding to a device and wait for superblock to be unfrozen. However this waiting has to happen without s_umount semaphore because that is required for superblock to thaw. So provide a function in VFS for this to keep dances with s_umount where they belong.

---
 fs/super.c         |   47 +++++++++++++++++++++++++++++++++++------------
 include/linux/fs.h |    1 +
 2 files changed, 36 insertions(+), 12 deletions(-)
fs/super.c +35 -12
index 6015c02..e15aaa9 100644
@@ -593,15 +593,7 @@ void iterate_supers_type(struct file_system_type *type,
 
 EXPORT_SYMBOL(iterate_supers_type);
 
-/**
- *	get_super - get the superblock of a device
- *	@bdev: device to get the superblock for
- *	
- *	Scans the superblock list and finds the superblock of the file system
- *	mounted on the device given. %NULL is returned if no match is found.
- */
-
-struct super_block *get_super(struct block_device *bdev)
+static struct super_block *__get_super(struct block_device *bdev, bool thawed)
 {
 	struct super_block *sb;
 
@@ -618,9 +610,13 @@ rescan:
 			spin_unlock(&sb_lock);
 			down_read(&sb->s_umount);
 			/* still alive? */
-			if (sb->s_root && (sb->s_flags & MS_BORN))
-				return sb;
-			up_read(&sb->s_umount);
+			if (sb->s_root && (sb->s_flags & MS_BORN)) {
+				if (!thawed || sb->s_frozen == SB_UNFROZEN)
+					return sb;
+				up_read(&sb->s_umount);
+				vfs_check_frozen(sb, SB_FREEZE_WRITE);
+			} else
+				up_read(&sb->s_umount);
 			/* nope, got unmounted */
 			spin_lock(&sb_lock);
 			__put_super(sb);
@@ -631,9 +627,36 @@ rescan:
 	return NULL;
 }
 
+/**
+ *	get_super - get the superblock of a device
+ *	@bdev: device to get the superblock for
+ *
+ *	Scans the superblock list and finds the superblock of the file system
+ *	mounted on the device given. %NULL is returned if no match is found.
+ */
+
+struct super_block *get_super(struct block_device *bdev)
+{
+	return __get_super(bdev, false);
+}
 EXPORT_SYMBOL(get_super);
 
 /**
+ *	get_super_thawed - get thawed superblock of a device
+ *	@bdev: device to get the superblock for
+ *
+ *	Scans the superblock list and finds the superblock of the file system
+ *	mounted on the device given once the superblock is thawed. %NULL is
+ *	returned if no match is found.
+ */
+
+struct super_block *get_super_thawed(struct block_device *bdev)
+{
+	return __get_super(bdev, true);
+}
+EXPORT_SYMBOL(get_super_thawed);
+
+/**
  * get_active_super - get an active reference to the superblock of a device
  * @bdev: device to get the superblock for
  *
include/linux/fs.h +1 -0
index 386da09..69cd5bb 100644
@@ -2496,6 +2496,7 @@ extern void get_filesystem(struct file_system_type *fs);
 extern void put_filesystem(struct file_system_type *fs);
 extern struct file_system_type *get_fs_type(const char *name);
 extern struct super_block *get_super(struct block_device *);
+extern struct super_block *get_super_thawed(struct block_device *);
 extern struct super_block *get_active_super(struct block_device *bdev);
 extern void drop_super(struct super_block *sb);
 extern void iterate_supers(void (*)(struct super_block *, void *), void *);
Signature · 1 line
1.7.1
#5 lore raw

Re: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw

Quoted 2 lines · Jan Kara
Quoted 1 line · Jan Kara

On Thu 09-02-12 10:20:49, Dave Chinner wrote:

...

Quoted 47 lines
Quoted 4 lines
Quoted 2 lines

The thawed parameter appears to be unused and the waiting for frozen filesystems appears to happen for all callers. Is this intentional?

Ah, sorry. Obviously that's a bug. Thanks for spotting it. I'll fix it
up.

Attached is a fixed version.

Honza

From 5dce7adb0c281612a14fa3dd8c8d5ef3f5eb3666 Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Tue, 7 Feb 2012 22:59:06 +0100
Subject: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw

In quota code we need to find a superblock corresponding to a device and wait for superblock to be unfrozen. However this waiting has to happen without s_umount semaphore because that is required for superblock to thaw. So provide a function in VFS for this to keep dances with s_umount where they belong.

---
 fs/super.c         |   47 +++++++++++++++++++++++++++++++++++------------
 include/linux/fs.h |    1 +
 2 files changed, 36 insertions(+), 12 deletions(-)
fs/super.c +1 -9
index 6015c02..e15aaa9 100644
@@ -593,15 +593,7 @@ void iterate_supers_type(struct file_system_type *type,
 
 EXPORT_SYMBOL(iterate_supers_type);
 
-/**
- *	get_super - get the superblock of a device
- *	@bdev: device to get the superblock for
- *	
- *	Scans the superblock list and finds the superblock of the file system
- *	mounted on the device given. %NULL is returned if no match is found.
- */
 
-
-struct super_block *get_super(struct block_device *bdev)
+static struct super_block *__get_super(struct block_device *bdev, bool thawed)
 {
 	struct super_block *sb;

fs/super.c rescan: · line 614

Quoted 8 lines
fs/super.c +2 -3
@@ -618,9 +610,13 @@ rescan:
 			spin_unlock(&sb_lock);
 			down_read(&sb->s_umount);
 			/* still alive? */
-			if (sb->s_root && (sb->s_flags & MS_BORN))
-				return sb;
-			up_read(&sb->s_umount);
+			if (sb->s_root && (sb->s_flags & MS_BORN)) {
+				if (!thawed || sb->s_frozen == SB_UNFROZEN)

I guess this has the same race we are worried about elsewhere (sb gets frozen immediately after we check) but probably can't fix that yet.

would "wait_for_thaw" vs. "thaw" be any clearer? Nitpicky I guess but the meaning of "thawed" isn't immediately clear here. If it's already thawed? If we want to wait for it it to be thawed? You can figure it out from the callers but maybe a comment or a different name might help. No big deal.

Quoted 9 lines
fs/super.c +5 -0
+					return sb;
+				up_read(&sb->s_umount);
+				vfs_check_frozen(sb, SB_FREEZE_WRITE);
+			} else
+				up_read(&sb->s_umount);
 			/* nope, got unmounted */
 			spin_lock(&sb_lock);
 			__put_super(sb);

fs/super.c rescan: · line 636

Quoted 10 lines
fs/super.c +7 -0
@@ -631,9 +627,36 @@ rescan:
 	return NULL;
 }
 
+/**
+ *	get_super - get the superblock of a device
+ *	@bdev: device to get the superblock for
+ *
+ *	Scans the superblock list and finds the superblock of the file system
+ *	mounted on the device given. %NULL is returned if no match is found.
+ */

I think it'd be nice to explicitly say in the comment that this may return a frozen superblock.

Quoted 4 lines
fs/super.c +4 -0
+struct super_block *get_super(struct block_device *bdev)
+{
+	return __get_super(bdev, false);
+}

fs/super.c rescan: · line 651

Quoted 10 lines
fs/super.c +7 -0
 EXPORT_SYMBOL(get_super);
 
 /**
+ *	get_super_thawed - get thawed superblock of a device
+ *	@bdev: device to get the superblock for
+ *
+ *	Scans the superblock list and finds the superblock of the file system
+ *	mounted on the device given once the superblock is thawed. %NULL is
+ *	returned if no match is found.
+ */

And to explicitly say that this one will not return until the sb is unfrozen?

Otherwise, this seems fine to me, thanks.

-Eric

Quoted 22 lines
fs/super.c +7 -0
+struct super_block *get_super_thawed(struct block_device *bdev)
+{
+	return __get_super(bdev, true);
+}
+EXPORT_SYMBOL(get_super_thawed);
+
+/**
  * get_active_super - get an active reference to the superblock of a device
  * @bdev: device to get the superblock for
  *
include/linux/fs.h +1 -0
index 386da09..69cd5bb 100644
@@ -2496,6 +2496,7 @@ extern void get_filesystem(struct file_system_type *fs);
 extern void put_filesystem(struct file_system_type *fs);
 extern struct file_system_type *get_fs_type(const char *name);
 extern struct super_block *get_super(struct block_device *);
+extern struct super_block *get_super_thawed(struct block_device *);
 extern struct super_block *get_active_super(struct block_device *bdev);
 extern void drop_super(struct super_block *sb);
 extern void iterate_supers(void (*)(struct super_block *, void *), void *);
#6 lore raw

Re: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw

Quoted 52 lines · Eric Sandeen
Quoted 2 lines · Jan Kara
Quoted 1 line · Jan Kara

On Thu 09-02-12 10:20:49, Dave Chinner wrote:

...

Quoted 46 lines
Quoted 4 lines
Quoted 2 lines

The thawed parameter appears to be unused and the waiting for frozen filesystems appears to happen for all callers. Is this intentional?

Ah, sorry. Obviously that's a bug. Thanks for spotting it. I'll fix it
up.

Attached is a fixed version.

Honza

From 5dce7adb0c281612a14fa3dd8c8d5ef3f5eb3666 Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Tue, 7 Feb 2012 22:59:06 +0100
Subject: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw

In quota code we need to find a superblock corresponding to a device and wait for superblock to be unfrozen. However this waiting has to happen without s_umount semaphore because that is required for superblock to thaw. So provide a function in VFS for this to keep dances with s_umount where they belong.

---
 fs/super.c         |   47 +++++++++++++++++++++++++++++++++++------------
 include/linux/fs.h |    1 +
 2 files changed, 36 insertions(+), 12 deletions(-)
fs/super.c +1 -9
index 6015c02..e15aaa9 100644
@@ -593,15 +593,7 @@ void iterate_supers_type(struct file_system_type *type,
 
 EXPORT_SYMBOL(iterate_supers_type);
 
-/**
- *	get_super - get the superblock of a device
- *	@bdev: device to get the superblock for
- *	
- *	Scans the superblock list and finds the superblock of the file system
- *	mounted on the device given. %NULL is returned if no match is found.
- */
 
-
-struct super_block *get_super(struct block_device *bdev)
+static struct super_block *__get_super(struct block_device *bdev, bool thawed)
 {
 	struct super_block *sb;
Quoted 12 lines

fs/super.c rescan: · line 614

Quoted 9 lines
fs/super.c +2 -3
@@ -618,9 +610,13 @@ rescan:
 			spin_unlock(&sb_lock);
 			down_read(&sb->s_umount);
 			/* still alive? */
-			if (sb->s_root && (sb->s_flags & MS_BORN))
-				return sb;
-			up_read(&sb->s_umount);
+			if (sb->s_root && (sb->s_flags & MS_BORN)) {
+				if (!thawed || sb->s_frozen == SB_UNFROZEN)

I guess this has the same race we are worried about elsewhere (sb gets frozen immediately after we check) but probably can't fix that yet.

It doesn't --- s_umount is locked for read for the whole duration of the quota call, so superblock cannot be frozen (because freezing takes s_umount for write).

Mikulas

author reviewer
#7 lore raw

Re: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw

In reply to Eric Sandeen
Quoted 49 lines · Eric Sandeen
Quoted 48 lines · Jan Kara
Quoted 5 lines · Jan Kara
Quoted 2 lines · Dave Chinner

The thawed parameter appears to be unused and the waiting for frozen filesystems appears to happen for all callers. Is this intentional?

Ah, sorry. Obviously that's a bug. Thanks for spotting it. I'll fix it
up.

Attached is a fixed version.

Honza

From 5dce7adb0c281612a14fa3dd8c8d5ef3f5eb3666 Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Tue, 7 Feb 2012 22:59:06 +0100
Subject: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw

In quota code we need to find a superblock corresponding to a device and wait for superblock to be unfrozen. However this waiting has to happen without s_umount semaphore because that is required for superblock to thaw. So provide a function in VFS for this to keep dances with s_umount where they belong.

---
 fs/super.c         |   47 +++++++++++++++++++++++++++++++++++------------
 include/linux/fs.h |    1 +
 2 files changed, 36 insertions(+), 12 deletions(-)
fs/super.c +1 -9
index 6015c02..e15aaa9 100644
@@ -593,15 +593,7 @@ void iterate_supers_type(struct file_system_type *type,
 
 EXPORT_SYMBOL(iterate_supers_type);
 
-/**
- *	get_super - get the superblock of a device
- *	@bdev: device to get the superblock for
- *	
- *	Scans the superblock list and finds the superblock of the file system
- *	mounted on the device given. %NULL is returned if no match is found.
- */
 
-
-struct super_block *get_super(struct block_device *bdev)
+static struct super_block *__get_super(struct block_device *bdev, bool thawed)
 {
 	struct super_block *sb;
Quoted 12 lines

fs/super.c rescan: · line 614

Quoted 9 lines
fs/super.c +2 -3
@@ -618,9 +610,13 @@ rescan:
 			spin_unlock(&sb_lock);
 			down_read(&sb->s_umount);
 			/* still alive? */
-			if (sb->s_root && (sb->s_flags & MS_BORN))
-				return sb;
-			up_read(&sb->s_umount);
+			if (sb->s_root && (sb->s_flags & MS_BORN)) {
+				if (!thawed || sb->s_frozen == SB_UNFROZEN)

I guess this has the same race we are worried about elsewhere (sb gets frozen immediately after we check) but probably can't fix that yet.

As Mikulas said, this is OK. We return to the caller with s_umount held
thus freezing cannot happen in parallel. That's why I'm sending this as a separate patch set...

Quoted 4 lines

would "wait_for_thaw" vs. "thaw" be any clearer? Nitpicky I guess but the meaning of "thawed" isn't immediately clear here. If it's already thawed? If we want to wait for it it to be thawed? You can figure it out from the callers but maybe a comment or a different name might help. No big deal.

How about "wait_thaw". That should be explicit enough...

Quoted 13 lines
Quoted 13 lines
fs/super.c +5 -0
+					return sb;
+				up_read(&sb->s_umount);
+				vfs_check_frozen(sb, SB_FREEZE_WRITE);
+			} else
+				up_read(&sb->s_umount);
 			/* nope, got unmounted */
 			spin_lock(&sb_lock);
 			__put_super(sb);
@@ -631,9 +627,36 @@ rescan:
 	return NULL;
 }
 
Quoted 10 lines

fs/super.c rescan: · line 636

Quoted 7 lines
fs/super.c +7 -0
+/**
+ *	get_super - get the superblock of a device
+ *	@bdev: device to get the superblock for
+ *
+ *	Scans the superblock list and finds the superblock of the file system
+ *	mounted on the device given. %NULL is returned if no match is found.
+ */

I think it'd be nice to explicitly say in the comment that this may return a frozen superblock.

Will do.

Quoted 6 lines
Quoted 6 lines
fs/super.c +4 -0
+struct super_block *get_super(struct block_device *bdev)
+{
+	return __get_super(bdev, false);
+}
 EXPORT_SYMBOL(get_super);
 
Quoted 10 lines

fs/super.c rescan: · line 651

Quoted 8 lines
fs/super.c +7 -0
 /**
+ *	get_super_thawed - get thawed superblock of a device
+ *	@bdev: device to get the superblock for
+ *
+ *	Scans the superblock list and finds the superblock of the file system
+ *	mounted on the device given once the superblock is thawed. %NULL is
+ *	returned if no match is found.
+ */

And to explicitly say that this one will not return until the sb is unfrozen?

It is written in the comment ("once the superblock is thawed"). But the
sentence looks ugly when I read it now so I'll try to reformulate it.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#8 lore raw

Re: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw

Quoted 6 lines · Jan Kara
Quoted 4 lines · Eric Sandeen

would "wait_for_thaw" vs. "thaw" be any clearer? Nitpicky I guess but the meaning of "thawed" isn't immediately clear here. If it's already thawed? If we want to wait for it it to be thawed? You can figure it out from the callers but maybe a comment or a different name might help. No big deal.

How about "wait_thaw". That should be explicit enough...

IMO, wait_for_thaw is much easier to read (i.e. better english ;) and hence the code documents itself better. There's no reason to skimp on characters here - it's not a heavily used variable....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
author reviewer
#9 lore raw

PATCH 2/2 quota: Fix deadlock with suspend and quotas

In reply to Jan Kara

This script causes a kernel deadlock:
set -e
DEVICE=/dev/vg1/linear
lvchange -ay $DEVICE
mkfs.ext3 $DEVICE
mount -t ext3 -o usrquota,grpquota $DEVICE /mnt/test quotacheck -gu /mnt/test
umount /mnt/test
mount -t ext3 -o usrquota,grpquota $DEVICE /mnt/test quotaon /mnt/test
dmsetup suspend $DEVICE
setquota -u root 1 2 3 4 /mnt/test &
sleep 1
dmsetup resume $DEVICE

setquota acquired semaphore s_umount for read and then tried to perform a transaction (and waits because the device is suspended). dmsetup resume tries to acquire s_umount for write before resuming the device (and waits for setquota).

Fix the deadlock by grabbing a thawed superblock for quota commands which need it.

---
 fs/quota/quota.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)
fs/quota/quota.c +21 -3
index 7898cd6..fc2c438 100644
@@ -292,11 +292,26 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
 	}
 }
 
+/* Return 1 if 'cmd' will block on frozen filesystem */
+static int quotactl_cmd_write(int cmd)
+{
+	switch (cmd) {
+	case Q_GETFMT:
+	case Q_GETINFO:
+	case Q_SYNC:
+	case Q_XGETQSTAT:
+	case Q_XGETQUOTA:
+	case Q_XQUOTASYNC:
+		return 0;
+	}
+	return 1;
+}
+
 /*
  * look up a superblock on which quota ops will be performed
  * - use the name of a block device to find the superblock thereon
  */
-static struct super_block *quotactl_block(const char __user *special)
+static struct super_block *quotactl_block(const char __user *special, int cmd)
 {
 #ifdef CONFIG_BLOCK
 	struct block_device *bdev;
@@ -309,7 +324,10 @@ static struct super_block *quotactl_block(const char __user *special)
 	putname(tmp);
 	if (IS_ERR(bdev))
 		return ERR_CAST(bdev);
-	sb = get_super(bdev);
+	if (quotactl_cmd_write(cmd))
+		sb = get_super_thawed(bdev);
+	else
+		sb = get_super(bdev);
 	bdput(bdev);
 	if (!sb)
 		return ERR_PTR(-ENODEV);
@@ -361,7 +379,7 @@ SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,
 			pathp = &path;
 	}
 
-	sb = quotactl_block(special);
+	sb = quotactl_block(special, cmds);
 	if (IS_ERR(sb)) {
 		ret = PTR_ERR(sb);
 		goto out;
Signature · 1 line
1.7.1
Reviewed-by on v1 2/2
#10 lore raw

Re: [PATCH 2/2] quota: Fix deadlock with suspend and quotas

Quoted 20 lines · Jan Kara

This script causes a kernel deadlock:
set -e
DEVICE=/dev/vg1/linear
lvchange -ay $DEVICE
mkfs.ext3 $DEVICE
mount -t ext3 -o usrquota,grpquota $DEVICE /mnt/test quotacheck -gu /mnt/test
umount /mnt/test
mount -t ext3 -o usrquota,grpquota $DEVICE /mnt/test quotaon /mnt/test
dmsetup suspend $DEVICE
setquota -u root 1 2 3 4 /mnt/test &
sleep 1
dmsetup resume $DEVICE

setquota acquired semaphore s_umount for read and then tried to perform a transaction (and waits because the device is suspended). dmsetup resume tries to acquire s_umount for write before resuming the device (and waits for setquota).

Quoted 5 lines

Fix the deadlock by grabbing a thawed superblock for quota commands which need it.

Makes sense to me, thanks.

Quoted 57 lines
---
 fs/quota/quota.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)
fs/quota/quota.c +21 -3
index 7898cd6..fc2c438 100644
@@ -292,11 +292,26 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
 	}
 }
 
+/* Return 1 if 'cmd' will block on frozen filesystem */
+static int quotactl_cmd_write(int cmd)
+{
+	switch (cmd) {
+	case Q_GETFMT:
+	case Q_GETINFO:
+	case Q_SYNC:
+	case Q_XGETQSTAT:
+	case Q_XGETQUOTA:
+	case Q_XQUOTASYNC:
+		return 0;
+	}
+	return 1;
+}
+
 /*
  * look up a superblock on which quota ops will be performed
  * - use the name of a block device to find the superblock thereon
  */
-static struct super_block *quotactl_block(const char __user *special)
+static struct super_block *quotactl_block(const char __user *special, int cmd)
 {
 #ifdef CONFIG_BLOCK
 	struct block_device *bdev;
@@ -309,7 +324,10 @@ static struct super_block *quotactl_block(const char __user *special)
 	putname(tmp);
 	if (IS_ERR(bdev))
 		return ERR_CAST(bdev);
-	sb = get_super(bdev);
+	if (quotactl_cmd_write(cmd))
+		sb = get_super_thawed(bdev);
+	else
+		sb = get_super(bdev);
 	bdput(bdev);
 	if (!sb)
 		return ERR_PTR(-ENODEV);
@@ -361,7 +379,7 @@ SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,
 			pathp = &path;
 	}
 
-	sb = quotactl_block(special);
+	sb = quotactl_block(special, cmds);
 	if (IS_ERR(sb)) {
 		ret = PTR_ERR(sb);
 		goto out;