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-net
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
9ebb1a55bc
commit
9fad680db1
+12
-3
@@ -445,7 +445,7 @@ pub struct Net {
|
|||||||
|
|
||||||
impl Net {
|
impl Net {
|
||||||
/// Create a new virtio network device with the given TAP interface.
|
/// Create a new virtio network device with the given TAP interface.
|
||||||
pub fn new_with_tap(tap: Tap, guest_mac: Option<&MacAddr>) -> Result<Self> {
|
pub fn new_with_tap(tap: Tap, guest_mac: Option<&MacAddr>, iommu: bool) -> Result<Self> {
|
||||||
// Set offload flags to match the virtio features below.
|
// Set offload flags to match the virtio features below.
|
||||||
tap.set_offload(
|
tap.set_offload(
|
||||||
net_gen::TUN_F_CSUM | net_gen::TUN_F_UFO | net_gen::TUN_F_TSO4 | net_gen::TUN_F_TSO6,
|
net_gen::TUN_F_CSUM | net_gen::TUN_F_UFO | net_gen::TUN_F_TSO4 | net_gen::TUN_F_TSO6,
|
||||||
@@ -464,6 +464,10 @@ impl Net {
|
|||||||
| 1 << VIRTIO_NET_F_HOST_UFO
|
| 1 << VIRTIO_NET_F_HOST_UFO
|
||||||
| 1 << VIRTIO_F_VERSION_1;
|
| 1 << VIRTIO_F_VERSION_1;
|
||||||
|
|
||||||
|
if iommu {
|
||||||
|
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
||||||
|
}
|
||||||
|
|
||||||
let mut config_space;
|
let mut config_space;
|
||||||
if let Some(mac) = guest_mac {
|
if let Some(mac) = guest_mac {
|
||||||
config_space = Vec::with_capacity(MAC_ADDR_LEN);
|
config_space = Vec::with_capacity(MAC_ADDR_LEN);
|
||||||
@@ -490,13 +494,18 @@ impl Net {
|
|||||||
|
|
||||||
/// Create a new virtio network device with the given IP address and
|
/// Create a new virtio network device with the given IP address and
|
||||||
/// netmask.
|
/// netmask.
|
||||||
pub fn new(ip_addr: Ipv4Addr, netmask: Ipv4Addr, guest_mac: Option<&MacAddr>) -> Result<Self> {
|
pub fn new(
|
||||||
|
ip_addr: Ipv4Addr,
|
||||||
|
netmask: Ipv4Addr,
|
||||||
|
guest_mac: Option<&MacAddr>,
|
||||||
|
iommu: bool,
|
||||||
|
) -> Result<Self> {
|
||||||
let tap = Tap::new().map_err(Error::TapOpen)?;
|
let tap = Tap::new().map_err(Error::TapOpen)?;
|
||||||
tap.set_ip_addr(ip_addr).map_err(Error::TapSetIp)?;
|
tap.set_ip_addr(ip_addr).map_err(Error::TapSetIp)?;
|
||||||
tap.set_netmask(netmask).map_err(Error::TapSetNetmask)?;
|
tap.set_netmask(netmask).map_err(Error::TapSetNetmask)?;
|
||||||
tap.enable().map_err(Error::TapEnable)?;
|
tap.enable().map_err(Error::TapEnable)?;
|
||||||
|
|
||||||
Self::new_with_tap(tap, guest_mac)
|
Self::new_with_tap(tap, guest_mac, iommu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -612,10 +612,10 @@ impl DeviceManager {
|
|||||||
for net_cfg in net_list_cfg.iter() {
|
for net_cfg in net_list_cfg.iter() {
|
||||||
let virtio_net_device = if let Some(ref tap_if_name) = net_cfg.tap {
|
let virtio_net_device = if let Some(ref tap_if_name) = net_cfg.tap {
|
||||||
let tap = Tap::open_named(tap_if_name).map_err(DeviceManagerError::OpenTap)?;
|
let tap = Tap::open_named(tap_if_name).map_err(DeviceManagerError::OpenTap)?;
|
||||||
vm_virtio::Net::new_with_tap(tap, Some(&net_cfg.mac))
|
vm_virtio::Net::new_with_tap(tap, Some(&net_cfg.mac), false)
|
||||||
.map_err(DeviceManagerError::CreateVirtioNet)?
|
.map_err(DeviceManagerError::CreateVirtioNet)?
|
||||||
} else {
|
} else {
|
||||||
vm_virtio::Net::new(net_cfg.ip, net_cfg.mask, Some(&net_cfg.mac))
|
vm_virtio::Net::new(net_cfg.ip, net_cfg.mask, Some(&net_cfg.mac), false)
|
||||||
.map_err(DeviceManagerError::CreateVirtioNet)?
|
.map_err(DeviceManagerError::CreateVirtioNet)?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user