qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] blkio: Respect memory-alignment for bounce buffer allocations
@ 2024-01-31 17:31 Kevin Wolf
  2024-01-31 17:45 ` Stefano Garzarella
  2024-01-31 20:07 ` Stefan Hajnoczi
  0 siblings, 2 replies; 3+ messages in thread
From: Kevin Wolf @ 2024-01-31 17:31 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, stefanha, sgarzare, qemu-devel

blkio_alloc_mem_region() requires that the requested buffer size is a
multiple of the memory-alignment property. If it isn't, the allocation
fails with a return value of -EINVAL.

Fix the call in blkio_resize_bounce_pool() to make sure the requested
size is properly aligned.

I observed this problem with vhost-vdpa, which requires page aligned
memory. As the virtio-blk device behind it still had 512 byte blocks, we
got bs->bl.request_alignment = 512, but actually any request that needed
a bounce buffer and was not aligned to 4k would fail without this fix.

Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/blkio.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/block/blkio.c b/block/blkio.c
index 0a0a6c0f5f..b989617608 100644
--- a/block/blkio.c
+++ b/block/blkio.c
@@ -89,6 +89,9 @@ static int blkio_resize_bounce_pool(BDRVBlkioState *s, int64_t bytes)
     /* Pad size to reduce frequency of resize calls */
     bytes += 128 * 1024;
 
+    /* Align the pool size to avoid blkio_alloc_mem_region() failure */
+    bytes = QEMU_ALIGN_UP(bytes, s->mem_region_alignment);
+
     WITH_QEMU_LOCK_GUARD(&s->blkio_lock) {
         int ret;
 
-- 
2.43.0



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

* Re: [PATCH] blkio: Respect memory-alignment for bounce buffer allocations
  2024-01-31 17:31 [PATCH] blkio: Respect memory-alignment for bounce buffer allocations Kevin Wolf
@ 2024-01-31 17:45 ` Stefano Garzarella
  2024-01-31 20:07 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Stefano Garzarella @ 2024-01-31 17:45 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-block, stefanha, qemu-devel

On Wed, Jan 31, 2024 at 06:31:40PM +0100, Kevin Wolf wrote:
>blkio_alloc_mem_region() requires that the requested buffer size is a
>multiple of the memory-alignment property. If it isn't, the allocation
>fails with a return value of -EINVAL.
>
>Fix the call in blkio_resize_bounce_pool() to make sure the requested
>size is properly aligned.
>
>I observed this problem with vhost-vdpa, which requires page aligned
>memory. As the virtio-blk device behind it still had 512 byte blocks, we
>got bs->bl.request_alignment = 512, but actually any request that needed
>a bounce buffer and was not aligned to 4k would fail without this fix.
>
>Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
>---
> block/blkio.c | 3 +++
> 1 file changed, 3 insertions(+)

Thanks for fixinig this!

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

>
>diff --git a/block/blkio.c b/block/blkio.c
>index 0a0a6c0f5f..b989617608 100644
>--- a/block/blkio.c
>+++ b/block/blkio.c
>@@ -89,6 +89,9 @@ static int blkio_resize_bounce_pool(BDRVBlkioState *s, int64_t bytes)
>     /* Pad size to reduce frequency of resize calls */
>     bytes += 128 * 1024;
>
>+    /* Align the pool size to avoid blkio_alloc_mem_region() failure */
>+    bytes = QEMU_ALIGN_UP(bytes, s->mem_region_alignment);
>+
>     WITH_QEMU_LOCK_GUARD(&s->blkio_lock) {
>         int ret;
>
>-- 
>2.43.0
>



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

* Re: [PATCH] blkio: Respect memory-alignment for bounce buffer allocations
  2024-01-31 17:31 [PATCH] blkio: Respect memory-alignment for bounce buffer allocations Kevin Wolf
  2024-01-31 17:45 ` Stefano Garzarella
@ 2024-01-31 20:07 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2024-01-31 20:07 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-block, sgarzare, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 890 bytes --]

On Wed, Jan 31, 2024 at 06:31:40PM +0100, Kevin Wolf wrote:
> blkio_alloc_mem_region() requires that the requested buffer size is a
> multiple of the memory-alignment property. If it isn't, the allocation
> fails with a return value of -EINVAL.
> 
> Fix the call in blkio_resize_bounce_pool() to make sure the requested
> size is properly aligned.
> 
> I observed this problem with vhost-vdpa, which requires page aligned
> memory. As the virtio-blk device behind it still had 512 byte blocks, we
> got bs->bl.request_alignment = 512, but actually any request that needed
> a bounce buffer and was not aligned to 4k would fail without this fix.
> 
> Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block/blkio.c | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-31 17:31 [PATCH] blkio: Respect memory-alignment for bounce buffer allocations Kevin Wolf
2024-01-31 17:45 ` Stefano Garzarella
2024-01-31 20:07 ` Stefan Hajnoczi

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).