Skip to content

Commit 34af78c

Browse files
committed
Merge tag 'iommu-updates-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu
Pull iommu updates from Joerg Roedel: - IOMMU Core changes: - Removal of aux domain related code as it is basically dead and will be replaced by iommu-fd framework - Split of iommu_ops to carry domain-specific call-backs separatly - Cleanup to remove useless ops->capable implementations - Improve 32-bit free space estimate in iova allocator - Intel VT-d updates: - Various cleanups of the driver - Support for ATS of SoC-integrated devices listed in ACPI/SATC table - ARM SMMU updates: - Fix SMMUv3 soft lockup during continuous stream of events - Fix error path for Qualcomm SMMU probe() - Rework SMMU IRQ setup to prepare the ground for PMU support - Minor cleanups and refactoring - AMD IOMMU driver: - Some minor cleanups and error-handling fixes - Rockchip IOMMU driver: - Use standard driver registration - MSM IOMMU driver: - Minor cleanup and change to standard driver registration - Mediatek IOMMU driver: - Fixes for IOTLB flushing logic * tag 'iommu-updates-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: (47 commits) iommu/amd: Improve amd_iommu_v2_exit() iommu/amd: Remove unused struct fault.devid iommu/amd: Clean up function declarations iommu/amd: Call memunmap in error path iommu/arm-smmu: Account for PMU interrupts iommu/vt-d: Enable ATS for the devices in SATC table iommu/vt-d: Remove unused function intel_svm_capable() iommu/vt-d: Add missing "__init" for rmrr_sanity_check() iommu/vt-d: Move intel_iommu_ops to header file iommu/vt-d: Fix indentation of goto labels iommu/vt-d: Remove unnecessary prototypes iommu/vt-d: Remove unnecessary includes iommu/vt-d: Remove DEFER_DEVICE_DOMAIN_INFO iommu/vt-d: Remove domain and devinfo mempool iommu/vt-d: Remove iova_cache_get/put() iommu/vt-d: Remove finding domain in dmar_insert_one_dev_info() iommu/vt-d: Remove intel_iommu::domains iommu/mediatek: Always tlb_flush_all when each PM resume iommu/mediatek: Add tlb_lock in tlb_flush_all iommu/mediatek: Remove the power status checking in tlb flush all ...
2 parents 6f2689a + e17c6de commit 34af78c

41 files changed

Lines changed: 662 additions & 2251 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ properties:
4444
- renesas,ipmmu-r8a77990 # R-Car E3
4545
- renesas,ipmmu-r8a77995 # R-Car D3
4646
- renesas,ipmmu-r8a779a0 # R-Car V3U
47+
- items:
48+
- enum:
49+
- renesas,ipmmu-r8a779f0 # R-Car S4-8
50+
- const: renesas,rcar-gen4-ipmmu-vmsa # R-Car Gen4
4751

4852
reg:
4953
maxItems: 1

drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ nvkm_device_tegra_probe_iommu(struct nvkm_device_tegra *tdev)
133133
* or equal to the system's PAGE_SIZE, with a preference if
134134
* both are equal.
135135
*/
136-
pgsize_bitmap = tdev->iommu.domain->ops->pgsize_bitmap;
136+
pgsize_bitmap = tdev->iommu.domain->pgsize_bitmap;
137137
if (pgsize_bitmap & PAGE_SIZE) {
138138
tdev->iommu.pgshift = PAGE_SHIFT;
139139
} else {

drivers/iommu/amd/amd_iommu.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ 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(u16 devid);
1717
extern void amd_iommu_restart_event_logging(struct amd_iommu *iommu);
18-
extern void amd_iommu_reset_cmd_buffer(struct amd_iommu *iommu);
1918
extern int amd_iommu_init_devices(void);
2019
extern void amd_iommu_uninit_devices(void);
2120
extern void amd_iommu_init_notifier(void);
@@ -117,8 +116,7 @@ void amd_iommu_domain_clr_pt_root(struct protection_domain *domain)
117116

118117

119118
extern bool translation_pre_enabled(struct amd_iommu *iommu);
120-
extern bool amd_iommu_is_attach_deferred(struct iommu_domain *domain,
121-
struct device *dev);
119+
extern bool amd_iommu_is_attach_deferred(struct device *dev);
122120
extern int __init add_special_device(u8 type, u8 id, u16 *devid,
123121
bool cmd_line);
124122

drivers/iommu/amd/init.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ void amd_iommu_restart_event_logging(struct amd_iommu *iommu)
671671
* This function resets the command buffer if the IOMMU stopped fetching
672672
* commands from it.
673673
*/
674-
void amd_iommu_reset_cmd_buffer(struct amd_iommu *iommu)
674+
static void amd_iommu_reset_cmd_buffer(struct amd_iommu *iommu)
675675
{
676676
iommu_feature_disable(iommu, CONTROL_CMDBUF_EN);
677677

@@ -990,6 +990,7 @@ static bool copy_device_table(void)
990990
get_order(dev_table_size));
991991
if (old_dev_tbl_cpy == NULL) {
992992
pr_err("Failed to allocate memory for copying old device table!\n");
993+
memunmap(old_devtb);
993994
return false;
994995
}
995996

@@ -1020,6 +1021,7 @@ static bool copy_device_table(void)
10201021
if ((int_ctl != DTE_IRQ_REMAP_INTCTL) ||
10211022
(int_tab_len != DTE_INTTABLEN)) {
10221023
pr_err("Wrong old irq remapping flag: %#x\n", devid);
1024+
memunmap(old_devtb);
10231025
return false;
10241026
}
10251027

@@ -1953,9 +1955,11 @@ static int __init amd_iommu_init_pci(void)
19531955

19541956
for_each_iommu(iommu) {
19551957
ret = iommu_init_pci(iommu);
1956-
if (ret)
1957-
break;
1958-
1958+
if (ret) {
1959+
pr_err("IOMMU%d: Failed to initialize IOMMU Hardware (error=%d)!\n",
1960+
iommu->index, ret);
1961+
goto out;
1962+
}
19591963
/* Need to setup range after PCI init */
19601964
iommu_set_cwwb_range(iommu);
19611965
}
@@ -1971,6 +1975,11 @@ static int __init amd_iommu_init_pci(void)
19711975
* active.
19721976
*/
19731977
ret = amd_iommu_init_api();
1978+
if (ret) {
1979+
pr_err("IOMMU: Failed to initialize IOMMU-API interface (error=%d)!\n",
1980+
ret);
1981+
goto out;
1982+
}
19741983

19751984
init_device_table_dma();
19761985

@@ -1980,6 +1989,7 @@ static int __init amd_iommu_init_pci(void)
19801989
if (!ret)
19811990
print_iommu_info();
19821991

1992+
out:
19831993
return ret;
19841994
}
19851995

drivers/iommu/amd/iommu.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,8 +2221,7 @@ static void amd_iommu_get_resv_regions(struct device *dev,
22212221
list_add_tail(&region->list, head);
22222222
}
22232223

