History

iommu/io-pgtable-arm: Prepare for TTBR1 usage

Now that we can correctly extract top-level indices without relying on the remaining upper bits being zero, the only remaining impediments to using a given table for TTBR1 are the address validation on map/unmap and the awkward TCR translation granule format. Add a quirk so that we can do the right thing at those points.

Robin Murphy committed 7 years ago

Commit db690301 parent ac4b80e2 files · +23 −6Browse files

Unified · Split

2 files
  1. drivers/iommu/io-pgtable-arm.c +19 −6
  2. include/linux/io-pgtable.h +4 −0
drivers/iommu/io-pgtable-arm.c+19−6
@@ -104,6 +104,10 @@ · 103 unmodified lines
104104 #define ARM_LPAE_TCR_TG0_64K 1
105105 #define ARM_LPAE_TCR_TG0_16K 2
106106
107+#define ARM_LPAE_TCR_TG1_16K 1
108+#define ARM_LPAE_TCR_TG1_4K 2
109+#define ARM_LPAE_TCR_TG1_64K 3
110+
107111 #define ARM_LPAE_TCR_SH_NS 0
108112 #define ARM_LPAE_TCR_SH_OS 2
109113 #define ARM_LPAE_TCR_SH_IS 3
@@ -464,6 +468,7 @@ static int arm_lpae_map(struct io_pgtable_ops *ops, unsigned long iova, · 354 unmodified lines
464468 arm_lpae_iopte *ptep = data->pgd;
465469 int ret, lvl = data->start_level;
466470 arm_lpae_iopte prot;
471+ long iaext = (long)iova >> cfg->ias;
467472
468473 /* If no access, then nothing to do */
469474 if (!(iommu_prot & (IOMMU_READ | IOMMU_WRITE)))
@@ -472,7 +477,9 @@ static int arm_lpae_map(struct io_pgtable_ops *ops, unsigned long iova, · 2 unmodified lines
472477 if (WARN_ON(!size || (size & cfg->pgsize_bitmap) != size))
473478 return -EINVAL;
474479
475− if (WARN_ON(iova >> data->iop.cfg.ias || paddr >> data->iop.cfg.oas))
480+ if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_TTBR1)
481+ iaext = ~iaext;
482+ if (WARN_ON(iaext || paddr >> cfg->oas))
476483 return -ERANGE;
477484
478485 prot = arm_lpae_prot_to_pte(data, iommu_prot);
@@ -638,11 +645,14 @@ static size_t arm_lpae_unmap(struct io_pgtable_ops *ops, unsigned long iova, · 159 unmodified lines
638645 struct arm_lpae_io_pgtable *data = io_pgtable_ops_to_data(ops);
639646 struct io_pgtable_cfg *cfg = &data->iop.cfg;
640647 arm_lpae_iopte *ptep = data->pgd;
648+ long iaext = (long)iova >> cfg->ias;
641649
642650 if (WARN_ON(!size || (size & cfg->pgsize_bitmap) != size))
643651 return 0;
644652
645− if (WARN_ON(iova >> data->iop.cfg.ias))
653+ if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_TTBR1)
654+ iaext = ~iaext;
655+ if (WARN_ON(iaext))
646656 return 0;
647657
648658 return __arm_lpae_unmap(data, gather, iova, size, data->start_level, ptep);
@@ -778,9 +788,11 @@ arm_64_lpae_alloc_pgtable_s1(struct io_pgtable_cfg *cfg, void *cookie) · 129 unmodified lines
778788 u64 reg;
779789 struct arm_lpae_io_pgtable *data;
780790 typeof(&cfg->arm_lpae_s1_cfg.tcr) tcr = &cfg->arm_lpae_s1_cfg.tcr;
791+ bool tg1;
781792
782793 if (cfg->quirks & ~(IO_PGTABLE_QUIRK_ARM_NS |
783− IO_PGTABLE_QUIRK_NON_STRICT))
794+ IO_PGTABLE_QUIRK_NON_STRICT |
795+ IO_PGTABLE_QUIRK_ARM_TTBR1))
784796 return NULL;
785797
786798 data = arm_lpae_alloc_pgtable(cfg);
@@ -798,15 +810,16 @@ arm_64_lpae_alloc_pgtable_s1(struct io_pgtable_cfg *cfg, void *cookie) · 11 unmodified lines
798810 tcr->orgn = ARM_LPAE_TCR_RGN_NC;
799811 }
800812
813+ tg1 = cfg->quirks & IO_PGTABLE_QUIRK_ARM_TTBR1;
801814 switch (ARM_LPAE_GRANULE(data)) {
802815 case SZ_4K:
803− tcr->tg = ARM_LPAE_TCR_TG0_4K;
816+ tcr->tg = tg1 ? ARM_LPAE_TCR_TG1_4K : ARM_LPAE_TCR_TG0_4K;
804817 break;
805818 case SZ_16K:
806− tcr->tg = ARM_LPAE_TCR_TG0_16K;
819+ tcr->tg = tg1 ? ARM_LPAE_TCR_TG1_16K : ARM_LPAE_TCR_TG0_16K;
807820 break;
808821 case SZ_64K:
809− tcr->tg = ARM_LPAE_TCR_TG0_64K;
822+ tcr->tg = tg1 ? ARM_LPAE_TCR_TG1_64K : ARM_LPAE_TCR_TG0_64K;
810823 break;
811824 }
812825
include/linux/io-pgtable.h+4−0
@@ -83,12 +83,16 @@ struct io_pgtable_cfg { · 82 unmodified lines
8383 * IO_PGTABLE_QUIRK_NON_STRICT: Skip issuing synchronous leaf TLBIs
8484 * on unmap, for DMA domains using the flush queue mechanism for
8585 * delayed invalidation.
86+ *
87+ * IO_PGTABLE_QUIRK_ARM_TTBR1: (ARM LPAE format) Configure the table
88+ * for use in the upper half of a split address space.
8689 */
8790 #define IO_PGTABLE_QUIRK_ARM_NS BIT(0)
8891 #define IO_PGTABLE_QUIRK_NO_PERMS BIT(1)
8992 #define IO_PGTABLE_QUIRK_TLBI_ON_MAP BIT(2)
9093 #define IO_PGTABLE_QUIRK_ARM_MTK_EXT BIT(3)
9194 #define IO_PGTABLE_QUIRK_NON_STRICT BIT(4)
95+ #define IO_PGTABLE_QUIRK_ARM_TTBR1 BIT(5)
9296 unsigned long quirks;
9397 unsigned long pgsize_bitmap;
9498 unsigned int ias;