public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] SMP race in ext2 - metadata corruption.
@ 2001-04-26 15:45 Alexander Viro
  2001-04-26 18:12 ` Andrea Arcangeli
  0 siblings, 1 reply; 90+ messages in thread
From: Alexander Viro @ 2001-04-26 15:45 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Alan Cox, linux-kernel

	Ext2 does getblk+wait_on_buffer for new metadata blocks before
filling them with zeroes. While that is enough for single-processor,
on SMP we have the following race:

getblk gives us unlocked, non-uptodate bh
wait_on_buffer() does nothing
					read from device locks it and starts IO
we zero it out.
					on-disk data overwrites our zeroes.
we mark it dirty
bdflush writes the old data (_not_ zeroes) back to disk.

Result: crap in metadata block. Proposed fix: lock_buffer()/unlock_buffer()
around memset()/mark_buffer_uptodate() instead of wait_on_buffer() before
them.

Patch against 2.4.4-pre7 follows. Please, apply.
								Al


--- S4-pre7/fs/ext2/inode.c	Wed Apr 25 20:43:08 2001
+++ S4-pre7-ext2/fs/ext2/inode.c	Thu Apr 26 11:36:11 2001
@@ -397,13 +397,13 @@
 		 * the pointer to new one, then send parent to disk.
 		 */
 		bh = getblk(inode->i_dev, parent, blocksize);
-		if (!buffer_uptodate(bh))
-			wait_on_buffer(bh);
+		lock_buffer(bh);
 		memset(bh->b_data, 0, blocksize);
 		branch[n].bh = bh;
 		branch[n].p = (u32*) bh->b_data + offsets[n];
 		*branch[n].p = branch[n].key;
 		mark_buffer_uptodate(bh, 1);
+		unlock_buffer(bh);
 		mark_buffer_dirty_inode(bh, inode);
 		if (IS_SYNC(inode) || inode->u.ext2_i.i_osync) {
 			ll_rw_block (WRITE, 1, &bh);
@@ -587,10 +587,10 @@
 		struct buffer_head *bh;
 		bh = getblk(dummy.b_dev, dummy.b_blocknr, inode->i_sb->s_blocksize);
 		if (buffer_new(&dummy)) {
-			if (!buffer_uptodate(bh))
-				wait_on_buffer(bh);
+			lock_buffer(bh);
 			memset(bh->b_data, 0, inode->i_sb->s_blocksize);
 			mark_buffer_uptodate(bh, 1);
+			unlock_buffer(bh);
 			mark_buffer_dirty_inode(bh, inode);
 		}
 		return bh;


^ permalink raw reply	[flat|nested] 90+ messages in thread

end of thread, other threads:[~2001-05-18 14:47 UTC | newest]

Thread overview: 90+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <Pine.LNX.4.21.0104270953280.2067-100000@penguin.transmeta.com>
2001-04-27 17:36 ` [PATCH] SMP race in ext2 - metadata corruption Jeff Garzik
     [not found] ` <3AE9A69B.D11F0BBD@evision-ventures.com>
2001-04-28  8:31   ` Matthias Urlichs
2001-04-28 13:20   ` Olaf Titz
2001-04-30  8:47 ` Neil Conway
2001-04-26 15:45 Alexander Viro
2001-04-26 18:12 ` Andrea Arcangeli
2001-04-26 18:24   ` Alexander Viro
2001-04-26 19:00     ` Chris Mason
2001-04-26 18:49   ` Linus Torvalds
2001-04-26 19:08     ` Alexander Viro
2001-04-26 19:17       ` Alexander Viro
2001-04-26 20:06         ` Andrea Arcangeli
2001-04-26 19:15     ` Andrea Arcangeli
2001-04-26 19:34       ` Alexander Viro
2001-04-26 19:44         ` Andrea Arcangeli
2001-04-26 19:55           ` Alexander Viro
2001-04-26 20:08             ` Linus Torvalds
2001-04-26 20:21               ` Andrea Arcangeli
2001-04-26 20:49               ` Alexander Viro
2001-04-26 21:07                 ` Andrea Arcangeli
2001-04-26 23:25                   ` Alexander Viro
2001-04-27  0:05                     ` Andrea Arcangeli
2001-04-27  0:19                       ` Linus Torvalds
2001-04-27  0:35                         ` Andrea Arcangeli
2001-04-26 21:13               ` Andrzej Krzysztofowicz
2001-04-27 18:02                 ` LA Walsh
2001-04-27 18:17                   ` dek_ml
2001-04-27  7:58               ` Vojtech Pavlik
2001-04-27 13:23                 ` Alexander Viro
2001-04-27 14:32                   ` Ville Herva
2001-04-27 16:52                 ` Linus Torvalds
2001-04-27 19:22                   ` Shane Wegner
2001-04-28  4:55                   ` Albert D. Cahalan
2001-04-28 10:05                     ` Jens Axboe
2001-04-27 14:29               ` Andi Kleen
2001-05-03  6:23               ` volodya
2001-05-03  9:29                 ` Alan Cox
2001-05-03 17:21                   ` Linus Torvalds
2001-05-04 11:40                     ` Rogier Wolff
2001-05-04 11:56                       ` Jens Axboe
2001-05-04 15:29                         ` Andrea Arcangeli
2001-05-04 17:40                           ` Linus Torvalds
2001-05-05  3:18                           ` Chris Wedgwood
2001-05-06  0:37                             ` Andrea Arcangeli
2001-05-06  2:14                               ` Chris Wedgwood
2001-05-06  2:50                                 ` Andrea Arcangeli
2001-05-06  3:00                                   ` Chris Wedgwood
2001-05-06  3:15                                     ` Alexander Viro
2001-05-06  3:32                                       ` Chris Wedgwood
2001-05-06  3:59                                         ` Alexander Viro
2001-05-06 12:47                                           ` Alan Cox
2001-05-06 19:46                                             ` Andreas Dilger
2001-05-06 20:58                                               ` Alan Cox
2001-05-07  4:08                                                 ` Andreas Dilger
2001-05-07 18:42                                           ` Pavel Machek
2001-05-11 14:54                                             ` Daniel Phillips
2001-05-18 14:46                                               ` Stephen C. Tweedie
2001-05-11 20:00                                             ` Alexander Viro
2001-05-06  3:38                                     ` Andreas Dilger
2001-05-06  3:51                                     ` Andrea Arcangeli
2001-05-04 12:15                       ` Marc SCHAEFER
2001-05-04 17:28                       ` Linus Torvalds
2001-05-04 17:39                         ` Alexander Viro
2001-05-04 17:55                           ` Linus Torvalds
2001-05-04 18:29                             ` Alexander Viro
2001-05-04 19:13                               ` Linus Torvalds
2001-05-05 11:20                               ` Albert D. Cahalan
2001-05-05 17:11                                 ` Alexander Viro
2001-05-04 18:20                         ` Richard Gooch
2001-05-04 18:35                           ` Alexander Viro
2001-05-04 18:49                             ` Richard Gooch
2001-05-04 19:15                               ` Alexander Viro
2001-05-04 19:36                                 ` Richard Gooch
2001-05-04 19:58                                   ` Alexander Viro
2001-05-04 20:04                                     ` Richard Gooch
2001-05-04 19:04                           ` Jens Axboe
2001-05-05 13:52                           ` Rogier Wolff
2001-05-05 18:12                             ` Richard Gooch
2001-05-08 13:46                           ` volodya
2001-05-09 10:30                             ` Helge Hafting
2001-05-04 21:11                         ` Alan Cox
2001-05-04 21:50                           ` Linus Torvalds
2001-04-26 20:11             ` Andrea Arcangeli
2001-04-26 20:14               ` Andrea Arcangeli
2001-04-26 20:26               ` Linus Torvalds
2001-04-26 21:16                 ` Andrea Arcangeli
2001-04-26 20:42         ` Richard B. Johnson
2001-04-26 20:55           ` Alexander Viro
2001-04-27 11:43             ` Richard B. Johnson
2001-04-26 19:39       ` Andrea Arcangeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox