Skip to content

Commit 9e7ee0f

Browse files
ubizjakjoergroedel
authored andcommitted
iommu/vt-d: Use try_cmpxchg64{,_local}() in iommu.c
Replace this pattern in iommu.c: cmpxchg64{,_local}(*ptr, 0, new) != 0 ... with the simpler and faster: !try_cmpxchg64{,_local}(*ptr, &tmp, new) The x86 CMPXCHG instruction returns success in the ZF flag, so this change saves a compare after the CMPXCHG. No functional change intended. Signed-off-by: Uros Bizjak <[email protected]> Cc: David Woodhouse <[email protected]> Cc: Lu Baolu <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Will Deacon <[email protected]> Cc: Robin Murphy <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent a770ccd commit 9e7ee0f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain,
865865
break;
866866

867867
if (!dma_pte_present(pte)) {
868-
uint64_t pteval;
868+
uint64_t pteval, tmp;
869869

870870
tmp_page = alloc_pgtable_page(domain->nid, gfp);
871871

@@ -877,7 +877,8 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain,
877877
if (domain->use_first_level)
878878
pteval |= DMA_FL_PTE_XD | DMA_FL_PTE_US | DMA_FL_PTE_ACCESS;
879879

880-
if (cmpxchg64(&pte->val, 0ULL, pteval))
880+
tmp = 0ULL;
881+
if (!try_cmpxchg64(&pte->val, &tmp, pteval))
881882
/* Someone else set it while we were thinking; use theirs. */
882883
free_pgtable_page(tmp_page);
883884
else
@@ -2128,8 +2129,8 @@ __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn,
21282129
/* We don't need lock here, nobody else
21292130
* touches the iova range
21302131
*/
2131-
tmp = cmpxchg64_local(&pte->val, 0ULL, pteval);
2132-
if (tmp) {
2132+
tmp = 0ULL;
2133+
if (!try_cmpxchg64_local(&pte->val, &tmp, pteval)) {
21332134
static int dumps = 5;
21342135
pr_crit("ERROR: DMA PTE for vPFN 0x%lx already set (to %llx not %llx)\n",
21352136
iov_pfn, tmp, (unsigned long long)pteval);

0 commit comments

Comments
 (0)