[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzYt4L7pxKr0ES=-kUd92NMtBPabM2hZW=TrGNARsLnCJA@mail.gmail.com>
Date: Sun, 10 Nov 2019 09:04:58 -0800
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Alexei Starovoitov <ast@...nel.org>
Cc: "David S. Miller" <davem@...emloft.net>,
Daniel Borkmann <daniel@...earbox.net>, x86@...nel.org,
Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
Kernel Team <kernel-team@...com>
Subject: Re: [PATCH v3 bpf-next 18/18] selftests/bpf: Add a test for attaching
BPF prog to another BPF prog and subprog
On Thu, Nov 7, 2019 at 10:43 PM Alexei Starovoitov <ast@...nel.org> wrote:
>
> Add a test that attaches one FEXIT program to main sched_cls networking program
> and two other FEXIT programs to subprograms. All three tracing programs
> access return values and skb->len of networking program and subprograms.
>
> Signed-off-by: Alexei Starovoitov <ast@...nel.org>
> ---
Acked-by: Andrii Nakryiko <andriin@...com>
> .../selftests/bpf/prog_tests/fexit_bpf2bpf.c | 76 ++++++++++++++++
> .../selftests/bpf/progs/fexit_bpf2bpf.c | 91 +++++++++++++++++++
> 2 files changed, 167 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
> create mode 100644 tools/testing/selftests/bpf/progs/fexit_bpf2bpf.c
>
[...]
> +SEC("fexit/test_pkt_access_subprog2")
> +int test_subprog2(struct args_subprog2 *ctx)
> +{
> + struct sk_buff *skb = (void *)ctx->args[0];
> + __u64 ret;
> + int len;
> +
> + bpf_probe_read(&len, sizeof(len),
> + __builtin_preserve_access_index(&skb->len));
nit: we have bpf_core_read() for this, but I suspect you may have
wanted __builtin spelled out explicitly
> +
> + ret = ctx->ret;
> + /* bpf_prog_load() loads "test_pkt_access.o" with BPF_F_TEST_RND_HI32
> + * which randomizes upper 32 bits after BPF_ALU32 insns.
> + * Hence after 'w0 <<= 1' upper bits of $rax are random.
> + * That is expected and correct. Trim them.
> + */
> + ret = (__u32) ret;
> + if (len != 74 || ret != 148)
> + return 0;
> + test_result_subprog2 = 1;
> + return 0;
> +}
> +char _license[] SEC("license") = "GPL";
> --
> 2.23.0
>
Powered by blists - more mailing lists