From: Daniel Borkmann <daniel@iogearbox.net>
To: Peter Zijlstra <peterz@infradead.org>, Alexei Starovoitov <ast@fb.com>
Cc: "David S . Miller" <davem@davemloft.net>,
Brendan Gregg <bgregg@netflix.com>,
Arnaldo Carvalho de Melo <acme@infradead.org>,
Wang Nan <wangnan0@huawei.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@fb.com
Subject: Re: [PATCH v2 net-next 2/6] bpf: introduce BPF_PROG_TYPE_PERF_EVENT program type
Date: Thu, 01 Sep 2016 10:33:59 +0200 [thread overview]
Message-ID: <57C7E7F7.5090304@iogearbox.net> (raw)
In-Reply-To: <20160901074452.GK10153@twins.programming.kicks-ass.net>
On 09/01/2016 09:44 AM, Peter Zijlstra wrote:
> On Wed, Aug 31, 2016 at 02:50:39PM -0700, Alexei Starovoitov wrote:
>> +static u32 pe_prog_convert_ctx_access(enum bpf_access_type type, int dst_reg,
>> + int src_reg, int ctx_off,
>> + struct bpf_insn *insn_buf,
>> + struct bpf_prog *prog)
>> +{
>> + struct bpf_insn *insn = insn_buf;
>> +
>> + BUILD_BUG_ON(FIELD_SIZEOF(struct perf_sample_data, period) != sizeof(u64));
>> + switch (ctx_off) {
>> + case offsetof(struct bpf_perf_event_data, sample_period):
>> + *insn++ = BPF_LDX_MEM(bytes_to_bpf_size(FIELD_SIZEOF(struct bpf_perf_event_data_kern, data)),
>> + dst_reg, src_reg,
>> + offsetof(struct bpf_perf_event_data_kern, data));
>> + *insn++ = BPF_LDX_MEM(BPF_DW, dst_reg, dst_reg,
>> + offsetof(struct perf_sample_data, period));
>> + break;
>
> OK, so that deals with us moving the period field in the structure, and
> break compile if we'd change its size or remove it outright (highly
> unlikely). In that latter case we can change this code to simply return
> a (u64)0 and things would continue to 'work'.
>
> Did I understand that correctly?
Yes, if a program accesses sample_period member of the struct bpf_perf_event_data
context, then the verifier rewrites this into above two loads to eventually fetch
the struct perf_sample_data's period to the given target register. As you said,
should the period field change size (or get removed), compilation would break
so this doesn't get unnoticed and the code can be adapted along with it. In the
(hopefully very unlikely) case the member gets removed, it could be replaced with
loading 0 (or some other, better workaround to derive it, if possible).
next prev parent reply other threads:[~2016-09-01 8:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-31 21:50 [PATCH v2 net-next 0/6] perf, bpf: add support for bpf in sw/hw perf_events Alexei Starovoitov
2016-08-31 21:50 ` [PATCH v2 net-next 1/6] bpf: support 8-byte metafield access Alexei Starovoitov
2016-08-31 21:50 ` [PATCH v2 net-next 2/6] bpf: introduce BPF_PROG_TYPE_PERF_EVENT program type Alexei Starovoitov
2016-09-01 7:44 ` Peter Zijlstra
2016-09-01 8:33 ` Daniel Borkmann [this message]
2016-08-31 21:50 ` [PATCH v2 net-next 3/6] bpf: perf_event progs should only use preallocated maps Alexei Starovoitov
2016-08-31 21:50 ` [PATCH v2 net-next 4/6] perf, bpf: add perf events core support for BPF_PROG_TYPE_PERF_EVENT programs Alexei Starovoitov
2016-09-01 8:12 ` Peter Zijlstra
2016-09-01 15:53 ` Alexei Starovoitov
2016-09-01 16:37 ` Peter Zijlstra
2016-08-31 21:50 ` [PATCH v2 net-next 5/6] samples/bpf: add perf_event+bpf example Alexei Starovoitov
2016-08-31 21:50 ` [PATCH v2 net-next 6/6] samples/bpf: add sampleip example Alexei Starovoitov
2016-09-01 0:18 ` [PATCH v2 net-next 0/6] perf, bpf: add support for bpf in sw/hw perf_events Brendan Gregg
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=57C7E7F7.5090304@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=acme@infradead.org \
--cc=ast@fb.com \
--cc=bgregg@netflix.com \
--cc=davem@davemloft.net \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=wangnan0@huawei.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