BPF List
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf-next v3 2/2] selftests/bpf: Add a negative test for stack accounting in jit mode
Date: Tue, 13 Feb 2024 12:28:18 -0800	[thread overview]
Message-ID: <21aab482-18f3-43a1-b3ca-44b2a1a447ff@linux.dev> (raw)
In-Reply-To: <CAEf4BzamGPs45fFTDW4P_Ymm3bZ+Z0yP4JBPZHgefYbc5DgapA@mail.gmail.com>


On 2/13/24 11:40 AM, Andrii Nakryiko wrote:
> On Thu, Feb 8, 2024 at 1:54 PM Yonghong Song <yonghong.song@linux.dev> wrote:
>> The new test is very similar to test_global_func1.c, but
>> is modified to fail on jit mode.
>>
>> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
>> ---
>>   .../bpf/prog_tests/test_global_funcs.c        |  3 ++
>>   .../selftests/bpf/progs/test_global_func18.c  | 44 +++++++++++++++++++
>>   2 files changed, 47 insertions(+)
>>   create mode 100644 tools/testing/selftests/bpf/progs/test_global_func18.c
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/test_global_funcs.c b/tools/testing/selftests/bpf/prog_tests/test_global_funcs.c
>> index a3a41680b38e..dccbf2213135 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/test_global_funcs.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/test_global_funcs.c
>> @@ -18,6 +18,7 @@
>>   #include "test_global_func15.skel.h"
>>   #include "test_global_func16.skel.h"
>>   #include "test_global_func17.skel.h"
>> +#include "test_global_func18.skel.h"
>>   #include "test_global_func_ctx_args.skel.h"
>>
>>   #include "bpf/libbpf_internal.h"
>> @@ -140,6 +141,8 @@ void test_test_global_funcs(void)
>>   {
>>          if (!env.jit_enabled) {
>>                  RUN_TESTS(test_global_func1);
>> +       } else {
>> +               RUN_TESTS(test_global_func18);
>>          }
>>
>>          RUN_TESTS(test_global_func2);
>> diff --git a/tools/testing/selftests/bpf/progs/test_global_func18.c b/tools/testing/selftests/bpf/progs/test_global_func18.c
>> new file mode 100644
>> index 000000000000..d1aa3b2c68fe
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/progs/test_global_func18.c
>> @@ -0,0 +1,44 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
>> +#include <stddef.h>
>> +#include <linux/bpf.h>
>> +#include <bpf/bpf_helpers.h>
>> +#include "bpf_misc.h"
>> +
>> +#define MAX_STACK1 (512 - 3 * 32 + 8)
>> +#define MAX_STACK2 (3 * 32)
>> +
>> +__attribute__ ((noinline))
> nit: we have __noinline defined, let's use it as a less verbose option?

A copy-paste issue. In v4, I will drop this patch
since I will increase the stack size to accommodate
both jit and !jit cases.

>
>> +int f1(struct __sk_buff *skb)
>> +{
>> +       return skb->len;
>> +}
>> +
>> +int f3(int, struct __sk_buff *skb, int);
>> +
>> +__attribute__ ((noinline))
>> +int f2(int val, struct __sk_buff *skb)
>> +{
>> +       volatile char buf[MAX_STACK1] = {};
>> +
>> +       __sink(buf[MAX_STACK1 - 1]);
>> +
>> +       return f1(skb) + f3(val, skb, 1);
>> +}
>> +
>> +__attribute__ ((noinline))
>> +int f3(int val, struct __sk_buff *skb, int var)
>> +{
>> +       volatile char buf[MAX_STACK2] = {};
>> +
>> +       __sink(buf[MAX_STACK2 - 1]);
>> +
>> +       return skb->ifindex * val * var;
>> +}
>> +
>> +SEC("tc")
>> +__failure __msg("combined stack size of 3 calls is 528")
>> +int global_func18(struct __sk_buff *skb)
>> +{
>> +       return f1(skb) + f2(2, skb) + f3(3, skb, 4);
>> +}
>> --
>> 2.39.3
>>
>>

  reply	other threads:[~2024-02-13 20:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-08 21:54 [PATCH bpf-next v3 1/2] bpf: Fix test verif_scale_strobemeta_subprogs failure due to llvm19 Yonghong Song
2024-02-08 21:54 ` [PATCH bpf-next v3 2/2] selftests/bpf: Add a negative test for stack accounting in jit mode Yonghong Song
2024-02-13 19:40   ` Andrii Nakryiko
2024-02-13 20:28     ` Yonghong Song [this message]
2024-02-13 19:21 ` [PATCH bpf-next v3 1/2] bpf: Fix test verif_scale_strobemeta_subprogs failure due to llvm19 Andrii Nakryiko
2024-02-13 20:26   ` Yonghong Song

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=21aab482-18f3-43a1-b3ca-44b2a1a447ff@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@kernel.org \
    /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