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 v2 2/4] selftests/bpf: test_progs/sockopt_sk: pass page size from userspace
Date: Sat, 27 Mar 2021 22:00:28 -0700 [thread overview]
Message-ID: <CAEf4BzafSuz9Mf63bxKLuEVvy_Wdk5-r7xot0LBf-vN1h+8RfQ@mail.gmail.com> (raw)
In-Reply-To: <20210326122438.211242-2-yauheni.kaliuta@redhat.com>
On Fri, Mar 26, 2021 at 5:24 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>
> ---
Acked-by: Andrii Nakryiko <andrii@kernel.org>
But I'd also shorten the subject to:
selftests/bpf: pass page size from userspace in sockopt_sk
It's just as clear and doesn't include unnecessary prog_tests/ path.
> 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 114c1a622ffa..6a7cb5f23db2 100644
> --- a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> @@ -201,6 +201,8 @@ static void run_test(int cgroup_fd)
> if (CHECK(!skel, "skel_load", "sockopt_sk skeleton failed\n"))
> goto cleanup;
>
> + skel->bss->page_size = getpagesize();
> +
> skel->links._setsockopt =
> bpf_program__attach_cgroup(skel->progs._setsockopt, cgroup_fd);
> if (CHECK(IS_ERR(skel->links._setsockopt),
> diff --git a/tools/testing/selftests/bpf/progs/sockopt_sk.c b/tools/testing/selftests/bpf/progs/sockopt_sk.c
> index d3597f81e6e9..55dfbe53c24e 100644
> --- a/tools/testing/selftests/bpf/progs/sockopt_sk.c
> +++ b/tools/testing/selftests/bpf/progs/sockopt_sk.c
> @@ -8,9 +8,7 @@
> char _license[] SEC("license") = "GPL";
> __u32 _version SEC("version") = 1;
>
> -#ifndef PAGE_SIZE
> -#define PAGE_SIZE 4096
> -#endif
> +int page_size; /* userspace should set it */
>
> #ifndef SOL_TCP
> #define SOL_TCP IPPROTO_TCP
> @@ -90,7 +88,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;
> @@ -161,7 +159,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)
> @@ -175,7 +173,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.29.2
>
next prev parent reply other threads:[~2021-03-28 5:01 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-26 11:46 [PATCH 0/3] bpf/selftests: page size fixes Yauheni Kaliuta
2021-03-26 11:47 ` [PATCH 1/3] selftests/bpf: test_progs/sockopt_sk: pass page size from userspace Yauheni Kaliuta
2021-03-26 11:47 ` [PATCH 2/3] bpf: selftests: test_progs/sockopt_sk: remove version Yauheni Kaliuta
2021-03-26 11:47 ` [PATCH 3/3] selftests/bpf: ringbuf, mmap: bump up page size to 64K Yauheni Kaliuta
2021-03-26 12:21 ` [PATCH 0/3] bpf/selftests: page size fixes Yauheni Kaliuta
2021-03-26 12:24 ` [PATCH v2 0/4] " Yauheni Kaliuta
2021-03-28 5:05 ` Andrii Nakryiko
2021-03-28 17:06 ` Yauheni Kaliuta
2021-03-28 18:30 ` Andrii Nakryiko
2021-03-26 12:24 ` [PATCH v2 1/4] selftests/bpf: test_progs/sockopt_sk: Convert to use BPF skeleton Yauheni Kaliuta
2021-03-26 12:24 ` [PATCH v2 2/4] selftests/bpf: test_progs/sockopt_sk: pass page size from userspace Yauheni Kaliuta
2021-03-28 5:00 ` Andrii Nakryiko [this message]
2021-03-26 12:24 ` [PATCH v2 3/4] bpf: selftests: test_progs/sockopt_sk: remove version Yauheni Kaliuta
2021-03-26 12:24 ` [PATCH v2 4/4] selftests/bpf: ringbuf, mmap: bump up page size to 64K Yauheni Kaliuta
2021-03-28 5:03 ` Andrii Nakryiko
2021-03-29 15:19 ` Yauheni Kaliuta
2021-03-31 5:49 ` Andrii Nakryiko
2021-03-31 6:11 ` Yauheni Kaliuta
2021-03-31 6:25 ` Andrii Nakryiko
2021-03-31 16:43 ` Yauheni Kaliuta
2021-03-28 4:58 ` [PATCH v2 1/4] selftests/bpf: test_progs/sockopt_sk: Convert to use BPF skeleton Andrii Nakryiko
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=CAEf4BzafSuz9Mf63bxKLuEVvy_Wdk5-r7xot0LBf-vN1h+8RfQ@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).