All of lore.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 v2 3/4] x86/alternatives: Optimize optimize_nops()
Date: Sun, 31 Mar 2024 20:00:41 +0200	[thread overview]
Message-ID: <20240331180042.13933-4-bp@alien8.de> (raw)
In-Reply-To: <20240331180042.13933-1-bp@alien8.de>

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(+)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 4b3378c71518..67dd7c371d28 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -233,6 +233,10 @@ static void noinline optimize_nops(const u8 * const instr, u8 *buf, size_t len)
 		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);
-- 
2.43.0


  parent reply	other threads:[~2024-03-31 18:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-31 18:00 [PATCH v2 0/4] x86/alternatives: Do NOPs optimization on a temporary buffer Borislav Petkov
2024-03-31 18:00 ` [PATCH v2 1/4] x86/alternatives: Use a temporary buffer when optimizing NOPs Borislav Petkov
2024-03-31 18:00 ` [PATCH v2 2/4] x86/alternatives: Get rid of __optimize_nops() Borislav Petkov
2024-03-31 18:00 ` Borislav Petkov [this message]
2024-03-31 18:00 ` [PATCH v2 4/4] x86/alternatives: Sort local vars in apply_alternatives() 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=20240331180042.13933-4-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.