BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
	bpf@vger.kernel.org,  ast@kernel.org, andrii@kernel.org,
	daniel@iogearbox.net, kafai@meta.com,  kernel-team@meta.com
Cc: Mykyta Yatsenko <yatsenko@meta.com>
Subject: Re: [PATCH bpf-next 3/3] selftests/bpf: add tests for bpf_dynptr_copy
Date: Tue, 18 Feb 2025 17:04:56 -0800	[thread overview]
Message-ID: <d9314a49d54d7478d2b85bee6f4de0fb3d680deb.camel@gmail.com> (raw)
In-Reply-To: <20250218190027.135888-4-mykyta.yatsenko5@gmail.com>

On Tue, 2025-02-18 at 19:00 +0000, Mykyta Yatsenko wrote:
> From: Mykyta Yatsenko <yatsenko@meta.com>
> 
> Add XDP setup type for dynptr tests, enabling testing for
> non-contiguous buffer.
> Add 2 tests:
>  - test_dynptr_copy - verify correctness for the fast (contiguous
>  buffer) code path.
>  - test_dynptr_copy_xdp - verifies code paths that handle
>  non-contiguous buffer.
> 
> Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
> ---

Acked-by: Eduard Zingerman <eddyz87@gmail.com>

[...]

> +SEC("xdp")
> +int test_dynptr_copy_xdp(struct xdp_md *xdp)
> +{

Nit: it would be helpful if there were a few comments
     explaining which special cases are tested at each step.

> +	struct bpf_dynptr ptr_buf, ptr_xdp;
> +	char *data = "qwertyuiopasdfghjkl;";
> +	char buf[32] = {'\0'};
> +	__u32 len = strlen(data);
> +	int i, chunks = 200;
> +
> +	bpf_dynptr_from_xdp(xdp, 0, &ptr_xdp);
> +	bpf_ringbuf_reserve_dynptr(&ringbuf, len * chunks, 0, &ptr_buf);
> +
> +	bpf_for(i, 0, chunks) {
> +		err =  err ?: bpf_dynptr_write(&ptr_buf, i * len, data, len, 0);
> +	}
> +
> +	err = err ?: bpf_dynptr_copy(&ptr_xdp, 0, &ptr_buf, 0, len * chunks);
> +
> +	bpf_for(i, 0, chunks) {
> +		memset(buf, 0, sizeof(buf));
> +		err = err ?: bpf_dynptr_read(&buf, len, &ptr_xdp, i * len, 0);
> +		err = err ?: memcmp(data, buf, len);
> +	}
> +
> +	memset(buf, 0, sizeof(buf));
> +	bpf_for(i, 0, chunks) {
> +		err = err ?: bpf_dynptr_write(&ptr_buf, i * len, buf, len, 0);
> +	}
> +
> +	err = err ?: bpf_dynptr_copy(&ptr_buf, 0, &ptr_xdp, 0, len * chunks);
> +
> +	bpf_for(i, 0, chunks) {
> +		memset(buf, 0, sizeof(buf));
> +		err = err ?: bpf_dynptr_read(&buf, len, &ptr_buf, i * len, 0);
> +		err = err ?: memcmp(data, buf, len);
> +	}
> +
> +	bpf_ringbuf_discard_dynptr(&ptr_buf, 0);
> +
> +	err = err ?: bpf_dynptr_copy(&ptr_xdp, 2, &ptr_xdp, len, len * (chunks - 1));
> +
> +	bpf_for(i, 0, chunks - 1) {
> +		memset(buf, 0, sizeof(buf));
> +		err = err ?: bpf_dynptr_read(&buf, len, &ptr_xdp, 2 + i * len, 0);
> +		err = err ?: memcmp(data, buf, len);
> +	}
> +
> +	err = err ?: (bpf_dynptr_copy(&ptr_xdp, 2000, &ptr_xdp, 0, len * chunks) == -E2BIG ? 0 : 1);
> +
> +	return XDP_DROP;
> +}



  reply	other threads:[~2025-02-19  1:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-18 19:00 [PATCH bpf-next 0/3] introduce bpf_dynptr_copy kfunc Mykyta Yatsenko
2025-02-18 19:00 ` [PATCH bpf-next 1/3] bpf/helpers: refactor bpf_dynptr_read and bpf_dynptr_write Mykyta Yatsenko
2025-02-18 19:00 ` [PATCH bpf-next 2/3] bpf/helpers: introduce bpf_dynptr_copy kfunc Mykyta Yatsenko
2025-02-19  1:01   ` Eduard Zingerman
2025-02-21  0:42   ` Andrii Nakryiko
2025-02-18 19:00 ` [PATCH bpf-next 3/3] selftests/bpf: add tests for bpf_dynptr_copy Mykyta Yatsenko
2025-02-19  1:04   ` Eduard Zingerman [this message]
2025-02-21  0:52   ` Andrii Nakryiko
2025-02-21  0:56     ` Eduard Zingerman
2025-02-21  1:03       ` Andrii Nakryiko
2025-02-21 12:08     ` Mykyta Yatsenko
2025-02-21 17:16       ` Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d9314a49d54d7478d2b85bee6f4de0fb3d680deb.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@meta.com \
    --cc=kernel-team@meta.com \
    --cc=mykyta.yatsenko5@gmail.com \
    --cc=yatsenko@meta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox