summaryrefslogtreecommitdiffstats
path: root/arch/powerpc/lib
diff options
context:
space:
mode:
authorChristophe Leroy <christophe.leroy@csgroup.eu>2022-12-02 09:31:42 +0100
committerMichael Ellerman <mpe@ellerman.id.au>2022-12-02 21:59:57 +1100
commitb988e7797d09379057cf991ae082f9ad7a309a63 (patch)
treeee80cecd3e52021109a0bed6f09b1a4fe200b926 /arch/powerpc/lib
parent3d1dbbca33a9c6dd3aafd4d14aaea9cc310723e1 (diff)
downloadlinux-b988e7797d09379057cf991ae082f9ad7a309a63.tar.gz
linux-b988e7797d09379057cf991ae082f9ad7a309a63.tar.bz2
linux-b988e7797d09379057cf991ae082f9ad7a309a63.zip
powerpc/feature-fixups: Do not patch init section after init
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. In the same spirit as jump_label with its jump_label_can_update() function, add is_fixup_addr_valid() function to skip patching on freed init section. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/8e9311fc1b057e4e6a2a3a0701ebcc74b787affe.1669969781.git.christophe.leroy@csgroup.eu
Diffstat (limited to 'arch/powerpc/lib')
-rw-r--r--arch/powerpc/lib/feature-fixups.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c
index 25168a59d1ce..80def1c2afcb 100644
--- a/arch/powerpc/lib/feature-fixups.c
+++ b/arch/powerpc/lib/feature-fixups.c
@@ -118,6 +118,12 @@ void do_feature_fixups(unsigned long value, void *fixup_start, void *fixup_end)
}
#ifdef CONFIG_PPC_BARRIER_NOSPEC
+static bool is_fixup_addr_valid(void *dest, size_t size)
+{
+ return system_state < SYSTEM_FREEING_INITMEM ||
+ !init_section_contains(dest, size);
+}
+
static int do_patch_fixups(long *start, long *end, unsigned int *instrs, int num)
{
int i;
@@ -126,6 +132,9 @@ static int do_patch_fixups(long *start, long *end, unsigned int *instrs, int num
int j;
unsigned int *dest = (void *)start + *start;
+ if (!is_fixup_addr_valid(dest, sizeof(*instrs) * num))
+ continue;
+
pr_devel("patching dest %lx\n", (unsigned long)dest);
for (j = 0; j < num; j++)
@@ -144,6 +153,9 @@ static int do_patch_entry_fixups(long *start, long *end, unsigned int *instrs,
for (i = 0; start < end; start++, i++) {
unsigned int *dest = (void *)start + *start;
+ if (!is_fixup_addr_valid(dest, sizeof(*instrs) * 3))
+ continue;
+
pr_devel("patching dest %lx\n", (unsigned long)dest);
// See comment in do_entry_flush_fixups() RE order of patching