block: Fix regression introduced with prep_writev2 support
cover block: Fix regression introduced with prep_writev2 support
Hi folks,
This is my first contribution to QEMU so please bear with me. :-)
I'm raising this because Kata Containers recently upgraded from QEMU 9 to 10 and it turns out this broke virtio-blk for the project [1].
The issue is that when QEMU introduced support for prep_writev2, it also started enforcing flags be unset when using prep_write. However, this breaks on systems where prep_writev2 isn't present and the prep_write branch is taken (e.g. Ubuntu 22.04 with liburing 2.1 in Kata), as the flags aren't necessarily empty there, and the assertion is violated.
We patched Kata by upgrading liburing [2] but I thought others might benefit from patching QEMU.
[1] https://github.com/kata-containers/kata-containers/issues/11686
[2] https://github.com/kata-containers/kata-containers/pull/11918
Aurélien Bombo (1):
block: Don't regress when prep_writev2 isn't present
block/io_uring.c | 1 - block/linux-aio.c | 1 - 2 files changed, 2 deletions(-)
Signature · 1 line
2.49.1
PATCH 1/1 block: Don't regress when prep_writev2 isn't present
From: Aurélien Bombo <[email protected]>
984a32f17e8d introduced support for prep_writev2 as released in liburing 2.2 and libaio 0.3.111. However, it also broke users of older versions of these libraries (without prep_writev2) who relied on flags being no-op, so we remove the check on flags.
--- block/io_uring.c | 1 - block/linux-aio.c | 1 - 2 files changed, 2 deletions(-)
block/io_uring.c +0 -1
@@ -349,7 +349,6 @@ static int luring_do_submit(int fd, LuringAIOCB *luringcb, LuringState *s, luringcb->qiov->niov, offset, luring_flags); }#else -assert (flags ==0 );io_uring_prep_writev (sqes, fd, luringcb->qiov->iov, luringcb->qiov->niov, offset);#endif
block/linux-aio.c +0 -1
@@ -383,7 +383,6 @@ static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset, io_prep_pwritev2(iocbs, fd, qiov->iov, qiov->niov, offset, laio_flags); }#else -assert (flags ==0 );io_prep_pwritev (iocbs, fd, qiov->iov, qiov->niov, offset);#endif break ;
Signature · 1 line
2.49.1
Re: [PATCH qemu 1/1] block: Don't regress when prep_writev2 isn't present
Am 22.10.2025 um 17:55 hat ~abombo geschrieben:
Quoted 20 lines
From: Aurélien Bombo <[email protected]>
984a32f17e8dintroduced support forprep_writev2as released in liburing 2.2 and libaio 0.3.111. However, it also broke users of older versions of these libraries (withoutprep_writev2) who relied on flags being no-op, so we remove the check on flags.Fixes 984a32f17e8dSigned-off-by Aurélien Bombo <[email protected]>--- block/io_uring.c | 1 - block/linux-aio.c | 1 - 2 files changed, 2 deletions(-)block/io_uring.c +0
-0
block/io_uring.c static int luring_do_submit(int fd, LuringAIOCB *luringcb, LuringState *s, · line 354
Quoted 7 lines
block/io_uring.c +0
-1@@ -349,7 +349,6 @@ static int luring_do_submit(int fd, LuringAIOCB *luringcb, LuringState *s, luringcb->qiov->niov, offset, luring_flags); }#else -assert (flags ==0 );io_uring_prep_writev (sqes, fd, luringcb->qiov->iov, luringcb->qiov->niov, offset);#endif
This doesn't look right to me. We're now silently ignoring the flags, i.e. with BDRV_REQ_FUA the caller believes the data is stable on disk when it really isn't. That's a data corruption bug.
The right question to ask is which flag is set and why it's set when we can't handle it. raw_open_common() has this code:
bs->supported_write_flags = BDRV_REQ_FUA;
if (s->use_linux_aio && !laio_has_fua()) {
bs->supported_write_flags &= ~BDRV_REQ_FUA;
} else if (s->use_linux_io_uring && !luring_has_fua()) {
bs->supported_write_flags &= ~BDRV_REQ_FUA;
}The *_has_fua() functions look like this:
bool luring_has_fua(void)
{
#ifdef HAVE_IO_URING_PREP_WRITEV2
return true;
#else
return false;
#endif
}So with a library version that doesn't support prep_writev2, the expected state is bs->supported_write_flags == 0. This should mean that bdrv_driver_pwritev() clears all flags before calling into file-posix (and therefore Linux AIO or io_uring) code.
Can you please debug where these assumptions break down in your case?
Kevin