* [PATCH v1] iommu/vt-d: Remove the redundant logic in first_level_by_default()
@ 2025-05-23 8:10 Wei Wang
2025-05-23 8:15 ` Tian, Kevin
2025-05-29 5:48 ` Ethan Zhao
0 siblings, 2 replies; 7+ messages in thread
From: Wei Wang @ 2025-05-23 8:10 UTC (permalink / raw)
To: baolu.lu, kevin.tian, yi.l.liu, dwmw2, jroedel, linux-kernel,
iommu
Cc: 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 <wei.w.wang@intel.com>
---
drivers/iommu/intel/iommu.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index cb0b993bebb4..228da47ab7cd 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -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)
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* RE: [PATCH v1] iommu/vt-d: Remove the redundant logic in first_level_by_default()
2025-05-23 8:10 [PATCH v1] iommu/vt-d: Remove the redundant logic in first_level_by_default() Wei Wang
@ 2025-05-23 8:15 ` Tian, Kevin
2025-05-29 5:48 ` Ethan Zhao
1 sibling, 0 replies; 7+ messages in thread
From: Tian, Kevin @ 2025-05-23 8:15 UTC (permalink / raw)
To: Wang, Wei W, baolu.lu@linux.intel.com, Liu, Yi L,
dwmw2@infradead.org, jroedel@suse.de,
linux-kernel@vger.kernel.org, iommu@lists.linux.dev
> From: Wang, Wei W <wei.w.wang@intel.com>
> Sent: Friday, May 23, 2025 4:11 PM
>
> 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 <wei.w.wang@intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1] iommu/vt-d: Remove the redundant logic in first_level_by_default()
2025-05-23 8:10 [PATCH v1] iommu/vt-d: Remove the redundant logic in first_level_by_default() Wei Wang
2025-05-23 8:15 ` Tian, Kevin
@ 2025-05-29 5:48 ` Ethan Zhao
2025-05-29 6:11 ` Tian, Kevin
1 sibling, 1 reply; 7+ messages in thread
From: Ethan Zhao @ 2025-05-29 5:48 UTC (permalink / raw)
To: Wei Wang, baolu.lu, kevin.tian, yi.l.liu, dwmw2, jroedel,
linux-kernel, iommu
在 2025/5/23 16:10, 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 <wei.w.wang@intel.com>
> ---
> drivers/iommu/intel/iommu.c | 10 +---------
> 1 file changed, 1 insertion(+), 9 deletions(-)
>
> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> index cb0b993bebb4..228da47ab7cd 100644
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -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;
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
> + 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
> }
>
> int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu)
--
"firm, enduring, strong, and long-lived"
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH v1] iommu/vt-d: Remove the redundant logic in first_level_by_default()
2025-05-29 5:48 ` Ethan Zhao
@ 2025-05-29 6:11 ` Tian, Kevin
2025-06-04 7:25 ` Ethan Zhao
0 siblings, 1 reply; 7+ messages in thread
From: Tian, Kevin @ 2025-05-29 6:11 UTC (permalink / raw)
To: Ethan Zhao, Wang, Wei W, baolu.lu@linux.intel.com, Liu, Yi L,
dwmw2@infradead.org, jroedel@suse.de,
linux-kernel@vger.kernel.org, iommu@lists.linux.dev
> From: Ethan Zhao <haifeng.zhao@linux.intel.com>
> Sent: Thursday, May 29, 2025 1:48 PM
>
> 在 2025/5/23 16:10, 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 <wei.w.wang@intel.com>
> > ---
> > drivers/iommu/intel/iommu.c | 10 +---------
> > 1 file changed, 1 insertion(+), 9 deletions(-)
> >
> > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> > index cb0b993bebb4..228da47ab7cd 100644
> > --- a/drivers/iommu/intel/iommu.c
> > +++ b/drivers/iommu/intel/iommu.c
> > @@ -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;
>
> 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
'e' is actually wrong. We should not return true when the 1st level
cap doesn't exist.
>
> > + 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
so this table is correct.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1] iommu/vt-d: Remove the redundant logic in first_level_by_default()
2025-05-29 6:11 ` Tian, Kevin
@ 2025-06-04 7:25 ` Ethan Zhao
2025-06-05 1:04 ` Wang, Wei W
0 siblings, 1 reply; 7+ messages in thread
From: Ethan Zhao @ 2025-06-04 7:25 UTC (permalink / raw)
To: Tian, Kevin, Ethan Zhao, Wang, Wei W, baolu.lu@linux.intel.com,
Liu, Yi L, dwmw2@infradead.org, jroedel@suse.de,
linux-kernel@vger.kernel.org, iommu@lists.linux.dev
On 5/29/2025 2:11 PM, Tian, Kevin wrote:
>> From: Ethan Zhao <haifeng.zhao@linux.intel.com>
>> Sent: Thursday, May 29, 2025 1:48 PM
>>
>> 在 2025/5/23 16:10, 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 <wei.w.wang@intel.com>
>>> ---
>>> drivers/iommu/intel/iommu.c | 10 +---------
>>> 1 file changed, 1 insertion(+), 9 deletions(-)
>>>
>>> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
>>> index cb0b993bebb4..228da47ab7cd 100644
>>> --- a/drivers/iommu/intel/iommu.c
>>> +++ b/drivers/iommu/intel/iommu.c
>>> @@ -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;
>>
>> 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
>
> '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
>
>>
>>> + 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
>
> so this table is correct.
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH v1] iommu/vt-d: Remove the redundant logic in first_level_by_default()
2025-06-04 7:25 ` Ethan Zhao
@ 2025-06-05 1:04 ` Wang, Wei W
2025-06-05 3:33 ` Ethan Zhao
0 siblings, 1 reply; 7+ messages in thread
From: Wang, Wei W @ 2025-06-05 1:04 UTC (permalink / raw)
To: Ethan Zhao, Tian, Kevin, Ethan Zhao, baolu.lu@linux.intel.com,
Liu, Yi L, dwmw2@infradead.org, jroedel@suse.de,
linux-kernel@vger.kernel.org, iommu@lists.linux.dev
On Wednesday, June 4, 2025 3:26 PM, Ethan Zhao wrote:
> On 5/29/2025 2:11 PM, Tian, Kevin wrote:
> >> From: Ethan Zhao <haifeng.zhao@linux.intel.com>
> >> Sent: Thursday, May 29, 2025 1:48 PM
> >>
> >> 在 2025/5/23 16:10, 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 <wei.w.wang@intel.com>
> >>> ---
> >>> drivers/iommu/intel/iommu.c | 10 +---------
> >>> 1 file changed, 1 insertion(+), 9 deletions(-)
> >>>
> >>> diff --git a/drivers/iommu/intel/iommu.c
> >>> b/drivers/iommu/intel/iommu.c index cb0b993bebb4..228da47ab7cd
> >>> 100644
> >>> --- a/drivers/iommu/intel/iommu.c
> >>> +++ b/drivers/iommu/intel/iommu.c
> >>> @@ -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;
> >>
> >> 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
> >
> > '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.
> >
> >>
> >>> + 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
> >
> > so this table is correct.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1] iommu/vt-d: Remove the redundant logic in first_level_by_default()
2025-06-05 1:04 ` Wang, Wei W
@ 2025-06-05 3:33 ` Ethan Zhao
0 siblings, 0 replies; 7+ messages in thread
From: Ethan Zhao @ 2025-06-05 3:33 UTC (permalink / raw)
To: Wang, Wei W, Tian, Kevin, Ethan Zhao, baolu.lu@linux.intel.com,
Liu, Yi L, dwmw2@infradead.org, jroedel@suse.de,
linux-kernel@vger.kernel.org, iommu@lists.linux.dev
On 6/5/2025 9:04 AM, Wang, Wei W wrote:
> On Wednesday, June 4, 2025 3:26 PM, Ethan Zhao wrote:
>> On 5/29/2025 2:11 PM, Tian, Kevin wrote:
>>>> From: Ethan Zhao <haifeng.zhao@linux.intel.com>
>>>> Sent: Thursday, May 29, 2025 1:48 PM
>>>>
>>>> 在 2025/5/23 16:10, 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 <wei.w.wang@intel.com>
>>>>> ---
>>>>> drivers/iommu/intel/iommu.c | 10 +---------
>>>>> 1 file changed, 1 insertion(+), 9 deletions(-)
>>>>>
>>>>> diff --git a/drivers/iommu/intel/iommu.c
>>>>> b/drivers/iommu/intel/iommu.c index cb0b993bebb4..228da47ab7cd
>>>>> 100644
>>>>> --- a/drivers/iommu/intel/iommu.c
>>>>> +++ b/drivers/iommu/intel/iommu.c
>>>>> @@ -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;
>>>>
>>>> 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
>>>
>>> '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.
>
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
>
>>>
>>>>
>>>>> + 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
>>>
>>> so this table is correct.
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-06-05 3:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-23 8:10 [PATCH v1] iommu/vt-d: Remove the redundant logic in first_level_by_default() Wei Wang
2025-05-23 8:15 ` Tian, Kevin
2025-05-29 5:48 ` Ethan Zhao
2025-05-29 6:11 ` Tian, Kevin
2025-06-04 7:25 ` Ethan Zhao
2025-06-05 1:04 ` Wang, Wei W
2025-06-05 3:33 ` Ethan Zhao
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).