Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755302AbbGWCWl (ORCPT ); Wed, 22 Jul 2015 22:22:41 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:35664 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753651AbbGWCWj (ORCPT ); Wed, 22 Jul 2015 22:22:39 -0400 Subject: Re: [PATCH v2 4/5] bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter To: xiakaixu References: <1437552572-84748-1-git-send-email-xiakaixu@huawei.com> <1437552572-84748-5-git-send-email-xiakaixu@huawei.com> <55B04003.3000904@plumgrid.com> <55B04DA5.6020807@huawei.com> Cc: davem@davemloft.net, acme@kernel.org, mingo@redhat.com, a.p.zijlstra@chello.nl, masami.hiramatsu.pt@hitachi.com, jolsa@kernel.org, wangnan0@huawei.com, linux-kernel@vger.kernel.org, pi3orama@163.com, hekuang@huawei.com From: Alexei Starovoitov Message-ID: <55B04FEB.4090800@plumgrid.com> Date: Wed, 22 Jul 2015 19:22:35 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 In-Reply-To: <55B04DA5.6020807@huawei.com> Content-Type: text/plain; charset=utf-8; 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: 1499 Lines: 45 On 7/22/15 7:12 PM, xiakaixu wrote: > So you mean like this? > > u64 bpf_perf_event_read(u64 r1, u64 index,...) > { > struct bpf_perf_event_array *array = (void *) (long) r1; > struct perf_event *event; > ... > event = array->events[index]; > ... > } yes. the only thing needed is to add: if (index >= array->map.max_entries) return -E2BIG; before accessing array->events[index]; >> > >>> >>+const struct bpf_func_proto bpf_perf_event_read_proto = { >>> >>+ .func = bpf_perf_event_read, >>> >>+ .gpl_only = false, >>> >>+ .ret_type = RET_INTEGER, >>> >>+ .arg1_type = ARG_CONST_MAP_PTR, >>> >>+ .arg2_type = ARG_PTR_TO_MAP_KEY, >> > >> >make it arg2_type = ARG_ANYTHING then you'll just index >> >into array the way prog_array does and similar to bpf_tail_call. > ARG_ANYTHING means any (initialized) argument is ok, but we here correct. > really want is map key. So I'm not sure ARG_ANYTHING is suitable. > You know ARG_ANYTHING is not checked enough in verifier. why? during perf_event_array creation time we check that key_size == u32 so we can accept any integer. ARG_PTR_TO_MAP_KEY forces program author to use stack instead of passing index directly. Direct index is obviously faster. -- 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/