From: Pierre Pfister Date: Wed, 7 Feb 2018 14:48:21 +0000 (+0100) Subject: af_packet: Fix lock position X-Git-Tag: v18.04-rc1~364 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=8cedff2f462ef9deada9aae223868a216c7aa7f2;p=vpp.git af_packet: Fix lock position 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 --- diff --git a/src/vnet/devices/af_packet/device.c b/src/vnet/devices/af_packet/device.c index 2c2489b55ab..0991378f640 100644 --- a/src/vnet/devices/af_packet/device.c +++ b/src/vnet/devices/af_packet/device.c @@ -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;