linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned
@ 2017-01-08 14:47 Chandan Rajendra
  2017-01-09 13:52 ` Christoph Hellwig
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Chandan Rajendra @ 2017-01-08 14:47 UTC (permalink / raw)
  To: axboe, jack
  Cc: Chandan Rajendra, linux-block, linux-fsdevel, linux-kernel,
	anton, linuxppc-dev

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.

Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
---
 fs/direct-io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/direct-io.c b/fs/direct-io.c
index aeae8c0..b20adf9 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -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)
-- 
2.5.5

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

* Re: [PATCH] do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned
  2017-01-08 14:47 [PATCH] do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned Chandan Rajendra
@ 2017-01-09 13:52 ` Christoph Hellwig
  2017-01-09 15:32 ` Jens Axboe
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2017-01-09 13:52 UTC (permalink / raw)
  To: Chandan Rajendra
  Cc: axboe, jack, linux-block, linux-fsdevel, linux-kernel, anton,
	linuxppc-dev

On Sun, Jan 08, 2017 at 08:17:10PM +0530, Chandan Rajendra wrote:
> 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,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH] do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned
  2017-01-08 14:47 [PATCH] do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned Chandan Rajendra
  2017-01-09 13:52 ` Christoph Hellwig
@ 2017-01-09 15:32 ` Jens Axboe
  2017-01-09 16:04 ` Jeff Moyer
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Jens Axboe @ 2017-01-09 15:32 UTC (permalink / raw)
  To: Chandan Rajendra, jack
  Cc: linux-block, linux-fsdevel, linux-kernel, anton, linuxppc-dev

On 01/08/2017 07:47 AM, Chandan Rajendra wrote:
> 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.

-- 
Jens Axboe

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

* Re: [PATCH] do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned
  2017-01-08 14:47 [PATCH] do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned Chandan Rajendra
  2017-01-09 13:52 ` Christoph Hellwig
  2017-01-09 15:32 ` Jens Axboe
@ 2017-01-09 16:04 ` Jeff Moyer
  2017-01-09 20:20 ` Jan Kara
  2017-01-09 21:42 ` [PATCH] direct-io: don't introduce another read of inode->i_blkbits Jeff Moyer
  4 siblings, 0 replies; 9+ messages in thread
From: Jeff Moyer @ 2017-01-09 16:04 UTC (permalink / raw)
  To: Chandan Rajendra
  Cc: axboe, jack, linux-block, linux-fsdevel, linux-kernel, anton,
	linuxppc-dev

Chandan Rajendra <chandan@linux.vnet.ibm.com> writes:

> 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.
>
> Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
> ---
>  fs/direct-io.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/direct-io.c b/fs/direct-io.c
> index aeae8c0..b20adf9 100644
> --- a/fs/direct-io.c
> +++ b/fs/direct-io.c
> @@ -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

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

* Re: [PATCH] do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned
  2017-01-08 14:47 [PATCH] do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned Chandan Rajendra
                   ` (2 preceding siblings ...)
  2017-01-09 16:04 ` Jeff Moyer
@ 2017-01-09 20:20 ` Jan Kara
  2017-01-09 21:42 ` [PATCH] direct-io: don't introduce another read of inode->i_blkbits Jeff Moyer
  4 siblings, 0 replies; 9+ messages in thread
From: Jan Kara @ 2017-01-09 20:20 UTC (permalink / raw)
  To: Chandan Rajendra
  Cc: axboe, jack, linux-block, linux-fsdevel, linux-kernel, anton,
	linuxppc-dev

On Sun 08-01-17 20:17:10, Chandan Rajendra wrote:
> 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:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
> ---
>  fs/direct-io.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/direct-io.c b/fs/direct-io.c
> index aeae8c0..b20adf9 100644
> --- a/fs/direct-io.c
> +++ b/fs/direct-io.c
> @@ -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)
> -- 
> 2.5.5
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* [PATCH] direct-io: don't introduce another read of inode->i_blkbits
  2017-01-08 14:47 [PATCH] do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned Chandan Rajendra
                   ` (3 preceding siblings ...)
  2017-01-09 20:20 ` Jan Kara
@ 2017-01-09 21:42 ` Jeff Moyer
  2017-01-09 21:44   ` Jens Axboe
  2017-01-10  5:27   ` Chandan Rajendra
  4 siblings, 2 replies; 9+ messages in thread
