[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <6acb94d4762b788abff8619a7f392a1041db6220.1664289176.git.christophe.leroy@csgroup.eu>
Date: Tue, 27 Sep 2022 16:33:10 +0200
From: Christophe Leroy <christophe.leroy@...roup.eu>
To: Benjamin Gray <bgray@...ux.ibm.com>,
Michael Ellerman <mpe@...erman.id.au>,
Nicholas Piggin <npiggin@...il.com>
Cc: Christophe Leroy <christophe.leroy@...roup.eu>,
linux-kernel@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org
Subject: [PATCH v1 5/6] 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@...roup.eu>
---
arch/powerpc/lib/feature-fixups.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c
index a03ed9931224..1d4342dc4b8d 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
--
2.37.1
Powered by blists - more mailing lists