aboutsummaryrefslogtreecommitdiff
path: root/tools/testing
AgeCommit message (Collapse)AuthorFilesLines
2023-04-13selftests/bpf: Fix compiler warnings in bpf_testmod for kfuncsAndrii Nakryiko1-0/+6
Add -Wmissing-prototypes ignore in bpf_testmod.c, similarly to what we do in kernel code proper. Reported-by: kernel test robot <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Link: https://lore.kernel.org/bpf/[email protected]
2023-04-13selftests/bpf: Remove stand-along test_verifier_log test binaryAndrii Nakryiko2-176/+1
test_prog's prog_tests/verifier_log.c is superseding test_verifier_log stand-alone test. It cover same checks and adds more, and is also integrated into test_progs test runner. Just remove test_verifier_log.c. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-13selftests/bpf: Keep the loop in bpf_testmod_loop_testSong Liu1-1/+5
Some compilers (for example clang-15) optimize bpf_testmod_loop_test and remove the loop: gcc version (gdb) disassemble bpf_testmod_loop_test Dump of assembler code for function bpf_testmod_loop_test: 0x0000000000000570 <+0>: callq 0x575 <bpf_testmod_loop_test+5> 0x0000000000000575 <+5>: xor %eax,%eax 0x0000000000000577 <+7>: test %edi,%edi 0x0000000000000579 <+9>: jle 0x587 <bpf_testmod_loop_test+23> 0x000000000000057b <+11>: xor %edx,%edx 0x000000000000057d <+13>: add %edx,%eax 0x000000000000057f <+15>: add $0x1,%edx 0x0000000000000582 <+18>: cmp %edx,%edi 0x0000000000000584 <+20>: jne 0x57d <bpf_testmod_loop_test+13> 0x0000000000000586 <+22>: retq 0x0000000000000587 <+23>: retq clang-15 version (gdb) disassemble bpf_testmod_loop_test Dump of assembler code for function bpf_testmod_loop_test: 0x0000000000000450 <+0>: nopl 0x0(%rax,%rax,1) 0x0000000000000455 <+5>: test %edi,%edi 0x0000000000000457 <+7>: jle 0x46b <bpf_testmod_loop_test+27> 0x0000000000000459 <+9>: lea -0x1(%rdi),%eax 0x000000000000045c <+12>: lea -0x2(%rdi),%ecx 0x000000000000045f <+15>: imul %rax,%rcx 0x0000000000000463 <+19>: shr %rcx 0x0000000000000466 <+22>: lea -0x1(%rdi,%rcx,1),%eax 0x000000000000046a <+26>: retq 0x000000000000046b <+27>: xor %eax,%eax 0x000000000000046d <+29>: retq Note: The jne instruction is removed in clang-15 version. Force the compile to keep the loop by making sum volatile. Signed-off-by: Song Liu <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-13selftests/bpf: Fix leaked bpf_link in get_stackid_cannot_attachSong Liu1-0/+1
skel->links.oncpu is leaked in one case. This causes test perf_branches fails when it runs after get_stackid_cannot_attach: ./test_progs -t get_stackid_cannot_attach,perf_branches 84 get_stackid_cannot_attach:OK test_perf_branches_common:PASS:test_perf_branches_load 0 nsec test_perf_branches_common:PASS:attach_perf_event 0 nsec test_perf_branches_common:PASS:set_affinity 0 nsec check_good_sample:FAIL:output not valid no valid sample from prog 146/1 perf_branches/perf_branches_hw:FAIL 146/2 perf_branches/perf_branches_no_hw:OK 146 perf_branches:FAIL All error logs: test_perf_branches_common:PASS:test_perf_branches_load 0 nsec test_perf_branches_common:PASS:attach_perf_event 0 nsec test_perf_branches_common:PASS:set_affinity 0 nsec check_good_sample:FAIL:output not valid no valid sample from prog 146/1 perf_branches/perf_branches_hw:FAIL 146 perf_branches:FAIL Summary: 1/1 PASSED, 0 SKIPPED, 1 FAILED Fix this by adding the missing bpf_link__destroy(). Fixes: 346938e9380c ("selftests/bpf: Add get_stackid_cannot_attach") Signed-off-by: Song Liu <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-13selftests/bpf: Use read_perf_max_sample_freq() in perf_event_stackmapSong Liu4-16/+24
Currently, perf_event sample period in perf_event_stackmap is set too low that the test fails randomly. Fix this by using the max sample frequency, from read_perf_max_sample_freq(). Move read_perf_max_sample_freq() to testing_helpers.c. Replace the CHECK() with if-printf, as CHECK is not available in testing_helpers.c. Fixes: 1da4864c2b20 ("selftests/bpf: Add callchain_stackid") Signed-off-by: Song Liu <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-13selftests/bpf: Fix use of uninitialized op_name in log testsLorenz Bauer1-1/+1
One of the test assertions uses an uninitialized op_name, which leads to some headscratching if it fails. Use a string constant instead. Fixes: b1a7a480a112 ("selftests/bpf: Add fixed vs rotating verifier log tests") Signed-off-by: Lorenz Bauer <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-12selftests/bpf: Test FOU kfuncs for externally controlled ipip devicesChristian Ehrig2-2/+268
Add tests for FOU and GUE encapsulation via the bpf_skb_{set,get}_fou_encap kfuncs, using ipip devices in collect-metadata mode. These tests make sure that we can successfully set and obtain FOU and GUE encap parameters using ingress / egress BPF tc-hooks. Signed-off-by: Christian Ehrig <[email protected]> Link: https://lore.kernel.org/r/040193566ddbdb0b53eb359f7ac7bbd316f338b5.1680874078.git.cehrig@cloudflare.com Signed-off-by: Alexei Starovoitov <[email protected]>
2023-04-12bpf: Remove bpf_cgroup_kptr_get() kfuncDavid Vernet3-67/+14
Now that bpf_cgroup_acquire() is KF_RCU | KF_RET_NULL, bpf_cgroup_kptr_get() is redundant. Let's remove it, and update selftests to instead use bpf_cgroup_acquire() where appropriate. The next patch will update the BPF documentation to not mention bpf_cgroup_kptr_get(). Signed-off-by: David Vernet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
2023-04-12bpf: Make bpf_cgroup_acquire() KF_RCU | KF_RET_NULLDavid Vernet3-7/+38
struct cgroup is already an RCU-safe type in the verifier. We can therefore update bpf_cgroup_acquire() to be KF_RCU | KF_RET_NULL, and subsequently remove bpf_cgroup_kptr_get(). This patch does the first of these by updating bpf_cgroup_acquire() to be KF_RCU | KF_RET_NULL, and also updates selftests accordingly. Signed-off-by: David Vernet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
2023-04-12selftests: hid: import hid-tools usb-crash testsBenjamin Tissoires3-0/+111
These tests have been developed in the hid-tools[0] tree for a while. Now that we have a proper selftests/hid kernel entry and that the tests are more reliable, it is time to directly include those in the kernel tree. This one gets skipped when run by vmtest.sh as we currently need to test against actual kernel modules (.ko), not built-in to fetch the list of supported devices. [0] https://gitlab.freedesktop.org/libevdev/hid-tools Signed-off-by: Benjamin Tissoires <[email protected]>
2023-04-12selftests: hid: import hid-tools hid-sony and hid-playstation testsBenjamin Tissoires4-0/+355
These tests have been developed in the hid-tools[0] tree for a while. Now that we have a proper selftests/hid kernel entry and that the tests are more reliable, it is time to directly include those in the kernel tree. The code is taken from [1] to fix a change in v6.3. [0] https://gitlab.freedesktop.org/libevdev/hid-tools Link: https://gitlab.freedesktop.org/libevdev/hid-tools/-/merge_requests/143 [1] Cc: Roderick Colenbrander <[email protected]> Cc: Jose Torreguitar <[email protected]> Signed-off-by: Roderick Colenbrander <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
2023-04-12selftests: hid: import hid-tools hid-ite testsBenjamin Tissoires4-0/+175
These tests have been developed in the hid-tools[0] tree for a while. Now that we have a proper selftests/hid kernel entry and that the tests are more reliable, it is time to directly include those in the kernel tree. [0] https://gitlab.freedesktop.org/libevdev/hid-tools Cc: Peter Hutterer <[email protected]> Cc: Roderick Colenbrander <[email protected]> Signed-off-by: Peter Hutterer <[email protected]> Signed-off-by: Roderick Colenbrander <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
2023-04-12selftests: hid: import hid-tools hid-apple testsBenjamin Tissoires4-0/+449
These tests have been developed in the hid-tools[0] tree for a while. Now that we have a proper selftests/hid kernel entry and that the tests are more reliable, it is time to directly include those in the kernel tree. [0] https://gitlab.freedesktop.org/libevdev/hid-tools Cc: Roderick Colenbrander <[email protected]> Signed-off-by: Roderick Colenbrander <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
2023-04-12selftests: hid: import hid-tools wacom testsBenjamin Tissoires5-0/+2215
These tests have been developed in the hid-tools[0] tree for a while. Now that we have a proper selftests/hid kernel entry and that the tests are more reliable, it is time to directly include those in the kernel tree. [0] https://gitlab.freedesktop.org/libevdev/hid-tools Cc: Jason Gerecke <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
2023-04-12selftests: hid: import hid-tools hid-multitouch and hid-tablets testsBenjamin Tissoires7-0/+2980
These tests have been developed in the hid-tools[0] tree for a while. Now that we have a proper selftests/hid kernel entry and that the tests are more reliable, it is time to directly include those in the kernel tree. There are a lot of multitouch tests, and the default timeout of 45 seconds is not big enough. Bump it to 200 seconds. [0] https://gitlab.freedesktop.org/libevdev/hid-tools Cc: Peter Hutterer <[email protected]> Cc: Kai-Heng Feng <[email protected]> Cc: Roderick Colenbrander <[email protected]> Cc: наб <[email protected]> Cc: Blaž Hrastnik <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Signed-off-by: Peter Hutterer <[email protected]> Signed-off-by: Roderick Colenbrander <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
2023-04-12selftests: hid: import hid-tools hid-mouse testsBenjamin Tissoires3-0/+985
These tests have been developed in the hid-tools[0] tree for a while. Now that we have a proper selftests/hid kernel entry and that the tests are more reliable, it is time to directly include those in the kernel tree. [0] https://gitlab.freedesktop.org/libevdev/hid-tools Cc: Peter Hutterer <[email protected]> Cc: Roderick Colenbrander <[email protected]> Signed-off-by: Peter Hutterer <[email protected]> Signed-off-by: Roderick Colenbrander <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
2023-04-12selftests: hid: import hid-tools hid-keyboards testsBenjamin Tissoires3-0/+493
These tests have been developed in the hid-tools[0] tree for a while. Now that we have a proper selftests/hid kernel entry and that the tests are more reliable, it is time to directly include those in the kernel tree. [0] https://gitlab.freedesktop.org/libevdev/hid-tools Cc: Nicolas Saenz Julienne <[email protected]> Cc: Peter Hutterer <[email protected]> Cc: Roderick Colenbrander <[email protected]> Signed-off-by: Peter Hutterer <[email protected]> Signed-off-by: Roderick Colenbrander <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
2023-04-12selftests: hid: import hid-tools hid-gamepad testsBenjamin Tissoires3-0/+217
These tests have been developed in the hid-tools[0] tree for a while. Now that we have a proper selftests/hid kernel entry and that the tests are more reliable, it is time to directly include those in the kernel tree. [0] https://gitlab.freedesktop.org/libevdev/hid-tools Cc: Candle Sun <[email protected]> Cc: Jose Torreguitar <[email protected]> Cc: Peter Hutterer <[email protected]> Cc: Roderick Colenbrander <[email protected]> Cc: Silvan Jegen <[email protected]> Signed-off-by: Silvan Jegen <[email protected]> Signed-off-by: Peter Hutterer <[email protected]> Signed-off-by: Roderick Colenbrander <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
2023-04-12selftests: hid: import hid-tools hid-core testsBenjamin Tissoires8-1/+620
These tests have been developed in the hid-tools[0] tree for a while. Now that we have a proper selftests/hid kernel entry and that the tests are more reliable, it is time to directly include those in the kernel tree. I haven't imported all of hid-tools, the python module, but only the tests related to the kernel. We can rely on pip to fetch the latest hid-tools release, and then run the tests directly from the tree. This should now be easier to request tests when something is not behaving properly in the HID subsystem. [0] https://gitlab.freedesktop.org/libevdev/hid-tools Cc: Peter Hutterer <[email protected]> Signed-off-by: Peter Hutterer <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
2023-04-12selftests: hid: make vmtest rely on makeBenjamin Tissoires1-10/+15
Having a default binary is simple enough, but this also means that we need to keep the targets in sync as we are adding them in the Makefile. So instead of doing that manual work, make vmtest.sh generic enough to actually be capable of running 'make -C tools/testing/selftests/hid'. The new image we use has make installed, which the base fedora image doesn't. Signed-off-by: Benjamin Tissoires <[email protected]>
2023-04-11kselftest/arm64: Convert za-fork to use kselftest.hMark Brown2-73/+17
Now that kselftest.h can be used with nolibc convert the za-fork test to use it. We do still have to open code ksft_print_msg() but that's not the end of the world. Some of the advantage comes from using printf() which we could have been using already. This does change the output when tests are skipped, bringing it in line with the standard kselftest output by removing the test name - we move from ok 0 skipped to ok 1 # SKIP fork_test The old output was not following KTAP format for skips, and the numbering was not standard or consistent with the reported plan. Signed-off-by: Mark Brown <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2023-04-11kselftest: Support nolibcMark Brown1-0/+2
Rather than providing headers for inclusion which replace any offered by the system nolibc is provided in the form of a header which should be added to the build via the compiler command line. In order to build with nolibc we need to not include the standard C headers, especially not stdio.h where the definitions of stdout, stdin and stderr will actively conflict with nolibc. Add an include guard which suppresses the inclusion of the standard headers when building with nolibc, allowing us to build tests using the nolibc headers. This allows us to avoid open coding of KTAP output for selftests that need to use nolibc in order to test interfaces that are controlled by libc. Signed-off-by: Mark Brown <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2023-04-11selftests/bpf: Add test to access u32 ptr argument in tracing programFeng Zhou1-0/+13
Adding verifier test for accessing u32 pointer argument in tracing programs. The test program loads 1nd argument of bpf_fentry_test9 function which is u32 pointer and checks that verifier allows that. Co-developed-by: Chengming Zhou <[email protected]> Signed-off-by: Chengming Zhou <[email protected]> Signed-off-by: Feng Zhou <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Jiri Olsa <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-11KVM: selftests: Add test to verify KVM's supported XCR0Aaron Lewis3-0/+153
Check both architectural rules and KVM's ABI for KVM_GET_SUPPORTED_CPUID to ensure the supported xfeatures[1] don't violate any of them. The architectural rules[2] and KVM's contract with userspace ensure for a given feature, e.g. sse, avx, amx, etc... their associated xfeatures are either all sets or none of them are set, and any dependencies are enabled if needed. [1] EDX:EAX of CPUID.(EAX=0DH,ECX=0) [2] SDM vol 1, 13.3 ENABLING THE XSAVE FEATURE SET AND XSAVE-ENABLED FEATURES Cc: Mingwei Zhang <[email protected]> Signed-off-by: Aaron Lewis <[email protected]> [sean: expand comments, use a fancy X86_PROPERTY] Reviewed-by: Aaron Lewis <[email protected]> Tested-by: Aaron Lewis <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
2023-04-11KVM: selftests: Add all known XFEATURE masks to common codeAaron Lewis2-30/+33
Add all known XFEATURE masks to processor.h to make them more broadly available in KVM selftests. Relocate and clean up the exiting AMX (XTILE) defines in processor.h, e.g. drop the intermediate define and use BIT_ULL. Signed-off-by: Aaron Lewis <[email protected]> Reviewed-by: Aaron Lewis <[email protected]> Tested-by: Aaron Lewis <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
2023-04-11KVM: selftests: Rework dynamic XFeature helper to take mask, not bitSean Christopherson3-11/+14
Take the XFeature mask in __vm_xsave_require_permission() instead of the bit so that there's no need to define macros for both the bit and the mask. Asserting that only a single bit is set and retrieving said bit is easy enough via log2 helpers. Opportunistically clean up the error message for the ARCH_REQ_XCOMP_GUEST_PERM sanity check. Reviewed-by: Aaron Lewis <[email protected]> Tested-by: Aaron Lewis <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
2023-04-11KVM: selftests: Move XGETBV and XSETBV helpers to common codeAaron Lewis2-21/+21
The instructions XGETBV and XSETBV are useful to other tests. Move them to processor.h to make them more broadly available. No functional change intended. Reviewed-by: Jim Mattson <[email protected]> Signed-off-by: Aaron Lewis <[email protected]> Reviewed-by: Mingwei Zhang <[email protected]> [sean: reword shortlog] Reviewed-by: Aaron Lewis <[email protected]> Tested-by: Aaron Lewis <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
2023-04-11selftests/bpf: Add verifier log tests for BPF_BTF_LOAD commandAndrii Nakryiko1-0/+188
Add verifier log tests for BPF_BTF_LOAD command, which are very similar, conceptually, to BPF_PROG_LOAD tests. These are two separate commands dealing with verbose verifier log, so should be both tested separately. Test that log_buf==NULL condition *does not* return -ENOSPC. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Lorenz Bauer <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-11selftests/bpf: Add testing of log_buf==NULL condition for BPF_PROG_LOADAndrii Nakryiko1-0/+23
Add few extra test conditions to validate that it's ok to pass log_buf==NULL and log_size==0 to BPF_PROG_LOAD command with the intent to get log_true_size without providing a buffer. Test that log_buf==NULL condition *does not* return -ENOSPC. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Lorenz Bauer <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-11selftests/bpf: Add tests to validate log_true_size featureAndrii Nakryiko1-16/+76
Add additional test cases validating that log_true_size is consistent between fixed and rotating log modes, and that log_true_size can be used *exactly* without causing -ENOSPC, while using just 1 byte shorter log buffer would cause -ENOSPC. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Lorenz Bauer <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-11selftests/bpf: Add fixed vs rotating verifier log testsAndrii Nakryiko1-0/+179
Add selftests validating BPF_LOG_FIXED behavior, which used to be the only behavior, and now default rotating BPF verifier log, which returns just up to last N bytes of full verifier log, instead of returning -ENOSPC. To stress test correctness of in-kernel verifier log logic, we force it to truncate program's verifier log to all lengths from 1 all the way to its full size (about 450 bytes today). This was a useful stress test while developing the feature. For both fixed and rotating log modes we expect -ENOSPC if log contents doesn't fit in user-supplied log buffer. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Lorenz Bauer <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-11veristat: Add more veristat control over verifier log optionsAndrii Nakryiko1-9/+35
Add --log-size to be able to customize log buffer sent to bpf() syscall for BPF program verification logging. Add --log-fixed to enforce BPF_LOG_FIXED behavior for BPF verifier log. This is useful in unlikely event that beginning of truncated verifier log is more important than the end of it (which with rotating verifier log behavior is the default now). Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-11bpf: Switch BPF verifier log to be a rotating log by defaultAndrii Nakryiko1-0/+1
Currently, if user-supplied log buffer to collect BPF verifier log turns out to be too small to contain full log, bpf() syscall returns -ENOSPC, fails BPF program verification/load, and preserves first N-1 bytes of the verifier log (where N is the size of user-supplied buffer). This is problematic in a bunch of common scenarios, especially when working with real-world BPF programs that tend to be pretty complex as far as verification goes and require big log buffers. Typically, it's when debugging tricky cases at log level 2 (verbose). Also, when BPF program is successfully validated, log level 2 is the only way to actually see verifier state progression and all the important details. Even with log level 1, it's possible to get -ENOSPC even if the final verifier log fits in log buffer, if there is a code path that's deep enough to fill up entire log, even if normally it would be reset later on (there is a logic to chop off successfully validated portions of BPF verifier log). In short, it's not always possible to pre-size log buffer. Also, what's worse, in practice, the end of the log most often is way more important than the beginning, but verifier stops emitting log as soon as initial log buffer is filled up. This patch switches BPF verifier log behavior to effectively behave as rotating log. That is, if user-supplied log buffer turns out to be too short, verifier will keep overwriting previously written log, effectively treating user's log buffer as a ring buffer. -ENOSPC is still going to be returned at the end, to notify user that log contents was truncated, but the important last N bytes of the log would be returned, which might be all that user really needs. This consistent -ENOSPC behavior, regardless of rotating or fixed log behavior, allows to prevent backwards compatibility breakage. The only user-visible change is which portion of verifier log user ends up seeing *if buffer is too small*. Given contents of verifier log itself is not an ABI, there is no breakage due to this behavior change. Specialized tools that rely on specific contents of verifier log in -ENOSPC scenario are expected to be easily adapted to accommodate old and new behaviors. Importantly, though, to preserve good user experience and not require every user-space application to adopt to this new behavior, before exiting to user-space verifier will rotate log (in place) to make it start at the very beginning of user buffer as a continuous zero-terminated string. The contents will be a chopped off N-1 last bytes of full verifier log, of course. Given beginning of log is sometimes important as well, we add BPF_LOG_FIXED (which equals 8) flag to force old behavior, which allows tools like veristat to request first part of verifier log, if necessary. BPF_LOG_FIXED flag is also a simple and straightforward way to check if BPF verifier supports rotating behavior. On the implementation side, conceptually, it's all simple. We maintain 64-bit logical start and end positions. If we need to truncate the log, start position will be adjusted accordingly to lag end position by N bytes. We then use those logical positions to calculate their matching actual positions in user buffer and handle wrap around the end of the buffer properly. Finally, right before returning from bpf_check(), we rotate user log buffer contents in-place as necessary, to make log contents contiguous. See comments in relevant functions for details. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Lorenz Bauer <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-10selftests/resctrl: Correct get_llc_perf() param in function commentIlpo Järvinen1-1/+1
get_llc_perf() function comment refers to cpu_no parameter that does not exist. Correct get_llc_perf() the comment to document llc_perf_miss instead. Signed-off-by: Ilpo Järvinen <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2023-04-10selftests/resctrl: Use remount_resctrlfs() consistently with booleanIlpo Järvinen5-8/+7
remount_resctrlfs() accepts a boolean value as an argument. Some tests pass 0/1 and some tests pass true/false. Make all the callers of remount_resctrlfs() use true/false so that the parameter usage is consistent across tests. Co-developed-by: Fenghua Yu <[email protected]> Signed-off-by: Fenghua Yu <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2023-04-10selftests/resctrl: Change name from CBM_MASK_PATH to INFO_PATHFenghua Yu2-2/+2
CBM_MASK_PATH is actually the path to resctrl/info. Change the macro name to correctly indicate what it represents. [ ij: Tweaked the changelog. ] Signed-off-by: Fenghua Yu <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2023-04-10selftests/resctrl: Change initialize_llc_perf() return type to voidIlpo Järvinen1-8/+3
initialize_llc_perf() unconditionally returns 0. initialize_llc_perf() performs only memory initialization, none of which can fail. Change the return type from int to void to accurately reflect that its return value doesn't need to be checked. Remove the error checking from the only callsite. Co-developed-by: Fenghua Yu <[email protected]> Signed-off-by: Fenghua Yu <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2023-04-10selftests/resctrl: Replace obsolete memalign() with posix_memalign()Ilpo Järvinen1-3/+4
memalign() is obsolete according to its manpage. Replace memalign() with posix_memalign() and remove malloc.h include that was there for memalign(). As a pointer is passed into posix_memalign(), initialize *p to NULL to silence a warning about the function's return value being used as uninitialized (which is not valid anyway because the error is properly checked before p is returned). Suggested-by: Reinette Chatre <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2023-04-10selftests/resctrl: Check for return value after write_schemata()Ilpo Järvinen1-1/+6
MBA test case writes schemata but it does not check if the write is successful or not. Add the error check and return error properly. Fixes: 01fee6b4d1f9 ("selftests/resctrl: Add MBA test") Co-developed-by: Fenghua Yu <[email protected]> Signed-off-by: Fenghua Yu <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2023-04-10selftests/resctrl: Allow ->setup() to return errorsIlpo Järvinen7-6/+12
resctrl_val() assumes ->setup() always returns either 0 to continue tests or < 0 in case of the normal termination of tests after x runs. The latter overlaps with normal error returns. Define END_OF_TESTS (=1) to differentiate the normal termination of tests and return errors as negative values. Alter callers of ->setup() to handle errors properly. Fixes: 790bf585b0ee ("selftests/resctrl: Add Cache Allocation Technology (CAT) selftest") Fixes: ecdbb911f22d ("selftests/resctrl: Add MBM test") Signed-off-by: Ilpo Järvinen <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2023-04-10selftests/resctrl: Move ->setup() call outside of test specific branchesIlpo Järvinen1-13/+6
resctrl_val() function is called only by MBM, MBA, and CMT tests which means the else branch is never used. Both test branches call param->setup(). Remove the unused else branch and place the ->setup() call outside of the test specific branches reducing code duplication. Co-developed-by: Fenghua Yu <[email protected]> Signed-off-by: Fenghua Yu <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2023-04-10selftests/resctrl: Return NULL if malloc_and_init_memory() did not alloc memIlpo Järvinen1-0/+2
malloc_and_init_memory() in fill_buf isn't checking if memalign() successfully allocated memory or not before accessing the memory. Check the return value of memalign() and return NULL if allocating aligned memory fails. Fixes: a2561b12fe39 ("selftests/resctrl: Add built in benchmark") Co-developed-by: Fenghua Yu <[email protected]> Signed-off-by: Fenghua Yu <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2023-04-10selftests/bpf: Reset err when symbol name already exist in kprobe_multi_testManu Bretelle1-1/+3
When trying to add a name to the hashmap, an error code of EEXIST is returned and we continue as names are possibly duplicated in the sys file. If the last name in the file is a duplicate, we will continue to the next iteration of the while loop, and exit the loop with a value of err set to EEXIST and enter the error label with err set, which causes the test to fail when it should not. This change reset err to 0 before continue-ing into the next iteration, this way, if there is no more data to read from the file we iterate through, err will be set to 0. Behaviour prior to this change: ``` test_kprobe_multi_bench_attach:FAIL:get_syms unexpected error: -17 (errno 2) All error logs: test_kprobe_multi_bench_attach:FAIL:get_syms unexpected error: -17 (errno 2) Summary: 0/1 PASSED, 0 SKIPPED, 1 FAILED ``` After this change: ``` Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED ``` Signed-off-by: Manu Bretelle <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-08Merge tag 'mm-hotfixes-stable-2023-04-07-16-23' of ↵Linus Torvalds1-0/+16
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Pull MM fixes from Andrew Morton: "28 hotfixes. 23 are cc:stable and the other five address issues which were introduced during this merge cycle. 20 are for MM and the remainder are for other subsystems" * tag 'mm-hotfixes-stable-2023-04-07-16-23' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (28 commits) maple_tree: fix a potential concurrency bug in RCU mode maple_tree: fix get wrong data_end in mtree_lookup_walk() mm/swap: fix swap_info_struct race between swapoff and get_swap_pages() nilfs2: fix sysfs interface lifetime mm: take a page reference when removing device exclusive entries mm: vmalloc: avoid warn_alloc noise caused by fatal signal nilfs2: initialize "struct nilfs_binfo_dat"->bi_pad field nilfs2: fix potential UAF of struct nilfs_sc_info in nilfs_segctor_thread() zsmalloc: document freeable stats zsmalloc: document new fullness grouping fsdax: force clear dirty mark if CoW mm/hugetlb: fix uffd wr-protection for CoW optimization path mm: enable maple tree RCU mode by default maple_tree: add RCU lock checking to rcu callback functions maple_tree: add smp_rmb() to dead node detection maple_tree: fix write memory barrier of nodes once dead for RCU mode maple_tree: remove extra smp_wmb() from mas_dead_leaves() maple_tree: fix freeing of nodes in rcu mode maple_tree: detect dead nodes in mas_start() maple_tree: be more cautious about dead nodes ...
2023-04-08KVM: selftests: Fix spelling mistake "KVM_HYPERCAL_EXIT_SMC" -> ↵Colin Ian King1-1/+1
"KVM_HYPERCALL_EXIT_SMC" There is a spelling mistake in a test assert message. Fix it. Signed-off-by: Colin Ian King <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
2023-04-08KVM: arm64: Test that SMC64 arch calls are reservedOliver Upton1-0/+8
Assert that the SMC64 view of the Arm architecture range is reserved by KVM and cannot be filtered by userspace. Signed-off-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
2023-04-07Merge tag 'for-netdev' of ↵Jakub Kicinski1-3/+27
https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf Daniel Borkmann says: ==================== pull-request: bpf 2023-04-08 We've added 4 non-merge commits during the last 11 day(s) which contain a total of 5 files changed, 39 insertions(+), 6 deletions(-). The main changes are: 1) Fix BPF TCP socket iterator to use correct helper for dropping socket's refcount, that is, sock_gen_put instead of sock_put, from Martin KaFai Lau. 2) Fix a BTI exception splat in BPF trampoline-generated code on arm64, from Xu Kuohai. 3) Fix a LongArch JIT error from missing BPF_NOSPEC no-op, from George Guo. 4) Fix dynamic XDP feature detection of veth in xdp_redirect selftest, from Lorenzo Bianconi. * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: selftests/bpf: fix xdp_redirect xdp-features selftest for veth driver bpf, arm64: Fixed a BTI error on returning to patched function LoongArch, bpf: Fix jit to skip speculation barrier opcode bpf: tcp: Use sock_gen_put instead of sock_put in bpf_iter_tcp ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2023-04-07selftests/bpf: Prevent infinite loop in veristat when base file is too shortEduard Zingerman1-2/+6
The following example forces veristat to loop indefinitely: $ cat two-ok file_name,prog_name,verdict,total_states file-a,a,success,12 file-b,b,success,67 $ cat add-failure file_name,prog_name,verdict,total_states file-a,a,success,12 file-b,b,success,67 file-b,c,failure,32 $ veristat -C two-ok add-failure <does not return> The loop is caused by handle_comparison_mode() not checking if `base` variable points to `fallback_stats` prior advancing joined results using `base`. Signed-off-by: Eduard Zingerman <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-07selftests/bpf: Use PERF_COUNT_HW_CPU_CYCLES event for get_branch_snapshotSong Liu1-2/+2
perf_event with type=PERF_TYPE_RAW and config=0x1b00 turned out to be not reliable in ensuring LBR is active. Thus, test_progs:get_branch_snapshot is not reliable in some systems. Replace it with PERF_COUNT_HW_CPU_CYCLES event, which gives more consistent results. Signed-off-by: Song Liu <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Jiri Olsa <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
2023-04-07selftests: bonding: add arp validate testHangbin Liu1-0/+55
This patch add bonding arp validate tests with mode active backup, monitor arp_ip_target and ns_ip6_target. It also checks mii_status to make sure all slaves are UP. Acked-by: Jonathan Toppins <[email protected]> Acked-by: Jay Vosburgh <[email protected]> Signed-off-by: Hangbin Liu <[email protected]> Signed-off-by: David S. Miller <[email protected]>