public inbox for linux-m68k@lists.linux-m68k.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Nick Desaulniers <ndesaulniers@google.com>
Cc: nicolas.pitre@linaro.org, linux-mips@linux-mips.org,
	linux-sh@vger.kernel.org, benh@kernel.crashing.org,
	Will Deacon <will.deacon@arm.com>,
	paulus@samba.org, mpe@ellerman.id.au, jejb@parisc-linux.org,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	gor@linux.vnet.ibm.com, mattst88@gmail.com,
	uclinux-h8-devel@lists.sourceforge.jp,
	Marc Zyngier <marc.zyngier@arm.com>,
	linuxram@us.ibm.com, linux-um@lists.infradead.org,
	Nicholas Piggin <npiggin@gmail.com>,
	luto@kernel.org, shannon.nelson@oracle.com,
	Thomas Gleixner <tglx@linutronix.de>,
	alex.bennee@linaro.org, rth@twiddle.net, jkosina@suse.cz,
	LKML <linux-kernel@vger.kernel.org>,
	ralf@linux-mips.org, rkuo@codeaurora.org, paul.burton@mips.com,
	aneesh.kumar@linux.vnet.ibm.com,
	Greg KH <gregkh@linuxfoundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-f>
Subject: Re: [PATCH] treewide: remove current_text_addr
Date: Mon, 27 Aug 2018 05:26:53 -0700	[thread overview]
Message-ID: <f9896d68-4a49-e666-cea5-a9c0522f1658@zytor.com> (raw)
In-Reply-To: <20180827073358.GV24124@hirez.programming.kicks-ass.net>

On 08/27/18 00:33, Peter Zijlstra wrote:
> 
> What problem are we trying to solve? _THIS_IP_ and _RET_IP_ work fine.
> We're 'good' at dealing with text addresses, we use them for call stacks
> and all sorts. Why does this need changing?
> 

_RET_IP_ works fine, with the following two caveats:

1. To get a unique IP for each call site, the function call needs to be
   tailcall protected (easily done by wrapping the function in an
  __always_inline function with the notailcall() function I described
  earlier.  Alternatively, a generic macro wrapper for the same thing:

  #define notailcall(x) ({ typeof(x) _x = (x); asm volatile("");  _x; })

2. To uniformly get the return IP, it needs to be defined as:

#define _RET_IP_((unsigned long) \
__builtin_extract_return_addr(__builtin_return_address(0)))

[sorry for the line wrapping]

Using the type unsigned long instead of void * seems kind of pointless
though.


_THIS_IP_, however, is completely ill-defined, other than being an
address *somewhere* in the same global function (not even necessarily
the same function if the function is static!)  As my experiment show, in
many (nearly) cases gcc will hoist the address all the way to the top of
the function, at least for the current generic implementation.

For the case where _THIS_IP_ is passed to an out-of-line function in all
cases, it is extra pointless because all it does is increase the
footprint of every caller: _RET_IP_ is inherently passed to the function
anyway, and with tailcall protection it will uniquely identify a callsite.

For the case where _THIS_IP_ is used inline, I believe the version I
described will at the very least avoid hoisting around volatile accesses
like READ_ONCE(). Surrounding the marked code with asm volatile("");
[which should be turned into a macro or inline, obviously] might be
necessary for it to make any kind of inherent sense.

The proposed "location identifier" does have a serious problem: with
inline functions you might very well have a bunch of duplicates pointing
into the inline function, so a single callsite isn't identifiable.

	-hpa

  reply	other threads:[~2018-08-27 12:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAKwvOdkWL_2yTnJqM6n6R9UCPwY4iz-9BQYGN2MDAk9EzumUvA@mail.gmail.com>
     [not found] ` <20180821202900.208417-1-ndesaulniers@google.com>
     [not found]   ` <207784db-4fcc-85e7-a0b2-fec26b7dab81@gmx.de>
2018-08-26  2:38     ` [PATCH] treewide: remove current_text_addr H. Peter Anvin
2018-08-26  3:16       ` H. Peter Anvin
2018-08-26  4:56         ` H. Peter Anvin
2018-08-26 19:30           ` H. Peter Anvin
2018-08-26 20:25             ` Linus Torvalds
2018-08-27  2:52               ` Nick Desaulniers
2018-08-27  7:33                 ` Peter Zijlstra
2018-08-27 12:26                   ` H. Peter Anvin [this message]
2018-08-27 13:11                     ` Peter Zijlstra
2018-08-27 13:33                       ` H. Peter Anvin
2018-08-31 16:48                         ` Nick Desaulniers
2018-08-27  7:43               ` Nicholas Piggin
2018-08-26 23:20             ` H. Peter Anvin

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=f9896d68-4a49-e666-cea5-a9c0522f1658@zytor.com \
    --to=hpa@zytor.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.bennee@linaro.org \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=catalin.marinas@arm.com \
    --cc=geert@linux-m68k.org \
    --cc=gor@linux.vnet.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jejb@parisc-linux.org \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=linuxram@us.ibm.com \
    --cc=luto@kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=mattst88@gmail.com \
    --cc=mpe@ellerman.id.au \
    --cc=ndesaulniers@google.com \
    --cc=nicolas.pitre@linaro.org \
    --cc=npiggin@gmail.com \
    --cc=paul.burton@mips.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=ralf@linux-mips.org \
    --cc=rkuo@codeaurora.org \
    --cc=rth@twiddle.net \
    --cc=shannon.nelson@oracle.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-f \
    --cc=uclinux-h8-devel@lists.sourceforge.jp \
    --cc=will.deacon@arm.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