mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
virtio-devices: Simplify interrupt handling
Previously the interrupt was created in VirtioPciDevice, moved via the Option::take() to the VirtioPciDeviceActivator and then moved to the VirtioDevice upon activation. On reset it would be moved back ready for reactivation. Since this already an Arc type remove the wrapping Option and instead refcount it such that the VirtioPciDevice can continue to hold onto it for later activations. This significantly simplifies the reset() logic as there is no need to hand back the interrupt. A few devices used whether the interrupt was Some to make triggering an interrupt a no-op. However the MSI-X interrupt routing already drops the interrupt if the driver hasn't yet configured the vector so it is safe to trigger the interrupt before device activation (e.g. balloon resize request before driver loaded). VirtioCommon still retains an Option<..> for the interrupt as the interrupt is not known until activation time (after this has been created). A helper VirtioCommon::trigger_interrupt() has been added to handle this. Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
@@ -443,14 +443,13 @@ impl VirtioDevice for Vdpa {
|
||||
self.activate_vdpa(&mem.memory(), virtio_interrupt.as_ref(), &queues)
|
||||
.map_err(ActivateError::ActivateVdpa)?;
|
||||
|
||||
// Store the virtio interrupt handler as we need to return it on reset
|
||||
self.common.interrupt_cb = Some(virtio_interrupt);
|
||||
|
||||
event!("vdpa", "activated", "id", &self.id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
|
||||
fn reset(&mut self) {
|
||||
// Backend reset failures are logged but don't skip local cleanup:
|
||||
// reset must converge to fresh state regardless of backend state.
|
||||
if let Err(e) = self.reset_vdpa() {
|
||||
@@ -459,8 +458,8 @@ impl VirtioDevice for Vdpa {
|
||||
|
||||
event!("vdpa", "reset", "id", &self.id);
|
||||
|
||||
// Return the virtio interrupt handler
|
||||
self.common.interrupt_cb.take()
|
||||
// Drop the interrupt callback clone
|
||||
self.common.interrupt_cb = None;
|
||||
}
|
||||
|
||||
fn set_access_platform(&mut self, access_platform: Arc<dyn AccessPlatform>) {
|
||||
|
||||
Reference in New Issue
Block a user