Skip to content

Commit 23971bd

Browse files
committed
Merge tag 'iommu-updates-v3.18' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu
Pull IOMMU updates from Joerg Roedel: "This pull-request includes: - change in the IOMMU-API to convert the former iommu_domain_capable function to just iommu_capable - various fixes in handling RMRR ranges for the VT-d driver (one fix requires a device driver core change which was acked by Greg KH) - the AMD IOMMU driver now assigns and deassigns complete alias groups to fix issues with devices using the wrong PCI request-id - MMU-401 support for the ARM SMMU driver - multi-master IOMMU group support for the ARM SMMU driver - various other small fixes all over the place" * tag 'iommu-updates-v3.18' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: (41 commits) iommu/vt-d: Work around broken RMRR firmware entries iommu/vt-d: Store bus information in RMRR PCI device path iommu/vt-d: Only remove domain when device is removed driver core: Add BUS_NOTIFY_REMOVED_DEVICE event iommu/amd: Fix devid mapping for ivrs_ioapic override iommu/irq_remapping: Fix the regression of hpet irq remapping iommu: Fix bus notifier breakage iommu/amd: Split init_iommu_group() from iommu_init_device() iommu: Rework iommu_group_get_for_pci_dev() iommu: Make of_device_id array const amd_iommu: do not dereference a NULL pointer address. iommu/omap: Remove omap_iommu unused owner field iommu: Remove iommu_domain_has_cap() API function IB/usnic: Convert to use new iommu_capable() API function vfio: Convert to use new iommu_capable() API function kvm: iommu: Convert to use new iommu_capable() API function iommu/tegra: Convert to iommu_capable() API function iommu/msm: Convert to iommu_capable() API function iommu/vt-d: Convert to iommu_capable() API function iommu/fsl: Convert to iommu_capable() API function ...
2 parents c0fa237 + 09b5269 commit 23971bd

25 files changed

Lines changed: 461 additions & 356 deletions

‎Documentation/devicetree/bindings/iommu/arm,smmu.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ conditions.
1414
"arm,smmu-v1"
1515
"arm,smmu-v2"
1616
"arm,mmu-400"
17+
"arm,mmu-401"
1718
"arm,mmu-500"
1819

1920
depending on the particular implementation and/or the

‎drivers/base/core.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,9 @@ void device_del(struct device *dev)
12111211
*/
12121212
if (platform_notify_remove)
12131213
platform_notify_remove(dev);
1214+
if (dev->bus)
1215+
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
1216+
BUS_NOTIFY_REMOVED_DEVICE, dev);
12141217
kobject_uevent(&dev->kobj, KOBJ_REMOVE);
12151218
cleanup_device_parent(dev);
12161219
kobject_del(&dev->kobj);

‎drivers/infiniband/hw/usnic/usnic_uiom.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ int usnic_uiom_attach_dev_to_pd(struct usnic_uiom_pd *pd, struct device *dev)
507507
if (err)
508508
goto out_free_dev;
509509

