[3/4] x86/alternatives: Optimize optimize_nops()

Message ID 20240130105941.19707-4-bp@alien8.de
State New
Headers
Series x86/alternatives: Do NOPs optimization on a temporary buffer |

Commit Message

Borislav Petkov Jan. 30, 2024, 10:59 a.m. UTC
  From: "Borislav Petkov (AMD)" <bp@alien8.de>

Return early if NOPs have already been optimized.

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

Patch

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 2dd1c7fe0949..68ee46c379c1 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -233,6 +233,10 @@  static void __init_or_module noinline optimize_nops(const u8 * const instr, u8 *
 		if (insn_is_nop(&insn)) {
 			int nop = i;
 
+			/* Has the NOP already been optimized? */
+			if (i + insn.length == len)
+				return;
+
 			next = skip_nops(buf, next, len);
 
 			add_nop(buf + nop, next - nop);