From: Vasant Hegde <vasant.hegde@amd.com>
To: Jason Gunthorpe <jgg@nvidia.com>,
iommu@lists.linux.dev, Joerg Roedel <joro@8bytes.org>,
Robin Murphy <robin.murphy@arm.com>,
Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
Will Deacon <will@kernel.org>
Cc: Joerg Roedel <jroedel@suse.de>, patches@lists.linux.dev
Subject: Re: [PATCH rc 1/2] iommu/amd: Put list_add/del(dev_data) back under the domain->lock
Date: Mon, 9 Dec 2024 13:53:30 +0530 [thread overview]
Message-ID: <54f4f74e-b58f-4b35-8bb7-672ae23a7bf5@amd.com> (raw)
In-Reply-To: <1-v1-3b9edcf8067d+3975-amd_dev_list_locking_jgg@nvidia.com>
On 12/6/2024 5:43 AM, Jason Gunthorpe wrote:
> The list domain->dev_list is protected by the domain->lock spinlock.
> Any iteration, addition or removal must be under the lock.
>
> Move the list_del() up into the critical section. pdom_is_sva_capable(),
> and destroy_gcr3_table() do not interact with the list element.
>
> Wrap the list_add() in a lock, it would make more sense if this was under
> the same critical section as adjusting the refcounts earlier, but that
> requires more complications.
>
> Fixes: d6b47dec3684 ("iommu/amd: Reduce domain lock scope in attach device path")
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Thanks for the fix. Patch looks good.
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
-Vasant
> ---
> drivers/iommu/amd/iommu.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index 3f691e1fd22ce4..23a168e229b171 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -2073,6 +2073,7 @@ static int attach_device(struct device *dev,
> struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
> struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
> struct pci_dev *pdev;
> + unsigned long flags;
> int ret = 0;
>
> mutex_lock(&dev_data->mutex);
> @@ -2113,7 +2114,9 @@ static int attach_device(struct device *dev,
>
> /* Update data structures */
> dev_data->domain = domain;
> + spin_lock_irqsave(&domain->lock, flags);
> list_add(&dev_data->list, &domain->dev_list);
> + spin_unlock_irqrestore(&domain->lock, flags);
>
> /* Update device table */
> dev_update_dte(dev_data, true);
> @@ -2160,6 +2163,7 @@ static void detach_device(struct device *dev)
> /* Flush IOTLB and wait for the flushes to finish */
> spin_lock_irqsave(&domain->lock, flags);
> amd_iommu_domain_flush_all(domain);
> + list_del(&dev_data->list);
> spin_unlock_irqrestore(&domain->lock, flags);
>
> /* Clear GCR3 table */
> @@ -2168,7 +2172,6 @@ static void detach_device(struct device *dev)
>
> /* Update data structures */
> dev_data->domain = NULL;
> - list_del(&dev_data->list);
>
> /* decrease reference counters - needs to happen after the flushes */
> pdom_detach_iommu(iommu, domain);
next prev parent reply other threads:[~2024-12-09 8:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-06 0:13 [PATCH rc 0/2] iommu/amd: Fix locking for domain->dev_list Jason Gunthorpe
2024-12-06 0:13 ` [PATCH rc 1/2] iommu/amd: Put list_add/del(dev_data) back under the domain->lock Jason Gunthorpe
2024-12-09 8:23 ` Vasant Hegde [this message]
2024-12-06 0:13 ` [PATCH rc 2/2] iommu/amd: Add lockdep asserts for domain->dev_list Jason Gunthorpe
2024-12-09 8:18 ` Vasant Hegde
2024-12-10 9:12 ` [PATCH rc 0/2] iommu/amd: Fix locking " Joerg Roedel
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=54f4f74e-b58f-4b35-8bb7-672ae23a7bf5@amd.com \
--to=vasant.hegde@amd.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=jroedel@suse.de \
--cc=patches@lists.linux.dev \
--cc=robin.murphy@arm.com \
--cc=suravee.suthikulpanit@amd.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