All of lore.kernel.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Marco Elver <elver@google.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Mark Brown <broonie@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	kasan-dev <kasan-dev@googlegroups.com>,
	linux-toolchains@vger.kernel.org,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v1] powerpc: Include running function as first entry in save_stack_trace() and friends
Date: Thu, 4 Mar 2021 13:24:47 -0600	[thread overview]
Message-ID: <20210304192447.GT29191@gate.crashing.org> (raw)
In-Reply-To: <CAKwvOd=wBArMwvtDC8zV-QjQa5UuwWoxksQ8j+hUCZzbEAn+Fw@mail.gmail.com>

On Thu, Mar 04, 2021 at 09:54:44AM -0800, Nick Desaulniers wrote:
> On Thu, Mar 4, 2021 at 9:42 AM Marco Elver <elver@google.com> wrote:
> include/linux/compiler.h:246:
> prevent_tail_call_optimization
> 
> commit a9a3ed1eff36 ("x86: Fix early boot crash on gcc-10, third try")

That is much heavier than needed (an mb()).  You can just put an empty
inline asm after a call before a return, and that call cannot be
optimised to a sibling call: (the end of a function is an implicit
return:)

Instead of:

void g(void);
void f(int x)
	if (x)
		g();
}

Do:

void g(void);
void f(int x)
	if (x)
		g();
	asm("");
}

This costs no extra instructions, and certainly not something as heavy
as an mb()!  It works without the "if" as well, of course, but with it
it is a more interesting example of a tail call.


Segher

WARNING: multiple messages have this Message-ID (diff)
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
	Marco Elver <elver@google.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
	LKML <linux-kernel@vger.kernel.org>,
	kasan-dev <kasan-dev@googlegroups.com>,
	Mark Brown <broonie@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	linux-toolchains@vger.kernel.org, Will Deacon <will@kernel.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v1] powerpc: Include running function as first entry in save_stack_trace() and friends
Date: Thu, 4 Mar 2021 13:24:47 -0600	[thread overview]
Message-ID: <20210304192447.GT29191@gate.crashing.org> (raw)
In-Reply-To: <CAKwvOd=wBArMwvtDC8zV-QjQa5UuwWoxksQ8j+hUCZzbEAn+Fw@mail.gmail.com>

On Thu, Mar 04, 2021 at 09:54:44AM -0800, Nick Desaulniers wrote:
> On Thu, Mar 4, 2021 at 9:42 AM Marco Elver <elver@google.com> wrote:
> include/linux/compiler.h:246:
> prevent_tail_call_optimization
> 
> commit a9a3ed1eff36 ("x86: Fix early boot crash on gcc-10, third try")

That is much heavier than needed (an mb()).  You can just put an empty
inline asm after a call before a return, and that call cannot be
optimised to a sibling call: (the end of a function is an implicit
return:)

Instead of:

void g(void);
void f(int x)
	if (x)
		g();
}

Do:

void g(void);
void f(int x)
	if (x)
		g();
	asm("");
}

This costs no extra instructions, and certainly not something as heavy
as an mb()!  It works without the "if" as well, of course, but with it
it is a more interesting example of a tail call.


Segher

WARNING: multiple messages have this Message-ID (diff)
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Marco Elver <elver@google.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Mark Brown <broonie@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	kasan-dev <kasan-dev@googlegroups.com>,
	linux-toolchains@vger.kernel.org,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v1] powerpc: Include running function as first entry in save_stack_trace() and friends
Date: Thu, 4 Mar 2021 13:24:47 -0600	[thread overview]
Message-ID: <20210304192447.GT29191@gate.crashing.org> (raw)
In-Reply-To: <CAKwvOd=wBArMwvtDC8zV-QjQa5UuwWoxksQ8j+hUCZzbEAn+Fw@mail.gmail.com>

On Thu, Mar 04, 2021 at 09:54:44AM -0800, Nick Desaulniers wrote:
> On Thu, Mar 4, 2021 at 9:42 AM Marco Elver <elver@google.com> wrote:
> include/linux/compiler.h:246:
> prevent_tail_call_optimization
> 
> commit a9a3ed1eff36 ("x86: Fix early boot crash on gcc-10, third try")

