@@ -117,6 +117,24 @@ void do_feature_fixups(unsigned long value, void *fixup_start, void *fixup_end)
117
117
}
118
118
}
119
119
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
+
120
138
#ifdef CONFIG_PPC_BOOK3S_64
121
139
static int do_patch_entry_fixups (long * start , long * end , unsigned int * instrs ,
122
140
bool do_fallback , void * fallback )
@@ -181,7 +199,7 @@ static void do_stf_entry_barrier_fixups(enum stf_barrier_type types)
181
199
182
200
static void do_stf_exit_barrier_fixups (enum stf_barrier_type types )
183
201
{
184
- unsigned int instrs [6 ], * dest ;
202
+ unsigned int instrs [6 ];
185
203
long * start , * end ;
186
204
int i ;
187
205
@@ -215,18 +233,8 @@ static void do_stf_exit_barrier_fixups(enum stf_barrier_type types)
215
233
instrs [i ++ ] = PPC_RAW_EIEIO () | 0x02000000 ; /* eieio + bit 6 hint */
216
234
}
217
235
218
- for (i = 0 ; start < end ; start ++ , i ++ ) {
219
- dest = (void * )start + * start ;
236
+ i = do_patch_fixups (start , end , instrs , ARRAY_SIZE (instrs ));
220
237
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
- }
230
238
printk (KERN_DEBUG "stf-barrier: patched %d exit locations (%s barrier)\n" , i ,
231
239
(types == STF_BARRIER_NONE ) ? "no" :
232
240
(types == STF_BARRIER_FALLBACK ) ? "fallback" :
@@ -283,7 +291,7 @@ void do_stf_barrier_fixups(enum stf_barrier_type types)
283
291
284
292
void do_uaccess_flush_fixups (enum l1d_flush_type types )
285
293
{
286
- unsigned int instrs [4 ], * dest ;
294
+ unsigned int instrs [4 ];
287
295
long * start , * end ;
288
296
int i ;
289
297
@@ -309,17 +317,7 @@ void do_uaccess_flush_fixups(enum l1d_flush_type types)
309
317
if (types & L1D_FLUSH_MTTRIG )
310
318
instrs [i ++ ] = PPC_RAW_MTSPR (SPRN_TRIG2 , _R0 );
311
319
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 ));
323
321
324
322
printk (KERN_DEBUG "uaccess-flush: patched %d locations (%s flush)\n" , i ,
325
323
(types == L1D_FLUSH_NONE ) ? "no" :
@@ -418,7 +416,7 @@ void do_entry_flush_fixups(enum l1d_flush_type types)
418
416
static int __do_rfi_flush_fixups (void * data )
419
417
{
420
418
enum l1d_flush_type types = * (enum l1d_flush_type * )data ;
421
- unsigned int instrs [3 ], * dest ;
419
+ unsigned int instrs [3 ];
422
420
long * start , * end ;
423
421
int i ;
424
422
@@ -442,15 +440,7 @@ static int __do_rfi_flush_fixups(void *data)
442
440
if (types & L1D_FLUSH_MTTRIG )
443
441
instrs [i ++ ] = PPC_RAW_MTSPR (SPRN_TRIG2 , _R0 );
444
442
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 ));
454
444
455
445
printk (KERN_DEBUG "rfi-flush: patched %d locations (%s flush)\n" , i ,
456
446
(types == L1D_FLUSH_NONE ) ? "no" :
@@ -492,7 +482,7 @@ void do_rfi_flush_fixups(enum l1d_flush_type types)
492
482
493
483
void do_barrier_nospec_fixups_range (bool enable , void * fixup_start , void * fixup_end )
494
484
{
495
- unsigned int instr , * dest ;
485
+ unsigned int instr ;
496
486
long * start , * end ;
497
487
int i ;
498
488
@@ -506,12 +496,7 @@ void do_barrier_nospec_fixups_range(bool enable, void *fixup_start, void *fixup_
506
496
instr = PPC_RAW_ORI (_R31 , _R31 , 0 ); /* speculation barrier */
507
497
}
508
498
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 );
515
500
516
501
printk (KERN_DEBUG "barrier-nospec: patched %d locations\n" , i );
517
502
}
@@ -533,7 +518,7 @@ void do_barrier_nospec_fixups(bool enable)
533
518
#ifdef CONFIG_PPC_E500
534
519
void do_barrier_nospec_fixups_range (bool enable , void * fixup_start , void * fixup_end )
535
520
{
536
- unsigned int instr [2 ], * dest ;
521
+ unsigned int instr [2 ];
537
522
long * start , * end ;
538
523
int i ;
539
524
@@ -549,13 +534,7 @@ void do_barrier_nospec_fixups_range(bool enable, void *fixup_start, void *fixup_
549
534
instr [1 ] = PPC_RAW_SYNC ();
550
535
}
551
536
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 ));
559
538
560
539
printk (KERN_DEBUG "barrier-nospec: patched %d locations\n" , i );
561
540
}
0 commit comments