Skip to contentSkip to conversation

do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned

PATCH In review Chandan Rajendra 5 participants 9 messages Jan 8, 2017 – Jan 10, 2017

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

PATCH 1/1 do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned

The code currently uses sdio->blkbits to compute the number of blocks to be cleaned. However sdio->blkbits is derived from the logical block size of the underlying block device (Refer to the definition of do_blockdev_direct_IO()). Due to this, generic/299 test would rarely fail when executed on an ext4 filesystem with 64k as the block size and when using a virtio based disk (having 512 byte as the logical block size) inside a kvm guest.

This commit fixes the bug by using inode->i_blkbits to compute the number of blocks to be cleaned.

---
 fs/direct-io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/direct-io.c +2 -1
index aeae8c0..b20adf9 100644
@@ -905,6 +905,7 @@ static inline void dio_zero_block(struct dio *dio, struct dio_submit *sdio,
 static int do_direct_IO(struct dio *dio, struct dio_submit *sdio,
 			struct buffer_head *map_bh)
 {
+	const unsigned i_blkbits = dio->inode->i_blkbits;
 	const unsigned blkbits = sdio->blkbits;
 	int ret = 0;
 
@@ -949,7 +950,7 @@ static int do_direct_IO(struct dio *dio, struct dio_submit *sdio,
 					clean_bdev_aliases(
 						map_bh->b_bdev,
 						map_bh->b_blocknr,
-						map_bh->b_size >> blkbits);
+						map_bh->b_size >> i_blkbits);
 				}
 
 				if (!sdio->blkfactor)
Signature · 1 line
2.5.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Chandan Rajendra

The code currently uses sdio->blkbits to compute the number of blocks to be cleaned. However sdio->blkbits is derived from the logical block size of the underlying block device (Refer to the definition of do_blockdev_direct_IO()). Due to this, generic/299 test would rarely fail when executed on an ext4 filesystem with 64k as the block size and when using a virtio based disk (having 512 byte as the logical block size) inside a kvm guest.

This commit fixes the bug by using inode->i_blkbits to compute the number of blocks to be cleaned.

Looks fine,

maintainer
#2 lore raw
In reply to Chandan Rajendra
Quoted 10 lines · Chandan Rajendra

The code currently uses sdio->blkbits to compute the number of blocks to be cleaned. However sdio->blkbits is derived from the logical block size of the underlying block device (Refer to the definition of do_blockdev_direct_IO()). Due to this, generic/299 test would rarely fail when executed on an ext4 filesystem with 64k as the block size and when using a virtio based disk (having 512 byte as the logical block size) inside a kvm guest.

This commit fixes the bug by using inode->i_blkbits to compute the number of blocks to be cleaned.

Thanks, added for 4.10.

Signature · 1 line
Jens Axboe
#3 lore raw
In reply to Chandan Rajendra
Quoted 21 lines · Chandan Rajendra

The code currently uses sdio->blkbits to compute the number of blocks to be cleaned. However sdio->blkbits is derived from the logical block size of the underlying block device (Refer to the definition of do_blockdev_direct_IO()). Due to this, generic/299 test would rarely fail when executed on an ext4 filesystem with 64k as the block size and when using a virtio based disk (having 512 byte as the logical block size) inside a kvm guest.

This commit fixes the bug by using inode->i_blkbits to compute the number of blocks to be cleaned.

---
 fs/direct-io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/direct-io.c +0 -0
index aeae8c0..b20adf9 100644

fs/direct-io.c static inline void dio_zero_block(struct dio *dio, struct dio_submit *sdio, · line 908

Quoted 4 lines
fs/direct-io.c +1 -0
@@ -905,6 +905,7 @@ static inline void dio_zero_block(struct dio *dio, struct dio_submit *sdio,
 static int do_direct_IO(struct dio *dio, struct dio_submit *sdio,
 			struct buffer_head *map_bh)
 {
+	const unsigned i_blkbits = dio->inode->i_blkbits;

NAK. Please see commit ab73857e354 ("direct-io: don't read inode->i_blkbits multiple times").

I think you want:

	const unsigned i_blkbits = sdio->blkbits + sdio->blkfactor;

as is used elsewhere in the code.

Cheers,
Jeff

reviewer Reviewed-by on v1 1/1
#4 lore raw
In reply to Chandan Rajendra
Quoted 10 lines · Chandan Rajendra

The code currently uses sdio->blkbits to compute the number of blocks to be cleaned. However sdio->blkbits is derived from the logical block size of the underlying block device (Refer to the definition of do_blockdev_direct_IO()). Due to this, generic/299 test would rarely fail when executed on an ext4 filesystem with 64k as the block size and when using a virtio based disk (having 512 byte as the logical block size) inside a kvm guest.

This commit fixes the bug by using inode->i_blkbits to compute the number of blocks to be cleaned.

Ah, good catch. You can add:

Honza

Quoted 29 lines
---
 fs/direct-io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/direct-io.c +2 -1
index aeae8c0..b20adf9 100644
@@ -905,6 +905,7 @@ static inline void dio_zero_block(struct dio *dio, struct dio_submit *sdio,
 static int do_direct_IO(struct dio *dio, struct dio_submit *sdio,
 			struct buffer_head *map_bh)
 {
+	const unsigned i_blkbits = dio->inode->i_blkbits;
 	const unsigned blkbits = sdio->blkbits;
 	int ret = 0;
 
@@ -949,7 +950,7 @@ static int do_direct_IO(struct dio *dio, struct dio_submit *sdio,
 					clean_bdev_aliases(
 						map_bh->b_bdev,
 						map_bh->b_blocknr,
-						map_bh->b_size >> blkbits);
+						map_bh->b_size >> i_blkbits);
 				}
 
 				if (!sdio->blkfactor)
Signature · 1 line
2.5.5
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#5 lore raw

PATCH 1/1 direct-io: don't introduce another read of inode->i_blkbits

In reply to Chandan Rajendra

Commit 20ce44d545844 ("do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned") introduced a regression: if the block size of the block device is changed while a direct I/O request is being setup, it can result in a panic. See commit ab73857e354ab ("direct-io:
don't read inode->i_blkbits multiple times") for the reasoning, and commit b87570f5d3496 ("Fix a crash when block device is read and block size is changed at the same time") for a more detailed problem description and reproducer.

Fixes 20ce44d545844

---
Chandan, can you please test this to ensure this still fixes your problem?

fs/direct-io.c +1 -1
index b20adf9..c87bae4 100644
@@ -905,8 +905,8 @@ static inline void dio_zero_block(struct dio *dio, struct dio_submit *sdio,
 static int do_direct_IO(struct dio *dio, struct dio_submit *sdio,
 			struct buffer_head *map_bh)
 {
-	const unsigned i_blkbits = dio->inode->i_blkbits;
 	const unsigned blkbits = sdio->blkbits;
+	const unsigned i_blkbits = blkbits + sdio->blkfactor;
 	int ret = 0;
 
 	while (sdio->block_in_file < sdio->final_block_in_request) {
maintainer
#6 lore raw

Re: [PATCH] direct-io: don't introduce another read of inode->i_blkbits

Quoted 9 lines · Jeff Moyer

Commit 20ce44d545844 ("do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned") introduced a regression: if the block size of the block device is changed while a direct I/O request is being setup, it can result in a panic. See commit ab73857e354ab ("direct-io:
don't read inode->i_blkbits multiple times") for the reasoning, and commit b87570f5d3496 ("Fix a crash when block device is read and block size is changed at the same time") for a more detailed problem description and reproducer.

Quoted 5 lines
Fixes 20ce44d545844

---
Chandan, can you please test this to ensure this still fixes your problem?

Please, that would be great. And if so, then let's fold the two.

Signature · 1 line
Jens Axboe
author Tested-by on v1 1/1
#7 lore raw

Re: [PATCH] direct-io: don't introduce another read of inode->i_blkbits

In reply to Jeff Moyer
Quoted 9 lines · Jeff Moyer

Commit 20ce44d545844 ("do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned") introduced a regression: if the block size of the block device is changed while a direct I/O request is being setup, it can result in a panic. See commit ab73857e354ab ("direct-io:
don't read inode->i_blkbits multiple times") for the reasoning, and commit b87570f5d3496 ("Fix a crash when block device is read and block size is changed at the same time") for a more detailed problem description and reproducer.

Quoted 5 lines
Fixes 20ce44d545844

---
Chandan, can you please test this to ensure this still fixes your problem?

This patch fixes the failure,

Signature · 1 line
chandan
maintainer
#8 lore raw

Re: [PATCH] direct-io: don't introduce another read of inode->i_blkbits

Quoted 13 lines · Chandan Rajendra
Quoted 12 lines · Jeff Moyer

Commit 20ce44d545844 ("do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned") introduced a regression: if the block size of the block device is changed while a direct I/O request is being setup, it can result in a panic. See commit ab73857e354ab ("direct-io:
don't read inode->i_blkbits multiple times") for the reasoning, and commit b87570f5d3496 ("Fix a crash when block device is read and block size is changed at the same time") for a more detailed problem description and reproducer.

Fixes 20ce44d545844
Quoted 7 lines
Quoted 2 lines

---
Chandan, can you please test this to ensure this still fixes your problem?

This patch fixes the failure,

I've updated the patch, thanks guys.

Signature · 1 line
Jens Axboe