mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vm-virtio: Add IOMMU support to virtio-blk
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:
committed by
Samuel Ortiz
parent
85e1865cb5
commit
9ebb1a55bc
@@ -503,6 +503,7 @@ impl<T: DiskFile> Block<T> {
|
|||||||
mut disk_image: T,
|
mut disk_image: T,
|
||||||
disk_path: PathBuf,
|
disk_path: PathBuf,
|
||||||
is_disk_read_only: bool,
|
is_disk_read_only: bool,
|
||||||
|
iommu: bool,
|
||||||
) -> io::Result<Block<T>> {
|
) -> io::Result<Block<T>> {
|
||||||
let disk_size = disk_image.seek(SeekFrom::End(0))? as u64;
|
let disk_size = disk_image.seek(SeekFrom::End(0))? as u64;
|
||||||
if disk_size % SECTOR_SIZE != 0 {
|
if disk_size % SECTOR_SIZE != 0 {
|
||||||
@@ -515,6 +516,10 @@ impl<T: DiskFile> Block<T> {
|
|||||||
|
|
||||||
let mut avail_features = (1u64 << VIRTIO_F_VERSION_1) | (1u64 << VIRTIO_BLK_F_FLUSH);
|
let mut avail_features = (1u64 << VIRTIO_F_VERSION_1) | (1u64 << VIRTIO_BLK_F_FLUSH);
|
||||||
|
|
||||||
|
if iommu {
|
||||||
|
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
||||||
|
}
|
||||||
|
|
||||||
if is_disk_read_only {
|
if is_disk_read_only {
|
||||||
avail_features |= 1u64 << VIRTIO_BLK_F_RO;
|
avail_features |= 1u64 << VIRTIO_BLK_F_RO;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -580,15 +580,17 @@ impl DeviceManager {
|
|||||||
let block = match image_type {
|
let block = match image_type {
|
||||||
ImageType::Raw => {
|
ImageType::Raw => {
|
||||||
let raw_img = vm_virtio::RawFile::new(raw_img);
|
let raw_img = vm_virtio::RawFile::new(raw_img);
|
||||||
let dev = vm_virtio::Block::new(raw_img, disk_cfg.path.clone(), false)
|
let dev =
|
||||||
.map_err(DeviceManagerError::CreateVirtioBlock)?;
|
vm_virtio::Block::new(raw_img, disk_cfg.path.clone(), false, false)
|
||||||
|
.map_err(DeviceManagerError::CreateVirtioBlock)?;
|
||||||
Box::new(dev) as Box<dyn vm_virtio::VirtioDevice>
|
Box::new(dev) as Box<dyn vm_virtio::VirtioDevice>
|
||||||
}
|
}
|
||||||
ImageType::Qcow2 => {
|
ImageType::Qcow2 => {
|
||||||
let qcow_img = QcowFile::from(raw_img)
|
let qcow_img = QcowFile::from(raw_img)
|
||||||
.map_err(DeviceManagerError::QcowDeviceCreate)?;
|
.map_err(DeviceManagerError::QcowDeviceCreate)?;
|
||||||
let dev = vm_virtio::Block::new(qcow_img, disk_cfg.path.clone(), false)
|
let dev =
|
||||||
.map_err(DeviceManagerError::CreateVirtioBlock)?;
|
vm_virtio::Block::new(qcow_img, disk_cfg.path.clone(), false, false)
|
||||||
|
.map_err(DeviceManagerError::CreateVirtioBlock)?;
|
||||||
Box::new(dev) as Box<dyn vm_virtio::VirtioDevice>
|
Box::new(dev) as Box<dyn vm_virtio::VirtioDevice>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user