public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/amd: Fix precedence order in set_dte_passthrough()
@ 2026-04-30 23:28 Weinan Liu
  2026-05-01  0:00 ` Weinan Liu
  2026-05-04  4:57 ` Vasant Hegde
  0 siblings, 2 replies; 4+ messages in thread
From: Weinan Liu @ 2026-04-30 23:28 UTC (permalink / raw)
  To: iommu, jgg, joro, suravee.suthikulpanit
  Cc: will, patches, stable, robin.murphy, vasant.hegde, santosh.shukla,
	chrisl, Weinan Liu

Bitwise OR | operator has a higher precedence than the ternary ?:
operatior. It will be incorrectly evaluated as:

new->data[1] |= (FIELD_PREP(...) | dev_data->ats_enabled) ? DTE_FLAG_IOTLB : 0;

Wrap the conditional operation in parentheses to enforce the
correct evaluation order.

Fixes: 93eee2a49c1b ("iommu/amd: Refactor logic to program the host page table in DTE")
Signed-off-by: Weinan Liu <wnliu@google.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/amd/iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 01171361f9bc..ccffbecb15c2 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2149,7 +2149,8 @@ static void set_dte_passthrough(struct iommu_dev_data *dev_data,
 	new->data[0] |= DTE_FLAG_TV | DTE_FLAG_IR | DTE_FLAG_IW;
 
 	new->data[1] |= FIELD_PREP(DTE_DOMID_MASK, domain->id) |
-			(dev_data->ats_enabled) ? DTE_FLAG_IOTLB : 0;
+			(dev_data->ats_enabled ? DTE_FLAG_IOTLB : 0);
+
 }
 
 static void set_dte_entry(struct amd_iommu *iommu,
-- 
2.54.0.545.g6539524ca2-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] iommu/amd: Fix precedence order in set_dte_passthrough()
  2026-04-30 23:28 [PATCH] iommu/amd: Fix precedence order in set_dte_passthrough() Weinan Liu
@ 2026-05-01  0:00 ` Weinan Liu
  2026-05-01  3:01   ` Chris Li
  2026-05-04  4:57 ` Vasant Hegde
  1 sibling, 1 reply; 4+ messages in thread
From: Weinan Liu @ 2026-05-01  0:00 UTC (permalink / raw)
  To: wnliu
  Cc: chrisl, iommu, jgg, joro, patches, robin.murphy, santosh.shukla,
	stable, suravee.suthikulpanit, vasant.hegde, will

Bitwise OR | operator has a higher precedence than the ternary ?:
operatior. It will be incorrectly evaluated as:

new->data[1] |= (FIELD_PREP(...) | dev_data->ats_enabled) ? DTE_FLAG_IOTLB : 0;

Wrap the conditional operation in parentheses to enforce the
correct evaluation order.

Fixes: 93eee2a49c1b ("iommu/amd: Refactor logic to program the host page table in DTE")
Cc: stable@vger.kernel.org # v7.0.*
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Weinan Liu <wnliu@google.com>
---
 drivers/iommu/amd/iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 01171361f9bc..ccffbecb15c2 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2149,7 +2149,8 @@ static void set_dte_passthrough(struct iommu_dev_data *dev_data,
 	new->data[0] |= DTE_FLAG_TV | DTE_FLAG_IR | DTE_FLAG_IW;
 
 	new->data[1] |= FIELD_PREP(DTE_DOMID_MASK, domain->id) |
-			(dev_data->ats_enabled) ? DTE_FLAG_IOTLB : 0;
+			(dev_data->ats_enabled ? DTE_FLAG_IOTLB : 0);
+
 }
 
 static void set_dte_entry(struct amd_iommu *iommu,
-- 
2.54.0.545.g6539524ca2-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iommu/amd: Fix precedence order in set_dte_passthrough()
  2026-05-01  0:00 ` Weinan Liu
@ 2026-05-01  3:01   ` Chris Li
  0 siblings, 0 replies; 4+ messages in thread
From: Chris Li @ 2026-05-01  3:01 UTC (permalink / raw)
  To: Weinan Liu
  Cc: iommu, jgg, joro, patches, robin.murphy, santosh.shukla, stable,
	suravee.suthikulpanit, vasant.hegde, will

On Thu, Apr 30, 2026 at 5:01 PM Weinan Liu <wnliu@google.com> wrote:
>
> Bitwise OR | operator has a higher precedence than the ternary ?:
> operatior. It will be incorrectly evaluated as:
>
> new->data[1] |= (FIELD_PREP(...) | dev_data->ats_enabled) ? DTE_FLAG_IOTLB : 0;
>
> Wrap the conditional operation in parentheses to enforce the
> correct evaluation order.
>
> Fixes: 93eee2a49c1b ("iommu/amd: Refactor logic to program the host page table in DTE")
> Cc: stable@vger.kernel.org # v7.0.*
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
> Signed-off-by: Weinan Liu <wnliu@google.com>

Acked-by: Chris Li <chrisl@kernel.org>

Chris

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iommu/amd: Fix precedence order in set_dte_passthrough()
  2026-04-30 23:28 [PATCH] iommu/amd: Fix precedence order in set_dte_passthrough() Weinan Liu
  2026-05-01  0:00 ` Weinan Liu
@ 2026-05-04  4:57 ` Vasant Hegde
  1 sibling, 0 replies; 4+ messages in thread
From: Vasant Hegde @ 2026-05-04  4:57 UTC (permalink / raw)
  To: Weinan Liu, iommu, jgg, joro, suravee.suthikulpanit
  Cc: will, patches, stable, robin.murphy, santosh.shukla, chrisl



On 5/1/2026 4:58 AM, Weinan Liu wrote:
> Bitwise OR | operator has a higher precedence than the ternary ?:
> operatior. It will be incorrectly evaluated as:
> 
> new->data[1] |= (FIELD_PREP(...) | dev_data->ats_enabled) ? DTE_FLAG_IOTLB : 0;
> 
> Wrap the conditional operation in parentheses to enforce the
> correct evaluation order.
> 
> Fixes: 93eee2a49c1b ("iommu/amd: Refactor logic to program the host page table in DTE")
> Signed-off-by: Weinan Liu <wnliu@google.com>
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>

-Vasant

> ---
>  drivers/iommu/amd/iommu.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index 01171361f9bc..ccffbecb15c2 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -2149,7 +2149,8 @@ static void set_dte_passthrough(struct iommu_dev_data *dev_data,
>  	new->data[0] |= DTE_FLAG_TV | DTE_FLAG_IR | DTE_FLAG_IW;
>  
>  	new->data[1] |= FIELD_PREP(DTE_DOMID_MASK, domain->id) |
> -			(dev_data->ats_enabled) ? DTE_FLAG_IOTLB : 0;
> +			(dev_data->ats_enabled ? DTE_FLAG_IOTLB : 0);
> +
>  }
>  
>  static void set_dte_entry(struct amd_iommu *iommu,


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-04  4:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 23:28 [PATCH] iommu/amd: Fix precedence order in set_dte_passthrough() Weinan Liu
2026-05-01  0:00 ` Weinan Liu
2026-05-01  3:01   ` Chris Li
2026-05-04  4:57 ` Vasant Hegde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox