From: Yonghong Song <yhs@fb.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Joe Burton <jevburton.kernel@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Network Development <netdev@vger.kernel.org>,
bpf <bpf@vger.kernel.org>, Petar Penkov <ppenkov@google.com>,
Stanislav Fomichev <sdf@google.com>,
Joe Burton <jevburton@google.com>
Subject: Re: [RFC PATCH v3 0/3] Introduce BPF map tracing capability
Date: Thu, 4 Nov 2021 10:11:31 -0700 [thread overview]
Message-ID: <71771c37-5e97-54e6-0d98-73878f3b74d5@fb.com> (raw)
In-Reply-To: <CAADnVQK6kMbX379dy5XOo1s7DricX1z9WZ04PhUD6DoEPO+jsg@mail.gmail.com>
On 11/4/21 9:14 AM, Alexei Starovoitov wrote:
> On Wed, Nov 3, 2021 at 9:23 PM Yonghong Song <yhs@fb.com> wrote:
>>
>> asm("") indeed helped preserve the call.
>>
>> [$ ~/tmp2] cat t.c
>> int __attribute__((noinline)) foo() { asm(""); return 1; }
>> int bar() { return foo() + foo(); }
>> [$ ~/tmp2] clang -O2 -c t.c
>> [$ ~/tmp2] llvm-objdump -d t.o
>>
>> t.o: file format elf64-x86-64
>>
>> Disassembly of section .text:
>>
>> 0000000000000000 <foo>:
>> 0: b8 01 00 00 00 movl $1, %eax
>> 5: c3 retq
>> 6: 66 2e 0f 1f 84 00 00 00 00 00 nopw %cs:(%rax,%rax)
>>
>> 0000000000000010 <bar>:
>> 10: 50 pushq %rax
>> 11: e8 00 00 00 00 callq 0x16 <bar+0x6>
>> 16: e8 00 00 00 00 callq 0x1b <bar+0xb>
>> 1b: b8 02 00 00 00 movl $2, %eax
>> 20: 59 popq %rcx
>> 21: c3 retq
>> [$ ~/tmp2]
>>
>> Note with asm(""), foo() is called twice, but the compiler optimization
>> knows foo()'s return value is 1 so it did calculation at compiler time,
>> assign the 2 to %eax and returns.
>
> Missed %eax=2 part...
> That means that asm("") is not enough.
> Maybe something like:
> int __attribute__((noinline)) foo()
> {
> int ret = 0;
> asm volatile("" : "=r"(var) : "0"(var));
asm volatile("" : "=r"(ret) : "0"(ret));
> return ret;
> }
Right. We should prevent compilers from "inlining" return values.
next prev parent reply other threads:[~2021-11-04 17:12 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-02 2:14 [RFC PATCH v3 0/3] Introduce BPF map tracing capability Joe Burton
2021-11-02 2:14 ` [RFC PATCH v3 1/3] bpf: Add map tracing functions and call sites Joe Burton
2021-11-02 2:14 ` [RFC PATCH v3 2/3] bpf: Add selftests Joe Burton
2021-11-04 6:32 ` Hou Tao
2021-11-09 18:17 ` Joe Burton
2021-11-02 2:14 ` [RFC PATCH v3 3/3] bpf: Add real world example for map tracing Joe Burton
2021-11-03 0:12 ` [RFC PATCH v3 0/3] Introduce BPF map tracing capability Alexei Starovoitov
2021-11-03 17:29 ` Yonghong Song
2021-11-03 17:45 ` Joe Burton
2021-11-03 17:49 ` Alexei Starovoitov
2021-11-04 4:23 ` Yonghong Song
2021-11-04 4:27 ` Alexei Starovoitov
2021-11-04 16:14 ` Alexei Starovoitov
2021-11-04 17:11 ` Yonghong Song [this message]
2021-11-03 10:34 ` Jamal Hadi Salim
2021-11-03 17:12 ` Joe Burton
2021-11-04 10:59 ` Jamal Hadi Salim
2021-11-04 11:08 ` Jamal Hadi Salim
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=71771c37-5e97-54e6-0d98-73878f3b74d5@fb.com \
--to=yhs@fb.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jevburton.kernel@gmail.com \
--cc=jevburton@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=ppenkov@google.com \
--cc=sdf@google.com \
--cc=songliubraving@fb.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).