]> www.infradead.org Git - users/dwmw2/linux.git/commit
iommufd: Use atomic_long_try_cmpxchg() in incr_user_locked_vm()
authorUros Bizjak <ubizjak@gmail.com>
Wed, 22 May 2024 08:26:49 +0000 (10:26 +0200)
committerJoerg Roedel <jroedel@suse.de>
Tue, 25 Jun 2024 12:21:10 +0000 (14:21 +0200)
commitb95a40122a8183873736e0506df8e3a881178099
tree261ca382465877f76dae4ec35677440fd0d4e5d4
parentc94ad1d5e3885bd4fa6abb695baf5a8f5c3c309c
iommufd: Use atomic_long_try_cmpxchg() in incr_user_locked_vm()

Use atomic_long_try_cmpxchg() instead of
atomic_long_cmpxchg (*ptr, old, new) != old in incr_user_locked_vm().
cmpxchg returns success in ZF flag, so this change saves a compare
after cmpxchg (and related move instruction in front of cmpxchg).

Also, atomic_long_try_cmpxchg() implicitly assigns old *ptr
value to "old" when cmpxchg fails. There is no need to re-read
the value in the loop.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Kevin Tian <kevin.tian@intel.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Will Deacon <will@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20240522082729.971123-3-ubizjak@gmail.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/iommufd/pages.c