public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Qing Zhao <QING.ZHAO@ORACLE.COM>,
	Kees Cook <keescook@chromium.org>,
	Kees Cook via Gcc-patches <gcc-patches@gcc.gnu.org>,
	Jakub Jelinek <jakub@redhat.com>, Uros Bizjak <ubizjak@gmail.com>,
	"Rodriguez Bahena, Victor" <victor.rodriguez.bahena@intel.com>,
	richard.sandiford@arm.com
Subject: Re: PING [Patch][Middle-end]Add -fzero-call-used-regs=[skip|used-gpr|all-gpr|used|all]
Date: Tue, 15 Sep 2020 14:22:20 -0500	[thread overview]
Message-ID: <20200915192220.GR28786@gate.crashing.org> (raw)
In-Reply-To: <mptbli72rgn.fsf@arm.com>

On Tue, Sep 15, 2020 at 12:46:00PM +0100, Richard Sandiford wrote:
> Segher Boessenkool <segher@kernel.crashing.org> writes:
> > On Mon, Sep 14, 2020 at 05:33:33PM +0100, Richard Sandiford wrote:
> >> > However, for the cases on Power as Segher mentioned, there are also some scratch registers used for
> >> > Other purpose, not sure whether we can correctly generate zeroing in middle-end for Power?
> >> 
> >> Segher would be better placed to answer that, but I think the process
> >> above has to give a conservatively-accurate list of live registers.
> >> If it misses a register, the other late rtl passes could clobber
> >> that same register.
> >
> > It will zero a whole bunch of registers that are overwritten later, that
> > are not parameter passing registers either.
> 
> This thread has covered two main issues: correctness and cost.
> The question above was about correctness, but your reply seems to be
> about cost.

The issues are very heavily intertwined.  A much too high execution
cost is unacceptable, just like machine code that does not implement the
source code faithfully.

> On the cost issue: when you say some registers are “overwritten later”:
> which registers do you mean, and who would be doing the overwriting?

(Glue) code that is generated by the linker.

> We were talking about inserting zeroing instructions immediately before
> returns that already exist.  It looks like the main Power return
> pattern is:

It is.

> (define_insn "<return_str>return"
>   [(any_return)]
>   "<return_pred>"
>   "blr"
>   [(set_attr "type" "jmpreg")])
> 
> Does this overwrite anything other than the PC?  If not, it doesn't

(We do not have a "PC" register, but :-) )

Nope.  The blr instruction does not write any register.  (The base
"bclr[l]" insn can write to CTR and LR).

> look like anything in the function itself would clobber other registers
> later (i.e. later than the inserted zeroing instructions).  And of course,
> if an attacker is performing a ROP attack, the attacker controls which
> address the BLR returns to.

That does not matter for the *normal* case.  Making the normal case even
more expensive than this scheme already is is no good.


Anyway, I was concerned about other architectures, too (that may not
even *have* a GCC port (yet)).  The point is that this should follow all
the rules we have for RTL.  Now that it will use DF (thanks!), most of
that will follow automatically (or easily, anyway).


Segher

  reply	other threads:[~2020-09-15 19:24 UTC|newest]

