Skip to content

Commit fbc5669

Browse files
aspskborkmann
authored andcommitted
bpf, docs: Document existing macros instead of deprecated
The BTF_TYPE_SAFE_NESTED macro was replaced by the BTF_TYPE_SAFE_TRUSTED, BTF_TYPE_SAFE_RCU, and BTF_TYPE_SAFE_RCU_OR_NULL macros. Fix the docs correspondingly. Fixes: 6fcd486 ("bpf: Refactor RCU enforcement in the verifier.") Signed-off-by: Anton Protopopov <aspsk@isovalent.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/20230622095424.1024244-1-aspsk@isovalent.com
1 parent 2404dd0 commit fbc5669

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

Documentation/bpf/kfuncs.rst

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,23 +227,49 @@ absolutely no ABI stability guarantees.
227227

228228
As mentioned above, a nested pointer obtained from walking a trusted pointer is
229229
no longer trusted, with one exception. If a struct type has a field that is
230-
guaranteed to be valid as long as its parent pointer is trusted, the
231-
``BTF_TYPE_SAFE_NESTED`` macro can be used to express that to the verifier as
232-
follows:
230+
guaranteed to be valid (trusted or rcu, as in KF_RCU description below) as long
231+
as its parent pointer is valid, the following macros can be used to express
232+
that to the verifier:
233+
234+
* ``BTF_TYPE_SAFE_TRUSTED``
235+
* ``BTF_TYPE_SAFE_RCU``
236+
* ``BTF_TYPE_SAFE_RCU_OR_NULL``
237+
238+
For example,
239+
240+
.. code-block:: c
241+
242+
BTF_TYPE_SAFE_TRUSTED(struct socket) {
243+
struct sock *sk;
244+
};
245+
246+
or
233247

234248
.. code-block:: c
235249
236-
BTF_TYPE_SAFE_NESTED(struct task_struct) {
250+
BTF_TYPE_SAFE_RCU(struct task_struct) {
237251
const cpumask_t *cpus_ptr;
252+
struct css_set __rcu *cgroups;
253+
struct task_struct __rcu *real_parent;
254+
struct task_struct *group_leader;
238255
};
239256
240257
In other words, you must:
241258

242-
1. Wrap the trusted pointer type in the ``BTF_TYPE_SAFE_NESTED`` macro.
259+
1. Wrap the valid pointer type in a ``BTF_TYPE_SAFE_*`` macro.
243260

244-
2. Specify the type and name of the trusted nested field. This field must match
261+
2. Specify the type and name of the valid nested field. This field must match
245262
the field in the original type definition exactly.
246263

264+
A new type declared by a ``BTF_TYPE_SAFE_*`` macro also needs to be emitted so
265+
that it appears in BTF. For example, ``BTF_TYPE_SAFE_TRUSTED(struct socket)``
266+
is emitted in the ``type_is_trusted()`` function as follows:
267+
268+
.. code-block:: c
269+
270+
BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct socket));
271+
272+
247273
2.4.5 KF_SLEEPABLE flag
248274
-----------------------
249275

0 commit comments

Comments
 (0)