linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <ast@plumgrid.com>
To: Kaixu Xia <xiakaixu@huawei.com>,
	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
Cc: wangnan0@huawei.com, linux-kernel@vger.kernel.org,
	pi3orama@163.com, hekuang@huawei.com, netdev@vger.kernel.org
Subject: Re: [PATCH v5 3/4] bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter
Date: Fri, 31 Jul 2015 09:43:45 -0700	[thread overview]
Message-ID: <55BBA5C1.1080403@plumgrid.com> (raw)
In-Reply-To: <1438343970-11974-4-git-send-email-xiakaixu@huawei.com>

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?


  reply	other threads:[~2015-07-31 16:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-31 11:59 [PATCH v5 0/4] bpf: Introduce the new ability of eBPF programs to access hardware PMU counter Kaixu Xia
2015-07-31 11:59 ` [PATCH v5 1/4] bpf: Make the bpf_prog_array_map more generic Kaixu Xia
2015-07-31 16:36   ` Alexei Starovoitov
2015-07-31 11:59 ` [PATCH v5 2/4] bpf: Add new bpf map type to store the pointer to struct perf_event Kaixu Xia
2015-07-31 16:39   ` Alexei Starovoitov
2015-07-31 11:59 ` [PATCH v5 3/4] bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter Kaixu Xia
2015-07-31 16:43   ` Alexei Starovoitov [this message]
2015-07-31 11:59 ` [PATCH v5 4/4] samples/bpf: example of get selected PMU counter value Kaixu Xia
2015-07-31 16:33 ` [PATCH v5 0/4] bpf: Introduce the new ability of eBPF programs to access hardware PMU counter Alexei Starovoitov

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=55BBA5C1.1080403@plumgrid.com \
    --to=ast@plumgrid.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=hekuang@huawei.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pi3orama@163.com \
    --cc=wangnan0@huawei.com \
    --cc=xiakaixu@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;
as well as URLs for NNTP newsgroup(s).