Thread overview: 188+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-04 19:01 [PATCH 1/4] matcher-1.m: Change return type to int H.J. Lu
2020-05-04 19:01 ` [PATCH 2/4] x86: Add -mzero-caller-saved-regs=[skip|used-gpr|all-gpr|used|all] H.J. Lu
2020-05-04 23:19   ` Rodriguez Bahena, Victor
2020-05-05  8:14   ` Uros Bizjak
2020-05-05  8:20     ` Richard Biener
2020-07-14 14:45       ` [Patch][Middle-end]Add -fzero-call-used-regs=[skip|used-gpr|all-gpr|used|all] Qing Zhao
2020-07-16 13:17         ` Victor Rodriguez
2020-07-28 20:05         ` PING " Qing Zhao
2020-07-31 17:57           ` Uros Bizjak
2020-08-03 15:42             ` Qing Zhao
2020-08-04  7:35               ` Richard Biener
2020-08-04 18:23                 ` H.J. Lu
2020-08-05  7:06                   ` Richard Biener
2020-08-05 12:26                     ` H.J. Lu
2020-08-05 12:30                       ` Richard Biener
2020-08-05 12:34                         ` H.J. Lu
2020-08-05 14:45                           ` H.J. Lu
2020-08-05 15:00                             ` Qing Zhao
2020-08-05 18:53                             ` Richard Biener
2020-08-05 19:08                               ` H.J. Lu
2020-08-05 20:22                               ` Qing Zhao
2020-08-06  8:37                                 ` Richard Biener
2020-08-06 15:45                                   ` Qing Zhao
2020-08-06 20:45                                   ` Kees Cook
2020-08-07  6:21                                     ` Richard Biener
2020-08-07 16:15                                       ` Qing Zhao
2020-08-05 21:35                 ` Qing Zhao
2020-08-06  8:31                   ` Richard Biener
2020-08-06  8:41                     ` Jakub Jelinek
2020-08-06  9:31                       ` Uros Bizjak
2020-08-06 14:56                     ` Qing Zhao
2020-08-06 23:37                     ` Segher Boessenkool
2020-08-07 16:06                       ` Qing Zhao
2020-08-07 22:59                         ` Segher Boessenkool
2020-08-10 16:34                           ` Qing Zhao
2020-08-10 19:51                             ` Qing Zhao
2020-08-19 20:05                       ` Qing Zhao
2020-08-19 22:57                         ` Segher Boessenkool
2020-08-19 23:27                           ` Qing Zhao
2020-08-24 14:47                             ` Rodriguez Bahena, Victor
2020-08-24 17:59                               ` Segher Boessenkool
2020-08-24 18:48                                 ` Qing Zhao
2020-08-24 20:26                                   ` Segher Boessenkool
2020-08-24 20:49                                     ` Qing Zhao
2020-09-04 15:18                                       ` Segher Boessenkool
2020-09-04 17:34                                         ` H.J. Lu
2020-09-04 18:09                                           ` Segher Boessenkool
2020-09-04 18:52                                             ` H.J. Lu
2020-09-07 14:06                                               ` Segher Boessenkool
2020-09-07 15:58                                                 ` H.J. Lu
2020-09-08 16:43                                                   ` Qing Zhao
2020-09-10 22:05                                                     ` Segher Boessenkool
2020-09-10 22:50                                                       ` Qing Zhao
2020-09-11 17:18                                                         ` Segher Boessenkool
2020-09-11 19:53                                                           ` Qing Zhao
2020-08-24 17:49                             ` Segher Boessenkool
2020-08-24 18:02                               ` Qing Zhao
2020-08-24 20:20                                 ` Segher Boessenkool
2020-08-24 20:43                                   ` Qing Zhao
2020-08-25  6:41                                     ` Uros Bizjak
2020-08-25 14:05                                       ` Qing Zhao
2020-08-25 22:31                                         ` Qing Zhao
2020-09-04 15:26                                     ` Segher Boessenkool
2020-08-25 21:54                                   ` Qing Zhao
2020-09-03 14:29                                     ` Qing Zhao
2020-09-03 15:08                                       ` Qing Zhao
2020-09-03 16:19                                         ` Qing Zhao
2020-09-03 17:13                                       ` Kees Cook
2020-09-03 17:43                                         ` Qing Zhao
2020-09-04  1:23                                           ` Rodriguez Bahena, Victor
2020-09-04 14:18                                             ` Qing Zhao
2020-09-07 13:06                                               ` Rodriguez Bahena, Victor
2020-09-08 15:00                                                 ` Qing Zhao
2020-09-10 19:07                                                   ` Kees Cook
2020-09-10 22:40                                                     ` Qing Zhao
2020-09-11 10:06                                                     ` Richard Sandiford
2020-09-11 16:14                                                       ` Segher Boessenkool
2020-09-11 16:52                                                         ` Qing Zhao
2020-09-11 17:13                                                           ` Segher Boessenkool
2020-09-11 19:40                                                             ` Qing Zhao
2020-09-11 20:05                                                               ` Segher Boessenkool
2020-09-11 20:17                                                                 ` Qing Zhao
2020-09-11 20:36                                                                   ` Segher Boessenkool
2020-09-11 21:12                                                                     ` Qing Zhao
2020-09-11 17:32                                                           ` Richard Sandiford
2020-09-11 20:01                                                             ` Segher Boessenkool
2020-09-11 20:14                                                             ` Qing Zhao
2020-09-11 21:03                                                               ` Segher Boessenkool
2020-09-11 21:29                                                                 ` Qing Zhao
2020-09-11 21:51                                                                   ` Segher Boessenkool
2020-09-11 22:41                                                                     ` Qing Zhao
2020-09-14 23:09                                                                       ` Segher Boessenkool
2020-09-15  3:07                                                                         ` Qing Zhao
2020-09-15 18:51                                                                           ` Segher Boessenkool
2020-09-11 21:44                                                               ` Richard Sandiford
2020-09-11 22:24                                                                 ` Qing Zhao
2020-09-11 22:56                                                                   ` Richard Sandiford
2020-09-14 14:56                                                                     ` Qing Zhao
2020-09-14 16:33                                                                       ` Richard Sandiford
2020-09-14 18:50                                                                         ` Qing Zhao
2020-09-14 19:20                                                                           ` Richard Sandiford
2020-09-14 20:24                                                                             ` Qing Zhao
2020-09-15  9:11                                                                               ` Richard Sandiford
2020-09-15 15:05                                                                                 ` Qing Zhao
2020-09-15 19:41                                                                                 ` Segher Boessenkool
2020-09-15 22:31                                                                                   ` Qing Zhao
2020-09-15 23:09                                                                                     ` Segher Boessenkool
2020-09-16  1:51                                                                                       ` Qing Zhao
2020-09-16 10:35                                                                                         ` Segher Boessenkool
2020-09-16 20:57                                                                                           ` Qing Zhao
2020-09-17  6:17                                                                                             ` Richard Sandiford
2020-09-17 14:40                                                                                               ` Qing Zhao
2020-09-17 16:27                                                                                                 ` Richard Sandiford
2020-09-17 19:07                                                                                                   ` Qing Zhao
2020-09-22 17:06                                                                                                     ` Richard Sandiford
2020-09-22 21:32                                                                                                       ` Qing Zhao
2020-09-23 11:05                                                                                                         ` Richard Sandiford
2020-09-23 14:14                                                                                                           ` Qing Zhao
2020-09-23 14:32                                                                                                             ` Richard Sandiford
2020-09-23 14:48                                                                                                               ` Qing Zhao
2020-09-23 15:21                                                                                                                 ` Richard Sandiford
2020-09-23 16:08                                                                                                                   ` Qing Zhao
2020-09-23 23:46                                                                                                           ` Segher Boessenkool
2020-09-22 22:37                                                                                                       ` Segher Boessenkool
2020-09-23 14:28                                                                                                         ` Qing Zhao
2020-09-23 23:40                                                                                                           ` Segher Boessenkool
2020-09-17 22:26                                                                                                   ` Segher Boessenkool
2020-09-14 23:35                                                                         ` Segher Boessenkool
2020-09-15 11:46                                                                           ` Richard Sandiford
2020-09-15 19:22                                                                             ` Segher Boessenkool [this message]
2020-09-14 23:20                                                                   ` Segher Boessenkool
2020-09-18 20:31                                                                 ` Qing Zhao
2020-09-18 22:51                                                                   ` Segher Boessenkool
2020-09-21 14:13                                                                     ` Qing Zhao
2020-09-21 20:34                                                                       ` Segher Boessenkool
2020-09-21 20:58                                                                         ` Qing Zhao
2020-09-22  0:25                                                                           ` Segher Boessenkool
2020-09-21  7:23                                                                   ` Richard Sandiford
2020-09-21 14:29                                                                     ` Qing Zhao
2020-09-21 15:35                                                                       ` Richard Sandiford
2020-09-21 16:34                                                                         ` Qing Zhao
2020-09-21 19:11                                                                           ` Richard Sandiford
2020-09-21 19:22                                                                             ` Qing Zhao
2020-09-21 20:05                                                                               ` Qing Zhao
2020-09-22 16:31                                                                                 ` Richard Sandiford
2020-09-22 18:25                                                                                   ` Qing Zhao
2020-09-22 18:35                                                                                     ` H.J. Lu
2020-09-22 19:34                                                                                       ` Qing Zhao
2020-09-23 10:43                                                                                         ` Richard Sandiford
2020-09-23 13:54                                                                                           ` Qing Zhao
2020-09-23 14:22                                                                                             ` Richard Sandiford
2020-09-23 14:35                                                                                               ` Qing Zhao
2020-09-23 14:40                                                                                                 ` Richard Sandiford
2020-09-23 14:49                                                                                                   ` Qing Zhao
2020-09-07 14:44                                             ` Segher Boessenkool
2020-09-08 15:05                                               ` Patrick McGehearty
2020-09-10 12:11                                                 ` Richard Sandiford
2020-09-10 14:34                                                   ` Qing Zhao
2020-09-10 14:59                                                     ` Rodriguez Bahena, Victor
2020-09-03 17:48                                         ` Ramana Radhakrishnan
2020-09-03 19:20                                           ` Qing Zhao
2020-09-04 15:43                                         ` Segher Boessenkool
2020-09-04 17:18                                           ` Qing Zhao
2020-09-04 18:04                                             ` Segher Boessenkool
2020-09-04 19:00                                               ` Qing Zhao
2020-09-07 14:36                                                 ` Segher Boessenkool
2020-09-08 14:55                                                   ` Qing Zhao
2020-09-10 21:56                                                     ` Segher Boessenkool
2020-08-24 14:36                           ` Rodriguez Bahena, Victor
2020-08-06 22:32                   ` Qing Zhao
2020-08-07 13:20           ` Alexandre Oliva
2020-08-07 17:04             ` Qing Zhao
2020-08-11  2:39               ` Alexandre Oliva
2020-08-11  5:57                 ` Kees Cook
2020-08-11 17:30                 ` Qing Zhao
2020-08-24 10:50                   ` Richard Biener
2020-08-24 14:48                     ` Qing Zhao
2020-08-25  5:16                     ` Alexandre Oliva
2020-08-25 14:19                       ` Jeff Law
2020-08-26 12:02                         ` Alexandre Oliva
2020-08-26 17:58                           ` Qing Zhao
2020-08-28  7:47                             ` Alexandre Oliva
2020-08-28 15:21                               ` Qing Zhao
2020-08-28 15:33                                 ` H.J. Lu
2020-08-26 18:36                           ` Jeff Law
2020-05-04 19:01 ` [PATCH 3/4] x86: Add ix86_any_return_p H.J. Lu
2020-05-04 19:01 ` [PATCH 4/4] Update gcc.target/i386/ret-thunk-2[234].c H.J. Lu
2020-05-05 16:29 ` [PATCH 1/4] matcher-1.m: Change return type to int Jeff Law

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=20200915192220.GR28786@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=QING.ZHAO@ORACLE.COM \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=keescook@chromium.org \
    --cc=richard.sandiford@arm.com \
    --cc=ubizjak@gmail.com \
    --cc=victor.rodriguez.bahena@intel.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).