* [PATCH 0/2] arm64: alternative: Remove optional 'cfg' parameter
@ 2026-09-02 11:32 Mark Rutland
2026-09-02 11:32 ` [PATCH 1/2] arm64: mte-kasan: Use IS_ENABLED() rather than ALTERNATIVE() " Mark Rutland
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Mark Rutland @ 2026-09-02 11:32 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: catalin.marinas, james.morse, mark.rutland, maz, will
These patches remove the optional 'cfg' parameter from alternative
macros.
Use of the 'cfg' parameter is less clear than ifdeffery or IS_ENABLED()
checks, and also doesn't allow the compiler to elide asm() blocks when
'cfg' is not selected, so it's preferable to avoid it.
Mark.
Mark Rutland (2):
arm64: mte-kasan: Use IS_ENABLED() rather than ALTERNATIVE() 'cfg'
parameter
arm64: alternative: Remove 'cfg' parameter
arch/arm64/include/asm/alternative-macros.h | 30 +++++++--------------
arch/arm64/include/asm/mte-kasan.h | 10 ++++---
2 files changed, 16 insertions(+), 24 deletions(-)
--
2.30.2
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 1/2] arm64: mte-kasan: Use IS_ENABLED() rather than ALTERNATIVE() 'cfg' parameter 2026-09-02 11:32 [PATCH 0/2] arm64: alternative: Remove optional 'cfg' parameter Mark Rutland @ 2026-09-02 11:32 ` Mark Rutland 2026-09-22 11:25 ` Vladimir Murzin 2026-09-02 11:32 ` [PATCH 2/2] arm64: alternative: Remove " Mark Rutland 2026-09-23 18:20 ` [PATCH 0/2] arm64: alternative: Remove optional " Catalin Marinas 2 siblings, 1 reply; 6+ messages in thread From: Mark Rutland @ 2026-09-02 11:32 UTC (permalink / raw) To: linux-arm-kernel; +Cc: catalin.marinas, james.morse, mark.rutland, maz, will The ALTERNATIVE() macro accepts an optional 'cfg' parameter, which accepts a CONFIG_* symbol. Where a CONFIG_* symbol is provided, but is not selected, the ALTERNATIVE() macro will expand to nothing. It would be nicer overall to remove the 'cfg' parameter and to have an explicit check for 'cfg' outside of the asm() block. This is clearer to a reader, and permits the compiler to elide the asm() block when 'cfg' is not selected. In the mte-kasan code, replace the usage of the 'cfg' parameter with an explicit IS_ENABLED() check. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: James Morse <james.morse@arm.com> Cc: Marc Zyngier <maz@kernel.org> Cc: Will Deacon <will@kernel.org> --- arch/arm64/include/asm/mte-kasan.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/mte-kasan.h b/arch/arm64/include/asm/mte-kasan.h index 3521392719189..de910f1c19e1b 100644 --- a/arch/arm64/include/asm/mte-kasan.h +++ b/arch/arm64/include/asm/mte-kasan.h @@ -53,14 +53,16 @@ static inline bool system_uses_mte_async_or_asymm_mode(void) */ static inline void mte_disable_tco(void) { - asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(0), - ARM64_MTE, CONFIG_KASAN_HW_TAGS)); + if (!IS_ENABLED(CONFIG_KASAN_HW_TAGS)) + return; + asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(0), ARM64_MTE)); } static inline void mte_enable_tco(void) { - asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(1), - ARM64_MTE, CONFIG_KASAN_HW_TAGS)); + if (!IS_ENABLED(CONFIG_KASAN_HW_TAGS)) + return; + asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(1), ARM64_MTE)); } /* -- 2.30.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] arm64: mte-kasan: Use IS_ENABLED() rather than ALTERNATIVE() 'cfg' parameter 2026-09-02 11:32 ` [PATCH 1/2] arm64: mte-kasan: Use IS_ENABLED() rather than ALTERNATIVE() " Mark Rutland @ 2026-09-22 11:25 ` Vladimir Murzin 0 siblings, 0 replies; 6+ messages in thread From: Vladimir Murzin @ 2026-09-22 11:25 UTC (permalink / raw) To: Mark Rutland, linux-arm-kernel; +Cc: catalin.marinas, james.morse, maz, will On 9/2/26 12:32, Mark Rutland wrote: > The ALTERNATIVE() macro accepts an optional 'cfg' parameter, which > accepts a CONFIG_* symbol. Where a CONFIG_* symbol is provided, but is > not selected, the ALTERNATIVE() macro will expand to nothing. > > It would be nicer overall to remove the 'cfg' parameter and to have an > explicit check for 'cfg' outside of the asm() block. This is clearer to > a reader, and permits the compiler to elide the asm() block when 'cfg' > is not selected. > > In the mte-kasan code, replace the usage of the 'cfg' parameter with an > explicit IS_ENABLED() check. > > Signed-off-by: Mark Rutland <mark.rutland@arm.com> > Cc: Catalin Marinas <catalin.marinas@arm.com> > Cc: James Morse <james.morse@arm.com> > Cc: Marc Zyngier <maz@kernel.org> > Cc: Will Deacon <will@kernel.org> > --- > arch/arm64/include/asm/mte-kasan.h | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/include/asm/mte-kasan.h b/arch/arm64/include/asm/mte-kasan.h > index 3521392719189..de910f1c19e1b 100644 > --- a/arch/arm64/include/asm/mte-kasan.h > +++ b/arch/arm64/include/asm/mte-kasan.h > @@ -53,14 +53,16 @@ static inline bool system_uses_mte_async_or_asymm_mode(void) > */ > static inline void mte_disable_tco(void) > { > - asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(0), > - ARM64_MTE, CONFIG_KASAN_HW_TAGS)); > + if (!IS_ENABLED(CONFIG_KASAN_HW_TAGS)) > + return; > + asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(0), ARM64_MTE)); > } > > static inline void mte_enable_tco(void) > { > - asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(1), > - ARM64_MTE, CONFIG_KASAN_HW_TAGS)); > + if (!IS_ENABLED(CONFIG_KASAN_HW_TAGS)) > + return; > + asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(1), ARM64_MTE)); > } > > /* > -- 2.30.2 > Looks reasonable, FWIW Reviewed-by: Vladimir Murzin <vladimir.murzin@arm.com> ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] arm64: alternative: Remove 'cfg' parameter 2026-09-02 11:32 [PATCH 0/2] arm64: alternative: Remove optional 'cfg' parameter Mark Rutland 2026-09-02 11:32 ` [PATCH 1/2] arm64: mte-kasan: Use IS_ENABLED() rather than ALTERNATIVE() " Mark Rutland @ 2026-09-02 11:32 ` Mark Rutland 2026-09-22 11:34 ` Vladimir Murzin 2026-09-23 18:20 ` [PATCH 0/2] arm64: alternative: Remove optional " Catalin Marinas 2 siblings, 1 reply; 6+ messages in thread From: Mark Rutland @ 2026-09-02 11:32 UTC (permalink / raw) To: linux-arm-kernel; +Cc: catalin.marinas, james.morse, mark.rutland, maz, will There are no remaining users of the 'cfg' parameter for alternative sequences. Remove support for the 'cfg' parameter. In general, it's better to use explicit ifdeffery or IS_ENABLED() checks. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: James Morse <james.morse@arm.com> Cc: Marc Zyngier <maz@kernel.org> Cc: Will Deacon <will@kernel.org> --- arch/arm64/include/asm/alternative-macros.h | 30 +++++++-------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/arch/arm64/include/asm/alternative-macros.h b/arch/arm64/include/asm/alternative-macros.h index 8624166248528..ee75a2f1a575f 100644 --- a/arch/arm64/include/asm/alternative-macros.h +++ b/arch/arm64/include/asm/alternative-macros.h @@ -53,8 +53,7 @@ * * Alternatives with callbacks do not generate replacement instructions. */ -#define __ALTERNATIVE_CFG(oldinstr, newinstr, cpucap, cfg_enabled) \ - ".if "__stringify(cfg_enabled)" == 1\n" \ +#define __ALTERNATIVE(oldinstr, newinstr, cpucap) \ "661:\n\t" \ oldinstr "\n" \ "662:\n" \ @@ -68,10 +67,8 @@ ".org . - (664b-663b) + (662b-661b)\n\t" \ ".org . - (662b-661b) + (664b-663b)\n\t" \ ".previous\n" \ - ".endif\n" -#define __ALTERNATIVE_CFG_CB(oldinstr, cpucap, cfg_enabled, cb) \ - ".if "__stringify(cfg_enabled)" == 1\n" \ +#define __ALTERNATIVE_CB(oldinstr, cpucap, cb) \ "661:\n\t" \ oldinstr "\n" \ "662:\n" \ @@ -80,13 +77,12 @@ ".popsection\n" \ "663:\n\t" \ "664:\n\t" \ - ".endif\n" -#define _ALTERNATIVE_CFG(oldinstr, newinstr, cpucap, cfg, ...) \ - __ALTERNATIVE_CFG(oldinstr, newinstr, cpucap, IS_ENABLED(cfg)) +#define _ALTERNATIVE(oldinstr, newinstr, cpucap) \ + __ALTERNATIVE(oldinstr, newinstr, cpucap) #define ALTERNATIVE_CB(oldinstr, cpucap, cb) \ - __ALTERNATIVE_CFG_CB(oldinstr, (1 << ARM64_CB_SHIFT) | (cpucap), 1, cb) + __ALTERNATIVE_CB(oldinstr, (1 << ARM64_CB_SHIFT) | (cpucap), cb) #else #include <asm/assembler.h> @@ -99,8 +95,7 @@ .byte \alt_len .endm -.macro alternative_insn insn1, insn2, cap, enable = 1 - .if \enable +.macro alternative_insn insn1, insn2, cap 661: \insn1 662: .pushsection .altinstructions, "a" altinstruction_entry 661b, 663f, \cap, 662b-661b, 664f-663f @@ -110,7 +105,6 @@ 664: .org . - (664b-663b) + (662b-661b) .org . - (662b-661b) + (664b-663b) .previous - .endif .endm /* @@ -204,20 +198,16 @@ alternative_else alternative_endif .endm -#define _ALTERNATIVE_CFG(insn1, insn2, cap, cfg, ...) \ - alternative_insn insn1, insn2, cap, IS_ENABLED(cfg) +#define _ALTERNATIVE(insn1, insn2, cap) \ + alternative_insn insn1, insn2, cap #endif /* __ASSEMBLER__ */ /* * Usage: asm(ALTERNATIVE(oldinstr, newinstr, cpucap)); - * - * Usage: asm(ALTERNATIVE(oldinstr, newinstr, cpucap, CONFIG_FOO)); - * N.B. If CONFIG_FOO is specified, but not selected, the whole block - * will be omitted, including oldinstr. */ -#define ALTERNATIVE(oldinstr, newinstr, ...) \ - _ALTERNATIVE_CFG(oldinstr, newinstr, __VA_ARGS__, 1) +#define ALTERNATIVE(oldinstr, newinstr, cpucap) \ + _ALTERNATIVE(oldinstr, newinstr, cpucap) #ifndef __ASSEMBLER__ -- 2.30.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] arm64: alternative: Remove 'cfg' parameter 2026-09-02 11:32 ` [PATCH 2/2] arm64: alternative: Remove " Mark Rutland @ 2026-09-22 11:34 ` Vladimir Murzin 0 siblings, 0 replies; 6+ messages in thread From: Vladimir Murzin @ 2026-09-22 11:34 UTC (permalink / raw) To: Mark Rutland, linux-arm-kernel; +Cc: catalin.marinas, james.morse, maz, will On 9/2/26 12:32, Mark Rutland wrote: > There are no remaining users of the 'cfg' parameter for alternative > sequences. > > Remove support for the 'cfg' parameter. In general, it's better to use > explicit ifdeffery or IS_ENABLED() checks. > > Signed-off-by: Mark Rutland <mark.rutland@arm.com> > Cc: Catalin Marinas <catalin.marinas@arm.com> > Cc: James Morse <james.morse@arm.com> > Cc: Marc Zyngier <maz@kernel.org> > Cc: Will Deacon <will@kernel.org> > --- > arch/arm64/include/asm/alternative-macros.h | 30 +++++++-------------- > 1 file changed, 10 insertions(+), 20 deletions(-) > > diff --git a/arch/arm64/include/asm/alternative-macros.h b/arch/arm64/include/asm/alternative-macros.h > index 8624166248528..ee75a2f1a575f 100644 > --- a/arch/arm64/include/asm/alternative-macros.h > +++ b/arch/arm64/include/asm/alternative-macros.h > @@ -53,8 +53,7 @@ > * > * Alternatives with callbacks do not generate replacement instructions. > */ > -#define __ALTERNATIVE_CFG(oldinstr, newinstr, cpucap, cfg_enabled) \ > - ".if "__stringify(cfg_enabled)" == 1\n" \ > +#define __ALTERNATIVE(oldinstr, newinstr, cpucap) \ > "661:\n\t" \ > oldinstr "\n" \ > "662:\n" \ > @@ -68,10 +67,8 @@ > ".org . - (664b-663b) + (662b-661b)\n\t" \ > ".org . - (662b-661b) + (664b-663b)\n\t" \ > ".previous\n" \ > - ".endif\n" > > -#define __ALTERNATIVE_CFG_CB(oldinstr, cpucap, cfg_enabled, cb) \ > - ".if "__stringify(cfg_enabled)" == 1\n" \ > +#define __ALTERNATIVE_CB(oldinstr, cpucap, cb) \ > "661:\n\t" \ > oldinstr "\n" \ > "662:\n" \ > @@ -80,13 +77,12 @@ > ".popsection\n" \ > "663:\n\t" \ > "664:\n\t" \ > - ".endif\n" > > -#define _ALTERNATIVE_CFG(oldinstr, newinstr, cpucap, cfg, ...) \ > - __ALTERNATIVE_CFG(oldinstr, newinstr, cpucap, IS_ENABLED(cfg)) > +#define _ALTERNATIVE(oldinstr, newinstr, cpucap) \ > + __ALTERNATIVE(oldinstr, newinstr, cpucap) > > #define ALTERNATIVE_CB(oldinstr, cpucap, cb) \ > - __ALTERNATIVE_CFG_CB(oldinstr, (1 << ARM64_CB_SHIFT) | (cpucap), 1, cb) > + __ALTERNATIVE_CB(oldinstr, (1 << ARM64_CB_SHIFT) | (cpucap), cb) > #else > > #include <asm/assembler.h> > @@ -99,8 +95,7 @@ > .byte \alt_len > .endm > > -.macro alternative_insn insn1, insn2, cap, enable = 1 > - .if \enable > +.macro alternative_insn insn1, insn2, cap > 661: \insn1 > 662: .pushsection .altinstructions, "a" > altinstruction_entry 661b, 663f, \cap, 662b-661b, 664f-663f > @@ -110,7 +105,6 @@ > 664: .org . - (664b-663b) + (662b-661b) > .org . - (662b-661b) + (664b-663b) > .previous > - .endif > .endm > > /* > @@ -204,20 +198,16 @@ alternative_else > alternative_endif > .endm > > -#define _ALTERNATIVE_CFG(insn1, insn2, cap, cfg, ...) \ > - alternative_insn insn1, insn2, cap, IS_ENABLED(cfg) > +#define _ALTERNATIVE(insn1, insn2, cap) \ > + alternative_insn insn1, insn2, cap > > #endif /* __ASSEMBLER__ */ > > /* > * Usage: asm(ALTERNATIVE(oldinstr, newinstr, cpucap)); > - * > - * Usage: asm(ALTERNATIVE(oldinstr, newinstr, cpucap, CONFIG_FOO)); > - * N.B. If CONFIG_FOO is specified, but not selected, the whole block > - * will be omitted, including oldinstr. > */ > -#define ALTERNATIVE(oldinstr, newinstr, ...) \ > - _ALTERNATIVE_CFG(oldinstr, newinstr, __VA_ARGS__, 1) > +#define ALTERNATIVE(oldinstr, newinstr, cpucap) \ > + _ALTERNATIVE(oldinstr, newinstr, cpucap) > > #ifndef __ASSEMBLER__ > > -- 2.30.2 > Digging through the history, it looks like the only users of cfg used to be PAN and UAO (modulo MTE from the previous patch), which are either gone (UAO) or have become unconditional (PAN). FWIW, Reviewed-by: Vladimir Murzin <vladimir.murzin@arm.com> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] arm64: alternative: Remove optional 'cfg' parameter 2026-09-02 11:32 [PATCH 0/2] arm64: alternative: Remove optional 'cfg' parameter Mark Rutland 2026-09-02 11:32 ` [PATCH 1/2] arm64: mte-kasan: Use IS_ENABLED() rather than ALTERNATIVE() " Mark Rutland 2026-09-02 11:32 ` [PATCH 2/2] arm64: alternative: Remove " Mark Rutland @ 2026-09-23 18:20 ` Catalin Marinas 2 siblings, 0 replies; 6+ messages in thread From: Catalin Marinas @ 2026-09-23 18:20 UTC (permalink / raw) To: linux-arm-kernel, Mark Rutland; +Cc: Will Deacon, james.morse, maz On Wed, 02 Sep 2026 12:32:30 +0100, Mark Rutland wrote: > These patches remove the optional 'cfg' parameter from alternative > macros. > > Use of the 'cfg' parameter is less clear than ifdeffery or IS_ENABLED() > checks, and also doesn't allow the compiler to elide asm() blocks when > 'cfg' is not selected, so it's preferable to avoid it. > > [...] Applied to arm64 (for-next/misc), thanks! [1/2] arm64: mte-kasan: Use IS_ENABLED() rather than ALTERNATIVE() 'cfg' parameter https://git.kernel.org/arm64/c/228718f6babd [2/2] arm64: alternative: Remove 'cfg' parameter https://git.kernel.org/arm64/c/0406e2e71daf ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-09-23 18:20 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-09-02 11:32 [PATCH 0/2] arm64: alternative: Remove optional 'cfg' parameter Mark Rutland 2026-09-02 11:32 ` [PATCH 1/2] arm64: mte-kasan: Use IS_ENABLED() rather than ALTERNATIVE() " Mark Rutland 2026-09-22 11:25 ` Vladimir Murzin 2026-09-02 11:32 ` [PATCH 2/2] arm64: alternative: Remove " Mark Rutland 2026-09-22 11:34 ` Vladimir Murzin 2026-09-23 18:20 ` [PATCH 0/2] arm64: alternative: Remove optional " Catalin Marinas
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.