tools/testing/selftests/bpf/progs/bpf_misc.h

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/bpf_misc.h

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/bpf_misc.h
Extension
.h
Size
12028 bytes
Lines
281
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#ifndef __BPF_MISC_H__
#define __BPF_MISC_H__

#define XSTR(s) STR(s)
#define STR(s) #s

/* Expand a macro and then stringize the expansion */
#define QUOTE(str) #str
#define EXPAND_QUOTE(str) QUOTE(str)

/* This set of attributes controls behavior of the
 * test_loader.c:test_loader__run_subtests().
 *
 * The test_loader sequentially loads each program in a skeleton.
 * Programs could be loaded in privileged and unprivileged modes.
 * - __success, __failure, __msg, __regex imply privileged mode;
 * - __success_unpriv, __failure_unpriv, __msg_unpriv, __regex_unpriv
 *   imply unprivileged mode.
 * If combination of privileged and unprivileged attributes is present
 * both modes are used. If none are present privileged mode is implied.
 *
 * See test_loader.c:drop_capabilities() for exact set of capabilities
 * that differ between privileged and unprivileged modes.
 *
 * For test filtering purposes the name of the program loaded in
 * unprivileged mode is derived from the usual program name by adding
 * `@unpriv' suffix.
 *
 * __msg             Message expected to be found in the verifier log.
 *                   Multiple __msg attributes could be specified.
 *                   To match a regular expression use "{{" "}}" brackets,
 *                   e.g. "foo{{[0-9]+}}"  matches strings like "foo007".
 *                   Extended POSIX regular expression syntax is allowed
 *                   inside the brackets.
 * __not_msg         Message not expected to be found in verifier log.
 *                   If __msg_not is situated between __msg tags
 *                   framework matches __msg tags first, and then
 *                   checks that __msg_not is not present in a portion of
 *                   a log between bracketing __msg tags.
 *                   Same regex syntax as for __msg is supported.
 * __msg_unpriv      Same as __msg but for unprivileged mode.
 * __not_msg_unpriv  Same as __not_msg but for unprivileged mode.
 *
 * __stderr          Message expected to be found in bpf stderr stream. The
 *                   same regex rules apply like __msg.
 * __stderr_unpriv   Same as __stderr but for unpriveleged mode.
 * __stdout          Same as __stderr but for stdout stream.
 * __stdout_unpriv   Same as __stdout but for unpriveleged mode.
 *
 * __xlated          Expect a line in a disassembly log after verifier applies rewrites.
 *                   Multiple __xlated attributes could be specified.
 *                   Regular expressions could be specified same way as in __msg.
 * __xlated_unpriv   Same as __xlated but for unprivileged mode.
 *
 * __jited           Match a line in a disassembly of the jited BPF program.
 *                   Has to be used after __arch_* macro.
 *                   For example:
 *
 *                       __arch_x86_64
 *                       __jited("   endbr64")
 *                       __jited("   nopl    (%rax,%rax)")
 *                       __jited("   xorq    %rax, %rax")
 *                       ...
 *                       __naked void some_test(void)
 *                       {
 *                           asm volatile (... ::: __clobber_all);
 *                       }
 *
 *                   Regular expressions could be included in patterns same way
 *                   as in __msg.
 *
 *                   By default assume that each pattern has to be matched on the
 *                   next consecutive line of disassembly, e.g.:
 *
 *                       __jited("   endbr64")             # matched on line N
 *                       __jited("   nopl    (%rax,%rax)") # matched on line N+1
 *
 *                   If match occurs on a wrong line an error is reported.
 *                   To override this behaviour use literal "...", e.g.:
 *
 *                       __jited("   endbr64")             # matched on line N
 *                       __jited("...")                    # not matched
 *                       __jited("   nopl    (%rax,%rax)") # matched on any line >= N
 *
 * __jited_unpriv    Same as __jited but for unprivileged mode.
 *
 *
 * __success         Expect program load success in privileged mode.
 * __success_unpriv  Expect program load success in unprivileged mode.
 *

Annotation

Implementation Notes