From: Baolu Lu <baolu.lu@linux.intel.com>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: baolu.lu@linux.intel.com, iommu@lists.linux.dev,
linux-kernel@vger.kernel.org,
David Woodhouse <dwmw2@infradead.org>,
Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>
Subject: Re: [PATCH 2/3] iommu/vt-d: Use try_cmpxchg64() in intel_pasid_get_entry()
Date: Fri, 24 May 2024 09:08:04 +0800 [thread overview]
Message-ID: <a6a8f04b-0dd8-462b-8bad-8b7c2dc0d736@linux.intel.com> (raw)
In-Reply-To: <CAFULd4aXBAxPS7hXJ_RKMzZu60yTr7gK1m3K8z0yq1mjYn3dyA@mail.gmail.com>
On 5/23/24 9:57 PM, Uros Bizjak wrote:
> On Thu, May 23, 2024 at 3:44 PM Baolu Lu<baolu.lu@linux.intel.com> wrote:
>> On 2024/5/23 21:34, Uros Bizjak wrote:
>>>>> + if (!try_cmpxchg64(&dir[dir_index].val, &tmp,
>>>>> + (u64)virt_to_phys(entries) | PASID_PTE_PRESENT)) {
>>>> Above change will cause a dead loop during boot. It should be
>>> No, it is correct as written:
>>>
>>> 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))
>> The return value of both cmpxchg64() and try_cmpxchg64() is the old
>> value that was loaded from the memory location, right?
> Actually, try_cmpxchg() returns true if successful and false if it fails.
Oh! I misunderstood this.
>
> 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.
Okay, it's fine.
Best regards,
baolu
next prev parent reply other threads:[~2024-05-24 1:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a6a8f04b-0dd8-462b-8bad-8b7c2dc0d736@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=ubizjak@gmail.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox