pflash: fix sectors vs bytes confusion in blk_pread_nonzeroes()
PATCH 1/1 pflash: fix sectors vs bytes confusion in blk_pread_nonzeroes()
The following expression is incorrect because blk_pread_nonzeroes() deals in units of bytes, not sectors:
bytes = MIN(size - offset, BDRV_REQUEST_MAX_SECTORS)
^^^^^^^
BDRV_REQUEST_MAX_BYTES is the appropriate constant.
--- hw/block/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/block.c +1 -1
@@ -30,7 +30,7 @@ static int blk_pread_nonzeroes(BlockBackend *blk, hwaddr size, void *buf)BlockDriverState *bs =blk_bs (blk);for (;;) { - bytes =MIN (size - offset,BDRV_REQUEST_MAX_SECTORS ); + bytes =MIN (size - offset,BDRV_REQUEST_MAX_BYTES );if (bytes <=0 ) {return 0 ; }
Signature · 1 line
2.43.0
Quoted 20 lines · Stefan Hajnoczi
The following expression is incorrect because
blk_pread_nonzeroes()deals in units of bytes, not sectors:bytes =
MIN(size - offset, BDRV_REQUEST_MAX_SECTORS)^^^^^^^
BDRV_REQUEST_MAX_BYTESis the appropriate constant.Fixes a4b15a8b9ef2 ("pflash: Only read non-zero parts of backend image")Cc Xiang Zheng <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/block/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/block/block.c +0
-0
hw/block/block.c static int blk_pread_nonzeroes(BlockBackend *blk, hwaddr size, void *buf) · line 36
Quoted 8 lines
hw/block/block.c +1
-1@@ -30,7 +30,7 @@ static int blk_pread_nonzeroes(BlockBackend *blk, hwaddr size, void *buf)BlockDriverState *bs =blk_bs (blk);for (;;) { - bytes =MIN (size - offset,BDRV_REQUEST_MAX_SECTORS ); + bytes =MIN (size - offset,BDRV_REQUEST_MAX_BYTES );if (bytes <=0 ) {return 0 ; }
Stefan Hajnoczi
AppliedQuoted 6 lines · Stefan Hajnoczi
The following expression is incorrect because
blk_pread_nonzeroes()deals in units of bytes, not sectors:bytes =
MIN(size - offset, BDRV_REQUEST_MAX_SECTORS)^^^^^^^
Quoted 8 lines
BDRV_REQUEST_MAX_BYTESis the appropriate constant.Fixes a4b15a8b9ef2 ("pflash: Only read non-zero parts of backend image")Cc Xiang Zheng <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/block/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Thanks, applied to my block tree:
https://gitlab.com/stefanha/qemu/commits/block
Stefan
Quoted 20 lines · Stefan Hajnoczi
The following expression is incorrect because
blk_pread_nonzeroes()deals in units of bytes, not sectors:bytes =
MIN(size - offset, BDRV_REQUEST_MAX_SECTORS)^^^^^^^
BDRV_REQUEST_MAX_BYTESis the appropriate constant.Fixes a4b15a8b9ef2 ("pflash: Only read non-zero parts of backend image")Cc Xiang Zheng <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/block/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/block/block.c +0
-0
hw/block/block.c static int blk_pread_nonzeroes(BlockBackend *blk, hwaddr size, void *buf) · line 33
Quoted 5 lines
hw/block/block.c +1
-1@@ -30,7 +30,7 @@ static int blk_pread_nonzeroes(BlockBackend *blk, hwaddr size, void *buf)BlockDriverState *bs =blk_bs (blk);for (;;) { - bytes =MIN (size - offset,BDRV_REQUEST_MAX_SECTORS ); + bytes =MIN (size - offset,BDRV_REQUEST_MAX_BYTES );
Hmm. This smells like a -stable material, but you know better not to Cc: qemu-stable@ for unrelated stuff... Is it not for stable?
Thanks,
/mjt
Quoted 24 lines · Michael Tokarev
Quoted 22 lines · Stefan Hajnoczi
The following expression is incorrect because
blk_pread_nonzeroes()deals in units of bytes, not sectors:bytes =
MIN(size - offset, BDRV_REQUEST_MAX_SECTORS)^^^^^^^
BDRV_REQUEST_MAX_BYTESis the appropriate constant.Fixes a4b15a8b9ef2 ("pflash: Only read non-zero parts of backend image")Cc Xiang Zheng <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/block/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/block/block.c +0
-0@@ -30,7 +30,7 @@ static int blk_pread_nonzeroes(BlockBackend *blk, hwaddr size, void *buf)BlockDriverState *bs =blk_bs (blk);
Quoted 6 lines
hw/block/block.c static int blk_pread_nonzeroes(BlockBackend *blk, hwaddr size, void *buf) · line 33
Quoted 3 lines
hw/block/block.c +1
-1for (;;) { - bytes =MIN (size - offset,BDRV_REQUEST_MAX_SECTORS ); + bytes =MIN (size - offset,BDRV_REQUEST_MAX_BYTES );Hmm. This smells like a -stable material, but you know better not to Cc: qemu-stable@ for unrelated stuff... Is it not for stable?
This is not a user-visible bug. The code still works with the smaller MAX_SECTORS value thanks to the loop.
It doesn't hurt to include it in -stable but I also think it doesn't help :-). It's just an inconsistency in the code.
Stefan
Quoted 11 lines · Stefan Hajnoczi
Quoted 6 lines · Michael Tokarev
hw/block/block.c static int blk_pread_nonzeroes(BlockBackend *blk, hwaddr size, void *buf) · line 33
Quoted 3 lines
for (;;) {hw/block/block.c +1
-1- bytes =MIN (size - offset,BDRV_REQUEST_MAX_SECTORS ); + bytes =MIN (size - offset,BDRV_REQUEST_MAX_BYTES );Hmm. This smells like a -stable material, but you know better not to Cc: qemu-stable@ for unrelated stuff... Is it not for stable?
This is not a user-visible bug. The code still works with the smaller
MAX_SECTORSvalue thanks to the loop.
Yeah, that's my thoughts exactly. Also, most of the time, the cap will be `size' anyway, not MAX. Still thought I'd ask :)
Thank you for the confirmation!
/mjt
Quoted 2 lines
It doesn't hurt to include it in -stable but I also think it doesn't help :-). It's just an inconsistency in the code.