rust-vmm / vfio

14 stars 20 forks source link

vfio_device: enable IommuDmaMap/IommuDmaUnmap to take SysError #13

Closed xuejun-xj closed 2 years ago

xuejun-xj commented 2 years ago

Improving the error that is reported through IommuDmaMap and IommuDmaUnmap by propagating the system error retrieved through SysError.

Also introducing new types of VfioError to provide more appropriate errors to the caller.

Signed-off-by: xuejun-xj jiyunxue@linux.alibaba.com Signed-off-by: jingshan jingshan@linux.alibaba.com

Summary of the PR

This PR enables VfioError::IommuDmaMap/IommuDmaUnmap to take SysError after calling the ioctls.

Issue: #12

sboeuf commented 2 years ago

You need to update the coverage for the buildkite CI.

xuejun-xj commented 2 years ago

Changes:

  1. Enable VfioError::IommuDmaMap and VfioError::IommuDmaUnmap to take SysError when it returns.
  2. Add VfioError::GetHostAddress error to handle failure of get_host_address method.
  3. Add VfioError::InvalidDmaUnmapSize error for unmap size check.
  4. When dma_map.size == 0x2000, it will be set to 0x1000 in test method unmap_dma so that VfioError::InvalidDmaUnmapSize error can be covered with unit tests.
  5. Add test_vfio_map_guest_memory test method.
xuejun-xj commented 2 years ago

@liuw @sboeuf Please review again for I have done some changes:

  1. I delete the InvalidVirtualAddress error because it is only used in test function previously. Instead, I use IommuDmaMap(SysError::last()) to be consistent with the real implementation.
  2. I also add a test function, test_vfio_map_guest_memory, to cover the errors I add and to test the methods, vfio_map_guest_memory and vfio_unmap_guest_memory.

Thanks!