History

vhost: switch to use new message format

We use to have message like: struct vhost_msg { int type; union { struct vhost_iotlb_msg iotlb; __u8 padding[64]; }; }; Unfortunately, there will be a hole of 32bit in 64bit machine because of the alignment. This leads a different formats between 32bit API and 64bit API. What's more it will break 32bit program running on 64bit machine. So fixing this by introducing a new message type with an explicit 32bit reserved field after type like: struct vhost_msg_v2 { __u32 type; __u32 reserved; union { struct vhost_iotlb_msg iotlb; __u8 padding[64]; }; }; We will have a consistent ABI after switching to use this. To enable this capability, introduce a new ioctl (VHOST_SET_BAKCEND_FEATURE) for userspace to enable this feature (VHOST_BACKEND_F_IOTLB_V2).

Jason Wang committed 8 years ago

Commit 429711a1 parent 9c2e9554 files · +111 −19Browse files

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

Unified · Split

include/uapi/linux/vhost.h+18−0
@@ -65,6 +65,7 @@ struct vhost_iotlb_msg { · 64 unmodified lines
65};65};
66 66
67#define VHOST_IOTLB_MSG 0x167#define VHOST_IOTLB_MSG 0x1
68#define VHOST_IOTLB_MSG_V2 0x2
68 69
69struct vhost_msg {70struct vhost_msg {
70 int type;71 int type;
@@ -74,6 +75,15 @@ struct vhost_msg { · 3 unmodified lines
74 };75 };
75};76};
76 77
78struct vhost_msg_v2 {
79 __u32 type;
80 __u32 reserved;
81 union {
82 struct vhost_iotlb_msg iotlb;
83 __u8 padding[64];
84 };
85};
86
77struct vhost_memory_region {87struct vhost_memory_region {
78 __u64 guest_phys_addr;88 __u64 guest_phys_addr;
79 __u64 memory_size; /* bytes */89 __u64 memory_size; /* bytes */
@@ -160,6 +170,14 @@ struct vhost_memory { · 80 unmodified lines
160#define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \170#define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \
161 struct vhost_vring_state)171 struct vhost_vring_state)
162 172
173/* Set or get vhost backend capability */
174
175/* Use message type V2 */
176#define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1
177
178#define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64)
179#define VHOST_GET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x26, __u64)
180
163/* VHOST_NET specific defines */181/* VHOST_NET specific defines */
164 182
165/* Attach virtio net ring to a raw socket, or tap device.183/* Attach virtio net ring to a raw socket, or tap device.