Parse the available vring buffer. Based on the hashmap table of external mappings required from various devices such as VFIO or vhost-user ones, this function might update the hashmap table of external mappings per domain. Basically, the VMM knows about the device_id <=> mapping relationship before running the VM, but at runtime, a new domain <=> mapping hashmap is created based on the information
(
desc_chain: &mut DescriptorChain<GuestMemoryLoadGuard<GuestMemoryMmap>>,
mapping: &Arc<IommuMapping>,
ext_mapping: &BTreeMap<u32, Arc<dyn ExternalDmaMapping>>,
msi_io
| 349 | // is created based on the information provided from the guest driver for |
| 350 | // virtio-iommu (giving the link device_id <=> domain). |
| 351 | fn parse( |
| 352 | desc_chain: &mut DescriptorChain<GuestMemoryLoadGuard<GuestMemoryMmap>>, |
| 353 | mapping: &Arc<IommuMapping>, |
| 354 | ext_mapping: &BTreeMap<u32, Arc<dyn ExternalDmaMapping>>, |
| 355 | msi_iova_space: (u64, u64), |
| 356 | input_range: Option<(u64, u64)>, |
| 357 | ) -> result::Result<usize, Error> { |
| 358 | let desc = desc_chain |
| 359 | .next() |
| 360 | .ok_or(Error::DescriptorChainTooShort) |
| 361 | .inspect_err(|_| { |
| 362 | error!("Missing head descriptor"); |
| 363 | })?; |
| 364 | |
| 365 | // The descriptor contains the request type which MUST be readable. |
| 366 | if desc.is_write_only() { |
| 367 | return Err(Error::UnexpectedWriteOnlyDescriptor); |
| 368 | } |
| 369 | |
| 370 | if (desc.len() as usize) < size_of::<VirtioIommuReqHead>() { |
| 371 | return Err(Error::InvalidRequest); |
| 372 | } |
| 373 | |
| 374 | let req_head: VirtioIommuReqHead = desc_chain |
| 375 | .memory() |
| 376 | .read_obj(desc.addr()) |
| 377 | .map_err(Error::GuestMemory)?; |
| 378 | let req_offset = size_of::<VirtioIommuReqHead>(); |
| 379 | let desc_size_left = (desc.len() as usize) - req_offset; |
| 380 | let req_addr = if let Some(addr) = desc.addr().checked_add(req_offset as u64) { |
| 381 | addr |
| 382 | } else { |
| 383 | return Err(Error::InvalidRequest); |
| 384 | }; |
| 385 | |
| 386 | let (msi_iova_start, msi_iova_end) = msi_iova_space; |
| 387 | |
| 388 | // Create the reply |
| 389 | let mut reply: Vec<u8> = Vec::new(); |
| 390 | let mut status = VIRTIO_IOMMU_S_OK; |
| 391 | let mut hdr_len = 0; |
| 392 | let mut unrecognised_type = false; |
| 393 | |
| 394 | let result = (|| { |
| 395 | match req_head.type_ { |
| 396 | VIRTIO_IOMMU_T_ATTACH => { |
| 397 | if desc_size_left != size_of::<VirtioIommuReqAttach>() { |
| 398 | status = VIRTIO_IOMMU_S_INVAL; |
| 399 | return Err(Error::InvalidAttachRequest); |
| 400 | } |
| 401 | |
| 402 | let req: VirtioIommuReqAttach = desc_chain |
| 403 | .memory() |
| 404 | .read_obj(req_addr as GuestAddress) |
| 405 | .map_err(Error::GuestMemory)?; |
| 406 | debug!("Attach request 0x{req:x?}"); |
| 407 | |
| 408 | if req.reserved.iter().any(|&b| b != 0) |
nothing calls this directly
no test coverage detected