History

vhost: new device IOTLB API

This patch tries to implement an device IOTLB for vhost. This could be used with userspace(qemu) implementation of DMA remapping to emulate an IOMMU for the guest. The idea is simple, cache the translation in a software device IOTLB (which is implemented as an interval tree) in vhost and use vhost_net file descriptor for reporting IOTLB miss and IOTLB update/invalidation. When vhost meets an IOTLB miss, the fault address, size and access can be read from the file. After userspace finishes the translation, it writes the translated address to the vhost_net file to update the device IOTLB. When device IOTLB is enabled by setting VIRTIO_F_IOMMU_PLATFORM all vq addresses set by ioctl are treated as iova instead of virtual address and the accessing can only be done through IOTLB instead of direct userspace memory access. Before each round or vq processing, all vq metadata is prefetched in device IOTLB to make sure no translation fault happens during vq processing. In most cases, virtqueues are contiguous even in virtual address space. The IOTLB translation for virtqueue itself may make it a little slower. We might add fast path cache on top of this patch.

Jason Wang committed 10 years ago

Commit 6b1e6cc1 parent b2fbd8b4 files · +705 −50Browse files

Showing the changes to include/uapi/linux (1 of 4 files). Show all

Unified · Split

include/uapi/linux/vhost.h+28−0
@@ -47,6 +47,32 @@ struct vhost_vring_addr { · 46 unmodified lines
4747 __u64 log_guest_addr;
4848 };
4949
50+/* no alignment requirement */
51+struct vhost_iotlb_msg {
52+ __u64 iova;
53+ __u64 size;
54+ __u64 uaddr;
55+#define VHOST_ACCESS_RO 0x1
56+#define VHOST_ACCESS_WO 0x2
57+#define VHOST_ACCESS_RW 0x3
58+ __u8 perm;
59+#define VHOST_IOTLB_MISS 1
60+#define VHOST_IOTLB_UPDATE 2
61+#define VHOST_IOTLB_INVALIDATE 3
62+#define VHOST_IOTLB_ACCESS_FAIL 4
63+ __u8 type;
64+};
65+
66+#define VHOST_IOTLB_MSG 0x1
67+
68+struct vhost_msg {
69+ int type;
70+ union {
71+ struct vhost_iotlb_msg iotlb;
72+ __u8 padding[64];
73+ };
74+};
75+
5076 struct vhost_memory_region {
5177 __u64 guest_phys_addr;
5278 __u64 memory_size; /* bytes */
@@ -146,6 +172,8 @@ struct vhost_memory { · 93 unmodified lines
146172 #define VHOST_F_LOG_ALL 26
147173 /* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */
148174 #define VHOST_NET_F_VIRTIO_NET_HDR 27
175+/* Vhost have device IOTLB */
176+#define VHOST_F_DEVICE_IOTLB 63
149177
150178 /* VHOST_SCSI specific definitions */
151179

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t