]> www.infradead.org Git - users/jedix/linux-maple.git/commit
maple_tree: Fix write memory barrier of nodes once dead for RCU mode
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Tue, 13 Dec 2022 13:53:37 +0000 (08:53 -0500)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 4 Jan 2023 20:56:18 +0000 (15:56 -0500)
commitb5feba1255a8d0a91a168e623131807bf66720d9
tree64422b834288331f0d6a6c823a4844b9d9a8d96d
parent838bab4bf4de6250f21d4d1ece658ed52cd86ce9
maple_tree: Fix write memory barrier of nodes once dead for RCU mode

During the development of the maple tree, the strategy of freeing
multiple nodes changed and, in the process, the pivots were reused to
store pointers to dead nodes.  To ensure the readers see accurate
pivots, the writers need to mark the nodes as dead and call smp_wmb() to
ensure any readers can identify the node as dead before using the pivot
values.

There were two places where the old method of marking the node as dead
without smp_wmb() were being used, which resulted in RCU readers seeing
the wrong pivot value before seeing the node was dead.  Fix this race
condition by using mte_set_node_dead() which has the smp_wmb() call to
ensure the race is closed.

Add a WARN_ON() to the ma_free_rcu() call to ensure all nodes being
freed are marked as dead to ensure there are no other call paths besides
the two updated paths.

This is necessary for the RCU mode of the maple tree.

Fixes: 54a611b60590 ("Maple Tree: add new data structure")
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
lib/maple_tree.c
tools/testing/radix-tree/maple.c