Linus Torvalds writes: (Summary) There's
no subtle lack of locking, or some optimistic access to a value that
can change.
can change.
The compiler can generate code to read the value fifteen billion times, and it will always get the same value.
times, and it will always get the same value.
Yes, maybe in between the different accesses, an NMI will happen, and the value will be incremented, but then as the NMI exits, it will decrement again, so the code that got interrupted will not actually see the change.
see the change.
So the READ_ONCE() isn't "paranoia".
can change.
The compiler can generate code to read the value fifteen billion times, and it will always get the same value.
times, and it will always get the same value.
Yes, maybe in between the different accesses, an NMI will happen, and the value will be incremented, but then as the NMI exits, it will decrement again, so the code that got interrupted will not actually see the change.
see the change.
So the READ_ONCE() isn't "paranoia".