Replaced below code with the wrapper FIELD_MODIFY(MASK, ®, val)
- reg &= ~MASK;
- reg |= FIELD_PREP(MASK, val);
The semantic patch that makes this change is available
in scripts/coccinelle/misc/field_modify.cocci.
More information about semantic patching is available at
https://coccinelle.gitlabpages.inria.fr/website
Signed-off-by: Luo Jie <quic_luoj@quicinc.com>
---
arch/arm64/include/asm/tlbflush.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h
index eba1a98657f1..0d250ef4161c 100644
--- a/arch/arm64/include/asm/tlbflush.h
+++ b/arch/arm64/include/asm/tlbflush.h
@@ -112,8 +112,7 @@ static inline unsigned long get_trans_granule(void)
level >= 0 && level <= 3) { \
u64 ttl = level & 3; \
ttl |= get_trans_granule() << 2; \
- arg &= ~TLBI_TTL_MASK; \
- arg |= FIELD_PREP(TLBI_TTL_MASK, ttl); \
+ FIELD_MODIFY(TLBI_TTL_MASK, &arg, ttl); \
} \
\
__tlbi(op, arg); \
--
2.34.1
On Thu, Apr 17, 2025 at 06:47:10PM +0800, Luo Jie wrote:
> Replaced below code with the wrapper FIELD_MODIFY(MASK, ®, val)
> - reg &= ~MASK;
> - reg |= FIELD_PREP(MASK, val);
> The semantic patch that makes this change is available
> in scripts/coccinelle/misc/field_modify.cocci.
>
> More information about semantic patching is available at
> https://coccinelle.gitlabpages.inria.fr/website
>
> Signed-off-by: Luo Jie <quic_luoj@quicinc.com>
> ---
> arch/arm64/include/asm/tlbflush.h | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h
> index eba1a98657f1..0d250ef4161c 100644
> --- a/arch/arm64/include/asm/tlbflush.h
> +++ b/arch/arm64/include/asm/tlbflush.h
> @@ -112,8 +112,7 @@ static inline unsigned long get_trans_granule(void)
> level >= 0 && level <= 3) { \
> u64 ttl = level & 3; \
> ttl |= get_trans_granule() << 2; \
> - arg &= ~TLBI_TTL_MASK; \
> - arg |= FIELD_PREP(TLBI_TTL_MASK, ttl); \
> + FIELD_MODIFY(TLBI_TTL_MASK, &arg, ttl); \
This could equally be:
arg = u64_replace_bits(arg, ttl, TLBI_TTL_MASK);
which already exists, so doesn't require a new macro to be introduced.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
> -----Original Message-----
> From: cocci-request@inria.fr <cocci-request@inria.fr> On Behalf Of Russell King
> (Oracle)
> Sent: Thursday, April 17, 2025 11:11 AM
> To: Luo Jie <quic_luoj@quicinc.com>
> Cc: Yury Norov <yury.norov@gmail.com>; Rasmus Villemoes
> <linux@rasmusvillemoes.dk>; Julia Lawall <Julia.Lawall@inria.fr>; Nicolas Palix
> <nicolas.palix@imag.fr>; Catalin Marinas <catalin.marinas@arm.com>; Will
> Deacon <will@kernel.org>; Marc Zyngier <maz@kernel.org>; Oliver Upton
> <oliver.upton@linux.dev>; Joey Gouly <joey.gouly@arm.com>; Suzuki K Poulose
> <suzuki.poulose@arm.com>; Zenghui Yu <yuzenghui@huawei.com>; linux-
> kernel@vger.kernel.org; cocci@inria.fr; linux-arm-kernel@lists.infradead.org;
> kvmarm@lists.linux.dev; andrew@lunn.ch; quic_kkumarcs@quicinc.com;
> quic_linchen@quicinc.com; quic_leiwei@quicinc.com;
> quic_suruchia@quicinc.com; quic_pavir@quicinc.com
> Subject: Re: [cocci] [PATCH v3 3/6] arm64: tlb: Convert the opencoded field
> modify
>
> On Thu, Apr 17, 2025 at 06:47:10PM +0800, Luo Jie wrote:
> > Replaced below code with the wrapper FIELD_MODIFY(MASK, ®, val)
> > - reg &= ~MASK;
> > - reg |= FIELD_PREP(MASK, val);
> > The semantic patch that makes this change is available
> > in scripts/coccinelle/misc/field_modify.cocci.
> >
> > More information about semantic patching is available at
> > https://coccinelle.gitlabpages.inria.fr/website
> >
> > Signed-off-by: Luo Jie <quic_luoj@quicinc.com>
> > ---
> > arch/arm64/include/asm/tlbflush.h | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/arch/arm64/include/asm/tlbflush.h
> b/arch/arm64/include/asm/tlbflush.h
> > index eba1a98657f1..0d250ef4161c 100644
> > --- a/arch/arm64/include/asm/tlbflush.h
> > +++ b/arch/arm64/include/asm/tlbflush.h
> > @@ -112,8 +112,7 @@ static inline unsigned long get_trans_granule(void)
> > level >= 0 && level <= 3) { \
> > u64 ttl = level & 3; \
> > ttl |= get_trans_granule() << 2; \
> > - arg &= ~TLBI_TTL_MASK; \
> > - arg |= FIELD_PREP(TLBI_TTL_MASK, ttl); \
> > + FIELD_MODIFY(TLBI_TTL_MASK, &arg, ttl); \
>
> This could equally be:
> arg = u64_replace_bits(arg, ttl, TLBI_TTL_MASK);
>
> which already exists, so doesn't require a new macro to be introduced.
>
I had been looking for something like this the other day but was grepping for "FIELD_REPLACE" and similar which didn't find things.. Neat to know it exists already :D
> --
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
On 4/18/2025 2:11 AM, Russell King (Oracle) wrote:
> On Thu, Apr 17, 2025 at 06:47:10PM +0800, Luo Jie wrote:
>> Replaced below code with the wrapper FIELD_MODIFY(MASK, ®, val)
>> - reg &= ~MASK;
>> - reg |= FIELD_PREP(MASK, val);
>> The semantic patch that makes this change is available
>> in scripts/coccinelle/misc/field_modify.cocci.
>>
>> More information about semantic patching is available at
>> https://coccinelle.gitlabpages.inria.fr/website
>>
>> Signed-off-by: Luo Jie <quic_luoj@quicinc.com>
>> ---
>> arch/arm64/include/asm/tlbflush.h | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h
>> index eba1a98657f1..0d250ef4161c 100644
>> --- a/arch/arm64/include/asm/tlbflush.h
>> +++ b/arch/arm64/include/asm/tlbflush.h
>> @@ -112,8 +112,7 @@ static inline unsigned long get_trans_granule(void)
>> level >= 0 && level <= 3) { \
>> u64 ttl = level & 3; \
>> ttl |= get_trans_granule() << 2; \
>> - arg &= ~TLBI_TTL_MASK; \
>> - arg |= FIELD_PREP(TLBI_TTL_MASK, ttl); \
>> + FIELD_MODIFY(TLBI_TTL_MASK, &arg, ttl); \
>
> This could equally be:
> arg = u64_replace_bits(arg, ttl, TLBI_TTL_MASK);
>
> which already exists, so doesn't require a new macro to be introduced.
>
Looks like the new macro FIELD_MODIFY() is accepted by Yury, maybe we
can keep to use FIELD_MODIFY() with this change for better readability?
> -----Original Message-----
> From: cocci-request@inria.fr <cocci-request@inria.fr> On Behalf Of Jie Luo
> Sent: Wednesday, April 23, 2025 6:16 AM
> To: Russell King (Oracle) <linux@armlinux.org.uk>
> Cc: Yury Norov <yury.norov@gmail.com>; Rasmus Villemoes
> <linux@rasmusvillemoes.dk>; Julia Lawall <Julia.Lawall@inria.fr>; Nicolas Palix
> <nicolas.palix@imag.fr>; Catalin Marinas <catalin.marinas@arm.com>; Will
> Deacon <will@kernel.org>; Marc Zyngier <maz@kernel.org>; Oliver Upton
> <oliver.upton@linux.dev>; Joey Gouly <joey.gouly@arm.com>; Suzuki K Poulose
> <suzuki.poulose@arm.com>; Zenghui Yu <yuzenghui@huawei.com>; linux-
> kernel@vger.kernel.org; cocci@inria.fr; linux-arm-kernel@lists.infradead.org;
> kvmarm@lists.linux.dev; andrew@lunn.ch; quic_kkumarcs@quicinc.com;
> quic_linchen@quicinc.com; quic_leiwei@quicinc.com;
> quic_suruchia@quicinc.com; quic_pavir@quicinc.com
> Subject: Re: [cocci] [PATCH v3 3/6] arm64: tlb: Convert the opencoded field
> modify
>
>
>
> On 4/18/2025 2:11 AM, Russell King (Oracle) wrote:
> > On Thu, Apr 17, 2025 at 06:47:10PM +0800, Luo Jie wrote:
> >> Replaced below code with the wrapper FIELD_MODIFY(MASK, ®, val)
> >> - reg &= ~MASK;
> >> - reg |= FIELD_PREP(MASK, val);
> >> The semantic patch that makes this change is available
> >> in scripts/coccinelle/misc/field_modify.cocci.
> >>
> >> More information about semantic patching is available at
> >> https://coccinelle.gitlabpages.inria.fr/website
> >>
> >> Signed-off-by: Luo Jie <quic_luoj@quicinc.com>
> >> ---
> >> arch/arm64/include/asm/tlbflush.h | 3 +--
> >> 1 file changed, 1 insertion(+), 2 deletions(-)
> >>
> >> diff --git a/arch/arm64/include/asm/tlbflush.h
> b/arch/arm64/include/asm/tlbflush.h
> >> index eba1a98657f1..0d250ef4161c 100644
> >> --- a/arch/arm64/include/asm/tlbflush.h
> >> +++ b/arch/arm64/include/asm/tlbflush.h
> >> @@ -112,8 +112,7 @@ static inline unsigned long get_trans_granule(void)
> >> level >= 0 && level <= 3) { \
> >> u64 ttl = level & 3; \
> >> ttl |= get_trans_granule() << 2; \
> >> - arg &= ~TLBI_TTL_MASK; \
> >> - arg |= FIELD_PREP(TLBI_TTL_MASK, ttl); \
> >> + FIELD_MODIFY(TLBI_TTL_MASK, &arg, ttl); \
> >
> > This could equally be:
> > arg = u64_replace_bits(arg, ttl, TLBI_TTL_MASK);
> >
> > which already exists, so doesn't require a new macro to be introduced.
> >
> Looks like the new macro FIELD_MODIFY() is accepted by Yury, maybe we
> can keep to use FIELD_MODIFY() with this change for better readability?
I'd prefer this version too rather than a pointer that modifies in place. Feels like it fits better with the other FIELD macros which don't take pointers and return their bits by value.
© 2016 - 2025 Red Hat, Inc.