Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1197180

Re: [PATCH v5 3/4] bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter

From Alexei Starovoitov <ast@plumgrid.com>
Newsgroups linux.kernel
Subject Re: [PATCH v5 3/4] bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter
Date 2015-07-31 18:50 +0200
Message-ID <pSlFo-33y-5@gated-at.bofh.it> (permalink)
References <pShip-53l-5@gated-at.bofh.it> <pShip-53l-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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/

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

Re: [PATCH v5 3/4] bpf: Implement function bpf_perf_event_read() that  get the selected hardware PMU conuter Alexei Starovoitov <ast@plumgrid.com> - 2015-07-31 18:50 +0200

csiph-web