]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/iommu/arm-smmu-v3.c
net/mlx5e: Avoid dealing with vport representors if not being e-switch manager
[mirror_ubuntu-bionic-kernel.git] / drivers / iommu / arm-smmu-v3.c
index 744592d330ca13f2734470c3992f5bb5b1b75088..9c30fb4fccef25eb5969d7fc636e445bd35a8984 100644 (file)
@@ -667,6 +667,7 @@ struct arm_smmu_domain {
        struct mutex                    init_mutex; /* Protects smmu pointer */
 
        struct io_pgtable_ops           *pgtbl_ops;
+       bool                            non_strict;
 
        enum arm_smmu_domain_stage      stage;
        union {
@@ -1466,6 +1467,12 @@ static void arm_smmu_tlb_inv_context(void *cookie)
                cmd.tlbi.vmid   = smmu_domain->s2_cfg.vmid;
        }
 
+       /*
+        * NOTE: when io-pgtable is in non-strict mode, we may get here with
+        * PTEs previously cleared by unmaps on the current CPU not yet visible
+        * to the SMMU. We are relying on the DSB implicit in queue_inc_prod()
+        * to guarantee those are observed before the TLBI. Do be careful, 007.
+        */
        arm_smmu_cmdq_issue_cmd(smmu, &cmd);
        __arm_smmu_tlb_sync(smmu);
 }
@@ -1691,6 +1698,9 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain)
        if (smmu->features & ARM_SMMU_FEAT_COHERENCY)
                pgtbl_cfg.quirks = IO_PGTABLE_QUIRK_NO_DMA;
 
+       if (smmu_domain->non_strict)
+               pgtbl_cfg.quirks |= IO_PGTABLE_QUIRK_NON_STRICT;
+
        pgtbl_ops = alloc_io_pgtable_ops(fmt, &pgtbl_cfg, smmu_domain);
        if (!pgtbl_ops)
                return -ENOMEM;
@@ -1839,6 +1849,14 @@ arm_smmu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size)
        return ops->unmap(ops, iova, size);
 }
 
+static void arm_smmu_flush_iotlb_all(struct iommu_domain *domain)
+{
+       struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
+
+       if (smmu_domain->smmu)
+               arm_smmu_tlb_inv_context(smmu_domain);
+}
+
 static void arm_smmu_iotlb_sync(struct iommu_domain *domain)
 {
        struct arm_smmu_device *smmu = to_smmu_domain(domain)->smmu;
@@ -1984,15 +2002,27 @@ static int arm_smmu_domain_get_attr(struct iommu_domain *domain,
 {
        struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
 
-       if (domain->type != IOMMU_DOMAIN_UNMANAGED)
-               return -EINVAL;
-
-       switch (attr) {
-       case DOMAIN_ATTR_NESTING:
-               *(int *)data = (smmu_domain->stage == ARM_SMMU_DOMAIN_NESTED);
-               return 0;
+       switch (domain->type) {
+       case IOMMU_DOMAIN_UNMANAGED:
+               switch (attr) {
+               case DOMAIN_ATTR_NESTING:
+                       *(int *)data = (smmu_domain->stage == ARM_SMMU_DOMAIN_NESTED);
+                       return 0;
+               default:
+                       return -ENODEV;
+               }
+               break;
+       case IOMMU_DOMAIN_DMA:
+               switch (attr) {
+               case DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE:
+                       *(int *)data = smmu_domain->non_strict;
+                       return 0;
+               default:
+                       return -ENODEV;
+               }
+               break;
        default:
-               return -ENODEV;
+               return -EINVAL;
        }
 }
 
@@ -2002,26 +2032,37 @@ static int arm_smmu_domain_set_attr(struct iommu_domain *domain,
        int ret = 0;
        struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
 
-       if (domain->type != IOMMU_DOMAIN_UNMANAGED)
-               return -EINVAL;
-
        mutex_lock(&smmu_domain->init_mutex);
 
-       switch (attr) {
-       case DOMAIN_ATTR_NESTING:
-               if (smmu_domain->smmu) {
-                       ret = -EPERM;
-                       goto out_unlock;
+       switch (domain->type) {
+       case IOMMU_DOMAIN_UNMANAGED:
+               switch (attr) {
+               case DOMAIN_ATTR_NESTING:
+                       if (smmu_domain->smmu) {
+                               ret = -EPERM;
+                               goto out_unlock;
+                       }
+
+                       if (*(int *)data)
+                               smmu_domain->stage = ARM_SMMU_DOMAIN_NESTED;
+                       else
+                               smmu_domain->stage = ARM_SMMU_DOMAIN_S1;
+                       break;
+               default:
+                       ret = -ENODEV;
+               }
+               break;
+       case IOMMU_DOMAIN_DMA:
+               switch(attr) {
+               case DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE:
+                       smmu_domain->non_strict = *(int *)data;
+                       break;
+               default:
+                       ret = -ENODEV;
                }
-
-               if (*(int *)data)
-                       smmu_domain->stage = ARM_SMMU_DOMAIN_NESTED;
-               else
-                       smmu_domain->stage = ARM_SMMU_DOMAIN_S1;
-
                break;
        default:
-               ret = -ENODEV;
+               ret = -EINVAL;
        }
 
 out_unlock:
@@ -2067,7 +2108,7 @@ static struct iommu_ops arm_smmu_ops = {
        .map                    = arm_smmu_map,
        .unmap                  = arm_smmu_unmap,
        .map_sg                 = default_iommu_map_sg,
-       .flush_iotlb_all        = arm_smmu_iotlb_sync,
+       .flush_iotlb_all        = arm_smmu_flush_iotlb_all,
        .iotlb_sync             = arm_smmu_iotlb_sync,
        .iova_to_phys           = arm_smmu_iova_to_phys,
        .add_device             = arm_smmu_add_device,