Skip to content

Commit 9a448e4

Browse files
ubizjakjoergroedel
authored andcommitted
iommu/amd: Use try_cmpxchg64() in v2_alloc_pte()
Use try_cmpxchg64() instead of cmpxchg64 (*ptr, old, new) != old in v2_alloc_pte(). cmpxchg returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg). This is the same improvement as implemented for alloc_pte() in: commit 0d10fe7 ("iommu/amd: Use try_cmpxchg64 in alloc_pte and free_clear_pte") Signed-off-by: Uros Bizjak <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Suravee Suthikulpanit <[email protected]> Cc: Will Deacon <[email protected]> Cc: Robin Murphy <[email protected]> Reviewed-by: Vasant Hegde <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 83a7eef commit 9a448e4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/iommu/amd/io_pgtable_v2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static u64 *v2_alloc_pte(int nid, u64 *pgd, unsigned long iova,
158158

159159
__npte = set_pgtable_attr(page);
160160
/* pte could have been changed somewhere. */
161-
if (cmpxchg64(pte, __pte, __npte) != __pte)
161+
if (!try_cmpxchg64(pte, &__pte, __npte))
162162
iommu_free_page(page);
163163
else if (IOMMU_PTE_PRESENT(__pte))
164164
*updated = true;

0 commit comments

Comments
 (0)