From: Jeff Moyer @ 2017-01-09 21:42 UTC (permalink / raw)
  To: axboe, Chandan Rajendra
  Cc: jack, linux-block, linux-fsdevel, linux-kernel, anton, linuxppc-dev

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
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>

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

diff --git a/fs/direct-io.c b/fs/direct-io.c
index b20adf9..c87bae4 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -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) {

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

* Re: [PATCH] direct-io: don't introduce another read of inode->i_blkbits
  2017-01-09 21:42 ` [PATCH] direct-io: don't introduce another read of inode->i_blkbits Jeff Moyer
@ 2017-01-09 21:44   ` Jens Axboe
  2017-01-10  5:27   ` Chandan Rajendra
  1 sibling, 0 replies; 9+ messages in thread
From: Jens Axboe @ 2017-01-09 21:44 UTC (permalink / raw)
  To: Jeff Moyer, Chandan Rajendra
  Cc: jack, linux-block, linux-fsdevel, linux-kernel, anton, linuxppc-dev

On 01/09/2017 02:42 PM, Jeff Moyer wrote:
> 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
> Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
> 
> ---
> 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.

-- 
Jens Axboe

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

* Re: [PATCH] direct-io: don't introduce another read of inode->i_blkbits
  2017-01-09 21:42 ` [PATCH] direct-io: don't introduce another read of inode->i_blkbits Jeff Moyer
  2017-01-09 21:44   ` Jens Axboe
@ 2017-01-10  5:27   ` Chandan Rajendra
  2017-01-10 20:31     ` Jens Axboe
  1 sibling, 1 reply; 9+ messages in thread
From: Chandan Rajendra @ 2017-01-10  5:27 UTC (permalink / raw)
  To: Jeff Moyer
  Cc: axboe, jack, linux-block, linux-fsdevel, linux-kernel, anton,
	linuxppc-dev

On Monday, January 09, 2017 04:42:58 PM Jeff Moyer wrote:
> 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
> Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
> 
> ---
> Chandan, can you please test this to ensure this still fixes your problem?

This patch fixes the failure,

Tested-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>

-- 
chandan

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

* Re: [PATCH] direct-io: don't introduce another read of inode->i_blkbits
  2017-01-10  5:27   ` Chandan Rajendra
@ 2017-01-10 20:31     ` Jens Axboe
  0 siblings, 0 replies; 9+ messages in thread
From: Jens Axboe @ 2017-01-10 20:31 UTC (permalink / raw)
  To: Chandan Rajendra, Jeff Moyer
  Cc: jack, linux-block, linux-fsdevel, linux-kernel, anton, linuxppc-dev

On 01/09/2017 10:27 PM, Chandan Rajendra wrote:
> On Monday, January 09, 2017 04:42:58 PM Jeff Moyer wrote:
>> 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
>> Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
>>
>> ---
>> Chandan, can you please test this to ensure this still fixes your problem?
> 
> This patch fixes the failure,
> 
> Tested-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
> 

I've updated the patch, thanks guys.

-- 
Jens Axboe

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

end of thread, other threads:[~2017-01-10 20:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-08 14:47 [PATCH] do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned Chandan Rajendra
2017-01-09 13:52 ` Christoph Hellwig
2017-01-09 15:32 ` Jens Axboe
2017-01-09 16:04 ` Jeff Moyer
2017-01-09 20:20 ` Jan Kara
2017-01-09 21:42 ` [PATCH] direct-io: don't introduce another read of inode->i_blkbits Jeff Moyer
2017-01-09 21:44   ` Jens Axboe
2017-01-10  5:27   ` Chandan Rajendra
2017-01-10 20:31     ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).