Re: [PATCH -next] locking/osq_lock: annotate a data race in osq_lock
From: Qian Cai
Date: Tue Feb 11 2020 - 06:57:09 EST
> On Feb 11, 2020, at 5:16 AM, Marco Elver <elver@xxxxxxxxxx> wrote:
>
> I have said this before: we're not just guarding against load/store
> tearing, although on their own, they make it deceptively easy to
> reason about data races.
>
> The case here seems to be another instance of a C-CAS, to avoid
> unnecessarily dirtying a cacheline.
>
> Here, the loop would make me suspicious, because a compiler could
> optimize out re-loading the value. Due to the smp_load_acquire,
> however, at the least we have 1 implied compiler barrier in this loop
> which means that will likely not happen.
>
> Before jumping to 'data_race()', I would ask again: how bad is the
> READ_ONCE? Is the generated code the same? If so, just use the
> READ_ONCE. Do you want to reason about all compiler optimizations? For
> this code here, I certainly don't want to.
>
> But in the end it's up to what maintainers prefer, and maybe there is
> a very compelling argument that I missed that makes the fact this is a
> data race always safe.
Yes, I feel like locking maintainers prefer data_race() rather than blindly adding READ_ONCE() unless there is an strong evidence that the later is needed.
Since I canât prove it is strictly needed to prevent from which specific optimization, I had chosen the data_race() approach.