iommu/arm-smmu-v3: Fix smmu_domain->nr_ats_masters decrement
Subsystems (2)
PATCH 1/1 iommu/arm-smmu-v3: Fix smmu_domain->nr_ats_masters decrement
The arm_smmu_attach_commit() updates master->ats_enabled before calling arm_smmu_remove_master_domain() that is supposed to clean up everything in the old domain, including the old domain's nr_ats_masters. So, it is supposed to use the old ats_enabled state of the device, not an updated state.
This isn't a problem if switching between two domains where:
- old ats_enabled = false; new ats_enabled = false
- old ats_enabled = true; new ats_enabled = true
but can fail cases where:
- old ats_enabled = false; new ats_enabled = true
(old domain should keep the counter but incorrectly decreased it)
- old ats_enabled = true; new ats_enabled = false
(old domain needed to decrease the counter but incorrectly missed it)
Update master->ats_enabled after arm_smmu_remove_master_domain() to fix this.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1 -1
@@ -2997,9 +2997,9 @@ void arm_smmu_attach_commit(struct arm_smmu_attach_state *state)/* ATS is being switched off, invalidate the entire ATC */ arm_smmu_atc_inv_master (master,IOMMU_NO_PASID ); } - master->ats_enabled = state->ats_enabled;arm_smmu_remove_master_domain (master, state->old_domain, state->ssid); + master->ats_enabled = state->ats_enabled; }static int arm_smmu_attach_dev (struct iommu_domain *domain,struct device *dev)
Signature · 1 line
2.43.0
Quoted 15 lines · Nicolin Chen
The
arm_smmu_attach_commit()updatesmaster->ats_enabledbefore callingarm_smmu_remove_master_domain()that is supposed to clean up everything in the old domain, including the old domain'snr_ats_masters. So, it is supposed to use the oldats_enabledstate of the device, not an updated state.This isn't a problem if switching between two domains where:
- oldats_enabled= false; newats_enabled= false
- oldats_enabled= true; newats_enabled= true
but can fail cases where:
- oldats_enabled= false; newats_enabled= true
(old domain should keep the counter but incorrectly decreased it)
- oldats_enabled= true; newats_enabled= false
(old domain needed to decrease the counter but incorrectly missed it)
Quoted 6 lines
Update
master->ats_enabledafterarm_smmu_remove_master_domain()to fix this.Fixes 7497f4211f4f ("iommu/arm-smmu-v3: Make changing domains be hitless for ATS")Signed-off-by Nicolin Chen <[email protected]>
arm_smmu_remove_master_domain() needs to see the old ats_enabled state for the cleanup.
Thanks,
Praan
Quoted 23 lines
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1
-1@@ -2997,9 +2997,9 @@ void arm_smmu_attach_commit(struct arm_smmu_attach_state *state)/* ATS is being switched off, invalidate the entire ATC */ arm_smmu_atc_inv_master (master,IOMMU_NO_PASID ); } - master->ats_enabled = state->ats_enabled;arm_smmu_remove_master_domain (master, state->old_domain, state->ssid); + master->ats_enabled = state->ats_enabled; }static int arm_smmu_attach_dev (struct iommu_domain *domain,struct device *dev)Signature · 1 line
2.43.0
Quoted 18 lines · Nicolin Chen
The
arm_smmu_attach_commit()updatesmaster->ats_enabledbefore callingarm_smmu_remove_master_domain()that is supposed to clean up everything in the old domain, including the old domain'snr_ats_masters. So, it is supposed to use the oldats_enabledstate of the device, not an updated state.This isn't a problem if switching between two domains where:
- oldats_enabled= false; newats_enabled= false
- oldats_enabled= true; newats_enabled= true
but can fail cases where:
- oldats_enabled= false; newats_enabled= true
(old domain should keep the counter but incorrectly decreased it)
- oldats_enabled= true; newats_enabled= false
(old domain needed to decrease the counter but incorrectly missed it)Update
master->ats_enabledafterarm_smmu_remove_master_domain()to fix this.
Quoted 6 lines
Fixes 7497f4211f4f ("iommu/arm-smmu-v3: Make changing domains be hitless for ATS")Signed-off-by Nicolin Chen <[email protected]>--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Jason
Quoted 42 lines · Nicolin Chen
The
arm_smmu_attach_commit()updatesmaster->ats_enabledbefore callingarm_smmu_remove_master_domain()that is supposed to clean up everything in the old domain, including the old domain'snr_ats_masters. So, it is supposed to use the oldats_enabledstate of the device, not an updated state.This isn't a problem if switching between two domains where:
- oldats_enabled= false; newats_enabled= false
- oldats_enabled= true; newats_enabled= true
but can fail cases where:
- oldats_enabled= false; newats_enabled= true
(old domain should keep the counter but incorrectly decreased it)
- oldats_enabled= true; newats_enabled= false
(old domain needed to decrease the counter but incorrectly missed it)Update
master->ats_enabledafterarm_smmu_remove_master_domain()to fix this.Fixes 7497f4211f4f ("iommu/arm-smmu-v3: Make changing domains be hitless for ATS")Signed-off-by Nicolin Chen <[email protected]>--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1
-1@@ -2997,9 +2997,9 @@ void arm_smmu_attach_commit(struct arm_smmu_attach_state *state)/* ATS is being switched off, invalidate the entire ATC */ arm_smmu_atc_inv_master (master,IOMMU_NO_PASID ); } - master->ats_enabled = state->ats_enabled;arm_smmu_remove_master_domain (master, state->old_domain, state->ssid); + master->ats_enabled = state->ats_enabled; }static int arm_smmu_attach_dev (struct iommu_domain *domain,struct device *dev)Signature · 1 line
2.43.0
Joerg -- please can you pick this up as a fix?
Thanks,
Will
Joerg Roedel
maintainerQuoted 2 lines · Nicolin Chen
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied for -rc, thanks.