Re: [PATCH] seqlock: Use WRITE_ONCE() on sequence update

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Dec 17, 2024 at 9:05 PM Daniel Xu <dxu@xxxxxxxxx> wrote:
> My understanding is that read_seqbegin() and read_seqretry()
> can execute at any time. That means the read side access of
> the sequence number can occur doing an increment.
>
> To prevent the reader from reading a partially written value,
> we need the WRITE_ONCE() to ensure the relaxed atomic
> write.

Hi Daniel,

This seems very odd to me. Assuming that the lock field is of an
atomic type, no reader will ever see a partial write.
By "atomic" I don't mean subject to atomic read-modify-write
operations, but simply that the hardware always completes a write to
the value before it is made visible to any observers. This should be
true for all aligned integral types in all modern architectures.

Also, I don't believe WRITE_ONCE() imposes any atomicity where none
exists. I'm not a Linux kernel developer, but from what I can tell all
it does is wrap a pointer with volatile, to ensure that the compiler
does not optimize-away the write. In this case I don't see how the
compiler can ignore seq->lock++ between a spin lock and a barrier.

--Elad

>
> Thanks,
> Daniel
>





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux