lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ec8c3fff-d08b-4132-9a9e-c70e3efe6f2a@gmail.com>
Date: Sat, 10 May 2025 22:46:04 +0200
From: Heiner Kallweit <hkallweit1@...il.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>, Ingo Molnar
 <mingo@...nel.org>, Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: Documentation of locking needs when working with lists?

On 10.05.2025 15:20, Greg Kroah-Hartman wrote:
> On Sat, May 10, 2025 at 10:46:32AM +0200, Heiner Kallweit wrote:
>> Even though lists are used everywhere, I was surprised not being able to find
>> documentation about which operations need locking, and which ones are safe
>> lock-less.
>>
>> My case:
>> I have a list where the only operation is adding entries.
>> It's clear that adding entries has to be serialized.
>> Question is whether a list_for_each_entry is safe lock-less.
>>
>> Looking at the code I *think* it's safe, under the precondition that
>> reading/writing pointers is atomic.
>>
>> Any hint or documentation link would be appreciated. Thanks!
> 
> You MUST have locking for your list if you have multiple processes
> accessing it at the same time.
> 
Thanks. Sure, I need locking for the writers (list_add_tail).
Question is about the reader, list_for_each_entry.
Last step in list_add_tail() is WRITE_ONCE(prev->next, new);
list_next_entry() reads the "next" member of the iterator.

Therefore I think list_next_entry() always sees a consistent
state, either the old or the new value of the "next" pointer.
So I don't see a need for locking list_for_each_entry().

If there is such a need, I'd be interested in the potential
race scenario.

> good luck!
> 
> greg k-h


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