Re: [PATCH bpf-next v4 2/3] selftests/bpf: Add test for recursive attachment of tracing progs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Nov 29, 2023 at 08:52:37PM +0100, Dmitrii Dolgov wrote:

SNIP

> +void test_recursive_fentry_attach(void)
> +{
> +	struct fentry_recursive_target *target_skel = NULL;
> +	struct fentry_recursive *tracing_chain[ATTACH_DEPTH + 1] = {};
> +	struct bpf_program *prog;
> +	int prev_fd, err;
> +
> +	target_skel = fentry_recursive_target__open_and_load();
> +	if (!ASSERT_OK_PTR(target_skel, "fentry_recursive_target__open_and_load"))
> +		goto close_prog;
> +
> +	/* This is going to be the start of the chain */
> +	tracing_chain[0] = fentry_recursive__open();
> +	if (!ASSERT_OK_PTR(tracing_chain[0], "fentry_recursive__open"))
> +		goto close_prog;
> +
> +	prog = tracing_chain[0]->progs.recursive_attach;
> +	prev_fd = bpf_program__fd(target_skel->progs.test1);
> +	err = bpf_program__set_attach_target(prog, prev_fd, "test1");
> +	if (!ASSERT_OK(err, "bpf_program__set_attach_target"))
> +		goto close_prog;
> +
> +	err = fentry_recursive__load(tracing_chain[0]);
> +	if (!ASSERT_OK(err, "fentry_recursive__load"))
> +		goto close_prog;

should you call fentry_recursive__attach in here as well?

> +
> +	/* Create an attachment chain to exhaust the limit */
> +	for (int i = 1; i < ATTACH_DEPTH; i++) {
> +		tracing_chain[i] = fentry_recursive__open();
> +		if (!ASSERT_OK_PTR(tracing_chain[i], "fentry_recursive__open"))
> +			goto close_prog;
> +
> +		prog = tracing_chain[i]->progs.recursive_attach;
> +		prev_fd = bpf_program__fd(tracing_chain[i-1]->progs.recursive_attach);

or maybe better brach here for (i == 0) and call

  bpf_program__set_attach_target(prog, prev_fd, "test1");


> +		err = bpf_program__set_attach_target(prog, prev_fd, "recursive_attach");
> +		if (!ASSERT_OK(err, "bpf_program__set_attach_target"))
> +			goto close_prog;
> +
> +		err = fentry_recursive__load(tracing_chain[i]);
> +		if (!ASSERT_OK(err, "fentry_recursive__load"))
> +			goto close_prog;
> +
> +		err = fentry_recursive__attach(tracing_chain[i]);
> +		if (!ASSERT_OK(err, "fentry_recursive__attach"))
> +			goto close_prog;
> +	}
> +
> +	/* The next attachment would fail */
> +	tracing_chain[ATTACH_DEPTH] = fentry_recursive__open();
> +	if (!ASSERT_OK_PTR(tracing_chain[ATTACH_DEPTH], "last fentry_recursive__open"))
> +		goto close_prog;
> +
> +	prog = tracing_chain[ATTACH_DEPTH]->progs.recursive_attach;
> +	prev_fd = bpf_program__fd(tracing_chain[ATTACH_DEPTH - 1]->progs.recursive_attach);
> +	err = bpf_program__set_attach_target(prog, prev_fd, "recursive_attach");
> +	if (!ASSERT_OK(err, "last bpf_program__set_attach_target"))
> +		goto close_prog;
> +
> +	err = fentry_recursive__load(tracing_chain[ATTACH_DEPTH]);
> +	if (!ASSERT_ERR(err, "last fentry_recursive__load"))
> +		goto close_prog;
> +
> +close_prog:
> +	fentry_recursive_target__destroy(target_skel);
> +	for (int i = 1; i < ATTACH_DEPTH + 1; i++) {

i = 0 ?

jirka

> +		if (tracing_chain[i])
> +			fentry_recursive__destroy(tracing_chain[i]);
> +	}
> +}

SNIP




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux