Thanks to visit codestin.com
Credit goes to github.com

Skip to content

block: Implement write_zeroes and punch_hole for AIO backend - #7817

Merged
rbradford merged 1 commit into
cloud-hypervisor:mainfrom
emirb:fix/aio-write-zeroes
Mar 12, 2026
Merged

rbradford merged 1 commit into
cloud-hypervisor:mainfrom
emirb:fix/aio-write-zeroes

Conversation

@emirb

@emirb emirb commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Trying out an upgrade from v50 to v51 and found out what seems to be regression, affecting everyone on RHEL 9 or everyone with io_uring disabled.

In v50 and earlier,VIRTIO_BLK_F_WRITE_ZEROES was not advertised, so guests never issued these requests. v51 added the feature (#7666) with implementations for the io_uring and sync backends, but left the AIO backend as error stubs.

The AIO block backend advertises VIRTIO_BLK_F_WRITE_ZEROES and VIRTIO_BLK_F_DISCARD to guests because RawFileDiskAio::supports_sparse_operations() probes the filesystem via fallocate() and returns true on ext4/XFS. However, RawFileAsyncAio::write_zeroes() and punch_hole() return errors because Linux AIO (io_submit) has no IOCB command for fallocate.

When io_uring is unavailable (e.g., kernel.io_uring_disabled=2, a common security hardening on enterprise Linux), Cloud Hypervisor falls back to the AIO backend. The guest negotiates the feature, issues WRITE_ZEROES requests, and gets I/O errors:

Guest dmesg:

2026-03-10 12:44:17.974009 [    0.334874] I/O error, dev vda, sector 9680 op 0x9:(WRITE_ZEROES) flags 0x800 phys_seg 0 prio class 2
2026-03-10 12:44:17.975411 [    0.346469] I/O error, dev vdb, sector 8792 op 0x9:(WRITE_ZEROES) flags 0x800 phys_seg 0 prio class 2

Cloud Hypervisor log:

2026-03-10 12:44:18.011007 cloud-hypervisor:   1.812897s: <_disk0_q1> WARN:virtio-devices/src/block.rs:291 -- Request failed: Request { request_type: WriteZeroes, sector: 0, data_descriptors: [(GuestAddress(100939080), 10)], status_addr: GuestAddress(101bf0d08), writeback: true, aligned_operations: [AlignedOperation { origin_ptr: 7fe12c939080, aligned_ptr: 7fe128c6a600, size: 10, layout: Layout { size: 10, align: 512 (1 << 9) } }], start: Instant { tv_sec: 30ae7, tv_nsec: 39cce969 } } AsyncWriteZeroes(WriteZeroes(Custom { kind: Other, error: "write_zeroes not supported with AIO backend" }))
2026-03-10 12:44:18.012650 cloud-hypervisor:   1.824487s: <_disk1_q1> WARN:virtio-devices/src/block.rs:291 -- Request failed: Request { request_type: WriteZeroes, sector: 0, data_descriptors: [(GuestAddress(100939080), 10)], status_addr: GuestAddress(101cd2808), writeback: true, aligned_operations: [AlignedOperation { origin_ptr: 7fe12c939080, aligned_ptr: 7fe128c6a400, size: 10, layout: Layout { size: 10, align: 512 (1 << 9) } }], start: Instant { tv_sec: 30ae7, tv_nsec: 3a7dc209 } } AsyncWriteZeroes(WriteZeroes(Custom { kind: Other, error: "write_zeroes not supported with AIO backend" }))
2026-03-10 12:44:18.014236 cloud-hypervisor:   6.354193s: <_disk3_q1> WARN:virtio-devices/src/block.rs:291 -- Request failed: Request { request_type: WriteZeroes, sector: 0, data_descriptors: [(GuestAddress(1009390a0), 10)], status_addr: GuestAddress(101e1e808), writeback: true, aligned_operations: [AlignedOperation { origin_ptr: 7fe12c9390a0, aligned_ptr: 7fe128c6b400, size: 10, layout: Layout { size: 10, align: 512 (1 << 9) } }], start: Instant { tv_sec: 30aec, tv_nsec: 1e75a364 } } AsyncWriteZeroes(WriteZeroes(Custom { kind: Other, error: "write_zeroes not supported with AIO backend" }))

Tested on a host with XFS (with 4 raw disk images, long stroy...) and kernel io_uring_disabled=2 (disabled by default in Centos Stream 9)

After this patch, all WRITE_ZEROES I/O errors are eliminated and the VM boots cleanly. (tested after compiling the patch, on the same host)

The fix implements write_zeroes and punch_hole using synchronous libc::fallocate() calls, matching the pattern used by the sync backend (RawFileSync). Linux AIO has no IOCB command for fallocate, so the operations execute synchronously and completions are signaled via a VecDeque-based completion list and the existing eventfd mechanism, identical to how RawFileSync handles these operations.

@emirb
emirb requested a review from a team as a code owner March 10, 2026 12:30
@phip1611

Copy link
Copy Markdown
Member

Thanks for your contribution! @weltling could you support with with review please?

The AIO block backend advertises VIRTIO_BLK_F_WRITE_ZEROES
and VIRTIO_BLK_F_DISCARD to guests because the filesystem
probe (supports_sparse_operations) returns true on ext4/XFS.
However, RawFileAsyncAio::write_zeroes() and punch_hole()
return errors because Linux AIO (io_submit) has no IOCB
command for fallocate.

When io_uring is unavailable (e.g. io_uring_disabled=2, a
common security hardening on enterprise Linux), Cloud
Hypervisor falls back to the AIO backend. The guest
negotiates the feature, issues WRITE_ZEROES requests, and
gets I/O errors.

Implement write_zeroes and punch_hole using synchronous
libc::fallocate() calls, matching the pattern used by the
sync backend (RawFileSync). A VecDeque-based completion
list signals results to the caller via the existing eventfd
mechanism.

Unit tests mirror the existing raw_sync.rs test suite.
Integration tests add AIO-specific variants of the discard
and fstrim tests using _disable_io_uring=on.

Signed-off-by: Emir Beganovic <[email protected]>
@emirb
emirb force-pushed the fix/aio-write-zeroes branch from a202215 to 5db7962 Compare March 10, 2026 19:06

@rbradford rbradford left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me but i'll rubberstamp based on @weltling

@weltling weltling left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach is fine - it's correct, simple, extends tests and matches the sync backend. Also it's the exact drop-in implementation that was meant to be filled one day, which turns out to be today :)

About the tests:

  • The unit tests seem to be a verbatim copy from raw_sync.rs with only diff in the constructor. That's not ideal but I'd say it's ok as the tests themselves aren't wrong. Probably next step would be to factor them out into a shared test helper.
  • A test for mixed AIO and sync completions would seem to be useful specifically for this patch, as VecDeque is the required pattern in this implementation.

Thanks

@rbradford
rbradford added this pull request to the merge queue Mar 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Mar 11, 2026
@liuw
liuw added this pull request to the merge queue Mar 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 11, 2026
@rbradford
rbradford added this pull request to the merge queue Mar 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Mar 11, 2026
@rbradford
rbradford added this pull request to the merge queue Mar 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Mar 11, 2026

@likebreath likebreath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good feature gap to close. Thank you.

@likebreath
likebreath added this pull request to the merge queue Mar 11, 2026
@github-project-automation github-project-automation Bot moved this from 🆕 New to 📋 Backlog in Cloud Hypervisor Roadmap Mar 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 11, 2026
@rbradford
rbradford added this pull request to the merge queue Mar 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Mar 12, 2026
@rbradford
rbradford added this pull request to the merge queue Mar 12, 2026
Merged via the queue into cloud-hypervisor:main with commit 623af62 Mar 12, 2026
37 checks passed
@github-project-automation github-project-automation Bot moved this from 📋 Backlog to ✅ Done in Cloud Hypervisor Roadmap Mar 12, 2026
@emirb
emirb deleted the fix/aio-write-zeroes branch March 13, 2026 06:53
@saravan2

saravan2 commented Apr 8, 2026

Copy link
Copy Markdown
Member

Encountered this scary regression on Rocky Linux Host where io_uring is disabled.

Since v51.1 still contains the bug, are there any plans to cut a v51.2 patch release in the near future ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

6 participants