Skip to content

Commit 1d5f34f

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/arm-smmu-v3: Thread SSID through the arm_smmu_attach_*() interface
Allow creating and managing arm_smmu_mater_domain's with a non-zero SSID through the arm_smmu_attach_*() family of functions. This triggers ATC invalidation for the correct SSID in PASID cases and tracks the per-attachment SSID in the struct arm_smmu_master_domain. Generalize arm_smmu_attach_remove() to be able to remove SSID's as well by ensuring the ATC for the PASID is flushed properly. Tested-by: Nicolin Chen <[email protected]> Tested-by: Shameer Kolothum <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Reviewed-by: Jerry Snitselaar <[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 be7c90d commit 1d5f34f

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,13 +2005,14 @@ arm_smmu_atc_inv_to_cmd(int ssid, unsigned long iova, size_t size,
20052005
cmd->atc.size = log2_span;
20062006
}
20072007

2008-
static int arm_smmu_atc_inv_master(struct arm_smmu_master *master)
2008+
static int arm_smmu_atc_inv_master(struct arm_smmu_master *master,
2009+
ioasid_t ssid)
20092010
{
20102011
int i;
20112012
struct arm_smmu_cmdq_ent cmd;
20122013
struct arm_smmu_cmdq_batch cmds;
20132014

2014-
arm_smmu_atc_inv_to_cmd(IOMMU_NO_PASID, 0, 0, &cmd);
2015+
arm_smmu_atc_inv_to_cmd(ssid, 0, 0, &cmd);
20152016

20162017
cmds.num = 0;
20172018
for (i = 0; i < master->num_streams; i++) {
@@ -2494,7 +2495,7 @@ static void arm_smmu_enable_ats(struct arm_smmu_master *master)
24942495
/*
24952496
* ATC invalidation of PASID 0 causes the entire ATC to be flushed.
24962497
*/
2497-
arm_smmu_atc_inv_master(master);
2498+
arm_smmu_atc_inv_master(master, IOMMU_NO_PASID);
24982499
if (pci_enable_ats(pdev, stu))
24992500
dev_err(master->dev, "Failed to enable ATS (STU %zu)\n", stu);
25002501
}
@@ -2581,7 +2582,8 @@ to_smmu_domain_devices(struct iommu_domain *domain)
25812582
}
25822583

25832584
static void arm_smmu_remove_master_domain(struct arm_smmu_master *master,
2584-
struct iommu_domain *domain)
2585+
struct iommu_domain *domain,
2586+
ioasid_t ssid)
25852587
{
25862588
struct arm_smmu_domain *smmu_domain = to_smmu_domain_devices(domain);
25872589
struct arm_smmu_master_domain *master_domain;
@@ -2591,8 +2593,7 @@ static void arm_smmu_remove_master_domain(struct arm_smmu_master *master,
25912593
return;
25922594

25932595
spin_lock_irqsave(&smmu_domain->devices_lock, flags);
2594-
master_domain = arm_smmu_find_master_domain(smmu_domain, master,
2595-
IOMMU_NO_PASID);
2596+
master_domain = arm_smmu_find_master_domain(smmu_domain, master, ssid);
25962597
if (master_domain) {
25972598
list_del(&master_domain->devices_elm);
25982599
kfree(master_domain);
@@ -2606,6 +2607,7 @@ struct arm_smmu_attach_state {
26062607
/* Inputs */
26072608
struct iommu_domain *old_domain;
26082609
struct arm_smmu_master *master;
2610+
ioasid_t ssid;
26092611
/* Resulting state */
26102612
bool ats_enabled;
26112613
};
@@ -2663,6 +2665,7 @@ static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state,
26632665
if (!master_domain)
26642666
return -ENOMEM;
26652667
master_domain->master = master;
2668+
master_domain->ssid = state->ssid;
26662669

26672670
/*
26682671
* During prepare we want the current smmu_domain and new
@@ -2710,17 +2713,20 @@ static void arm_smmu_attach_commit(struct arm_smmu_attach_state *state)
27102713

27112714
if (state->ats_enabled && !master->ats_enabled) {
27122715
arm_smmu_enable_ats(master);
2713-
} else if (master->ats_enabled) {
2716+
} else if (state->ats_enabled && master->ats_enabled) {
27142717
/*
27152718
* The translation has changed, flush the ATC. At this point the
27162719
* SMMU is translating for the new domain and both the old&new
27172720
* domain will issue invalidations.
27182721
*/
2719-
arm_smmu_atc_inv_master(master);
2722+
arm_smmu_atc_inv_master(master, state->ssid);
2723+
} else if (!state->ats_enabled && master->ats_enabled) {
2724+
/* ATS is being switched off, invalidate the entire ATC */
2725+
arm_smmu_atc_inv_master(master, IOMMU_NO_PASID);
27202726
}
27212727
master->ats_enabled = state->ats_enabled;
27222728

2723-
arm_smmu_remove_master_domain(master, state->old_domain);
2729+
arm_smmu_remove_master_domain(master, state->old_domain, state->ssid);
27242730
}
27252731

27262732
static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
@@ -2732,6 +2738,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
27322738
struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
27332739
struct arm_smmu_attach_state state = {
27342740
.old_domain = iommu_get_domain_for_dev(dev),
2741+
.ssid = IOMMU_NO_PASID,
27352742
};
27362743
struct arm_smmu_master *master;
27372744
struct arm_smmu_cd *cdptr;
@@ -2829,6 +2836,7 @@ static int arm_smmu_attach_dev_ste(struct iommu_domain *domain,
28292836
struct arm_smmu_attach_state state = {
28302837
.master = master,
28312838
.old_domain = iommu_get_domain_for_dev(dev),
2839+
.ssid = IOMMU_NO_PASID,
28322840
};
28332841

28342842
if (arm_smmu_ssids_in_use(&master->cd_table))

0 commit comments

Comments
 (0)