From: Juergen Gross <jgross@suse.com>
To: Borislav Petkov <bp@alien8.de>
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 v4 2/5] x86/alternative: add indirect call patching
Date: Tue, 14 Nov 2023 13:56:37 +0100 [thread overview]
Message-ID: <9ccdcff2-90f9-47da-9aea-46cffe7fae85@suse.com> (raw)
In-Reply-To: <20231114123737.GBZVNqEXKgt+6P1Wiv@fat_crate.local>
[-- Attachment #1.1.1: Type: text/plain, Size: 1890 bytes --]
On 14.11.23 13:37, Borislav Petkov wrote:
> On Mon, Oct 30, 2023 at 03:25:05PM +0100, Juergen Gross wrote:
>> + * Rewrite the "call BUG_func" replacement to point to the target of the
>> + * indirect pv_ops call "call *disp(%ip)".
>> + */
>> +static int alt_replace_call(u8 *instr, u8 *insn_buff, struct alt_instr *a)
>> +{
>> + void *target, *bug = &BUG_func;
>> +
>> + if (a->replacementlen != 5 || insn_buff[0] != CALL_INSN_OPCODE) {
>> + pr_err("Alternative: ALT_FLAG_CALL set for a non-call replacement instruction\n");
>
> No need for the printk prefix.
Okay.
>
>> + pr_err(" Ignoring the flag for the instruction at %pS (%px)\n", instr, instr);
>
> No ignoring - BUG
Okay.
>
>> + return 5;
>> + }
>> +
>> + if (a->instrlen != 6 || instr[0] != 0xff || instr[1] != 0x15) {
>> + pr_err("Alternative: ALT_FLAG_CALL set for unrecognized indirect call\n");
>> + pr_err(" Not replacing the instruction at %pS (%px)\n", instr, instr);
>> + return -1;
>
> Ditto.
Okay.
>
>> + }
>> +
>> +#ifdef CONFIG_X86_64
>> + /* ff 15 00 00 00 00 call *0x0(%rip) */
>> + target = *(void **)(instr + a->instrlen + *(s32 *)(instr + 2));
>> +#else
>> + /* ff 15 00 00 00 00 call *0x0 */
>> + target = *(void **)(*(s32 *)(instr + 2));
>> +#endif
>> + if (!target)
>> + target = bug;
>> +
>> + /* (BUG_func - .) + (target - BUG_func) := target - . */
>> + *(s32 *)(insn_buff + 1) += target - bug;
>
> If I squint hard enough, this looks like it is replacing one call with
> another. We have a C macro alternative_call() which does exactly that.
> Why can't you define an asm version ALTERNATIVE_CALL and use it
> instead of using adding a new flag? We have 16 possible ones in total.
It is replacing an _indirect_ call with a _direct_ one, taking the call target
from the pointer used by the indirect call.
Juergen
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3149 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
next prev parent reply other threads:[~2023-11-14 12:56 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-30 14:25 [PATCH v4 0/5] x86/paravirt: Get rid of paravirt patching Juergen Gross
2023-10-30 14:25 ` [PATCH v4 1/5] x86/paravirt: move some functions and defines to alternative Juergen Gross
2023-10-30 14:25 ` [PATCH v4 2/5] x86/alternative: add indirect call patching Juergen Gross
2023-11-14 12:37 ` Borislav Petkov
2023-11-14 12:50 ` Peter Zijlstra
2023-11-14 13:47 ` Borislav Petkov
2023-11-14 14:18 ` Peter Zijlstra
2023-11-14 14:27 ` Borislav Petkov
2023-11-14 14:35 ` Juergen Gross
2023-11-14 12:56 ` Juergen Gross [this message]
2023-11-14 15:06 ` Borislav Petkov
2023-11-14 16:16 ` Juergen Gross
2023-10-30 14:25 ` [PATCH v4 3/5] x86/paravirt: introduce ALT_NOT_XEN Juergen Gross
2023-11-14 15:09 ` Borislav Petkov
2023-11-14 16:17 ` Juergen Gross
2023-10-30 14:25 ` [PATCH v4 4/5] x86/paravirt: switch mixed paravirt/alternative calls to alternative_2 Juergen Gross
2023-11-21 18:45 ` Borislav Petkov
2023-11-29 10:08 ` Juergen Gross
2023-10-30 14:25 ` [PATCH v4 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=9ccdcff2-90f9-47da-9aea-46cffe7fae85@suse.com \
--to=jgross@suse.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.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®