bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Cc: bpf <bpf@vger.kernel.org>, Andrii Nakryiko <andrii@kernel.org>,
	Jiri Olsa <jolsa@redhat.com>
Subject: Re: [PATCH bpf-next v3 3/8] selftests/bpf: pass page size from userspace in sockopt_sk
Date: Wed, 31 Mar 2021 11:44:23 -0700	[thread overview]
Message-ID: <CAEf4BzZYhqzYgxdgGUZtPoU5Lkq4vVLSF7Vu=9QXKCBEp+rh-Q@mail.gmail.com> (raw)
In-Reply-To: <20210331164504.320614-3-yauheni.kaliuta@redhat.com>

On Wed, Mar 31, 2021 at 9:45 AM Yauheni Kaliuta
<yauheni.kaliuta@redhat.com> wrote:
>
> Since there is no convenient way for bpf program to get PAGE_SIZE
> from inside of the kernel, pass the value from userspace.
>
> Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
> ---
>  tools/testing/selftests/bpf/prog_tests/sockopt_sk.c |  2 ++
>  tools/testing/selftests/bpf/progs/sockopt_sk.c      | 10 ++++------
>  2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> index 7274b12abe17..4b937e5dbaca 100644
> --- a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> @@ -200,6 +200,8 @@ static void run_test(int cgroup_fd)
>         if (!ASSERT_OK_PTR(skel, "skel_load"))
>                 goto cleanup;
>
> +       skel->bss->page_size = getpagesize();
> +
>         skel->links._setsockopt =
>                 bpf_program__attach_cgroup(skel->progs._setsockopt, cgroup_fd);
>         if (!ASSERT_OK_PTR(skel->links._setsockopt, "setsockopt_link"))
> diff --git a/tools/testing/selftests/bpf/progs/sockopt_sk.c b/tools/testing/selftests/bpf/progs/sockopt_sk.c
> index 978a68005966..d6d03f64e2e4 100644
> --- a/tools/testing/selftests/bpf/progs/sockopt_sk.c
> +++ b/tools/testing/selftests/bpf/progs/sockopt_sk.c
> @@ -7,9 +7,7 @@
>
>  char _license[] SEC("license") = "GPL";
>
> -#ifndef PAGE_SIZE
> -#define PAGE_SIZE 4096
> -#endif
> +int page_size; /* userspace should set it */

please zero-initialize this, otherwise it will cause problems on some
versions of Clang

>
>  #ifndef SOL_TCP
>  #define SOL_TCP IPPROTO_TCP
> @@ -89,7 +87,7 @@ int _getsockopt(struct bpf_sockopt *ctx)
>                  * program can only see the first PAGE_SIZE
>                  * bytes of data.
>                  */
> -               if (optval_end - optval != PAGE_SIZE)
> +               if (optval_end - optval != page_size)
>                         return 0; /* EPERM, unexpected data size */
>
>                 return 1;
> @@ -160,7 +158,7 @@ int _setsockopt(struct bpf_sockopt *ctx)
>
>         if (ctx->level == SOL_IP && ctx->optname == IP_FREEBIND) {
>                 /* Original optlen is larger than PAGE_SIZE. */
> -               if (ctx->optlen != PAGE_SIZE * 2)
> +               if (ctx->optlen != page_size * 2)
>                         return 0; /* EPERM, unexpected data size */
>
>                 if (optval + 1 > optval_end)
> @@ -174,7 +172,7 @@ int _setsockopt(struct bpf_sockopt *ctx)
>                  * program can only see the first PAGE_SIZE
>                  * bytes of data.
>                  */
> -               if (optval_end - optval != PAGE_SIZE)
> +               if (optval_end - optval != page_size)
>                         return 0; /* EPERM, unexpected data size */
>
>                 return 1;
> --
> 2.31.1
>

  reply	other threads:[~2021-03-31 18:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-31 16:44 [PATCH bpf-next v3 0/8] bpf/selftests: page size fixes Yauheni Kaliuta
2021-03-31 16:44 ` [PATCH bpf-next v3 1/8] selftests/bpf: test_progs/sockopt_sk: remove version Yauheni Kaliuta
2021-03-31 16:44   ` [PATCH bpf-next v3 2/8] selftests/bpf: test_progs/sockopt_sk: Convert to use BPF skeleton Yauheni Kaliuta
2021-03-31 16:44   ` [PATCH bpf-next v3 3/8] selftests/bpf: pass page size from userspace in sockopt_sk Yauheni Kaliuta
2021-03-31 18:44     ` Andrii Nakryiko [this message]
2021-03-31 16:45   ` [PATCH bpf-next v3 4/8] selftests/bpf: pass page size from userspace in map_ptr Yauheni Kaliuta
2021-03-31 16:45   ` [PATCH bpf-next v3 5/8] selftests/bpf: mmap: use runtime page size Yauheni Kaliuta
2021-03-31 16:45   ` [PATCH bpf-next v3 6/8] selftests/bpf: ringbuf: " Yauheni Kaliuta
2021-03-31 16:45   ` [PATCH bpf-next v3 7/8] libbpf: add bpf_map__inner_map API Yauheni Kaliuta
2021-03-31 18:48     ` Andrii Nakryiko
2021-03-31 16:45   ` [PATCH bpf-next v3 8/8] selftests/bpf: ringbuf_multi: use runtime page size Yauheni Kaliuta
2021-03-31 18:52     ` Andrii Nakryiko
2021-04-07 16:36       ` Yauheni Kaliuta
2021-04-07 18:05         ` Andrii Nakryiko
2021-04-07 18:17           ` Andrii Nakryiko
2021-04-08  5:56             ` Yauheni Kaliuta

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='CAEf4BzZYhqzYgxdgGUZtPoU5Lkq4vVLSF7Vu=9QXKCBEp+rh-Q@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=jolsa@redhat.com \
    --cc=yauheni.kaliuta@redhat.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;
as well as URLs for NNTP newsgroup(s).