[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ebd61ee8-ef18-c00c-f909-9d74002bd9a0@fb.com>
Date: Sat, 14 Sep 2019 18:23:43 +0000
From: Yonghong Song <yhs@...com>
To: KP Singh <kpsingh@...omium.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"bpf@...r.kernel.org" <bpf@...r.kernel.org>,
"linux-security-module@...r.kernel.org"
<linux-security-module@...r.kernel.org>
CC: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
James Morris <jmorris@...ei.org>,
Kees Cook <keescook@...omium.org>,
Thomas Garnier <thgarnie@...omium.org>,
"Michael Halcrow" <mhalcrow@...gle.com>,
Paul Turner <pjt@...gle.com>,
Brendan Gregg <brendan.d.gregg@...il.com>,
Jann Horn <jannh@...gle.com>,
Matthew Garrett <mjg59@...gle.com>,
Christian Brauner <christian@...uner.io>,
Mickaël Salaün <mic@...ikod.net>,
Florent Revest <revest@...omium.org>,
Martin Lau <kafai@...com>, Song Liu <songliubraving@...com>,
"Serge E. Hallyn" <serge@...lyn.com>,
"Mauro Carvalho Chehab" <mchehab+samsung@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Nicolas Ferre <nicolas.ferre@...rochip.com>,
Stanislav Fomichev <sdf@...gle.com>,
"Quentin Monnet" <quentin.monnet@...ronome.com>,
Andrey Ignatov <rdna@...com>, "Joe Stringer" <joe@...d.net.nz>
Subject: Re: [RFC v1 09/14] krsi: Add a helper function for
bpf_perf_event_output
On 9/10/19 12:55 PM, KP Singh wrote:
> From: KP Singh <kpsingh@...gle.com>
>
> This helper is mapped to the existing operation
> BPF_FUNC_perf_event_output.
>
> An example usage of this function would be:
>
> #define BUF_SIZE 64;
>
> struct bpf_map_def SEC("maps") perf_map = {
> .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
> .key_size = sizeof(int),
> .value_size = sizeof(u32),
> .max_entries = MAX_CPUS,
> };
could you use a map definition similar to
tools/testing/selftests/bpf/progs/test_perf_buffer.c?
struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__uint(key_size, sizeof(int));
__uint(value_size, sizeof(u32));
} perf_map SEC(".maps");
>
> SEC("krsi")
> int bpf_prog1(void *ctx)
> {
> char buf[BUF_SIZE];
> int len;
> u64 flags = BPF_F_CURRENT_CPU;
>
> /* some logic that fills up buf with len data*/
> len = fill_up_buf(buf);
> if (len < 0)
> return len;
> if (len > BU)
BUF_SIZE?
> return 0;
>
> bpf_perf_event_output(ctx, &perf_map, flags, buf len);
buf, len?
> return 0;
> }
>
> A sample program that showcases the use of bpf_perf_event_output is
> added later.
>
> Signed-off-by: KP Singh <kpsingh@...gle.com>
> ---
> security/krsi/ops.c | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/security/krsi/ops.c b/security/krsi/ops.c
> index a61508b7018f..57bd304a03f4 100644
> --- a/security/krsi/ops.c
> +++ b/security/krsi/ops.c
> @@ -111,6 +111,26 @@ static bool krsi_prog_is_valid_access(int off, int size,
> return false;
> }
>
> +BPF_CALL_5(krsi_event_output, void *, log,
Maybe name the first argument as 'ctx' to follow typical helper convention?
> + struct bpf_map *, map, u64, flags, void *, data, u64, size)
> +{
> + if (unlikely(flags & ~(BPF_F_INDEX_MASK)))
> + return -EINVAL;
> +
> + return bpf_event_output(map, flags, data, size, NULL, 0, NULL);
> +}
> +
> +static const struct bpf_func_proto krsi_event_output_proto = {
> + .func = krsi_event_output,
> + .gpl_only = true,
> + .ret_type = RET_INTEGER,
> + .arg1_type = ARG_PTR_TO_CTX,
> + .arg2_type = ARG_CONST_MAP_PTR,
> + .arg3_type = ARG_ANYTHING,
> + .arg4_type = ARG_PTR_TO_MEM,
> + .arg5_type = ARG_CONST_SIZE_OR_ZERO,
> +};
> +
> static const struct bpf_func_proto *krsi_prog_func_proto(enum bpf_func_id
> func_id,
> const struct bpf_prog
> @@ -121,6 +141,8 @@ static const struct bpf_func_proto *krsi_prog_func_proto(enum bpf_func_id
> return &bpf_map_lookup_elem_proto;
> case BPF_FUNC_get_current_pid_tgid:
> return &bpf_get_current_pid_tgid_proto;
> + case BPF_FUNC_perf_event_output:
> + return &krsi_event_output_proto;
> default:
> return NULL;
> }
>
Powered by blists - more mailing lists