virtio-devices: Add feature acked gated accessor for AccessPlatform

Add VirtioCommon::access_platform() method. The virtio spec requires
that only if the feature is acked should the accesses be transformed via
the access platform implementation. This will enable that filtering.

Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
Rob Bradford
2026-04-17 08:51:28 +01:00
parent e38f00644d
commit ea64d109c7

View File

@@ -16,6 +16,7 @@ use std::thread;
use anyhow::anyhow;
use libc::EFD_NONBLOCK;
use log::{error, info, warn};
use virtio_bindings::virtio_config::VIRTIO_F_ACCESS_PLATFORM;
use virtio_queue::Queue;
use vm_device::UserspaceMapping;
use vm_memory::{GuestAddress, GuestMemoryAtomic};
@@ -332,6 +333,15 @@ impl VirtioCommon {
// requires the addresses held by the descriptors to be translated.
self.avail_features &= !(1 << VIRTIO_F_RING_INDIRECT_DESC);
}
/// Returns the access platform only if the feature has been acked.
pub fn access_platform(&self) -> Option<Arc<dyn AccessPlatform>> {
if self.feature_acked(VIRTIO_F_ACCESS_PLATFORM as u64) {
self.access_platform.clone()
} else {
None
}
}
}
impl Pausable for VirtioCommon {