extern const struct bpf_func_proto bpf_map_update_elem_proto;
 extern const struct bpf_func_proto bpf_map_delete_elem_proto;
 
-extern const struct bpf_func_proto bpf_perf_event_read_proto;
 extern const struct bpf_func_proto bpf_get_prandom_u32_proto;
 extern const struct bpf_func_proto bpf_get_smp_processor_id_proto;
 extern const struct bpf_func_proto bpf_tail_call_proto;
 
 
        attr = perf_event_attrs(event);
        if (IS_ERR(attr))
-               return (void *)attr;
+               goto err;
 
-       if (attr->type != PERF_TYPE_RAW &&
-           !(attr->type == PERF_TYPE_SOFTWARE &&
-             attr->config == PERF_COUNT_SW_BPF_OUTPUT) &&
-           attr->type != PERF_TYPE_HARDWARE) {
-               perf_event_release_kernel(event);
-               return ERR_PTR(-EINVAL);
-       }
-       return event;
+       if (attr->inherit)
+               goto err;
+
+       if (attr->type == PERF_TYPE_RAW)
+               return event;
+
+       if (attr->type == PERF_TYPE_HARDWARE)
+               return event;
+
+       if (attr->type == PERF_TYPE_SOFTWARE &&
+           attr->config == PERF_COUNT_SW_BPF_OUTPUT)
+               return event;
+err:
+       perf_event_release_kernel(event);
+       return ERR_PTR(-EINVAL);
 }
 
 static void perf_event_fd_array_put_ptr(void *ptr)
 
        if (!event)
                return -ENOENT;
 
+       /* make sure event is local and doesn't have pmu::count */
+       if (event->oncpu != smp_processor_id() ||
+           event->pmu->count)
+               return -EINVAL;
+
        /*
         * we don't know if the function is run successfully by the
         * return value. It can be judged in other places, such as
        return perf_event_read_local(event);
 }
 
-const struct bpf_func_proto bpf_perf_event_read_proto = {
+static const struct bpf_func_proto bpf_perf_event_read_proto = {
        .func           = bpf_perf_event_read,
        .gpl_only       = false,
        .ret_type       = RET_INTEGER,