aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Moyer <jmoyer@redhat.com>2012-05-11 10:34:10 -0400
committerJens Axboe <axboe@kernel.dk>2012-05-11 10:42:14 -0400
commit080399aaaf3531f5b8761ec0ac30ff98891e8686 (patch)
tree28ba8f41bb67a58992bc426dac7002983bc64e8f
parenta09ba13eefb155a00d8d50008a0c0a2406985ddd (diff)
block: don't mark buffers beyond end of disk as mapped
Hi, We have a bug report open where a squashfs image mounted on ppc64 would exhibit errors due to trying to read beyond the end of the disk. It can easily be reproduced by doing the following: [root@ibm-p750e-02-lp3 ~]# ls -l install.img -rw-r--r-- 1 root root 142032896 Apr 30 16:46 install.img [root@ibm-p750e-02-lp3 ~]# mount -o loop ./install.img /mnt/test [root@ibm-p750e-02-lp3 ~]# dd if=/dev/loop0 of=/dev/null dd: reading `/dev/loop0': Input/output error 277376+0 records in 277376+0 records out 142016512 bytes (142 MB) copied, 0.9465 s, 150 MB/s In dmesg, you'll find the following: squashfs: version 4.0 (2009/01/31) Phillip Lougher [ 43.106012] attempt to access beyond end of device [ 43.106029] loop0: rw=0, want=277410, limit=277408 [ 43.106039] Buffer I/O error on device loop0, logical block 138704 [ 43.106053] attempt to access beyond end of device [ 43.106057] loop0: rw=0, want=277412, limit=277408 [ 43.106061] Buffer I/O error on device loop0, logical block 138705 [ 43.106066] attempt to access beyond end of device [ 43.106070] loop0: rw=0, want=277414, limit=277408 [ 43.106073] Buffer I/O error on device loop0, logical block 138706 [ 43.106078] attempt to access beyond end of device [ 43.106081] loop0: rw=0, want=277416, limit=277408 [ 43.106085] Buffer I/O error on device loop0, logical block 138707 [ 43.106089] attempt to access beyond end of device [ 43.106093] loop0: rw=0, want=277418, limit=277408 [ 43.106096] Buffer I/O error on device loop0, logical block 138708 [ 43.106101] attempt to access beyond end of device [ 43.106104] loop0: rw=0, want=277420, limit=277408 [ 43.106108] Buffer I/O error on device loop0, logical block 138709 [ 43.106112] attempt to access beyond end of device [ 43.106116] loop0: rw=0, want=277422, limit=277408 [ 43.106120] Buffer I/O error on device loop0, logical block 138710 [ 43.106124] attempt to access beyond end of device [ 43.106128] loop0: rw=0, want=277424, limit=277408 [ 43.106131] Buffer I/O error on device loop0, logical block 138711 [ 43.106135] attempt to access beyond end of device [ 43.106139] loop0: rw=0, want=277426, limit=277408 [ 43.106143] Buffer I/O error on device loop0, logical block 138712 [ 43.106147] attempt to access beyond end of device [ 43.106151] loop0: rw=0, want=277428, limit=277408 [ 43.106154] Buffer I/O error on device loop0, logical block 138713 [ 43.106158] attempt to access beyond end of device [ 43.106162] loop0: rw=0, want=277430, limit=277408 [ 43.106166] attempt to access beyond end of device [ 43.106169] loop0: rw=0, want=277432, limit=277408 ... [ 43.106307] attempt to access beyond end of device [ 43.106311] loop0: rw=0, want=277470, limit=2774 Squashfs manages to read in the end block(s) of the disk during the mount operation. Then, when dd reads the block device, it leads to block_read_full_page being called with buffers that are beyond end of disk, but are marked as mapped. Thus, it would end up submitting read I/O against them, resulting in the errors mentioned above. I fixed the problem by modifying init_page_buffers to only set the buffer mapped if it fell inside of i_size. Cheers, Jeff Signed-off-by: Jeff Moyer <jmoyer@redhat.com> Acked-by: Nick Piggin <npiggin@kernel.dk> -- Changes from v1->v2: re-used max_block, as suggested by Nick Piggin. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--fs/block_dev.c6
-rw-r--r--fs/buffer.c4
-rw-r--r--include/linux/fs.h1
3 files changed, 7 insertions, 4 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c
index e08f6a20a5bb..ba11c30f302d 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -70,7 +70,7 @@ static void bdev_inode_switch_bdi(struct inode *inode,
70 spin_unlock(&dst->wb.list_lock); 70 spin_unlock(&dst->wb.list_lock);
71} 71}
72 72
73static sector_t max_block(struct block_device *bdev) 73sector_t blkdev_max_block(struct block_device *bdev)
74{ 74{
75 sector_t retval = ~((sector_t)0); 75 sector_t retval = ~((sector_t)0);
76 loff_t sz = i_size_read(bdev->bd_inode); 76 loff_t sz = i_size_read(bdev->bd_inode);
@@ -163,7 +163,7 @@ static int
163blkdev_get_block(struct inode *inode, sector_t iblock, 163blkdev_get_block(struct inode *inode, sector_t iblock,
164 struct buffer_head *bh, int create) 164 struct buffer_head *bh, int create)
165{ 165{
166 if (iblock >= max_block(I_BDEV(inode))) { 166 if (iblock >= blkdev_max_block(I_BDEV(inode))) {
167 if (create) 167 if (create)
168 return -EIO; 168 return -EIO;
169 169
@@ -185,7 +185,7 @@ static int
185blkdev_get_blocks(struct inode *inode, sector_t iblock, 185blkdev_get_blocks(struct inode *inode, sector_t iblock,
186 struct buffer_head *bh, int create) 186 struct buffer_head *bh, int create)
187{ 187{
188 sector_t end_block = max_block(I_BDEV(inode)); 188 sector_t end_block = blkdev_max_block(I_BDEV(inode));
189 unsigned long max_blocks = bh->b_size >> inode->i_blkbits; 189 unsigned long max_blocks = bh->b_size >> inode->i_blkbits;
190 190
191 if ((iblock + max_blocks) > end_block) { 191 if ((iblock + max_blocks) > end_block) {
diff --git a/fs/buffer.c b/fs/buffer.c
index 351e18ea2e53..ad5938ca357c 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -921,6 +921,7 @@ init_page_buffers(struct page *page, struct block_device *bdev,
921 struct buffer_head *head = page_buffers(page); 921 struct buffer_head *head = page_buffers(page);
922 struct buffer_head *bh = head; 922 struct buffer_head *bh = head;
923 int uptodate = PageUptodate(page); 923 int uptodate = PageUptodate(page);
924 sector_t end_block = blkdev_max_block(I_BDEV(bdev->bd_inode));
924 925
925 do { 926 do {
926 if (!buffer_mapped(bh)) { 927 if (!buffer_mapped(bh)) {
@@ -929,7 +930,8 @@ init_page_buffers(struct page *page, struct block_device *bdev,
929 bh->b_blocknr = block; 930 bh->b_blocknr = block;
930 if (uptodate) 931 if (uptodate)
931 set_buffer_uptodate(bh); 932 set_buffer_uptodate(bh);
932 set_buffer_mapped(bh); 933 if (block < end_block)
934 set_buffer_mapped(bh);
933 } 935 }
934 block++; 936 block++;
935 bh = bh->b_this_page; 937 bh = bh->b_this_page;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 8de675523e46..25c40b9f848a 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2051,6 +2051,7 @@ extern void unregister_blkdev(unsigned int, const char *);
2051extern struct block_device *bdget(dev_t); 2051extern struct block_device *bdget(dev_t);
2052extern struct block_device *bdgrab(struct block_device *bdev); 2052extern struct block_device *bdgrab(struct block_device *bdev);
2053extern void bd_set_size(struct block_device *, loff_t size); 2053extern void bd_set_size(struct block_device *, loff_t size);
2054extern sector_t blkdev_max_block(struct block_device *bdev);
2054extern void bd_forget(struct inode *inode); 2055extern void bd_forget(struct inode *inode);
2055extern void bdput(struct block_device *); 2056extern void bdput(struct block_device *);
2056extern void invalidate_bdev(struct block_device *); 2057extern void invalidate_bdev(struct block_device *);