Skip to content

KFunc bpf_rcu_read_lock



This kfunc is used to define a RCU read lock region in the BPF program. The end of such a region is marked by bpf_rcu_read_unlock

The current implementation does not support nested rcu read lock region in the prog.

void bpf_rcu_read_lock()


  struct task_struct {
    struct task_struct              *last_wakee;
    struct task_struct __rcu        *real_parent;

Let us say prog does task = bpf_get_current_task_btf() to get a task pointer. The basic rules are:

  • 'real_parent = task->real_parent should be inside bpf_rcu_read_lock region. This is to simulate rcu_dereference() operation. The real_parent is marked as MEM_RCU only if (1). task->real_parent is inside bpf_rcu_read_lock region, and (2). task is a trusted ptr. So MEM_RCU marked ptr can be 'trusted' inside the bpf_rcu_read_lock region.
  • last_wakee = real_parent->last_wakee should be inside bpf_rcu_read_lock region since it tries to access rcu protected memory.
  • the ptr 'last_wakee' will be marked as PTR_UNTRUSTED since in general it is not clear whether the object pointed by 'last_wakee' is valid or not even inside bpf_rcu_read_lock region.

Program types

The following program types can make use of this kfunc:


Docs could be improved

This part of the docs is incomplete, contributions are very welcome