From: Eduard Zingerman <eddyz87@gmail.com>
To: Vadim Fedorenko <vadim.fedorenko@linux.dev>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>, X86 ML <x86@kernel.org>,
bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next 1/2] bpf: add bpf_get_hw_counter kfunc
Date: Thu, 24 Oct 2024 10:31:28 -0700 [thread overview]
Message-ID: <b83c12777cd1980c16da363097aeb8ef6a1def91.camel@gmail.com> (raw)
In-Reply-To: <4d7f00e6-8fab-4274-8121-620820b99f02@linux.dev>
On Thu, 2024-10-24 at 14:11 +0100, Vadim Fedorenko wrote:
[...]
> > > @@ -20396,6 +20398,15 @@ static int fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
> > > desc->func_id == special_kfunc_list[KF_bpf_rdonly_cast]) {
> > > insn_buf[0] = BPF_MOV64_REG(BPF_REG_0, BPF_REG_1);
> > > *cnt = 1;
> > > + } else if (IS_ENABLED(CONFIG_X86) &&
> >
> > It's better to introduce bpf_jit_inlines_kfunc_call()
> > similar to bpf_jit_inlines_helper_call().
>
> Yep, I thought about introducing it while adding more architectures, but
> can do it from the beginning.
After thinking a bit more, I think I messed up in a private discussion
with Vadim. It is necessary to introduce bpf_jit_inlines_kfunc_call()
and use it in the mark_fastcall_pattern_for_call(),
otherwise the following situation is possible:
- the program is executed on the arch where inlining for
bpf_get_hw_counter() is not implemented;
- there is a pattern in the code:
r1 = *(u64 *)(r10 - 256);
call bpf_get_hw_fastcall
*(u64 *)(r10 - 256) = r1;
... r10 - 8 is not used ...
... r1 is read ...
- mark_fastcall_pattern_for_call() would mark spill and fill as
members of the pattern;
- fastcall contract is not violated, because reserved stack slots are
used as expected;
- remove_fastcall_spills_fills() would remove spill and fill:
call bpf_get_hw_fastcall
... r1 is read ...
- since call is not transformed to instructions by a specific jit the
value of r1 would be clobbered, making the program invalid.
Vadim, sorry I did not point this out earlier, I thought that fastcall
contract ensuring logic would handle everything.
[...]
next prev parent reply other threads:[~2024-10-24 17:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 21:04 [PATCH bpf-next 1/2] bpf: add bpf_get_hw_counter kfunc Vadim Fedorenko
2024-10-23 21:04 ` [PATCH bpf-next 2/2] selftests/bpf: add selftest to check rdtsc jit Vadim Fedorenko
2024-10-24 1:39 ` [PATCH bpf-next 1/2] bpf: add bpf_get_hw_counter kfunc Alexei Starovoitov
2024-10-24 13:11 ` Vadim Fedorenko
2024-10-24 17:03 ` Alexei Starovoitov
2024-10-24 17:31 ` Eduard Zingerman [this message]
2024-10-24 17:47 ` Eduard Zingerman
2024-10-24 16:03 ` kernel test robot
2024-10-24 16:13 ` kernel test robot
2024-10-24 16:13 ` kernel test robot
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=b83c12777cd1980c16da363097aeb8ef6a1def91.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=tglx@linutronix.de \
--cc=vadim.fedorenko@linux.dev \
--cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox