The replacement code of a feature section is put in __ftr_alt_<label>, which is an allocatable section but not an executable one, even though it holds instructions. Mark it with 'x' flag.
The replacement code of a feature section (__ftr_alt_*) is linked inside .text. Collect it in .__ftr_alternates.text instead, placed after the init text. It is never run from where it is linked: it is only copied over the original code at boot. Co-developed-by: Nicholas Piggin <[email protected]> Signed-off-by: Nicholas Piggin <[email protected]> Co-developed-by: Sathvika Vasireddy <[email protected]> Signed-off-by: Sathvika Vasireddy <[email protected]> Signed-off-by: Shivang Upadhyay <[email protected]> --- arch/powerpc/include/asm/feature-fixups.h | 2 +- arch/powerpc/kernel/vmlinux.lds.S | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/asm/feature-fixups.h b/arch/powerpc/include/asm/feature-fixups.h index 756a6c694018..2c1d033cbb85 100644 --- a/arch/powerpc/include/asm/feature-fixups.h +++ b/arch/powerpc/include/asm/feature-fixups.h @@ -32,7 +32,7 @@ #define FTR_SECTION_ELSE_NESTED(label) \ label##2: \ - .pushsection __ftr_alt_##label,"a"; \ + .pushsection __ftr_alt_##label,"ax"; \ .align 2; \ label##3: diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S index 8fc11d6565bf..07f3d6b35a7e 100644 --- a/arch/powerpc/kernel/vmlinux.lds.S +++ b/arch/powerpc/kernel/vmlinux.lds.S @@ -99,8 +99,7 @@ SECTIONS .text : AT(ADDR(.text) - LOAD_OFFSET) { ALIGN_FUNCTION(); #endif - /* careful! __ftr_alt_* sections need to be close to .text */ - *(.text.hot .text.hot.* TEXT_MAIN .text.fixup .text.unlikely .text.unlikely.* .fixup __ftr_alt_* .ref.text); + *(.text.hot .text.hot.* TEXT_MAIN .text.fixup .text.unlikely .text.unlikely.* .fixup .ref.text); *(.tramp.ftrace.text); NOINSTR_TEXT SCHED_TEXT @@ -267,6 +266,10 @@ SECTIONS _einittext = .; } :text + .__ftr_alternates.text : AT(ADDR(.__ftr_alternates.text) - LOAD_OFFSET) { + *(__ftr_alt_*); + } + /* .exit.text is discarded at runtime, not link time, * to deal with references from __bug_table */ -- 2.56.1
