iommu/vt-d: Remove dead code in intel_iommu_domain_alloc_paging_flags()
Subsystems (2)
PATCH 1/1 iommu/vt-d: Remove dead code in intel_iommu_domain_alloc_paging_flags()
When dirty_tracking is enabled, first_stage is set to false to use the second stage translation table. dmar_domain->use_first_level, which is assigned from first_page, is guaranteed to be false when the execution reaches the location of the code to be removed by this patch. So the handling for dmar_domain->use_first_level being true there will never be executed.
--- drivers/iommu/intel/iommu.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/iommu/intel/iommu.c +1 -6
@@ -3418,13 +3418,8 @@ intel_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,spin_lock_init (&dmar_domain->s1_lock); } -if (dirty_tracking) { -if (dmar_domain->use_first_level) { -iommu_domain_free (domain); -return ERR_PTR (-EOPNOTSUPP ); - } +if (dirty_tracking) domain->dirty_ops = &intel_dirty_ops; - }return domain; }
base-commit: e0797d3b91de75b6c95b4a0e0649ebd4aac1d9d1
Signature · 1 line
2.43.0
Baolu Lu
maintainerQuoted 17 lines · Wei Wang
When
dirty_trackingis enabled,first_stageis set to false to use the second stage translation table.dmar_domain->use_first_level, which is assigned fromfirst_page, is guaranteed to be false when the execution reaches the location of the code to be removed by this patch. So the handling fordmar_domain->use_first_levelbeing true there will never be executed.Signed-off-by Wei Wang<[email protected]>--- drivers/iommu/intel/iommu.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)drivers/iommu/intel/iommu.c +0
-0
drivers/iommu/intel/iommu.c intel_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags, · line 3422
Quoted 5 lines
drivers/iommu/intel/iommu.c +0
-2@@ -3418,13 +3418,8 @@ intel_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,spin_lock_init (&dmar_domain->s1_lock); } -if (dirty_tracking) { -if (dmar_domain->use_first_level) {
This *explicit* check enforces that dirty tracking cannot be supported for a domain that relies on first-stage translation due to the lack of enabling/disabling dirty tracking support.
While this might appear redundant, this prevents potential issues if related code is modified without awareness of this dependency.
drivers/iommu/intel/iommu.c intel_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags, · line 3425
Quoted 3 lines
drivers/iommu/intel/iommu.c +0
-3-iommu_domain_free (domain); -return ERR_PTR (-EOPNOTSUPP ); - }
Thanks,
baolu
Quoted 29 lines · Baolu Lu
drivers/iommu/intel/iommu.c intel_iommu_domain_alloc_paging_flags(struct
Quoted 17 lines · Wei Wang
When
dirty_trackingis enabled,first_stageis set to false to use the second stage translation table.dmar_domain->use_first_level, which is assigned fromfirst_page, is guaranteed to be false when the execution reaches the location of the code to be removed by this patch. So the handling fordmar_domain->use_first_levelbeing true there will never be executed.Signed-off-by Wei Wang<[email protected]>--- drivers/iommu/intel/iommu.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)drivers/iommu/intel/iommu.c +0
-0@@ -3418,13 +3418,8 @@ intel_iommu_domain_alloc_paging_flags(structdevice *dev, u32 flags,
drivers/iommu/intel/iommu.c intel_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags, · line 3422
Quoted 5 lines
drivers/iommu/intel/iommu.c +0
-2spin_lock_init (&dmar_domain->s1_lock); } -if (dirty_tracking) { -if (dmar_domain->use_first_level) {This *explicit* check enforces that dirty tracking cannot be supported for a domain that relies on first-stage translation due to the lack of enabling/disabling dirty tracking support.
Quoted 2 lines
While this might appear redundant, this prevents potential issues if related code is modified without awareness of this dependency.
Would a warning (i.e., WARN_ON(dmar_domain->use_first_level)) be better here? (this condition seems unlikely to occur in practice, especially in official kernel releases, and the current handling logic appears somewhat confusing. If developers add some new logic that could change dmar_domain->use_first_level to ture (maybe by mistake) in the future, they could bring the handling back, which might look clearer?)
Quoted 7 lines
drivers/iommu/intel/iommu.c intel_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags, · line 3425
Quoted 4 lines
drivers/iommu/intel/iommu.c +0
-3-iommu_domain_free (domain); -return ERR_PTR (-EOPNOTSUPP ); - }Thanks,
baolu
Quoted 28 lines · Baolu Lu
Quoted 17 lines · Wei Wang
When
dirty_trackingis enabled,first_stageis set to false to use the second stage translation table.dmar_domain->use_first_level, which is assigned fromfirst_page, is guaranteed to be false when the execution reaches the location of the code to be removed by this patch. So the handling fordmar_domain->use_first_levelbeing true there will never be executed.Signed-off-by Wei Wang<[email protected]>---
drivers/iommu/intel/iommu.c| 7 +------1 file changed, 1 insertion(+), 6 deletions(-)drivers/iommu/intel/iommu.c +0
-0drivers/iommu/intel/iommu.c intel_iommu_domain_alloc_paging_flags(struct · line 3422
Quoted 5 lines
drivers/iommu/intel/iommu.c +0
-2@@ -3418,13 +3418,8 @@ intel_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags, spin_lock_init(&dmar_domain->s1_lock); } - if (dirty_tracking) { - if (dmar_domain->use_first_level) {This *explicit* check enforces that dirty tracking cannot be supported for a domain that relies on first-stage translation due to the lack of enabling/disabling dirty tracking support.
Quoted 2 lines
While this might appear redundant, this prevents potential issues if related code is modified without awareness of this dependency.
There would always something sooner or later like this to stop the improper configuration/coding , under an assumption that caller path always coded perfect, indeed, we could remove a lot of error stopper code.
But that world seems never works like that.
Thanks,
Ethan
Quoted 8 lines
drivers/iommu/intel/iommu.c intel_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags, · line 3425
Quoted 4 lines
drivers/iommu/intel/iommu.c +0
-3- iommu_domain_free(domain); - return ERR_PTR(-EOPNOTSUPP); - }Thanks,
baolu
Quoted 11 lines · Wei Wang
When
dirty_trackingis enabled,first_stageis set to false to use the second stage translation table.dmar_domain->use_first_level, which is assigned fromfirst_page, is guaranteed to be false when the execution reaches the location of the code to be removed by this patch. So the handling fordmar_domain->use_first_levelbeing true there will never be executed.Signed-off-by Wei Wang <[email protected]>--- drivers/iommu/intel/iommu.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
I noticed this too
Jason