From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexei Starovoitov Subject: Re: [PATCH V3 2/2] bpf: control all the perf events stored in PERF_EVENT_ARRAY maps Date: Fri, 16 Oct 2015 15:12:20 -0700 Message-ID: <56217644.2060707@plumgrid.com> References: <1444981333-70429-1-git-send-email-xiakaixu@huawei.com> <1444981333-70429-3-git-send-email-xiakaixu@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Cc: wangnan0@huawei.com, linux-kernel@vger.kernel.org, pi3orama@163.com, hekuang@huawei.com, netdev@vger.kernel.org To: Kaixu Xia , davem@davemloft.net, acme@kernel.org, mingo@redhat.com, a.p.zijlstra@chello.nl, masami.hiramatsu.pt@hitachi.com, jolsa@kernel.org, daniel@iogearbox.net Return-path: In-Reply-To: <1444981333-70429-3-git-send-email-xiakaixu@huawei.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: netdev.vger.kernel.org On 10/16/15 12:42 AM, Kaixu Xia wrote: > This patch implements the function that controlling all the perf > events stored in PERF_EVENT_ARRAY maps by setting the parameter > 'index' to maps max_entries. > > Signed-off-by: Kaixu Xia > --- > kernel/trace/bpf_trace.c | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > index 3175600..4b385863 100644 > --- a/kernel/trace/bpf_trace.c > +++ b/kernel/trace/bpf_trace.c > @@ -229,13 +229,30 @@ static u64 bpf_perf_event_dump_control(u64 r1, u64 index, u64 flag, u64 r4, u64 > struct bpf_map *map = (struct bpf_map *) (unsigned long) r1; > struct bpf_array *array = container_of(map, struct bpf_array, map); > struct perf_event *event; > + int i; > > - if (unlikely(index >= array->map.max_entries)) > + if (unlikely(index > array->map.max_entries)) > return -E2BIG; > > if (flag & BIT_FLAG_CHECK) > return -EINVAL; > > + if (index == array->map.max_entries) { I don't like in-band signaling like this, since it's easy to make mistake on the bpf program side. Please use 2nd bit of 'flags' for that instead. Also squash this patch into 1st.