Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755488AbbHDRnk (ORCPT ); Tue, 4 Aug 2015 13:43:40 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:33302 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754704AbbHDRni (ORCPT ); Tue, 4 Aug 2015 13:43:38 -0400 Subject: Re: [PATCH v6 2/4] bpf: Add new bpf map type to store the pointer to struct perf_event 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: <1438678696-88289-1-git-send-email-xiakaixu@huawei.com> <1438678696-88289-3-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: <55C0F9C7.6070901@plumgrid.com> Date: Tue, 4 Aug 2015 10:43:35 -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: <1438678696-88289-3-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: 1350 Lines: 46 On 8/4/15 1:58 AM, Kaixu Xia wrote: > diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c > index 45df657..b1e98ff 100644 > --- a/kernel/bpf/arraymap.c > +++ b/kernel/bpf/arraymap.c > @@ -273,3 +273,60 @@ static int __init register_prog_array_map(void) > return 0; > } > late_initcall(register_prog_array_map); > + > +static void perf_event_array_map_free(struct bpf_map *map) > +{ > + bpf_fd_array_map_clear(map); > + fd_array_map_free(map); > +} > + > +static void *perf_event_fd_array_get_ptr(struct bpf_map *map, int fd) > +{ > + struct perf_event *event; > + struct perf_event_attr *attr; > + > + event = perf_event_get(fd); > + if (IS_ERR(event)) > + return event; > + > + attr = perf_event_attrs(event); > + if (IS_ERR(attr)) > + return attr; > + > + if (attr->type != PERF_TYPE_RAW && > + attr->type != PERF_TYPE_HARDWARE) { > + perf_event_release_kernel(event); > + return ERR_PTR(-EINVAL); > + } > + return event; > +} I'm not sure whether Peter wanted to see the above function to be in events/core.c or not. imo it's fine here, since perf_event_attr is an uapi struct. -- 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/