Skip to contentSkip to conversation

pflash: fix sectors vs bytes confusion in blk_pread_nonzeroes()

PATCH Applied Stefan Hajnoczi 4 participants 6 messages Jan 30, 2024 – Feb 9, 2024

lore
Share & tools
lore
#0 lore raw

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.

Fixes a4b15a8b9ef2 ("pflash: Only read non-zero parts of backend image")
Cc Xiang Zheng <[email protected]>
---
 hw/block/block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/block.c +1 -1
index 9f52ee6e72..ff503002aa 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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_BYTES is the appropriate constant.

Fixes a4b15a8b9ef2 ("pflash: Only read non-zero parts of backend image")
Cc Xiang Zheng <[email protected]>
---
  hw/block/block.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/block.c +0 -0
index 9f52ee6e72..ff503002aa 100644

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;
          }
author Applied
#2 lore raw
In reply to Stefan Hajnoczi
Quoted 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_BYTES is the appropriate constant.

Fixes a4b15a8b9ef2 ("pflash: Only read non-zero parts of backend image")
Cc Xiang Zheng <[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

#3 lore raw
In reply to Stefan Hajnoczi
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_BYTES is the appropriate constant.

Fixes a4b15a8b9ef2 ("pflash: Only read non-zero parts of backend image")
Cc Xiang Zheng <[email protected]>
---
  hw/block/block.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/block.c +0 -0
index 9f52ee6e72..ff503002aa 100644

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

#4 lore raw
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_BYTES is the appropriate constant.

Fixes a4b15a8b9ef2 ("pflash: Only read non-zero parts of backend image")
Cc Xiang Zheng <[email protected]>
---
  hw/block/block.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/block.c +0 -0
index 9f52ee6e72..ff503002aa 100644
@@ -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 -1
      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?

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

#5 lore raw
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_SECTORS value 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.