All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Kenny Yu <kennyyu@fb.com>, Andrii Nakryiko <andrii@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>, bpf <bpf@vger.kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Gabriele <phoenix1987@gmail.com>, Yonghong Song <yhs@fb.com>
Subject: Re: [PATCH v5 bpf-next 1/3] bpf: Add bpf_access_process_vm() helper
Date: Fri, 21 Jan 2022 09:20:39 -0800	[thread overview]
Message-ID: <CAEf4Bzaen2f2njYOAJuyWot2YvXn0YV=2zBVyFZw=_CqJdggPw@mail.gmail.com> (raw)
In-Reply-To: <CAADnVQL-85q36gRvMGocXMLNk4WjDa_Xpi8Y9ZQS+qYLhF8E+A@mail.gmail.com>

On Thu, Jan 20, 2022 at 6:28 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Thu, Jan 20, 2022 at 2:46 PM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
> a
> > > + *             wrapper of **access_process_vm**\ ().
> > > + *     Return
> > > + *             The number of bytes written to the buffer, or a negative error
> > > + *             in case of failure.
> >
> > wait, can it read less than *size* and return success?
> >
> > bpf_probe_read_kernel() returns:
> >
> > 0 on success, or a negative error in case of failure.
> >
> > Let's be consistent. Returning the number of read bytes makes more
> > sense in cases when we don't know the amount of bytes to be actually
> > read ahead of time (e.g., when reading zero-terminated strings).
> >
> > BTW, should we also add a C string reading helper as well, just like
> > there is bpf_probe_read_user_str() and bpf_probe_read_user()?
>
> That would be difficult. There is no suitable kernel api for that.

Ok, but maybe we can add it later. Otherwise it will be hard to
profiler Python processes and such, because you most certainly will
need to read zero-terminated strings there.

>
> > Another thing, I think it's important to mention that this helper can
> > be used only from sleepable BPF programs.
> >
> > And not to start the bikeshedding session, but we have
> > bpf_copy_from_user(), wouldn't something like
> > bpf_copy_from_user_{vm,process,remote}() be more in line and less
> > surprising for BPF users. BTW, "access" implies writing just as much
> > as reading, so using "access" in the sense of "read" seems wrong and
> > confusing.
>
> How about bpf_copy_from_user_task() ?
> The task is the second to last argument, so the name fits ?

yeah, I like the name


> Especially if we call it this way it would be best to align
> return codes with bpf_copy_from_user.
> Adding memset() in case of failure is mandatory too.
> I've missed this bit earlier.

Yep, good catch! Seems like copy_from_user() currently returns amount
of bytes *not* read and memsets those unread bytes to zero. So for
efficiency we could probably memset only those that were read.

>
> The question is to decide what to do with
> ret > 0 && ret < size condition.
> Is it a failure and we should memset() the whole buffer and
> return -EFAULT or memset only the leftover bytes and return 0?
> I think the former is best to align with bpf_copy_from_user.

