Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753482AbbGWBKc (ORCPT ); Wed, 22 Jul 2015 21:10:32 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:32428 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752033AbbGWBKb (ORCPT ); Wed, 22 Jul 2015 21:10:31 -0400 Message-ID: <55B03E99.7000803@huawei.com> Date: Thu, 23 Jul 2015 09:08:41 +0800 From: "Wangnan (F)" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Alexei Starovoitov , Kaixu Xia , , , , , , CC: , , Subject: Re: [PATCH v2 1/5] bpf: Add new bpf map type to store the pointer to struct perf_event References: <1437552572-84748-1-git-send-email-xiakaixu@huawei.com> <1437552572-84748-2-git-send-email-xiakaixu@huawei.com> <55B039F7.8060706@plumgrid.com> In-Reply-To: <55B039F7.8060706@plumgrid.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.111.66.109] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2493 Lines: 71 On 2015/7/23 8:48, Alexei Starovoitov wrote: > On 7/22/15 1:09 AM, Kaixu Xia wrote: >> Introduce a new bpf map type 'BPF_MAP_TYPE_PERF_EVENT_ARRAY'. >> This map will only store the pointer to struct perf_event. >> >> Signed-off-by: Kaixu Xia >> --- >> include/linux/bpf.h | 2 ++ >> include/uapi/linux/bpf.h | 1 + >> kernel/bpf/arraymap.c | 40 ++++++++++++++++++++++++++++++++++++++++ >> 3 files changed, 43 insertions(+) >> >> diff --git a/include/linux/bpf.h b/include/linux/bpf.h >> index 4383476..f6a2442 100644 >> --- a/include/linux/bpf.h >> +++ b/include/linux/bpf.h >> @@ -11,6 +11,8 @@ >> #include >> #include >> >> +#define MAX_PERF_EVENT_ARRAY_ENTRY (2*NR_CPUS) > > why this artificial limit? > Just drop it. > Then we should find another way to prevent user create a large map but only use a small portion of it, since normal array map can't report whether a slot is used or not. When releasing the map, we have to release each perf event. Currently the only way is to check map value in each slot. >> +static struct bpf_map *perf_event_array_map_alloc(union bpf_attr *attr) >> +{ >> + /* only the pointer to struct perf_event can be stored in >> + * perf_event_array map >> + */ >> + if (attr->value_size != sizeof(void *)) >> + return ERR_PTR(-EINVAL); > > hmm. that's odd. why reinvent things? please do the same as > prog_array does. Namely below: > >> +static const struct bpf_map_ops perf_event_array_ops = { >> + .map_alloc = perf_event_array_map_alloc, >> + .map_free = array_map_free, >> + .map_get_next_key = perf_event_array_map_get_next_key, >> + .map_lookup_elem = array_map_lookup_elem, >> + .map_delete_elem = array_map_delete_elem, > > this is broken. you don't want programs to manipulate > 'struct perf_event *' pointers. > lookup/update/delete helpers shouldn't be accessible from the programs > then update/delete can be cleanly implemented and called via syscall. > See how prog_array does it. > > Also please collapse patches 1-3 into one. Their logically one piece. > I'll comment on them as well, but it would have been easier for me > and you if their were part of one email thread. > -- 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/