mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Juergen Gross <jgross@suse.com>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH v5 3/5] x86/alternative: add indirect call patching
Date: Wed, 6 Dec 2023 12:06:36 +0100	[thread overview]
Message-ID: <20231206110636.GBZXBVvCWj2IDjVk4c@fat_crate.local> (raw)
In-Reply-To: <20231129133332.31043-4-jgross@suse.com>

On Wed, Nov 29, 2023 at 02:33:30PM +0100, Juergen Gross wrote:
> In order to prepare replacing of paravirt patching with alternative
> patching, add the capability to replace an indirect call with a direct
> one to alternative patching.
> 
> This is done via a new flag ALT_FLAG_CALL as the target of the call
> instruction needs to be evaluated using the value of the location
> addressed by the indirect call. For convenience add a macro for a
> default call instruction. In case it is being used without the new
> flag being set, it will result in a BUG() when being executed. As in
> most cases the feature used will be X86_FEATURE_ALWAYS add another
> macro ALT_CALL_ALWAYS usable for the flags parameter of the ALTERNATIVE
> macros.
> 
> For a complete replacement handle the special cases of calling a nop
> function and an indirect call of NULL the same way as paravirt does.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

That SOB chain basically says that you're PeterZ and you're sending this
patch. :)

Are you trying to say that he co-developed it or suggested it or
Originally-by?

Documentation/process/submitting-patches.rst has it all.

Also, what I did ontop of this is below as we must dump the full flags
now with the debug output since you're adding more flags than ALT_NOT.

Also, the naked magic numbers need explanation.

Please include into your next submission.

Thx.

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index e7e53b9e801b..888205234f15 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -395,6 +395,9 @@ noinstr void BUG_func(void)
 }
 EXPORT_SYMBOL_GPL(BUG_func);
 
+#define CALL_RIP_REL_PREFIX	0xff
+#define CALL_RIP_REL_MODRM	0x15
+
 /*
  * Rewrite the "call BUG_func" replacement to point to the target of the
  * indirect pv_ops call "call *disp(%ip)".
@@ -409,11 +412,14 @@ static int alt_replace_call(u8 *instr, u8 *insn_buff, struct alt_instr *a)
 		BUG();
 	}
 
-	if (a->instrlen != 6 || instr[0] != 0xff || instr[1] != 0x15) {
+	if (a->instrlen != 6 ||
+	    instr[0] != CALL_RIP_REL_PREFIX ||
+	    instr[1] != CALL_RIP_REL_MODRM) {
 		pr_err("ALT_FLAG_DIRECT_CALL set for unrecognized indirect call\n");
 		BUG();
 	}
 
+	/* Skip CALL_RIP_REL_PREFIX and CALL_RIP_REL_MODRM */
 	disp = *(s32 *)(instr + 2);
 #ifdef CONFIG_X86_64
 	/* ff 15 00 00 00 00   call   *0x0(%rip) */
@@ -493,12 +499,11 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start,
 			continue;
 		}
 
-		DPRINTK(ALT, "feat: %s%d*32+%d, old: (%pS (%px) len: %d), repl: (%px, len: %d)",
-			(a->flags & ALT_FLAG_NOT) ? "!" : "",
+		DPRINTK(ALT, "feat: %d32+%d, old: (%pS (%px) len: %d), repl: (%px, len: %d) flags: 0x%x",
 			a->cpuid >> 5,
 			a->cpuid & 0x1f,
 			instr, instr, a->instrlen,
-			replacement, a->replacementlen);
+			replacement, a->replacementlen, a->flags);
 
 		memcpy(insn_buff, replacement, a->replacementlen);
 		insn_buff_sz = a->replacementlen;

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

  reply	other threads:[~2023-12-06 11:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-29 13:33 [PATCH v5 0/5] 86/paravirt: Get rid of paravirt patching Juergen Gross
2023-11-29 13:33 ` [PATCH v5 1/5] x86/paravirt: introduce ALT_NOT_XEN Juergen Gross
2023-12-14 11:36   ` [tip: x86/paravirt] x86/paravirt: Introduce ALT_NOT_XEN tip-bot2 for Juergen Gross
2023-11-29 13:33 ` [PATCH v5 2/5] x86/paravirt: move some functions and defines to alternative Juergen Gross
2023-12-14 11:36   ` [tip: x86/paravirt] x86/paravirt: Move some functions and defines to alternative.c tip-bot2 for Juergen Gross
2023-11-29 13:33 ` [PATCH v5 3/5] x86/alternative: add indirect call patching Juergen Gross
2023-12-06 11:06   ` Borislav Petkov [this message]
2023-12-30 11:31     ` [tip: x86/paravirt] x86/alternative: Correct feature bit debug output tip-bot2 for Borislav Petkov (AMD)
2023-11-29 13:33 ` [PATCH v5 4/5] x86/paravirt: switch mixed paravirt/alternative calls to alternative_2 Juergen Gross
2023-12-06 11:08   ` Borislav Petkov
2023-12-08 11:53     ` Juergen Gross
2023-12-08 12:57       ` Borislav Petkov
2023-12-08 15:16         ` Juergen Gross
2023-11-29 13:33 ` [PATCH v5 5/5] x86/paravirt: remove no longer needed paravirt patching code Juergen Gross

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=20231206110636.GBZXBVvCWj2IDjVk4c@fat_crate.local \
    --to=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --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

all inboxes | Powered by JetHome®