From: Borislav Petkov <bp@alien8.de>
To: Mathias Krause <minipli@googlemail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Borislav Petkov <bp@suse.de>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Michael Matz <matz@suse.de>
Subject: Re: [PATCH] x86/alternatives: Fix alt_max_short macro to really be a max()
Date: Thu, 5 Oct 2017 09:38:09 +0200 [thread overview]
Message-ID: <20171005073809.depam2y4vw2mb5ya@pd.tnic> (raw)
In-Reply-To: <1507140492-7832-1-git-send-email-minipli@googlemail.com>
On Wed, Oct 04, 2017 at 08:08:12PM +0200, Mathias Krause wrote:
> The alt_max_short() macro in asm/alternative.h does not work as
> intended, leading to nasty bugs. E.g. alt_max_short("1", "3")
> evaluates to 3, but alt_max_short("3", "1") evaluates to 1 -- not
> exactly the maximum of 1 and 3.
>
> In fact, I had to learn it the hard way by crashing my kernel in not
> so funny ways by attempting to make use of the ALTENATIVE_2 macro
> with alternatives where the first one was larger than the second
> one.
>
> According to [1] and commit dbe4058a6a44 ("x86/alternatives: Fix
> ALTERNATIVE_2 padding generation properly") the right handed side
> should read "-(-(a < b))" not "-(-(a - b))". Fix that, to make the
> macro work as intended.
>
> While at it, fix up the comment regarding the additional "-", too.
> It's not about gas' usage of s32 but brain dead logic of having a
> "true" value of -1 for the < operator ... *sigh*
>
> Btw., the one in asm/alternative-asm.h is correct. And, apparently,
> all current users of ALTERNATIVE_2() pass same sized alternatives,
> avoiding to hit the bug.
>
> [1] http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
>
> Fixes: dbe4058a6a44 ("x86/alternatives: Fix ALTERNATIVE_2 padding generation properly")
> Signed-off-by: Mathias Krause <minipli@googlemail.com>
> Cc: Borislav Petkov <bp@suse.de>
> ---
> arch/x86/include/asm/alternative.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
> index c096624137ae..7c553f48f163 100644
> --- a/arch/x86/include/asm/alternative.h
> +++ b/arch/x86/include/asm/alternative.h
> @@ -106,9 +106,9 @@ static inline int alternatives_text_reserved(void *start, void *end)
> * max without conditionals. Idea adapted from:
^^^^^^^^^^^^^^^^^^^^^^^^^
You did read this part, right?
AFAIR, gas can't stomach conditionals but I don't remember the details
anymore. Could be that -1 representation of "true". Let me add Micha to
CC.
Anyway, how can I reproduce your observation? Code snippet and compiler
pls.
Thx.
--
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.
next prev parent reply other threads:[~2017-10-05 7:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-04 18:08 Mathias Krause
2017-10-05 7:38 ` Borislav Petkov [this message]
2017-10-05 7:58 ` Mathias Krause
2017-10-05 12:35 ` Mathias Krause
2017-10-05 12:39 ` Borislav Petkov
2017-10-05 12:52 ` Michael Matz
2017-10-05 13:01 ` Mathias Krause
2017-10-05 14:55 ` 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=20171005073809.depam2y4vw2mb5ya@pd.tnic \
--to=bp@alien8.de \
--cc=bp@suse.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matz@suse.de \
--cc=mingo@redhat.com \
--cc=minipli@googlemail.com \
--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®