FD.io VPP  v19.08.3-2-gbabecb413
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/ip/ip.h>
38 
39 #include <vnet/ethernet/ethernet.h>
40 #include <vnet/devices/devices.h>
41 #include <vnet/feature/feature.h>
42 
46 
47 /*
48  * On the transmit side, we keep processing the buffers from vlib in the while
49  * loop and prepare the copy order to be executed later. However, the static
50  * array which we keep the copy order is limited to VHOST_USER_COPY_ARRAY_N
51  * entries. In order to not corrupt memory, we have to do the copy when the
52  * static array reaches the copy threshold. We subtract 40 in case the code
53  * goes into the inner loop for a maximum of 64k frames which may require
54  * more array entries. We subtract 200 because our default buffer size is
55  * 2048 and the default desc len is likely 1536. While it takes less than 40
56  * vlib buffers for the jumbo frame, it may take twice as much descriptors
57  * for the same jumbo frame. Use 200 for the extra head room.
58  */
59 #define VHOST_USER_TX_COPY_THRESHOLD (VHOST_USER_COPY_ARRAY_N - 200)
60 
62 
63 #define foreach_vhost_user_tx_func_error \
64  _(NONE, "no error") \
65  _(NOT_READY, "vhost vring not ready") \
66  _(DOWN, "vhost interface is down") \
67  _(PKT_DROP_NOBUF, "tx packet drops (no available descriptors)") \
68  _(PKT_DROP_NOMRG, "tx packet drops (cannot merge descriptors)") \
69  _(MMAP_FAIL, "mmap failure") \
70  _(INDIRECT_OVERFLOW, "indirect descriptor table overflow")
71 
72 typedef enum
73 {
74 #define _(f,s) VHOST_USER_TX_FUNC_ERROR_##f,
76 #undef _
79 
80 static __clib_unused char *vhost_user_tx_func_error_strings[] = {
81 #define _(n,s) s,
83 #undef _
84 };
85 
86 static __clib_unused u8 *
87 format_vhost_user_interface_name (u8 * s, va_list * args)
88 {
89  u32 i = va_arg (*args, u32);
90  u32 show_dev_instance = ~0;
92 
94  show_dev_instance = vum->show_dev_instance_by_real_dev_instance[i];
95 
96  if (show_dev_instance != ~0)
97  i = show_dev_instance;
98 
99  s = format (s, "VirtualEthernet0/0/%d", i);
100  return s;
101 }
102 
103 static __clib_unused int
105 {
106  // FIXME: check if the new dev instance is already used
109  hi->dev_instance);
110 
112  hi->dev_instance, ~0);
113 
115  new_dev_instance;
116 
117  vu_log_debug (vui, "renumbered vhost-user interface dev_instance %d to %d",
118  hi->dev_instance, new_dev_instance);
119 
120  return 0;
121 }
122 
123 /**
124  * @brief Try once to lock the vring
125  * @return 0 on success, non-zero on failure.
126  */
129 {
130  return clib_atomic_test_and_set (vui->vring_locks[qid]);
131 }
132 
133 /**
134  * @brief Spin until the vring is successfully locked
135  */
138 {
139  while (vhost_user_vring_try_lock (vui, qid))
140  ;
141 }
142 
143 /**
144  * @brief Unlock the vring lock
145  */
148 {
149  clib_atomic_release (vui->vring_locks[qid]);
150 }
151 
154  vhost_user_intf_t * vui, u16 qid,
155  vlib_buffer_t * b, vhost_user_vring_t * rxvq)
156 {
158  u32 last_avail_idx = rxvq->last_avail_idx;
159  u32 desc_current = rxvq->avail->ring[last_avail_idx & rxvq->qsz_mask];
160  vring_desc_t *hdr_desc = 0;
161  u32 hint = 0;
162 
163  clib_memset (t, 0, sizeof (*t));
164  t->device_index = vui - vum->vhost_user_interfaces;
165  t->qid = qid;
166 
167  hdr_desc = &rxvq->desc[desc_current];
168  if (rxvq->desc[desc_current].flags & VIRTQ_DESC_F_INDIRECT)
169  {
170  t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_INDIRECT;
171  /* Header is the first here */
172  hdr_desc = map_guest_mem (vui, rxvq->desc[desc_current].addr, &hint);
173  }
174  if (rxvq->desc[desc_current].flags & VIRTQ_DESC_F_NEXT)
175  {
176  t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_SIMPLE_CHAINED;
177  }
178  if (!(rxvq->desc[desc_current].flags & VIRTQ_DESC_F_NEXT) &&
179  !(rxvq->desc[desc_current].flags & VIRTQ_DESC_F_INDIRECT))
180  {
181  t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_SINGLE_DESC;
182  }
183 
184  t->first_desc_len = hdr_desc ? hdr_desc->len : 0;
185 }
186 
189  u16 copy_len, u32 * map_hint)
190 {
191  void *dst0, *dst1, *dst2, *dst3;
192  if (PREDICT_TRUE (copy_len >= 4))
193  {
194  if (PREDICT_FALSE (!(dst2 = map_guest_mem (vui, cpy[0].dst, map_hint))))
195  return 1;
196  if (PREDICT_FALSE (!(dst3 = map_guest_mem (vui, cpy[1].dst, map_hint))))
197  return 1;
198  while (PREDICT_TRUE (copy_len >= 4))
199  {
200  dst0 = dst2;
201  dst1 = dst3;
202 
203  if (PREDICT_FALSE
204  (!(dst2 = map_guest_mem (vui, cpy[2].dst, map_hint))))
205  return 1;
206  if (PREDICT_FALSE
207  (!(dst3 = map_guest_mem (vui, cpy[3].dst, map_hint))))
208  return 1;
209 
210  CLIB_PREFETCH ((void *) cpy[2].src, 64, LOAD);
211  CLIB_PREFETCH ((void *) cpy[3].src, 64, LOAD);
212 
213  clib_memcpy_fast (dst0, (void *) cpy[0].src, cpy[0].len);
214  clib_memcpy_fast (dst1, (void *) cpy[1].src, cpy[1].len);
215 
216  vhost_user_log_dirty_pages_2 (vui, cpy[0].dst, cpy[0].len, 1);
217  vhost_user_log_dirty_pages_2 (vui, cpy[1].dst, cpy[1].len, 1);
218  copy_len -= 2;
219  cpy += 2;
220  }
221  }
222  while (copy_len)
223  {
224  if (PREDICT_FALSE (!(dst0 = map_guest_mem (vui, cpy->dst, map_hint))))
225  return 1;
226  clib_memcpy_fast (dst0, (void *) cpy->src, cpy->len);
227  vhost_user_log_dirty_pages_2 (vui, cpy->dst, cpy->len, 1);
228  copy_len -= 1;
229  cpy += 1;
230  }
231  return 0;
232 }
233 
236  virtio_net_hdr_t * hdr)
237 {
238  /* checksum offload */
239  if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
240  {
241  hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
242  hdr->csum_start = vnet_buffer (b)->l4_hdr_offset;
243  hdr->csum_offset = offsetof (udp_header_t, checksum);
244  }
245  else if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
246  {
247  hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
248  hdr->csum_start = vnet_buffer (b)->l4_hdr_offset;
249  hdr->csum_offset = offsetof (tcp_header_t, checksum);
250  }
251 
252  /* GSO offload */
253  if (b->flags & VNET_BUFFER_F_GSO)
254  {
255  if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
256  {
257  if ((b->flags & VNET_BUFFER_F_IS_IP4) &&
258  (vui->features & (1ULL << FEAT_VIRTIO_NET_F_GUEST_TSO4)))
259  {
260  hdr->gso_size = vnet_buffer2 (b)->gso_size;
261  hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
262  }
263  else if ((b->flags & VNET_BUFFER_F_IS_IP6) &&
264  (vui->features & (1ULL << FEAT_VIRTIO_NET_F_GUEST_TSO6)))
265  {
266  hdr->gso_size = vnet_buffer2 (b)->gso_size;
267  hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
268  }
269  }
270  else if ((vui->features & (1ULL << FEAT_VIRTIO_NET_F_GUEST_UFO)) &&
271  (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
272  {
273  hdr->gso_size = vnet_buffer2 (b)->gso_size;
274  hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP;
275  }
276  }
277 }
278 
281  node, vlib_frame_t * frame)
282 {
283  u32 *buffers = vlib_frame_vector_args (frame);
284  u32 n_left = frame->n_vectors;
286  vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
287  vhost_user_intf_t *vui =
289  u32 qid = ~0;
290  vhost_user_vring_t *rxvq;
291  u8 error;
292  u32 thread_index = vm->thread_index;
293  vhost_cpu_t *cpu = &vum->cpus[thread_index];
294  u32 map_hint = 0;
295  u8 retry = 8;
296  u16 copy_len;
297  u16 tx_headers_len;
298  u32 or_flags;
299 
300  if (PREDICT_FALSE (!vui->admin_up))
301  {
302  error = VHOST_USER_TX_FUNC_ERROR_DOWN;
303  goto done3;
304  }
305 
306  if (PREDICT_FALSE (!vui->is_ready))
307  {
308  error = VHOST_USER_TX_FUNC_ERROR_NOT_READY;
309  goto done3;
310  }
311 
312  qid = VHOST_VRING_IDX_RX (*vec_elt_at_index (vui->per_cpu_tx_qid,
313  thread_index));
314  rxvq = &vui->vrings[qid];
315  if (PREDICT_FALSE (rxvq->avail == 0))
316  {
317  error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
318  goto done3;
319  }
320 
321  if (PREDICT_FALSE (vui->use_tx_spinlock))
322  vhost_user_vring_lock (vui, qid);
323 
324 retry:
325  error = VHOST_USER_TX_FUNC_ERROR_NONE;
326  tx_headers_len = 0;
327  copy_len = 0;
328  while (n_left > 0)
329  {
330  vlib_buffer_t *b0, *current_b0;
331  u16 desc_head, desc_index, desc_len;
332  vring_desc_t *desc_table;
333  uword buffer_map_addr;
334  u32 buffer_len;
335  u16 bytes_left;
336 
337  if (PREDICT_TRUE (n_left > 1))
338  vlib_prefetch_buffer_with_index (vm, buffers[1], LOAD);
339 
340  b0 = vlib_get_buffer (vm, buffers[0]);
341 
342  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
343  {
344  cpu->current_trace = vlib_add_trace (vm, node, b0,
345  sizeof (*cpu->current_trace));
346  vhost_user_tx_trace (cpu->current_trace, vui, qid / 2, b0, rxvq);
347  }
348 
349  if (PREDICT_FALSE (rxvq->last_avail_idx == rxvq->avail->idx))
350  {
351  error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
352  goto done;
353  }
354 
355  desc_table = rxvq->desc;
356  desc_head = desc_index =
357  rxvq->avail->ring[rxvq->last_avail_idx & rxvq->qsz_mask];
358 
359  /* Go deeper in case of indirect descriptor
360  * I don't know of any driver providing indirect for RX. */
361  if (PREDICT_FALSE (rxvq->desc[desc_head].flags & VIRTQ_DESC_F_INDIRECT))
362  {
363  if (PREDICT_FALSE
364  (rxvq->desc[desc_head].len < sizeof (vring_desc_t)))
365  {
366  error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
367  goto done;
368  }
369  if (PREDICT_FALSE
370  (!(desc_table =
371  map_guest_mem (vui, rxvq->desc[desc_index].addr,
372  &map_hint))))
373  {
374  error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
375  goto done;
376  }
377  desc_index = 0;
378  }
379 
380  desc_len = vui->virtio_net_hdr_sz;
381  buffer_map_addr = desc_table[desc_index].addr;
382  buffer_len = desc_table[desc_index].len;
383 
384  {
385  // Get a header from the header array
386  virtio_net_hdr_mrg_rxbuf_t *hdr = &cpu->tx_headers[tx_headers_len];
387  tx_headers_len++;
388  hdr->hdr.flags = 0;
389  hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_NONE;
390  hdr->num_buffers = 1; //This is local, no need to check
391 
392  or_flags = (b0->flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM) ||
393  (b0->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM) ||
394  (b0->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM);
395 
396  /* Guest supports csum offload and buffer requires checksum offload? */
397  if (or_flags
398  && (vui->features & (1ULL << FEAT_VIRTIO_NET_F_GUEST_CSUM)))
399  vhost_user_handle_tx_offload (vui, b0, &hdr->hdr);
400 
401  // Prepare a copy order executed later for the header
402  ASSERT (copy_len < VHOST_USER_COPY_ARRAY_N);
403  vhost_copy_t *cpy = &cpu->copy[copy_len];
404  copy_len++;
405  cpy->len = vui->virtio_net_hdr_sz;
406  cpy->dst = buffer_map_addr;
407  cpy->src = (uword) hdr;
408  }
409 
410  buffer_map_addr += vui->virtio_net_hdr_sz;
411  buffer_len -= vui->virtio_net_hdr_sz;
412  bytes_left = b0->current_length;
413  current_b0 = b0;
414  while (1)
415  {
416  if (buffer_len == 0)
417  { //Get new output
418  if (desc_table[desc_index].flags & VIRTQ_DESC_F_NEXT)
419  {
420  //Next one is chained
421  desc_index = desc_table[desc_index].next;
422  buffer_map_addr = desc_table[desc_index].addr;
423  buffer_len = desc_table[desc_index].len;
424  }
425  else if (vui->virtio_net_hdr_sz == 12) //MRG is available
426  {
427  virtio_net_hdr_mrg_rxbuf_t *hdr =
428  &cpu->tx_headers[tx_headers_len - 1];
429 
430  //Move from available to used buffer
431  rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].id =
432  desc_head;
433  rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].len =
434  desc_len;
435  vhost_user_log_dirty_ring (vui, rxvq,
436  ring[rxvq->last_used_idx &
437  rxvq->qsz_mask]);
438 
439  rxvq->last_avail_idx++;
440  rxvq->last_used_idx++;
441  hdr->num_buffers++;
442  desc_len = 0;
443 
444  if (PREDICT_FALSE
445  (rxvq->last_avail_idx == rxvq->avail->idx))
446  {
447  //Dequeue queued descriptors for this packet
448  rxvq->last_used_idx -= hdr->num_buffers - 1;
449  rxvq->last_avail_idx -= hdr->num_buffers - 1;
450  error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
451  goto done;
452  }
453 
454  desc_table = rxvq->desc;
455  desc_head = desc_index =
456  rxvq->avail->ring[rxvq->last_avail_idx & rxvq->qsz_mask];
457  if (PREDICT_FALSE
458  (rxvq->desc[desc_head].flags & VIRTQ_DESC_F_INDIRECT))
459  {
460  //It is seriously unlikely that a driver will put indirect descriptor
461  //after non-indirect descriptor.
462  if (PREDICT_FALSE
463  (rxvq->desc[desc_head].len < sizeof (vring_desc_t)))
464  {
465  error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
466  goto done;
467  }
468  if (PREDICT_FALSE
469  (!(desc_table =
470  map_guest_mem (vui,
471  rxvq->desc[desc_index].addr,
472  &map_hint))))
473  {
474  error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
475  goto done;
476  }
477  desc_index = 0;
478  }
479  buffer_map_addr = desc_table[desc_index].addr;
480  buffer_len = desc_table[desc_index].len;
481  }
482  else
483  {
484  error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOMRG;
485  goto done;
486  }
487  }
488 
489  {
490  ASSERT (copy_len < VHOST_USER_COPY_ARRAY_N);
491  vhost_copy_t *cpy = &cpu->copy[copy_len];
492  copy_len++;
493  cpy->len = bytes_left;
494  cpy->len = (cpy->len > buffer_len) ? buffer_len : cpy->len;
495  cpy->dst = buffer_map_addr;
496  cpy->src = (uword) vlib_buffer_get_current (current_b0) +
497  current_b0->current_length - bytes_left;
498 
499  bytes_left -= cpy->len;
500  buffer_len -= cpy->len;
501  buffer_map_addr += cpy->len;
502  desc_len += cpy->len;
503 
504  CLIB_PREFETCH (&rxvq->desc, CLIB_CACHE_LINE_BYTES, LOAD);
505  }
506 
507  // Check if vlib buffer has more data. If not, get more or break.
508  if (PREDICT_TRUE (!bytes_left))
509  {
510  if (PREDICT_FALSE
511  (current_b0->flags & VLIB_BUFFER_NEXT_PRESENT))
512  {
513  current_b0 = vlib_get_buffer (vm, current_b0->next_buffer);
514  bytes_left = current_b0->current_length;
515  }
516  else
517  {
518  //End of packet
519  break;
520  }
521  }
522  }
523 
524  //Move from available to used ring
525  rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].id = desc_head;
526  rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].len = desc_len;
527  vhost_user_log_dirty_ring (vui, rxvq,
528  ring[rxvq->last_used_idx & rxvq->qsz_mask]);
529  rxvq->last_avail_idx++;
530  rxvq->last_used_idx++;
531 
532  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
533  {
534  cpu->current_trace->hdr = cpu->tx_headers[tx_headers_len - 1];
535  }
536 
537  n_left--; //At the end for error counting when 'goto done' is invoked
538 
539  /*
540  * Do the copy periodically to prevent
541  * cpu->copy array overflow and corrupt memory
542  */
544  {
545  if (PREDICT_FALSE (vhost_user_tx_copy (vui, cpu->copy, copy_len,
546  &map_hint)))
547  {
548  vlib_error_count (vm, node->node_index,
549  VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
550  }
551  copy_len = 0;
552 
553  /* give buffers back to driver */
555  rxvq->used->idx = rxvq->last_used_idx;
556  vhost_user_log_dirty_ring (vui, rxvq, idx);
557  }
558  buffers++;
559  }
560 
561 done:
562  //Do the memory copies
563  if (PREDICT_FALSE (vhost_user_tx_copy (vui, cpu->copy, copy_len,
564  &map_hint)))
565  {
566  vlib_error_count (vm, node->node_index,
567  VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
568  }
569 
571  rxvq->used->idx = rxvq->last_used_idx;
572  vhost_user_log_dirty_ring (vui, rxvq, idx);
573 
574  /*
575  * When n_left is set, error is always set to something too.
576  * In case error is due to lack of remaining buffers, we go back up and
577  * retry.
578  * The idea is that it is better to waste some time on packets
579  * that have been processed already than dropping them and get
580  * more fresh packets with a good likelyhood that they will be dropped too.
581  * This technique also gives more time to VM driver to pick-up packets.
582  * In case the traffic flows from physical to virtual interfaces, this
583  * technique will end-up leveraging the physical NIC buffer in order to
584  * absorb the VM's CPU jitter.
585  */
586  if (n_left && (error == VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF) && retry)
587  {
588  retry--;
589  goto retry;
590  }
591 
592  /* interrupt (call) handling */
593  if ((rxvq->callfd_idx != ~0) &&
595  {
596  rxvq->n_since_last_int += frame->n_vectors - n_left;
597 
598  if (rxvq->n_since_last_int > vum->coalesce_frames)
599  vhost_user_send_call (vm, rxvq);
600  }
601 
602  vhost_user_vring_unlock (vui, qid);
603 
604 done3:
605  if (PREDICT_FALSE (n_left && error != VHOST_USER_TX_FUNC_ERROR_NONE))
606  {
607  vlib_error_count (vm, node->node_index, error, n_left);
611  thread_index, vui->sw_if_index, n_left);
612  }
613 
614  vlib_buffer_free (vm, vlib_frame_vector_args (frame), frame->n_vectors);
615  return frame->n_vectors;
616 }
617 
618 static __clib_unused clib_error_t *
621 {
622  vlib_main_t *vm = vnm->vlib_main;
623  vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
625  vhost_user_intf_t *vui =
627  vhost_user_vring_t *txvq = &vui->vrings[VHOST_VRING_IDX_TX (qid)];
628 
629  if ((mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT) ||
631  {
632  if (txvq->kickfd_idx == ~0)
633  {
634  // We cannot support interrupt mode if the driver opts out
635  return clib_error_return (0, "Driver does not support interrupt");
636  }
638  {
639  vum->ifq_count++;
640  // Start the timer if this is the first encounter on interrupt
641  // interface/queue
642  if ((vum->ifq_count == 1) &&
643  (vum->coalesce_time > 0.0) && (vum->coalesce_frames > 0))
647  }
648  }
649  else if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
650  {
651  if (((txvq->mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT) ||
653  vum->ifq_count)
654  {
655  vum->ifq_count--;
656  // Stop the timer if there is no more interrupt interface/queue
657  if ((vum->ifq_count == 0) &&
658  (vum->coalesce_time > 0.0) && (vum->coalesce_frames > 0))
662  }
663  }
664 
665  txvq->mode = mode;
668  else if ((mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE) ||
670  txvq->used->flags = 0;
671  else
672  {
673  vu_log_err (vui, "unhandled mode %d changed for if %d queue %d", mode,
674  hw_if_index, qid);
675  return clib_error_return (0, "unsupported");
676  }
677 
678  return 0;
679 }
680 
681 static __clib_unused clib_error_t *
683  u32 flags)
684 {
685  vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
687  vhost_user_intf_t *vui =
689  u8 link_old, link_new;
690 
691  link_old = vui_is_link_up (vui);
692 
693  vui->admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
694 
695  link_new = vui_is_link_up (vui);
696 
697  if (link_old != link_new)
698  vnet_hw_interface_set_flags (vnm, vui->hw_if_index, link_new ?
700 
701  return /* no error */ 0;
702 }
703 
704 /* *INDENT-OFF* */
706  .name = "vhost-user",
707  .tx_function_n_errors = VHOST_USER_TX_FUNC_N_ERROR,
708  .tx_function_error_strings = vhost_user_tx_func_error_strings,
709  .format_device_name = format_vhost_user_interface_name,
710  .name_renumber = vhost_user_name_renumber,
711  .admin_up_down_function = vhost_user_interface_admin_up_down,
712  .rx_mode_change_function = vhost_user_interface_rx_mode_change,
713  .format_tx_trace = format_vhost_trace,
714 };
715 
716 /* *INDENT-ON* */
717 
718 /*
719  * fd.io coding-style-patch-verification: ON
720  *
721  * Local Variables:
722  * eval: (c-set-style "gnu")
723  * End:
724  */
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
u32 len
Definition: pci.h:212
static __clib_unused u8 * format_vhost_user_interface_name(u8 *s, va_list *args)
static __clib_unused int vhost_user_name_renumber(vnet_hw_interface_t *hi, u32 new_dev_instance)
vmrglw vmrglh hi
static __clib_unused clib_error_t * vhost_user_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
static_always_inline int vhost_user_vring_try_lock(vhost_user_intf_t *vui, u32 qid)
Try once to lock the vring.
u32 flags
Definition: vhost_user.h:141
vring_desc_t * desc
Definition: vhost_user.h:263
u32 virtio_ring_flags
The device index.
Definition: vhost_user.h:348
virtio_net_hdr_mrg_rxbuf_t hdr
Length of the first data descriptor.
Definition: vhost_user.h:350
vhost_cpu_t * cpus
Per-CPU data for vhost-user.
Definition: vhost_user.h:381
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:865
#define vnet_buffer2(b)
Definition: buffer.h:424
vhost_user_tx_func_error_t
#define foreach_vhost_user_tx_func_error
vnet_interface_main_t interface_main
Definition: vnet.h:56
#define PREDICT_TRUE(x)
Definition: clib.h:113
static __clib_unused char * vhost_user_tx_func_error_strings[]
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
Definition: error_funcs.h:57
#define VHOST_USER_TX_COPY_THRESHOLD
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
vring_used_elem_t ring[0]
Definition: pci.h:235
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vhost_copy_t copy[VHOST_USER_COPY_ARRAY_N]
Definition: vhost_user.h:363
u16 next
Definition: pci.h:214
vring_avail_t * avail
Definition: vhost_user.h:264
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
u32 thread_index
Definition: main.h:218
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
vl_api_address_t src
Definition: gre.api:51
int i
#define VHOST_USER_EVENT_START_TIMER
Definition: vhost_user.h:292
#define VRING_AVAIL_F_NO_INTERRUPT
Definition: vhost_user.h:46
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
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:78
u16 idx
Definition: pci.h:220
static_always_inline void vhost_user_vring_lock(vhost_user_intf_t *vui, u32 qid)
Spin until the vring is successfully locked.
u16 flags
Definition: pci.h:233
struct _vnet_device_class vnet_device_class_t
struct _tcp_header tcp_header_t
vring_used_t * used
Definition: vhost_user.h:265
vhost_trace_t * current_trace
Definition: vhost_user.h:367
unsigned char u8
Definition: types.h:56
#define vu_log_debug(dev, f,...)
Definition: vhost_user.h:48
u64 addr
Definition: pci.h:211
vnet_hw_interface_rx_mode
Definition: interface.h:53
#define static_always_inline
Definition: clib.h:100
#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:440
static_always_inline u32 vhost_user_tx_copy(vhost_user_intf_t *vui, vhost_copy_t *cpy, u16 copy_len, u32 *map_hint)
static_always_inline void * map_guest_mem(vhost_user_intf_t *vui, uword addr, u32 *hint)
#define VHOST_VRING_IDX_TX(qid)
Definition: vhost_user.h:24
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define VRING_USED_F_NO_NOTIFY
Definition: vhost_user.h:45
#define clib_error_return(e, args...)
Definition: error.h:99
static_always_inline u8 * format_vhost_trace(u8 *s, va_list *va)
#define VNET_DEVICE_CLASS_TX_FN(devclass)
Definition: interface.h:298
unsigned int u32
Definition: types.h:88
#define clib_atomic_test_and_set(a)
Definition: atomics.h:42
VNET_DEVICE_CLASS(vhost_user_device_class)
#define VHOST_USER_COPY_ARRAY_N
Definition: vhost_user.h:355
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
vlib_main_t * vlib_main
Definition: vnet.h:80
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:934
#define clib_atomic_release(a)
Definition: atomics.h:43
unsigned short u16
Definition: types.h:57
#define VIRTQ_DESC_F_INDIRECT
Definition: vhost_user.h:28
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
#define PREDICT_FALSE(x)
Definition: clib.h:112
vhost_user_main_t vhost_user_main
Definition: vhost_user.c:56
vnet_main_t vnet_main
Definition: misc.c:43
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:845
vl_api_address_t dst
Definition: gre.api:52
static_always_inline void vhost_user_vring_unlock(vhost_user_intf_t *vui, u32 qid)
Unlock the vring lock.
static_always_inline u8 vui_is_link_up(vhost_user_intf_t *vui)
u8 len
Definition: ip_types.api:90
#define VHOST_VRING_IDX_RX(qid)
Definition: vhost_user.h:23
vnet_device_class_t vhost_user_device_class
u32 * show_dev_instance_by_real_dev_instance
Definition: vhost_user.h:375
u16 device_index
The interface queue index (Not the virtio vring idx)
Definition: vhost_user.h:347
vhost_user_intf_t * vhost_user_interfaces
Definition: vhost_user.h:374
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
vlib_main_t * vm
Definition: buffer.c:323
static __clib_unused clib_error_t * vhost_user_interface_rx_mode_change(vnet_main_t *vnm, u32 hw_if_index, u32 qid, vnet_hw_interface_rx_mode mode)
#define VHOST_USER_EVENT_STOP_TIMER
Definition: vhost_user.h:293
u16 first_desc_len
Runtime queue flags.
Definition: vhost_user.h:349
vl_api_vxlan_gbp_api_tunnel_mode_t mode
Definition: vxlan_gbp.api:44
u16 flags
Definition: pci.h:219
#define ASSERT(truth)
#define vu_log_err(dev, f,...)
Definition: vhost_user.h:61
#define VIRTQ_DESC_F_NEXT
Definition: vhost_user.h:27
static_always_inline void vhost_user_send_call(vlib_main_t *vm, vhost_user_vring_t *vq)
volatile u32 * vring_locks[VHOST_VRING_MAX_N]
Definition: vhost_user.h:322
vlib_node_registration_t vhost_user_send_interrupt_node
(constructor) VLIB_REGISTER_NODE (vhost_user_send_interrupt_node)
Definition: vhost_user.c:53
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)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
u16 ring[0]
Definition: pci.h:221
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:140
vhost_user_vring_t vrings[VHOST_VRING_MAX_N]
Definition: vhost_user.h:321
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:492
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
static_always_inline void vhost_user_log_dirty_pages_2(vhost_user_intf_t *vui, u64 addr, u64 len, u8 is_host_address)
#define vhost_user_log_dirty_ring(vui, vq, member)
u16 idx
Definition: pci.h:234
#define vnet_buffer(b)
Definition: buffer.h:365
u16 flags
Definition: pci.h:213
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:116
virtio_net_hdr_mrg_rxbuf_t tx_headers[VLIB_FRAME_SIZE]
Definition: vhost_user.h:362
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:486
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
static_always_inline void vhost_user_handle_tx_offload(vhost_user_intf_t *vui, vlib_buffer_t *b, virtio_net_hdr_t *hdr)