FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
vhost_user_output.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * vhost-user-output
4  *
5  * Copyright (c) 2014-2018 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <stddef.h>
21 #include <fcntl.h> /* for open */
22 #include <sys/ioctl.h>
23 #include <sys/socket.h>
24 #include <sys/un.h>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27 #include <sys/uio.h> /* for iovec */
28 #include <netinet/in.h>
29 #include <sys/vfs.h>
30 
31 #include <linux/if_arp.h>
32 #include <linux/if_tun.h>
33 
34 #include <vlib/vlib.h>
35 #include <vlib/unix/unix.h>
36 
37 #include <vnet/ethernet/ethernet.h>
38 #include <vnet/devices/devices.h>
39 #include <vnet/feature/feature.h>
40 
43 
45 /*
46  * On the transmit side, we keep processing the buffers from vlib in the while
47  * loop and prepare the copy order to be executed later. However, the static
48  * array which we keep the copy order is limited to VHOST_USER_COPY_ARRAY_N
49  * entries. In order to not corrupt memory, we have to do the copy when the
50  * static array reaches the copy threshold. We subtract 40 in case the code
51  * goes into the inner loop for a maximum of 64k frames which may require
52  * more array entries. We subtract 200 because our default buffer size is
53  * 2048 and the default desc len is likely 1536. While it takes less than 40
54  * vlib buffers for the jumbo frame, it may take twice as much descriptors
55  * for the same jumbo frame. Use 200 for the extra head room.
56  */
57 #define VHOST_USER_TX_COPY_THRESHOLD (VHOST_USER_COPY_ARRAY_N - 200)
58 
60 
61 #define foreach_vhost_user_tx_func_error \
62  _(NONE, "no error") \
63  _(NOT_READY, "vhost vring not ready") \
64  _(DOWN, "vhost interface is down") \
65  _(PKT_DROP_NOBUF, "tx packet drops (no available descriptors)") \
66  _(PKT_DROP_NOMRG, "tx packet drops (cannot merge descriptors)") \
67  _(MMAP_FAIL, "mmap failure") \
68  _(INDIRECT_OVERFLOW, "indirect descriptor table overflow")
69 
70 typedef enum
71 {
72 #define _(f,s) VHOST_USER_TX_FUNC_ERROR_##f,
74 #undef _
77 
78 static __clib_unused char *vhost_user_tx_func_error_strings[] = {
79 #define _(n,s) s,
81 #undef _
82 };
83 
84 static __clib_unused u8 *
85 format_vhost_user_interface_name (u8 * s, va_list * args)
86 {
87  u32 i = va_arg (*args, u32);
88  u32 show_dev_instance = ~0;
90 
92  show_dev_instance = vum->show_dev_instance_by_real_dev_instance[i];
93 
94  if (show_dev_instance != ~0)
95  i = show_dev_instance;
96 
97  s = format (s, "VirtualEthernet0/0/%d", i);
98  return s;
99 }
100 
101 static __clib_unused int
103 {
104  // FIXME: check if the new dev instance is already used
107  hi->dev_instance);
108 
110  hi->dev_instance, ~0);
111 
112  vum->show_dev_instance_by_real_dev_instance[hi->dev_instance] =
113  new_dev_instance;
114 
115  vu_log_debug (vui, "renumbered vhost-user interface dev_instance %d to %d",
116  hi->dev_instance, new_dev_instance);
117 
118  return 0;
119 }
120 
121 /**
122  * @brief Spin until the vring is successfully locked
123  */
126 {
128 }
129 
130 /**
131  * @brief Unlock the vring lock
132  */
135 {
137 }
138 
141  vhost_user_intf_t * vui, u16 qid,
143 {
145  u32 last_avail_idx = rxvq->last_avail_idx;
146  u32 desc_current = rxvq->avail->ring[last_avail_idx & rxvq->qsz_mask];
147  vring_desc_t *hdr_desc = 0;
148  u32 hint = 0;
149 
150  clib_memset (t, 0, sizeof (*t));
151  t->device_index = vui - vum->vhost_user_interfaces;
152  t->qid = qid;
153 
154  hdr_desc = &rxvq->desc[desc_current];
155  if (rxvq->desc[desc_current].flags & VRING_DESC_F_INDIRECT)
156  {
157  t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_INDIRECT;
158  /* Header is the first here */
159  hdr_desc = map_guest_mem (vui, rxvq->desc[desc_current].addr, &hint);
160  }
161  if (rxvq->desc[desc_current].flags & VRING_DESC_F_NEXT)
162  {
163  t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_SIMPLE_CHAINED;
164  }
165  if (!(rxvq->desc[desc_current].flags & VRING_DESC_F_NEXT) &&
166  !(rxvq->desc[desc_current].flags & VRING_DESC_F_INDIRECT))
167  {
168  t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_SINGLE_DESC;
169  }
170 
171  t->first_desc_len = hdr_desc ? hdr_desc->len : 0;
172 }
173 
176  u16 copy_len, u32 * map_hint)
177 {
178  void *dst0, *dst1, *dst2, *dst3;
179  if (PREDICT_TRUE (copy_len >= 4))
180  {
181  if (PREDICT_FALSE (!(dst2 = map_guest_mem (vui, cpy[0].dst, map_hint))))
182  return 1;
183  if (PREDICT_FALSE (!(dst3 = map_guest_mem (vui, cpy[1].dst, map_hint))))
184  return 1;
185  while (PREDICT_TRUE (copy_len >= 4))
186  {
187  dst0 = dst2;
188  dst1 = dst3;
189 
190  if (PREDICT_FALSE
191  (!(dst2 = map_guest_mem (vui, cpy[2].dst, map_hint))))
192  return 1;
193  if (PREDICT_FALSE
194  (!(dst3 = map_guest_mem (vui, cpy[3].dst, map_hint))))
195  return 1;
196 
197  CLIB_PREFETCH ((void *) cpy[2].src, 64, LOAD);
198  CLIB_PREFETCH ((void *) cpy[3].src, 64, LOAD);
199 
200  clib_memcpy_fast (dst0, (void *) cpy[0].src, cpy[0].len);
201  clib_memcpy_fast (dst1, (void *) cpy[1].src, cpy[1].len);
202 
203  vhost_user_log_dirty_pages_2 (vui, cpy[0].dst, cpy[0].len, 1);
204  vhost_user_log_dirty_pages_2 (vui, cpy[1].dst, cpy[1].len, 1);
205  copy_len -= 2;
206  cpy += 2;
207  }
208  }
209  while (copy_len)
210  {
211  if (PREDICT_FALSE (!(dst0 = map_guest_mem (vui, cpy->dst, map_hint))))
212  return 1;
213  clib_memcpy_fast (dst0, (void *) cpy->src, cpy->len);
214  vhost_user_log_dirty_pages_2 (vui, cpy->dst, cpy->len, 1);
215  copy_len -= 1;
216  cpy += 1;
217  }
218  return 0;
219 }
220 
223  virtio_net_hdr_t * hdr)
224 {
225  generic_header_offset_t gho = { 0 };
226  int is_ip4 = b->flags & VNET_BUFFER_F_IS_IP4;
227  int is_ip6 = b->flags & VNET_BUFFER_F_IS_IP6;
228  vnet_buffer_oflags_t oflags = vnet_buffer (b)->oflags;
229 
230  ASSERT (!(is_ip4 && is_ip6));
231  vnet_generic_header_offset_parser (b, &gho, 1 /* l2 */ , is_ip4, is_ip6);
232  if (oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM)
233  {
234  ip4_header_t *ip4;
235 
236  ip4 =
238  ip4->checksum = ip4_header_checksum (ip4);
239  }
240 
241  /* checksum offload */
242  if (oflags & VNET_BUFFER_OFFLOAD_F_UDP_CKSUM)
243  {
244  hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
245  hdr->csum_start = gho.l4_hdr_offset;
246  hdr->csum_offset = offsetof (udp_header_t, checksum);
247  }
248  else if (oflags & VNET_BUFFER_OFFLOAD_F_TCP_CKSUM)
249  {
250  hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
251  hdr->csum_start = gho.l4_hdr_offset;
252  hdr->csum_offset = offsetof (tcp_header_t, checksum);
253  }
254 
255  /* GSO offload */
256  if (b->flags & VNET_BUFFER_F_GSO)
257  {
258  if (oflags & VNET_BUFFER_OFFLOAD_F_TCP_CKSUM)
259  {
260  if (is_ip4 &&
261  (vui->features & VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO4)))
262  {
263  hdr->gso_size = vnet_buffer2 (b)->gso_size;
264  hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
265  }
266  else if (is_ip6 &&
267  (vui->features & VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO6)))
268  {
269  hdr->gso_size = vnet_buffer2 (b)->gso_size;
270  hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
271  }
272  }
273  else if ((vui->features & VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_UFO)) &&
274  (oflags & VNET_BUFFER_OFFLOAD_F_UDP_CKSUM))
275  {
276  hdr->gso_size = vnet_buffer2 (b)->gso_size;
277  hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP;
278  }
279  }
280 }
281 
284  vhost_user_vring_t * rxvq,
285  u16 * n_descs_processed, u8 chained,
287 {
288  u16 desc_idx, flags;
289  vring_packed_desc_t *desc_table = rxvq->packed_desc;
290  u16 last_used_idx = rxvq->last_used_idx;
291 
292  if (PREDICT_FALSE (*n_descs_processed == 0))
293  return;
294 
295  if (rxvq->used_wrap_counter)
296  flags = desc_table[last_used_idx & rxvq->qsz_mask].flags |
298  else
299  flags = desc_table[last_used_idx & rxvq->qsz_mask].flags &
301 
303 
304  for (desc_idx = 1; desc_idx < *n_descs_processed; desc_idx++)
305  {
306  if (rxvq->used_wrap_counter)
307  desc_table[rxvq->last_used_idx & rxvq->qsz_mask].flags |=
309  else
310  desc_table[rxvq->last_used_idx & rxvq->qsz_mask].flags &=
313  }
314 
315  desc_table[last_used_idx & rxvq->qsz_mask].flags = flags;
316 
317  *n_descs_processed = 0;
318 
319  if (chained)
320  {
321  vring_packed_desc_t *desc_table = rxvq->packed_desc;
322 
323  while (desc_table[rxvq->last_used_idx & rxvq->qsz_mask].flags &
326 
327  /* Advance past the current chained table entries */
329  }
330 
331  /* interrupt (call) handling */
332  if ((rxvq->callfd_idx != ~0) &&
333  (rxvq->avail_event->flags != VRING_EVENT_F_DISABLE))
334  {
336 
337  rxvq->n_since_last_int += frame->n_vectors - n_left;
338  if (rxvq->n_since_last_int > vum->coalesce_frames)
339  vhost_user_send_call (vm, vui, rxvq);
340  }
341 }
342 
345  u16 qid, vlib_buffer_t * b,
346  vhost_user_vring_t * rxvq)
347 {
349  u32 last_avail_idx = rxvq->last_avail_idx;
350  u32 desc_current = last_avail_idx & rxvq->qsz_mask;
351  vring_packed_desc_t *hdr_desc = 0;
352  u32 hint = 0;
353 
354  clib_memset (t, 0, sizeof (*t));
355  t->device_index = vui - vum->vhost_user_interfaces;
356  t->qid = qid;
357 
358  hdr_desc = &rxvq->packed_desc[desc_current];
359  if (rxvq->packed_desc[desc_current].flags & VRING_DESC_F_INDIRECT)
360  {
361  t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_INDIRECT;
362  /* Header is the first here */
363  hdr_desc = map_guest_mem (vui, rxvq->packed_desc[desc_current].addr,
364  &hint);
365  }
366  if (rxvq->packed_desc[desc_current].flags & VRING_DESC_F_NEXT)
367  {
368  t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_SIMPLE_CHAINED;
369  }
370  if (!(rxvq->packed_desc[desc_current].flags & VRING_DESC_F_NEXT) &&
371  !(rxvq->packed_desc[desc_current].flags & VRING_DESC_F_INDIRECT))
372  {
373  t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_SINGLE_DESC;
374  }
375 
376  t->first_desc_len = hdr_desc ? hdr_desc->len : 0;
377 }
378 
382 {
383  u32 *buffers = vlib_frame_vector_args (frame);
384  u32 n_left = frame->n_vectors;
386  vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
387  vhost_user_intf_t *vui =
389  u32 qid;
390  vhost_user_vring_t *rxvq;
391  u8 error;
393  vhost_cpu_t *cpu = &vum->cpus[thread_index];
394  u32 map_hint = 0;
395  u8 retry = 8;
396  u16 copy_len;
397  u16 tx_headers_len;
398  vring_packed_desc_t *desc_table;
399  u32 or_flags;
400  u16 desc_head, desc_index, desc_len;
401  u16 n_descs_processed;
402  u8 indirect, chained;
403 
404  qid = VHOST_VRING_IDX_RX (*vec_elt_at_index (vui->per_cpu_tx_qid,
405  thread_index));
406  rxvq = &vui->vrings[qid];
407 
408 retry:
409  error = VHOST_USER_TX_FUNC_ERROR_NONE;
410  tx_headers_len = 0;
411  copy_len = 0;
412  n_descs_processed = 0;
413 
414  while (n_left > 0)
415  {
416  vlib_buffer_t *b0, *current_b0;
417  uword buffer_map_addr;
418  u32 buffer_len;
419  u16 bytes_left;
420  u32 total_desc_len = 0;
421  u16 n_entries = 0;
422 
423  indirect = 0;
424  chained = 0;
425  if (PREDICT_TRUE (n_left > 1))
426  vlib_prefetch_buffer_with_index (vm, buffers[1], LOAD);
427 
428  b0 = vlib_get_buffer (vm, buffers[0]);
429  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
430  {
431  cpu->current_trace = vlib_add_trace (vm, node, b0,
432  sizeof (*cpu->current_trace));
433  vhost_user_tx_trace_packed (cpu->current_trace, vui, qid / 2, b0,
434  rxvq);
435  }
436 
437  desc_table = rxvq->packed_desc;
438  desc_head = desc_index = rxvq->last_avail_idx & rxvq->qsz_mask;
439  if (PREDICT_FALSE (!vhost_user_packed_desc_available (rxvq, desc_head)))
440  {
441  error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
442  goto done;
443  }
444  /*
445  * Go deeper in case of indirect descriptor.
446  * To test it, turn off mrg_rxbuf.
447  */
448  if (desc_table[desc_head].flags & VRING_DESC_F_INDIRECT)
449  {
450  indirect = 1;
451  if (PREDICT_FALSE (desc_table[desc_head].len <
452  sizeof (vring_packed_desc_t)))
453  {
454  error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
455  goto done;
456  }
457  n_entries = desc_table[desc_head].len >> 4;
458  desc_table = map_guest_mem (vui, desc_table[desc_index].addr,
459  &map_hint);
460  if (PREDICT_FALSE (desc_table == 0))
461  {
462  error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
463  goto done;
464  }
465  desc_index = 0;
466  }
467  else if (rxvq->packed_desc[desc_head].flags & VRING_DESC_F_NEXT)
468  chained = 1;
469 
470  desc_len = vui->virtio_net_hdr_sz;
471  buffer_map_addr = desc_table[desc_index].addr;
472  buffer_len = desc_table[desc_index].len;
473 
474  /* Get a header from the header array */
475  virtio_net_hdr_mrg_rxbuf_t *hdr = &cpu->tx_headers[tx_headers_len];
476  tx_headers_len++;
477  hdr->hdr.flags = 0;
478  hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_NONE;
479  hdr->num_buffers = 1;
480 
481  or_flags = (b0->flags & VNET_BUFFER_F_OFFLOAD);
482 
483  /* Guest supports csum offload and buffer requires checksum offload? */
484  if (or_flags &&
485  (vui->features & VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_CSUM)))
486  vhost_user_handle_tx_offload (vui, b0, &hdr->hdr);
487 
488  /* Prepare a copy order executed later for the header */
489  ASSERT (copy_len < VHOST_USER_COPY_ARRAY_N);
490  vhost_copy_t *cpy = &cpu->copy[copy_len];
491  copy_len++;
492  cpy->len = vui->virtio_net_hdr_sz;
493  cpy->dst = buffer_map_addr;
494  cpy->src = (uword) hdr;
495 
496  buffer_map_addr += vui->virtio_net_hdr_sz;
497  buffer_len -= vui->virtio_net_hdr_sz;
498  bytes_left = b0->current_length;
499  current_b0 = b0;
500  while (1)
501  {
502  if (buffer_len == 0)
503  {
504  /* Get new output */
505  if (chained)
506  {
507  /*
508  * Next one is chained
509  * Test it with both indirect and mrg_rxbuf off
510  */
511  if (PREDICT_FALSE (!(desc_table[desc_index].flags &
513  {
514  /*
515  * Last descriptor in chain.
516  * Dequeue queued descriptors for this packet
517  */
519  &n_descs_processed);
520  error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
521  goto done;
522  }
524  desc_index = rxvq->last_avail_idx & rxvq->qsz_mask;
525  n_descs_processed++;
526  buffer_map_addr = desc_table[desc_index].addr;
527  buffer_len = desc_table[desc_index].len;
528  total_desc_len += desc_len;
529  desc_len = 0;
530  }
531  else if (indirect)
532  {
533  /*
534  * Indirect table
535  * Test it with mrg_rxnuf off
536  */
537  if (PREDICT_TRUE (n_entries > 0))
538  n_entries--;
539  else
540  {
541  /* Dequeue queued descriptors for this packet */
543  &n_descs_processed);
544  error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
545  goto done;
546  }
547  total_desc_len += desc_len;
548  desc_index = (desc_index + 1) & rxvq->qsz_mask;
549  buffer_map_addr = desc_table[desc_index].addr;
550  buffer_len = desc_table[desc_index].len;
551  desc_len = 0;
552  }
553  else if (vui->virtio_net_hdr_sz == 12)
554  {
555  /*
556  * MRG is available
557  * This is the default setting for the guest VM
558  */
559  virtio_net_hdr_mrg_rxbuf_t *hdr =
560  &cpu->tx_headers[tx_headers_len - 1];
561 
562  desc_table[desc_index].len = desc_len;
564  desc_head = desc_index =
565  rxvq->last_avail_idx & rxvq->qsz_mask;
566  hdr->num_buffers++;
567  n_descs_processed++;
568  desc_len = 0;
569 
571  (rxvq, desc_index)))
572  {
573  /* Dequeue queued descriptors for this packet */
574  vhost_user_dequeue_descs (rxvq, hdr,
575  &n_descs_processed);
576  error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
577  goto done;
578  }
579 
580  buffer_map_addr = desc_table[desc_index].addr;
581  buffer_len = desc_table[desc_index].len;
582  }
583  else
584  {
585  error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOMRG;
586  goto done;
587  }
588  }
589 
590  ASSERT (copy_len < VHOST_USER_COPY_ARRAY_N);
591  vhost_copy_t *cpy = &cpu->copy[copy_len];
592  copy_len++;
593  cpy->len = bytes_left;
594  cpy->len = (cpy->len > buffer_len) ? buffer_len : cpy->len;
595  cpy->dst = buffer_map_addr;
596  cpy->src = (uword) vlib_buffer_get_current (current_b0) +
597  current_b0->current_length - bytes_left;
598 
599  bytes_left -= cpy->len;
600  buffer_len -= cpy->len;
601  buffer_map_addr += cpy->len;
602  desc_len += cpy->len;
603 
605 
606  /* Check if vlib buffer has more data. If not, get more or break */
607  if (PREDICT_TRUE (!bytes_left))
608  {
609  if (PREDICT_FALSE
610  (current_b0->flags & VLIB_BUFFER_NEXT_PRESENT))
611  {
612  current_b0 = vlib_get_buffer (vm, current_b0->next_buffer);
613  bytes_left = current_b0->current_length;
614  }
615  else
616  {
617  /* End of packet */
618  break;
619  }
620  }
621  }
622 
623  /* Move from available to used ring */
624  total_desc_len += desc_len;
625  rxvq->packed_desc[desc_head].len = total_desc_len;
626 
627  vhost_user_advance_last_avail_table_idx (vui, rxvq, chained);
628  n_descs_processed++;
629 
630  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
631  cpu->current_trace->hdr = cpu->tx_headers[tx_headers_len - 1];
632 
633  n_left--;
634 
635  /*
636  * Do the copy periodically to prevent
637  * cpu->copy array overflow and corrupt memory
638  */
639  if (PREDICT_FALSE (copy_len >= VHOST_USER_TX_COPY_THRESHOLD) || chained)
640  {
641  if (PREDICT_FALSE (vhost_user_tx_copy (vui, cpu->copy, copy_len,
642  &map_hint)))
643  vlib_error_count (vm, node->node_index,
644  VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
645  copy_len = 0;
646 
647  /* give buffers back to driver */
648  vhost_user_mark_desc_available (vm, vui, rxvq, &n_descs_processed,
649  chained, frame, n_left);
650  }
651 
652  buffers++;
653  }
654 
655 done:
656  if (PREDICT_TRUE (copy_len))
657  {
658  if (PREDICT_FALSE (vhost_user_tx_copy (vui, cpu->copy, copy_len,
659  &map_hint)))
660  vlib_error_count (vm, node->node_index,
661  VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
662 
663  vhost_user_mark_desc_available (vm, vui, rxvq, &n_descs_processed,
664  chained, frame, n_left);
665  }
666 
667  /*
668  * When n_left is set, error is always set to something too.
669  * In case error is due to lack of remaining buffers, we go back up and
670  * retry.
671  * The idea is that it is better to waste some time on packets
672  * that have been processed already than dropping them and get
673  * more fresh packets with a good likelyhood that they will be dropped too.
674  * This technique also gives more time to VM driver to pick-up packets.
675  * In case the traffic flows from physical to virtual interfaces, this
676  * technique will end-up leveraging the physical NIC buffer in order to
677  * absorb the VM's CPU jitter.
678  */
679  if (n_left && (error == VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF) && retry)
680  {
681  retry--;
682  goto retry;
683  }
684 
685  vhost_user_vring_unlock (vui, qid);
686 
687  if (PREDICT_FALSE (n_left && error != VHOST_USER_TX_FUNC_ERROR_NONE))
688  {
689  vlib_error_count (vm, node->node_index, error, n_left);
692  VNET_INTERFACE_COUNTER_DROP, thread_index, vui->sw_if_index, n_left);
693  }
694 
696  return frame->n_vectors;
697 }
698 
702 {
703  u32 *buffers = vlib_frame_vector_args (frame);
704  u32 n_left = frame->n_vectors;
706  vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
707  vhost_user_intf_t *vui =
709  u32 qid = ~0;
710  vhost_user_vring_t *rxvq;
711  u8 error;
713  vhost_cpu_t *cpu = &vum->cpus[thread_index];
714  u32 map_hint = 0;
715  u8 retry = 8;
716  u16 copy_len;
717  u16 tx_headers_len;
718  u32 or_flags;
719 
720  if (PREDICT_FALSE (!vui->admin_up))
721  {
722  error = VHOST_USER_TX_FUNC_ERROR_DOWN;
723  goto done3;
724  }
725 
726  if (PREDICT_FALSE (!vui->is_ready))
727  {
728  error = VHOST_USER_TX_FUNC_ERROR_NOT_READY;
729  goto done3;
730  }
731 
732  qid = VHOST_VRING_IDX_RX (*vec_elt_at_index (vui->per_cpu_tx_qid,
733  thread_index));
734  rxvq = &vui->vrings[qid];
735  if (PREDICT_FALSE (rxvq->avail == 0))
736  {
737  error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
738  goto done3;
739  }
740 
741  if (PREDICT_FALSE (vui->use_tx_spinlock))
742  vhost_user_vring_lock (vui, qid);
743 
746 
747 retry:
748  error = VHOST_USER_TX_FUNC_ERROR_NONE;
749  tx_headers_len = 0;
750  copy_len = 0;
751  while (n_left > 0)
752  {
753  vlib_buffer_t *b0, *current_b0;
754  u16 desc_head, desc_index, desc_len;
755  vring_desc_t *desc_table;
756  uword buffer_map_addr;
757  u32 buffer_len;
758  u16 bytes_left;
759 
760  if (PREDICT_TRUE (n_left > 1))
761  vlib_prefetch_buffer_with_index (vm, buffers[1], LOAD);
762 
763  b0 = vlib_get_buffer (vm, buffers[0]);
764 
765  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
766  {
767  cpu->current_trace = vlib_add_trace (vm, node, b0,
768  sizeof (*cpu->current_trace));
769  vhost_user_tx_trace (cpu->current_trace, vui, qid / 2, b0, rxvq);
770  }
771 
772  if (PREDICT_FALSE (rxvq->last_avail_idx == rxvq->avail->idx))
773  {
774  error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
775  goto done;
776  }
777 
778  desc_table = rxvq->desc;
779  desc_head = desc_index =
780  rxvq->avail->ring[rxvq->last_avail_idx & rxvq->qsz_mask];
781 
782  /* Go deeper in case of indirect descriptor
783  * I don't know of any driver providing indirect for RX. */
784  if (PREDICT_FALSE (rxvq->desc[desc_head].flags & VRING_DESC_F_INDIRECT))
785  {
786  if (PREDICT_FALSE
787  (rxvq->desc[desc_head].len < sizeof (vring_desc_t)))
788  {
789  error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
790  goto done;
791  }
792  if (PREDICT_FALSE
793  (!(desc_table =
794  map_guest_mem (vui, rxvq->desc[desc_index].addr,
795  &map_hint))))
796  {
797  error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
798  goto done;
799  }
800  desc_index = 0;
801  }
802 
803  desc_len = vui->virtio_net_hdr_sz;
804  buffer_map_addr = desc_table[desc_index].addr;
805  buffer_len = desc_table[desc_index].len;
806 
807  {
808  // Get a header from the header array
809  virtio_net_hdr_mrg_rxbuf_t *hdr = &cpu->tx_headers[tx_headers_len];
810  tx_headers_len++;
811  hdr->hdr.flags = 0;
812  hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_NONE;
813  hdr->num_buffers = 1; //This is local, no need to check
814 
815  or_flags = (b0->flags & VNET_BUFFER_F_OFFLOAD);
816 
817  /* Guest supports csum offload and buffer requires checksum offload? */
818  if (or_flags
819  && (vui->features & VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_CSUM)))
820  vhost_user_handle_tx_offload (vui, b0, &hdr->hdr);
821 
822  // Prepare a copy order executed later for the header
823  ASSERT (copy_len < VHOST_USER_COPY_ARRAY_N);
824  vhost_copy_t *cpy = &cpu->copy[copy_len];
825  copy_len++;
826  cpy->len = vui->virtio_net_hdr_sz;
827  cpy->dst = buffer_map_addr;
828  cpy->src = (uword) hdr;
829  }
830 
831  buffer_map_addr += vui->virtio_net_hdr_sz;
832  buffer_len -= vui->virtio_net_hdr_sz;
833  bytes_left = b0->current_length;
834  current_b0 = b0;
835  while (1)
836  {
837  if (buffer_len == 0)
838  { //Get new output
839  if (desc_table[desc_index].flags & VRING_DESC_F_NEXT)
840  {
841  //Next one is chained
842  desc_index = desc_table[desc_index].next;
843  buffer_map_addr = desc_table[desc_index].addr;
844  buffer_len = desc_table[desc_index].len;
845  }
846  else if (vui->virtio_net_hdr_sz == 12) //MRG is available
847  {
848  virtio_net_hdr_mrg_rxbuf_t *hdr =
849  &cpu->tx_headers[tx_headers_len - 1];
850 
851  //Move from available to used buffer
852  rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].id =
853  desc_head;
854  rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].len =
855  desc_len;
856  vhost_user_log_dirty_ring (vui, rxvq,
857  ring[rxvq->last_used_idx &
858  rxvq->qsz_mask]);
859 
860  rxvq->last_avail_idx++;
861  rxvq->last_used_idx++;
862  hdr->num_buffers++;
863  desc_len = 0;
864 
865  if (PREDICT_FALSE
866  (rxvq->last_avail_idx == rxvq->avail->idx))
867  {
868  //Dequeue queued descriptors for this packet
869  rxvq->last_used_idx -= hdr->num_buffers - 1;
870  rxvq->last_avail_idx -= hdr->num_buffers - 1;
871  error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
872  goto done;
873  }
874 
875  desc_table = rxvq->desc;
876  desc_head = desc_index =
877  rxvq->avail->ring[rxvq->last_avail_idx & rxvq->qsz_mask];
878  if (PREDICT_FALSE
879  (rxvq->desc[desc_head].flags & VRING_DESC_F_INDIRECT))
880  {
881  //It is seriously unlikely that a driver will put indirect descriptor
882  //after non-indirect descriptor.
883  if (PREDICT_FALSE
884  (rxvq->desc[desc_head].len < sizeof (vring_desc_t)))
885  {
886  error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
887  goto done;
888  }
889  if (PREDICT_FALSE
890  (!(desc_table =
891  map_guest_mem (vui,
892  rxvq->desc[desc_index].addr,
893  &map_hint))))
894  {
895  error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
896  goto done;
897  }
898  desc_index = 0;
899  }
900  buffer_map_addr = desc_table[desc_index].addr;
901  buffer_len = desc_table[desc_index].len;
902  }
903  else
904  {
905  error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOMRG;
906  goto done;
907  }
908  }
909 
910  {
911  ASSERT (copy_len < VHOST_USER_COPY_ARRAY_N);
912  vhost_copy_t *cpy = &cpu->copy[copy_len];
913  copy_len++;
914  cpy->len = bytes_left;
915  cpy->len = (cpy->len > buffer_len) ? buffer_len : cpy->len;
916  cpy->dst = buffer_map_addr;
917  cpy->src = (uword) vlib_buffer_get_current (current_b0) +
918  current_b0->current_length - bytes_left;
919 
920  bytes_left -= cpy->len;
921  buffer_len -= cpy->len;
922  buffer_map_addr += cpy->len;
923  desc_len += cpy->len;
924 
925  CLIB_PREFETCH (&rxvq->desc, CLIB_CACHE_LINE_BYTES, LOAD);
926  }
927 
928  // Check if vlib buffer has more data. If not, get more or break.
929  if (PREDICT_TRUE (!bytes_left))
930  {
931  if (PREDICT_FALSE
932  (current_b0->flags & VLIB_BUFFER_NEXT_PRESENT))
933  {
934  current_b0 = vlib_get_buffer (vm, current_b0->next_buffer);
935  bytes_left = current_b0->current_length;
936  }
937  else
938  {
939  //End of packet
940  break;
941  }
942  }
943  }
944 
945  //Move from available to used ring
946  rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].id = desc_head;
947  rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].len = desc_len;
948  vhost_user_log_dirty_ring (vui, rxvq,
949  ring[rxvq->last_used_idx & rxvq->qsz_mask]);
950  rxvq->last_avail_idx++;
951  rxvq->last_used_idx++;
952 
953  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
954  {
955  cpu->current_trace->hdr = cpu->tx_headers[tx_headers_len - 1];
956  }
957 
958  n_left--; //At the end for error counting when 'goto done' is invoked
959 
960  /*
961  * Do the copy periodically to prevent
962  * cpu->copy array overflow and corrupt memory
963  */
965  {
966  if (PREDICT_FALSE (vhost_user_tx_copy (vui, cpu->copy, copy_len,
967  &map_hint)))
968  {
969  vlib_error_count (vm, node->node_index,
970  VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
971  }
972  copy_len = 0;
973 
974  /* give buffers back to driver */
976  rxvq->used->idx = rxvq->last_used_idx;
977  vhost_user_log_dirty_ring (vui, rxvq, idx);
978  }
979  buffers++;
980  }
981 
982 done:
983  //Do the memory copies
984  if (PREDICT_FALSE (vhost_user_tx_copy (vui, cpu->copy, copy_len,
985  &map_hint)))
986  {
987  vlib_error_count (vm, node->node_index,
988  VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
989  }
990 
992  rxvq->used->idx = rxvq->last_used_idx;
993  vhost_user_log_dirty_ring (vui, rxvq, idx);
994 
995  /*
996  * When n_left is set, error is always set to something too.
997  * In case error is due to lack of remaining buffers, we go back up and
998  * retry.
999  * The idea is that it is better to waste some time on packets
1000  * that have been processed already than dropping them and get
1001  * more fresh packets with a good likelihood that they will be dropped too.
1002  * This technique also gives more time to VM driver to pick-up packets.
1003  * In case the traffic flows from physical to virtual interfaces, this
1004  * technique will end-up leveraging the physical NIC buffer in order to
1005  * absorb the VM's CPU jitter.
1006  */
1007  if (n_left && (error == VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF) && retry)
1008  {
1009  retry--;
1010  goto retry;
1011  }
1012 
1013  /* interrupt (call) handling */
1014  if ((rxvq->callfd_idx != ~0) &&
1016  {
1017  rxvq->n_since_last_int += frame->n_vectors - n_left;
1018 
1019  if (rxvq->n_since_last_int > vum->coalesce_frames)
1020  vhost_user_send_call (vm, vui, rxvq);
1021  }
1022 
1023  vhost_user_vring_unlock (vui, qid);
1024 
1025 done3:
1026  if (PREDICT_FALSE (n_left && error != VHOST_USER_TX_FUNC_ERROR_NONE))
1027  {
1028  vlib_error_count (vm, node->node_index, error, n_left);
1032  thread_index, vui->sw_if_index, n_left);
1033  }
1034 
1036  return frame->n_vectors;
1037 }
1038 
1039 static __clib_unused clib_error_t *
1042 {
1043  vlib_main_t *vm = vnm->vlib_main;
1044  vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
1046  vhost_user_intf_t *vui =
1048  vhost_user_vring_t *txvq = &vui->vrings[VHOST_VRING_IDX_TX (qid)];
1049 
1052  {
1053  if (txvq->kickfd_idx == ~0)
1054  {
1055  // We cannot support interrupt mode if the driver opts out
1056  return clib_error_return (0, "Driver does not support interrupt");
1057  }
1058  if (txvq->mode == VNET_HW_IF_RX_MODE_POLLING)
1059  {
1060  vum->ifq_count++;
1061  // Start the timer if this is the first encounter on interrupt
1062  // interface/queue
1063  if ((vum->ifq_count == 1) &&
1064  (vum->coalesce_time > 0.0) && (vum->coalesce_frames > 0))
1068  }
1069  }
1070  else if (mode == VNET_HW_IF_RX_MODE_POLLING)
1071  {
1072  if (((txvq->mode == VNET_HW_IF_RX_MODE_INTERRUPT) ||
1073  (txvq->mode == VNET_HW_IF_RX_MODE_ADAPTIVE)) && vum->ifq_count)
1074  {
1075  vum->ifq_count--;
1076  // Stop the timer if there is no more interrupt interface/queue
1077  if ((vum->ifq_count == 0) &&
1078  (vum->coalesce_time > 0.0) && (vum->coalesce_frames > 0))
1082  }
1083  }
1084 
1085  txvq->mode = mode;
1088  else if ((mode == VNET_HW_IF_RX_MODE_ADAPTIVE) ||
1090  txvq->used->flags = 0;
1091  else
1092  {
1093  vu_log_err (vui, "unhandled mode %d changed for if %d queue %d", mode,
1094  hw_if_index, qid);
1095  return clib_error_return (0, "unsupported");
1096  }
1097 
1098  return 0;
1099 }
1100 
1101 static __clib_unused clib_error_t *
1103  u32 flags)
1104 {
1105  vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
1107  vhost_user_intf_t *vui =
1109  u8 link_old, link_new;
1110 
1111  link_old = vui_is_link_up (vui);
1112 
1114 
1115  link_new = vui_is_link_up (vui);
1116 
1117  if (link_old != link_new)
1118  vnet_hw_interface_set_flags (vnm, vui->hw_if_index, link_new ?
1120 
1121  return /* no error */ 0;
1122 }
1123 
1124 /* *INDENT-OFF* */
1126  .name = "vhost-user",
1127  .tx_function_n_errors = VHOST_USER_TX_FUNC_N_ERROR,
1128  .tx_function_error_strings = vhost_user_tx_func_error_strings,
1129  .format_device_name = format_vhost_user_interface_name,
1130  .name_renumber = vhost_user_name_renumber,
1131  .admin_up_down_function = vhost_user_interface_admin_up_down,
1132  .rx_mode_change_function = vhost_user_interface_rx_mode_change,
1133  .format_tx_trace = format_vhost_trace,
1134 };
1135 
1136 /* *INDENT-ON* */
1137 
1138 /*
1139  * fd.io coding-style-patch-verification: ON
1140  *
1141  * Local Variables:
1142  * eval: (c-set-style "gnu")
1143  * End:
1144  */
vhost_trace_t::qid
u16 qid
Definition: vhost_user.h:302
vlib.h
vlib_buffer_t::next_buffer
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:149
vhost_user_send_call
static_always_inline void vhost_user_send_call(vlib_main_t *vm, vhost_user_intf_t *vui, vhost_user_vring_t *vq)
Definition: vhost_user_inline.h:364
vlib_buffer_free
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: buffer_funcs.h:982
vhost_user_vring_t
Definition: vhost_user.h:180
vhost_user_vring_t::mode
u32 mode
Definition: vhost_user.h:219
VIRTIO_NET_HDR_GSO_NONE
#define VIRTIO_NET_HDR_GSO_NONE
Definition: virtio_std.h:143
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:492
vhost_user_inline.h
vui_is_link_up
static_always_inline u8 vui_is_link_up(vhost_user_intf_t *vui)
Definition: vhost_user_inline.h:379
VNET_HW_IF_RX_MODE_ADAPTIVE
@ VNET_HW_IF_RX_MODE_ADAPTIVE
Definition: interface.h:58
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
vnet_device_class_t
struct _vnet_device_class vnet_device_class_t
vhost_user_device_class
vnet_device_class_t vhost_user_device_class
vhost_user_log_dirty_pages_2
static_always_inline void vhost_user_log_dirty_pages_2(vhost_user_intf_t *vui, u64 addr, u64 len, u8 is_host_address)
Definition: vhost_user_inline.h:175
vhost_user_vring_unlock
static_always_inline void vhost_user_vring_unlock(vhost_user_intf_t *vui, u32 qid)
Unlock the vring lock.
Definition: vhost_user_output.c:134
ip4
vl_api_ip4_address_t ip4
Definition: one.api:376
vhost_user_intf_t::features
u64 features
Definition: vhost_user.h:252
vring_used_t::flags
u16 flags
Definition: virtio_std.h:117
vhost_user_intf_t::hw_if_index
u32 hw_if_index
Definition: vhost_user.h:249
clib_spinlock_lock_if_init
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:106
vhost_user_main_t::ifq_count
u32 ifq_count
Definition: vhost_user.h:345
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
vring_avail_t::ring
u16 ring[0]
Definition: virtio_std.h:105
vhost_user_main_t
Definition: vhost_user.h:328
generic_header_offset_t::l4_hdr_offset
i16 l4_hdr_offset
Definition: hdr_offset_parser.h:74
tcp_header_t
struct _tcp_header tcp_header_t
VNET_DEVICE_CLASS
VNET_DEVICE_CLASS(vhost_user_device_class)
vhost_copy_t::dst
uword dst
Definition: vhost_user.h:295
vhost_user_interface_rx_mode_change
static __clib_unused clib_error_t * vhost_user_interface_rx_mode_change(vnet_main_t *vnm, u32 hw_if_index, u32 qid, vnet_hw_if_rx_mode mode)
Definition: vhost_user_output.c:1040
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
vnet_buffer_oflags_t
vnet_buffer_oflags_t
Definition: buffer.h:118
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
format_vhost_user_interface_name
static __clib_unused u8 * format_vhost_user_interface_name(u8 *s, va_list *args)
Definition: vhost_user_output.c:85
u16
unsigned short u16
Definition: types.h:57
vring_desc_t::addr
u64 addr
Definition: virtio_std.h:95
vhost_trace_t::device_index
u16 device_index
The interface queue index (Not the virtio vring idx)
Definition: vhost_user.h:303
mode
vl_api_tunnel_mode_t mode
Definition: gre.api:48
VHOST_USER_TX_COPY_THRESHOLD
#define VHOST_USER_TX_COPY_THRESHOLD
Definition: vhost_user_output.c:57
VNET_SW_INTERFACE_FLAG_ADMIN_UP
@ VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:843
VNET_HW_IF_RX_MODE_POLLING
@ VNET_HW_IF_RX_MODE_POLLING
Definition: interface.h:56
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vhost_cpu_t::copy
vhost_copy_t copy[VHOST_USER_COPY_ARRAY_N]
Definition: vhost_user.h:318
vhost_user_advance_last_avail_table_idx
static_always_inline void vhost_user_advance_last_avail_table_idx(vhost_user_intf_t *vui, vhost_user_vring_t *vring, u8 chained)
Definition: vhost_user_inline.h:422
VRING_DESC_F_USED
#define VRING_DESC_F_USED
Definition: virtio_std.h:76
VNET_HW_INTERFACE_FLAG_LINK_UP
@ VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:509
VIRTIO_FEATURE
#define VIRTIO_FEATURE(X)
Definition: virtio_std.h:67
vhost_user_main_t::coalesce_time
f64 coalesce_time
Definition: vhost_user.h:335
vnet_interface_main_t::sw_if_counters
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:1022
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
vnet_buffer2
#define vnet_buffer2(b)
Definition: buffer.h:499
vring_used_elem_t::id
u32 id
Definition: virtio_std.h:111
vnet_hw_interface_t::dev_instance
u32 dev_instance
Definition: interface.h:660
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
vhost_user_vring_t::avail_event
vring_desc_event_t * avail_event
Definition: vhost_user.h:195
vlib_error_count
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
Definition: error_funcs.h:57
vlib_frame_t
Definition: node.h:372
vhost_user_log_dirty_ring
#define vhost_user_log_dirty_ring(vui, vq, member)
Definition: vhost_user_inline.h:203
vlib_process_signal_event
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:1019
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
vhost_user_tx_func_error_strings
static __clib_unused char * vhost_user_tx_func_error_strings[]
Definition: vhost_user_output.c:78
vhost_cpu_t
Definition: vhost_user.h:312
udp_header_t
Definition: udp_packet.h:45
ip4_header_t
Definition: ip4_packet.h:87
vhost_user_packed_desc_available
static_always_inline u8 vhost_user_packed_desc_available(vhost_user_vring_t *vring, u16 idx)
Definition: vhost_user_inline.h:404
ethernet.h
VNET_DEVICE_CLASS_TX_FN
#define VNET_DEVICE_CLASS_TX_FN(devclass)
Definition: interface.h:317
error
Definition: cJSON.c:88
vhost_user_device_class_packed
static_always_inline uword vhost_user_device_class_packed(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: vhost_user_output.c:380
VHOST_USER_TX_FUNC_N_ERROR
@ VHOST_USER_TX_FUNC_N_ERROR
Definition: vhost_user_output.c:75
VHOST_VRING_IDX_RX
#define VHOST_VRING_IDX_RX(qid)
Definition: vhost_user.h:33
vhost_copy_t
Definition: vhost_user.h:293
CLIB_PREFETCH
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
vhost_user_is_packed_ring_supported
static_always_inline u64 vhost_user_is_packed_ring_supported(vhost_user_intf_t *vui)
Definition: vhost_user_inline.h:252
vlib_increment_simple_counter
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 increment)
Increment a simple counter.
Definition: counter.h:74
VIRTIO_NET_HDR_GSO_TCPV4
#define VIRTIO_NET_HDR_GSO_TCPV4
Definition: virtio_std.h:144
vhost_user_tx_func_error_t
vhost_user_tx_func_error_t
Definition: vhost_user_output.c:70
vhost_user_advance_last_used_idx
static_always_inline void vhost_user_advance_last_used_idx(vhost_user_vring_t *vring)
Definition: vhost_user_inline.h:475
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
len
u8 len
Definition: ip_types.api:103
vhost_user_handle_tx_offload
static_always_inline void vhost_user_handle_tx_offload(vhost_user_intf_t *vui, vlib_buffer_t *b, virtio_net_hdr_t *hdr)
Definition: vhost_user_output.c:222
vnet_interface_output_runtime_t::dev_instance
u32 dev_instance
Definition: interface_funcs.h:476
vhost_user_tx_trace
static_always_inline void vhost_user_tx_trace(vhost_trace_t *t, vhost_user_intf_t *vui, u16 qid, vlib_buffer_t *b, vhost_user_vring_t *rxvq)
Definition: vhost_user_output.c:140
feature.h
vring_desc_t::flags
u16 flags
Definition: virtio_std.h:97
vring_desc_t
Definition: virtio_std.h:93
VHOST_USER_EVENT_STOP_TIMER
#define VHOST_USER_EVENT_STOP_TIMER
Definition: vhost_user.h:237
vring_avail_t::flags
u16 flags
Definition: virtio_std.h:103
VRING_DESC_F_AVAIL
#define VRING_DESC_F_AVAIL
Definition: virtio_std.h:75
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
vhost_trace_t::virtio_ring_flags
u32 virtio_ring_flags
The device index.
Definition: vhost_user.h:304
vnet_get_hw_interface
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface_funcs.h:44
vhost_trace_t::hdr
virtio_net_hdr_mrg_rxbuf_t hdr
Length of the first data descriptor.
Definition: vhost_user.h:306
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
vhost_user_interface_admin_up_down
static __clib_unused clib_error_t * vhost_user_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: vhost_user_output.c:1102
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
vnet_hw_if_rx_mode
vnet_hw_if_rx_mode
Definition: interface.h:53
static_always_inline
#define static_always_inline
Definition: clib.h:112
VRING_DESC_F_INDIRECT
#define VRING_DESC_F_INDIRECT
Definition: virtio_std.h:73
vlib_prefetch_buffer_with_index
#define vlib_prefetch_buffer_with_index(vm, bi, type)
Prefetch buffer metadata by buffer index The first 64 bytes of buffer contains most header informatio...
Definition: buffer_funcs.h:507
vu_log_err
#define vu_log_err(dev, f,...)
Definition: vhost_user.h:58
uword
u64 uword
Definition: types.h:112
VIRTIO_NET_HDR_GSO_UDP
#define VIRTIO_NET_HDR_GSO_UDP
Definition: virtio_std.h:145
vhost_copy_t::src
uword src
Definition: vhost_user.h:296
vlib_main_t::thread_index
u32 thread_index
Definition: main.h:213
vhost_cpu_t::current_trace
vhost_trace_t * current_trace
Definition: vhost_user.h:322
VNET_HW_IF_RX_MODE_INTERRUPT
@ VNET_HW_IF_RX_MODE_INTERRUPT
Definition: interface.h:57
VRING_DESC_F_NEXT
#define VRING_DESC_F_NEXT
Definition: virtio_std.h:71
vhost_user_vring_t::last_used_idx
u16 last_used_idx
Definition: vhost_user.h:185
vhost_user_main_t::coalesce_frames
u32 coalesce_frames
Definition: vhost_user.h:334
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
vhost_user_vring_t::packed_desc
vring_packed_desc_t * packed_desc
Definition: vhost_user.h:190
vring_desc_t::len
u32 len
Definition: virtio_std.h:96
vhost_user_intf_t::vrings
vhost_user_vring_t * vrings
Definition: vhost_user.h:265
vnet_main_t::vlib_main
vlib_main_t * vlib_main
Definition: vnet.h:111
vhost_user_vring_t::last_avail_idx
u16 last_avail_idx
Definition: vhost_user.h:184
src
vl_api_address_t src
Definition: gre.api:54
VRING_AVAIL_F_NO_INTERRUPT
#define VRING_AVAIL_F_NO_INTERRUPT
Definition: virtio_std.h:91
CLIB_MEMORY_BARRIER
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:137
VHOST_VRING_IDX_TX
#define VHOST_VRING_IDX_TX(qid)
Definition: vhost_user.h:34
vhost_user_tx_copy
static_always_inline u32 vhost_user_tx_copy(vhost_user_intf_t *vui, vhost_copy_t *cpy, u16 copy_len, u32 *map_hint)
Definition: vhost_user_output.c:175
VRING_USED_F_NO_NOTIFY
#define VRING_USED_F_NO_NOTIFY
Definition: virtio_std.h:90
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
vhost_user_vring_t::callfd_idx
u32 callfd_idx
Definition: vhost_user.h:214
vhost_user_main_t::cpus
vhost_cpu_t * cpus
Per-CPU data for vhost-user.
Definition: vhost_user.h:339
vlib_buffer_t::current_length
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:122
vhost_user_dequeue_descs
static_always_inline void vhost_user_dequeue_descs(vhost_user_vring_t *rxvq, virtio_net_hdr_mrg_rxbuf_t *hdr, u16 *n_descs_processed)
Definition: vhost_user_inline.h:452
vhost_user_name_renumber
static __clib_unused int vhost_user_name_renumber(vnet_hw_interface_t *hi, u32 new_dev_instance)
Definition: vhost_user_output.c:102
vhost_user_vring_t::desc
vring_desc_t * desc
Definition: vhost_user.h:189
generic_header_offset_t::l3_hdr_offset
i16 l3_hdr_offset
Definition: hdr_offset_parser.h:73
vhost_user_vring_t::avail
vring_avail_t * avail
Definition: vhost_user.h:194
VHOST_USER_COPY_ARRAY_N
#define VHOST_USER_COPY_ARRAY_N
Definition: vhost_user.h:310
vhost_user_dequeue_chained_descs
static_always_inline void vhost_user_dequeue_chained_descs(vhost_user_vring_t *rxvq, u16 *n_descs_processed)
Definition: vhost_user_inline.h:464
is_ip6
bool is_ip6
Definition: ip.api:43
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
vhost_user_intf_t::admin_up
u32 admin_up
Definition: vhost_user.h:243
VHOST_USER_EVENT_START_TIMER
#define VHOST_USER_EVENT_START_TIMER
Definition: vhost_user.h:236
vhost_user_vring_lock
static_always_inline void vhost_user_vring_lock(vhost_user_intf_t *vui, u32 qid)
Spin until the vring is successfully locked.
Definition: vhost_user_output.c:125
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
foreach_vhost_user_tx_func_error
#define foreach_vhost_user_tx_func_error
Definition: vhost_user_output.c:61
vhost_user_main_t::show_dev_instance_by_real_dev_instance
u32 * show_dev_instance_by_real_dev_instance
Definition: vhost_user.h:333
vec_validate_init_empty
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header,...
Definition: vec.h:570
vhost_user_main
vhost_user_main_t vhost_user_main
Definition: vhost_user.c:55
u32
unsigned int u32
Definition: types.h:88
vhost_trace_t
Definition: vhost_user.h:300
VIRTIO_NET_HDR_GSO_TCPV6
#define VIRTIO_NET_HDR_GSO_TCPV6
Definition: virtio_std.h:146
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
vhost_user_mark_desc_available
static_always_inline void vhost_user_mark_desc_available(vlib_main_t *vm, vhost_user_intf_t *vui, vhost_user_vring_t *rxvq, u16 *n_descs_processed, u8 chained, vlib_frame_t *frame, u32 n_left)
Definition: vhost_user_output.c:283
generic_header_offset_t
Definition: hdr_offset_parser.h:65
vhost_user_vring_t::used_wrap_counter
u16 used_wrap_counter
Definition: vhost_user.h:229
n_left
u32 n_left
Definition: interface_output.c:1078
vring_used_t::idx
u16 idx
Definition: virtio_std.h:118
VIRTIO_NET_HDR_F_NEEDS_CSUM
#define VIRTIO_NET_HDR_F_NEEDS_CSUM
Definition: virtio_std.h:140
vnet_main
vnet_main_t vnet_main
Definition: misc.c:43
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
vhost_user_intf_t
Definition: vhost_user.h:239
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
format_vhost_trace
static_always_inline u8 * format_vhost_trace(u8 *s, va_list *va)
Definition: vhost_user_inline.h:210
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vnet_hw_interface_set_flags
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
Definition: interface.c:513
vnet_generic_header_offset_parser
static_always_inline void vnet_generic_header_offset_parser(vlib_buffer_t *b0, generic_header_offset_t *gho, int is_l2, int is_ip4, int is_ip6)
Definition: hdr_offset_parser.h:471
unix.h
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
ip4_header_checksum
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:314
vhost_user.h
vring_used_t::ring
vring_used_elem_t ring[0]
Definition: virtio_std.h:119
map_guest_mem
static_always_inline void * map_guest_mem(vhost_user_intf_t *vui, uword addr, u32 *hint)
Definition: vhost_user_inline.h:21
vhost_user_vring_t::vring_lock
clib_spinlock_t vring_lock
Definition: vhost_user.h:209
vhost_user_vring_t::kickfd_idx
u32 kickfd_idx
Definition: vhost_user.h:215
vring_desc_t::next
u16 next
Definition: virtio_std.h:98
devices.h
vu_log_debug
#define vu_log_debug(dev, f,...)
Definition: vhost_user.h:45
vhost_user_main_t::vhost_user_interfaces
vhost_user_intf_t * vhost_user_interfaces
Definition: vhost_user.h:332
vhost_user_vring_t::used
vring_used_t * used
Definition: vhost_user.h:199
vlib_node_runtime_t
Definition: node.h:454
clib_spinlock_unlock_if_init
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:129
vring_used_elem_t::len
u32 len
Definition: virtio_std.h:112
vhost_trace_t::first_desc_len
u16 first_desc_len
Runtime queue flags
Definition: vhost_user.h:305
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125
vhost_user_vring_t::qsz_mask
u16 qsz_mask
Definition: vhost_user.h:183
hdr_offset_parser.h
vring_avail_t::idx
u16 idx
Definition: virtio_std.h:104
vhost_user_send_interrupt_node
vlib_node_registration_t vhost_user_send_interrupt_node
(constructor) VLIB_REGISTER_NODE (vhost_user_send_interrupt_node)
Definition: vhost_user.c:52
vhost_copy_t::len
u32 len
Definition: vhost_user.h:297
VNET_INTERFACE_COUNTER_DROP
@ VNET_INTERFACE_COUNTER_DROP
Definition: interface.h:903
vhost_user_advance_last_avail_idx
static_always_inline void vhost_user_advance_last_avail_idx(vhost_user_vring_t *vring)
Definition: vhost_user_inline.h:411
vnet_main_t::interface_main
vnet_interface_main_t interface_main
Definition: vnet.h:81
vhost_cpu_t::tx_headers
virtio_net_hdr_mrg_rxbuf_t tx_headers[VLIB_FRAME_SIZE]
Definition: vhost_user.h:317
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
vnet_interface_output_runtime_t
Definition: interface_funcs.h:472
vhost_user_tx_trace_packed
static_always_inline void vhost_user_tx_trace_packed(vhost_trace_t *t, vhost_user_intf_t *vui, u16 qid, vlib_buffer_t *b, vhost_user_vring_t *rxvq)
Definition: vhost_user_output.c:344
vhost_user_vring_t::n_since_last_int
u16 n_since_last_int
Definition: vhost_user.h:186
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105