Skip to content

Commit 7bdecc2

Browse files
committed
Merge tag 'iommu-fixes-v6.4-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu
Pull iommu fixes from Joerg Roedel: "AMD IOMMU fixes: - Fix domain type and size checks - IOTLB flush fix for invalidating ranges - Guest IRQ handling fixes and GALOG overflow fix Rockchip IOMMU: - Error handling fix Mediatek IOMMU: - IOTLB flushing fix Renesas IOMMU: - Fix Kconfig dependencies to avoid build errors on RiscV" * tag 'iommu-fixes-v6.4-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: iommu/mediatek: Flush IOTLB completely only if domain has been attached iommu/amd/pgtbl_v2: Fix domain max address iommu/amd: Fix domain flush size when syncing iotlb iommu/amd: Add missing domain type checks iommu/amd: Fix up merge conflict resolution iommu/amd: Handle GALog overflows iommu/amd: Don't block updates to GATag if guest mode is on iommu/rockchip: Fix unwind goto issue iommu: Make IPMMU_VMSA dependencies more strict
2 parents e99a746 + b3fc957 commit 7bdecc2

File tree

6 files changed

+61
-16
lines changed

6 files changed

+61
-16
lines changed

drivers/iommu/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ config EXYNOS_IOMMU_DEBUG
282282
config IPMMU_VMSA
283283
bool "Renesas VMSA-compatible IPMMU"
284284
depends on ARCH_RENESAS || COMPILE_TEST
285+
depends on ARM || ARM64 || COMPILE_TEST
285286
depends on !GENERIC_ATOMIC64 # for IOMMU_IO_PGTABLE_LPAE
286287
select IOMMU_API
287288
select IOMMU_IO_PGTABLE_LPAE

drivers/iommu/amd/amd_iommu.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ extern irqreturn_t amd_iommu_int_thread(int irq, void *data);
1515
extern irqreturn_t amd_iommu_int_handler(int irq, void *data);
1616
extern void amd_iommu_apply_erratum_63(struct amd_iommu *iommu, u16 devid);
1717
extern void amd_iommu_restart_event_logging(struct amd_iommu *iommu);
18-
extern int amd_iommu_init_devices(void);
19-
extern void amd_iommu_uninit_devices(void);
20-
extern void amd_iommu_init_notifier(void);
18+
extern void amd_iommu_restart_ga_log(struct amd_iommu *iommu);
2119
extern void amd_iommu_set_rlookup_table(struct amd_iommu *iommu, u16 devid);
2220

2321
#ifdef CONFIG_AMD_IOMMU_DEBUGFS

drivers/iommu/amd/init.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,30 @@ void amd_iommu_restart_event_logging(struct amd_iommu *iommu)
758758
iommu_feature_enable(iommu, CONTROL_EVT_LOG_EN);
759759
}
760760

