Skip to content

mempool: fix races between list walk and create/free

Robert Sanford dpdk-dev 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest3 patches 5 repliesIn review
  2. v33 patches 1 replySuperseded
  3. v23 patches 3 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v13 patches3 repliesSuperseded

Changes in v4 from the cover letter

- Patch 3, as suggested by Morten Brørup: the dump goes to "NUL" instead of "/dev/null" on Windows. Acked-by added.
- Rebased on main.
- Patches 1 and 2: unchanged.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3mempool: fix race between list walk and freelib/mempool/rte_mempool.c lib/mempool/rte_mempool.h+11 -00 replies
2/3mempool: fix dump of unpopulated pooldoc/guides/rel_notes/release_26_11.rst lib/mempool/rte_mempool.c lib/mempool/rte_mempool.h+66 -45 replies
3/3test/mempool: add list walk race testapp/test/test_mempool.c+150 -00 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchMorten Brørup
1/3R-b
2/3A-b
3/3A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/3] mempool: fix races between list walk and create/free

From: Robert Sanford <[email protected]>

A thread walking the mempool list with rte_mempool_walk(), rte_mempool_lookup() or rte_mempool_list_dump() can crash while other threads create and free mempools. We hit this in production, in a process that walks the mempools while other threads create and free them.

There are two races:

- rte_mempool_free() unlinks and frees the list entry without the mempool list lock that the walkers hold, so a walker can reach a freed entry or mempool. Patch 1 takes the lock in rte_mempool_free(), as rte_mempool_create_empty() already does. A rte_mempool_walk() callback can therefore no longer free a mempool; this is documented.

- A mempool is on the list before its store exists, but rte_mempool_dump() queries the mempool driver, which reads the store. So rte_mempool_list_dump() and the telemetry /mempool/info handler crash on such a mempool. Patch 2 adds rte_mempool_is_created(), makes them report the mempool without querying the driver until it returns true, and documents that rte_mempool_walk() callbacks must check it before querying the driver.

Patch 3 adds a test to mempool_autotest. On x86 with 4 or 8 lcores, it crashed in all 20 runs without patch 1, without patch 2, or without both, and passed in all 20 runs with both patches.

v4:
- Patch 3, as suggested by Morten Brørup: the dump goes to "NUL" instead of "/dev/null" on Windows. Acked-by added.
- Rebased on main.
- Patches 1 and 2: unchanged.

v3:
- Patch 2, as suggested by Morten Brørup: the helper that tests RTE_MEMPOOL_F_POOL_CREATED is now the public function rte_mempool_is_created(), and the rte_mempool_walk() documentation refers to it instead of the flag. Release note added. Acked-by added.
- Patch 3: the walk callback uses rte_mempool_is_created().
- Patch 1: unchanged.

v2:
- Patch 2 reworked as suggested by Morten Brørup: rte_mempool_walk() no longer skips mempools that are not populated yet. Instead, rte_mempool_dump() and the telemetry callback report them without querying the mempool driver, and the rte_mempool_walk() documentation asks callbacks to check RTE_MEMPOOL_F_POOL_CREATED. The flag is now set and tested with release/acquire atomics instead of plain accesses with fences. New title.
- Patch 3: the walk callback dumps every mempool, and checks the flag before querying the driver. The test waits 100 us instead of 10 us before populating, so that it still finds unpopulated mempools reliably.
- Patch 1: unchanged, Reviewed-by added.

Robert Sanford (3):
mempool: fix race between list walk and free
mempool: fix dump of unpopulated pool
test/mempool: add list walk race test

 app/test/test_mempool.c                | 150 +++++++++++++++++++++++++
 doc/guides/rel_notes/release_26_11.rst |   7 ++
 lib/mempool/rte_mempool.c              |  45 +++++++-
 lib/mempool/rte_mempool.h              |  29 +++++
 4 files changed, 227 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1