aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorBorislav Petkov <bp@suse.de>2014-12-30 14:27:09 -0500
committerBorislav Petkov <bp@suse.de>2015-02-23 07:35:50 -0500
commitdb477a3386dee183130916d6bbf21f5828b0b2e2 (patch)
treee0ffaf1a29bbe80b905b51f4ce3efcf002c15838 /arch/x86
parent338ea55579d1dbd83753b10db74da747b2f1998f (diff)
x86/alternatives: Cleanup DPRINTK macro
Make it pass __func__ implicitly. Also, dump info about each replacing we're doing. Fixup comments and style while at it. Signed-off-by: Borislav Petkov <bp@suse.de>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/kernel/alternative.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 703130f469ec..1e86e85bcf58 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -52,10 +52,10 @@ static int __init setup_noreplace_paravirt(char *str)
52__setup("noreplace-paravirt", setup_noreplace_paravirt); 52__setup("noreplace-paravirt", setup_noreplace_paravirt);
53#endif 53#endif
54 54
55#define DPRINTK(fmt, ...) \ 55#define DPRINTK(fmt, args...) \
56do { \ 56do { \
57 if (debug_alternative) \ 57 if (debug_alternative) \
58 printk(KERN_DEBUG fmt, ##__VA_ARGS__); \ 58 printk(KERN_DEBUG "%s: " fmt "\n", __func__, ##args); \
59} while (0) 59} while (0)
60 60
61/* 61/*
@@ -243,12 +243,13 @@ extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
243extern s32 __smp_locks[], __smp_locks_end[]; 243extern s32 __smp_locks[], __smp_locks_end[];
244void *text_poke_early(void *addr, const void *opcode, size_t len); 244void *text_poke_early(void *addr, const void *opcode, size_t len);
245 245
246/* Replace instructions with better alternatives for this CPU type. 246/*
247 This runs before SMP is initialized to avoid SMP problems with 247 * Replace instructions with better alternatives for this CPU type. This runs
248 self modifying code. This implies that asymmetric systems where 248 * before SMP is initialized to avoid SMP problems with self modifying code.
249 APs have less capabilities than the boot processor are not handled. 249 * This implies that asymmetric systems where APs have less capabilities than
250 Tough. Make sure you disable such features by hand. */ 250 * the boot processor are not handled. Tough. Make sure you disable such
251 251 * features by hand.
252 */
252void __init_or_module apply_alternatives(struct alt_instr *start, 253void __init_or_module apply_alternatives(struct alt_instr *start,
253 struct alt_instr *end) 254 struct alt_instr *end)
254{ 255{
@@ -256,10 +257,10 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
256 u8 *instr, *replacement; 257 u8 *instr, *replacement;
257 u8 insnbuf[MAX_PATCH_LEN]; 258 u8 insnbuf[MAX_PATCH_LEN];
258 259
259 DPRINTK("%s: alt table %p -> %p\n", __func__, start, end); 260 DPRINTK("alt table %p -> %p", start, end);
260 /* 261 /*
261 * The scan order should be from start to end. A later scanned 262 * The scan order should be from start to end. A later scanned
262 * alternative code can overwrite a previous scanned alternative code. 263 * alternative code can overwrite previously scanned alternative code.
263 * Some kernel functions (e.g. memcpy, memset, etc) use this order to 264 * Some kernel functions (e.g. memcpy, memset, etc) use this order to
264 * patch code. 265 * patch code.
265 * 266 *
@@ -275,11 +276,19 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
275 if (!boot_cpu_has(a->cpuid)) 276 if (!boot_cpu_has(a->cpuid))
276 continue; 277 continue;
277 278
279 DPRINTK("feat: %d*32+%d, old: (%p, len: %d), repl: (%p, len: %d)",
280 a->cpuid >> 5,
281 a->cpuid & 0x1f,
282 instr, a->instrlen,
283 replacement, a->replacementlen);
284
278 memcpy(insnbuf, replacement, a->replacementlen); 285 memcpy(insnbuf, replacement, a->replacementlen);
279 286
280 /* 0xe8 is a relative jump; fix the offset. */ 287 /* 0xe8 is a relative jump; fix the offset. */
281 if (*insnbuf == 0xe8 && a->replacementlen == 5) 288 if (*insnbuf == 0xe8 && a->replacementlen == 5) {
282 *(s32 *)(insnbuf + 1) += replacement - instr; 289 *(s32 *)(insnbuf + 1) += replacement - instr;
290 DPRINTK("Fix CALL offset: 0x%x", *(s32 *)(insnbuf + 1));
291 }
283 292
284 add_nops(insnbuf + a->replacementlen, 293 add_nops(insnbuf + a->replacementlen,
285 a->instrlen - a->replacementlen); 294 a->instrlen - a->replacementlen);
@@ -371,8 +380,8 @@ void __init_or_module alternatives_smp_module_add(struct module *mod,
371 smp->locks_end = locks_end; 380 smp->locks_end = locks_end;
372 smp->text = text; 381 smp->text = text;
373 smp->text_end = text_end; 382 smp->text_end = text_end;
374 DPRINTK("%s: locks %p -> %p, text %p -> %p, name %s\n", 383 DPRINTK("locks %p -> %p, text %p -> %p, name %s\n",
375 __func__, smp->locks, smp->locks_end, 384 smp->locks, smp->locks_end,
376 smp->text, smp->text_end, smp->name); 385 smp->text, smp->text_end, smp->name);
377 386
378 list_add_tail(&smp->next, &smp_alt_modules); 387 list_add_tail(&smp->next, &smp_alt_modules);