public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: X86 ML <x86@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH v1 02/12] x86, alternatives: Cleanup DPRINTK macro
Date: Tue,  3 Feb 2015 19:16:20 +0100	[thread overview]
Message-ID: <1422987390-17878-3-git-send-email-bp@alien8.de> (raw)
In-Reply-To: <1422987390-17878-1-git-send-email-bp@alien8.de>

From: Borislav Petkov <bp@suse.de>

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>
---
 arch/x86/kernel/alternative.c | 41 +++++++++++++++++++++++++----------------
 1 file 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)
 __setup("noreplace-paravirt", setup_noreplace_paravirt);
 #endif
 
-#define DPRINTK(fmt, ...)				\
-do {							\
-	if (debug_alternative)				\
-		printk(KERN_DEBUG fmt, ##__VA_ARGS__);	\
+#define DPRINTK(fmt, args...)						\
+do {									\
+	if (debug_alternative)						\
+		printk(KERN_DEBUG "%s: " fmt "\n", __func__, ##args);	\
 } while (0)
 
 /*
@@ -243,12 +243,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)
 {
@@ -256,10 +257,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.
 	 *
@@ -275,11 +276,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);
@@ -371,8 +380,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);
 
 	list_add_tail(&smp->next, &smp_alt_modules);
-- 
2.2.0.33.gc18b867


  parent reply	other threads:[~2015-02-03 18:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-03 18:16 [PATCH v1 00/12] x86, alternatives: Instruction padding and more robust JMPs Borislav Petkov
2015-02-03 18:16 ` [PATCH v1 01/12] x86, copy_user: Remove FIX_ALIGNMENT define Borislav Petkov
2015-02-03 18:16 ` Borislav Petkov [this message]
2015-02-03 19:01   ` [PATCH v1 02/12] x86, alternatives: Cleanup DPRINTK macro Joe Perches
2015-02-03 18:16 ` [PATCH v1 03/12] x86, alternatives: Add instruction padding Borislav Petkov
2015-02-03 18:16 ` [PATCH v1 04/12] x86, alternatives: Make JMPs more robust Borislav Petkov
2015-02-03 18:16 ` [PATCH v1 05/12] x86, alternatives: Use optimized NOPs for padding Borislav Petkov
2015-02-03 19:36   ` Andy Lutomirski
2015-02-03 19:54     ` Borislav Petkov
2015-02-03 18:16 ` [PATCH v1 06/12] x86, copy_page_64.S: Use generic ALTERNATIVE macro Borislav Petkov
2015-02-03 18:16 ` [PATCH v1 07/12] x86, copy_user_64.S: Convert to ALTERNATIVE_2 Borislav Petkov
2015-02-03 18:16 ` [PATCH v1 08/12] x86, SMAP: Use ALTERNATIVE macro Borislav Petkov
2015-02-03 18:16 ` [PATCH v1 09/12] x86, alternative: Convert X86_INVD_BUG to generic macro Borislav Petkov
2015-02-03 18:16 ` [PATCH v1 10/12] x86, alternatives: Convert clear_page_64.S Borislav Petkov
2015-02-03 18:16 ` [PATCH v1 11/12] x86, alternative: Use alternative_2 in rdtsc_barrier Borislav Petkov
2015-02-03 19:55   ` Andy Lutomirski
2015-02-03 20:08     ` Borislav Petkov
2015-02-03 18:16 ` [PATCH v1 12/12] x86, alternative: Cleanup prefetch primitives Borislav Petkov
2015-02-18 21:20 ` [PATCH v1 00/12] x86, alternatives: Instruction padding and more robust JMPs Ingo Molnar
2015-02-18 21:23   ` Borislav Petkov
2015-02-24 11:04   ` Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1422987390-17878-3-git-send-email-bp@alien8.de \
    --to=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox