• Kumar Kartikeya Dwivedi's avatar
    selftests/bpf: Add BPF assertion macros · d6ea0680
    Kumar Kartikeya Dwivedi authored
    Add macros implementing an 'assert' statement primitive using macros,
    built on top of the BPF exceptions support introduced in previous
    patches.
    
    The bpf_assert_*_with variants allow supplying a value which can the be
    inspected within the exception handler to signify the assert statement
    that led to the program being terminated abruptly, or be returned by the
    default exception handler.
    
    Note that only 64-bit scalar values are supported with these assertion
    macros, as during testing I found other cases quite unreliable in
    presence of compiler shifts/manipulations extracting the value of the
    right width from registers scrubbing the verifier's bounds information
    and knowledge about the value in the register.
    
    Thus, it is easier to reliably support this feature with only the full
    register width, and support both signed and unsigned variants.
    
    The bpf_assert_range is interesting in particular, which clamps the
    value in the [begin, end] (both inclusive) range within verifier state,
    and emits a check for the same at runtime.
    Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
    Link: https://lore.kernel.org/r/20230912233214.1518551-17-memxor@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    d6ea0680
bpf_experimental.h 14.9 KB