2224-
bool amd_iommu_is_attach_deferred(struct iommu_domain *domain,
2225-
struct device *dev)
2224+
bool amd_iommu_is_attach_deferred(struct device *dev)
22262225
{
22272226
struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
22282227

@@ -2275,13 +2274,6 @@ static int amd_iommu_def_domain_type(struct device *dev)
22752274
const struct iommu_ops amd_iommu_ops = {
22762275
.capable = amd_iommu_capable,
22772276
.domain_alloc = amd_iommu_domain_alloc,
2278-
.domain_free = amd_iommu_domain_free,
2279-
.attach_dev = amd_iommu_attach_device,
2280-
.detach_dev = amd_iommu_detach_device,
2281-
.map = amd_iommu_map,
2282-
.iotlb_sync_map = amd_iommu_iotlb_sync_map,
2283-
.unmap = amd_iommu_unmap,
2284-
.iova_to_phys = amd_iommu_iova_to_phys,
22852277
.probe_device = amd_iommu_probe_device,
22862278
.release_device = amd_iommu_release_device,
22872279
.probe_finalize = amd_iommu_probe_finalize,
@@ -2290,9 +2282,18 @@ const struct iommu_ops amd_iommu_ops = {
22902282
.put_resv_regions = generic_iommu_put_resv_regions,
22912283
.is_attach_deferred = amd_iommu_is_attach_deferred,
22922284
.pgsize_bitmap = AMD_IOMMU_PGSIZES,
2293-
.flush_iotlb_all = amd_iommu_flush_iotlb_all,
2294-
.iotlb_sync = amd_iommu_iotlb_sync,
22952285
.def_domain_type = amd_iommu_def_domain_type,
2286+
.default_domain_ops = &(const struct iommu_domain_ops) {
2287+
.attach_dev = amd_iommu_attach_device,
2288+
.detach_dev = amd_iommu_detach_device,
2289+
.map = amd_iommu_map,
2290+
.unmap = amd_iommu_unmap,
2291+
.iotlb_sync_map = amd_iommu_iotlb_sync_map,
2292+
.iova_to_phys = amd_iommu_iova_to_phys,
2293+
.flush_iotlb_all = amd_iommu_flush_iotlb_all,
2294+
.iotlb_sync = amd_iommu_iotlb_sync,
2295+
.free = amd_iommu_domain_free,
2296+
}
22962297
};
22972298

22982299
/*****************************************************************************

drivers/iommu/amd/iommu_v2.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
MODULE_LICENSE("GPL v2");
2525
MODULE_AUTHOR("Joerg Roedel <jroedel@suse.de>");
2626

27-
#define MAX_DEVICES 0x10000
2827
#define PRI_QUEUE_SIZE 512
2928

3029
struct pri_queue {
@@ -71,7 +70,6 @@ struct fault {
7170
struct pasid_state *state;
7271
struct mm_struct *mm;
7372
u64 address;
74-
u16 devid;
7573
u32 pasid;
7674
u16 tag;
7775
u16 finish;
@@ -125,6 +123,15 @@ static void free_device_state(struct device_state *dev_state)
125123
{
126124
struct iommu_group *group;
127125

126+
/* Get rid of any remaining pasid states */
127+
free_pasid_states(dev_state);
128+
129+
/*
130+
* Wait until the last reference is dropped before freeing
131+
* the device state.
132+
*/
133+
wait_event(dev_state->wq, !atomic_read(&dev_state->count));
134+
128135
/*
129136
* First detach device from domain - No more PRI requests will arrive
130137
* from that device after it is unbound from the IOMMUv2 domain.
@@ -537,7 +544,7 @@ static int ppr_notifier(struct notifier_block *nb, unsigned long e, void *data)
537544
ret = NOTIFY_DONE;
538545

539546
/* In kdump kernel pci dev is not initialized yet -> send INVALID */
540-
if (amd_iommu_is_attach_deferred(NULL, &pdev->dev)) {
547+
if (amd_iommu_is_attach_deferred(&pdev->dev)) {
541548
amd_iommu_complete_ppr(pdev, iommu_fault->pasid,
542549
PPR_INVALID, tag);
543550
goto out;
@@ -850,15 +857,7 @@ void amd_iommu_free_device(struct pci_dev *pdev)
850857

851858
spin_unlock_irqrestore(&state_lock, flags);
852859

853-
/* Get rid of any remaining pasid states */
854-
free_pasid_states(dev_state);
855-
856860
put_device_state(dev_state);
857-
/*
858-
* Wait until the last reference is dropped before freeing
859-
* the device state.
860-
*/
861-
wait_event(dev_state->wq, !atomic_read(&dev_state->count));
862861
free_device_state(dev_state);
863862
}
864863
EXPORT_SYMBOL(amd_iommu_free_device);
@@ -955,8 +954,8 @@ static int __init amd_iommu_v2_init(void)
955954

956955
static void __exit amd_iommu_v2_exit(void)
957956
{
958-
struct device_state *dev_state;
959-
int i;
957+
struct device_state *dev_state, *next;
958+
unsigned long flags;
960959

961960
if (!amd_iommu_v2_supported())
962961
return;
@@ -969,18 +968,18 @@ static void __exit amd_iommu_v2_exit(void)
969968
* The loop below might call flush_workqueue(), so call
970969
* destroy_workqueue() after it
971970
*/
972-
for (i = 0; i < MAX_DEVICES; ++i) {
973-
dev_state = get_device_state(i);
974-
975-
if (dev_state == NULL)
976-
continue;
971+
spin_lock_irqsave(&state_lock, flags);
977972

973+
list_for_each_entry_safe(dev_state, next, &state_list, list) {
978974
WARN_ON_ONCE(1);
979975

980976
put_device_state(dev_state);
981-
amd_iommu_free_device(dev_state->pdev);
977+
list_del(&dev_state->list);
978+
free_device_state(dev_state);
982979
}
983980

981+
spin_unlock_irqrestore(&state_lock, flags);
982+
984983
destroy_workqueue(iommu_wq);
985984
}
986985

drivers/iommu/apple-dart.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -765,15 +765,6 @@ static void apple_dart_get_resv_regions(struct device *dev,
765765

766766
static const struct iommu_ops apple_dart_iommu_ops = {
767767
.domain_alloc = apple_dart_domain_alloc,
768-
.domain_free = apple_dart_domain_free,
769-
.attach_dev = apple_dart_attach_dev,
770-
.detach_dev = apple_dart_detach_dev,
771-
.map_pages = apple_dart_map_pages,
772-
.unmap_pages = apple_dart_unmap_pages,
773-
.flush_iotlb_all = apple_dart_flush_iotlb_all,
774-
.iotlb_sync = apple_dart_iotlb_sync,
775-
.iotlb_sync_map = apple_dart_iotlb_sync_map,
776-
.iova_to_phys = apple_dart_iova_to_phys,
777768
.probe_device = apple_dart_probe_device,
778769
.release_device = apple_dart_release_device,
779770
.device_group = apple_dart_device_group,
@@ -782,6 +773,17 @@ static const struct iommu_ops apple_dart_iommu_ops = {
782773
.get_resv_regions = apple_dart_get_resv_regions,
783774
.put_resv_regions = generic_iommu_put_resv_regions,
784775
.pgsize_bitmap = -1UL, /* Restricted during dart probe */
776+
.default_domain_ops = &(const struct iommu_domain_ops) {
777+
.attach_dev = apple_dart_attach_dev,
778+
.detach_dev = apple_dart_detach_dev,
779+
.map_pages = apple_dart_map_pages,
780+
.unmap_pages = apple_dart_unmap_pages,
781+
.flush_iotlb_all = apple_dart_flush_iotlb_all,
782+
.iotlb_sync = apple_dart_iotlb_sync,
783+
.iotlb_sync_map = apple_dart_iotlb_sync_map,
784+
.iova_to_phys = apple_dart_iova_to_phys,
785+
.free = apple_dart_domain_free,
786+
}
785787
};
786788

787789
static irqreturn_t apple_dart_irq(int irq, void *dev)

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,7 @@ static irqreturn_t arm_smmu_evtq_thread(int irq, void *dev)
15581558
dev_info(smmu->dev, "\t0x%016llx\n",
15591559
(unsigned long long)evt[i]);
15601560

1561+
cond_resched();
15611562
}
15621563

15631564
/*
@@ -2841,17 +2842,9 @@ static int arm_smmu_dev_disable_feature(struct device *dev,
28412842
static struct iommu_ops arm_smmu_ops = {
28422843
.capable = arm_smmu_capable,
28432844
.domain_alloc = arm_smmu_domain_alloc,
2844-
.domain_free = arm_smmu_domain_free,
2845-
.attach_dev = arm_smmu_attach_dev,
2846-
.map_pages = arm_smmu_map_pages,
2847-
.unmap_pages = arm_smmu_unmap_pages,
2848-
.flush_iotlb_all = arm_smmu_flush_iotlb_all,
2849-
.iotlb_sync = arm_smmu_iotlb_sync,
2850-
.iova_to_phys = arm_smmu_iova_to_phys,
28512845
.probe_device = arm_smmu_probe_device,
28522846
.release_device = arm_smmu_release_device,
28532847
.device_group = arm_smmu_device_group,
2854-
.enable_nesting = arm_smmu_enable_nesting,
28552848
.of_xlate = arm_smmu_of_xlate,
28562849
.get_resv_regions = arm_smmu_get_resv_regions,
28572850
.put_resv_regions = generic_iommu_put_resv_regions,
@@ -2865,6 +2858,16 @@ static struct iommu_ops arm_smmu_ops = {
28652858
.page_response = arm_smmu_page_response,
28662859
.pgsize_bitmap = -1UL, /* Restricted during device attach */
28672860
.owner = THIS_MODULE,
2861+
.default_domain_ops = &(const struct iommu_domain_ops) {
2862+
.attach_dev = arm_smmu_attach_dev,
2863+
.map_pages = arm_smmu_map_pages,
2864+
.unmap_pages = arm_smmu_unmap_pages,
2865+
.flush_iotlb_all = arm_smmu_flush_iotlb_all,
2866+
.iotlb_sync = arm_smmu_iotlb_sync,
2867+
.iova_to_phys = arm_smmu_iova_to_phys,
2868+
.enable_nesting = arm_smmu_enable_nesting,
2869+
.free = arm_smmu_domain_free,
2870+
}
28682871
};
28692872

28702873
/* Probing and initialisation functions */
@@ -2911,32 +2914,20 @@ static int arm_smmu_init_one_queue(struct arm_smmu_device *smmu,
29112914
return 0;
29122915
}
29132916

2914-
static void arm_smmu_cmdq_free_bitmap(void *data)
2915-
{
2916-
unsigned long *bitmap = data;
2917-
bitmap_free(bitmap);
2918-
}
2919-
29202917
static int arm_smmu_cmdq_init(struct arm_smmu_device *smmu)
29212918
{
2922-
int ret = 0;
29232919
struct arm_smmu_cmdq *cmdq = &smmu->cmdq;
29242920
unsigned int nents = 1 << cmdq->q.llq.max_n_shift;
2925-
atomic_long_t *bitmap;
29262921

29272922
atomic_set(&cmdq->owner_prod, 0);
29282923
atomic_set(&cmdq->lock, 0);
29292924

2930-
bitmap = (atomic_long_t *)bitmap_zalloc(nents, GFP_KERNEL);
2931-
if (!bitmap) {
2932-
dev_err(smmu->dev, "failed to allocate cmdq bitmap\n");
2933-
ret = -ENOMEM;
2934-
} else {
2935-
cmdq->valid_map = bitmap;
2936-
devm_add_action(smmu->dev, arm_smmu_cmdq_free_bitmap, bitmap);
2937-
}
2925+
cmdq->valid_map = (atomic_long_t *)devm_bitmap_zalloc(smmu->dev, nents,
2926+
GFP_KERNEL);
2927+
if (!cmdq->valid_map)
2928+
return -ENOMEM;
29382929

2939-
return ret;
2930+
return 0;
29402931
}
29412932

29422933
static int arm_smmu_init_queues(struct arm_smmu_device *smmu)
@@ -2981,10 +2972,10 @@ static int arm_smmu_init_l1_strtab(struct arm_smmu_device *smmu)
29812972
{
29822973
unsigned int i;
29832974
struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg;
2984-
size_t size = sizeof(*cfg->l1_desc) * cfg->num_l1_ents;
29852975
void *strtab = smmu->strtab_cfg.strtab;
29862976

2987-
cfg->l1_desc = devm_kzalloc(smmu->dev, size, GFP_KERNEL);
2977+
cfg->l1_desc = devm_kcalloc(smmu->dev, cfg->num_l1_ents,
2978+
sizeof(*cfg->l1_desc), GFP_KERNEL);
29882979
if (!cfg->l1_desc)
29892980
return -ENOMEM;
29902981

0 commit comments

Comments
 (0)