Commit 81f95a55802be669b3191b2828c34006d0f04214

Authored by Michael S. Tsirkin
1 parent 3dfbff328f

vhost: move per-vq net specific fields out to net

This will remove the need for vhost scsi to pull
in virtio-net.h.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Showing 3 changed files with 27 additions and 21 deletions Side-by-side Diff

... ... @@ -72,6 +72,12 @@
72 72  
73 73 struct vhost_net_virtqueue {
74 74 struct vhost_virtqueue vq;
  75 + /* hdr is used to store the virtio header.
  76 + * Since each iovec has >= 1 byte length, we never need more than
  77 + * header length entries to store the header. */
  78 + struct iovec hdr[sizeof(struct virtio_net_hdr_mrg_rxbuf)];
  79 + size_t vhost_hlen;
  80 + size_t sock_hlen;
75 81 /* vhost zerocopy support fields below: */
76 82 /* last used idx for outstanding DMA zerocopy buffers */
77 83 int upend_idx;
... ... @@ -166,7 +172,7 @@
166 172 return -ENOMEM;
167 173 }
168 174  
169   -void vhost_net_reset_ubuf_info(struct vhost_net *n)
  175 +void vhost_net_vq_reset(struct vhost_net *n)
170 176 {
171 177 int i;
172 178  
... ... @@ -176,6 +182,8 @@
176 182 n->vqs[i].ubufs = NULL;
177 183 kfree(n->vqs[i].ubuf_info);
178 184 n->vqs[i].ubuf_info = NULL;
  185 + n->vqs[i].vhost_hlen = 0;
  186 + n->vqs[i].sock_hlen = 0;
179 187 }
180 188  
181 189 }
182 190  
... ... @@ -302,8 +310,8 @@
302 310 * read-size critical section for our kind of RCU. */
303 311 static void handle_tx(struct vhost_net *net)
304 312 {
305   - struct vhost_virtqueue *vq = &net->vqs[VHOST_NET_VQ_TX].vq;
306 313 struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX];
  314 + struct vhost_virtqueue *vq = &nvq->vq;
