[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <bf2ea452-75ea-4091-90fe-c83062729b76@amd.com>
Date: Thu, 23 May 2024 16:10:28 +0530
From: Vasant Hegde <vasant.hegde@....com>
To: Uros Bizjak <ubizjak@...il.com>, iommu@...ts.linux.dev,
linux-kernel@...r.kernel.org
Cc: Joerg Roedel <joro@...tes.org>,
Suravee Suthikulpanit <suravee.suthikulpanit@....com>,
Will Deacon <will@...nel.org>, Robin Murphy <robin.murphy@....com>
Subject: Re: [PATCH 1/3] iommu/amd: Use try_cmpxchg64() in v2_alloc_pte()
On 5/22/2024 1:56 PM, Uros Bizjak wrote:
> Use try_cmpxchg64() instead of cmpxchg64 (*ptr, old, new) != old in
> v2_alloc_pte(). cmpxchg returns success in ZF flag, so this change
> saves a compare after cmpxchg (and related move instruction
> in front of cmpxchg).
>
> This is the same improvement as implemented for alloc_pte() in:
>
> commit 0d10fe759117 ("iommu/amd: Use try_cmpxchg64 in alloc_pte and free_clear_pte")
>
> Signed-off-by: Uros Bizjak <ubizjak@...il.com>
> Cc: Joerg Roedel <joro@...tes.org>
> Cc: Suravee Suthikulpanit <suravee.suthikulpanit@....com>
> Cc: Will Deacon <will@...nel.org>
> Cc: Robin Murphy <robin.murphy@....com>
Thanks for fixing it. Looks good to me.
Reviewed-by: Vasant Hegde <vasant.hegde@....com>
-Vasant
> ---
> drivers/iommu/amd/io_pgtable_v2.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/amd/io_pgtable_v2.c b/drivers/iommu/amd/io_pgtable_v2.c
> index 78ac37c5ccc1..664e91c88748 100644
> --- a/drivers/iommu/amd/io_pgtable_v2.c
> +++ b/drivers/iommu/amd/io_pgtable_v2.c
> @@ -158,7 +158,7 @@ static u64 *v2_alloc_pte(int nid, u64 *pgd, unsigned long iova,
>
> __npte = set_pgtable_attr(page);
> /* pte could have been changed somewhere. */
> - if (cmpxchg64(pte, __pte, __npte) != __pte)
> + if (!try_cmpxchg64(pte, &__pte, __npte))
> iommu_free_page(page);
> else if (IOMMU_PTE_PRESENT(__pte))
> *updated = true;
Powered by blists - more mailing lists