All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Alejandro Vallejo <alejandro.vallejo@cloud.com>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v3] x86/altcall: further refine clang workaround
Date: Wed, 31 Jul 2024 09:51:08 +0200	[thread overview]
Message-ID: <Zqns7Pf3uCikjScZ@macbook> (raw)
In-Reply-To: <8701cfdf-a44c-4bec-8190-7d38e8267a78@suse.com>

On Wed, Jul 31, 2024 at 08:26:02AM +0200, Jan Beulich wrote:
> On 30.07.2024 17:53, Roger Pau Monne wrote:
> > The current code in ALT_CALL_ARG() won't successfully workaround the clang
> > code-generation issue if the arg parameter has a size that's not a power of 2.
> > While there are no such sized parameters at the moment, improve the workaround
> > to also be effective when such sizes are used.
> > 
> > Instead of using a union with a long use an unsigned long that's first
> > initialized to 0 and afterwards set to the argument value.
> > 
> > Reported-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
> > Suggested-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
> > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> 
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
> Albeit if you don't mind ...
> 
> > --- a/xen/arch/x86/include/asm/alternative.h
> > +++ b/xen/arch/x86/include/asm/alternative.h
> > @@ -169,27 +169,25 @@ extern void alternative_branches(void);
> >  
> >  #ifdef CONFIG_CC_IS_CLANG
> >  /*
> > - * Use a union with an unsigned long in order to prevent clang from
> > - * skipping a possible truncation of the value.  By using the union any
> > - * truncation is carried before the call instruction, in turn covering
> > - * for ABI-non-compliance in that the necessary clipping / extension of
> > - * the value is supposed to be carried out in the callee.
> > + * Clang doesn't follow the psABI and doesn't truncate parameter values at the
> > + * callee.  This can lead to bad code being generated when using alternative
> > + * calls.
> >   *
> > - * Note this behavior is not mandated by the standard, and hence could
> > - * stop being a viable workaround, or worse, could cause a different set
> > - * of code-generation issues in future clang versions.
> > + * Workaround it by using a temporary intermediate variable that's zeroed
> > + * before being assigned the parameter value, as that forces clang to zero the
> > + * register at the caller.
> >   *
> >   * This has been reported upstream:
> >   * https://github.com/llvm/llvm-project/issues/12579
> >   * https://github.com/llvm/llvm-project/issues/82598
> >   */
> >  #define ALT_CALL_ARG(arg, n)                                            \
> > -    register union {                                                    \
> > -        typeof(arg) e[sizeof(long) / sizeof(arg)];                      \
> > -        unsigned long r;                                                \
> > -    } a ## n ## _ asm ( ALT_CALL_arg ## n ) = {                         \
> > -        .e[0] = ({ BUILD_BUG_ON(sizeof(arg) > sizeof(void *)); (arg); })\
> > -    }
> > +    register unsigned long a ## n ## _ asm ( ALT_CALL_arg ## n ) = ({   \
> > +        unsigned long tmp = 0;                                          \
> > +        *(typeof(arg) *)&tmp = (arg);                                   \
> > +        BUILD_BUG_ON(sizeof(arg) > sizeof(unsigned long));              \
> 
> ... I'd like to switch around these two lines while committing.

Sure, feel free to swap them.

Thanks, Roger.


      reply	other threads:[~2024-07-31  7:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-30 15:53 [PATCH v3] x86/altcall: further refine clang workaround Roger Pau Monne
2024-07-31  6:26 ` Jan Beulich
2024-07-31  7:51   ` Roger Pau Monné [this message]

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=Zqns7Pf3uCikjScZ@macbook \
    --to=roger.pau@citrix.com \
    --cc=alejandro.vallejo@cloud.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.