| From: Borislav Petkov <bp@suse.de> |
| Date: Tue, 30 Dec 2014 20:27:09 +0100 |
| Subject: x86/alternatives: Cleanup DPRINTK macro |
| |
| commit db477a3386dee183130916d6bbf21f5828b0b2e2 upstream. |
| |
| 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> |
| Signed-off-by: Hugh Dickins <hughd@google.com> |
| [bwh: Update one more use of DPRINTK() that was removed upstream] |
| Signed-off-by: Ben Hutchings <ben@decadent.org.uk> |
| --- |
| arch/x86/kernel/alternative.c | 42 +++++++++++++++++++++++++++--------------- |
| 1 file changed, 27 insertions(+), 15 deletions(-) |
| |
| diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c |
| index bda833c5f6ce..bd7bb2afbde5 100644 |
| --- a/arch/x86/kernel/alternative.c |
| +++ b/arch/x86/kernel/alternative.c |
| @@ -63,8 +63,11 @@ static int __init setup_noreplace_paravirt(char *str) |
| __setup("noreplace-paravirt", setup_noreplace_paravirt); |
| #endif |
| |
| -#define DPRINTK(fmt, args...) if (debug_alternative) \ |
| - printk(KERN_DEBUG fmt, args) |
| +#define DPRINTK(fmt, args...) \ |
| +do { \ |
| + if (debug_alternative) \ |
| + printk(KERN_DEBUG "%s: " fmt "\n", __func__, ##args); \ |
| +} while (0) |
| |
| /* |
| * Each GENERIC_NOPX is of X bytes, and defined as an array of bytes |
| @@ -251,12 +254,13 @@ extern struct alt_instr __alt_instructions[], __alt_instructions_end[]; |
| extern s32 __smp_locks[], __smp_locks_end[]; |
| void *text_poke_early(void *addr, const void *opcode, size_t len); |
| |
| -/* Replace instructions with better alternatives for this CPU type. |
| - This runs before SMP is initialized to avoid SMP problems with |
| - self modifying code. This implies that asymmetric systems where |
| - APs have less capabilities than the boot processor are not handled. |
| - Tough. Make sure you disable such features by hand. */ |
| - |
| +/* |
| + * Replace instructions with better alternatives for this CPU type. This runs |
| + * before SMP is initialized to avoid SMP problems with self modifying code. |
| + * This implies that asymmetric systems where APs have less capabilities than |
| + * the boot processor are not handled. Tough. Make sure you disable such |
| + * features by hand. |
| + */ |
| void __init_or_module apply_alternatives(struct alt_instr *start, |
| struct alt_instr *end) |
| { |
| @@ -264,10 +268,10 @@ void __init_or_module apply_alternatives(struct alt_instr *start, |
| u8 *instr, *replacement; |
| u8 insnbuf[MAX_PATCH_LEN]; |
| |
| - DPRINTK("%s: alt table %p -> %p\n", __func__, start, end); |
| + DPRINTK("alt table %p -> %p", start, end); |
| /* |
| * The scan order should be from start to end. A later scanned |
| - * alternative code can overwrite a previous scanned alternative code. |
| + * alternative code can overwrite previously scanned alternative code. |
| * Some kernel functions (e.g. memcpy, memset, etc) use this order to |
| * patch code. |
| * |
| @@ -283,11 +287,19 @@ void __init_or_module apply_alternatives(struct alt_instr *start, |
| if (!boot_cpu_has(a->cpuid)) |
| continue; |
| |
| + DPRINTK("feat: %d*32+%d, old: (%p, len: %d), repl: (%p, len: %d)", |
| + a->cpuid >> 5, |
| + a->cpuid & 0x1f, |
| + instr, a->instrlen, |
| + replacement, a->replacementlen); |
| + |
| memcpy(insnbuf, replacement, a->replacementlen); |
| |
| /* 0xe8 is a relative jump; fix the offset. */ |
| - if (*insnbuf == 0xe8 && a->replacementlen == 5) |
| - *(s32 *)(insnbuf + 1) += replacement - instr; |
| + if (*insnbuf == 0xe8 && a->replacementlen == 5) { |
| + *(s32 *)(insnbuf + 1) += replacement - instr; |
| + DPRINTK("Fix CALL offset: 0x%x", *(s32 *)(insnbuf + 1)); |
| + } |
| |
| add_nops(insnbuf + a->replacementlen, |
| a->instrlen - a->replacementlen); |
| @@ -383,8 +395,8 @@ void __init_or_module alternatives_smp_module_add(struct module *mod, |
| smp->locks_end = locks_end; |
| smp->text = text; |
| smp->text_end = text_end; |
| - DPRINTK("%s: locks %p -> %p, text %p -> %p, name %s\n", |
| - __func__, smp->locks, smp->locks_end, |
| + DPRINTK("locks %p -> %p, text %p -> %p, name %s\n", |
| + smp->locks, smp->locks_end, |
| smp->text, smp->text_end, smp->name); |
| |
| mutex_lock(&smp_alt); |
| @@ -408,7 +420,7 @@ void __init_or_module alternatives_smp_module_del(struct module *mod) |
| continue; |
| list_del(&item->next); |
| mutex_unlock(&smp_alt); |
| - DPRINTK("%s: %s\n", __func__, item->name); |
| + DPRINTK("%s\n", item->name); |
| kfree(item); |
| return; |
| } |
| |