iommu/vt-d: Remove the redundant logic in first_level_by_default()
Subsystems (2)
PATCH 1/1 iommu/vt-d: Remove the redundant logic in first_level_by_default()
This original implementation included redundant logic to determine whether first-stage translation should be used by default. Simplify it and preserve the original behavior:
- Returns false in legacy mode (no scalable mode support).
- Defaults to first-level translation when both FLTS and SLTS are supported.
--- drivers/iommu/intel/iommu.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/iommu/intel/iommu.c +1 -9
@@ -1366,15 +1366,7 @@ static void free_dmar_iommu(struct intel_iommu *iommu)*/ static bool first_level_by_default (struct intel_iommu *iommu) { -/* Only SL is available in legacy mode */ -if (!sm_supported (iommu)) -return false; - -/* Only level (either FL or SL) is available, just use it */ -if (ecap_flts (iommu->ecap) ^ecap_slts (iommu->ecap)) -return ecap_flts (iommu->ecap); - -return true; +return sm_supported (iommu) &&ecap_flts (iommu->ecap); }int domain_attach_iommu (struct dmar_domain *domain,struct intel_iommu *iommu)
Signature · 1 line
2.43.0
Quoted 11 lines
From: Wang, Wei W <[email protected]>
Sent: Friday, May 23, 2025 4:11 PMThis original implementation included redundant logic to determine whether first-stage translation should be used by default. Simplify it and preserve the original behavior:
- Returns false in legacy mode (no scalable mode support).
- Defaults to first-level translation when both FLTS and SLTS are supported.Signed-off-by Wei Wang <[email protected]>
Quoted 19 lines · Wei Wang
This original implementation included redundant logic to determine whether first-stage translation should be used by default. Simplify it and preserve the original behavior:
- Returns false in legacy mode (no scalable mode support).
- Defaults to first-level translation when both FLTS and SLTS are supported.Signed-off-by Wei Wang <[email protected]>--- drivers/iommu/intel/iommu.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)drivers/iommu/intel/iommu.c +0
-0@@ -1366,15 +1366,7 @@ static void free_dmar_iommu(struct intel_iommu *iommu)*/ static bool first_level_by_default (struct intel_iommu *iommu)
drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct intel_iommu *iommu) · line 1377
Quoted 10 lines
drivers/iommu/intel/iommu.c +0
-9{ -/* Only SL is available in legacy mode */ -if (!sm_supported (iommu)) -return false; - -/* Only level (either FL or SL) is available, just use it */ -if (ecap_flts (iommu->ecap) ^ecap_slts (iommu->ecap)) -return ecap_flts (iommu->ecap); - -return true;
The function works like a digital circurt has 3 single bit inputs sm, flts, slts and one bit output ret.
so the true value table of the orignal function looks like
sm flts slts ret
a 0 x x false
b 1 1 0 true
c 1 0 1 false
d 1 1 1 true
e 1 0 0 true
drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct intel_iommu *iommu) · line 1369
Quoted 1 line
drivers/iommu/intel/iommu.c +1
-0+return sm_supported (iommu) &&ecap_flts (iommu->ecap);
And the true value table of this new one looks like
sm flts slts ret
f 1 1 x true
g 1 0 x false
h 0 1 x false
i 0 0 x false
h, i covers a
g, doesn't cover e, c
f, covers b, d
So if we take them as two circurt blocks (chip), their functions aren't equal to each other.
If we don't make any assumption, I wouldn't replace the old chip with new one
But, maybe all the new chip and old one all works well under specific context that I
didn't think deeper. :)
Thanks,
Ethan
Quoted 3 lines
drivers/iommu/intel/iommu.c +0
-0}int domain_attach_iommu (struct dmar_domain *domain,struct intel_iommu *iommu)
Signature · 1 line
"firm, enduring, strong, and long-lived"
Quoted 39 lines
From: Ethan Zhao <[email protected]>
Sent: Thursday, May 29, 2025 1:48 PMQuoted 1 line · Wei Wang
This original implementation included redundant logic to determine
whether
drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct
Quoted 16 lines
first-stage translation should be used by default. Simplify it and preserve the original behavior:
- Returns false in legacy mode (no scalable mode support).
- Defaults to first-level translation when both FLTS and SLTS are supported.Signed-off-by Wei Wang <[email protected]>--- drivers/iommu/intel/iommu.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)drivers/iommu/intel/iommu.c +0
-0@@ -1366,15 +1366,7 @@ static void free_dmar_iommu(struct
intel_iommu*iommu)drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct intel_iommu *iommu) · line 1377
Quoted 12 lines
drivers/iommu/intel/iommu.c +0
-9*/ static bool first_level_by_default (struct intel_iommu *iommu) { -/* Only SL is available in legacy mode */ -if (!sm_supported (iommu)) -return false; - -/* Only level (either FL or SL) is available, just use it */ -if (ecap_flts (iommu->ecap) ^ecap_slts (iommu->ecap)) -return ecap_flts (iommu->ecap); - -return true;The function works like a digital circurt has 3 single bit inputs sm, flts, slts and one bit output ret.
Quoted 8 lines
so the true value table of the orignal function looks like
sm flts slts ret
a 0 x x false
b 1 1 0 true
c 1 0 1 false
d 1 1 1 true
e 1 0 0 true
'e' is actually wrong. We should not return true when the 1st level cap doesn't exist.
Quoted 5 lines
drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct intel_iommu *iommu) · line 1369
Quoted 2 lines
drivers/iommu/intel/iommu.c +1
-0+return sm_supported (iommu) &&ecap_flts (iommu->ecap);And the true value table of this new one looks like
Quoted 7 lines
sm flts slts ret
f 1 1 x true
g 1 0 x falseh 0 1 x false
i 0 0 x false
so this table is correct.
Quoted 48 lines · Kevin
Quoted 39 lines
From: Ethan Zhao <[email protected]>
Sent: Thursday, May 29, 2025 1:48 PMQuoted 1 line · Wei Wang
This original implementation included redundant logic to determine
whether
drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct
Quoted 16 lines
first-stage translation should be used by default. Simplify it and preserve the original behavior:
- Returns false in legacy mode (no scalable mode support).
- Defaults to first-level translation when both FLTS and SLTS are supported.Signed-off-by Wei Wang <[email protected]>--- drivers/iommu/intel/iommu.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)drivers/iommu/intel/iommu.c +0
-0@@ -1366,15 +1366,7 @@ static void free_dmar_iommu(struct
intel_iommu*iommu)drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct intel_iommu *iommu) · line 1377
Quoted 12 lines
drivers/iommu/intel/iommu.c +0
-9*/ static bool first_level_by_default (struct intel_iommu *iommu) { -/* Only SL is available in legacy mode */ -if (!sm_supported (iommu)) -return false; - -/* Only level (either FL or SL) is available, just use it */ -if (ecap_flts (iommu->ecap) ^ecap_slts (iommu->ecap)) -return ecap_flts (iommu->ecap); - -return true;The function works like a digital circurt has 3 single bit inputs sm, flts, slts and one bit output ret.
Quoted 8 lines
so the true value table of the orignal function looks like
sm flts slts ret
a 0 x x false
b 1 1 0 true
c 1 0 1 false
d 1 1 1 true
e 1 0 0 true
Quoted 2 lines
'e' is actually wrong. We should not return true when the 1st level cap doesn't exist.
If so, this patch should mention it fixes such case with fix tag, not
"removing the redundant logic with the same behavior".
Thanks,
Ethan
Quoted 15 lines
Quoted 6 lines
drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct intel_iommu *iommu) · line 1369
Quoted 3 lines
drivers/iommu/intel/iommu.c +1
-0+return sm_supported (iommu) &&ecap_flts (iommu->ecap);And the true value table of this new one looks like
Quoted 7 lines
sm flts slts ret
f 1 1 x true
g 1 0 x falseh 0 1 x false
i 0 0 x falseso this table is correct.
Quoted 50 lines · Ethan Zhao
Quoted 49 lines · Kevin
Quoted 48 lines
From: Ethan Zhao <[email protected]>
Sent: Thursday, May 29, 2025 1:48 PMQuoted 1 line · Wei Wang
This original implementation included redundant logic to determine
whether
drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct
Quoted 17 lines
first-stage translation should be used by default. Simplify it and preserve the original behavior:
- Returns false in legacy mode (no scalable mode support).
- Defaults to first-level translation when both FLTS and SLTS are supported.Signed-off-by Wei Wang <[email protected]>--- drivers/iommu/intel/iommu.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cindexcb0b993bebb4..228da47ab7cd100644drivers/iommu/intel/iommu.c +0
-0@@ -1366,15 +1366,7 @@ static void free_dmar_iommu(struct
intel_iommu*iommu)drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct intel_iommu *iommu) · line 1377
Quoted 12 lines
drivers/iommu/intel/iommu.c +0
-9*/ static bool first_level_by_default (struct intel_iommu *iommu) { -/* Only SL is available in legacy mode */ -if (!sm_supported (iommu)) -return false; - -/* Only level (either FL or SL) is available, just use it */ -if (ecap_flts (iommu->ecap) ^ecap_slts (iommu->ecap)) -return ecap_flts (iommu->ecap); - -return true;The function works like a digital circurt has 3 single bit inputs sm, flts, slts and one bit output ret.
so the true value table of the orignal function looks like
sm flts slts ret
a 0 x x false
b 1 1 0 true
c 1 0 1 false
d 1 1 1 true
e 1 0 0 true
Quoted 6 lines
Quoted 2 lines
'e' is actually wrong. We should not return true when the 1st level cap doesn't exist.
If so, this patch should mention it fixes such case with fix tag, not
"removing the redundant logic with the same behavior".
Probably not a fix (just code improvement). Your 'e' above is not possible from the hardware side, and the old implementation doesn't have it too.
Quoted 15 lines
Quoted 15 lines
Quoted 6 lines
drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct intel_iommu *iommu) · line 1369
Quoted 3 lines
drivers/iommu/intel/iommu.c +1
-0+return sm_supported (iommu) &&ecap_flts (iommu->ecap);And the true value table of this new one looks like
Quoted 7 lines
sm flts slts ret
f 1 1 x true
g 1 0 x falseh 0 1 x false
i 0 0 x falseso this table is correct.
Quoted 54 lines · Wei W
Quoted 53 lines · Ethan Zhao
Quoted 51 lines · Kevin
Quoted 40 lines
From: Ethan Zhao <[email protected]>
Sent: Thursday, May 29, 2025 1:48 PMQuoted 1 line · Wei Wang
This original implementation included redundant logic to determine
whether
drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct
Quoted 17 lines
first-stage translation should be used by default. Simplify it and preserve the original behavior:
- Returns false in legacy mode (no scalable mode support).
- Defaults to first-level translation when both FLTS and SLTS are supported.Signed-off-by Wei Wang <[email protected]>--- drivers/iommu/intel/iommu.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cindexcb0b993bebb4..228da47ab7cd100644drivers/iommu/intel/iommu.c +0
-0@@ -1366,15 +1366,7 @@ static void free_dmar_iommu(struct
intel_iommu*iommu)drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct intel_iommu *iommu) · line 1377
Quoted 12 lines
drivers/iommu/intel/iommu.c +0
-9*/ static bool first_level_by_default (struct intel_iommu *iommu) { -/* Only SL is available in legacy mode */ -if (!sm_supported (iommu)) -return false; - -/* Only level (either FL or SL) is available, just use it */ -if (ecap_flts (iommu->ecap) ^ecap_slts (iommu->ecap)) -return ecap_flts (iommu->ecap); - -return true;The function works like a digital circurt has 3 single bit inputs sm, flts, slts and one bit output ret.
Quoted 8 lines
so the true value table of the orignal function looks like
sm flts slts ret
a 0 x x false
b 1 1 0 true
c 1 0 1 false
d 1 1 1 true
e 1 0 0 true'e' is actually wrong. We should not return true when the 1st level cap doesn't exist.
Quoted 7 lines
Quoted 3 lines
If so, this patch should mention it fixes such case with fix tag, not
"removing the redundant logic with the same behavior".Probably not a fix (just code improvement). Your 'e' above is not possible from the hardware side, and the old implementation doesn't have it too.
Is there any items in Intel VT-d spec to say "It is impossible to have both flts and slts to false" or you design code under an assumption that hardware always works perfect ?
You made an assumption that the hardware never would reach there and then got a conclusion 'e' doesn't exist ?
Thanks,
Ethan
Quoted 17 lines
Quoted 16 lines
Quoted 16 lines
Quoted 7 lines
drivers/iommu/intel/iommu.c static void free_dmar_iommu(struct intel_iommu *iommu) · line 1369
Quoted 4 lines
drivers/iommu/intel/iommu.c +1
-0+return sm_supported (iommu) &&ecap_flts (iommu->ecap);And the true value table of this new one looks like
Quoted 7 lines
sm flts slts ret
f 1 1 x true
g 1 0 x falseh 0 1 x false
i 0 0 x falseso this table is correct.