-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/bpf: Add a negative test for stack accounting in jit mode
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>
- Loading branch information
Yonghong Song
authored and
Kernel Patches Daemon
committed
Feb 8, 2024
1 parent
1a37cc2
commit c9ccb34
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
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); | ||
} |