* [PATCH 1/2] iommu/arm-smmu-qcom: Use FIELD_MODIFY()
2026-04-30 16:45 [PATCH 0/2] iommu/arm-smmu: Use FIELD_MODIFY() for bitfield operations Hans Zhang
@ 2026-04-30 16:45 ` Hans Zhang
2026-04-30 16:45 ` [PATCH 2/2] iommu/arm-smmu-v3: " Hans Zhang
2026-05-19 10:51 ` [PATCH 0/2] iommu/arm-smmu: Use FIELD_MODIFY() for bitfield operations Will Deacon
2 siblings, 0 replies; 5+ messages in thread
From: Hans Zhang @ 2026-04-30 16:45 UTC (permalink / raw)
To: will, robin.murphy, joro
Cc: iommu, linux-arm-msm, linux-kernel, linux-arm-kernel, Hans Zhang
Use FIELD_MODIFY() to remove open-coded bit manipulation.
No functional change intended.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c
index 65e0ef6539fe..99469c4ebac2 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c
@@ -208,8 +208,7 @@ static phys_addr_t qcom_tbu_trigger_atos(struct arm_smmu_domain *smmu_domain,
/* Set address and stream-id */
val = readq_relaxed(tbu->base + DEBUG_SID_HALT_REG);
- val &= ~DEBUG_SID_HALT_SID;
- val |= FIELD_PREP(DEBUG_SID_HALT_SID, sid);
+ FIELD_MODIFY(DEBUG_SID_HALT_SID, &val, sid);
writeq_relaxed(val, tbu->base + DEBUG_SID_HALT_REG);
writeq_relaxed(iova, tbu->base + DEBUG_VA_ADDR_REG);
val = FIELD_PREP(DEBUG_AXUSER_CDMID, DEBUG_AXUSER_CDMID_VAL);
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] iommu/arm-smmu-v3: Use FIELD_MODIFY()
2026-04-30 16:45 [PATCH 0/2] iommu/arm-smmu: Use FIELD_MODIFY() for bitfield operations Hans Zhang
2026-04-30 16:45 ` [PATCH 1/2] iommu/arm-smmu-qcom: Use FIELD_MODIFY() Hans Zhang
@ 2026-04-30 16:45 ` Hans Zhang
2026-05-19 10:51 ` [PATCH 0/2] iommu/arm-smmu: Use FIELD_MODIFY() for bitfield operations Will Deacon
2 siblings, 0 replies; 5+ messages in thread
From: Hans Zhang @ 2026-04-30 16:45 UTC (permalink / raw)
To: will, robin.murphy, joro
Cc: iommu, linux-arm-msm, linux-kernel, linux-arm-kernel, Hans Zhang
Use FIELD_MODIFY() to remove open-coded bit manipulation.
No functional change intended.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
index ddae0b07c76b..b62e91e4781d 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
@@ -330,8 +330,7 @@ static int arm_vsmmu_convert_user_cmd(struct arm_vsmmu *vsmmu,
case CMDQ_OP_TLBI_NH_VAA:
case CMDQ_OP_TLBI_NH_ALL:
case CMDQ_OP_TLBI_NH_ASID:
- cmd->cmd[0] &= ~CMDQ_TLBI_0_VMID;
- cmd->cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_VMID, vsmmu->vmid);
+ FIELD_MODIFY(CMDQ_TLBI_0_VMID, &cmd->cmd[0], vsmmu->vmid);
break;
case CMDQ_OP_ATC_INV:
case CMDQ_OP_CFGI_CD:
@@ -340,8 +339,7 @@ static int arm_vsmmu_convert_user_cmd(struct arm_vsmmu *vsmmu,
if (arm_vsmmu_vsid_to_sid(vsmmu, vsid, &sid))
return -EIO;
- cmd->cmd[0] &= ~CMDQ_CFGI_0_SID;
- cmd->cmd[0] |= FIELD_PREP(CMDQ_CFGI_0_SID, sid);
+ FIELD_MODIFY(CMDQ_CFGI_0_SID, &cmd->cmd[0], sid);
break;
}
default:
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] iommu/arm-smmu: Use FIELD_MODIFY() for bitfield operations
2026-04-30 16:45 [PATCH 0/2] iommu/arm-smmu: Use FIELD_MODIFY() for bitfield operations Hans Zhang
2026-04-30 16:45 ` [PATCH 1/2] iommu/arm-smmu-qcom: Use FIELD_MODIFY() Hans Zhang
2026-04-30 16:45 ` [PATCH 2/2] iommu/arm-smmu-v3: " Hans Zhang
@ 2026-05-19 10:51 ` Will Deacon
2026-05-19 12:20 ` Hans Zhang
2 siblings, 1 reply; 5+ messages in thread
From: Will Deacon @ 2026-05-19 10:51 UTC (permalink / raw)
To: Hans Zhang
Cc: robin.murphy, joro, iommu, linux-arm-msm, linux-kernel,
linux-arm-kernel
On Fri, May 01, 2026 at 12:45:43AM +0800, Hans Zhang wrote:
> Replace open-coded bitfield modifications with the standard FIELD_MODIFY()
> macro. This improves code readability and adds type/range checking without
> functional changes.
Does it _really_ improve the readability? '&=' and '|=' patterns are
pretty idiomatic C code, if you ask me.
> FIELD_MODIFY() internally performs the same mask-clear + set operation but
> eliminates repetitive boilerplate.
>
> ---
> Hi, If the Maintainers think it's not necessary, please ignore it.
I don't really mind the code either way, so I think I'd prefer to leave
it as-is unless somebody wants to convince me otherwise...
Will
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] iommu/arm-smmu: Use FIELD_MODIFY() for bitfield operations
2026-05-19 10:51 ` [PATCH 0/2] iommu/arm-smmu: Use FIELD_MODIFY() for bitfield operations Will Deacon
@ 2026-05-19 12:20 ` Hans Zhang
0 siblings, 0 replies; 5+ messages in thread
From: Hans Zhang @ 2026-05-19 12:20 UTC (permalink / raw)
To: Will Deacon
Cc: robin.murphy, joro, iommu, linux-arm-msm, linux-kernel,
linux-arm-kernel
On 5/19/26 18:51, Will Deacon wrote:
> On Fri, May 01, 2026 at 12:45:43AM +0800, Hans Zhang wrote:
>> Replace open-coded bitfield modifications with the standard FIELD_MODIFY()
>> macro. This improves code readability and adds type/range checking without
>> functional changes.
>
> Does it _really_ improve the readability? '&=' and '|=' patterns are
> pretty idiomatic C code, if you ask me.
>
>> FIELD_MODIFY() internally performs the same mask-clear + set operation but
>> eliminates repetitive boilerplate.
>>
>> ---
>> Hi, If the Maintainers think it's not necessary, please ignore it.
>
> I don't really mind the code either way, so I think I'd prefer to leave
> it as-is unless somebody wants to convince me otherwise...
>
> Will
Hi Will,
It's not like that. Please take a look at the accepted patch below.
https://lore.kernel.org/linux-pci/20260505165436.GA737933@bhelgaas/
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=42ec65b46a4fc7565d48daa42bf025fdc67800eb
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=5fd6f2154734f447e83b6de9a08d16848605191e
Best regards,
Hans
^ permalink raw reply [flat|nested] 5+ messages in thread