From: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>
To: ihor.solodrai@linux.dev, andrii@kernel.org
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
eddyz87@gmail.com, mykolal@fb.com, kernel-team@meta.com
Subject: Re: [PATCH bpf-next 1/2] bpf: add bpf_dynptr_memset() kfunc
Date: Thu, 19 Jun 2025 00:44:28 +0100 [thread overview]
Message-ID: <b35ce32e-a5e7-4589-ab16-d931194a32bb@gmail.com> (raw)
In-Reply-To: <20250618223310.3684760-1-isolodrai@meta.com>
On 6/18/25 23:33, Ihor Solodrai wrote:
> Currently there is no straightforward way to fill dynptr memory with a
> value (most commonly zero). One can do it with bpf_dynptr_write(), but
> a temporary buffer is necessary for that.
>
> Implement bpf_dynptr_memset() - an analogue of memset() from libc.
>
> Signed-off-by: Ihor Solodrai <isolodrai@meta.com>
> ---
> kernel/bpf/helpers.c | 28 ++++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
>
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index b71e428ad936..dfd04628a522 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
> @@ -2906,6 +2906,33 @@ __bpf_kfunc int bpf_dynptr_copy(struct bpf_dynptr *dst_ptr, u32 dst_off,
> return 0;
> }
>
> +/**
> + * bpf_dynptr_memset() - Fill dynptr memory with a constant byte.
> + * @ptr: Destination dynptr - where data will be filled
> + * @val: Constant byte to fill the memory with
> + * @n: Number of bytes to fill
> + *
> + * Fills the first n bytes of the memory area pointed to by ptr
> + * with the constant byte val.
> + * Returns 0 on success; negative error, otherwise.
> + */
> + __bpf_kfunc int bpf_dynptr_memset(struct bpf_dynptr *ptr, u8 val, u32 n)
> + {
> + struct bpf_dynptr_kern *p = (struct bpf_dynptr_kern *)ptr;
> + int err;
> +
> + if (__bpf_dynptr_is_rdonly(p))
> + return -EINVAL;
> +
> + err = bpf_dynptr_check_off_len(p, 0, n);
> + if (err)
> + return err;
> +
> + memset(p->data + p->offset, val, n);
Do we need to handle non-contiguous buffers, similarly to
bpf_dynptr_write (BPF_DYNPTR_TYPE_XDP case)?
> +
> + return 0;
> +}
> +
> __bpf_kfunc void *bpf_cast_to_kern_ctx(void *obj)
> {
> return obj;
> @@ -3364,6 +3391,7 @@ BTF_ID_FLAGS(func, bpf_dynptr_is_rdonly)
> BTF_ID_FLAGS(func, bpf_dynptr_size)
> BTF_ID_FLAGS(func, bpf_dynptr_clone)
> BTF_ID_FLAGS(func, bpf_dynptr_copy)
> +BTF_ID_FLAGS(func, bpf_dynptr_memset)
> #ifdef CONFIG_NET
> BTF_ID_FLAGS(func, bpf_modify_return_test_tp)
> #endif
next prev parent reply other threads:[~2025-06-18 23:44 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-18 22:33 [PATCH bpf-next 1/2] bpf: add bpf_dynptr_memset() kfunc Ihor Solodrai
2025-06-18 22:33 ` [PATCH bpf-next 2/2] selftests/bpf: add test cases for bpf_dynptr_memset() Ihor Solodrai
2025-06-18 23:44 ` Mykyta Yatsenko [this message]
2025-06-19 17:09 ` [PATCH bpf-next 1/2] bpf: add bpf_dynptr_memset() kfunc Ihor Solodrai
2025-06-19 17:19 ` Eduard Zingerman
2025-06-19 17:55 ` Ihor Solodrai
2025-06-19 17:57 ` Eduard Zingerman
2025-06-19 18:04 ` Ihor Solodrai
2025-06-19 18:13 ` Eduard Zingerman
2025-06-19 18:17 ` Eduard Zingerman
2025-06-23 21:38 ` Andrii Nakryiko
2025-06-23 21:45 ` Eduard Zingerman
2025-06-23 22:12 ` Andrii Nakryiko
2025-06-20 15:09 ` Mykyta Yatsenko
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=b35ce32e-a5e7-4589-ab16-d931194a32bb@gmail.com \
--to=mykyta.yatsenko5@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=kernel-team@meta.com \
--cc=mykolal@fb.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.