public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] iommu/amd: Use try_cmpxchg64() in v2_alloc_pte()
@ 2024-05-22  8:26 Uros Bizjak
  2024-05-22  8:26 ` [PATCH 2/3] iommu/vt-d: Use try_cmpxchg64() in intel_pasid_get_entry() Uros Bizjak
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Uros Bizjak @ 2024-05-22  8:26 UTC (permalink / raw)
  To: iommu, linux-kernel
  Cc: Uros Bizjak, Joerg Roedel, Suravee Suthikulpanit, Will Deacon,
	Robin Murphy

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 0d10fe759117 ("iommu/amd: Use try_cmpxchg64 in alloc_pte and free_clear_pte")

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Cc: Will Deacon <will@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>
---
 drivers/iommu/amd/io_pgtable_v2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/amd/io_pgtable_v2.c b/drivers/iommu/amd/io_pgtable_v2.c
index 78ac37c5ccc1..664e91c88748 100644
--- a/drivers/iommu/amd/io_pgtable_v2.c
+++ b/drivers/iommu/amd/io_pgtable_v2.c
@@ -158,7 +158,7 @@ static u64 *v2_alloc_pte(int nid, u64 *pgd, unsigned long iova,
 
 			__npte = set_pgtable_attr(page);
 			/* pte could have been changed somewhere. */
-			if (cmpxchg64(pte, __pte, __npte) != __pte)
+			if (!try_cmpxchg64(pte, &__pte, __npte))
 				iommu_free_page(page);
 			else if (IOMMU_PTE_PRESENT(__pte))
 				*updated = true;
-- 
2.45.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-05-24  1:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-22  8:26 [PATCH 1/3] iommu/amd: Use try_cmpxchg64() in v2_alloc_pte() Uros Bizjak
2024-05-22  8:26 ` [PATCH 2/3] iommu/vt-d: Use try_cmpxchg64() in intel_pasid_get_entry() Uros Bizjak
2024-05-23 13:24   ` Baolu Lu
2024-05-23 13:34     ` Uros Bizjak
2024-05-23 13:44       ` Baolu Lu
2024-05-23 13:57         ` Uros Bizjak
2024-05-24  1:08           ` Baolu Lu
2024-05-24  1:09   ` Baolu Lu
2024-05-22  8:26 ` [PATCH 3/3] iommufd: Use atomic_long_try_cmpxchg() in incr_user_locked_vm() Uros Bizjak
2024-05-22 12:45   ` Jason Gunthorpe
2024-05-23 10:40 ` [PATCH 1/3] iommu/amd: Use try_cmpxchg64() in v2_alloc_pte() Vasant Hegde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox