Skip to contentSkip to conversation

Linux-2.4.18 block MTD dead-lock

PATCH In review Takeharu KATO 2 participants 3 messages Nov 26, 2002

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Linux-2.4.18 block MTD dead-lock

MTD developers:

I found a bug relevant to MTD device and Linux-2.4.18.
I post the report about the issue.

P.S. I attach the patch to fix this problem.
If you have no time to read following report. please see this patch.

-- the report --

1. The symptom
When we was trying to mount MTD-block-device twice,
second mount process fall in dead-locked state. This is due not to be able to obtain the semaphore of the superblock().

We met this with Linux-2.4.18 kernel on PPC405GP.
This issue has never taken place with Linux-2.4.2.

2. The reason
We found this was caused in the release method of
MTD. In particular, this method indirectly call sync_super with calling ``invalidate_device'' in this method.

When the kernel attempt to mount the block device,
it call ``get_sb_bdev'' function in fs/super.c. This function return the super block information to caller and this function perform following operations.

Step1. Open the block device to be mounted.

Step2. Obtain semaphore of the super block to
update super block information.

Step3. Search the block device in super block list
for mounted devices.

Step4. If the device has been already mounted,
it close the block device using its release method then return the super block information.

Step5 If the device has not been mounted yet,
the file system read the super block from the device and return the information.

The reason of the deadlock is that the process
keep waiting for the semaphore owned by itself when it call MTD release method.
The process has already obtained the semaphore since
the Step2 was performed.

3. The solution

We changed the sequence of the function called ``get_sb_bdev''
in fs/super.c. We changed the function to make the block device
to be mounted checked before opening the device.
Please refer the patch to make out the changes in detail.

-- the report --

Sincerely, yours.

Signature · 3 lines
Takeharu KATO
Fujitsu Limited
Email:[email protected] (ext. 7112-4621)
fs/super.c +13 -10
@@ -15,7 +15,7 @@
  *  Added kerneld support: Jacques Gelinas and Bjorn Ekwall
  *  Added change_root: Werner Almesberger & Hans Lermen, Feb '96
  *  Added options to /proc/mounts:
- *    Torbj�rn Lindh ([email protected]), April 14, 1996.
+ *    Torbj�-A�rn Lindh ([email protected]), April 14, 1996.�$)B
  *  Added devfs support: Richard Gooch <[email protected]>, 13-JAN-1998
  *  Heavily rewritten for 'one fs - one tree' dcache architecture. AV, Mar 2000
  */
@@ -645,21 +645,16 @@
 	dev = to_kdev_t(bdev->bd_dev);
 	if (!(flags & MS_RDONLY))
 		mode |= FMODE_WRITE;
-	error = blkdev_get(bdev, mode, 0, BDEV_FS);
-	devfs_put_ops (de);   /*  Decrement module use count now we're safe  */
-	if (error)
-		goto out;
 	check_disk_change(dev);
 	error = -EACCES;
 	if (!(flags & MS_RDONLY) && is_read_only(dev)) {
-		blkdev_put(bdev, BDEV_FS);
+		devfs_put_ops (de);   /*  Decrement module use count   */
 		goto out;
 	}
-
 	error = -ENOMEM;
 	s = alloc_super();
 	if (!s) {
-		blkdev_put(bdev, BDEV_FS);
+		devfs_put_ops (de);   /*  Decrement module use count   */
 		goto out;
 	}
 
@@ -675,16 +670,24 @@
 		    ((flags ^ old->s_flags) & MS_RDONLY)) {
 			spin_unlock(&sb_lock);
 			destroy_super(s);
-			blkdev_put(bdev, BDEV_FS);
+		devfs_put_ops (de);   /*  Decrement module use count   */
 			goto out;
 		}
 		if (!grab_super(old))
 			goto restart;
 		destroy_super(s);
-		blkdev_put(bdev, BDEV_FS);
+		devfs_put_ops (de);   /*  Decrement module use count   */
 		path_release(&nd);
 		return old;
 	}
+	/*
+	 * 2002.11.08 moved by T. KATO  
+	 * To make MTD worked.
+	 */
+	error = blkdev_get(bdev, mode, 0, BDEV_FS);
+	devfs_put_ops (de);   /*  Decrement module use count now we're safe  */
+	if (error)
+		goto out;
 	s->s_dev = dev;
 	s->s_bdev = bdev;
 	s->s_flags = flags;
#1 lore raw
Quoted 5 lines · [email protected] said:

3. The solution
We changed the sequence of the function called ``get_sb_bdev''
in fs/super.c. We changed the function to make the block device to
be mounted checked before opening the device.
Please refer the patch to make out the changes in detail.

Wrong fix. Use the fix which is already in 2.4.19.

--
dwmw2

#2 lore raw

Dear Woodhouse:

Quoted 10 lines · David Woodhouse
Quoted 5 lines · [email protected] said:

3. The solution
We changed the sequence of the function called ``get_sb_bdev''
in fs/super.c. We changed the function to make the block device to
be mounted checked before opening the device.
Please refer the patch to make out the changes in detail.

Wrong fix. Use the fix which is already in 2.4.19.

Thank you for your response.
I'll try it later.

Yours, Sincerely.

Signature · 3 lines
Takeharu KATO
Fujitsu Limited
Email:[email protected] (ext. 7112-4621)