Skip to content

Commit 6381b44

Browse files
committed
Merge tag 'iommu-fixes-v5.5-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu
Pull iommu fixes from Joerg Roedel: "Two fixes: - Fix NULL-ptr dereference bug in Intel IOMMU driver - Properly save and restore AMD IOMMU performance counter registers when testing if they are writable" * tag 'iommu-fixes-v5.5-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: iommu/amd: Fix IOMMU perf counter clobbering during init iommu/vt-d: Call __dmar_remove_one_dev_info with valid pointer
2 parents 3c45d75 + 8c17bbf commit 6381b44

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

drivers/iommu/amd_iommu_init.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,27 +1655,39 @@ static int iommu_pc_get_set_reg(struct amd_iommu *iommu, u8 bank, u8 cntr,
16551655
static void init_iommu_perf_ctr(struct amd_iommu *iommu)
16561656
{
16571657
struct pci_dev *pdev = iommu->dev;
1658-
u64 val = 0xabcd, val2 = 0;
1658+
u64 val = 0xabcd, val2 = 0, save_reg = 0;
16591659

16601660
if (!iommu_feature(iommu, FEATURE_PC))
16611661
return;
16621662

16631663
amd_iommu_pc_present = true;
16641664

1665+
/* save the value to restore, if writable */
1666+
if (iommu_pc_get_set_reg(iommu, 0, 0, 0, &save_reg, false))
1667+
goto pc_false;
1668+
16651669
/* Check if the performance counters can be written to */
16661670
if ((iommu_pc_get_set_reg(iommu, 0, 0, 0, &val, true)) ||
16671671
(iommu_pc_get_set_reg(iommu, 0, 0, 0, &val2, false)) ||
1668-
(val != val2)) {
1669-
pci_err(pdev, "Unable to write to IOMMU perf counter.\n");
1670-
amd_iommu_pc_present = false;
1671-
return;
1672-
}
1672+
(val != val2))
1673+
goto pc_false;
1674+
1675+
/* restore */
1676+
if (iommu_pc_get_set_reg(iommu, 0, 0, 0, &save_reg, true))
1677+
goto pc_false;
16731678

16741679
pci_info(pdev, "IOMMU performance counters supported\n");
16751680

16761681
val = readl(iommu->mmio_base + MMIO_CNTR_CONF_OFFSET);
16771682
iommu->max_banks = (u8) ((val >> 12) & 0x3f);
16781683
iommu->max_counters = (u8) ((val >> 7) & 0xf);
1684+
1685+
return;
1686+
1687+
pc_false:
1688+
pci_err(pdev, "Unable to read/write to IOMMU perf counter.\n");
1689+
amd_iommu_pc_present = false;
1690+
return;
16791691
}
16801692

16811693
static ssize_t amd_iommu_show_cap(struct device *dev,

drivers/iommu/intel-iommu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5163,7 +5163,8 @@ static void dmar_remove_one_dev_info(struct device *dev)
51635163

51645164
spin_lock_irqsave(&device_domain_lock, flags);
51655165
info = dev->archdata.iommu;
5166-
if (info)
5166+
if (info && info != DEFER_DEVICE_DOMAIN_INFO
5167+
&& info != DUMMY_DEVICE_DOMAIN_INFO)
51675168
__dmar_remove_one_dev_info(info);
51685169
spin_unlock_irqrestore(&device_domain_lock, flags);
51695170
}

0 commit comments

Comments
 (0)