Skip to contentSkip to conversation

block/export: improve vu_blk_sect_range_ok()

PATCH Applied Stefan Hajnoczi 3 participants 4 messages Mar 31, 2021 – May 12, 2021 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/export: improve vu_blk_sect_range_ok()

The checks in vu_blk_sect_range_ok() assume VIRTIO_BLK_SECTOR_SIZE is equal to BDRV_SECTOR_SIZE. This is true, but let's add a QEMU_BUILD_BUG_ON() to make it explicit.

We might as well check that the request buffer size is a multiple of VIRTIO_BLK_SECTOR_SIZE while we're at it.

---
 block/export/vhost-user-blk-server.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
block/export/vhost-user-blk-server.c +8 -1
index fa06996d37..1862563336 100644
@@ -70,9 +70,16 @@ static void vu_blk_req_complete(VuBlkReq *req)
 static bool vu_blk_sect_range_ok(VuBlkExport *vexp, uint64_t sector,
                                  size_t size)
 {
-    uint64_t nb_sectors = size >> BDRV_SECTOR_BITS;
+    uint64_t nb_sectors;
     uint64_t total_sectors;
 
+    if (size % VIRTIO_BLK_SECTOR_SIZE) {
+        return false;
+    }
+
+    nb_sectors = size >> VIRTIO_BLK_SECTOR_BITS;
+
+    QEMU_BUILD_BUG_ON(BDRV_SECTOR_SIZE != VIRTIO_BLK_SECTOR_SIZE);
     if (nb_sectors > BDRV_REQUEST_MAX_SECTORS) {
         return false;
     }
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Stefan Hajnoczi

The checks in vu_blk_sect_range_ok() assume VIRTIO_BLK_SECTOR_SIZE is equal to BDRV_SECTOR_SIZE. This is true, but let's add a QEMU_BUILD_BUG_ON() to make it explicit.

Quoted 8 lines

We might as well check that the request buffer size is a multiple of VIRTIO_BLK_SECTOR_SIZE while we're at it.

---
 block/export/vhost-user-blk-server.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#2 lore raw
In reply to Stefan Hajnoczi
Quoted 4 lines · Stefan Hajnoczi

The checks in vu_blk_sect_range_ok() assume VIRTIO_BLK_SECTOR_SIZE is equal to BDRV_SECTOR_SIZE. This is true, but let's add a QEMU_BUILD_BUG_ON() to make it explicit.

Quoted 8 lines

We might as well check that the request buffer size is a multiple of VIRTIO_BLK_SECTOR_SIZE while we're at it.

---
 block/export/vhost-user-blk-server.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Ping for QEMU 6.1.

Stefan

Quoted 26 lines
block/export/vhost-user-blk-server.c +8 -1
index fa06996d37..1862563336 100644
@@ -70,9 +70,16 @@ static void vu_blk_req_complete(VuBlkReq *req)
 static bool vu_blk_sect_range_ok(VuBlkExport *vexp, uint64_t sector,
                                  size_t size)
 {
-    uint64_t nb_sectors = size >> BDRV_SECTOR_BITS;
+    uint64_t nb_sectors;
     uint64_t total_sectors;
 
+    if (size % VIRTIO_BLK_SECTOR_SIZE) {
+        return false;
+    }
+
+    nb_sectors = size >> VIRTIO_BLK_SECTOR_BITS;
+
+    QEMU_BUILD_BUG_ON(BDRV_SECTOR_SIZE != VIRTIO_BLK_SECTOR_SIZE);
     if (nb_sectors > BDRV_REQUEST_MAX_SECTORS) {
         return false;
     }
Signature · 1 line
2.30.2
Applied
#3 lore raw

Am 11.05.2021 um 10:25 hat Stefan Hajnoczi geschrieben:

Quoted 8 lines · Stefan Hajnoczi
Quoted 7 lines

The checks in vu_blk_sect_range_ok() assume VIRTIO_BLK_SECTOR_SIZE is equal to BDRV_SECTOR_SIZE. This is true, but let's add a QEMU_BUILD_BUG_ON() to make it explicit.

We might as well check that the request buffer size is a multiple of VIRTIO_BLK_SECTOR_SIZE while we're at it.

Quoted 7 lines
Quoted 5 lines
---
 block/export/vhost-user-blk-server.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Ping for QEMU 6.1.

Thanks, applied to the block branch.

Kevin