510-
if (!iommu_domain_has_cap(pd->domain, IOMMU_CAP_CACHE_COHERENCY)) {
510+
if (!iommu_capable(dev->bus, IOMMU_CAP_CACHE_COHERENCY)) {
511511
usnic_err("IOMMU of %s does not support cache coherency\n",
512512
dev_name(dev));
513513
err = -EINVAL;

‎drivers/iommu/amd_iommu.c‎

Lines changed: 68 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,27 @@ int amd_iommu_max_glx_val = -1;
8787

8888
static struct dma_map_ops amd_iommu_dma_ops;
8989

90+
/*
91+
* This struct contains device specific data for the IOMMU
92+
*/
93+
struct iommu_dev_data {
94+
struct list_head list; /* For domain->dev_list */
95+
struct list_head dev_data_list; /* For global dev_data_list */
96+
struct list_head alias_list; /* Link alias-groups together */
97+
struct iommu_dev_data *alias_data;/* The alias dev_data */
98+
struct protection_domain *domain; /* Domain the device is bound to */
99+
u16 devid; /* PCI Device ID */
100+
bool iommu_v2; /* Device can make use of IOMMUv2 */
101+
bool passthrough; /* Default for device is pt_domain */
102+
struct {
103+
bool enabled;
104+
int qdep;
105+
} ats; /* ATS state */
106+
bool pri_tlp; /* PASID TLB required for
107+
PPR completions */
108+
u32 errata; /* Bitmap for errata to apply */
109+
};
110+
90111
/*
91112
* general struct to manage commands send to an IOMMU
92113
*/
@@ -114,8 +135,9 @@ static struct iommu_dev_data *alloc_dev_data(u16 devid)
114135
if (!dev_data)
115136
return NULL;
116137

138+
INIT_LIST_HEAD(&dev_data->alias_list);
139+
117140
dev_data->devid = devid;
118-
atomic_set(&dev_data->bind, 0);
119141

120142
spin_lock_irqsave(&dev_data_list_lock, flags);
121143
list_add_tail(&dev_data->dev_data_list, &dev_data_list);
@@ -260,17 +282,13 @@ static bool check_device(struct device *dev)
260282
return true;
261283
}
262284

263-
static int init_iommu_group(struct device *dev)
285+
static void init_iommu_group(struct device *dev)
264286
{
265287
struct iommu_group *group;
266288

267289
group = iommu_group_get_for_dev(dev);
268-
269-
if (IS_ERR(group))
270-
return PTR_ERR(group);
271-
272-
iommu_group_put(group);
273-
return 0;
290+
if (!IS_ERR(group))
291+
iommu_group_put(group);
274292
}
275293

276294
static int __last_alias(struct pci_dev *pdev, u16 alias, void *data)
@@ -340,7 +358,6 @@ static int iommu_init_device(struct device *dev)
340358
struct pci_dev *pdev = to_pci_dev(dev);
341359
struct iommu_dev_data *dev_data;
342360
u16 alias;
343-
int ret;
344361

345362
if (dev->archdata.iommu)
346363
return 0;
@@ -362,12 +379,9 @@ static int iommu_init_device(struct device *dev)
362379
return -ENOTSUPP;
363380
}
364381
dev_data->alias_data = alias_data;
365-
}
366382

367-
ret = init_iommu_group(dev);
368-
if (ret) {
369-
free_dev_data(dev_data);
370-
return ret;
383+
/* Add device to the alias_list */
384+
list_add(&dev_data->alias_list, &alias_data->alias_list);
371385
}
372386

373387
if (pci_iommuv2_capable(pdev)) {
@@ -455,6 +469,15 @@ int __init amd_iommu_init_devices(void)
455469
goto out_free;
456470
}
457471

472+
/*
473+
* Initialize IOMMU groups only after iommu_init_device() has
474+
* had a chance to populate any IVRS defined aliases.
475+
*/
476+
for_each_pci_dev(pdev) {
477+
if (check_device(&pdev->dev))
478+
init_iommu_group(&pdev->dev);
479+
}
480+
458481
return 0;
459482

