[tip:,x86/alternatives] x86/alternatives: Optimize optimize_nops()

Message ID 170783855882.398.12172953906300246762.tip-bot2@tip-bot2
State New
Headers
Series [tip:,x86/alternatives] x86/alternatives: Optimize optimize_nops() |

Commit Message

tip-bot2 for Thomas Gleixner Feb. 13, 2024, 3:35 p.m. UTC
  The following commit has been merged into the x86/alternatives branch of tip:

Commit-ID:     f7045230fa2933bf3b38c9c92b5ba46486ef33f9
Gitweb:        https://git.kernel.org/tip/f7045230fa2933bf3b38c9c92b5ba46486ef33f9
Author:        Borislav Petkov (AMD) <bp@alien8.de>
AuthorDate:    Tue, 30 Jan 2024 11:59:40 +01:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Tue, 13 Feb 2024 16:26:56 +01:00

x86/alternatives: Optimize optimize_nops()

Return early if NOPs have already been optimized.

Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20240130105941.19707-4-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 cdbece3..1ceaaab 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);