Yeah, I think all or nothing approach (either complete success and
zero return, or memset and error return) is best and most in line with
other similar helpers.

  reply	other threads:[~2022-01-21 17:20 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 23:31 [PATCH bpf-next 0/3] Add bpf_access_process_vm helper and sleepable bpf iterator programs Kenny Yu
2022-01-13 23:31 ` [PATCH bpf-next 1/3] bpf: Add bpf_access_process_vm() helper Kenny Yu
2022-01-13 23:31 ` [PATCH bpf-next 2/3] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-13 23:31 ` [PATCH bpf-next 3/3] selftests/bpf: Add test " Kenny Yu
2022-01-14  0:48 ` [PATCH v2 bpf-next 0/4] Add bpf_access_process_vm helper and " Kenny Yu
2022-01-14  0:48   ` [PATCH v2 bpf-next 1/4] bpf: Add bpf_access_process_vm() helper Kenny Yu
2022-01-14  0:48   ` [PATCH v2 bpf-next 2/4] bpf: Add support for sleepable programs in bpf_iter_run_prog Kenny Yu
2022-01-14  2:50     ` Alexei Starovoitov
2022-01-14 23:15       ` Kenny Yu
2022-01-14  0:48   ` [PATCH v2 bpf-next 3/4] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-14  0:49   ` [PATCH v2 bpf-next 4/4] selftests/bpf: Add test " Kenny Yu
2022-01-14  2:39     ` Alexei Starovoitov
2022-01-14 23:14       ` Kenny Yu
2022-01-15  1:38         ` Andrii Nakryiko
2022-01-15  4:30           ` Kenny Yu
2022-01-15 16:27           ` Gabriele
2022-01-19 16:56             ` Kenny Yu
2022-01-19 18:02 ` [PATCH v3 bpf-next 0/3] Add bpf_access_process_vm helper and " Kenny Yu
2022-01-19 18:02   ` [PATCH v3 bpf-next 1/3] bpf: Add bpf_access_process_vm() helper Kenny Yu
2022-01-19 20:16     ` Alexei Starovoitov
2022-01-19 22:51       ` Kenny Yu
2022-01-19 18:02   ` [PATCH v3 bpf-next 2/3] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-19 18:02   ` [PATCH v3 bpf-next 3/3] selftests/bpf: Add test " Kenny Yu
2022-01-19 22:59 ` [PATCH v4 bpf-next 0/3] Add bpf_access_process_vm helper and " Kenny Yu
2022-01-19 22:59   ` [PATCH v4 bpf-next 1/3] bpf: Add bpf_access_process_vm() helper Kenny Yu
2022-01-20  3:45     ` Yonghong Song
2022-01-20 17:11       ` Kenny Yu
2022-01-19 22:59   ` [PATCH v4 bpf-next 2/3] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-19 22:59   ` [PATCH v4 bpf-next 3/3] selftests/bpf: Add test " Kenny Yu
2022-01-20 17:29 ` [PATCH v5 bpf-next 0/3] Add bpf_access_process_vm helper and " Kenny Yu
2022-01-20 17:29   ` [PATCH v5 bpf-next 1/3] bpf: Add bpf_access_process_vm() helper Kenny Yu
2022-01-20 22:45     ` Andrii Nakryiko
2022-01-21  2:27       ` Alexei Starovoitov
2022-01-21 17:20         ` Andrii Nakryiko [this message]
2022-01-21 17:41           ` Kenny Yu
2022-01-21 17:47             ` Alexei Starovoitov
2022-01-21 18:30               ` Kenny Yu
2022-01-20 17:29   ` [PATCH v5 bpf-next 2/3] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-20 17:29   ` [PATCH v5 bpf-next 3/3] selftests/bpf: Add test " Kenny Yu
2022-01-20 22:48     ` Andrii Nakryiko
2022-01-21 19:30 ` [PATCH v6 bpf-next 0/3] Add bpf_copy_from_user_task helper and " Kenny Yu
2022-01-21 19:30   ` [PATCH v6 bpf-next 1/3] bpf: Add bpf_copy_from_user_task() helper Kenny Yu
2022-01-21 19:53     ` Andrii Nakryiko
2022-01-21 20:04       ` Yonghong Song
2022-01-21 20:07         ` Andrii Nakryiko
2022-01-21 21:15           ` Yonghong Song
2022-01-24 17:30             ` Kenny Yu
2022-01-22  9:58       ` Gabriele
2022-01-22 10:08         ` Gabriele
2022-01-21 19:30   ` [PATCH v6 bpf-next 2/3] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-21 19:54     ` Andrii Nakryiko
2022-01-21 19:30   ` [PATCH v6 bpf-next 3/3] selftests/bpf: Add test " Kenny Yu
2022-01-21 19:55     ` Andrii Nakryiko
2022-01-24 18:53 ` [PATCH v7 bpf-next 0/4] Add bpf_copy_from_user_task helper and " Kenny Yu
2022-01-24 18:54   ` [PATCH v7 bpf-next 1/4] bpf: Add support for bpf iterator programs to use sleepable helpers Kenny Yu
2022-01-24 22:19     ` Andrii Nakryiko
2022-01-24 18:54   ` [PATCH v7 bpf-next 2/4] bpf: Add bpf_copy_from_user_task() helper Kenny Yu
2022-01-24 22:18     ` Andrii Nakryiko
2022-01-25  4:06       ` Alexei Starovoitov
2022-01-24 18:54   ` [PATCH v7 bpf-next 3/4] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-24 18:54   ` [PATCH v7 bpf-next 4/4] selftests/bpf: Add test " Kenny Yu
2022-01-25  4:10   ` [PATCH v7 bpf-next 0/4] Add bpf_copy_from_user_task helper and " patchwork-bot+netdevbpf

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='CAEf4Bzaen2f2njYOAJuyWot2YvXn0YV=2zBVyFZw=_CqJdggPw@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kennyyu@fb.com \
    --cc=phoenix1987@gmail.com \
    --cc=yhs@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.