tools/memory-model: Make ppo a subrelation of po
authorJonas Oberhauser <jonas.oberhauser@huaweicloud.com>
Fri, 24 Feb 2023 13:52:51 +0000 (14:52 +0100)
committerPaul E. McKenney <paulmck@kernel.org>
Wed, 22 Mar 2023 19:02:21 +0000 (12:02 -0700)
commit762e9357e713a2025db05bc36a36a7afc248f9d3
treedefafde7429f8d3c2af07e64aca43c6b9e691eba
parent614e40faf5ae30113f94b00106ce690602f10fc2
tools/memory-model: Make ppo a subrelation of po

As stated in the documentation and implied by its name, the ppo
(preserved program order) relation is intended to link po-earlier
to po-later instructions under certain conditions.  However, a
corner case currently allows instructions to be linked by ppo that
are not executed by the same thread, i.e., instructions are being
linked that have no po relation.

This happens due to the mb/strong-fence/fence relations, which (as
one case) provide order when locks are passed between threads
followed by an smp_mb__after_unlock_lock() fence.  This is
illustrated in the following litmus test (as can be seen when using
herd7 with `doshow ppo`):

P0(spinlock_t *x, spinlock_t *y)
{
    spin_lock(x);
    spin_unlock(x);
}

P1(spinlock_t *x, spinlock_t *y)
{
    spin_lock(x);
    smp_mb__after_unlock_lock();
    *y = 1;
}

The ppo relation will link P0's spin_lock(x) and P1's *y=1, because
P0 passes a lock to P1 which then uses this fence.

The patch makes ppo a subrelation of po by letting fence contribute
to ppo only in case the fence links events of the same thread.

Signed-off-by: Jonas Oberhauser <jonas.oberhauser@huaweicloud.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Acked-by: Andrea Parri <parri.andrea@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
tools/memory-model/linux-kernel.cat