RE: [patch 14/30] drm/i915/pmu: Replace open coded kstat_irqs() copy

From: David Laight
Date: Fri Dec 11 2020 - 09:21:44 EST


From: Thomas Gleixner
> Sent: 11 December 2020 12:58
..
> > After my failed hasty sketch from last night I had a different one which
> > was kind of heuristics based (re-reading the upper dword and retrying if
> > it changed on 32-bit).
>
> The problem is that there will be two seperate modifications for the low
> and high word. Several ways how the compiler can translate this, but the
> problem is the same for all of them:
>
> CPU 0 CPU 1
> load low
> load high
> add low, 1
> addc high, 0
> store low load high
> --> NMI load low
> load high and compare
> store high
>
> You can't catch that. If this really becomes an issue you need a
> sequence counter around it.

Or just two copies of the high word.
Provided the accesses are sequenced:
writer:
load high:low
add small_value,high:low
store high
store low
store high_copy
reader:
load high_copy
load low
load high
if (high != high_copy)
low = 0;

The read value is always stale, so it probably doesn't
matter that the value you have is one that is between the
value when you started and that when you finished.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)