That is much heavier than needed (an mb()).  You can just put an empty
inline asm after a call before a return, and that call cannot be
optimised to a sibling call: (the end of a function is an implicit
return:)

Instead of:

void g(void);
void f(int x)
	if (x)
		g();
}

Do:

void g(void);
void f(int x)
	if (x)
		g();
	asm("");
}

This costs no extra instructions, and certainly not something as heavy
as an mb()!  It works without the "if" as well, of course, but with it
it is a more interesting example of a tail call.


Segher

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-03-04 19:33 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-03 14:09 [PATCH v1] powerpc: Include running function as first entry in save_stack_trace() and friends Christophe Leroy
2021-03-03 14:09 ` Christophe Leroy
2021-03-03 14:38 ` Marco Elver
2021-03-03 14:38   ` Marco Elver
2021-03-03 14:52   ` Christophe Leroy
2021-03-03 14:52     ` Christophe Leroy
2021-03-03 15:20     ` Marco Elver
2021-03-03 15:20       ` Marco Elver
2021-03-03 15:20       ` Marco Elver
2021-03-04 14:57       ` Mark Rutland
2021-03-04 14:57         ` Mark Rutland
2021-03-04 14:57         ` Mark Rutland
2021-03-04 15:30         ` Marco Elver
2021-03-04 15:30           ` Marco Elver
2021-03-04 15:30           ` Marco Elver
2021-03-04 16:59           ` Mark Rutland
2021-03-04 16:59             ` Mark Rutland
2021-03-04 16:59             ` Mark Rutland
2021-03-04 17:25             ` Marco Elver
2021-03-04 17:25               ` Marco Elver
2021-03-04 17:25               ` Marco Elver
2021-03-04 17:54               ` Nick Desaulniers
2021-03-04 17:54                 ` Nick Desaulniers
2021-03-04 17:54                 ` Nick Desaulniers
2021-03-04 19:24                 ` Segher Boessenkool [this message]
2021-03-04 19:24                   ` Segher Boessenkool
2021-03-04 19:24                   ` Segher Boessenkool
2021-03-05  6:38                   ` Christophe Leroy
2021-03-05  6:38                     ` Christophe Leroy
2021-03-05  6:38                     ` Christophe Leroy
2021-03-05 18:16                     ` Segher Boessenkool
2021-03-05 18:16                       ` Segher Boessenkool
2021-03-05 18:16                       ` Segher Boessenkool
2021-03-04 18:01               ` Mark Rutland
2021-03-04 18:01                 ` Mark Rutland
2021-03-04 18:01                 ` Mark Rutland
2021-03-04 18:22                 ` Marco Elver
2021-03-04 18:22                   ` Marco Elver
2021-03-04 18:22                   ` Marco Elver
2021-03-04 18:51                   ` Mark Rutland
2021-03-04 18:51                     ` Mark Rutland
2021-03-04 18:51                     ` Mark Rutland
2021-03-04 19:01                     ` Marco Elver
2021-03-04 19:01                       ` Marco Elver
2021-03-04 19:01                       ` Marco Elver
2021-03-05 12:04                       ` Mark Rutland
2021-03-05 12:04                         ` Mark Rutland
2021-03-05 12:04                         ` Mark Rutland
2021-03-04 21:54         ` Segher Boessenkool
2021-03-04 21:54           ` Segher Boessenkool
2021-03-04 21:54           ` Segher Boessenkool
2021-03-09 16:05           ` Mark Rutland
2021-03-09 16:05             ` Mark Rutland
2021-03-09 16:05             ` Mark Rutland
2021-03-09 22:05             ` Segher Boessenkool
2021-03-09 22:05               ` Segher Boessenkool
2021-03-09 22:05               ` Segher Boessenkool
2021-03-10 11:32               ` Mark Rutland
2021-03-10 11:32                 ` Mark Rutland
2021-03-10 11:32                 ` Mark Rutland
2021-03-10 17:37                 ` Segher Boessenkool
2021-03-10 17:37                   ` Segher Boessenkool
2021-03-10 17:37                   ` Segher Boessenkool

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=20210304192447.GT29191@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=elver@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-toolchains@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mark.rutland@arm.com \
    --cc=ndesaulniers@google.com \
    --cc=paulus@samba.org \
    --cc=will@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 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.