On Thu, May 23, 2024 at 3:44 PM Baolu Lu<baolu.lu@xxxxxxxxxxxxxxx> wrote:
On 2024/5/23 21:34, Uros Bizjak wrote:Actually, try_cmpxchg() returns true if successful and false if it fails.
The return value of both cmpxchg64() and try_cmpxchg64() is the oldNo, it is correct as written:+ if (!try_cmpxchg64(&dir[dir_index].val, &tmp,Above change will cause a dead loop during boot. It should be
+ (u64)virt_to_phys(entries) | PASID_PTE_PRESENT)) {
if (cmpxchg64(*ptr, 0, new))
can be written as:
if (cmpxchg64(*ptr, 0, new) != 0)
this is equivalent to:
tmp = 0ULL;
if (!try_cmpxchg64(*ptr, &tmp, new))
value that was loaded from the memory location, right?
tmp = 0ULL;
if (!try_cmpxchg64(*ptr, &tmp, new))
The logic in the above snippet can be interpreted as:
if we fail to compare *ptr with 0, then:
iommu_free_page(entries);
goto retry;
as intended in the original code.