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 <ubizjak@gmail.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Lu Baolu <baolu.lu@linux.intel.com> Cc: Joerg Roedel <joro@8bytes.org> Cc: Will Deacon <will@kernel.org> Cc: Robin Murphy <robin.murphy@arm.com> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Link: https://lore.kernel.org/r/20240522082729.971123-2-ubizjak@gmail.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 83a7eef commit 5c555f1

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

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)