[PATCH v2 2/2] iommu/arm-smmu-v3: Configure STU of a PF if ATS is not enabled.
Ganapatrao Kulkarni
gankulkarni at os.amperecomputing.com
Mon Mar 13 07:19:20 PDT 2023
Hi Will, Robin,
On 28-02-2023 09:51 am, Ganapatrao Kulkarni wrote:
> When the host kernel is booted with iommu passthrough mode, PF and VFs
> are enumerated with iommu/smmu domain set to bypass mode.
> In bypass mode, ATS is not enabled on all VFs and associated PF.
> When VFs are attached to a VM, the corresponding iommu domain is set to
> SMMU translation mode and smmu-v3 driver try to enable the ATS and fails
> due to invalid STU of a PF.
>
> Adding a fix to configure STU of a PF while enumerating in passthrough
> mode.
>
Any comments on this patch/series?
> Signed-off-by: Ganapatrao Kulkarni <gankulkarni at os.amperecomputing.com>
> ---
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 25 ++++++++++++++++++++-
> 1 file changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> index f2425b0f0cd6..b218ef0bf001 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -2292,6 +2292,23 @@ static bool arm_smmu_ats_supported(struct arm_smmu_master *master)
> return dev_is_pci(dev) && pci_ats_supported(to_pci_dev(dev));
> }
>
> +static void arm_smmu_ats_stu_init(struct arm_smmu_master *master)
> +{
> + size_t stu;
> + struct pci_dev *pdev;
> + struct arm_smmu_device *smmu = master->smmu;
> +
> + if (master->ats_enabled)
> + return;
> +
> + /* Smallest Translation Unit: log2 of the smallest supported granule */
> + stu = __ffs(smmu->pgsize_bitmap);
> + pdev = to_pci_dev(master->dev);
> +
> + if (pci_ats_stu_configure(pdev, stu))
> + dev_err(master->dev, "Failed to configure ATS STU (%zu)\n", stu);
> +}
> +
> static void arm_smmu_enable_ats(struct arm_smmu_master *master)
> {
> size_t stu;
> @@ -2404,6 +2421,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
> struct arm_smmu_device *smmu;
> struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
> struct arm_smmu_master *master;
> + bool ats_supported;
>
> if (!fwspec)
> return -ENOENT;
> @@ -2446,9 +2464,10 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
> }
>
> master->domain = smmu_domain;
> + ats_supported = arm_smmu_ats_supported(master);
>
> if (smmu_domain->stage != ARM_SMMU_DOMAIN_BYPASS)
> - master->ats_enabled = arm_smmu_ats_supported(master);
> + master->ats_enabled = ats_supported;
>
> arm_smmu_install_ste_for_dev(master);
>
> @@ -2458,6 +2477,10 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
>
> arm_smmu_enable_ats(master);
>
> + /* Configure ATS STU of a PF in passthrough */
> + if (!master->ats_enabled && ats_supported)
> + arm_smmu_ats_stu_init(master);
> +
> out_unlock:
> mutex_unlock(&smmu_domain->init_mutex);
> return ret;
Thanks,
Ganapat
More information about the linux-arm-kernel
mailing list