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

Skip to content

virtio-devices: Signal NEEDS_RESET - #8295

Merged
rbradford merged 4 commits into
cloud-hypervisor:mainfrom
weltling:virtio-activate-failure
Jun 2, 2026
Merged

rbradford merged 4 commits into
cloud-hypervisor:mainfrom
weltling:virtio-activate-failure

Conversation

@weltling

@weltling weltling commented May 29, 2026

Copy link
Copy Markdown
Member

When a virtio device fails to activate after the guest writes DRIVER_OK, the VMM bubbles the error up and never releases the activation barrier. The vCPU stays blocked and the guest deadlocks.

The fix is to signal DEVICE_NEEDS_RESET, deliver a config change interrupt, and release the activation barrier so the guest can recover.

@weltling
weltling requested a review from a team as a code owner May 29, 2026 14:01
Comment thread virtio-devices/src/block.rs Outdated
return Err(e);
}

self.common.epoll_threads = Some(epoll_threads);

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 abort_partial_activate() feels a bit messy. The thing it does is assign the threads to the common and then call .reset()

If you checked the activate error here then you could just straight up call .reset() as the partial set of threads would have been assigned to the common?

Alternatively maybe we should do some refactoring and move spawn_virtio_thread to be a method on VirtioCommon and have it clean itself up (also we could remove this assignment from every device.

Could you look at a refactoring like that?

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.

I'm looking at that refactoring - and it looks like it would be a nice cleanup - watch this space - 👀

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.

@rbradford rebased and ready for the next round.

@weltling
weltling force-pushed the virtio-activate-failure branch from d4b2f14 to c01b4bc Compare June 1, 2026 16:57
@weltling weltling changed the title virtio-devices: Signal NEEDS_RESET and join workers on activation failure virtio-devices: Signal NEEDS_RESET Jun 1, 2026

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

I notice this doesn't need touch all the devices - that's a nice cleanup!

format_args!("{}: virtio device activation failed: {e:?}", self.id),
);
} else {
self.device_activated.store(true, Ordering::SeqCst);

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.

nit: I know you are just reordering existing code but I think this should be Release and not SeqCst

https://doc.rust-lang.org/std/sync/atomic/enum.Ordering.html#variant.Release

No need to change it here, but I wanted to mention that I used to think of SeqCst as a safe fallback as well. After many fruitful discussions about this, I now think that treating it that way is actually an antipattern. @olivereanderson

Comment thread vmm/src/device_manager.rs
Comment thread vmm/src/device_manager.rs
for activator in self.pending_activations.lock().unwrap().drain(..) {
activator
.activate()
.map_err(DeviceManagerError::VirtioActivate)?;

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.

Does this make VirtioActivate an unused error type?

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.

Indeed, good catch. Folded the removal into the first commit.

Thanks

weltling added 4 commits June 1, 2026 21:20
When the guest writes DRIVER_OK and the device fails to activate, the
VMM previously bubbled the error up via VirtioActivate and never
released the activation barrier, leaving the vCPU that wrote DRIVER_OK
blocked on the barrier and effectively deadlocking the guest.

Per virtio 1.3 section 2.1.2, a device that has experienced an error
it cannot recover from should set DEVICE_NEEDS_RESET in its status and
notify the driver via a configuration change interrupt. Do that on
activation failure through the existing mark_device_needs_reset
helper, then release the activation barrier so the vCPU can resume.

DeviceManager::activate_virtio_devices now logs and continues instead
of aborting the whole pending list, so one failing device does not
take down the VMM or block pause and migration. The activator has
already reported the failure with the device id.

Signed-off-by: Anatol Belski <[email protected]>
Add TestVirtioDevice with a controllable ActivateResult,
TestVirtioInterrupt that records delivered interrupt types, and a
make_activator helper that builds a complete VirtioPciDeviceActivator
with observable status, activated flag, interrupt log, and barrier.

Assisted-by: Claude:Opus-4.7
Signed-off-by: Anatol Belski <[email protected]>
Feed BadActivate into VirtioPciDeviceActivator and assert that the
error propagates, device_activated stays false, DEVICE_NEEDS_RESET is
set in status, a single Config interrupt is delivered, and a thread
waiting on the activation barrier unblocks. The barrier release is
the deadlock fixed by the NEEDS_RESET on activation failure change.

Assisted-by: Claude:Opus-4.7
Signed-off-by: Anatol Belski <[email protected]>
Feed Ok into VirtioPciDeviceActivator and assert that activate returns
Ok, device_activated becomes true, DEVICE_NEEDS_RESET is not set,
status is otherwise unchanged, no Config interrupt is delivered, and
the barrier waiter unblocks normally.

Assisted-by: Claude:Opus-4.7
Signed-off-by: Anatol Belski <[email protected]>
@weltling
weltling force-pushed the virtio-activate-failure branch from c01b4bc to 928ac67 Compare June 1, 2026 19:24
@rbradford
rbradford added this pull request to the merge queue Jun 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jun 2, 2026
@weltling

weltling commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

This CI failure in the VFIO tests looks unrelated. The host log shows the single _disk0 activation completing cleanly, with the barrier released and no NEEDS_RESET:

virtio-devices/src/transport/pci_device.rs:356 -- _virtio-pci-_disk0: Barrier released
vmm/src/vm.rs:484 -- Barrier released

The failure is the guest NVIDIA driver bailing with NV_ERR_NOT_SUPPORTED:

NVRM: GPU 0000:00:06.0: RmInitAdapter failed! (0x62:0xffff:2468)

which seems a BAR mapping flake.

Thanks

@rbradford
rbradford merged commit a89600a into cloud-hypervisor:main Jun 2, 2026
41 checks passed
@rbradford

Copy link
Copy Markdown
Member

It wasn't kicked out of the MQ because VFIO - I don't really understand why it got kicked out at all.

@weltling
weltling deleted the virtio-activate-failure branch June 2, 2026 13:53
@github-project-automation github-project-automation Bot moved this from 🆕 New to ✅ Done in Cloud Hypervisor Roadmap Jul 8, 2026
@rbradford rbradford added the bug-fix Bug fix to include in release notes label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix Bug fix to include in release notes

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

4 participants