af_packet: Fix lock position 45/10445/2
authorPierre Pfister <ppfister@cisco.com>
Wed, 7 Feb 2018 14:48:21 +0000 (15:48 +0100)
committerDamjan Marion <dmarion.lists@gmail.com>
Wed, 7 Feb 2018 18:46:28 +0000 (18:46 +0000)
In multi-worker cases, af-packet tx was subject to a pretty
serious race condition as the device lock was obtained
after some queue values were read from queue.

Result could go from packet loss to queue inconsistency, leading
to tx being stuck for 'some time'.

The fix is really simple. Finding the problem was not...

Change-Id: Ib18967b7459a8609428a56de934c577cea87b165
Signed-off-by: Pierre Pfister <ppfister@cisco.com>
src/vnet/devices/af_packet/device.c

index 2c2489b..0991378 100644 (file)
@@ -87,6 +87,7 @@ af_packet_interface_tx (vlib_main_t * vm,
   vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
   af_packet_if_t *apif =
     pool_elt_at_index (apm->interfaces, rd->dev_instance);
+  clib_spinlock_lock_if_init (&apif->lockp);
   int block = 0;
   u32 block_size = apif->tx_req->tp_block_size;
   u32 frame_size = apif->tx_req->tp_frame_size;
@@ -96,8 +97,6 @@ af_packet_interface_tx (vlib_main_t * vm,
   struct tpacket2_hdr *tph;
   u32 frame_not_ready = 0;
 
-  clib_spinlock_lock_if_init (&apif->lockp);
-
   while (n_left > 0)
     {
       u32 len;