From: Jason Gunthorpe <jgg@nvidia.com>
To: Michael Shavit <mshavit@google.com>
Cc: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, nicolinc@nvidia.com,
tina.zhang@intel.com, jean-philippe@linaro.org, will@kernel.org,
robin.murphy@arm.com, Dawei Li <set_pte_at@outlook.com>,
Joerg Roedel <joro@8bytes.org>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Lu Baolu <baolu.lu@linux.intel.com>,
Mark Brown <broonie@kernel.org>
Subject: Re: [RFC PATCH v2 4/9] iommu/arm-smmu-v3-sva: Allocate new ASID from installed_smmus
Date: Tue, 22 Aug 2023 10:19:44 -0300 [thread overview]
Message-ID: <ZOS18J4ytKjHFT+N@nvidia.com> (raw)
In-Reply-To: <20230822185632.RFC.v2.4.I326c62dc062aed8d901d319aa665dbe983c7904c@changeid>
On Tue, Aug 22, 2023 at 06:57:00PM +0800, Michael Shavit wrote:
> Pick an ASID that is within the supported range of all SMMUs that the
> domain is installed to.
>
> Signed-off-by: Michael Shavit <mshavit@google.com>
> ---
>
> (no changes since v1)
>
> .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 23 +++++++++++++++----
> 1 file changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> index fe88a7880ad57..92d2f8c4e90a8 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> @@ -66,6 +66,20 @@ static int arm_smmu_write_ctx_desc_devices(struct arm_smmu_domain *smmu_domain,
> return ret;
> }
>
> +static u32 arm_smmu_domain_max_asid_bits(struct arm_smmu_domain *smmu_domain)
> +{
> + struct arm_smmu_master *master;
> + unsigned long flags;
> + u32 asid_bits = 16;
> +
> + spin_lock_irqsave(&smmu_domain->devices_lock, flags);
> + list_for_each_entry(master, &smmu_domain->devices,
> + domain_head)
> + asid_bits = min(asid_bits, master->smmu->asid_bits);
> + spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
> + return asid_bits;
> +}
I still don't like this, it is not locked properly. You release the
devices_lock which means the max_asid could change before we get to
arm_smmu_write_ctx_desc()
If you want to take this shortcut temporarily then a global max_asid
is probably a better plan. Change it to a per-master allocation later
to remove that.
Jason
WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgg@nvidia.com>
To: Michael Shavit <mshavit@google.com>
Cc: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, nicolinc@nvidia.com,
tina.zhang@intel.com, jean-philippe@linaro.org, will@kernel.org,
robin.murphy@arm.com, Dawei Li <set_pte_at@outlook.com>,
Joerg Roedel <joro@8bytes.org>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Lu Baolu <baolu.lu@linux.intel.com>,
Mark Brown <broonie@kernel.org>
Subject: Re: [RFC PATCH v2 4/9] iommu/arm-smmu-v3-sva: Allocate new ASID from installed_smmus
Date: Tue, 22 Aug 2023 10:19:44 -0300 [thread overview]
Message-ID: <ZOS18J4ytKjHFT+N@nvidia.com> (raw)
In-Reply-To: <20230822185632.RFC.v2.4.I326c62dc062aed8d901d319aa665dbe983c7904c@changeid>
On Tue, Aug 22, 2023 at 06:57:00PM +0800, Michael Shavit wrote:
> Pick an ASID that is within the supported range of all SMMUs that the
> domain is installed to.
>
> Signed-off-by: Michael Shavit <mshavit@google.com>
> ---
>
> (no changes since v1)
>
> .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 23 +++++++++++++++----
> 1 file changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> index fe88a7880ad57..92d2f8c4e90a8 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> @@ -66,6 +66,20 @@ static int arm_smmu_write_ctx_desc_devices(struct arm_smmu_domain *smmu_domain,
> return ret;
> }
>
> +static u32 arm_smmu_domain_max_asid_bits(struct arm_smmu_domain *smmu_domain)
> +{
> + struct arm_smmu_master *master;
> + unsigned long flags;
> + u32 asid_bits = 16;
> +
> + spin_lock_irqsave(&smmu_domain->devices_lock, flags);
> + list_for_each_entry(master, &smmu_domain->devices,
> + domain_head)
> + asid_bits = min(asid_bits, master->smmu->asid_bits);
> + spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
> + return asid_bits;
> +}
I still don't like this, it is not locked properly. You release the
devices_lock which means the max_asid could change before we get to
arm_smmu_write_ctx_desc()
If you want to take this shortcut temporarily then a global max_asid
is probably a better plan. Change it to a per-master allocation later
to remove that.
Jason
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-08-22 13:19 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-22 10:56 [RFC PATCH v2 0/9] Install domain onto multiple smmus Michael Shavit
2023-08-22 10:56 ` Michael Shavit
2023-08-22 10:56 ` [RFC PATCH v2 1/9] iommu/arm-smmu-v3: group attached devices by smmu Michael Shavit
2023-08-22 10:56 ` Michael Shavit
2023-08-22 12:49 ` Jason Gunthorpe
2023-08-22 12:49 ` Jason Gunthorpe
2023-08-22 10:56 ` [RFC PATCH v2 2/9] iommu/arm-smmu-v3-sva: Move SVA optimization into arm_smmu_tlb_inv_range_asid Michael Shavit
2023-08-22 10:56 ` Michael Shavit
2023-08-22 10:56 ` [RFC PATCH v2 3/9] iommu/arm-smmu-v3: Issue invalidations commands to multiple SMMUs Michael Shavit
2023-08-22 10:56 ` Michael Shavit
2023-08-22 13:14 ` Jason Gunthorpe
2023-08-22 13:14 ` Jason Gunthorpe
2023-08-22 10:57 ` [RFC PATCH v2 4/9] iommu/arm-smmu-v3-sva: Allocate new ASID from installed_smmus Michael Shavit
2023-08-22 10:57 ` Michael Shavit
2023-08-22 13:19 ` Jason Gunthorpe [this message]
2023-08-22 13:19 ` Jason Gunthorpe
2023-08-23 7:26 ` Michael Shavit
2023-08-23 7:26 ` Michael Shavit
2023-08-22 10:57 ` [RFC PATCH v2 5/9] iommu/arm-smmu-v3: Alloc vmid from global pool Michael Shavit
2023-08-22 10:57 ` Michael Shavit
2023-08-22 10:57 ` [RFC PATCH v2 6/9] iommu/arm-smmu-v3: check smmu compatibility on attach Michael Shavit
2023-08-22 10:57 ` Michael Shavit
2023-08-22 10:57 ` [RFC PATCH v2 7/9] iommu/arm-smmu-v3: Add arm_smmu_device as a parameter to domain_finalise Michael Shavit
2023-08-22 10:57 ` Michael Shavit
2023-08-22 10:57 ` [RFC PATCH v2 8/9] iommu/arm-smmu-v3: check for domain initialization using pgtbl_ops Michael Shavit
2023-08-22 10:57 ` Michael Shavit
2023-08-22 10:57 ` [RFC PATCH v2 9/9] iommu/arm-smmu-v3: allow multi-SMMU domain installs Michael Shavit
2023-08-22 10:57 ` Michael Shavit
2023-08-23 2:42 ` [RFC PATCH v2 0/9] Install domain onto multiple smmus Baolu Lu
2023-08-23 2:42 ` Baolu Lu
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=ZOS18J4ytKjHFT+N@nvidia.com \
--to=jgg@nvidia.com \
--cc=baolu.lu@linux.intel.com \
--cc=broonie@kernel.org \
--cc=iommu@lists.linux.dev \
--cc=jean-philippe@linaro.org \
--cc=joro@8bytes.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mshavit@google.com \
--cc=nicolinc@nvidia.com \
--cc=robin.murphy@arm.com \
--cc=set_pte_at@outlook.com \
--cc=tina.zhang@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.