Re: Debugging a TTY race condition on M1 (memory ordering dragons)
From: Peter Zijlstra
Date: Mon Aug 15 2022 - 18:14:35 EST
On Tue, Aug 16, 2022 at 04:15:00AM +0900, Hector Martin wrote:
> FWIW, I didn't actually use a full barrier in my patch. I just replaced
> the test_and_set_bit() with the underlying atomic op, sans early exit path.
That isn't quite true; you used atomic_long_fetch_or() which is used in
the generic implementation, but x86 would end up using "LOCK BTS" for
arch_test_and_set_bit(), while atomic_*fetch_or() ends up being a "LOCK
CMPXCHG" loop (which is significantly worse, performance wise).
That said; I don't have a nice solution that works well across the
various architectures.
(in one previous instance of this problem we ended up using a
cmpxchg_relaxed() coupled with an smp_mb__before_atomic(), but there is
no relaxed version of test_and_set_bit())