public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102952] New: New code-gen options for retpolines and straight line speculation
@ 2021-10-26 15:54 andrew.cooper3 at citrix dot com
  2021-10-26 15:56 ` [Bug c/102952] " andrew.cooper3 at citrix dot com
                   ` (43 more replies)
  0 siblings, 44 replies; 45+ messages in thread
From: andrew.cooper3 at citrix dot com @ 2021-10-26 15:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102952

            Bug ID: 102952
           Summary: New code-gen options for retpolines and straight line
                    speculation
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andrew.cooper3 at citrix dot com
  Target Milestone: ---

Hello

[FYI, this is being cross-requested of Clang too]

Linux and other kernel level software makes use of
-mindirect-branch=thunk-extern to be able to alter the handling of indirect
branches at boot.  It turns out to be advantageous to inline the thunks when
retpoline is not in use. 
https://lore.kernel.org/lkml/20211026120132.613201817@infradead.org/ is some
infrastructure to make this work.

In some cases, we want to be able to inline an `lfence; jmp *%reg` thunk.  This
is fine for the low 8 registers, but not fine for %r{8..15} where the REX
prefix pushes the replacement size to being 6 bytes.

It would be very useful to have a code-gen option to write out `call
%cs:__x86_indirect_thunk_r{8..15}` where the redundant %cs prefix will increase
the instruction length to 6, allowing the non-retpoline form to be inlined.


Relatedly, x86 straight line speculation has been discussed before, but without
any action taken.  It would be helpful to have a code gen option which would
emit `int3` following any `ret` instruction, and any indirect jump, as neither
of these two cases have following architectural execution.

The reason these two are related is that if both options are in use, we want an
extra byte of replacement space to be able to inline `lfence; jmp *%reg; int3`.


Third (and possibly only for future optimisations), Clang has been observed to
spot conditional tail calls as `Jcc __x86_indirect_thunk_*`.  This is a 6 byte
source size, but needs up to 9 bytes of space for inlining including an `int3`
for straight line speculation reasons (See
https://lore.kernel.org/lkml/20211026120310.359986601@infradead.org/ for full
details).  It might be enough to simply prohibit an optimisation like this when
trying to pad retpolines for inlineability.

^ permalink raw reply	[flat|nested] 45+ messages in thread

end of thread, other threads:[~2022-02-16 14:01 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-26 15:54 [Bug c/102952] New: New code-gen options for retpolines and straight line speculation andrew.cooper3 at citrix dot com
2021-10-26 15:56 ` [Bug c/102952] " andrew.cooper3 at citrix dot com
2021-10-26 17:11 ` [Bug target/102952] " andrew.cooper3 at citrix dot com
2021-10-27  7:00 ` rguenth at gcc dot gnu.org
2021-10-27 14:50 ` hjl.tools at gmail dot com
2021-10-27 15:01 ` hjl.tools at gmail dot com
2021-10-27 15:03 ` hjl.tools at gmail dot com
2021-10-27 17:55 ` hjl.tools at gmail dot com
2021-10-27 19:59 ` peterz at infradead dot org
2021-10-27 20:00 ` hjl.tools at gmail dot com
2021-10-27 20:14 ` peterz at infradead dot org
2021-10-27 20:20 ` peterz at infradead dot org
2021-10-27 21:42 ` hjl.tools at gmail dot com
2021-10-27 21:42 ` hjl.tools at gmail dot com
2021-10-27 22:07 ` peterz at infradead dot org
2021-10-27 22:12 ` hjl.tools at gmail dot com
2021-10-27 22:16 ` andrew.cooper3 at citrix dot com
2021-10-27 22:39 ` hjl.tools at gmail dot com
2021-10-27 22:42 ` hjl.tools at gmail dot com
2021-10-27 22:46 ` andrew.cooper3 at citrix dot com
2021-10-27 22:53 ` hjl.tools at gmail dot com
2021-10-28  7:30 ` peterz at infradead dot org
2021-10-28  7:43 ` peterz at infradead dot org
2021-10-28 22:07 ` andrew.cooper3 at citrix dot com
2021-10-28 22:26 ` hjl.tools at gmail dot com
2021-11-15 14:27 ` hjl.tools at gmail dot com
2021-11-16 12:57 ` peterz at infradead dot org
2021-11-16 18:52 ` hjl.tools at gmail dot com
2021-11-17 21:35 ` cvs-commit at gcc dot gnu.org
2021-11-18 16:26 ` cvs-commit at gcc dot gnu.org
2021-11-18 18:30 ` hjl.tools at gmail dot com
2022-01-06  9:51 ` andrew.cooper3 at citrix dot com
2022-01-06 13:21 ` hjl.tools at gmail dot com
2022-01-06 13:23 ` hjl.tools at gmail dot com
2022-01-06 18:13 ` andrew.cooper3 at citrix dot com
2022-01-06 19:53 ` cvs-commit at gcc dot gnu.org
2022-01-06 20:12 ` hjl.tools at gmail dot com
2022-01-31  8:04 ` rguenth at gcc dot gnu.org
2022-01-31 13:34 ` hjl.tools at gmail dot com
2022-01-31 15:43 ` hjl.tools at gmail dot com
2022-01-31 18:56 ` hjl.tools at gmail dot com
2022-02-07 23:06 ` andrew.cooper3 at citrix dot com
2022-02-16 14:01 ` cvs-commit at gcc dot gnu.org
2022-02-16 14:01 ` cvs-commit at gcc dot gnu.org
2022-02-16 14:01 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).