@@ -263,6 +263,7 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
263263 struct alt_instr * end )
264264{
265265 struct alt_instr * a ;
266+ u8 * instr , * replacement ;
266267 u8 insnbuf [MAX_PATCH_LEN ];
267268
268269 DPRINTK ("%s: alt table %p -> %p\n" , __func__ , start , end );
@@ -276,25 +277,29 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
276277 * order.
277278 */
278279 for (a = start ; a < end ; a ++ ) {
279- u8 * instr = a -> instr ;
280+ instr = (u8 * )& a -> instr_offset + a -> instr_offset ;
281+ replacement = (u8 * )& a -> repl_offset + a -> repl_offset ;
280282 BUG_ON (a -> replacementlen > a -> instrlen );
281283 BUG_ON (a -> instrlen > sizeof (insnbuf ));
282284 BUG_ON (a -> cpuid >= NCAPINTS * 32 );
283285 if (!boot_cpu_has (a -> cpuid ))
284286 continue ;
287+
288+ memcpy (insnbuf , replacement , a -> replacementlen );
289+
290+ /* 0xe8 is a relative jump; fix the offset. */
291+ if (* insnbuf == 0xe8 && a -> replacementlen == 5 )
292+ * (s32 * )(insnbuf + 1 ) += replacement - instr ;
293+
294+ add_nops (insnbuf + a -> replacementlen ,
295+ a -> instrlen - a -> replacementlen );
296+
285297#ifdef CONFIG_X86_64
286298 /* vsyscall code is not mapped yet. resolve it manually. */
287299 if (instr >= (u8 * )VSYSCALL_START && instr < (u8 * )VSYSCALL_END ) {
288300 instr = __va (instr - (u8 * )VSYSCALL_START + (u8 * )__pa_symbol (& __vsyscall_0 ));
289- DPRINTK ("%s: vsyscall fixup: %p => %p\n" ,
290- __func__ , a -> instr , instr );
291301 }
292302#endif
293- memcpy (insnbuf , a -> replacement , a -> replacementlen );
294- if (* insnbuf == 0xe8 && a -> replacementlen == 5 )
295- * (s32 * )(insnbuf + 1 ) += a -> replacement - a -> instr ;
296- add_nops (insnbuf + a -> replacementlen ,
297- a -> instrlen - a -> replacementlen );
298303 text_poke_early (instr , insnbuf , a -> instrlen );
299304 }
300305}
0 commit comments