All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf@vger.kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@kernel.org, memxor@gmail.com, eddyz87@gmail.com,
	djwong@kernel.org, kernel-team@fb.com
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: Add a test for arena range tree algorithm
Date: Fri, 15 Nov 2024 13:20:53 +0100	[thread overview]
Message-ID: <Zzc8pVMtTAkqUdvA@krava> (raw)
In-Reply-To: <20241108025616.17625-3-alexei.starovoitov@gmail.com>

On Thu, Nov 07, 2024 at 06:56:16PM -0800, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> 
> Add a test that verifies specific behavior of arena range tree
> algorithm and just existing bif_alloc1 test due to use
> of global data in arena.
> 
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---
>  .../bpf/progs/verifier_arena_large.c          | 110 +++++++++++++++++-
>  1 file changed, 108 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/progs/verifier_arena_large.c b/tools/testing/selftests/bpf/progs/verifier_arena_large.c
> index 6065f862d964..8a9af79db884 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_arena_large.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_arena_large.c
> @@ -29,12 +29,12 @@ int big_alloc1(void *ctx)
>  	if (!page1)
>  		return 1;
>  	*page1 = 1;
> -	page2 = bpf_arena_alloc_pages(&arena, base + ARENA_SIZE - PAGE_SIZE,
> +	page2 = bpf_arena_alloc_pages(&arena, base + ARENA_SIZE - PAGE_SIZE * 2,
>  				      1, NUMA_NO_NODE, 0);
>  	if (!page2)
>  		return 2;
>  	*page2 = 2;
> -	no_page = bpf_arena_alloc_pages(&arena, base + ARENA_SIZE,
> +	no_page = bpf_arena_alloc_pages(&arena, base + ARENA_SIZE - PAGE_SIZE,
>  					1, NUMA_NO_NODE, 0);
>  	if (no_page)
>  		return 3;
> @@ -66,4 +66,110 @@ int big_alloc1(void *ctx)
>  #endif
>  	return 0;
>  }
> +
> +#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
> +#define PAGE_CNT 100
> +__u8 __arena * __arena page[PAGE_CNT]; /* occupies the first page */
> +__u8 __arena *base;
> +
> +/*
> + * Check that arena's range_tree algorithm allocates pages sequentially
> + * on the first pass and then fills in all gaps on the second pass.
> + */
> +__noinline int alloc_pages(int page_cnt, int pages_atonce, bool first_pass,
> +		int max_idx, int step)
> +{
> +	__u8 __arena *pg;
> +	int i, pg_idx;
> +
> +	for (i = 0; i < page_cnt; i++) {
> +		pg = bpf_arena_alloc_pages(&arena, NULL, pages_atonce,
> +					   NUMA_NO_NODE, 0);
> +		if (!pg)
> +			return step;
> +		pg_idx = (pg - base) / PAGE_SIZE;

hi,
I'm getting compile error below with clang 20.0.0:

      CLNG-BPF [test_progs] verifier_arena_large.bpf.o
    progs/verifier_arena_large.c:90:24: error: unsupported signed division, please convert to unsigned div/mod.
       90 |                 pg_idx = (pg - base) / PAGE_SIZE;

should we just convert it to unsigned div like below?

also I saw recent llvm change [1] that might help, I'll give it a try

jirka


[1] 38a8000f30aa [BPF] Use mul for certain div/mod operations (#110712)
---
diff --git a/tools/testing/selftests/bpf/progs/verifier_arena_large.c b/tools/testing/selftests/bpf/progs/verifier_arena_large.c
index 8a9af79db884..e743d008697e 100644
--- a/tools/testing/selftests/bpf/progs/verifier_arena_large.c
+++ b/tools/testing/selftests/bpf/progs/verifier_arena_large.c
@@ -87,7 +87,7 @@ __noinline int alloc_pages(int page_cnt, int pages_atonce, bool first_pass,
 					   NUMA_NO_NODE, 0);
 		if (!pg)
 			return step;
-		pg_idx = (pg - base) / PAGE_SIZE;
+		pg_idx = (unsigned int) (pg - base) / PAGE_SIZE;
 		if (first_pass) {
 			/* Pages must be allocated sequentially */
 			if (pg_idx != i)

  parent reply	other threads:[~2024-11-15 12:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-08  2:56 [PATCH bpf-next 0/2] bpf: range_tree for bpf arena Alexei Starovoitov
2024-11-08  2:56 ` [PATCH bpf-next 1/2] bpf: Introduce range_tree data structure and use it in " Alexei Starovoitov
2024-11-13 16:02   ` Kumar Kartikeya Dwivedi
2025-01-06 16:12   ` Barret Rhoden
2025-01-06 17:45     ` Alexei Starovoitov
2024-11-08  2:56 ` [PATCH bpf-next 2/2] selftests/bpf: Add a test for arena range tree algorithm Alexei Starovoitov
2024-11-13 16:04   ` Kumar Kartikeya Dwivedi
2024-11-15 12:20   ` Jiri Olsa [this message]
2024-11-15 16:30     ` Yonghong Song
2024-11-16 19:00       ` Alexei Starovoitov
2024-11-16 20:35         ` Jiri Olsa
2024-11-13 21:59 ` [PATCH bpf-next 0/2] bpf: range_tree for bpf arena Andrii Nakryiko
2024-11-14  0:48   ` Alexei Starovoitov
2024-11-13 22:10 ` 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=Zzc8pVMtTAkqUdvA@krava \
    --to=olsajiri@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=djwong@kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@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 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.