Skip to content

Commit ef9417e

Browse files
committed
Merge tag 'iommu-updates-v4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu
Pull IOMMU updates from Joerg Roedel: "This time there are not a lot of changes coming from the IOMMU side. That is partly because I returned from my parental leave late in the development process and probably partly because everyone was busy with Spectre and Meltdown mitigation work and didn't find the time for IOMMU work. So here are the few changes that queued up for this merge window: - 5-level page-table support for the Intel IOMMU. - error reporting improvements for the AMD IOMMU driver - additional DT bindings for ipmmu-vmsa (Renesas) - small fixes and cleanups" * tag 'iommu-updates-v4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: iommu: Clean up of_iommu_init_fn iommu/ipmmu-vmsa: Remove redundant of_iommu_init_fn hook iommu/msm: Claim bus ops on probe iommu/vt-d: Enable 5-level paging mode in the PASID entry iommu/vt-d: Add a check for 5-level paging support iommu/vt-d: Add a check for 1GB page support iommu/vt-d: Enable upto 57 bits of domain address width iommu/vt-d: Use domain instead of cache fetching iommu/exynos: Don't unconditionally steal bus ops iommu/omap: Fix debugfs_create_*() usage iommu/vt-d: clean up pr_irq if request_threaded_irq fails iommu: Check the result of iommu_group_get() for NULL iommu/ipmmu-vmsa: Add r8a779(70|95) DT bindings iommu/ipmmu-vmsa: Add r8a7796 DT binding iommu/amd: Set the device table entry PPR bit for IOMMU V2 devices iommu/amd - Record more information about unknown events
2 parents 605dc77 + fedbd94 commit ef9417e

File tree

16 files changed

+83
-70
lines changed

16 files changed

+83
-70
lines changed

Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Required Properties:
1616
- "renesas,ipmmu-r8a7793" for the R8A7793 (R-Car M2-N) IPMMU.
1717
- "renesas,ipmmu-r8a7794" for the R8A7794 (R-Car E2) IPMMU.
1818
- "renesas,ipmmu-r8a7795" for the R8A7795 (R-Car H3) IPMMU.
19+
- "renesas,ipmmu-r8a7796" for the R8A7796 (R-Car M3-W) IPMMU.
20+
- "renesas,ipmmu-r8a77970" for the R8A77970 (R-Car V3M) IPMMU.
21+
- "renesas,ipmmu-r8a77995" for the R8A77995 (R-Car D3) IPMMU.
1922
- "renesas,ipmmu-vmsa" for generic R-Car Gen2 VMSA-compatible IPMMU.
2023

2124
- reg: Base address and size of the IPMMU registers.

drivers/iommu/amd_iommu.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,9 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
617617
address, flags);
618618
break;
619619
default:
620-
printk(KERN_ERR "UNKNOWN type=0x%02x]\n", type);
620+
printk(KERN_ERR "UNKNOWN type=0x%02x event[0]=0x%08x "
621+
"event[1]=0x%08x event[2]=0x%08x event[3]=0x%08x\n",
622+
type, event[0], event[1], event[2], event[3]);
621623
}
622624

623625
memset(__evt, 0, 4 * sizeof(u32));
@@ -1816,7 +1818,8 @@ static bool dma_ops_domain(struct protection_domain *domain)
18161818
return domain->flags & PD_DMA_OPS_MASK;
18171819
}
18181820

