From: Baolu Lu <baolu.lu@linux.intel.com>
To: Uros Bizjak <ubizjak@gmail.com>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: baolu.lu@linux.intel.com, 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: Thu, 23 May 2024 21:24:36 +0800 [thread overview]
Message-ID: <c1892ba9-4eae-40fc-b3ab-73d0f82a74ea@linux.intel.com> (raw)
In-Reply-To: <20240522082729.971123-2-ubizjak@gmail.com>
On 2024/5/22 16:26, Uros Bizjak wrote:
> 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>
> ---
> drivers/iommu/intel/pasid.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
> index abce19e2ad6f..9bf45bc4b967 100644
> --- a/drivers/iommu/intel/pasid.c
> +++ b/drivers/iommu/intel/pasid.c
> @@ -146,6 +146,8 @@ static struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid)
> retry:
> entries = get_pasid_table_from_pde(&dir[dir_index]);
> if (!entries) {
> + u64 tmp;
> +
> entries = iommu_alloc_page_node(info->iommu->node, GFP_ATOMIC);
> if (!entries)
> return NULL;
> @@ -156,8 +158,9 @@ static struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid)
> * clear. However, this entry might be populated by others
> * while we are preparing it. Use theirs with a retry.
> */
> - if (cmpxchg64(&dir[dir_index].val, 0ULL,
> - (u64)virt_to_phys(entries) | PASID_PTE_PRESENT)) {
> + tmp = 0ULL;
nit: can this simply be
tmp = 0;
?
> + 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
if (try_cmpxchg64(&dir[dir_index].val, &tmp,
(u64)virt_to_phys(entries) | PASID_PTE_PRESENT)) {
> iommu_free_page(entries);
> goto retry;
> }
Best regards,
baolu
next prev parent reply other threads:[~2024-05-23 13:24 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 [this message]
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
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=c1892ba9-4eae-40fc-b3ab-73d0f82a74ea@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