On Tue, 2025-02-18 at 19:00 +0000, Mykyta Yatsenko wrote: > From: Mykyta Yatsenko <yatsenko@xxxxxxxx> > > 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@xxxxxxxx> > --- Acked-by: Eduard Zingerman <eddyz87@xxxxxxxxx> [...] > +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; > +}