Skip to content

Commit b988e77

Browse files
chleroympe
authored andcommitted
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 51c3c62 ("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 <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/8e9311fc1b057e4e6a2a3a0701ebcc74b787affe.1669969781.git.christophe.leroy@csgroup.eu
1 parent 3d1dbbc commit b988e77

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

arch/powerpc/lib/feature-fixups.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ void do_feature_fixups(unsigned long value, void *fixup_start, void *fixup_end)
118118
}
119119

120120
#ifdef CONFIG_PPC_BARRIER_NOSPEC
121+
static bool is_fixup_addr_valid(void *dest, size_t size)
122+
{
123+
return system_state < SYSTEM_FREEING_INITMEM ||
124+
!init_section_contains(dest, size);
125+
}
126+
121127
static int do_patch_fixups(long *start, long *end, unsigned int *instrs, int num)
122128
{
123129
int i;
@@ -126,6 +132,9 @@ static int do_patch_fixups(long *start, long *end, unsigned int *instrs, int num
126132
int j;
127133
unsigned int *dest = (void *)start + *start;
128134

135+
if (!is_fixup_addr_valid(dest, sizeof(*instrs) * num))
136+
continue;
137+
129138
pr_devel("patching dest %lx\n", (unsigned long)dest);
130139

131140
for (j = 0; j < num; j++)
@@ -144,6 +153,9 @@ static int do_patch_entry_fixups(long *start, long *end, unsigned int *instrs,
144153
for (i = 0; start < end; start++, i++) {
145154
unsigned int *dest = (void *)start + *start;
146155

156+
if (!is_fixup_addr_valid(dest, sizeof(*instrs) * 3))
157+
continue;
158+
147159
pr_devel("patching dest %lx\n", (unsigned long)dest);
148160

149161
// See comment in do_entry_flush_fixups() RE order of patching

0 commit comments

Comments
 (0)