From: "H. Peter Anvin" <hpa@zytor.com>
To: Helge Deller <deller@gmx.de>,
Nick Desaulniers <ndesaulniers@google.com>,
torvalds@linux-foundation.org, akpm@linux-foundation.org
Cc: "Nicolas Pitre" <nicolas.pitre@linaro.org>,
linux-mips@linux-mips.org, linux-sh@vger.kernel.org,
"Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
"Will Deacon" <will.deacon@arm.com>,
"Paul Mackerras" <paulus@samba.org>,
"Michael Ellerman" <mpe@ellerman.id.au>,
"James E.J. Bottomley" <jejb@parisc-linux.org>,
"Geert Uytterhoeven" <geert@linux-m68k.org>,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Vasily Gorbik" <gor@linux.vnet.ibm.com>,
"Matt Turner" <mattst88@gmail.com>,
uclinux-h8-devel@lists.sourceforge.jp,
"Marc Zyngier" <marc.zyngier@arm.com>,
"Ram Pai" <linuxram@us.ibm.com>,
linux-um@lists.infradead.org,
"Nicholas Piggin" <npiggin@gmail.com>,
"Andy Lutomirski" <luto@kernel.org>,
"Shannon Nelson" <shannon.nelson@oracle.com>,
tglx@linutronix.de, "Alex Bennée" <alex.bennee@linaro.org>,
"Richard Henderson" <rth@twiddle.net>,
"Jiri Kosina" <jkosina@suse.cz>,
linux-kernel@vger.kerne
Subject: Re: [PATCH] treewide: remove current_text_addr
Date: Sun, 26 Aug 2018 16:20:19 -0700 [thread overview]
Message-ID: <e425d208-214b-06a2-a032-7442a10388fc@zytor.com> (raw)
In-Reply-To: <6ca8a1d3-ff95-e9f4-f003-0a5af85bcb6f@zytor.com>
On 08/26/18 12:30, H. Peter Anvin wrote:
> Here is a full-blown (user space) test program demonstrating the whole
> technique and how to use it.
>
> -hpa
Incidentally, it looks like _RET_IP_ really should be defined as:
/*
* Is there any reason whatsoever to have _RET_IP_ an unsigned int
* rather than a pointer throughout?
*/
#define _RET_IP_PTR_ \
__builtin_extract_return_addr(__builtin_return_addr(0))
#define _RET_IP_ ((unsigned long)_RET_IP_PTR_)
On some architectures __builtin_extract_return_addr() is apparently
necessary; its a nop on x86. Why that isn't part of
__builtin_return_addr() one can really wonder.
So, checking into all of this, the generic _THIS_IP_ DOES NOT WORK on
x86. I have tried a tons of variants, including adding various asm
volatile(...) instructions, and no matter what I do, it will always
return the address of the surrounding function rather than any kind of
local IP. The only way to get a localized address seems to be in
assembly, but even so, there is absolutely no guarantee that the value
of _THIS_IP_ has anything to do with where the code is otherwise
localized in the function.
>From examining the output of gcc, the fundamental problem seems to be
that *no matter what* one do with the label, unless gcc actually
produces a computed goto somewhere in the code, that it can't remove
with dead-code elimination or constant propagation, it will arbitrarily
hoist the labels all the way to the beginning of the function. Given
that, I suspect that other versions of gcc might have similar problems.
This is the closest thing to arch-neutral I have been able to find that
also works on x86, while not at the same time horribly polluting the
namespace:
#define __here(n) ___here_ ## n
#define __hereasm(n) ".L___here_" #n
#define _THIS_IP_CTR_(n) \
({ \
extern const char __here(n) asm(__hereasm(n)); \
asm volatile(__hereasm(n) ": /* _THIS_IP_ */"); \
(unsigned long)&__here(n); \
})
#define _THIS_IP_ _THIS_IP_CTR_(__COUNTER__)
The use of asm volatile() to define a label means that the position in
the instruction stream is at least reasonably well-defined.
-hpa
prev parent reply other threads:[~2018-08-26 23:20 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
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 [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=e425d208-214b-06a2-a032-7442a10388fc@zytor.com \
--to=hpa@zytor.com \
--cc=akpm@linux-foundation.org \
--cc=alex.bennee@linaro.org \
--cc=benh@kernel.crashing.org \
--cc=catalin.marinas@arm.com \
--cc=deller@gmx.de \
--cc=geert@linux-m68k.org \
--cc=gor@linux.vnet.ibm.com \
--cc=jejb@parisc-linux.org \
--cc=jkosina@suse.cz \
--cc=linux-kernel@vger.kerne \
--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=paulus@samba.org \
--cc=rth@twiddle.net \
--cc=shannon.nelson@oracle.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--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;
as well as URLs for NNTP newsgroup(s).