Skip to content

Commit 5c555f1

Browse files
ubizjakjoergroedel
authored andcommitted
iommu/vt-d: Use try_cmpxchg64() in intel_pasid_get_entry()
Use try_cmpxchg64() instead of cmpxchg64 (*ptr, old, new) != old in intel_pasid_get_entry(). cmpxchg returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg). 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: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 83a7eef commit 5c555f1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/iommu/intel/pasid.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ static struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid)
146146
retry:
147147
entries = get_pasid_table_from_pde(&dir[dir_index]);
148148
if (!entries) {
149+
u64 tmp;
150+
149151
entries = iommu_alloc_page_node(info->iommu->node, GFP_ATOMIC);
150152
if (!entries)
151153
return NULL;
@@ -156,8 +158,9 @@ static struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid)
156158
* clear. However, this entry might be populated by others
157159
* while we are preparing it. Use theirs with a retry.
158160
*/
159-
if (cmpxchg64(&dir[dir_index].val, 0ULL,
160-
(u64)virt_to_phys(entries) | PASID_PTE_PRESENT)) {
161+
tmp = 0ULL;
162+
if (!try_cmpxchg64(&dir[dir_index].val, &tmp,
163+
(u64)virt_to_phys(entries) | PASID_PTE_PRESENT)) {
161164
iommu_free_page(entries);
162165
goto retry;
163166
}

0 commit comments

Comments
 (0)