qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

Merge remote-tracking branch 'remotes/elmarco/tags/vu-pull-request' into staging

# gpg: Signature made Thu 12 Oct 2017 21:52:28 BST
# gpg: using RSA key 0xDAE8E10975969CE5
# gpg: Good signature from "Marc-André Lureau <marcandre.lureau@redhat.com>"
# gpg: aka "Marc-André Lureau <marcandre.lureau@gmail.com>"
# gpg: WARNING: This key is not certified with sufficiently trusted signatures!
# gpg: It is not certain that the signature belongs to the owner.
# Primary key fingerprint: 87A9 BD93 3F87 C606 D276 F62D DAE8 E109 7596 9CE5

* remotes/elmarco/tags/vu-pull-request:
libvhost-user: Support VHOST_USER_SET_SLAVE_REQ_FD
libvhost-user: Update and fix feature and request lists
vhost-user-bridge: Only process received packets on started queues
libvhost-user: vu_queue_started

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

+56 -7
+37 -6
contrib/libvhost-user/libvhost-user.c
··· 56 56 } while (0) 57 57 58 58 static const char * 59 - vu_request_to_string(int req) 59 + vu_request_to_string(unsigned int req) 60 60 { 61 61 #define REQ(req) [req] = #req 62 62 static const char *vu_request_str[] = { 63 - REQ(VHOST_USER_NONE), 64 - REQ(VHOST_USER_GET_FEATURES), 65 - REQ(VHOST_USER_SET_FEATURES), 66 63 REQ(VHOST_USER_NONE), 67 64 REQ(VHOST_USER_GET_FEATURES), 68 65 REQ(VHOST_USER_SET_FEATURES), ··· 83 80 REQ(VHOST_USER_GET_QUEUE_NUM), 84 81 REQ(VHOST_USER_SET_VRING_ENABLE), 85 82 REQ(VHOST_USER_SEND_RARP), 86 - REQ(VHOST_USER_INPUT_GET_CONFIG), 83 + REQ(VHOST_USER_NET_SET_MTU), 84 + REQ(VHOST_USER_SET_SLAVE_REQ_FD), 85 + REQ(VHOST_USER_IOTLB_MSG), 86 + REQ(VHOST_USER_SET_VRING_ENDIAN), 87 87 REQ(VHOST_USER_MAX), 88 88 }; 89 89 #undef REQ ··· 726 726 static bool 727 727 vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg) 728 728 { 729 - uint64_t features = 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD; 729 + uint64_t features = 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD | 730 + 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ; 730 731 731 732 if (dev->iface->get_protocol_features) { 732 733 features |= dev->iface->get_protocol_features(dev); ··· 780 781 } 781 782 782 783 static bool 784 + vu_set_slave_req_fd(VuDev *dev, VhostUserMsg *vmsg) 785 + { 786 + if (vmsg->fd_num != 1) { 787 + vu_panic(dev, "Invalid slave_req_fd message (%d fd's)", vmsg->fd_num); 788 + return false; 789 + } 790 + 791 + if (dev->slave_fd != -1) { 792 + close(dev->slave_fd); 793 + } 794 + dev->slave_fd = vmsg->fds[0]; 795 + DPRINT("Got slave_fd: %d\n", vmsg->fds[0]); 796 + 797 + return false; 798 + } 799 + 800 + static bool 783 801 vu_process_message(VuDev *dev, VhostUserMsg *vmsg) 784 802 { 785 803 int do_reply = 0; ··· 842 860 return vu_get_queue_num_exec(dev, vmsg); 843 861 case VHOST_USER_SET_VRING_ENABLE: 844 862 return vu_set_vring_enable_exec(dev, vmsg); 863 + case VHOST_USER_SET_SLAVE_REQ_FD: 864 + return vu_set_slave_req_fd(dev, vmsg); 845 865 case VHOST_USER_NONE: 846 866 break; 847 867 default: ··· 915 935 916 936 917 937 vu_close_log(dev); 938 + if (dev->slave_fd != -1) { 939 + close(dev->slave_fd); 940 + dev->slave_fd = -1; 941 + } 918 942 919 943 if (dev->sock != -1) { 920 944 close(dev->sock); ··· 945 969 dev->remove_watch = remove_watch; 946 970 dev->iface = iface; 947 971 dev->log_call_fd = -1; 972 + dev->slave_fd = -1; 948 973 for (i = 0; i < VHOST_MAX_NR_VIRTQUEUE; i++) { 949 974 dev->vq[i] = (VuVirtq) { 950 975 .call_fd = -1, .kick_fd = -1, .err_fd = -1, ··· 964 989 vu_queue_enabled(VuDev *dev, VuVirtq *vq) 965 990 { 966 991 return vq->enable; 992 + } 993 + 994 + bool 995 + vu_queue_started(const VuDev *dev, const VuVirtq *vq) 996 + { 997 + return vq->started; 967 998 } 968 999 969 1000 static inline uint16_t
+18 -1
contrib/libvhost-user/libvhost-user.h
··· 34 34 VHOST_USER_PROTOCOL_F_MQ = 0, 35 35 VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1, 36 36 VHOST_USER_PROTOCOL_F_RARP = 2, 37 + VHOST_USER_PROTOCOL_F_REPLY_ACK = 3, 38 + VHOST_USER_PROTOCOL_F_NET_MTU = 4, 39 + VHOST_USER_PROTOCOL_F_SLAVE_REQ = 5, 40 + VHOST_USER_PROTOCOL_F_CROSS_ENDIAN = 6, 37 41 38 42 VHOST_USER_PROTOCOL_F_MAX 39 43 }; ··· 61 65 VHOST_USER_GET_QUEUE_NUM = 17, 62 66 VHOST_USER_SET_VRING_ENABLE = 18, 63 67 VHOST_USER_SEND_RARP = 19, 64 - VHOST_USER_INPUT_GET_CONFIG = 20, 68 + VHOST_USER_NET_SET_MTU = 20, 69 + VHOST_USER_SET_SLAVE_REQ_FD = 21, 70 + VHOST_USER_IOTLB_MSG = 22, 71 + VHOST_USER_SET_VRING_ENDIAN = 23, 65 72 VHOST_USER_MAX 66 73 } VhostUserRequest; 67 74 ··· 219 226 VuDevRegion regions[VHOST_MEMORY_MAX_NREGIONS]; 220 227 VuVirtq vq[VHOST_MAX_NR_VIRTQUEUE]; 221 228 int log_call_fd; 229 + int slave_fd; 222 230 uint64_t log_size; 223 231 uint8_t *log_table; 224 232 uint64_t features; ··· 333 341 * Returns: whether the queue is enabled. 334 342 */ 335 343 bool vu_queue_enabled(VuDev *dev, VuVirtq *vq); 344 + 345 + /** 346 + * vu_queue_started: 347 + * @dev: a VuDev context 348 + * @vq: a VuVirtq queue 349 + * 350 + * Returns: whether the queue is started. 351 + */ 352 + bool vu_queue_started(const VuDev *dev, const VuVirtq *vq); 336 353 337 354 /** 338 355 * vu_queue_empty:
+1
tests/vhost-user-bridge.c
··· 277 277 DPRINT(" hdrlen = %d\n", hdrlen); 278 278 279 279 if (!vu_queue_enabled(dev, vq) || 280 + !vu_queue_started(dev, vq) || 280 281 !vu_queue_avail_bytes(dev, vq, hdrlen, 0)) { 281 282 DPRINT("Got UDP packet, but no available descriptors on RX virtq.\n"); 282 283 return;