Commit Graph

7 Commits

Author SHA1 Message Date
Jerome Marchand 9187621f65 selftests/bpf: fix some typos in selftests
JIRA: https://issues.redhat.com/browse/RHEL-63880

commit 5db0ba6766f8a6606e655ddad745c87bc01349c7
Author: Lin Yikai <yikai.lin@vivo.com>
Date:   Thu Sep 5 19:03:05 2024 +0800

    selftests/bpf: fix some typos in selftests

    Hi, fix some spelling errors in selftest, the details are as follows:

    -in the codes:
    	test_bpf_sk_stoarge_map_iter_fd(void)
    		->test_bpf_sk_storage_map_iter_fd(void)
    	load BTF from btf_data.o->load BTF from btf_data.bpf.o

    -in the code comments:
    	preample->preamble
    	multi-contollers->multi-controllers
    	errono->errno
    	unsighed/unsinged->unsigned
    	egree->egress
    	shoud->should
    	regsiter->register
    	assummed->assumed
    	conditiona->conditional
    	rougly->roughly
    	timetamp->timestamp
    	ingores->ignores
    	null-termainted->null-terminated
    	slepable->sleepable
    	implemenation->implementation
    	veriables->variables
    	timetamps->timestamps
    	substitue a costant->substitute a constant
    	secton->section
    	unreferened->unreferenced
    	verifer->verifier
    	libppf->libbpf
    ...

    Signed-off-by: Lin Yikai <yikai.lin@vivo.com>
    Link: https://lore.kernel.org/r/20240905110354.3274546-1-yikai.lin@vivo.com
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2025-01-21 11:27:03 +01:00
Jerome Marchand 81c017fbe7 selftests/bpf: Fix missing BUILD_BUG_ON() declaration
JIRA: https://issues.redhat.com/browse/RHEL-63880

commit 6495eb79ca7d15bd87c38d77307e8f9b6b7bf4ef
Author: Tony Ambardar <tony.ambardar@gmail.com>
Date:   Mon Jul 22 22:54:36 2024 -0700

    selftests/bpf: Fix missing BUILD_BUG_ON() declaration

    Explicitly include '<linux/build_bug.h>' to fix errors seen compiling with
    gcc targeting mips64el/musl-libc:

      user_ringbuf.c: In function 'test_user_ringbuf_loop':
      user_ringbuf.c:426:9: error: implicit declaration of function 'BUILD_BUG_ON' [-Werror=implicit-function-declaration]
        426 |         BUILD_BUG_ON(total_samples <= c_max_entries);
            |         ^~~~~~~~~~~~
      cc1: all warnings being treated as errors

    Fixes: e5a9df51c746 ("selftests/bpf: Add selftests validating the user ringbuf")
    Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/b28575f9221ec54871c46a2e87612bb4bbf46ccd.1721713597.git.tony.ambardar@gmail.com

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2025-01-13 17:36:35 +01:00
Artem Savkov 536eab41f8 selftests/bpf: Use __NR_prlimit64 instead of __NR_getrlimit in user_ringbuf test
Bugzilla: https://bugzilla.redhat.com/2221599