460483
out_free:
@@ -1368,6 +1391,9 @@ static int iommu_map_page(struct protection_domain *dom,
13681391
count = PAGE_SIZE_PTE_COUNT(page_size);
13691392
pte = alloc_pte(dom, bus_addr, page_size, NULL, GFP_KERNEL);
13701393

1394+
if (!pte)
1395+
return -ENOMEM;
1396+
13711397
for (i = 0; i < count; ++i)
13721398
if (IOMMU_PTE_PRESENT(pte[i]))
13731399
return -EBUSY;
@@ -2122,35 +2148,29 @@ static void do_detach(struct iommu_dev_data *dev_data)
21222148
static int __attach_device(struct iommu_dev_data *dev_data,
21232149
struct protection_domain *domain)
21242150
{
2151+
struct iommu_dev_data *head, *entry;
21252152
int ret;
21262153

21272154
/* lock domain */
21282155
spin_lock(&domain->lock);
21292156

2130-
if (dev_data->alias_data != NULL) {
2131-
struct iommu_dev_data *alias_data = dev_data->alias_data;
2157+
head = dev_data;
21322158

2133-
/* Some sanity checks */
2134-
ret = -EBUSY;
2135-
if (alias_data->domain != NULL &&
2136-
alias_data->domain != domain)
2137-
goto out_unlock;
2159+
if (head->alias_data != NULL)
2160+
head = head->alias_data;
21382161

2139-
if (dev_data->domain != NULL &&
2140-
dev_data->domain != domain)
2141-
goto out_unlock;
2162+
/* Now we have the root of the alias group, if any */
21422163

2143-
/* Do real assignment */
2144-
if (alias_data->domain == NULL)
2145-
do_attach(alias_data, domain);
2146-
2147-
atomic_inc(&alias_data->bind);
2148-
}
2164+
ret = -EBUSY;
2165+
if (head->domain != NULL)
2166+
goto out_unlock;
21492167

2150-
if (dev_data->domain == NULL)
2151-
do_attach(dev_data, domain);
2168+
/* Attach alias group root */
2169+
do_attach(head, domain);
21522170

2153-
atomic_inc(&dev_data->bind);
2171+
/* Attach other devices in the alias group */
2172+
list_for_each_entry(entry, &head->alias_list, alias_list)
2173+
do_attach(entry, domain);
21542174

21552175
ret = 0;
21562176

@@ -2298,6 +2318,7 @@ static int attach_device(struct device *dev,
22982318
*/
22992319
static void __detach_device(struct iommu_dev_data *dev_data)
23002320
{
2321+
struct iommu_dev_data *head, *entry;
23012322
struct protection_domain *domain;
23022323
unsigned long flags;
23032324

@@ -2307,15 +2328,14 @@ static void __detach_device(struct iommu_dev_data *dev_data)
23072328

23082329
spin_lock_irqsave(&domain->lock, flags);
23092330

2310-
if (dev_data->alias_data != NULL) {
2311-
struct iommu_dev_data *alias_data = dev_data->alias_data;
2331+
head = dev_data;
2332+
if (head->alias_data != NULL)
2333+
head = head->alias_data;
23122334

2313-
if (atomic_dec_and_test(&alias_data->bind))
2314-
do_detach(alias_data);
2315-
}
2335+
list_for_each_entry(entry, &head->alias_list, alias_list)
2336+
do_detach(entry);
23162337

2317-
if (atomic_dec_and_test(&dev_data->bind))
2318-
do_detach(dev_data);
2338+
do_detach(head);
23192339

23202340
spin_unlock_irqrestore(&domain->lock, flags);
23212341

@@ -2415,6 +2435,7 @@ static int device_change_notifier(struct notifier_block *nb,
24152435
case BUS_NOTIFY_ADD_DEVICE:
24162436

24172437
iommu_init_device(dev);
2438+
init_iommu_group(dev);
24182439

24192440
/*
24202441
* dev_data is still NULL and
@@ -3158,7 +3179,6 @@ static void cleanup_domain(struct protection_domain *domain)
31583179
entry = list_first_entry(&domain->dev_list,
31593180
struct iommu_dev_data, list);
31603181
__detach_device(entry);
3161-
atomic_set(&entry->bind, 0);
31623182
}
31633183

31643184
write_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
@@ -3384,28 +3404,27 @@ static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,
33843404
return paddr;
33853405
}
33863406

3387-
static int amd_iommu_domain_has_cap(struct iommu_domain *domain,
3388-
unsigned long cap)
3407+
static bool amd_iommu_capable(enum iommu_cap cap)
33893408
{
33903409
switch (cap) {
33913410
case IOMMU_CAP_CACHE_COHERENCY:
3392-
return 1;
3411+
return true;
33933412
case IOMMU_CAP_INTR_REMAP:
3394-
return irq_remapping_enabled;
3413+
return (irq_remapping_enabled == 1);
33953414
}
33963415

3397-
return 0;
3416+
return false;
33983417
}
33993418

34003419
static const struct iommu_ops amd_iommu_ops = {
3420+
.capable = amd_iommu_capable,
34013421
.domain_init = amd_iommu_domain_init,
34023422
.domain_destroy = amd_iommu_domain_destroy,
34033423
.attach_dev = amd_iommu_attach_device,
34043424
.detach_dev = amd_iommu_detach_device,
34053425
.map = amd_iommu_map,
34063426
.unmap = amd_iommu_unmap,
34073427
.iova_to_phys = amd_iommu_iova_to_phys,
3408-
.domain_has_cap = amd_iommu_domain_has_cap,
34093428
.pgsize_bitmap = AMD_IOMMU_PGSIZES,
34103429
};
34113430

@@ -4235,7 +4254,7 @@ static int msi_setup_irq(struct pci_dev *pdev, unsigned int irq,
42354254
return 0;
42364255
}
42374256

4238-
static int setup_hpet_msi(unsigned int irq, unsigned int id)
4257+
static int alloc_hpet_msi(unsigned int irq, unsigned int id)
42394258
{
42404259
struct irq_2_irte *irte_info;
42414260
struct irq_cfg *cfg;
@@ -4274,6 +4293,6 @@ struct irq_remap_ops amd_iommu_irq_ops = {
42744293
.compose_msi_msg = compose_msi_msg,
42754294
.msi_alloc_irq = msi_alloc_irq,
42764295
.msi_setup_irq = msi_setup_irq,
4277-
.setup_hpet_msi = setup_hpet_msi,
4296+
.alloc_hpet_msi = alloc_hpet_msi,
42784297
};
42794298
#endif

‎drivers/iommu/amd_iommu_init.c‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ static void __init set_dev_entry_from_acpi(struct amd_iommu *iommu,
712712
set_iommu_for_device(iommu, devid);
713713
}
714714

715-
static int __init add_special_device(u8 type, u8 id, u16 devid, bool cmd_line)
715+
static int __init add_special_device(u8 type, u8 id, u16 *devid, bool cmd_line)
716716
{
717717
struct devid_map *entry;
718718
struct list_head *list;
@@ -731,6 +731,8 @@ static int __init add_special_device(u8 type, u8 id, u16 devid, bool cmd_line)
731731
pr_info("AMD-Vi: Command-line override present for %s id %d - ignoring\n",
732732
type == IVHD_SPECIAL_IOAPIC ? "IOAPIC" : "HPET", id);
733733

734+
*devid = entry->devid;
735+
734736
return 0;
735737
}
736738

@@ -739,7 +741,7 @@ static int __init add_special_device(u8 type, u8 id, u16 devid, bool cmd_line)
739741
return -ENOMEM;
740742

741743
entry->id = id;
742-
entry->devid = devid;
744+
entry->devid = *devid;
743745
entry->cmd_line = cmd_line;
744746

745747
list_add_tail(&entry->list, list);
@@ -754,7 +756,7 @@ static int __init add_early_maps(void)
754756
for (i = 0; i < early_ioapic_map_size; ++i) {
755757
ret = add_special_device(IVHD_SPECIAL_IOAPIC,
756758
early_ioapic_map[i].id,
757-
early_ioapic_map[i].devid,
759+
&early_ioapic_map[i].devid,
758760
early_ioapic_map[i].cmd_line);
759761
if (ret)
760762
return ret;
@@ -763,7 +765,7 @@ static int __init add_early_maps(void)
763765
for (i = 0; i < early_hpet_map_size; ++i) {
764766
ret = add_special_device(IVHD_SPECIAL_HPET,
765767
early_hpet_map[i].id,
766-
early_hpet_map[i].devid,
768+
&early_hpet_map[i].devid,
767769
early_hpet_map[i].cmd_line);
768770
if (ret)
769771
return ret;
@@ -978,10 +980,17 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
978980
PCI_SLOT(devid),
979981
PCI_FUNC(devid));
980982

981-
set_dev_entry_from_acpi(iommu, devid, e->flags, 0);
982-
ret = add_special_device(type, handle, devid, false);
983+
ret = add_special_device(type, handle, &devid, false);
983984
if (ret)
984985
return ret;
986+
987+
/*
988+
* add_special_device might update the devid in case a
989+
* command-line override is present. So call
990+
* set_dev_entry_from_acpi after add_special_device.
991+
*/
992+
set_dev_entry_from_acpi(iommu, devid, e->flags, 0);
993+
985994
break;
986995
}
987996
default:

‎drivers/iommu/amd_iommu_types.h‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -417,27 +417,6 @@ struct protection_domain {
417417

418418
};
419419

420-
/*
421-
* This struct contains device specific data for the IOMMU
422-
*/
423-
struct iommu_dev_data {
424-
struct list_head list; /* For domain->dev_list */
425-
struct list_head dev_data_list; /* For global dev_data_list */
426-
struct iommu_dev_data *alias_data;/* The alias dev_data */
427-
struct protection_domain *domain; /* Domain the device is bound to */
428-
atomic_t bind; /* Domain attach reference count */
429-
u16 devid; /* PCI Device ID */
430-
bool iommu_v2; /* Device can make use of IOMMUv2 */
431-
bool passthrough; /* Default for device is pt_domain */
432-
struct {
433-
bool enabled;
434-
int qdep;
435-
} ats; /* ATS state */
436-
bool pri_tlp; /* PASID TLB required for
437-
PPR completions */
438-
u32 errata; /* Bitmap for errata to apply */
439-
};
440-
441420
/*
442421
* For dynamic growth the aperture size is split into ranges of 128MB of
443422
* DMA address space each. This struct represents one such range.

0 commit comments

Comments
 (0)