diff options
author | Padma Ram <padmaram86.raja@gmail.com> | 2019-10-01 06:35:18 +0530 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2019-10-03 16:20:47 +0000 |
commit | d570c4d18df404cb59ef72d20d56f8e31418c8e9 (patch) | |
tree | ed57280bac2fa90da9aa9e2cd87982f8e6d5e319 | |
parent | fb0bb3a732cd46848e26fcc6a17d9fdf99727af3 (diff) |
memif: memif buffer leaks during disconnect.
- code added to release the mbuf's to main pool during memif disconnect.
Type: fix
Change-Id: I504dacc9a40bc1702831cf3208fd532d1ae68a6f
Signed-off-by: Padma Ram <padmaram86.raja@gmail.com>
-rw-r--r-- | src/plugins/memif/memif.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c index c2df8d3b12e..c216a165d46 100644 --- a/src/plugins/memif/memif.c +++ b/src/plugins/memif/memif.c @@ -70,6 +70,7 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err) { memif_main_t *mm = &memif_main; vnet_main_t *vnm = vnet_get_main (); + vlib_main_t *vm = vlib_get_main (); memif_region_t *mr; memif_queue_t *mq; int i; @@ -126,7 +127,19 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err) memif_log_warn (mif, "Unable to unassign interface %d, queue %d: rc=%d", mif->hw_if_index, i, rv); - mq->ring = 0; + if (mif->flags & MEMIF_IF_FLAG_ZERO_COPY) + { + + u16 cur_slot,last_slot, start; + u16 ring_size = 1 << mq->log2_ring_size; + u16 mask = ring_size - 1; + cur_slot = mq->last_tail; + last_slot = mq->ring->head - 1 ; + start = (mq->last_tail & mask); + u16 n_slots = ((last_slot - cur_slot) & mask) + 1; + vlib_buffer_free_from_ring(vm,mq->buffers,start,ring_size,n_slots); + } + mq->ring = 0; } } @@ -136,7 +149,28 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err) vec_free (mif->rx_queues); vec_foreach (mq, mif->tx_queues) - memif_queue_intfd_close (mq); + { + if (mif->flags & MEMIF_IF_FLAG_ZERO_COPY) + { + memif_ring_t *ring = mq->ring; + u16 cur_slot,last_slot, start; + u16 ring_size = 1 << mq->log2_ring_size; + u16 mask = ring_size - 1; + u16 n_slots = ring->tail - mq->last_tail; + cur_slot = mq->last_tail; + last_slot = mq->ring->head; + start = (mq->last_tail & mask); + if(last_slot > cur_slot) + n_slots = n_slots + ((last_slot - cur_slot)) ; + else if (last_slot < cur_slot) + n_slots = n_slots + (cur_slot - last_slot); + vlib_buffer_free_from_ring_no_next (vm, mq->buffers, + start, + ring_size, n_slots); + } + memif_queue_intfd_close (mq); + } + vec_free (mif->tx_queues); /* free memory regions */ |