commit 84c22fa83f9cb97061359f97d85f53a9ccde02c4
Author: Tiezhu Yang <yangtiezhu@loongson.cn>
Date:   Fri Feb 24 18:36:55 2023 +0800

    selftests/bpf: Use __NR_prlimit64 instead of __NR_getrlimit in user_ringbuf test
    
    After commit 80d7da1cac ("asm-generic: Drop getrlimit and setrlimit
    syscalls from default list"), new architectures won't need to include
    getrlimit and setrlimit, they are superseded with prlimit64.
    
    In order to maintain compatibility for the new architectures, such as
    LoongArch which does not define __NR_getrlimit, it is better to use
    __NR_prlimit64 instead of __NR_getrlimit in user_ringbuf test to fix
    the following build error:
    
        TEST-OBJ [test_progs] user_ringbuf.test.o
      tools/testing/selftests/bpf/prog_tests/user_ringbuf.c: In function 'kick_kernel_cb':
      tools/testing/selftests/bpf/prog_tests/user_ringbuf.c:593:17: error: '__NR_getrlimit' undeclared (first use in this function)
        593 |         syscall(__NR_getrlimit);
            |                 ^~~~~~~~~~~~~~
      tools/testing/selftests/bpf/prog_tests/user_ringbuf.c:593:17: note: each undeclared identifier is reported only once for each function it appears in
      make: *** [Makefile:573: tools/testing/selftests/bpf/user_ringbuf.test.o] Error 1
      make: Leaving directory 'tools/testing/selftests/bpf'
    
    Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/1677235015-21717-4-git-send-email-yangtiezhu@loongson.cn

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2023-09-22 09:12:07 +02:00
Viktor Malik 6a98d5687e selftests/bpf: Clean up user_ringbuf, cgrp_kfunc, kfunc_dynptr_param tests
Bugzilla: https://bugzilla.redhat.com/2178930

commit 8032cad1030279066ce4a1f82b76d0fe7eb578e2
Author: Joanne Koong <joannelkoong@gmail.com>
Date:   Mon Feb 13 21:13:31 2023 -0800

    selftests/bpf: Clean up user_ringbuf, cgrp_kfunc, kfunc_dynptr_param tests
    
    Clean up user_ringbuf, cgrp_kfunc, and kfunc_dynptr_param tests to use
    the generic verification tester for checking verifier rejections.
    The generic verification tester uses btf_decl_tag-based annotations
    for verifying that the tests fail with the expected log messages.
    
    Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
    Acked-by: David Vernet <void@manifault.com>
    Reviewed-by: Roberto Sassu <roberto.sassu@huawei.com>
    Link: https://lore.kernel.org/r/20230214051332.4007131-1-joannelkoong@gmail.com
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2023-06-13 22:45:31 +02:00
Jerome Marchand 92de11b48e selftests/bpf: Add test for dynptr reinit in user_ringbuf callback
Bugzilla: https://bugzilla.redhat.com/2177177

commit 292064cce7969787f13ed9988733aadc12fe0ca2
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Date:   Thu Dec 8 02:11:41 2022 +0530

    selftests/bpf: Add test for dynptr reinit in user_ringbuf callback
    
    The original support for bpf_user_ringbuf_drain callbacks simply
    short-circuited checks for the dynptr state, allowing users to pass
    PTR_TO_DYNPTR (now CONST_PTR_TO_DYNPTR) to helpers that initialize a
    dynptr. This bug would have also surfaced with other dynptr helpers in
    the future that changed dynptr view or modified it in some way.
    
    Include test cases for all cases, i.e. both bpf_dynptr_from_mem and
    bpf_ringbuf_reserve_dynptr, and ensure verifier rejects both of them.
    Without the fix, both of these programs load and pass verification.
    
    While at it, remove sys_nanosleep target from failure cases' SEC
    definition, as there is no such tracepoint.
    
    Acked-by: David Vernet <void@manifault.com>
    Acked-by: Joanne Koong <joannelkoong@gmail.com>
    Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
    Link: https://lore.kernel.org/r/20221207204141.308952-8-memxor@gmail.com
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2023-04-28 11:43:17 +02:00
Jerome Marchand a59af7f5dd bpf: Rework process_dynptr_func
Bugzilla: https://bugzilla.redhat.com/2177177

commit 270605317366e4535d8d9fc3d9da1ad0fb3c9d45
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Date:   Thu Dec 8 02:11:37 2022 +0530

    bpf: Rework process_dynptr_func
    
    Recently, user ringbuf support introduced a PTR_TO_DYNPTR register type
    for use in callback state, because in case of user ringbuf helpers,
    there is no dynptr on the stack that is passed into the callback. To
    reflect such a state, a special register type was created.
    
    However, some checks have been bypassed incorrectly during the addition
    of this feature. First, for arg_type with MEM_UNINIT flag which
    initialize a dynptr, they must be rejected for such register type.
    Secondly, in the future, there are plans to add dynptr helpers that
    operate on the dynptr itself and may change its offset and other
    properties.
    
    In all of these cases, PTR_TO_DYNPTR shouldn't be allowed to be passed
    to such helpers, however the current code simply returns 0.
    
    The rejection for helpers that release the dynptr is already handled.
    
    For fixing this, we take a step back and rework existing code in a way
    that will allow fitting in all classes of helpers and have a coherent
    model for dealing with the variety of use cases in which dynptr is used.
    
    First, for ARG_PTR_TO_DYNPTR, it can either be set alone or together
    with a DYNPTR_TYPE_* constant that denotes the only type it accepts.
    
    Next, helpers which initialize a dynptr use MEM_UNINIT to indicate this
    fact. To make the distinction clear, use MEM_RDONLY flag to indicate
    that the helper only operates on the memory pointed to by the dynptr,
    not the dynptr itself. In C parlance, it would be equivalent to taking
    the dynptr as a point to const argument.
    
    When either of these flags are not present, the helper is allowed to
    mutate both the dynptr itself and also the memory it points to.
    Currently, the read only status of the memory is not tracked in the
    dynptr, but it would be trivial to add this support inside dynptr state
    of the register.
    
    With these changes and renaming PTR_TO_DYNPTR to CONST_PTR_TO_DYNPTR to
    better reflect its usage, it can no longer be passed to helpers that
    initialize a dynptr, i.e. bpf_dynptr_from_mem, bpf_ringbuf_reserve_dynptr.
    
    A note to reviewers is that in code that does mark_stack_slots_dynptr,
    and unmark_stack_slots_dynptr, we implicitly rely on the fact that
    PTR_TO_STACK reg is the only case that can reach that code path, as one
    cannot pass CONST_PTR_TO_DYNPTR to helpers that don't set MEM_RDONLY. In
    both cases such helpers won't be setting that flag.
    
    The next patch will add a couple of selftest cases to make sure this
    doesn't break.
    
    Fixes: 205715673844 ("bpf: Add bpf_user_ringbuf_drain() helper")
    Acked-by: Joanne Koong <joannelkoong@gmail.com>
    Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
    Link: https://lore.kernel.org/r/20221207204141.308952-4-memxor@gmail.com
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2023-04-28 11:43:17 +02:00
Artem Savkov 0664d5e5a7 selftests/bpf: Add selftests validating the user ringbuf
Bugzilla: https://bugzilla.redhat.com/2166911

commit e5a9df51c74671cfe15af1d50e5f508bd3efddab
Author: David Vernet <void@manifault.com>
Date:   Mon Sep 19 19:01:00 2022 -0500

    selftests/bpf: Add selftests validating the user ringbuf
    
    This change includes selftests that validate the expected behavior and
    APIs of the new BPF_MAP_TYPE_USER_RINGBUF map type.
    
    Signed-off-by: David Vernet <void@manifault.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20220920000100.477320-5-void@manifault.com

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2023-03-06 14:54:26 +01:00