BPF List
 help / color / mirror / Atom feed
From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Joanne Koong <joannekoong@fb.com>, bpf@vger.kernel.org
Cc: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net,
	Joanne Koong <joannelkoong@gmail.com>
Subject: Re: [PATCH bpf-next v1 4/7] bpf: Add bpf_dynptr_read and bpf_dynptr_write
Date: Sat, 02 Apr 2022 15:35:24 +0200	[thread overview]
Message-ID: <87ilrrfw0z.fsf@toke.dk> (raw)
In-Reply-To: <20220402015826.3941317-5-joannekoong@fb.com>

Joanne Koong <joannekoong@fb.com> writes:

> From: Joanne Koong <joannelkoong@gmail.com>
>
> This patch adds two helper functions, bpf_dynptr_read and
> bpf_dynptr_write:
>
> long bpf_dynptr_read(void *dst, u32 len, struct bpf_dynptr *src, u32 offset);
>
> long bpf_dynptr_write(struct bpf_dynptr *dst, u32 offset, void *src, u32 len);
>
> The dynptr passed into these functions must be valid dynptrs that have
> been initialized.
>
> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> ---
>  include/linux/bpf.h            |  6 ++++
>  include/uapi/linux/bpf.h       | 18 +++++++++++
>  kernel/bpf/helpers.c           | 56 ++++++++++++++++++++++++++++++++++
>  tools/include/uapi/linux/bpf.h | 18 +++++++++++
>  4 files changed, 98 insertions(+)
>
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index e0fcff9f2aee..cded9753fb7f 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -2426,6 +2426,12 @@ enum bpf_dynptr_type {
>  #define DYNPTR_MAX_SIZE	((1UL << 28) - 1)
>  #define DYNPTR_SIZE_MASK	0xFFFFFFF
>  #define DYNPTR_TYPE_SHIFT	29
> +#define DYNPTR_RDONLY_BIT	BIT(28)
> +
> +static inline bool bpf_dynptr_is_rdonly(struct bpf_dynptr_kern *ptr)
> +{
> +	return ptr->size & DYNPTR_RDONLY_BIT;
> +}
>  
>  static inline enum bpf_dynptr_type bpf_dynptr_get_type(struct bpf_dynptr_kern *ptr)
>  {
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 6a57d8a1b882..16a35e46be90 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -5175,6 +5175,22 @@ union bpf_attr {
>   *		After this operation, *ptr* will be an invalidated dynptr.
>   *	Return
>   *		Void.
> + *
> + * long bpf_dynptr_read(void *dst, u32 len, struct bpf_dynptr *src, u32 offset)
> + *	Description
> + *		Read *len* bytes from *src* into *dst*, starting from *offset*
> + *		into *dst*.

nit: this should be "starting from *offset* into *src*, no? (same below)

-Toke


  reply	other threads:[~2022-04-02 13:35 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-02  1:58 [PATCH bpf-next v1 0/7] Dynamic pointers Joanne Koong
2022-04-02  1:58 ` [PATCH bpf-next v1 1/7] bpf: Add MEM_UNINIT as a bpf_type_flag Joanne Koong
2022-04-06 18:33   ` Andrii Nakryiko
2022-04-02  1:58 ` [PATCH bpf-next v1 2/7] bpf: Add MEM_RELEASE " Joanne Koong
2022-04-04  7:34   ` Kumar Kartikeya Dwivedi
2022-04-04 19:04     ` Joanne Koong
2022-04-06 18:42   ` Andrii Nakryiko
2022-04-02  1:58 ` [PATCH bpf-next v1 3/7] bpf: Add bpf_dynptr_from_mem, bpf_malloc, bpf_free Joanne Koong
2022-04-06 22:23   ` Andrii Nakryiko
2022-04-08 22:04     ` Joanne Koong
2022-04-08 22:46       ` Andrii Nakryiko
2022-04-08 23:37         ` Joanne Koong
2022-04-09  1:11           ` Alexei Starovoitov
2022-04-12  2:12             ` Andrii Nakryiko
2022-04-15  1:43               ` Joanne Koong
2022-04-12  2:05           ` Andrii Nakryiko
2022-04-02  1:58 ` [PATCH bpf-next v1 4/7] bpf: Add bpf_dynptr_read and bpf_dynptr_write Joanne Koong
2022-04-02 13:35   ` Toke Høiland-Jørgensen [this message]
2022-04-04 20:18     ` Joanne Koong
2022-04-06 22:32   ` Andrii Nakryiko
2022-04-08 23:07     ` Joanne Koong
2022-04-02  1:58 ` [PATCH bpf-next v1 5/7] bpf: Add dynptr data slices Joanne Koong
2022-04-02  1:58 ` [PATCH bpf-next v1 6/7] bpf: Dynptr support for ring buffers Joanne Koong
2022-04-02  6:40   ` kernel test robot
2022-04-06 22:50   ` Andrii Nakryiko
2022-04-02  1:58 ` [PATCH bpf-next v1 7/7] bpf: Dynptr tests Joanne Koong
2022-04-06 23:11   ` Andrii Nakryiko
2022-04-08 23:16     ` Joanne Koong
2022-04-06 23:13 ` [PATCH bpf-next v1 0/7] Dynamic pointers Andrii Nakryiko
2022-04-07 12:44   ` Brendan Jackman
2022-04-07 20:40     ` Joanne Koong
2022-04-08 10:21       ` Brendan Jackman

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=87ilrrfw0z.fsf@toke.dk \
    --to=toke@redhat.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=joannekoong@fb.com \
    --cc=joannelkoong@gmail.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