]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
bpf: Replace __opt annotation with __nullable for kfuncs
authorPuranjay Mohan <puranjay@kernel.org>
Fri, 2 Jan 2026 22:15:12 +0000 (14:15 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 2 Jan 2026 23:51:34 +0000 (15:51 -0800)
commita069190b590e108223cd841a1c2d0bfb92230ecc
tree93bf902f316f8165587c24d6dcec6fc3c7f1c32a
parent7694ff8f6ca7f7cdf2e5636ecbe6dacaeb71678d
bpf: Replace __opt annotation with __nullable for kfuncs

The __opt annotation was originally introduced specifically for
buffer/size argument pairs in bpf_dynptr_slice() and
bpf_dynptr_slice_rdwr(), allowing the buffer pointer to be NULL while
still validating the size as a constant.  The __nullable annotation
serves the same purpose but is more general and is already used
throughout the BPF subsystem for raw tracepoints, struct_ops, and other
kfuncs.

This patch unifies the two annotations by replacing __opt with
__nullable.  The key change is in the verifier's
get_kfunc_ptr_arg_type() function, where mem/size pair detection is now
performed before the nullable check.  This ensures that buffer/size
pairs are correctly classified as KF_ARG_PTR_TO_MEM_SIZE even when the
buffer is nullable, while adding an !arg_mem_size condition to the
nullable check prevents interference with mem/size pair handling.

When processing KF_ARG_PTR_TO_MEM_SIZE arguments, the verifier now uses
is_kfunc_arg_nullable() instead of the removed is_kfunc_arg_optional()
to determine whether to skip size validation for NULL buffers.

This is the first documentation added for the __nullable annotation,
which has been in use since it was introduced but was previously
undocumented.

No functional changes to verifier behavior - nullable buffer/size pairs
continue to work exactly as before.

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Link: https://lore.kernel.org/r/20260102221513.1961781-1-puranjay@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Documentation/bpf/kfuncs.rst
include/linux/bpf.h
kernel/bpf/helpers.c
kernel/bpf/verifier.c