diff mbox series

[v2,1/5] powerpc/code-patching: Remove #ifdef CONFIG_STRICT_KERNEL_RWX

Message ID f67d2a109404d03e8fdf1ea15388c8778337a76b.1669969781.git.christophe.leroy@csgroup.eu (mailing list archive)
State Accepted
Commit 84ecfe6f38ae4ee779ebd97ee173937fff565bf9
Headers show
Series [v2,1/5] powerpc/code-patching: Remove #ifdef CONFIG_STRICT_KERNEL_RWX | expand

Commit Message

Christophe Leroy Dec. 2, 2022, 8:31 a.m. UTC
No need to have one implementation of patch_instruction() for
CONFIG_STRICT_KERNEL_RWX and one for !CONFIG_STRICT_KERNEL_RWX.

In patch_instruction(), call raw_patch_instruction() when
!CONFIG_STRICT_KERNEL_RWX.

In poking_init(), bail out immediately, it will be equivalent
to the weak default implementation.

Everything else is declared static and will be discarded by
GCC when !CONFIG_STRICT_KERNEL_RWX.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
v2 of the series is only a rebase over today's powerpc/next
---
 arch/powerpc/lib/code-patching.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

Comments

Michael Ellerman Dec. 8, 2022, 12:40 p.m. UTC | #1
On Fri, 2 Dec 2022 09:31:39 +0100, Christophe Leroy wrote:
> No need to have one implementation of patch_instruction() for
> CONFIG_STRICT_KERNEL_RWX and one for !CONFIG_STRICT_KERNEL_RWX.
> 
> In patch_instruction(), call raw_patch_instruction() when
> !CONFIG_STRICT_KERNEL_RWX.
> 
> In poking_init(), bail out immediately, it will be equivalent
> to the weak default implementation.
> 
> [...]

Applied to powerpc/next.

[1/5] powerpc/code-patching: Remove #ifdef CONFIG_STRICT_KERNEL_RWX
      https://git.kernel.org/powerpc/c/84ecfe6f38ae4ee779ebd97ee173937fff565bf9
[2/5] powerpc/feature-fixups: Refactor entry fixups patching
      https://git.kernel.org/powerpc/c/6076dc349b1c587c74c37027efff76f0fa4646f4
[3/5] powerpc/feature-fixups: Refactor other fixups patching
      https://git.kernel.org/powerpc/c/3d1dbbca33a9c6dd3aafd4d14aaea9cc310723e1
[4/5] powerpc/feature-fixups: Do not patch init section after init
      https://git.kernel.org/powerpc/c/b988e7797d09379057cf991ae082f9ad7a309a63
[5/5] powerpc/code-patching: Remove protection against patching init addresses after init
      https://git.kernel.org/powerpc/c/6f3a81b60091031c2c14eb2373d1937b027deb46

cheers
diff mbox series

Patch

diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 0c5fdfd4765d..98a7bbfc8f67 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -46,8 +46,6 @@  int raw_patch_instruction(u32 *addr, ppc_inst_t instr)
 	return __patch_instruction(addr, instr, addr);
 }
 
-#ifdef CONFIG_STRICT_KERNEL_RWX
-
 struct patch_context {
 	union {
 		struct vm_struct *area;
@@ -208,6 +206,9 @@  void __init poking_init(void)
 {
 	int ret;
 
+	if (!IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
+		return;
+
 	if (mm_patch_enabled())
 		ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
 					"powerpc/text_poke_mm:online",
@@ -358,7 +359,8 @@  static int do_patch_instruction(u32 *addr, ppc_inst_t instr)
 	 * when text_poke_area is not ready, but we still need
 	 * to allow patching. We just do the plain old patching
 	 */
-	if (!static_branch_likely(&poking_init_done))
+	if (!IS_ENABLED(CONFIG_STRICT_KERNEL_RWX) ||
+	    !static_branch_likely(&poking_init_done))
 		return raw_patch_instruction(addr, instr);
 
 	local_irq_save(flags);
@@ -370,14 +372,6 @@  static int do_patch_instruction(u32 *addr, ppc_inst_t instr)
 
 	return err;
 }
-#else /* !CONFIG_STRICT_KERNEL_RWX */
-
-static int do_patch_instruction(u32 *addr, ppc_inst_t instr)
-{
-	return raw_patch_instruction(addr, instr);
-}
-
-#endif /* CONFIG_STRICT_KERNEL_RWX */
 
 __ro_after_init DEFINE_STATIC_KEY_FALSE(init_mem_is_free);