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: <14e0bf75-27f4-83ec-d52f-82d7d4dab5a7@redhat.com>
Date:   Fri, 26 Nov 2021 11:34:28 +0100
From:   Paolo Bonzini <pbonzini@...hat.com>
To:     "Maciej S. Szmigiero" <mail@...iej.szmigiero.name>
Cc:     Sean Christopherson <seanjc@...gle.com>,
        Vitaly Kuznetsov <vkuznets@...hat.com>,
        Wanpeng Li <wanpengli@...cent.com>,
        Jim Mattson <jmattson@...gle.com>,
        Joerg Roedel <joro@...tes.org>,
        Igor Mammedov <imammedo@...hat.com>, kvm@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/3] KVM: Use atomic_long_cmpxchg() instead of an
 open-coded variant

On 11/26/21 01:31, Maciej S. Szmigiero wrote:
> -		if ((long)old == atomic_long_read(&slots->last_used_slot))
> -			atomic_long_set(&slots->last_used_slot, (long)new);
> +		/*
> +		 * The atomicity isn't strictly required here since we are
> +		 * operating on an inactive memslots set anyway.
> +		 */
> +		atomic_long_cmpxchg(&slots->last_used_slot,
> +				    (unsigned long)old, (unsigned long)new);

I think using read/set is more readable than a comment saying that 
atomicity is not required.

It's a fairly common pattern, and while I agree that it's a PITA to 
write atomic_long_read and atomic_long_set, the person that reads the 
code is also helped by read/set, because they know they have to think 
about ownership invariants rather than concurrency invariants.

Paolo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