Re: [PATCH v2] timekeeping: don't use seqcount loop in ktime_mono_to_any on 64-bit systems

From: Thomas Gleixner
Date: Tue Sep 10 2024 - 13:46:12 EST


On Tue, Sep 10 2024 at 08:55, Jeff Layton wrote:
> ktime_mono_to_any only fetches the offset inside the loop. This is a
> single word on 64-bit hosts, and seqcount_read_begin implies a full SMP
> barrier.
>
> When BITS_PER_LONG == 64, just do a simple ktime_add instead as there
> is no possibility of getting a torn offset value.
>
> Cc: Vadim Fedorenko <vadim.fedorenko@xxxxxxxxx>
> Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
> ---
> Thanks for the review so far, Thomas! Hopefully this looks better.
> Disregard my earlier question about making this a static inline too.
> That would require making offsets[] a global symbol, which I don't think
> we want to do.

This still fails to address these:

> Please describe functions with foo() and not foo.

> Which will make KCSAN complain ...
>
> So yes, READ_ONCE() is the correct thing todo, but then we want to have
> the counterpart at the write sides.

KCSAN requires this to be annotated and it's also a good documentation
that this is a intentional unprotected access.

Thanks,

tglx