Skip to content

Commit 1a2b418

Browse files
committed
Merge tag 'iommu-fixes-v6.7-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu
Pull iommu fixes from Joerg Roedel: - Fix race conditions in device probe path - Handle ERR_PTR() returns in __iommu_domain_alloc() path - Update MAINTAINERS entry for Qualcom IOMMUs - Printk argument fix in device tree specific code - Several Intel VT-d fixes from Lu Baolu: - Do not support enforcing cache coherency for non-empty domains - Avoid devTLB invalidation if iommu is off - Disable PCI ATS in legacy passthrough mode - Support non-PCI devices when clearing context - Fix incorrect cache invalidation for mm notification - Add MTL to quirk list to skip TE disabling - Set variable intel_dirty_ops to static * tag 'iommu-fixes-v6.7-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: iommu: Fix printk arg in of_iommu_get_resv_regions() iommu/vt-d: Set variable intel_dirty_ops to static iommu/vt-d: Fix incorrect cache invalidation for mm notification iommu/vt-d: Add MTL to quirk list to skip TE disabling iommu/vt-d: Make context clearing consistent with context mapping iommu/vt-d: Disable PCI ATS in legacy passthrough mode iommu/vt-d: Omit devTLB invalidation requests when TES=0 iommu/vt-d: Support enforce_cache_coherency only for empty domains iommu: Avoid more races around device probe MAINTAINERS: list all Qualcomm IOMMU drivers in the QUALCOMM IOMMU entry iommu: Flow ERR_PTR out from __iommu_domain_alloc()
2 parents 06a3c59 + c2183b3 commit 1a2b418

File tree

9 files changed

+126
-42
lines changed

9 files changed

+126
-42
lines changed

MAINTAINERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17946,6 +17946,8 @@ L: iommu@lists.linux.dev
1794617946
L: linux-arm-msm@vger.kernel.org
1794717947
S: Maintained
1794817948
F: drivers/iommu/arm/arm-smmu/qcom_iommu.c
17949+
F: drivers/iommu/arm/arm-smmu/arm-smmu-qcom*
17950+
F: drivers/iommu/msm_iommu*
1794917951

1795017952
QUALCOMM IPC ROUTER (QRTR) DRIVER
1795117953
M: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

drivers/acpi/scan.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,17 +1568,22 @@ static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev,
15681568
int err;
15691569
const struct iommu_ops *ops;
15701570

1571+
/* Serialise to make dev->iommu stable under our potential fwspec */
1572+
mutex_lock(&iommu_probe_device_lock);
15711573
/*
15721574
* If we already translated the fwspec there is nothing left to do,
15731575
* return the iommu_ops.
15741576
*/
15751577
ops = acpi_iommu_fwspec_ops(dev);
1576-
if (ops)
1578+
if (ops) {
1579+
mutex_unlock(&iommu_probe_device_lock);
15771580
return ops;
1581+
}
15781582

15791583
err = iort_iommu_configure_id(dev, id_in);
15801584
if (err && err != -EPROBE_DEFER)
15811585
err = viot_iommu_configure(dev);
1586+
mutex_unlock(&iommu_probe_device_lock);
15821587

15831588
/*
15841589
* If we have reason to believe the IOMMU driver missed the initial

drivers/iommu/intel/dmar.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,15 @@ void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 pfsid,
15221522
{
15231523
struct qi_desc desc;
15241524

1525+
/*
1526+
* VT-d spec, section 4.3:
1527+
*
1528+
* Software is recommended to not submit any Device-TLB invalidation
1529+
* requests while address remapping hardware is disabled.
1530+
*/
1531+
if (!(iommu->gcmd & DMA_GCMD_TE))
1532+
return;
1533+
15251534
if (mask) {
15261535
addr |= (1ULL << (VTD_PAGE_SHIFT + mask - 1)) - 1;
15271536
desc.qw1 = QI_DEV_IOTLB_ADDR(addr) | QI_DEV_IOTLB_SIZE;
@@ -1587,6 +1596,15 @@ void qi_flush_dev_iotlb_pasid(struct intel_iommu *iommu, u16 sid, u16 pfsid,
15871596
unsigned long mask = 1UL << (VTD_PAGE_SHIFT + size_order - 1);
15881597
struct qi_desc desc = {.qw1 = 0, .qw2 = 0, .qw3 = 0};
15891598

1599+
/*
1600+
* VT-d spec, section 4.3:
1601+
*
1602+
* Software is recommended to not submit any Device-TLB invalidation
1603+
* requests while address remapping hardware is disabled.
1604+
*/
1605+
if (!(iommu->gcmd & DMA_GCMD_TE))
1606+
return;
1607+
15901608
desc.qw0 = QI_DEV_EIOTLB_PASID(pasid) | QI_DEV_EIOTLB_SID(sid) |
15911609
QI_DEV_EIOTLB_QDEP(qdep) | QI_DEIOTLB_TYPE |
15921610
QI_DEV_IOTLB_PFSID(pfsid);

drivers/iommu/intel/iommu.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ static int iommu_skip_te_disable;
299299
#define IDENTMAP_AZALIA 4
300300

301301
const struct iommu_ops intel_iommu_ops;
302-
const struct iommu_dirty_ops intel_dirty_ops;
302+
static const struct iommu_dirty_ops intel_dirty_ops;
303303

304304
static bool translation_pre_enabled(struct intel_iommu *iommu)
305305
{
@@ -2207,6 +2207,8 @@ __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn,
22072207
attr |= DMA_FL_PTE_DIRTY;
22082208
}
22092209

2210+
domain->has_mappings = true;
2211+
22102212
pteval = ((phys_addr_t)phys_pfn << VTD_PAGE_SHIFT) | attr;
22112213

22122214
while (nr_pages > 0) {
@@ -2490,7 +2492,8 @@ static int dmar_domain_attach_device(struct dmar_domain *domain,
24902492
return ret;
24912493
}
24922494

2493-
iommu_enable_pci_caps(info);
2495+
if (sm_supported(info->iommu) || !domain_type_is_si(info->domain))
2496+
iommu_enable_pci_caps(info);
24942497

24952498
return 0;
24962499
}
@@ -3925,8 +3928,8 @@ static int domain_context_clear_one_cb(struct pci_dev *pdev, u16 alias, void *op
39253928
*/
39263929
static void domain_context_clear(struct device_domain_info *info)
39273930
{
3928-
if (!info->iommu || !info->dev || !dev_is_pci(info->dev))
3929-
return;
3931+
if (!dev_is_pci(info->dev))
3932+
domain_context_clear_one(info, info->bus, info->devfn);
39303933

39313934
pci_for_each_dma_alias(to_pci_dev(info->dev),
39323935
&domain_context_clear_one_cb, info);
@@ -4360,7 +4363,8 @@ static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain)
43604363
return true;
43614364

43624365
spin_lock_irqsave(&dmar_domain->lock, flags);
4363-
if (!domain_support_force_snooping(dmar_domain)) {
4366+
if (!domain_support_force_snooping(dmar_domain) ||
4367+
(!dmar_domain->use_first_level && dmar_domain->has_mappings)) {
43644368
spin_unlock_irqrestore(&dmar_domain->lock, flags);
43654369
return false;
43664370
}
@@ -4925,7 +4929,7 @@ static int intel_iommu_read_and_clear_dirty(struct iommu_domain *domain,
49254929
return 0;
49264930
}
49274931

4928-
const struct iommu_dirty_ops intel_dirty_ops = {
4932+
static const struct iommu_dirty_ops intel_dirty_ops = {
49294933
.set_dirty_tracking = intel_iommu_set_dirty_tracking,
49304934
.read_and_clear_dirty = intel_iommu_read_and_clear_dirty,
49314935
};
@@ -5073,7 +5077,7 @@ static void quirk_igfx_skip_te_disable(struct pci_dev *dev)
50735077
ver = (dev->device >> 8) & 0xff;
50745078
if (ver != 0x45 && ver != 0x46 && ver != 0x4c &&
50755079
ver != 0x4e && ver != 0x8a && ver != 0x98 &&
5076-
ver != 0x9a && ver != 0xa7)
5080+
ver != 0x9a && ver != 0xa7 && ver != 0x7d)
50775081
return;
50785082

50795083
if (risky_device(dev))

drivers/iommu/intel/iommu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ struct dmar_domain {
602602
*/
603603
u8 dirty_tracking:1; /* Dirty tracking is enabled */
604604
u8 nested_parent:1; /* Has other domains nested on it */
605+
u8 has_mappings:1; /* Has mappings configured through
606+
* iommu_map() interface.
607+
*/
605608

606609
spinlock_t lock; /* Protect device tracking lists */
607610
struct list_head devices; /* all devices' list */

drivers/iommu/intel/svm.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,39 @@ static void intel_flush_svm_range(struct intel_svm *svm, unsigned long address,
216216
rcu_read_unlock();
217217
}
218218

219+
static void intel_flush_svm_all(struct intel_svm *svm)
220+
{
221+
struct device_domain_info *info;
222+
struct intel_svm_dev *sdev;
223+
224+
rcu_read_lock();
225+
list_for_each_entry_rcu(sdev, &svm->devs, list) {
226+
info = dev_iommu_priv_get(sdev->dev);
227+
228+
qi_flush_piotlb(sdev->iommu, sdev->did, svm->pasid, 0, -1UL, 0);
229+
if (info->ats_enabled) {
230+
qi_flush_dev_iotlb_pasid(sdev->iommu, sdev->sid, info->pfsid,
231+
svm->pasid, sdev->qdep,
232+
0, 64 - VTD_PAGE_SHIFT);
233+
quirk_extra_dev_tlb_flush(info, 0, 64 - VTD_PAGE_SHIFT,
234+
svm->pasid, sdev->qdep);
235+
}
236+
}
237+
rcu_read_unlock();
238+
}
239+
219240
/* Pages have been freed at this point */
220241
static void intel_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn,
221242
struct mm_struct *mm,
222243
unsigned long start, unsigned long end)
223244
{
224245
struct intel_svm *svm = container_of(mn, struct intel_svm, notifier);
225246

247+
if (start == 0 && end == -1UL) {
248+
intel_flush_svm_all(svm);
249+
return;
250+
}
251+
226252
intel_flush_svm_range(svm, start,
227253
(end - start + PAGE_SIZE - 1) >> VTD_PAGE_SHIFT, 0);
228254
}

drivers/iommu/iommu.c

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,12 @@ static void iommu_deinit_device(struct device *dev)
485485
dev_iommu_free(dev);
486486
}
487487

488+
DEFINE_MUTEX(iommu_probe_device_lock);
489+
488490
static int __iommu_probe_device(struct device *dev, struct list_head *group_list)
489491
{
490492
const struct iommu_ops *ops = dev->bus->iommu_ops;
491493
struct iommu_group *group;
492-
static DEFINE_MUTEX(iommu_probe_device_lock);
493494
struct group_device *gdev;
494495
int ret;
495496

@@ -502,17 +503,15 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
502503
* probably be able to use device_lock() here to minimise the scope,
503504
* but for now enforcing a simple global ordering is fine.
504505
*/
505-
mutex_lock(&iommu_probe_device_lock);
506+
lockdep_assert_held(&iommu_probe_device_lock);
506507

507508
/* Device is probed already if in a group */
508-
if (dev->iommu_group) {
509-
ret = 0;
510-
goto out_unlock;
511-
}
509+
if (dev->iommu_group)
510+
return 0;
512511

513512
ret = iommu_init_device(dev, ops);
514513
if (ret)
515-
goto out_unlock;
514+
return ret;
516515

517516
group = dev->iommu_group;
518517
gdev = iommu_group_alloc_device(group, dev);
@@ -548,7 +547,6 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
548547
list_add_tail(&group->entry, group_list);
549548
}
550549
mutex_unlock(&group->mutex);
551-
mutex_unlock(&iommu_probe_device_lock);
552550

553551
if (dev_is_pci(dev))
554552
iommu_dma_set_pci_32bit_workaround(dev);
@@ -562,8 +560,6 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
562560
iommu_deinit_device(dev);
563561
mutex_unlock(&group->mutex);
564562
iommu_group_put(group);
565-
out_unlock:
566-
mutex_unlock(&iommu_probe_device_lock);
567563

568564
return ret;
569565
}
@@ -573,7 +569,9 @@ int iommu_probe_device(struct device *dev)
573569
const struct iommu_ops *ops;
574570
int ret;
575571

572+
mutex_lock(&iommu_probe_device_lock);
576573
ret = __iommu_probe_device(dev, NULL);
574+
mutex_unlock(&iommu_probe_device_lock);
577575
if (ret)
578576
return ret;
579577

@@ -1788,7 +1786,7 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
17881786
*/
17891787
if (ops->default_domain) {
17901788
if (req_type)
1791-
return NULL;
1789+
return ERR_PTR(-EINVAL);
17921790
return ops->default_domain;
17931791
}
17941792

@@ -1797,15 +1795,15 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
17971795

17981796
/* The driver gave no guidance on what type to use, try the default */
17991797
dom = __iommu_group_alloc_default_domain(group, iommu_def_domain_type);
1800-
if (dom)
1798+
if (!IS_ERR(dom))
18011799
return dom;
18021800

18031801
/* Otherwise IDENTITY and DMA_FQ defaults will try DMA */
18041802
if (iommu_def_domain_type == IOMMU_DOMAIN_DMA)
1805-
return NULL;
1803+
return ERR_PTR(-EINVAL);
18061804
dom = __iommu_group_alloc_default_domain(group, IOMMU_DOMAIN_DMA);
1807-
if (!dom)
1808-
return NULL;
1805+
if (IS_ERR(dom))
1806+
return dom;
18091807

18101808
pr_warn("Failed to allocate default IOMMU domain of type %u for group %s - Falling back to IOMMU_DOMAIN_DMA",
18111809
iommu_def_domain_type, group->name);
@@ -1822,7 +1820,9 @@ static int probe_iommu_group(struct device *dev, void *data)
18221820
struct list_head *group_list = data;
18231821
int ret;
18241822

1823+
mutex_lock(&iommu_probe_device_lock);
18251824
ret = __iommu_probe_device(dev, group_list);
1825+
mutex_unlock(&iommu_probe_device_lock);
18261826
if (ret == -ENODEV)
18271827
ret = 0;
18281828

@@ -2094,10 +2094,17 @@ static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,
20942094
else if (ops->domain_alloc)
20952095
domain = ops->domain_alloc(alloc_type);
20962096
else
2097-
return NULL;
2097+
return ERR_PTR(-EOPNOTSUPP);
20982098

2099+
/*
2100+
* Many domain_alloc ops now return ERR_PTR, make things easier for the
2101+
* driver by accepting ERR_PTR from all domain_alloc ops instead of
2102+
* having two rules.
2103+
*/
2104+
if (IS_ERR(domain))
2105+
return domain;
20992106
if (!domain)
2100-
return NULL;
2107+
return ERR_PTR(-ENOMEM);
21012108

21022109
domain->type = type;
21032110
/*
@@ -2110,9 +2117,14 @@ static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,
21102117
if (!domain->ops)
21112118
domain->ops = ops->default_domain_ops;
21122119

2113-
if (iommu_is_dma_domain(domain) && iommu_get_dma_cookie(domain)) {
2114-
iommu_domain_free(domain);
2115-
domain = NULL;
2120+
if (iommu_is_dma_domain(domain)) {
2121+
int rc;
2122+
2123+
rc = iommu_get_dma_cookie(domain);
2124+
if (rc) {
2125+
iommu_domain_free(domain);
2126+
return ERR_PTR(rc);
2127+
}
21162128
}
21172129
return domain;
21182130
}
@@ -2129,10 +2141,15 @@ __iommu_group_domain_alloc(struct iommu_group *group, unsigned int type)
21292141

21302142
struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus)
21312143
{
2144+
struct iommu_domain *domain;
2145+
21322146
if (bus == NULL || bus->iommu_ops == NULL)
21332147
return NULL;
2134-
return __iommu_domain_alloc(bus->iommu_ops, NULL,
2148+
domain = __iommu_domain_alloc(bus->iommu_ops, NULL,
21352149
IOMMU_DOMAIN_UNMANAGED);
2150+
if (IS_ERR(domain))
2151+
return NULL;
2152+
return domain;
21362153
}
21372154
EXPORT_SYMBOL_GPL(iommu_domain_alloc);
21382155

@@ -3041,8 +3058,8 @@ static int iommu_setup_default_domain(struct iommu_group *group,
30413058
return -EINVAL;
30423059

30433060
dom = iommu_group_alloc_default_domain(group, req_type);
3044-
if (!dom)
3045-
return -ENODEV;
3061+
if (IS_ERR(dom))
3062+
return PTR_ERR(dom);
30463063

30473064
if (group->default_domain == dom)
30483065
return 0;
@@ -3243,21 +3260,23 @@ void iommu_device_unuse_default_domain(struct device *dev)
32433260

32443261
static int __iommu_group_alloc_blocking_domain(struct iommu_group *group)
32453262
{
3263+
struct iommu_domain *domain;
3264+
32463265
if (group->blocking_domain)
32473266
return 0;
32483267

3249-
group->blocking_domain =
3250-
__iommu_group_domain_alloc(group, IOMMU_DOMAIN_BLOCKED);
3251-
if (!group->blocking_domain) {
3268+
domain = __iommu_group_domain_alloc(group, IOMMU_DOMAIN_BLOCKED);
3269+
if (IS_ERR(domain)) {
32523270
/*
32533271
* For drivers that do not yet understand IOMMU_DOMAIN_BLOCKED
32543272
* create an empty domain instead.
32553273
*/
3256-
group->blocking_domain = __iommu_group_domain_alloc(
3257-
group, IOMMU_DOMAIN_UNMANAGED);
3258-
if (!group->blocking_domain)
3259-
return -EINVAL;
3274+
domain = __iommu_group_domain_alloc(group,
3275+
IOMMU_DOMAIN_UNMANAGED);
3276+
if (IS_ERR(domain))
3277+
return PTR_ERR(domain);
32603278
}
3279+
group->blocking_domain = domain;
32613280
return 0;
32623281
}
32633282

0 commit comments

Comments
 (0)