Skip to contentSkip to conversation

iommu/amd: Fix precedence order in set_dte_passthrough()

PATCH In review Weinan Liu 3 participants 3 messages Apr 30 – May 4

Subsystems (2)
lore
Share & tools
lore

Weinan Liu

author
#0 lore raw

PATCH 1/1 iommu/amd: Fix precedence order in set_dte_passthrough()

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")
---
 drivers/iommu/amd/iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/amd/iommu.c +2 -1
index 01171361f9bc..ccffbecb15c2 100644
@@ -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,
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · 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;

Quoted 8 lines

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")
---
 drivers/iommu/amd/iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

This should go to rc

Jason

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Weinan Liu
Quoted 10 lines · 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")

-Vasant