Lines Matching refs:vq
97 struct vhost_virtqueue *vq; member
108 struct vhost_virtqueue vq; member
228 static void vhost_net_enable_zcopy(int vq) in vhost_net_enable_zcopy() argument
230 vhost_net_zcopy_mask |= 0x1 << vq; in vhost_net_enable_zcopy()
234 vhost_net_ubuf_alloc(struct vhost_virtqueue *vq, bool zcopy) in vhost_net_ubuf_alloc() argument
245 ubufs->vq = vq; in vhost_net_ubuf_alloc()
359 struct vhost_virtqueue *vq) in vhost_zerocopy_signal_used() argument
362 container_of(vq, struct vhost_net_virtqueue, vq); in vhost_zerocopy_signal_used()
367 if (vq->heads[i].len == VHOST_DMA_FAILED_LEN) in vhost_zerocopy_signal_used()
369 if (VHOST_DMA_IS_DONE(vq->heads[i].len)) { in vhost_zerocopy_signal_used()
370 vq->heads[i].len = VHOST_DMA_CLEAR_LEN; in vhost_zerocopy_signal_used()
377 vhost_add_used_and_signal_n(vq->dev, vq, in vhost_zerocopy_signal_used()
378 &vq->heads[nvq->done_idx], add); in vhost_zerocopy_signal_used()
389 struct vhost_virtqueue *vq = ubufs->vq; in vhost_zerocopy_callback() local
395 vq->heads[ubuf->desc].len = success ? in vhost_zerocopy_callback()
407 vhost_poll_queue(&vq->poll); in vhost_zerocopy_callback()
424 struct vhost_virtqueue *vq) in vhost_net_disable_vq() argument
427 container_of(vq, struct vhost_net_virtqueue, vq); in vhost_net_disable_vq()
429 if (!vhost_vq_get_backend(vq)) in vhost_net_disable_vq()
435 struct vhost_virtqueue *vq) in vhost_net_enable_vq() argument
438 container_of(vq, struct vhost_net_virtqueue, vq); in vhost_net_enable_vq()
442 sock = vhost_vq_get_backend(vq); in vhost_net_enable_vq()
451 struct vhost_virtqueue *vq = &nvq->vq; in vhost_net_signal_used() local
452 struct vhost_dev *dev = vq->dev; in vhost_net_signal_used()
457 vhost_add_used_and_signal_n(dev, vq, vq->heads, nvq->done_idx); in vhost_net_signal_used()
480 vq_err(&nvq->vq, "Fail to batch sending packets\n"); in vhost_tx_batch()
510 struct vhost_virtqueue *vq) in vhost_net_busy_poll_try_queue() argument
512 if (!vhost_vq_avail_empty(&net->dev, vq)) { in vhost_net_busy_poll_try_queue()
513 vhost_poll_queue(&vq->poll); in vhost_net_busy_poll_try_queue()
514 } else if (unlikely(vhost_enable_notify(&net->dev, vq))) { in vhost_net_busy_poll_try_queue()
515 vhost_disable_notify(&net->dev, vq); in vhost_net_busy_poll_try_queue()
516 vhost_poll_queue(&vq->poll); in vhost_net_busy_poll_try_queue()
529 struct vhost_virtqueue *vq = poll_rx ? tvq : rvq; in vhost_net_busy_poll() local
535 if (!mutex_trylock(&vq->mutex)) in vhost_net_busy_poll()
538 vhost_disable_notify(&net->dev, vq); in vhost_net_busy_poll()
564 vhost_net_busy_poll_try_queue(net, vq); in vhost_net_busy_poll()
568 mutex_unlock(&vq->mutex); in vhost_net_busy_poll()
577 struct vhost_virtqueue *rvq = &rnvq->vq; in vhost_net_tx_get_vq_desc()
578 struct vhost_virtqueue *tvq = &tnvq->vq; in vhost_net_tx_get_vq_desc()
602 struct vhost_virtqueue *vq = &nvq->vq; in vhost_exceeds_maxpend() local
605 min_t(unsigned int, VHOST_MAX_PEND, vq->num >> 2); in vhost_exceeds_maxpend()
608 static size_t init_iov_iter(struct vhost_virtqueue *vq, struct iov_iter *iter, in init_iov_iter() argument
612 size_t len = iov_length(vq->iov, out); in init_iov_iter()
614 iov_iter_init(iter, WRITE, vq->iov, out, len); in init_iov_iter()
626 struct vhost_virtqueue *vq = &nvq->vq; in get_tx_bufs() local
631 if (ret < 0 || ret == vq->num) in get_tx_bufs()
635 vq_err(vq, "Unexpected descriptor format for TX: out %d, int %d\n", in get_tx_bufs()
641 *len = init_iov_iter(vq, &msg->msg_iter, nvq->vhost_hlen, *out); in get_tx_bufs()
643 vq_err(vq, "Unexpected header len for TX: %zd expected %zd\n", in get_tx_bufs()
651 static bool tx_can_batch(struct vhost_virtqueue *vq, size_t total_len) in tx_can_batch() argument
654 !vhost_vq_avail_empty(vq->dev, vq); in tx_can_batch()
697 struct vhost_virtqueue *vq = &nvq->vq; in vhost_net_build_xdp() local
698 struct vhost_net *net = container_of(vq->dev, struct vhost_net, in vhost_net_build_xdp()
700 struct socket *sock = vhost_vq_get_backend(vq); in vhost_net_build_xdp()
738 vhost16_to_cpu(vq, gso->csum_start) + in vhost_net_build_xdp()
739 vhost16_to_cpu(vq, gso->csum_offset) + 2 > in vhost_net_build_xdp()
740 vhost16_to_cpu(vq, gso->hdr_len)) { in vhost_net_build_xdp()
741 gso->hdr_len = cpu_to_vhost16(vq, in vhost_net_build_xdp()
742 vhost16_to_cpu(vq, gso->csum_start) + in vhost_net_build_xdp()
743 vhost16_to_cpu(vq, gso->csum_offset) + 2); in vhost_net_build_xdp()
745 if (vhost16_to_cpu(vq, gso->hdr_len) > len) in vhost_net_build_xdp()
771 struct vhost_virtqueue *vq = &nvq->vq; in handle_tx_copy() local
798 if (head == vq->num) { in handle_tx_copy()
800 vhost_poll_queue(&vq->poll); in handle_tx_copy()
802 vq))) { in handle_tx_copy()
803 vhost_disable_notify(&net->dev, vq); in handle_tx_copy()
820 vhost_discard_vq_desc(vq, 1); in handle_tx_copy()
821 vhost_net_enable_vq(net, vq); in handle_tx_copy()
832 if (tx_can_batch(vq, total_len)) in handle_tx_copy()
841 vhost_discard_vq_desc(vq, 1); in handle_tx_copy()
842 vhost_net_enable_vq(net, vq); in handle_tx_copy()
850 vq->heads[nvq->done_idx].id = cpu_to_vhost32(vq, head); in handle_tx_copy()
851 vq->heads[nvq->done_idx].len = 0; in handle_tx_copy()
853 } while (likely(!vhost_exceeds_weight(vq, ++sent_pkts, total_len))); in handle_tx_copy()
861 struct vhost_virtqueue *vq = &nvq->vq; in handle_tx_zerocopy() local
883 vhost_zerocopy_signal_used(net, vq); in handle_tx_zerocopy()
892 if (head == vq->num) { in handle_tx_zerocopy()
894 vhost_poll_queue(&vq->poll); in handle_tx_zerocopy()
895 } else if (unlikely(vhost_enable_notify(&net->dev, vq))) { in handle_tx_zerocopy()
896 vhost_disable_notify(&net->dev, vq); in handle_tx_zerocopy()
909 vq->heads[nvq->upend_idx].id = cpu_to_vhost32(vq, head); in handle_tx_zerocopy()
910 vq->heads[nvq->upend_idx].len = VHOST_DMA_IN_PROGRESS; in handle_tx_zerocopy()
928 if (tx_can_batch(vq, total_len) && in handle_tx_zerocopy()
938 if (vq->heads[ubuf->desc].len == VHOST_DMA_IN_PROGRESS) in handle_tx_zerocopy()
944 vhost_discard_vq_desc(vq, 1); in handle_tx_zerocopy()
945 vhost_net_enable_vq(net, vq); in handle_tx_zerocopy()
953 vhost_add_used_and_signal(&net->dev, vq, head, 0); in handle_tx_zerocopy()
955 vhost_zerocopy_signal_used(net, vq); in handle_tx_zerocopy()
957 } while (likely(!vhost_exceeds_weight(vq, ++sent_pkts, total_len))); in handle_tx_zerocopy()
965 struct vhost_virtqueue *vq = &nvq->vq; in handle_tx() local
968 mutex_lock_nested(&vq->mutex, VHOST_NET_VQ_TX); in handle_tx()
969 sock = vhost_vq_get_backend(vq); in handle_tx()
973 if (!vq_meta_prefetch(vq)) in handle_tx()
976 vhost_disable_notify(&net->dev, vq); in handle_tx()
977 vhost_net_disable_vq(net, vq); in handle_tx()
985 mutex_unlock(&vq->mutex); in handle_tx()
1014 struct vhost_virtqueue *rvq = &rnvq->vq; in vhost_net_rx_peek_head_len()
1015 struct vhost_virtqueue *tvq = &tnvq->vq; in vhost_net_rx_peek_head_len()
1040 static int get_rx_bufs(struct vhost_virtqueue *vq, in get_rx_bufs() argument
1063 r = vhost_get_vq_desc(vq, vq->iov + seg, in get_rx_bufs()
1064 ARRAY_SIZE(vq->iov) - seg, &out, in get_rx_bufs()
1070 if (d == vq->num) { in get_rx_bufs()
1075 vq_err(vq, "unexpected descriptor format for RX: " in get_rx_bufs()
1084 heads[headcount].id = cpu_to_vhost32(vq, d); in get_rx_bufs()
1085 len = iov_length(vq->iov + seg, in); in get_rx_bufs()
1086 heads[headcount].len = cpu_to_vhost32(vq, len); in get_rx_bufs()
1091 heads[headcount - 1].len = cpu_to_vhost32(vq, len + datalen); in get_rx_bufs()
1103 vhost_discard_vq_desc(vq, headcount); in get_rx_bufs()
1112 struct vhost_virtqueue *vq = &nvq->vq; in handle_rx() local
1137 mutex_lock_nested(&vq->mutex, VHOST_NET_VQ_RX); in handle_rx()
1138 sock = vhost_vq_get_backend(vq); in handle_rx()
1142 if (!vq_meta_prefetch(vq)) in handle_rx()
1145 vhost_disable_notify(&net->dev, vq); in handle_rx()
1146 vhost_net_disable_vq(net, vq); in handle_rx()
1151 vq_log = unlikely(vhost_has_feature(vq, VHOST_F_LOG_ALL)) ? in handle_rx()
1152 vq->log : NULL; in handle_rx()
1153 mergeable = vhost_has_feature(vq, VIRTIO_NET_F_MRG_RXBUF); in handle_rx()
1162 headcount = get_rx_bufs(vq, vq->heads + nvq->done_idx, in handle_rx()
1171 vhost_poll_queue(&vq->poll); in handle_rx()
1172 } else if (unlikely(vhost_enable_notify(&net->dev, vq))) { in handle_rx()
1175 vhost_disable_notify(&net->dev, vq); in handle_rx()
1187 iov_iter_init(&msg.msg_iter, READ, vq->iov, 1, 1); in handle_rx()
1194 iov_iter_init(&msg.msg_iter, READ, vq->iov, in, vhost_len); in handle_rx()
1210 vhost_discard_vq_desc(vq, headcount); in handle_rx()
1217 vq_err(vq, "Unable to write vnet_hdr " in handle_rx()
1218 "at addr %p\n", vq->iov->iov_base); in handle_rx()
1229 num_buffers = cpu_to_vhost16(vq, headcount); in handle_rx()
1233 vq_err(vq, "Failed num_buffers write"); in handle_rx()
1234 vhost_discard_vq_desc(vq, headcount); in handle_rx()
1241 vhost_log_write(vq, vq_log, log, vhost_len, in handle_rx()
1242 vq->iov, in); in handle_rx()
1244 } while (likely(!vhost_exceeds_weight(vq, ++recv_pkts, total_len))); in handle_rx()
1247 vhost_poll_queue(&vq->poll); in handle_rx()
1249 vhost_net_enable_vq(net, vq); in handle_rx()
1252 mutex_unlock(&vq->mutex); in handle_rx()
1257 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue, in handle_tx_kick() local
1259 struct vhost_net *net = container_of(vq->dev, struct vhost_net, dev); in handle_tx_kick()
1266 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue, in handle_rx_kick() local
1268 struct vhost_net *net = container_of(vq->dev, struct vhost_net, dev); in handle_rx_kick()
1324 vqs[VHOST_NET_VQ_TX] = &n->vqs[VHOST_NET_VQ_TX].vq; in vhost_net_open()
1325 vqs[VHOST_NET_VQ_RX] = &n->vqs[VHOST_NET_VQ_RX].vq; in vhost_net_open()
1326 n->vqs[VHOST_NET_VQ_TX].vq.handle_kick = handle_tx_kick; in vhost_net_open()
1327 n->vqs[VHOST_NET_VQ_RX].vq.handle_kick = handle_rx_kick; in vhost_net_open()
1355 struct vhost_virtqueue *vq) in vhost_net_stop_vq() argument
1359 container_of(vq, struct vhost_net_virtqueue, vq); in vhost_net_stop_vq()
1361 mutex_lock(&vq->mutex); in vhost_net_stop_vq()
1362 sock = vhost_vq_get_backend(vq); in vhost_net_stop_vq()
1363 vhost_net_disable_vq(n, vq); in vhost_net_stop_vq()
1364 vhost_vq_set_backend(vq, NULL); in vhost_net_stop_vq()
1367 mutex_unlock(&vq->mutex); in vhost_net_stop_vq()
1374 *tx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_TX].vq); in vhost_net_stop()
1375 *rx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_RX].vq); in vhost_net_stop()
1382 mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1384 mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1387 mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1390 mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1496 struct vhost_virtqueue *vq; in vhost_net_set_backend() local
1510 vq = &n->vqs[index].vq; in vhost_net_set_backend()
1512 mutex_lock(&vq->mutex); in vhost_net_set_backend()
1515 if (!vhost_vq_access_ok(vq)) { in vhost_net_set_backend()
1526 oldsock = vhost_vq_get_backend(vq); in vhost_net_set_backend()
1528 ubufs = vhost_net_ubuf_alloc(vq, in vhost_net_set_backend()
1535 vhost_net_disable_vq(n, vq); in vhost_net_set_backend()
1536 vhost_vq_set_backend(vq, sock); in vhost_net_set_backend()
1538 r = vhost_vq_init_access(vq); in vhost_net_set_backend()
1541 r = vhost_net_enable_vq(n, vq); in vhost_net_set_backend()
1559 mutex_unlock(&vq->mutex); in vhost_net_set_backend()
1563 mutex_lock(&vq->mutex); in vhost_net_set_backend()
1564 vhost_zerocopy_signal_used(n, vq); in vhost_net_set_backend()
1565 mutex_unlock(&vq->mutex); in vhost_net_set_backend()
1577 vhost_vq_set_backend(vq, oldsock); in vhost_net_set_backend()
1578 vhost_net_enable_vq(n, vq); in vhost_net_set_backend()
1585 mutex_unlock(&vq->mutex); in vhost_net_set_backend()
1650 mutex_lock(&n->vqs[i].vq.mutex); in vhost_net_set_features()
1651 n->vqs[i].vq.acked_features = features; in vhost_net_set_features()
1654 mutex_unlock(&n->vqs[i].vq.mutex); in vhost_net_set_features()