From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Benjamin Gray <bgray@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH v1 6/6] powerpc/code-patching: Remove protection against patching init addresses after init
Date: Tue, 27 Sep 2022 16:33:11 +0200 [thread overview]
Message-ID: <0df84a2eea551c1d000c34c36d0c1d23cbe26a97.1664289176.git.christophe.leroy@csgroup.eu> (raw)
In-Reply-To: <b0aac2127d30c32e5742e978045c5793667bb7ce.1664289176.git.christophe.leroy@csgroup.eu>
Once init section is freed, attempting to patch init code
ends up in the weed.
Commit 51c3c62b58b3 ("powerpc: Avoid code patching freed init sections")
protected patch_instruction() against that, but it is the responsibility
of the caller to ensure that the patched memory is valid.
All callers have now been verified and fixed so the check
can be removed.
This improves ftrace activation by about 2% on 8xx.
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
arch/powerpc/include/asm/code-patching.h | 2 --
arch/powerpc/lib/code-patching.c | 13 +------------
arch/powerpc/mm/mem.c | 1 -
3 files changed, 1 insertion(+), 15 deletions(-)
diff --git a/arch/powerpc/include/asm/code-patching.h b/arch/powerpc/include/asm/code-patching.h
index 1c6316ec4b74..3f881548fb61 100644
--- a/arch/powerpc/include/asm/code-patching.h
+++ b/arch/powerpc/include/asm/code-patching.h
@@ -22,8 +22,6 @@
#define BRANCH_SET_LINK 0x1
#define BRANCH_ABSOLUTE 0x2
-DECLARE_STATIC_KEY_FALSE(init_mem_is_free);
-
/*
* Powerpc branch instruction is :
*
diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 647a0bb35848..125c55e3e148 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -174,7 +174,7 @@ static int __do_patch_instruction(u32 *addr, ppc_inst_t instr)
return err;
}
-static int do_patch_instruction(u32 *addr, ppc_inst_t instr)
+int patch_instruction(u32 *addr, ppc_inst_t instr)
{
int err;
unsigned long flags;
@@ -194,17 +194,6 @@ static int do_patch_instruction(u32 *addr, ppc_inst_t instr)
return err;
}
-
-__ro_after_init DEFINE_STATIC_KEY_FALSE(init_mem_is_free);
-
-int patch_instruction(u32 *addr, ppc_inst_t instr)
-{
- /* Make sure we aren't patching a freed init section */
- if (static_branch_likely(&init_mem_is_free) && init_section_contains(addr, 4))
- return 0;
-
- return do_patch_instruction(addr, instr);
-}
NOKPROBE_SYMBOL(patch_instruction);
int patch_branch(u32 *addr, unsigned long target, int flags)
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 01772e79fd93..fb89883e97bd 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -344,7 +344,6 @@ void free_initmem(void)
{
ppc_md.progress = ppc_printk_progress;
mark_initmem_nx();
- static_branch_enable(&init_mem_is_free);
free_initmem_default(POISON_FREE_INITMEM);
ftrace_free_init_tramp();
}
--
2.37.1
next prev parent reply other threads:[~2022-09-27 14:37 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-22 15:40 [PATCH v1 0/4] Kill the time spent in patch_instruction() Christophe Leroy
2022-03-22 15:40 ` [PATCH v1 1/4] powerpc/code-patching: Don't call is_vmalloc_or_module_addr() without CONFIG_MODULES Christophe Leroy
2022-09-27 14:33 ` Christophe Leroy
2022-03-22 15:40 ` [PATCH v1 2/4] powerpc/code-patching: Speed up page mapping/unmapping Christophe Leroy
2022-09-27 14:33 ` Christophe Leroy
2022-03-22 15:40 ` [PATCH v1 3/4] powerpc/code-patching: Use jump_label for testing freed initmem Christophe Leroy
2022-05-19 2:17 ` Guenter Roeck
2022-05-19 6:27 ` Christophe Leroy
2022-05-19 6:53 ` Christophe Leroy
2022-05-19 17:27 ` Christophe Leroy
2022-09-27 14:33 ` Christophe Leroy
2022-03-22 15:40 ` [PATCH v1 4/4] powerpc/code-patching: Use jump_label to check if poking_init() is done Christophe Leroy
2022-09-27 14:33 ` Christophe Leroy
2022-05-15 10:28 ` [PATCH v1 0/4] Kill the time spent in patch_instruction() Michael Ellerman
2022-05-17 6:44 ` Christophe Leroy
2022-05-17 12:37 ` Michael Ellerman
2022-05-31 6:24 ` Christophe Leroy
2022-06-24 7:06 ` Christophe Leroy
2022-09-27 14:33 ` Christophe Leroy
2022-09-27 14:33 ` [PATCH v1 1/6] powerpc/code-patching: Use pte_offset_kernel() instead of virt_to_kpte() Christophe Leroy
2022-09-27 14:33 ` [PATCH v1 2/6] powerpc/code-patching: Remove #ifdef CONFIG_STRICT_KERNEL_RWX Christophe Leroy
2022-09-27 14:33 ` [PATCH v1 3/6] powerpc/feature-fixups: Refactor entry fixups patching Christophe Leroy
2022-09-27 14:33 ` [PATCH v1 4/6] powerpc/feature-fixups: Refactor other " Christophe Leroy
2022-09-27 14:33 ` [PATCH v1 5/6] powerpc/feature-fixups: Do not patch init section after init Christophe Leroy
2022-09-27 14:33 ` Christophe Leroy [this message]
2022-09-27 14:38 ` [PATCH v1 0/4] Kill the time spent in patch_instruction() Christophe Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0df84a2eea551c1d000c34c36d0c1d23cbe26a97.1664289176.git.christophe.leroy@csgroup.eu \
--to=christophe.leroy@csgroup.eu \
--cc=bgray@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).