Skip to content

Commit 90105ae

Browse files
committed
Merge tag 'iommu-fixes-v5.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu
Pull iommu fixes from Joerg Roedel: - Fixes for page-table issues on Mali GPUs - Missing free in an error path for ARM-SMMU - PASID decoding in the AMD IOMMU Event log code - Another update for the locking fixes in the AMD IOMMU driver - Reduce the calls to platform_get_irq() in the IPMMU-VMSA and Rockchip IOMMUs to get rid of the warning message added to this function recently * tag 'iommu-fixes-v5.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: iommu/amd: Check PM_LEVEL_SIZE() condition in locked section iommu/amd: Fix incorrect PASID decoding from event log iommu/ipmmu-vmsa: Only call platform_get_irq() when interrupt is mandatory iommu/rockchip: Don't use platform_get_irq to implicitly count irqs iommu/io-pgtable-arm: Support all Mali configurations iommu/io-pgtable-arm: Correct Mali attributes iommu/arm-smmu: Free context bitmap in the err path of arm_smmu_init_domain_context
2 parents 8eb4b3b + 46ac18c commit 90105ae

File tree

6 files changed

+70
-27
lines changed

6 files changed

+70
-27
lines changed

drivers/iommu/amd_iommu.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,8 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
583583
retry:
584584
type = (event[1] >> EVENT_TYPE_SHIFT) & EVENT_TYPE_MASK;
585585
devid = (event[0] >> EVENT_DEVID_SHIFT) & EVENT_DEVID_MASK;
586-
pasid = PPR_PASID(*(u64 *)&event[0]);
586+
pasid = (event[0] & EVENT_DOMID_MASK_HI) |
587+
(event[1] & EVENT_DOMID_MASK_LO);
587588
flags = (event[1] >> EVENT_FLAGS_SHIFT) & EVENT_FLAGS_MASK;
588589
address = (u64)(((u64)event[3]) << 32) | event[2];
589590

