Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1945956AbbGQKpY (ORCPT ); Fri, 17 Jul 2015 06:45:24 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:32602 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757693AbbGQKpU (ORCPT ); Fri, 17 Jul 2015 06:45:20 -0400 From: kaixu xia To: , , , , , , CC: , , , , Subject: [RFC PATCH 4/6] bpf: Add a bpf program function argument constraint for PMU map Date: Fri, 17 Jul 2015 18:43:34 +0800 Message-ID: <1437129816-13176-5-git-send-email-xiakaixu@huawei.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1437129816-13176-1-git-send-email-xiakaixu@huawei.com> References: <1437129816-13176-1-git-send-email-xiakaixu@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.110.52.33] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2948 Lines: 71 For the pmu that contains the pointer to struct perf_event, add the corresponding bpf program function argument constraint 'ARG_PTR_TO_MAP_PERF_EVENT_VALUE'. Signed-off-by: kaixu xia --- include/linux/bpf.h | 1 + kernel/bpf/verifier.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index f593199..31a93fc 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -56,6 +56,7 @@ enum bpf_arg_type { ARG_CONST_MAP_PTR, /* const argument used as pointer to bpf_map */ ARG_PTR_TO_MAP_KEY, /* pointer to stack used as map key */ ARG_PTR_TO_MAP_VALUE, /* pointer to stack used as map value */ + ARG_PTR_TO_MAP_PERF_EVENT_VALUE, /* pointer to stack used as map pmu value */ /* the following constraints used to prototype bpf_memcmp() and other * functions that access data on eBPF program stack diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 039d866..a04223b 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -132,6 +132,7 @@ enum bpf_reg_type { PTR_TO_CTX, /* reg points to bpf_context */ CONST_PTR_TO_MAP, /* reg points to struct bpf_map */ PTR_TO_MAP_VALUE, /* reg points to map element value */ + PTR_TO_PTR_PERF_EVENT, /* reg points to map element pmu value */ PTR_TO_MAP_VALUE_OR_NULL,/* points to map elem value or NULL */ FRAME_PTR, /* reg == frame_pointer */ PTR_TO_STACK, /* reg == frame_pointer + imm */ @@ -769,6 +770,8 @@ static int check_func_arg(struct verifier_env *env, u32 regno, if (arg_type == ARG_PTR_TO_STACK || arg_type == ARG_PTR_TO_MAP_KEY || arg_type == ARG_PTR_TO_MAP_VALUE) { expected_type = PTR_TO_STACK; + } else if (arg_type == ARG_PTR_TO_MAP_PERF_EVENT_VALUE) { + expected_type = PTR_TO_PTR_PERF_EVENT; } else if (arg_type == ARG_CONST_STACK_SIZE) { expected_type = CONST_IMM; } else if (arg_type == ARG_CONST_MAP_PTR) { @@ -817,6 +820,9 @@ static int check_func_arg(struct verifier_env *env, u32 regno, } err = check_stack_boundary(env, regno, (*mapp)->value_size); + } else if (arg_type == ARG_PTR_TO_MAP_PERF_EVENT_VALUE) { + /* check for ARG_PTR_TO_MAP_PERF_EVENT_VALUE has been done before*/ + } else if (arg_type == ARG_CONST_STACK_SIZE) { /* bpf_xxx(..., buf, len) call will access 'len' bytes * from stack pointer 'buf'. Check it @@ -902,6 +908,9 @@ static int check_call(struct verifier_env *env, int func_id) return -EINVAL; } regs[BPF_REG_0].map_ptr = map; + + if (map->flags & BPF_MAP_FLAG_PERF_EVENT) + regs[BPF_REG_0].type = PTR_TO_PTR_PERF_EVENT; } else { verbose("unknown return type %d of func %d\n", fn->ret_type, func_id); -- 1.7.10.4 -- 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/