1819-
static void set_dte_entry(u16 devid, struct protection_domain *domain, bool ats)
1821+
static void set_dte_entry(u16 devid, struct protection_domain *domain,
1822+
bool ats, bool ppr)
18201823
{
18211824
u64 pte_root = 0;
18221825
u64 flags = 0;
@@ -1833,6 +1836,13 @@ static void set_dte_entry(u16 devid, struct protection_domain *domain, bool ats)
18331836
if (ats)
18341837
flags |= DTE_FLAG_IOTLB;
18351838

1839+
if (ppr) {
1840+
struct amd_iommu *iommu = amd_iommu_rlookup_table[devid];
1841+
1842+
if (iommu_feature(iommu, FEATURE_EPHSUP))
1843+
pte_root |= 1ULL << DEV_ENTRY_PPR;
1844+
}
1845+
18361846
if (domain->flags & PD_IOMMUV2_MASK) {
18371847
u64 gcr3 = iommu_virt_to_phys(domain->gcr3_tbl);
18381848
u64 glx = domain->glx;
@@ -1895,9 +1905,9 @@ static void do_attach(struct iommu_dev_data *dev_data,
18951905
domain->dev_cnt += 1;
18961906

18971907
/* Update device table */
1898-
set_dte_entry(dev_data->devid, domain, ats);
1908+
set_dte_entry(dev_data->devid, domain, ats, dev_data->iommu_v2);
18991909
if (alias != dev_data->devid)
1900-
set_dte_entry(alias, domain, ats);
1910+
set_dte_entry(alias, domain, ats, dev_data->iommu_v2);
19011911

19021912
device_flush_dte(dev_data);
19031913
}
@@ -2276,13 +2286,15 @@ static void update_device_table(struct protection_domain *domain)
22762286
struct iommu_dev_data *dev_data;
22772287

22782288
list_for_each_entry(dev_data, &domain->dev_list, list) {
2279-
set_dte_entry(dev_data->devid, domain, dev_data->ats.enabled);
2289+
set_dte_entry(dev_data->devid, domain, dev_data->ats.enabled,
2290+
dev_data->iommu_v2);
22802291

22812292
if (dev_data->devid == dev_data->alias)
22822293
continue;
22832294

22842295
/* There is an alias, update device table entry for it */
2285-
set_dte_entry(dev_data->alias, domain, dev_data->ats.enabled);
2296+
set_dte_entry(dev_data->alias, domain, dev_data->ats.enabled,
2297+
dev_data->iommu_v2);
22862298
}
22872299
}
22882300

drivers/iommu/amd_iommu_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
#define FEATURE_HE (1ULL<<8)
9999
#define FEATURE_PC (1ULL<<9)
100100
#define FEATURE_GAM_VAPIC (1ULL<<21)
101+
#define FEATURE_EPHSUP (1ULL<<50)
101102

102103
#define FEATURE_PASID_SHIFT 32
103104
#define FEATURE_PASID_MASK (0x1fULL << FEATURE_PASID_SHIFT)
@@ -192,6 +193,7 @@
192193
/* macros and definitions for device table entries */
193194
#define DEV_ENTRY_VALID 0x00
194195
#define DEV_ENTRY_TRANSLATION 0x01
196+
#define DEV_ENTRY_PPR 0x34
195197
#define DEV_ENTRY_IR 0x3d
196198
#define DEV_ENTRY_IW 0x3e
197199
#define DEV_ENTRY_NO_PAGE_FAULT 0x62

drivers/iommu/arm-smmu-v3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2971,7 +2971,7 @@ static struct platform_driver arm_smmu_driver = {
29712971
};
29722972
module_platform_driver(arm_smmu_driver);
29732973

2974-
IOMMU_OF_DECLARE(arm_smmuv3, "arm,smmu-v3", NULL);
2974+
IOMMU_OF_DECLARE(arm_smmuv3, "arm,smmu-v3");
29752975

29762976
MODULE_DESCRIPTION("IOMMU API for ARM architected SMMUv3 implementations");
29772977
MODULE_AUTHOR("Will Deacon <[email protected]>");

drivers/iommu/arm-smmu.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,12 +2211,12 @@ static struct platform_driver arm_smmu_driver = {
22112211
};
22122212
module_platform_driver(arm_smmu_driver);
22132213

2214-
IOMMU_OF_DECLARE(arm_smmuv1, "arm,smmu-v1", NULL);
2215-
IOMMU_OF_DECLARE(arm_smmuv2, "arm,smmu-v2", NULL);
2216-
IOMMU_OF_DECLARE(arm_mmu400, "arm,mmu-400", NULL);
2217-
IOMMU_OF_DECLARE(arm_mmu401, "arm,mmu-401", NULL);
2218-
IOMMU_OF_DECLARE(arm_mmu500, "arm,mmu-500", NULL);
2219-
IOMMU_OF_DECLARE(cavium_smmuv2, "cavium,smmu-v2", NULL);
2214+
IOMMU_OF_DECLARE(arm_smmuv1, "arm,smmu-v1");
2215+
IOMMU_OF_DECLARE(arm_smmuv2, "arm,smmu-v2");
2216+
IOMMU_OF_DECLARE(arm_mmu400, "arm,mmu-400");
2217+
IOMMU_OF_DECLARE(arm_mmu401, "arm,mmu-401");
2218+
IOMMU_OF_DECLARE(arm_mmu500, "arm,mmu-500");
2219+
IOMMU_OF_DECLARE(cavium_smmuv2, "cavium,smmu-v2");
22202220

22212221
MODULE_DESCRIPTION("IOMMU API for ARM architected SMMU implementations");
22222222
MODULE_AUTHOR("Will Deacon <[email protected]>");

drivers/iommu/exynos-iommu.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,8 +1353,15 @@ static const struct iommu_ops exynos_iommu_ops = {
13531353

13541354
static int __init exynos_iommu_init(void)
13551355
{
1356+
struct device_node *np;
13561357
int ret;
13571358

1359+
np = of_find_matching_node(NULL, sysmmu_of_match);
1360+
if (!np)
1361+
return 0;
1362+
1363+
of_node_put(np);
1364+
13581365
lv2table_kmem_cache = kmem_cache_create("exynos-iommu-lv2table",
13591366
LV2TABLE_SIZE, LV2TABLE_SIZE, 0, NULL);
13601367
if (!lv2table_kmem_cache) {
@@ -1394,4 +1401,4 @@ static int __init exynos_iommu_init(void)
13941401
}
13951402
core_initcall(exynos_iommu_init);
13961403

1397-
IOMMU_OF_DECLARE(exynos_iommu_of, "samsung,exynos-sysmmu", NULL);
1404+
IOMMU_OF_DECLARE(exynos_iommu_of, "samsung,exynos-sysmmu");

drivers/iommu/intel-iommu.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#define IOAPIC_RANGE_END (0xfeefffff)
6565
#define IOVA_START_ADDR (0x1000)
6666

67-
#define DEFAULT_DOMAIN_ADDRESS_WIDTH 48
67+
#define DEFAULT_DOMAIN_ADDRESS_WIDTH 57
6868

6969
#define MAX_AGAW_WIDTH 64
7070
#define MAX_AGAW_PFN_WIDTH (MAX_AGAW_WIDTH - VTD_PAGE_SHIFT)
@@ -1601,8 +1601,7 @@ static void iommu_flush_iotlb_psi(struct intel_iommu *iommu,
16011601
* flush. However, device IOTLB doesn't need to be flushed in this case.
16021602
*/
16031603
if (!cap_caching_mode(iommu->cap) || !map)
1604-
iommu_flush_dev_iotlb(get_iommu_domain(iommu, did),
1605-
addr, mask);
1604+
iommu_flush_dev_iotlb(domain, addr, mask);
16061605
}
16071606

16081607
static void iommu_flush_iova(struct iova_domain *iovad)

drivers/iommu/intel-svm.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#include <linux/interrupt.h>
2727
#include <asm/page.h>
2828

29+
#define PASID_ENTRY_P BIT_ULL(0)
30+
#define PASID_ENTRY_FLPM_5LP BIT_ULL(9)
31+
#define PASID_ENTRY_SRE BIT_ULL(11)
32+
2933
static irqreturn_t prq_event_thread(int irq, void *d);
3034

3135
struct pasid_entry {
@@ -41,6 +45,14 @@ int intel_svm_alloc_pasid_tables(struct intel_iommu *iommu)
4145
struct page *pages;
4246
int order;
4347

48+
if (cpu_feature_enabled(X86_FEATURE_GBPAGES) &&
49+
!cap_fl1gp_support(iommu->cap))
50+
return -EINVAL;
51+
52+
if (cpu_feature_enabled(X86_FEATURE_LA57) &&
53+
!cap_5lp_support(iommu->cap))
54+
return -EINVAL;
55+
4456
/* Start at 2 because it's defined as 2^(1+PSS) */
4557
iommu->pasid_max = 2 << ecap_pss(iommu->ecap);
4658

@@ -129,6 +141,7 @@ int intel_svm_enable_prq(struct intel_iommu *iommu)
129141
pr_err("IOMMU: %s: Failed to request IRQ for page request queue\n",
130142
iommu->name);
131143
dmar_free_hwirq(irq);
144+
iommu->pr_irq = 0;
132145
goto err;
133146
}
134147
dmar_writeq(iommu->reg + DMAR_PQH_REG, 0ULL);
@@ -144,9 +157,11 @@ int intel_svm_finish_prq(struct intel_iommu *iommu)
144157
dmar_writeq(iommu->reg + DMAR_PQT_REG, 0ULL);
145158
dmar_writeq(iommu->reg + DMAR_PQA_REG, 0ULL);
146159

147-
free_irq(iommu->pr_irq, iommu);
148-
dmar_free_hwirq(iommu->pr_irq);
149-
iommu->pr_irq = 0;
160+
if (iommu->pr_irq) {
161+
free_irq(iommu->pr_irq, iommu);
162+
dmar_free_hwirq(iommu->pr_irq);
163+
iommu->pr_irq = 0;
164+
}
150165

151166
free_pages((unsigned long)iommu->prq, PRQ_ORDER);
152167
iommu->prq = NULL;
@@ -290,6 +305,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_
290305
struct intel_svm_dev *sdev;
291306
struct intel_svm *svm = NULL;
292307
struct mm_struct *mm = NULL;
308+
u64 pasid_entry_val;
293309
int pasid_max;
294310
int ret;
295311

@@ -396,9 +412,15 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_
396412
kfree(sdev);
397413
goto out;
398414
}
399-
iommu->pasid_table[svm->pasid].val = (u64)__pa(mm->pgd) | 1;
415+
pasid_entry_val = (u64)__pa(mm->pgd) | PASID_ENTRY_P;
400416
} else
401-
iommu->pasid_table[svm->pasid].val = (u64)__pa(init_mm.pgd) | 1 | (1ULL << 11);
417+
pasid_entry_val = (u64)__pa(init_mm.pgd) |
418+
PASID_ENTRY_P | PASID_ENTRY_SRE;
419+
if (cpu_feature_enabled(X86_FEATURE_LA57))
420+
pasid_entry_val |= PASID_ENTRY_FLPM_5LP;
421+
422+
iommu->pasid_table[svm->pasid].val = pasid_entry_val;
423+
402424
wmb();
403425
/* In caching mode, we still have to flush with PASID 0 when
404426
* a PASID table entry becomes present. Not entirely clear

drivers/iommu/iommu.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,9 @@ int iommu_attach_device(struct iommu_domain *domain, struct device *dev)
13031303
int ret;
13041304

13051305
group = iommu_group_get(dev);
1306+
if (!group)
1307+
return -ENODEV;
1308+
13061309
/*
13071310
* Lock the group to make sure the device-count doesn't
13081311
* change while we are attaching
@@ -1341,6 +1344,8 @@ void iommu_detach_device(struct iommu_domain *domain, struct device *dev)
13411344
struct iommu_group *group;
13421345

13431346
group = iommu_group_get(dev);
1347+
if (!group)
1348+
return;
13441349

13451350
mutex_lock(&group->mutex);
13461351
if (iommu_group_device_count(group) != 1) {

drivers/iommu/ipmmu-vmsa.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,18 +1108,8 @@ static void __exit ipmmu_exit(void)
11081108
subsys_initcall(ipmmu_init);
11091109
module_exit(ipmmu_exit);
11101110

1111-
#ifdef CONFIG_IOMMU_DMA
1112-
static int __init ipmmu_vmsa_iommu_of_setup(struct device_node *np)
1113-
{
1114-
ipmmu_init();
1115-
return 0;
1116-
}
1117-
1118-
IOMMU_OF_DECLARE(ipmmu_vmsa_iommu_of, "renesas,ipmmu-vmsa",
1119-
ipmmu_vmsa_iommu_of_setup);
1120-
IOMMU_OF_DECLARE(ipmmu_r8a7795_iommu_of, "renesas,ipmmu-r8a7795",
1121-
ipmmu_vmsa_iommu_of_setup);
1122-
#endif
1111+
IOMMU_OF_DECLARE(ipmmu_vmsa_iommu_of, "renesas,ipmmu-vmsa");
1112+
IOMMU_OF_DECLARE(ipmmu_r8a7795_iommu_of, "renesas,ipmmu-r8a7795");
11231113

11241114
MODULE_DESCRIPTION("IOMMU API for Renesas VMSA-compatible IPMMU");
11251115
MODULE_AUTHOR("Laurent Pinchart <[email protected]>");

drivers/iommu/msm_iommu.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,8 @@ static int msm_iommu_probe(struct platform_device *pdev)
823823
goto fail;
824824
}
825825

826+
bus_set_iommu(&platform_bus_type, &msm_iommu_ops);
827+
826828
pr_info("device mapped at %p, irq %d with %d ctx banks\n",
827829
iommu->base, iommu->irq, iommu->ncb);
828830

@@ -875,19 +877,7 @@ static void __exit msm_iommu_driver_exit(void)
875877
subsys_initcall(msm_iommu_driver_init);
876878
module_exit(msm_iommu_driver_exit);
877879

878-
static int __init msm_iommu_init(void)
879-
{
880-
bus_set_iommu(&platform_bus_type, &msm_iommu_ops);
881-
return 0;
882-
}
883-
884-
static int __init msm_iommu_of_setup(struct device_node *np)
885-
{
886-
msm_iommu_init();
887-
return 0;
888-
}
889-
890-
IOMMU_OF_DECLARE(msm_iommu_of, "qcom,apq8064-iommu", msm_iommu_of_setup);
880+
IOMMU_OF_DECLARE(msm_iommu_of, "qcom,apq8064-iommu");
891881

892882
MODULE_LICENSE("GPL v2");
893883
MODULE_AUTHOR("Stepan Moskovchenko <[email protected]>");

drivers/iommu/of_iommu.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,3 @@ const struct iommu_ops *of_iommu_configure(struct device *dev,
231231

232232
return ops;
233233
}
234-
235-
static int __init of_iommu_init(void)
236-
{
237-
struct device_node *np;
238-
const struct of_device_id *match, *matches = &__iommu_of_table;
239-
240-
for_each_matching_node_and_match(np, matches, &match) {
241-
const of_iommu_init_fn init_fn = match->data;
242-
243-
if (init_fn && init_fn(np))
244-
pr_err("Failed to initialise IOMMU %pOF\n", np);
245-
}
246-
247-
return 0;
248-
}
249-
postcore_initcall_sync(of_iommu_init);

drivers/iommu/omap-iommu-debug.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ void omap_iommu_debugfs_add(struct omap_iommu *obj)
274274
if (!obj->debug_dir)
275275
return;
276276

277-
d = debugfs_create_u8("nr_tlb_entries", 0400, obj->debug_dir,
278-
(u8 *)&obj->nr_tlb_entries);
277+
d = debugfs_create_u32("nr_tlb_entries", 0400, obj->debug_dir,
278+
&obj->nr_tlb_entries);
279279
if (!d)
280280
return;
281281

drivers/iommu/qcom_iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ static void __exit qcom_iommu_exit(void)
947947
module_init(qcom_iommu_init);
948948
module_exit(qcom_iommu_exit);
949949

950-
IOMMU_OF_DECLARE(qcom_iommu_dev, "qcom,msm-iommu-v1", NULL);
950+
IOMMU_OF_DECLARE(qcom_iommu_dev, "qcom,msm-iommu-v1");
951951

952952
MODULE_DESCRIPTION("IOMMU API for QCOM IOMMU v1 implementations");
953953
MODULE_LICENSE("GPL v2");

include/linux/intel-iommu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
/*
8484
* Decoding Capability Register
8585
*/
86+
#define cap_5lp_support(c) (((c) >> 60) & 1)
8687
#define cap_pi_support(c) (((c) >> 59) & 1)
88+
#define cap_fl1gp_support(c) (((c) >> 56) & 1)
8789
#define cap_read_drain(c) (((c) >> 55) & 1)
8890
#define cap_write_drain(c) (((c) >> 54) & 1)
8991
#define cap_max_amask_val(c) (((c) >> 48) & 0x3f)

include/linux/of_iommu.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ static inline const struct iommu_ops *of_iommu_configure(struct device *dev,
3434

3535
extern struct of_device_id __iommu_of_table;
3636

37-
typedef int (*of_iommu_init_fn)(struct device_node *);
38-
39-
#define IOMMU_OF_DECLARE(name, compat, fn) \
40-
_OF_DECLARE(iommu, name, compat, fn, of_iommu_init_fn)
37+
#define IOMMU_OF_DECLARE(name, compat) OF_DECLARE_1(iommu, name, compat, NULL)
4138

4239
#endif /* __OF_IOMMU_H */

0 commit comments

Comments
 (0)