307 315 unsigned out, in, s;
308 316 int head;
309 317 struct msghdr msg = {
... ... @@ -329,7 +337,7 @@
329 337 mutex_lock(&vq->mutex);
330 338 vhost_disable_notify(&net->dev, vq);
331 339  
332   - hdr_size = vq->vhost_hlen;
  340 + hdr_size = nvq->vhost_hlen;
333 341 zcopy = nvq->ubufs;
334 342  
335 343 for (;;) {
336 344  
... ... @@ -369,14 +377,14 @@
369 377 break;
370 378 }
371 379 /* Skip header. TODO: support TSO. */
372   - s = move_iovec_hdr(vq->iov, vq->hdr, hdr_size, out);
  380 + s = move_iovec_hdr(vq->iov, nvq->hdr, hdr_size, out);
373 381 msg.msg_iovlen = out;
374 382 len = iov_length(vq->iov, out);
375 383 /* Sanity check */
376 384 if (!len) {
377 385 vq_err(vq, "Unexpected header len for TX: "
378 386 "%zd expected %zd\n",
379   - iov_length(vq->hdr, s), hdr_size);
  387 + iov_length(nvq->hdr, s), hdr_size);
380 388 break;
381 389 }
382 390 zcopy_used = zcopy && (len >= VHOST_GOODCOPY_LEN ||
... ... @@ -523,7 +531,8 @@
523 531 * read-size critical section for our kind of RCU. */
524 532 static void handle_rx(struct vhost_net *net)
525 533 {
526   - struct vhost_virtqueue *vq = &net->vqs[VHOST_NET_VQ_RX].vq;
  534 + struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_RX];
  535 + struct vhost_virtqueue *vq = &nvq->vq;
527 536 unsigned uninitialized_var(in), log;
528 537 struct vhost_log *vq_log;
529 538 struct msghdr msg = {
... ... @@ -551,8 +560,8 @@
551 560  
552 561 mutex_lock(&vq->mutex);
553 562 vhost_disable_notify(&net->dev, vq);
554   - vhost_hlen = vq->vhost_hlen;
555   - sock_hlen = vq->sock_hlen;
  563 + vhost_hlen = nvq->vhost_hlen;
  564 + sock_hlen = nvq->sock_hlen;
556 565  
557 566 vq_log = unlikely(vhost_has_feature(&net->dev, VHOST_F_LOG_ALL)) ?
558 567 vq->log : NULL;
559 568  
... ... @@ -582,11 +591,11 @@
582 591 /* We don't need to be notified again. */
583 592 if (unlikely((vhost_hlen)))
584 593 /* Skip header. TODO: support TSO. */
585   - move_iovec_hdr(vq->iov, vq->hdr, vhost_hlen, in);
  594 + move_iovec_hdr(vq->iov, nvq->hdr, vhost_hlen, in);
586 595 else
587 596 /* Copy the header for use in VIRTIO_NET_F_MRG_RXBUF:
588 597 * needed because recvmsg can modify msg_iov. */
589   - copy_iovec_hdr(vq->iov, vq->hdr, sock_hlen, in);
  598 + copy_iovec_hdr(vq->iov, nvq->hdr, sock_hlen, in);
590 599 msg.msg_iovlen = in;
591 600 err = sock->ops->recvmsg(NULL, sock, &msg,
592 601 sock_len, MSG_DONTWAIT | MSG_TRUNC);
... ... @@ -600,7 +609,7 @@
600 609 continue;
601 610 }
602 611 if (unlikely(vhost_hlen) &&
603   - memcpy_toiovecend(vq->hdr, (unsigned char *)&hdr, 0,
  612 + memcpy_toiovecend(nvq->hdr, (unsigned char *)&hdr, 0,
604 613 vhost_hlen)) {
605 614 vq_err(vq, "Unable to write vnet_hdr at addr %p\n",
606 615 vq->iov->iov_base);
... ... @@ -608,7 +617,7 @@
608 617 }
609 618 /* TODO: Should check and handle checksum. */
610 619 if (likely(mergeable) &&
611   - memcpy_toiovecend(vq->hdr, (unsigned char *)&headcount,
  620 + memcpy_toiovecend(nvq->hdr, (unsigned char *)&headcount,
612 621 offsetof(typeof(hdr), num_buffers),
613 622 sizeof hdr.num_buffers)) {
614 623 vq_err(vq, "Failed num_buffers write");
... ... @@ -686,6 +695,8 @@
686 695 n->vqs[i].ubuf_info = NULL;
687 696 n->vqs[i].upend_idx = 0;
688 697 n->vqs[i].done_idx = 0;
  698 + n->vqs[i].vhost_hlen = 0;
  699 + n->vqs[i].sock_hlen = 0;
689 700 }
690 701 r = vhost_dev_init(dev, vqs, VHOST_NET_VQ_MAX);
691 702 if (r < 0) {
... ... @@ -783,7 +794,7 @@
783 794 vhost_net_flush(n);
784 795 vhost_dev_stop(&n->dev);
785 796 vhost_dev_cleanup(&n->dev, false);
786   - vhost_net_reset_ubuf_info(n);
  797 + vhost_net_vq_reset(n);
787 798 if (tx_sock)
788 799 fput(tx_sock->file);
789 800 if (rx_sock)
... ... @@ -964,7 +975,7 @@
964 975 vhost_net_stop(n, &tx_sock, &rx_sock);
965 976 vhost_net_flush(n);
966 977 err = vhost_dev_reset_owner(&n->dev);
967   - vhost_net_reset_ubuf_info(n);
  978 + vhost_net_vq_reset(n);
968 979 done:
969 980 mutex_unlock(&n->dev.mutex);
970 981 if (tx_sock)
... ... @@ -1001,8 +1012,8 @@
1001 1012 smp_wmb();
1002 1013 for (i = 0; i < VHOST_NET_VQ_MAX; ++i) {
1003 1014 mutex_lock(&n->vqs[i].vq.mutex);
1004   - n->vqs[i].vq.vhost_hlen = vhost_hlen;
1005   - n->vqs[i].vq.sock_hlen = sock_hlen;
  1015 + n->vqs[i].vhost_hlen = vhost_hlen;
  1016 + n->vqs[i].sock_hlen = sock_hlen;
1006 1017 mutex_unlock(&n->vqs[i].vq.mutex);
1007 1018 }
1008 1019 vhost_net_flush(n);
drivers/vhost/vhost.c
... ... @@ -179,8 +179,6 @@
179 179 vq->used_flags = 0;
180 180 vq->log_used = false;
181 181 vq->log_addr = -1ull;
182   - vq->vhost_hlen = 0;
183   - vq->sock_hlen = 0;
184 182 vq->private_data = NULL;
185 183 vq->log_base = NULL;
186 184 vq->error_ctx = NULL;
drivers/vhost/vhost.h
... ... @@ -102,10 +102,7 @@
102 102 /* hdr is used to store the virtio header.
103 103 * Since each iovec has >= 1 byte length, we never need more than
104 104 * header length entries to store the header. */
105   - struct iovec hdr[sizeof(struct virtio_net_hdr_mrg_rxbuf)];
106 105 struct iovec *indirect;
107   - size_t vhost_hlen;
108   - size_t sock_hlen;
109 106 struct vring_used_elem *heads;
110 107 /* We use a kind of RCU to access private pointer.
111 108 * All readers access it from worker, which makes it possible to