Comment 0 for bug 2025591

Revision history for this message
Chengen Du (chengendu) wrote : Align the iov length to the logical block size

[Impact]
When the logical block size of the virtual block device is smaller than the block device it is backed by on the host,
qemu encounters a situation where it needs to bounce unaligned buffers during the use of direct IO.
In the past, the logical block size happened to align with the memory page offset, leading qemu to mistakenly use the memory offset as the block size.
However, a kernel commit b1a000d3b8ec resolved this issue by separating memory alignment from the logical block size.
As a result, qemu now has an incorrect understanding of the minimum vector size.

[Fix]
Upstream commit 25474d90aa50 fixed this issue.
==========
Author: Keith Busch <email address hidden>
CommitDate: Fri Sep 30 18:43:44 2022 +0200

    block: use the request length for iov alignment

    An iov length needs to be aligned to the logical block size, which may
    be larger than the memory alignment.

    Tested-by: Jens Axboe <email address hidden>
    Signed-off-by: Keith Busch <email address hidden>
    Message-Id: <email address hidden>
    Reviewed-by: Kevin Wolf <email address hidden>
    Signed-off-by: Kevin Wolf <email address hidden>
==========

[Test Plan]
1. Get a ubuntu image and convert it to RAW format
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64-disk-kvm.img
qemu-img convert jammy-server-cloudimg-amd64-disk-kvm.img jammy-server-cloudimg-amd64-disk-kvm.raw
2. Set up a loop device with RAW image
losetup -b 4096 -f jammy-server-cloudimg-amd64-disk-kvm.raw
3. Get loop device number by `losetup -a` command
4. Start the virtual machine
qemu-system-x86_64 -enable-kvm -drive file=/dev/loopX,format=raw,cache=none --nographic

[Where problems could occur]
The patch addressed the issue of misusing the memory offset as the block size.
This problem only occurred when the cache option was set to "none" and the Linux kernel being used had the commit b1a000d3b8ec.
However, it is worth noting that the patch also worked effectively with older kernels.

[Other Info]