@@ -616,7 +617,7 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
616617
address, flags);
617618
break;
618619
case EVENT_TYPE_PAGE_TAB_ERR:
619-
dev_err(dev, "Event logged [PAGE_TAB_HARDWARE_ERROR device=%02x:%02x.%x domain=0x%04x address=0x%llx flags=0x%04x]\n",
620+
dev_err(dev, "Event logged [PAGE_TAB_HARDWARE_ERROR device=%02x:%02x.%x pasid=0x%04x address=0x%llx flags=0x%04x]\n",
620621
PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
621622
pasid, address, flags);
622623
break;
@@ -1463,6 +1464,7 @@ static void free_pagetable(struct protection_domain *domain)
14631464
* to 64 bits.
14641465
*/
14651466
static bool increase_address_space(struct protection_domain *domain,
1467+
unsigned long address,
14661468
gfp_t gfp)
14671469
{
14681470
unsigned long flags;
@@ -1471,8 +1473,8 @@ static bool increase_address_space(struct protection_domain *domain,
14711473

14721474
spin_lock_irqsave(&domain->lock, flags);
14731475

1474-
if (WARN_ON_ONCE(domain->mode == PAGE_MODE_6_LEVEL))
1475-
/* address space already 64 bit large */
1476+
if (address <= PM_LEVEL_SIZE(domain->mode) ||
1477+
WARN_ON_ONCE(domain->mode == PAGE_MODE_6_LEVEL))
14761478
goto out;
14771479

14781480
pte = (void *)get_zeroed_page(gfp);
@@ -1505,7 +1507,7 @@ static u64 *alloc_pte(struct protection_domain *domain,
15051507
BUG_ON(!is_power_of_2(page_size));
15061508

15071509
while (address > PM_LEVEL_SIZE(domain->mode))
1508-
*updated = increase_address_space(domain, gfp) || *updated;
1510+
*updated = increase_address_space(domain, address, gfp) || *updated;
15091511

15101512
level = domain->mode - 1;
15111513
pte = &domain->pt_root[PM_LEVEL_INDEX(level, address)];

drivers/iommu/amd_iommu_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@
130130
#define EVENT_TYPE_INV_PPR_REQ 0x9
131131
#define EVENT_DEVID_MASK 0xffff
132132
#define EVENT_DEVID_SHIFT 0
133-
#define EVENT_DOMID_MASK 0xffff
134-
#define EVENT_DOMID_SHIFT 0
133+
#define EVENT_DOMID_MASK_LO 0xffff
134+
#define EVENT_DOMID_MASK_HI 0xf0000
135135
#define EVENT_FLAGS_MASK 0xfff
136136
#define EVENT_FLAGS_SHIFT 0x10
137137

drivers/iommu/arm-smmu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
812812
return 0;
813813

814814
out_clear_smmu:
815+
__arm_smmu_free_bitmap(smmu->context_map, cfg->cbndx);
815816
smmu_domain->smmu = NULL;
816817
out_unlock:
817818
mutex_unlock(&smmu_domain->init_mutex);

drivers/iommu/io-pgtable-arm.c

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@
166166
#define ARM_MALI_LPAE_TTBR_READ_INNER BIT(2)
167167
#define ARM_MALI_LPAE_TTBR_SHARE_OUTER BIT(4)
168168

169+
#define ARM_MALI_LPAE_MEMATTR_IMP_DEF 0x88ULL
170+
#define ARM_MALI_LPAE_MEMATTR_WRITE_ALLOC 0x8DULL
171+
169172
/* IOPTE accessors */
170173
#define iopte_deref(pte,d) __va(iopte_to_paddr(pte, d))
171174

@@ -1015,27 +1018,56 @@ arm_32_lpae_alloc_pgtable_s2(struct io_pgtable_cfg *cfg, void *cookie)
10151018
static struct io_pgtable *
10161019
arm_mali_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
10171020
{
1018-
struct io_pgtable *iop;
1021+
struct arm_lpae_io_pgtable *data;
10191022

1020-
if (cfg->ias != 48 || cfg->oas > 40)
1023+
/* No quirks for Mali (hopefully) */
1024+
if (cfg->quirks)
1025+
return NULL;
1026+
1027+
if (cfg->ias > 48 || cfg->oas > 40)
10211028
return NULL;
10221029

10231030
cfg->pgsize_bitmap &= (SZ_4K | SZ_2M | SZ_1G);
1024-
iop = arm_64_lpae_alloc_pgtable_s1(cfg, cookie);
1025-
if (iop) {
1026-
u64 mair, ttbr;
10271031

1028-
/* Copy values as union fields overlap */
1029-
mair = cfg->arm_lpae_s1_cfg.mair[0];
1030-
ttbr = cfg->arm_lpae_s1_cfg.ttbr[0];
1032+
data = arm_lpae_alloc_pgtable(cfg);
1033+
if (!data)
1034+
return NULL;
10311035

1032-
cfg->arm_mali_lpae_cfg.memattr = mair;
1033-
cfg->arm_mali_lpae_cfg.transtab = ttbr |
1034-
ARM_MALI_LPAE_TTBR_READ_INNER |
1035-
ARM_MALI_LPAE_TTBR_ADRMODE_TABLE;
1036+
/* Mali seems to need a full 4-level table regardless of IAS */
1037+
if (data->levels < ARM_LPAE_MAX_LEVELS) {
1038+
data->levels = ARM_LPAE_MAX_LEVELS;
1039+
data->pgd_size = sizeof(arm_lpae_iopte);
10361040
}
1041+
/*
1042+
* MEMATTR: Mali has no actual notion of a non-cacheable type, so the
1043+
* best we can do is mimic the out-of-tree driver and hope that the
1044+
* "implementation-defined caching policy" is good enough. Similarly,
1045+
* we'll use it for the sake of a valid attribute for our 'device'
1046+
* index, although callers should never request that in practice.
1047+
*/
1048+
cfg->arm_mali_lpae_cfg.memattr =
1049+
(ARM_MALI_LPAE_MEMATTR_IMP_DEF
1050+
<< ARM_LPAE_MAIR_ATTR_SHIFT(ARM_LPAE_MAIR_ATTR_IDX_NC)) |
1051+
(ARM_MALI_LPAE_MEMATTR_WRITE_ALLOC
1052+
<< ARM_LPAE_MAIR_ATTR_SHIFT(ARM_LPAE_MAIR_ATTR_IDX_CACHE)) |
1053+
(ARM_MALI_LPAE_MEMATTR_IMP_DEF
1054+
<< ARM_LPAE_MAIR_ATTR_SHIFT(ARM_LPAE_MAIR_ATTR_IDX_DEV));
10371055

1038-
return iop;
1056+
data->pgd = __arm_lpae_alloc_pages(data->pgd_size, GFP_KERNEL, cfg);
1057+
if (!data->pgd)
1058+
goto out_free_data;
1059+
1060+
/* Ensure the empty pgd is visible before TRANSTAB can be written */
1061+
wmb();
1062+
1063+
cfg->arm_mali_lpae_cfg.transtab = virt_to_phys(data->pgd) |
1064+
ARM_MALI_LPAE_TTBR_READ_INNER |
1065+
ARM_MALI_LPAE_TTBR_ADRMODE_TABLE;
1066+
return &data->iop;
1067+
1068+
out_free_data:
1069+
kfree(data);
1070+
return NULL;
10391071
}
10401072

10411073
struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s1_init_fns = {

drivers/iommu/ipmmu-vmsa.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,6 @@ static int ipmmu_probe(struct platform_device *pdev)
10861086

10871087
mmu->num_ctx = min(IPMMU_CTX_MAX, mmu->features->number_of_contexts);
10881088

1089-
irq = platform_get_irq(pdev, 0);
1090-
10911089
/*
10921090
* Determine if this IPMMU instance is a root device by checking for
10931091
* the lack of has_cache_leaf_nodes flag or renesas,ipmmu-main property.
@@ -1106,6 +1104,7 @@ static int ipmmu_probe(struct platform_device *pdev)
11061104

11071105
/* Root devices have mandatory IRQs */
11081106
if (ipmmu_is_root(mmu)) {
1107+
irq = platform_get_irq(pdev, 0);
11091108
if (irq < 0) {
11101109
dev_err(&pdev->dev, "no IRQ found\n");
11111110
return irq;

drivers/iommu/rockchip-iommu.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct rk_iommu {
100100
struct device *dev;
101101
void __iomem **bases;
102102
int num_mmu;
103+
int num_irq;
103104
struct clk_bulk_data *clocks;
104105
int num_clocks;
105106
bool reset_disabled;
@@ -1136,7 +1137,7 @@ static int rk_iommu_probe(struct platform_device *pdev)
11361137
struct rk_iommu *iommu;
11371138
struct resource *res;
11381139
int num_res = pdev->num_resources;
1139-
int err, i, irq;
1140+
int err, i;
11401141

11411142
iommu = devm_kzalloc(dev, sizeof(*iommu), GFP_KERNEL);
11421143
if (!iommu)
@@ -1163,6 +1164,10 @@ static int rk_iommu_probe(struct platform_device *pdev)
11631164
if (iommu->num_mmu == 0)
11641165
return PTR_ERR(iommu->bases[0]);
11651166

1167+
iommu->num_irq = platform_irq_count(pdev);
1168+
if (iommu->num_irq < 0)
1169+
return iommu->num_irq;
1170+
11661171
iommu->reset_disabled = device_property_read_bool(dev,
11671172
"rockchip,disable-mmu-reset");
11681173

@@ -1219,8 +1224,9 @@ static int rk_iommu_probe(struct platform_device *pdev)
12191224

12201225
pm_runtime_enable(dev);
12211226

1222-
i = 0;
1223-
while ((irq = platform_get_irq(pdev, i++)) != -ENXIO) {
1227+
for (i = 0; i < iommu->num_irq; i++) {
1228+
int irq = platform_get_irq(pdev, i);
1229+
12241230
if (irq < 0)
12251231
return irq;
12261232

@@ -1245,10 +1251,13 @@ static int rk_iommu_probe(struct platform_device *pdev)
12451251
static void rk_iommu_shutdown(struct platform_device *pdev)
12461252
{
12471253
struct rk_iommu *iommu = platform_get_drvdata(pdev);
1248-
int i = 0, irq;
1254+
int i;
1255+
1256+
for (i = 0; i < iommu->num_irq; i++) {
1257+
int irq = platform_get_irq(pdev, i);
12491258

1250-
while ((irq = platform_get_irq(pdev, i++)) != -ENXIO)
12511259
devm_free_irq(iommu->dev, irq, iommu);
1260+
}
12521261

12531262
pm_runtime_force_suspend(&pdev->dev);
12541263
}

0 commit comments

Comments
 (0)