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 selftest for checking subreg equality
Add a selftest to ensure subreg equality if source register upper 32bit is 0. Without previous patch, the new test will fail verification. Signed-off-by: Yonghong Song <yhs@fb.com>
- Loading branch information
1 parent
5d9ec32
commit caf25e8
Showing
2 changed files
with
29 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,27 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
|
||
#include <linux/bpf.h> | ||
#include <bpf/bpf_helpers.h> | ||
#include "bpf_misc.h" | ||
|
||
SEC("socket") | ||
__description("check w reg equal if r reg upper32 bits 0") | ||
__success | ||
__naked void subreg_equality(void) | ||
{ | ||
asm volatile (" \ | ||
call %[bpf_ktime_get_ns]; \ | ||
*(u64 *)(r10 - 8) = r0; \ | ||
r2 = *(u32 *)(r10 - 8); \ | ||
w3 = w2; \ | ||
if w2 < 9 goto l0_%=; \ | ||
exit; \ | ||
l0_%=: if r3 < 9 goto l1_%=; \ | ||
r0 -= r1; \ | ||
l1_%=: exit; \ | ||
" : | ||
: __imm(bpf_ktime_get_ns) | ||
: __clobber_all); | ||
} | ||
|
||
char _license[] SEC("license") = "GPL"; |