mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Matthias Welwarsky <matthias.welwarsky@sysgo.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>
Cc: linux-kernel@vger.kernel.org, x86-ml <x86@kernel.org>
Subject: Re: x86, possible bug in __memmove() alternatives patching
Date: Wed, 30 Mar 2022 07:44:14 -0700	[thread overview]
Message-ID: <6e8f0e63-5e21-3694-3e76-290e3fe58e9d@intel.com> (raw)
In-Reply-To: <3160482.aeNJFYEL58@linux-3513>

On 3/30/22 06:56, Matthias Welwarsky wrote:
> 
> Here's the relevant bits:
> 
>         /* FSRM implies ERMS => no length checks, do the copy directly */
> .Lmemmove_begin_forward:
>         ALTERNATIVE "cmp $0x20, %rdx; jb 1f", "", X86_FEATURE_FSRM
>         ALTERNATIVE "", __stringify(movq %rdx, %rcx; rep movsb; RET), 
> X86_FEATURE_ERMS
> 
> If FSRM is there but ERMS isn't, the first ALTERNATIVE is activated but not 
> the second one. That means the length check (< 32) and subsequent "jb 1f" is 
> suppressed but the "movq %rdx, %rcx; rep movsb; RET" is also not there. 

Ahh, thanks for the explanation.  It would help if I wasn't reading the
code wrong.

> I'll send a patch. I think the same rationale applies to FSRM as to ERMS, 
> which gets manually cleared when IA32_MISC_ENABLE says that fast string ops 
> are not available. It will be a one liner added to the dependency table in 
> cpu-deps.c, making FSRM depend on ERMS so that it gets automatically cleared.

Sounds good.  Could you also add some of that explanation to a comment
__memmove and basically say that the code is broken if the dependency
isn't enforced?

  reply	other threads:[~2022-03-30 14:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25  8:51 Matthias Welwarsky
2022-03-25 22:07 ` Borislav Petkov
2022-03-26  4:45   ` Dave Hansen
2022-03-26  8:27     ` Borislav Petkov
2022-03-29 22:34       ` Dave Hansen
2022-03-26 11:39     ` Matthias Welwarsky
2022-03-29 22:33       ` Dave Hansen
2022-03-30 13:56         ` Matthias Welwarsky
2022-03-30 14:44           ` Dave Hansen [this message]
2022-03-30 14:54           ` 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=6e8f0e63-5e21-3694-3e76-290e3fe58e9d@intel.com \
    --to=dave.hansen@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthias.welwarsky@sysgo.com \
    --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®