This patch allow device to register its own message handler during vhost_dev_init(). vDPA device will use it to implement its own DMA mapping logic.
Unified · Split
| @@ -1324,7 +1324,8 @@ static int vhost_net_open(struct inode *inode, struct file *f) · 1323 unmodified lines | ||
| 1324 | 1324 | } |
| 1325 | 1325 | vhost_dev_init(dev, vqs, VHOST_NET_VQ_MAX, |
| 1326 | 1326 | UIO_MAXIOV + VHOST_NET_BATCH, |
| 1327 | − VHOST_NET_PKT_WEIGHT, VHOST_NET_WEIGHT); | |
| 1327 | + VHOST_NET_PKT_WEIGHT, VHOST_NET_WEIGHT, | |
| 1328 | + NULL); | |
| 1328 | 1329 | |
| 1329 | 1330 | vhost_poll_init(n->poll + VHOST_NET_VQ_TX, handle_tx_net, EPOLLOUT, dev); |
| 1330 | 1331 | vhost_poll_init(n->poll + VHOST_NET_VQ_RX, handle_rx_net, EPOLLIN, dev); |
| @@ -1628,7 +1628,7 @@ static int vhost_scsi_open(struct inode *inode, struct file *f) · 1627 unmodified lines | ||
| 1628 | 1628 | vs->vqs[i].vq.handle_kick = vhost_scsi_handle_kick; |
| 1629 | 1629 | } |
| 1630 | 1630 | vhost_dev_init(&vs->dev, vqs, VHOST_SCSI_MAX_VQ, UIO_MAXIOV, |
| 1631 | − VHOST_SCSI_WEIGHT, 0); | |
| 1631 | + VHOST_SCSI_WEIGHT, 0, NULL); | |
| 1632 | 1632 | |
| 1633 | 1633 | vhost_scsi_init_inflight(vs, NULL); |
| 1634 | 1634 | |
| @@ -457,7 +457,9 @@ static size_t vhost_get_desc_size(struct vhost_virtqueue *vq, · 456 unmodified lines | ||
| 457 | 457 | |
| 458 | 458 | void vhost_dev_init(struct vhost_dev *dev, |
| 459 | 459 | struct vhost_virtqueue **vqs, int nvqs, |
| 460 | − int iov_limit, int weight, int byte_weight) | |
| 460 | + int iov_limit, int weight, int byte_weight, | |
| 461 | + int (*msg_handler)(struct vhost_dev *dev, | |
| 462 | + struct vhost_iotlb_msg *msg)) | |
| 461 | 463 | { |
| 462 | 464 | struct vhost_virtqueue *vq; |
| 463 | 465 | int i; |
| @@ -473,6 +475,7 @@ void vhost_dev_init(struct vhost_dev *dev, · 9 unmodified lines | ||
| 473 | 475 | dev->iov_limit = iov_limit; |
| 474 | 476 | dev->weight = weight; |
| 475 | 477 | dev->byte_weight = byte_weight; |
| 478 | + dev->msg_handler = msg_handler; | |
| 476 | 479 | init_llist_head(&dev->work_list); |
| 477 | 480 | init_waitqueue_head(&dev->wait); |
| 478 | 481 | INIT_LIST_HEAD(&dev->read_list); |
| @@ -1178,7 +1181,12 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev, · 699 unmodified lines | ||
| 1178 | 1181 | ret = -EINVAL; |
| 1179 | 1182 | goto done; |
| 1180 | 1183 | } |
| 1181 | − if (vhost_process_iotlb_msg(dev, &msg)) { | |
| 1184 | + | |
| 1185 | + if (dev->msg_handler) | |
| 1186 | + ret = dev->msg_handler(dev, &msg); | |
| 1187 | + else | |
| 1188 | + ret = vhost_process_iotlb_msg(dev, &msg); | |
| 1189 | + if (ret) { | |
| 1182 | 1190 | ret = -EFAULT; |
| 1183 | 1191 | goto done; |
| 1184 | 1192 | } |
| @@ -174,11 +174,15 @@ struct vhost_dev { · 173 unmodified lines | ||
| 174 | 174 | int weight; |
| 175 | 175 | int byte_weight; |
| 176 | 176 | u64 kcov_handle; |
| 177 | + int (*msg_handler)(struct vhost_dev *dev, | |
| 178 | + struct vhost_iotlb_msg *msg); | |
| 177 | 179 | }; |
| 178 | 180 | |
| 179 | 181 | bool vhost_exceeds_weight(struct vhost_virtqueue *vq, int pkts, int total_len); |
| 180 | 182 | void vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue **vqs, |
| 181 | − int nvqs, int iov_limit, int weight, int byte_weight); | |
| 183 | + int nvqs, int iov_limit, int weight, int byte_weight, | |
| 184 | + int (*msg_handler)(struct vhost_dev *dev, | |
| 185 | + struct vhost_iotlb_msg *msg)); | |
| 182 | 186 | long vhost_dev_set_owner(struct vhost_dev *dev); |
| 183 | 187 | bool vhost_dev_has_owner(struct vhost_dev *dev); |
| 184 | 188 | long vhost_dev_check_owner(struct vhost_dev *); |
| @@ -621,7 +621,7 @@ static int vhost_vsock_dev_open(struct inode *inode, struct file *file) · 620 unmodified lines | ||
| 621 | 621 | |
| 622 | 622 | vhost_dev_init(&vsock->dev, vqs, ARRAY_SIZE(vsock->vqs), |
| 623 | 623 | UIO_MAXIOV, VHOST_VSOCK_PKT_WEIGHT, |
| 624 | − VHOST_VSOCK_WEIGHT); | |
| 624 | + VHOST_VSOCK_WEIGHT, NULL); | |
| 625 | 625 | |
| 626 | 626 | file->private_data = vsock; |
| 627 | 627 | spin_lock_init(&vsock->send_pkt_list_lock); |