* [PATCH v1] iommu/vt-d: Remove dead code in intel_iommu_domain_alloc_paging_flags()
@ 2025-05-30 9:13 Wei Wang
2025-06-03 2:39 ` Baolu Lu
2025-06-03 15:06 ` Jason Gunthorpe
0 siblings, 2 replies; 5+ messages in thread
From: Wei Wang @ 2025-05-30 9:13 UTC (permalink / raw)
To: baolu.lu, kevin.tian, yi.l.liu, dwmw2, jroedel, linux-kernel,
iommu
Cc: Wei Wang
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.
Signed-off-by: Wei Wang <wei.w.wang@intel.com>
---
drivers/iommu/intel/iommu.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index cb0b993bebb4..1145567c60f9 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v1] iommu/vt-d: Remove dead code in intel_iommu_domain_alloc_paging_flags()
2025-05-30 9:13 [PATCH v1] iommu/vt-d: Remove dead code in intel_iommu_domain_alloc_paging_flags() Wei Wang
@ 2025-06-03 2:39 ` Baolu Lu
2025-06-03 3:31 ` Wang, Wei W
2025-06-05 3:55 ` Ethan Zhao
2025-06-03 15:06 ` Jason Gunthorpe
1 sibling, 2 replies; 5+ messages in thread
From: Baolu Lu @ 2025-06-03 2:39 UTC (permalink / raw)
To: Wei Wang, kevin.tian, yi.l.liu, dwmw2, jroedel, linux-kernel,
iommu
On 5/30/25 17:13, Wei Wang wrote:
> 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.
>
> Signed-off-by: Wei Wang<wei.w.wang@intel.com>
> ---
> drivers/iommu/intel/iommu.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> index cb0b993bebb4..1145567c60f9 100644
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -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.
> - iommu_domain_free(domain);
> - return ERR_PTR(-EOPNOTSUPP);
> - }
Thanks,
baolu
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH v1] iommu/vt-d: Remove dead code in intel_iommu_domain_alloc_paging_flags()
2025-06-03 2:39 ` Baolu Lu
@ 2025-06-03 3:31 ` Wang, Wei W
2025-06-05 3:55 ` Ethan Zhao
1 sibling, 0 replies; 5+ messages in thread
From: Wang, Wei W @ 2025-06-03 3:31 UTC (permalink / raw)
To: Baolu Lu, Tian, Kevin, Liu, Yi L, dwmw2@infradead.org,
jroedel@suse.de, linux-kernel@vger.kernel.org,
iommu@lists.linux.dev
On Tuesday, June 3, 2025 10:40 AM, Baolu Lu wrote:
> On 5/30/25 17:13, Wei Wang wrote:
> > 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.
> >
> > Signed-off-by: Wei Wang<wei.w.wang@intel.com>
> > ---
> > drivers/iommu/intel/iommu.c | 7 +------
> > 1 file changed, 1 insertion(+), 6 deletions(-)
> >
> > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> > index cb0b993bebb4..1145567c60f9 100644
> > --- a/drivers/iommu/intel/iommu.c
> > +++ b/drivers/iommu/intel/iommu.c
> > @@ -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.
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?)
>
> > - iommu_domain_free(domain);
> > - return ERR_PTR(-EOPNOTSUPP);
> > - }
>
> Thanks,
> baolu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] iommu/vt-d: Remove dead code in intel_iommu_domain_alloc_paging_flags()
2025-05-30 9:13 [PATCH v1] iommu/vt-d: Remove dead code in intel_iommu_domain_alloc_paging_flags() Wei Wang
2025-06-03 2:39 ` Baolu Lu
@ 2025-06-03 15:06 ` Jason Gunthorpe
1 sibling, 0 replies; 5+ messages in thread
From: Jason Gunthorpe @ 2025-06-03 15:06 UTC (permalink / raw)
To: Wei Wang
Cc: baolu.lu, kevin.tian, yi.l.liu, dwmw2, jroedel, linux-kernel,
iommu
On Fri, May 30, 2025 at 05:13:25PM +0800, Wei Wang wrote:
> 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.
>
> Signed-off-by: Wei Wang <wei.w.wang@intel.com>
> ---
> drivers/iommu/intel/iommu.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
I noticed this too
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] iommu/vt-d: Remove dead code in intel_iommu_domain_alloc_paging_flags()
2025-06-03 2:39 ` Baolu Lu
2025-06-03 3:31 ` Wang, Wei W
@ 2025-06-05 3:55 ` Ethan Zhao
1 sibling, 0 replies; 5+ messages in thread
From: Ethan Zhao @ 2025-06-05 3:55 UTC (permalink / raw)
To: Baolu Lu, Wei Wang, kevin.tian, yi.l.liu, dwmw2, jroedel,
linux-kernel, iommu
On 6/3/2025 10:39 AM, Baolu Lu wrote:
> On 5/30/25 17:13, Wei Wang wrote:
>> 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.
>>
>> Signed-off-by: Wei Wang<wei.w.wang@intel.com>
>> ---
>> drivers/iommu/intel/iommu.c | 7 +------
>> 1 file changed, 1 insertion(+), 6 deletions(-)
>>
>> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
>> index cb0b993bebb4..1145567c60f9 100644
>> --- a/drivers/iommu/intel/iommu.c
>> +++ b/drivers/iommu/intel/iommu.c
>> @@ -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.
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
>
>> - iommu_domain_free(domain);
>> - return ERR_PTR(-EOPNOTSUPP);
>> - }
>
> Thanks,
> baolu
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-06-05 3:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-30 9:13 [PATCH v1] iommu/vt-d: Remove dead code in intel_iommu_domain_alloc_paging_flags() Wei Wang
2025-06-03 2:39 ` Baolu Lu
2025-06-03 3:31 ` Wang, Wei W
2025-06-05 3:55 ` Ethan Zhao
2025-06-03 15:06 ` Jason Gunthorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).