mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-23 03:42:20 +00:00
vm-virtio: Add IOMMU support to virtio-rng
Adding virtio feature VIRTIO_F_IOMMU_PLATFORM when explicitly asked by the user. The need for this feature is to be able to attach the virtio device to a virtual IOMMU. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
ee1899c6f6
commit
9ab00dcb75
@ -15,7 +15,7 @@ use std::thread;
|
|||||||
use super::Error as DeviceError;
|
use super::Error as DeviceError;
|
||||||
use super::{
|
use super::{
|
||||||
ActivateError, ActivateResult, DeviceEventT, Queue, VirtioDevice, VirtioDeviceType,
|
ActivateError, ActivateResult, DeviceEventT, Queue, VirtioDevice, VirtioDeviceType,
|
||||||
VIRTIO_F_VERSION_1,
|
VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1,
|
||||||
};
|
};
|
||||||
use crate::{VirtioInterrupt, VirtioInterruptType};
|
use crate::{VirtioInterrupt, VirtioInterruptType};
|
||||||
use vm_memory::{Bytes, GuestMemoryMmap};
|
use vm_memory::{Bytes, GuestMemoryMmap};
|
||||||
@ -164,9 +164,13 @@ pub struct Rng {
|
|||||||
|
|
||||||
impl Rng {
|
impl Rng {
|
||||||
/// Create a new virtio rng device that gets random data from /dev/urandom.
|
/// Create a new virtio rng device that gets random data from /dev/urandom.
|
||||||
pub fn new(path: &str) -> io::Result<Rng> {
|
pub fn new(path: &str, iommu: bool) -> io::Result<Rng> {
|
||||||
let random_file = File::open(path)?;
|
let random_file = File::open(path)?;
|
||||||
let avail_features = 1u64 << VIRTIO_F_VERSION_1;
|
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1;
|
||||||
|
|
||||||
|
if iommu {
|
||||||
|
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Rng {
|
Ok(Rng {
|
||||||
kill_evt: None,
|
kill_evt: None,
|
||||||
|
@ -634,8 +634,8 @@ impl DeviceManager {
|
|||||||
|
|
||||||
// Add virtio-rng if required
|
// Add virtio-rng if required
|
||||||
if let Some(rng_path) = vm_info.vm_cfg.rng.src.to_str() {
|
if let Some(rng_path) = vm_info.vm_cfg.rng.src.to_str() {
|
||||||
let virtio_rng_device =
|
let virtio_rng_device = vm_virtio::Rng::new(rng_path, false)
|
||||||
vm_virtio::Rng::new(rng_path).map_err(DeviceManagerError::CreateVirtioRng)?;
|
.map_err(DeviceManagerError::CreateVirtioRng)?;
|
||||||
devices.push(Box::new(virtio_rng_device) as Box<dyn vm_virtio::VirtioDevice>);
|
devices.push(Box::new(virtio_rng_device) as Box<dyn vm_virtio::VirtioDevice>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user