mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/alternatives: Guard NOPs optimization
@ 2015-04-04 21:07 Borislav Petkov
  2015-04-07  9:41 ` [tip:x86/asm] " tip-bot for Borislav Petkov
  0 siblings, 1 reply; 2+ messages in thread
From: Borislav Petkov @ 2015-04-04 21:07 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: X86 ML, LKML

From: Borislav Petkov <bp@suse.de>

Take a look at the first insn byte before optimizing the NOP -
there might be something else already, like the ALTERNATIVE_2() in
rdtsc_barrier() which nops out on AMD even though we just patched in an
MFENCE.

This happens because the alternatives sees X86_FEATURE_MFENCE_RDTSC,
AMD CPUs set it, we patch in the MFENCE and right afterwards it sees
X86_FEATURE_LFENCE_RDTSC which AMD CPUs don't set and we blindly
optimize the NOP.

Checking whether at least the first byte is 0x90 prevents that.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/kernel/alternative.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 7c4ad005d7a0..aef653193160 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -325,6 +325,9 @@ done:
 
 static void __init_or_module optimize_nops(struct alt_instr *a, u8 *instr)
 {
+	if (instr[0] != 0x90)
+		return;
+
 	add_nops(instr + (a->instrlen - a->padlen), a->padlen);
 
 	DUMP_BYTES(instr, a->instrlen, "%p: [%d:%d) optimized NOPs: ",
-- 
2.3.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-07  9:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-04 21:07 [PATCH] x86/alternatives: Guard NOPs optimization Borislav Petkov
2015-04-07  9:41 ` [tip:x86/asm] " tip-bot for Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome