Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753277AbbGaQnt (ORCPT ); Fri, 31 Jul 2015 12:43:49 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:33431 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753128AbbGaQnr (ORCPT ); Fri, 31 Jul 2015 12:43:47 -0400 Subject: Re: [PATCH v5 3/4] bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter 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 References: <1438343970-11974-1-git-send-email-xiakaixu@huawei.com> <1438343970-11974-4-git-send-email-xiakaixu@huawei.com> Cc: wangnan0@huawei.com, linux-kernel@vger.kernel.org, pi3orama@163.com, hekuang@huawei.com, netdev@vger.kernel.org From: Alexei Starovoitov Message-ID: <55BBA5C1.1080403@plumgrid.com> Date: Fri, 31 Jul 2015 09:43:45 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <1438343970-11974-4-git-send-email-xiakaixu@huawei.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1736 Lines: 48 On 7/31/15 4:59 AM, Kaixu Xia wrote: > +static int check_func_limit(struct bpf_map **mapp, int func_id) > +{ > + struct bpf_map *map = *mapp; > + > + if (map && map->map_type == BPF_MAP_TYPE_PROG_ARRAY && > + func_id != BPF_FUNC_tail_call) > + /* prog_array map type needs extra care: > + * only allow to pass it into bpf_tail_call() for now. > + * bpf_map_delete_elem() can be allowed in the future, > + * while bpf_map_update_elem() must only be done via syscall > + */ > + return -EINVAL; > + > + if (func_id == BPF_FUNC_tail_call && > + map->map_type != BPF_MAP_TYPE_PROG_ARRAY) > + /* don't allow any other map type to be passed into > + * bpf_tail_call() > + */ > + return -EINVAL; > + > + if (map && map->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY && > + func_id != BPF_FUNC_perf_event_read) > + /* perf_event_array map type needs extra care: > + * only allow to pass it into bpf_perf_event_read() for now. > + * bpf_map_update/delete_elem() must only be done via syscall > + */ > + return -EINVAL; > + > + if (func_id == BPF_FUNC_perf_event_read && > + map->map_type != BPF_MAP_TYPE_PERF_EVENT_ARRAY) > + /* don't allow any other map type to be passed into > + * bpf_perf_event_read() > + */ > + return -EINVAL; copy paste of comments is too much. The whole thing probably can be better generalized with an array {{BPF_MAP_TYPE_PROG_ARRAY, BPF_FUNC_tail_call}, {BPF_MAP_TYPE_PERF_EVENT_ARRAY, BPF_FUNC_perf_event_read}, } and a loop? -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/