From: Borislav Petkov <bp@suse.de>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>, Tony Luck <tony.luck@intel.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Borislav Petkov <bp@alien8.de>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [GIT PULL] x86/asm changes for v5.6
Date: Wed, 29 Jan 2020 14:26:18 +0100 [thread overview]
Message-ID: <20200129132618.GA30979@zn.tnic> (raw)
In-Reply-To: <CAHk-=wi=otQxzhLAofWEvULLMk2X3G3zcWfUWz7e1CFz+xYs2Q@mail.gmail.com>
On Tue, Jan 28, 2020 at 12:06:53PM -0800, Linus Torvalds wrote:
> On Tue, Jan 28, 2020 at 11:51 AM Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> >
> > ALTERNATIVE_2 \
> > "cmp $680, %rdx ; jb 3f ; cmpb %dil, %sil; je 4f", \
> > "movq %rdx, %rcx ; rep movsb; retq", X86_FEATURE_FSRM, \
> > "cmp $0x20, %rdx; jb 1f; movq %rdx, %rcx; rep movsb; retq", X86_FEATURE_ERMS
>
> Note the UNTESTED part.
>
> In particular, I didn't check what the priority for the alternatives
> is. Since FSRM being set always implies ERMS being set too, it may be
> that the ERMS case is always picked with the above code.
>
> So maybe the FSRM and ERMS lines need to be switched around, and
> somebody should add a comment to the ALTERNATIVE_2 macro about the
> priority rules for feature1 vs feature2 when both are set..
>
> IOW, testing most definitely required for that patch suggestion of mine..
So what is there now before your patch is this (I've forced both
X86_FEATURE_FSRM and X86_FEATURE_ERMS on a BDW guest).
[ 4.238160] apply_alternatives: feat: 18*32+4, old: (__memmove+0x17/0x1a0 (ffffffff817d90d7) len: 10), repl: (ffffffff8251dbbb, len: 0), pad: 0
[ 4.239503] ffffffff817d90d7: old_insn: 48 83 fa 20 0f 82 f5 00 00 00
That's what in vmlinux:
ffffffff817d90d7: 48 83 fa 20 cmp $0x20,%rdx
ffffffff817d90db: 0f 82 f5 00 00 00 jb ffffffff817d91d6
which is 10 bytes.
It gets replaced to:
[ 4.240194] ffffffff817d90d7: final_insn: 0f 1f 84 00 00 00 00 00 66 90
ffffffff817d90d7: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1)
ffffffff817d90de: 00
ffffffff817d90df: 66 90 xchg %ax,%ax
I.e., NOPed out.
ERMS replaces the bytes *after* these 10 bytes, note the VA:
0xffffffff817d90d7 + 0xa = 0xffffffff817d90e1
[ 4.240917] apply_alternatives: feat: 9*32+9, old: (__memmove+0x21/0x1a0 (ffffffff817d90e1) len: 6), repl: (ffffffff8251dbbb, len: 6), pad: 6
[ 4.242209] ffffffff817d90e1: old_insn: 90 90 90 90 90 90
[ 4.242823] ffffffff8251dbbb: rpl_insn: 48 89 d1 f3 a4 c3
[ 4.243503] ffffffff817d90e1: final_insn: 48 89 d1 f3 a4 c3
which turns into
ffffffff817d90e1: 48 89 d1 mov %rdx,%rcx
ffffffff817d90e4: f3 a4 rep movsb %ds:(%rsi),%es:(%rdi)
ffffffff817d90e6: c3 retq
as expected.
And yes, your idea makes sense to use ALTERNATIVE_2 but as it is, it
triple-faults my guest. I'll debug it more later to find out why, when I
get a chance.
--
Regards/Gruss,
Boris.
SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg
next prev parent reply other threads:[~2020-01-29 13:26 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-28 16:59 [GIT PULL] x86/asm changes for v5.6 Ingo Molnar
2020-01-28 19:51 ` Linus Torvalds
2020-01-28 20:06 ` Linus Torvalds
2020-01-28 20:14 ` Ingo Molnar
2020-01-28 20:41 ` Luck, Tony
2020-01-28 21:04 ` Linus Torvalds
2020-01-28 22:31 ` Borislav Petkov
2020-01-29 18:00 ` Josh Poimboeuf
2020-01-29 13:26 ` Borislav Petkov [this message]
2020-01-29 17:07 ` Luck, Tony
2020-01-29 17:40 ` Linus Torvalds
2020-01-29 18:34 ` Borislav Petkov
2020-01-29 18:56 ` Linus Torvalds
2020-01-30 8:51 ` Borislav Petkov
2020-01-30 15:27 ` Linus Torvalds
2020-01-30 17:39 ` Borislav Petkov
2020-01-30 18:02 ` Linus Torvalds
2020-01-31 14:27 ` Borislav Petkov
2020-01-31 16:05 ` Josh Poimboeuf
2020-01-29 19:42 ` Luck, Tony
2020-01-30 5:47 ` Damian Tometzki
2020-01-30 7:55 ` Borislav Petkov
2020-01-30 11:10 ` Mike Rapoport
2020-01-30 11:53 ` Borislav Petkov
2020-01-30 11:59 ` Mike Rapoport
2020-01-30 12:06 ` Borislav Petkov
2020-01-30 16:45 ` Damian Tometzki
2020-01-30 17:39 ` Borislav Petkov
2020-01-28 21:15 ` pr-tracker-bot
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=20200129132618.GA30979@zn.tnic \
--to=bp@suse.de \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=torvalds@linux-foundation.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