All of lore.kernel.org
 help / color / mirror / Atom feed
* Crash when IO is being submitted and block size is changed
@ 2012-06-28  3:04 Mikulas Patocka
  2012-06-28 11:15 ` Jan Kara
  2012-06-29  6:25 ` Crash when IO is being submitted and block size is changed Vyacheslav Dubeyko
  0 siblings, 2 replies; 49+ messages in thread
From: Mikulas Patocka @ 2012-06-28  3:04 UTC (permalink / raw)
  To: Alexander Viro, Jens Axboe, Alasdair G. Kergon
  Cc: linux-kernel, linux-fsdevel, linux-mm, dm-devel

Hi

The kernel crashes when IO is being submitted to a block device and block 
size of that device is changed simultaneously.

To reproduce the crash, apply this patch:

--- linux-3.4.3-fast.orig/fs/block_dev.c 2012-06-27 20:24:07.000000000 +0200
+++ linux-3.4.3-fast/fs/block_dev.c 2012-06-27 20:28:34.000000000 +0200
@@ -28,6 +28,7 @@
 #include <linux/log2.h>
 #include <linux/cleancache.h>
 #include <asm/uaccess.h> 
+#include <linux/delay.h>
 #include "internal.h"
 struct bdev_inode {
@@ -203,6 +204,7 @@ blkdev_get_blocks(struct inode *inode, s
 
 	bh->b_bdev = I_BDEV(inode);
 	bh->b_blocknr = iblock;
+	msleep(1000);
 	bh->b_size = max_blocks << inode->i_blkbits;
 	if (max_blocks)
 		set_buffer_mapped(bh);

Use some device with 4k blocksize, for example a ramdisk.
Run "dd if=/dev/ram0 of=/dev/null bs=4k count=1 iflag=direct"
While it is sleeping in the msleep function, run "blockdev --setbsz 2048 
/dev/ram0" on the other console.
You get a BUG at fs/direct-io.c:1013 - BUG_ON(this_chunk_bytes == 0);


One may ask "why would anyone do this - submit I/O and change block size 
simultaneously?" - the problem is that udev and lvm can scan and read all 
block devices anytime - so anytime you change block device size, there may 
be some i/o to that device in flight and the crash may happen. That BUG 
actually happened in production environment because of lvm scanning block 
devices and some other software changing block size at the same time.


I would like to know, what is your opinion on fixing this crash? There are 
several possibilities:

* we could potentially read i_blkbits once, store it in the direct i/o 
structure and never read it again - direct i/o could be maybe modified for 
this (it reads i_blkbits only at a few places). But what about non-direct 
i/o? Non-direct i/o is reading i_blkbits much more often and the code was 
obviously written without consideration that it may change - for block 
devices, i_blkbits is essentially a random value that can change anytime 
you read it and the code of block_read_full_page, __block_write_begin, 
__block_write_full_page and others doesn't seem to take it into account.

* put some rw-lock arond all I/Os on block device. The rw-lock would be 
taken for read on all I/O paths and it would be taken for write when 
changing the block device size. The downside would be a possible 
performance hit of the rw-lock. The rw-lock could be made per-cpu to avoid 
cache line bouncing (take the rw-lock belonging to the current cpu for 
read; for write take all cpus' locks).

* allow changing block size only if the device is open only once and the 
process is singlethreaded? (so there couldn't be any outstanding I/Os). I 
don't know if this could be tested reliably... Another question: what to 
do if the device is open multiple times?

Do you have any other ideas what to do with it?

Mikulas

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

end of thread, other threads:[~2012-11-16 22:02 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-28  3:04 Crash when IO is being submitted and block size is changed Mikulas Patocka
2012-06-28 11:15 ` Jan Kara
2012-06-28 15:44   ` Mikulas Patocka
2012-06-28 16:53     ` Jan Kara
2012-07-16  0:55   ` Mikulas Patocka
2012-07-17 19:19     ` Jeff Moyer
2012-07-19  2:27       ` Mikulas Patocka
2012-07-19 13:33         ` Jeff Moyer
2012-07-28 16:40           ` [PATCH 1/3] Fix " Mikulas Patocka
2012-07-28 16:41             ` [PATCH 2/3] Introduce percpu rw semaphores Mikulas Patocka
2012-07-28 16:42               ` [PATCH 3/3] blockdev: turn a rw semaphore into a percpu rw semaphore Mikulas Patocka
2012-07-28 20:44               ` [PATCH 2/3] Introduce percpu rw semaphores Eric Dumazet
2012-07-29  5:13                 ` [dm-devel] " Mikulas Patocka
2012-07-29 10:10                   ` Eric Dumazet
2012-07-29 18:36                     ` Eric Dumazet
2012-08-01 20:07                       ` Mikulas Patocka
2012-08-01 20:09                       ` [PATCH 4/3] " Mikulas Patocka
2012-08-31 18:40                         ` [PATCH 0/4] Fix a crash when block device is read and block size is changed at the same time Mikulas Patocka
2012-08-31 18:41                           ` [PATCH 1/4] Add a lock that will be needed by the next patch Mikulas Patocka
2012-08-31 18:42                             ` [PATCH 2/4] blockdev: fix a crash when block size is changed and I/O is issued simultaneously Mikulas Patocka
2012-08-31 18:43                               ` [PATCH 3/4] blockdev: turn a rw semaphore into a percpu rw semaphore Mikulas Patocka
2012-08-31 18:43                                 ` [PATCH 4/4] New percpu lock implementation Mikulas Patocka
2012-08-31 19:27                           ` [PATCH 0/4] Fix a crash when block device is read and block size is changed at the same time Mikulas Patocka
2012-08-31 20:11                             ` Jeff Moyer
2012-08-31 20:34                               ` Mikulas Patocka
2012-09-17 21:19                               ` Jeff Moyer
2012-09-17 21:19                                 ` Jeff Moyer
2012-09-18 17:04                                 ` Mikulas Patocka
2012-09-18 17:22                                   ` Jeff Moyer
2012-09-18 18:55                                     ` Mikulas Patocka
2012-09-18 18:58                                       ` Jeff Moyer
2012-09-18 20:11                                   ` Jeff Moyer
2012-09-25 17:49                                     ` Jeff Moyer
2012-09-25 17:59                                       ` Jens Axboe
2012-09-25 17:59                                         ` Jens Axboe
2012-09-25 18:11                                         ` Jens Axboe
2012-09-25 18:11                                           ` Jens Axboe
2012-09-25 22:49                                           ` [PATCH 1/2] " Mikulas Patocka
2012-09-26  5:48                                             ` Jens Axboe
2012-09-26  5:48                                               ` Jens Axboe
2012-11-16 22:02                                             ` Jeff Moyer
2012-09-25 22:50                                           ` [PATCH 2/2] " Mikulas Patocka
2012-09-25 22:58                                       ` [PATCH 0/4] " Mikulas Patocka
2012-09-26 13:47                                         ` Jeff Moyer
2012-09-26 14:35                                           ` Mikulas Patocka
2012-07-30 17:00                   ` [dm-devel] [PATCH 2/3] Introduce percpu rw semaphores Paul E. McKenney
2012-07-31  0:00                     ` Mikulas Patocka
2012-08-01 17:15                       ` Paul E. McKenney
2012-06-29  6:25 ` Crash when IO is being submitted and block size is changed Vyacheslav Dubeyko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.