761+
/*
762+
* This function restarts event logging in case the IOMMU experienced
763+
* an GA log overflow.
764+
*/
765+
void amd_iommu_restart_ga_log(struct amd_iommu *iommu)
766+
{
767+
u32 status;
768+
769+
status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET);
770+
if (status & MMIO_STATUS_GALOG_RUN_MASK)
771+
return;
772+
773+
pr_info_ratelimited("IOMMU GA Log restarting\n");
774+
775+
iommu_feature_disable(iommu, CONTROL_GALOG_EN);
776+
iommu_feature_disable(iommu, CONTROL_GAINT_EN);
777+
778+
writel(MMIO_STATUS_GALOG_OVERFLOW_MASK,
779+
iommu->mmio_base + MMIO_STATUS_OFFSET);
780+
781+
iommu_feature_enable(iommu, CONTROL_GAINT_EN);
782+
iommu_feature_enable(iommu, CONTROL_GALOG_EN);
783+
}
784+
761785
/*
762786
* This function resets the command buffer if the IOMMU stopped fetching
763787
* commands from it.

drivers/iommu/amd/iommu.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,7 @@ amd_iommu_set_pci_msi_domain(struct device *dev, struct amd_iommu *iommu) { }
845845
(MMIO_STATUS_EVT_OVERFLOW_INT_MASK | \
846846
MMIO_STATUS_EVT_INT_MASK | \
847847
MMIO_STATUS_PPR_INT_MASK | \
848+
MMIO_STATUS_GALOG_OVERFLOW_MASK | \
848849
MMIO_STATUS_GALOG_INT_MASK)
849850

850851
irqreturn_t amd_iommu_int_thread(int irq, void *data)
@@ -868,10 +869,16 @@ irqreturn_t amd_iommu_int_thread(int irq, void *data)
868869
}
869870

870871
#ifdef CONFIG_IRQ_REMAP
871-
if (status & MMIO_STATUS_GALOG_INT_MASK) {
872+
if (status & (MMIO_STATUS_GALOG_INT_MASK |
873+
MMIO_STATUS_GALOG_OVERFLOW_MASK)) {
872874
pr_devel("Processing IOMMU GA Log\n");
873875
iommu_poll_ga_log(iommu);
874876
}
877+
878+
if (status & MMIO_STATUS_GALOG_OVERFLOW_MASK) {
879+
pr_info_ratelimited("IOMMU GA Log overflow\n");
880+
amd_iommu_restart_ga_log(iommu);
881+
}
875882
#endif
876883

877884
if (status & MMIO_STATUS_EVT_OVERFLOW_INT_MASK) {
@@ -2067,7 +2074,7 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
20672074
{
20682075
struct io_pgtable_ops *pgtbl_ops;
20692076
struct protection_domain *domain;
2070-
int pgtable = amd_iommu_pgtable;
2077+
int pgtable;
20712078
int mode = DEFAULT_PGTABLE_LEVEL;
20722079
int ret;
20732080

@@ -2084,6 +2091,10 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
20842091
mode = PAGE_MODE_NONE;
20852092
} else if (type == IOMMU_DOMAIN_UNMANAGED) {
20862093
pgtable = AMD_IOMMU_V1;
2094+
} else if (type == IOMMU_DOMAIN_DMA || type == IOMMU_DOMAIN_DMA_FQ) {
2095+
pgtable = amd_iommu_pgtable;
2096+
} else {
2097+
return NULL;
20872098
}
20882099

20892100
switch (pgtable) {
@@ -2118,6 +2129,15 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
21182129
return NULL;
21192130
}
21202131

2132+
static inline u64 dma_max_address(void)
2133+
{
2134+
if (amd_iommu_pgtable == AMD_IOMMU_V1)
2135+
return ~0ULL;
2136+
2137+
/* V2 with 4/5 level page table */
2138+
return ((1ULL << PM_LEVEL_SHIFT(amd_iommu_gpt_level)) - 1);
2139+
}
2140+
21212141
static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
21222142
{
21232143
struct protection_domain *domain;
@@ -2134,7 +2154,7 @@ static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
21342154
return NULL;
21352155

21362156
domain->domain.geometry.aperture_start = 0;
2137-
domain->domain.geometry.aperture_end = ~0ULL;
2157+
domain->domain.geometry.aperture_end = dma_max_address();
21382158
domain->domain.geometry.force_aperture = true;
21392159

21402160
return &domain->domain;
@@ -2387,7 +2407,7 @@ static void amd_iommu_iotlb_sync(struct iommu_domain *domain,
23872407
unsigned long flags;
23882408

23892409
spin_lock_irqsave(&dom->lock, flags);
2390-
domain_flush_pages(dom, gather->start, gather->end - gather->start, 1);
2410+
domain_flush_pages(dom, gather->start, gather->end - gather->start + 1, 1);
23912411
amd_iommu_domain_flush_complete(dom);
23922412
spin_unlock_irqrestore(&dom->lock, flags);
23932413
}
@@ -3493,8 +3513,7 @@ int amd_iommu_activate_guest_mode(void *data)
34933513
struct irte_ga *entry = (struct irte_ga *) ir_data->entry;
34943514
u64 valid;
34953515

3496-
if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) ||
3497-
!entry || entry->lo.fields_vapic.guest_mode)
3516+
if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) || !entry)
34983517
return 0;
34993518

35003519
valid = entry->lo.fields_vapic.valid;

drivers/iommu/mtk_iommu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,8 @@ static void mtk_iommu_flush_iotlb_all(struct iommu_domain *domain)
781781
{
782782
struct mtk_iommu_domain *dom = to_mtk_domain(domain);
783783

784-
mtk_iommu_tlb_flush_all(dom->bank->parent_data);
784+
if (dom->bank)
785+
mtk_iommu_tlb_flush_all(dom->bank->parent_data);
785786
}
786787

787788
static void mtk_iommu_iotlb_sync(struct iommu_domain *domain,

drivers/iommu/rockchip-iommu.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,20 +1335,22 @@ static int rk_iommu_probe(struct platform_device *pdev)
13351335
for (i = 0; i < iommu->num_irq; i++) {
13361336
int irq = platform_get_irq(pdev, i);
13371337

1338-
if (irq < 0)
1339-
return irq;
1338+
if (irq < 0) {
1339+
err = irq;
1340+
goto err_pm_disable;
1341+
}
13401342

13411343
err = devm_request_irq(iommu->dev, irq, rk_iommu_irq,
13421344
IRQF_SHARED, dev_name(dev), iommu);
1343-
if (err) {
1344-
pm_runtime_disable(dev);
1345-
goto err_remove_sysfs;
1346-
}
1345+
if (err)
1346+
goto err_pm_disable;
13471347
}
13481348

13491349
dma_set_mask_and_coherent(dev, rk_ops->dma_bit_mask);
13501350

13511351
return 0;
1352+
err_pm_disable:
1353+
pm_runtime_disable(dev);
13521354
err_remove_sysfs:
13531355
iommu_device_sysfs_remove(&iommu->iommu);
13541356
err_put_group:

0 commit comments

Comments
 (0)