Skip to content

Commit 3d1dbbc

Browse files
chleroympe
authored andcommitted
powerpc/feature-fixups: Refactor other fixups patching
Several fonctions have the same loop for patching instructions. Introduce function do_patch_fixups() to refactor those loops. Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/58ab36949c18f94d466fc98d6c085783b0cd474f.1669969781.git.christophe.leroy@csgroup.eu
1 parent 6076dc3 commit 3d1dbbc

File tree

1 file changed

+28
-49
lines changed

1 file changed

+28
-49
lines changed

arch/powerpc/lib/feature-fixups.c

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ void do_feature_fixups(unsigned long value, void *fixup_start, void *fixup_end)
117117
}
118118
}
119119

120+
#ifdef CONFIG_PPC_BARRIER_NOSPEC
121+
static int do_patch_fixups(long *start, long *end, unsigned int *instrs, int num)
122+
{
123+
int i;
124+
125+
for (i = 0; start < end; start++, i++) {
126+
int j;
127+
unsigned int *dest = (void *)start + *start;
128+
129+
pr_devel("patching dest %lx\n", (unsigned long)dest);
130+
131+
for (j = 0; j < num; j++)
132+
patch_instruction(dest + j, ppc_inst(instrs[j]));
133+
}
134+
return i;
135+
}
136+
#endif
137+
120138
#ifdef CONFIG_PPC_BOOK3S_64
121139
static int do_patch_entry_fixups(long *start, long *end, unsigned int *instrs,
122140
bool do_fallback, void *fallback)
@@ -181,7 +199,7 @@ static void do_stf_entry_barrier_fixups(enum stf_barrier_type types)
181199

182200
static void do_stf_exit_barrier_fixups(enum stf_barrier_type types)
183201
{
184-
unsigned int instrs[6], *dest;
202+
unsigned int instrs[6];
185203
long *start, *end;
186204
int i;
187205

@@ -215,18 +233,8 @@ static void do_stf_exit_barrier_fixups(enum stf_barrier_type types)
215233
instrs[i++] = PPC_RAW_EIEIO() | 0x02000000; /* eieio + bit 6 hint */
216234
}
217235

218-
for (i = 0; start < end; start++, i++) {
219-
dest = (void *)start + *start;
236+
i = do_patch_fixups(start, end, instrs, ARRAY_SIZE(instrs));
220237

221-
pr_devel("patching dest %lx\n", (unsigned long)dest);
222-
223-
patch_instruction(dest, ppc_inst(instrs[0]));
224-
patch_instruction(dest + 1, ppc_inst(instrs[1]));
225-
patch_instruction(dest + 2, ppc_inst(instrs[2]));
226-
patch_instruction(dest + 3, ppc_inst(instrs[3]));
227-
patch_instruction(dest + 4, ppc_inst(instrs[4]));
228-
patch_instruction(dest + 5, ppc_inst(instrs[5]));
229-
}
230238
printk(KERN_DEBUG "stf-barrier: patched %d exit locations (%s barrier)\n", i,
231239
(types == STF_BARRIER_NONE) ? "no" :
232240
(types == STF_BARRIER_FALLBACK) ? "fallback" :
@@ -283,7 +291,7 @@ void do_stf_barrier_fixups(enum stf_barrier_type types)
283291

284292
void do_uaccess_flush_fixups(enum l1d_flush_type types)
285293
{
286-
unsigned int instrs[4], *dest;
294+
unsigned int instrs[4];
287295
long *start, *end;
288296
int i;
289297

@@ -309,17 +317,7 @@ void do_uaccess_flush_fixups(enum l1d_flush_type types)
309317
if (types & L1D_FLUSH_MTTRIG)
310318
instrs[i++] = PPC_RAW_MTSPR(SPRN_TRIG2, _R0);
311319

312-
for (i = 0; start < end; start++, i++) {
313-
dest = (void *)start + *start;
314-
315-
pr_devel("patching dest %lx\n", (unsigned long)dest);
316-
317-
patch_instruction(dest, ppc_inst(instrs[0]));
318-
319-
patch_instruction(dest + 1, ppc_inst(instrs[1]));
320-
patch_instruction(dest + 2, ppc_inst(instrs[2]));
321-
patch_instruction(dest + 3, ppc_inst(instrs[3]));
322-
}
320+
i = do_patch_fixups(start, end, instrs, ARRAY_SIZE(instrs));
323321

324322
printk(KERN_DEBUG "uaccess-flush: patched %d locations (%s flush)\n", i,
325323
(types == L1D_FLUSH_NONE) ? "no" :
@@ -418,7 +416,7 @@ void do_entry_flush_fixups(enum l1d_flush_type types)
418416
static int __do_rfi_flush_fixups(void *data)
419417
{
420418
enum l1d_flush_type types = *(enum l1d_flush_type *)data;
421-
unsigned int instrs[3], *dest;
419+
unsigned int instrs[3];
422420
long *start, *end;
423421
int i;
424422

@@ -442,15 +440,7 @@ static int __do_rfi_flush_fixups(void *data)
442440
if (types & L1D_FLUSH_MTTRIG)
443441
instrs[i++] = PPC_RAW_MTSPR(SPRN_TRIG2, _R0);
444442

445-
for (i = 0; start < end; start++, i++) {
446-
dest = (void *)start + *start;
447-
448-
pr_devel("patching dest %lx\n", (unsigned long)dest);
449-
450-
patch_instruction(dest, ppc_inst(instrs[0]));
451-
patch_instruction(dest + 1, ppc_inst(instrs[1]));
452-
patch_instruction(dest + 2, ppc_inst(instrs[2]));
453-
}
443+
i = do_patch_fixups(start, end, instrs, ARRAY_SIZE(instrs));
454444

455445
printk(KERN_DEBUG "rfi-flush: patched %d locations (%s flush)\n", i,
456446
(types == L1D_FLUSH_NONE) ? "no" :
@@ -492,7 +482,7 @@ void do_rfi_flush_fixups(enum l1d_flush_type types)
492482

493483
void do_barrier_nospec_fixups_range(bool enable, void *fixup_start, void *fixup_end)
494484
{
495-
unsigned int instr, *dest;
485+
unsigned int instr;
496486
long *start, *end;
497487
int i;
498488

@@ -506,12 +496,7 @@ void do_barrier_nospec_fixups_range(bool enable, void *fixup_start, void *fixup_
506496
instr = PPC_RAW_ORI(_R31, _R31, 0); /* speculation barrier */
507497
}
508498

509-
for (i = 0; start < end; start++, i++) {
510-
dest = (void *)start + *start;
511-
512-
pr_devel("patching dest %lx\n", (unsigned long)dest);
513-
patch_instruction(dest, ppc_inst(instr));
514-
}
499+
i = do_patch_fixups(start, end, &instr, 1);
515500

516501
printk(KERN_DEBUG "barrier-nospec: patched %d locations\n", i);
517502
}
@@ -533,7 +518,7 @@ void do_barrier_nospec_fixups(bool enable)
533518
#ifdef CONFIG_PPC_E500
534519
void do_barrier_nospec_fixups_range(bool enable, void *fixup_start, void *fixup_end)
535520
{
536-
unsigned int instr[2], *dest;
521+
unsigned int instr[2];
537522
long *start, *end;
538523
int i;
539524

@@ -549,13 +534,7 @@ void do_barrier_nospec_fixups_range(bool enable, void *fixup_start, void *fixup_
549534
instr[1] = PPC_RAW_SYNC();
550535
}
551536

552-
for (i = 0; start < end; start++, i++) {
553-
dest = (void *)start + *start;
554-
555-
pr_devel("patching dest %lx\n", (unsigned long)dest);
556-
patch_instruction(dest, ppc_inst(instr[0]));
557-
patch_instruction(dest + 1, ppc_inst(instr[1]));
558-
}
537+
i = do_patch_fixups(start, end, instr, ARRAY_SIZE(instr));
559538

560539
printk(KERN_DEBUG "barrier-nospec: patched %d locations\n", i);
561540
}

0 commit comments

Comments
 (0)