mcslock: fix hang in weak memory model
authorDiogo Behrens <diogo.behrens@huawei.com>
Wed, 26 Aug 2020 09:20:02 +0000 (11:20 +0200)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 25 Nov 2020 16:30:04 +0000 (17:30 +0100)
commit021b698eb56e48009d74d818bea5a9bdad4f54fa
treee6655079ffb5f94cd9fefed30b47b5edb3538ac9
parentf32fed83db8ba3f929d520bd370df612728a130b
mcslock: fix hang in weak memory model

The initialization me->locked=1 in lock() must happen before
next->locked=0 in unlock(), otherwise a thread may hang forever,
waiting me->locked become 0. On weak memory systems (such as ARMv8),
the current implementation allows me->locked=1 to be reordered with
announcing the node (pred->next=me) and, consequently, to be
reordered with next->locked=0 in unlock().

This fix adds a release barrier to pred->next=me, forcing
me->locked=1 to happen before this operation.

Fixes: 2173f3333b61 ("mcslock: add MCS queued lock implementation")
Cc: stable@dpdk.org
Signed-off-by: Diogo Behrens <diogo.behrens@huawei.com>
Acked-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
lib/librte_eal/include/generic/rte_mcslock.h