From: Tero Kristo <tero.kristo@linux.intel.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>
Subject: Re: bpf: RFC for platform specific BPF helper addition
Date: Fri, 24 Feb 2023 13:49:27 +0200 [thread overview]
Message-ID: <f171f10b-f7e5-e63d-b446-b37a2856909a@linux.intel.com> (raw)
In-Reply-To: <CAADnVQJ4fHzqeuhbCF5SDR5V1Ktku=U2RRRPLc17ia0aFgNG=w@mail.gmail.com>
On 23/02/2023 19:46, Alexei Starovoitov wrote:
> On Thu, Feb 23, 2023 at 5:23 AM Tero Kristo <tero.kristo@linux.intel.com> wrote:
>> Hi,
>>
>> Some background first; on x86 platforms there is a free running TSC
>> counter which can be used to generate extremely accurate profiling time
>> stamps. Currently this can be used by BPF programs via hooking into perf
>> subsystem and reading the value there; however this reduces the accuracy
>> due to latency + jitter involved with long execution chain, and also the
>> timebase gets converted into relative from the start of the execution of
>> the program, instead of getting an absolute system level value.
> Are you talking about rdtsc or some other counter?
> Does it need an arch specific setup?
Yes, this is rdtsc. TSC is setup automatically by the arch, but
exporting it to BPF takes a few lines of arch specific code (I did use
register_btf_kfunc_id_set() during init, under arch/x86/kernel/tsc.c.)
>
>> Now, I do have a pretty trivial patch (under internal review atm. at
>> Intel) that adds an x86 platform specific bpf helper that can directly
>> read this timestamp counter without relying to perf subsystem hooks.
>>
>> Do people have any feedback / insights on this list about addition of
>> such platform specific BPF helper, basically thumbs up/down for adding
>> such a thing? Currently I don't think there are any platform specific
>> helpers in the kernel.
> Right. That's one of the reasons we don't add new helpers anymore.
> Please use kfunc instead. You can add it to:
> arch/x86/net/bpf_jit_comp.c
> like:
> __bpf_kfunc u64 bpf_read_rdtsc(void)
> { asm ("...
> or to arch specific kernel module.
>
> Make sure to add selftests when you submit a patch.
Ok, I can take a look at the selftest side if things nudge forward,
however there is some internal pressure to ditch the whole idea of
bpf_rdtsc() due to potential of side channel attacks by using BPF, and
exploiting the accurate timer in the process. Any thoughts on that side?
Using BPF requires root access nowadays so it is sort of on-par to
out-of-tree kernel modules.
-Tero
next prev parent reply other threads:[~2023-02-24 11:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-23 13:20 bpf: RFC for platform specific BPF helper addition Tero Kristo
2023-02-23 17:46 ` Alexei Starovoitov
2023-02-24 11:49 ` Tero Kristo [this message]
2023-02-25 0:01 ` Alexei Starovoitov
2023-02-28 9:45 ` Tero Kristo
2023-03-01 6:04 ` Alexei Starovoitov
2023-03-01 12:06 ` Eduard Zingerman
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=f171f10b-f7e5-e63d-b446-b37a2856909a@linux.intel.com \
--to=tero.kristo@linux.intel.com \
--cc=alexei.starovoitov@gmail.com \
--cc=bpf@vger.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