Skip to content

virtio_blk: Use write through mode without negotiated FLUSH - #5153

Open
Anatol Belski (weltling) wants to merge 4 commits into
microsoft:mainfrom
weltling:virtio-blk-flush-durability
Open

Anatol Belski (weltling) wants to merge 4 commits into
microsoft:mainfrom
weltling:virtio-blk-flush-durability

Conversation

@weltling

Copy link
Copy Markdown
Member

The device currently offers FLUSH but not CONFIG_WCE. If the guest does not negotiate FLUSH, completed writes must be durable. Previously, writes could complete while their data remained in volatile cache.

Select the write cache policy at queue startup. When FLUSH is not negotiated, request FUA if the backend supports it. For other backends, wait for a cache flush before completing the write. Preserve writeback mode when FLUSH is negotiated.

Add tests for cache policy selection and completion ordering. Verify that write and flush errors are reported to the guest.

@weltling
Anatol Belski (weltling) requested a review from a team as a code owner November 19, 2026 13:06
Copilot AI balanced review requested due to automatic review settings November 19, 2026 13:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The SQLite fallback can acknowledge writes that are not durable because sync_cache drops its transaction without committing it before switching to synchronous=NORMAL.

1 open issue
What changed in this PR

This PR updates virtio-blk to select write-through mode when the guest does not negotiate FLUSH, while preserving writeback mode when FLUSH is negotiated.

Changes:

  • Select the cache policy at queue startup.
  • Request Force Unit Access (FUA) when supported; otherwise flush the backend cache before completing writes.
  • Add tests for policy selection, completion ordering, and write and flush error reporting.
File Description
vm/​devices/​virtio/​virtio_blk/​src/​lib.rs Selects and applies the negotiated cache policy to write requests.
vm/​devices/​virtio/​virtio_blk/​src/​integration_tests.rs Tests cache policy combinations, flush ordering, and error propagation.

Review effort: Balanced

Comment thread vm/devices/virtio/virtio_blk/src/lib.rs Resolved
@weltling
Anatol Belski (weltling) requested a review from a team as a code owner November 19, 2026 13:59
Copilot AI balanced review requested due to automatic review settings November 19, 2026 13:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A failed flush leaves SQLite in FULL synchronous mode, causing subsequent writeback transactions to sync until another flush succeeds.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 19, 2026 14:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The tests do not verify that flush commits run with synchronous=FULL, so a missing mode switch could leave data unsynced without failing either test.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 19, 2026 15:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Restoring SQLite’s FULL mode can force a WAL sync on every write, and the tests do not verify that flush waits for pending non-FUA writes.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread vm/devices/virtio/virtio_blk/src/lib.rs Resolved
Copilot AI balanced review requested due to automatic review settings November 19, 2026 16:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

SQLite-backed NVMe and IDE disks can acknowledge FUA writes without a WAL sync in NORMAL mode, risking loss of data reported as durable after a host power failure.

1 open issue
2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 19, 2026 17:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Globally enabling SQLite NORMAL can cause acknowledged write-through SCSI and IDE writes to be lost on host power failure.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 19, 2026 17:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Non-FUA writes can suffer a substantial throughput regression, and guest flushes can fail when the SQLite log cannot grow even if prior writes are already durable.

2 open issues
1 resolved since last review

Review effort: Balanced

@weltling

Copy link
Copy Markdown
Member Author

🟡 Changes recommended

Non-FUA writes can suffer a substantial throughput regression, and guest flushes can fail when the SQLite log cannot grow even if prior writes are already durable.
2 open issues

* <img alt="Medium severity" width="62" height="18" src="https://camo.githubusercontent.com/7dc8929f1372d7be218d83fe61e6c3fb67ed8bc61cd50c1e8e4696827da90595/68747470733a2f2f6769746875622e6769746875626173736574732e636f6d2f7374617469632f696d616765732f69636f6e732f636f70696c6f742d636f64652d7265766965772f6d656469756d2d76322d6c696768742e706e67"> [Flush negotiation forces synchronization on every non-FUA write](https://github.com/microsoft/openvmm/pull/5153#discussion_r4633050791) · New

* <img alt="Medium severity" width="62" height="18" src="https://camo.githubusercontent.com/7dc8929f1372d7be218d83fe61e6c3fb67ed8bc61cd50c1e8e4696827da90595/68747470733a2f2f6769746875622e6769746875626173736574732e636f6d2f7374617469632f696d616765732f69636f6e732f636f70696c6f742d636f64652d7265766965772f6d656469756d2d76322d6c696768742e706e67"> [Redundant flush transaction can fail when the SQLite log is full](https://github.com/microsoft/openvmm/pull/5153#discussion_r4633050866) · New

1 resolved since last review

Review effort: Balanced

These observation seem correct but go far out of scope of this PR which only targets virtio-blk.

Thanks

Copilot AI balanced review requested due to automatic review settings November 20, 2026 22:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

On macOS, the advertised FUA support may acknowledge writes without flushing the drive’s volatile cache, risking data loss on power failure.

1 open issue
2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 21, 2026 12:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The negotiated-FLUSH test does not assert a successful status, so it can pass even if the request reports an error or leaves the status byte unchanged.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 21, 2026 13:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Cross-platform FUA and flush durability, including macOS SQLite behavior, requires platform-specific and power-loss validation that hook-based tests cannot provide.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Comment thread vm/devices/virtio/virtio_blk/src/lib.rs Outdated
VIRTIO_BLK_T_IN => {
let disk_sector = virtio_to_disk_sector(header.sector, sector_shift, sector_mask)?;
let (bytes, bounced) = do_io(disk, mem, work, disk_sector, true).await?;
let (bytes, bounced) = do_io(disk, mem, work, disk_sector, true, false).await?;

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.

Let's avoid functions with multiple bool parameters--it's impossible to tell what's going on in the caller.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Rewrote to keep the original do_io signature. A new shared helper uses an enum to distinquish read, write back and write through.

Thanks

@jstarks

Copy link
Copy Markdown
Member

Let's not take the sqlite changes. This is a test-only backend and I don't see a need to change the FUA or flush behavior in this PR.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 16:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The helper interfaces use adjacent positional booleans for write permission and cache mode, creating ambiguity that should be resolved with a descriptive cache-policy enum.

1 open issue

Review effort: Balanced

Comment thread vm/devices/virtio/virtio_blk/src/lib.rs Resolved
Select the write cache policy from the negotiated FLUSH feature.
Require durable writes when FLUSH is not negotiated.

Use FUA when the backend supports it. Otherwise, wait for a cache
flush before completing the request.

Use writeback mode when FLUSH is negotiated.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
Add a queue setup helper that accepts the negotiated features.

Test writes with and without negotiated FLUSH. Test backends with
and without FUA support.

Verify that explicit flush requests reach the backend and report
success to the guest.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
Hold the backend write pending when FLUSH is not negotiated. Verify
that the cache flush does not start before the write completes.
Then delay the cache flush and verify that the status byte and used
ring remain unchanged while the flush is pending.

Test completed flushes and flush errors. Verify that a flush error
is reported to the guest as an I/O error.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
Return a backend error for a FUA write when FLUSH is not negotiated.
Verify that the guest receives an I/O error instead of success.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 17:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the virtio-blk write-durability change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@weltling

Copy link
Copy Markdown
Member Author

Let's not take the sqlite changes. This is a test-only backend and I don't see a need to change the FUA or flush behavior in this PR.

Removed the sqlite part as suggested.

Thanks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants