Skip to content

Commit 1b50017

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/arm-smmu-v3: Remove arm_smmu_master->domain
Introducing global statics which are of type struct iommu_domain, not struct arm_smmu_domain makes it difficult to retain arm_smmu_master->domain, as it can no longer point to an IDENTITY or BLOCKED domain. The only place that uses the value is arm_smmu_detach_dev(). Change things to work like other drivers and call iommu_get_domain_for_dev() to obtain the current domain. The master->domain is subtly protecting the master->domain_head against being unused as only PAGING domains will set master->domain and only paging domains use the master->domain_head. To make it simple keep the master->domain_head initialized so that the list_del() logic just does nothing for attached non-PAGING domains. Tested-by: Shameer Kolothum <[email protected]> Tested-by: Nicolin Chen <[email protected]> Tested-by: Moritz Fischer <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Reviewed-by: Mostafa Saleh <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent d550ddc commit 1b50017

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,19 +2507,20 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master)
25072507

25082508
static void arm_smmu_detach_dev(struct arm_smmu_master *master)
25092509
{
2510+
struct iommu_domain *domain = iommu_get_domain_for_dev(master->dev);
2511+
struct arm_smmu_domain *smmu_domain;
25102512
unsigned long flags;
2511-
struct arm_smmu_domain *smmu_domain = master->domain;
25122513

2513-
if (!smmu_domain)
2514+
if (!domain)
25142515
return;
25152516

2517+
smmu_domain = to_smmu_domain(domain);
25162518
arm_smmu_disable_ats(master, smmu_domain);
25172519

25182520
spin_lock_irqsave(&smmu_domain->devices_lock, flags);
2519-
list_del(&master->domain_head);
2521+
list_del_init(&master->domain_head);
25202522
spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
25212523

2522-
master->domain = NULL;
25232524
master->ats_enabled = false;
25242525
}
25252526

@@ -2573,8 +2574,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
25732574

25742575
arm_smmu_detach_dev(master);
25752576

2576-
master->domain = smmu_domain;
2577-
25782577
/*
25792578
* The SMMU does not support enabling ATS with bypass. When the STE is
25802579
* in bypass (STE.Config[2:0] == 0b100), ATS Translation Requests and
@@ -2593,28 +2592,22 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
25932592
case ARM_SMMU_DOMAIN_S1:
25942593
if (!master->cd_table.cdtab) {
25952594
ret = arm_smmu_alloc_cd_tables(master);
2596-
if (ret) {
2597-
master->domain = NULL;
2595+
if (ret)
25982596
goto out_list_del;
2599-
}
26002597
} else {
26012598
/*
26022599
* arm_smmu_write_ctx_desc() relies on the entry being
26032600
* invalid to work, clear any existing entry.
26042601
*/
26052602
ret = arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID,
26062603
NULL);
2607-
if (ret) {
2608-
master->domain = NULL;
2604+
if (ret)
26092605
goto out_list_del;
2610-
}
26112606
}
26122607

26132608
ret = arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, &smmu_domain->cd);
2614-
if (ret) {
2615-
master->domain = NULL;
2609+
if (ret)
26162610
goto out_list_del;
2617-
}
26182611

26192612
arm_smmu_make_cdtable_ste(&target, master);
26202613
arm_smmu_install_ste_for_dev(master, &target);
@@ -2640,7 +2633,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
26402633

26412634
out_list_del:
26422635
spin_lock_irqsave(&smmu_domain->devices_lock, flags);
2643-
list_del(&master->domain_head);
2636+
list_del_init(&master->domain_head);
26442637
spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
26452638

26462639
out_unlock:
@@ -2841,6 +2834,7 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev)
28412834
master->dev = dev;
28422835
master->smmu = smmu;
28432836
INIT_LIST_HEAD(&master->bonds);
2837+
INIT_LIST_HEAD(&master->domain_head);
28442838
dev_iommu_priv_set(dev, master);
28452839

28462840
ret = arm_smmu_insert_master(smmu, master);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,6 @@ struct arm_smmu_stream {
695695
struct arm_smmu_master {
696696
struct arm_smmu_device *smmu;
697697
struct device *dev;
698-
struct arm_smmu_domain *domain;
699698
struct list_head domain_head;
700699
struct arm_smmu_stream *streams;
701700
/* Locked by the iommu core using the group mutex */

0 commit comments

Comments
 (0)