* [PATCH] block/export: improve vu_blk_sect_range_ok()
@ 2021-03-31 14:27 Stefan Hajnoczi
2021-03-31 20:27 ` Eric Blake
2021-05-11 8:25 ` Stefan Hajnoczi
0 siblings, 2 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2021-03-31 14:27 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Coiby Xu, qemu-block, Max Reitz
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.
Suggested-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block/export/vhost-user-blk-server.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c
index fa06996d37..1862563336 100644
--- a/block/export/vhost-user-blk-server.c
+++ b/block/export/vhost-user-blk-server.c
@@ -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;
}
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] block/export: improve vu_blk_sect_range_ok()
2021-03-31 14:27 [PATCH] block/export: improve vu_blk_sect_range_ok() Stefan Hajnoczi
@ 2021-03-31 20:27 ` Eric Blake
2021-05-11 8:25 ` Stefan Hajnoczi
1 sibling, 0 replies; 4+ messages in thread
From: Eric Blake @ 2021-03-31 20:27 UTC (permalink / raw)
To: Stefan Hajnoczi, qemu-devel; +Cc: Kevin Wolf, qemu-block, Coiby Xu, Max Reitz
On 3/31/21 9:27 AM, Stefan Hajnoczi wrote:
> 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.
>
> Suggested-by: Max Reitz <mreitz@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> block/export/vhost-user-blk-server.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] block/export: improve vu_blk_sect_range_ok()
2021-03-31 14:27 [PATCH] block/export: improve vu_blk_sect_range_ok() Stefan Hajnoczi
2021-03-31 20:27 ` Eric Blake
@ 2021-05-11 8:25 ` Stefan Hajnoczi
2021-05-12 14:41 ` Kevin Wolf
1 sibling, 1 reply; 4+ messages in thread
From: Stefan Hajnoczi @ 2021-05-11 8:25 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Coiby Xu, qemu-block, Max Reitz
[-- Attachment #1: Type: text/plain, Size: 1490 bytes --]
On Wed, Mar 31, 2021 at 03:27:27PM +0100, Stefan Hajnoczi wrote:
> 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.
>
> Suggested-by: Max Reitz <mreitz@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> block/export/vhost-user-blk-server.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
Ping for QEMU 6.1.
Stefan
>
> diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c
> index fa06996d37..1862563336 100644
> --- a/block/export/vhost-user-blk-server.c
> +++ b/block/export/vhost-user-blk-server.c
> @@ -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;
> }
> --
> 2.30.2
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] block/export: improve vu_blk_sect_range_ok()
2021-05-11 8:25 ` Stefan Hajnoczi
@ 2021-05-12 14:41 ` Kevin Wolf
0 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2021-05-12 14:41 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: Coiby Xu, qemu-devel, qemu-block, Max Reitz
[-- Attachment #1: Type: text/plain, Size: 742 bytes --]
Am 11.05.2021 um 10:25 hat Stefan Hajnoczi geschrieben:
> On Wed, Mar 31, 2021 at 03:27:27PM +0100, Stefan Hajnoczi wrote:
> > 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.
> >
> > Suggested-by: Max Reitz <mreitz@redhat.com>
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> > ---
> > 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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-05-12 14:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-31 14:27 [PATCH] block/export: improve vu_blk_sect_range_ok() Stefan Hajnoczi
2021-03-31 20:27 ` Eric Blake
2021-05-11 8:25 ` Stefan Hajnoczi
2021-05-12 14:41 ` Kevin Wolf
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).