• Delyan Kratunov's avatar
    bpf: implement sleepable uprobes by chaining gps · 8c7dcb84
    Delyan Kratunov authored
    uprobes work by raising a trap, setting a task flag from within the
    interrupt handler, and processing the actual work for the uprobe on the
    way back to userspace. As a result, uprobe handlers already execute in a
    might_fault/_sleep context. The primary obstacle to sleepable bpf uprobe
    programs is therefore on the bpf side.
    
    Namely, the bpf_prog_array attached to the uprobe is protected by normal
    rcu. In order for uprobe bpf programs to become sleepable, it has to be
    protected by the tasks_trace rcu flavor instead (and kfree() called after
    a corresponding grace period).
    
    Therefore, the free path for bpf_prog_array now chains a tasks_trace and
    normal grace periods one after the other.
    
    Users who iterate under tasks_trace read section would
    be safe, as would users who iterate under normal read sections (from
    non-sleepable locations).
    
    The downside is that the tasks_trace latency affects all perf_event-attached
    bpf programs (and not just uprobe ones). This is deemed safe given the
    possible attach rates for kprobe/uprobe/tp programs.
    
    Separately, non-sleepable programs need access to dynamically sized
    rcu-protected maps, so bpf_run_prog_array_sleepables now conditionally takes
    an rcu read section, in addition to the overarching tasks_trace section.
    Signed-off-by: default avatarDelyan Kratunov <delyank@fb.com>
    Link: https://lore.kernel.org/r/ce844d62a2fd0443b08c5ab02e95bc7149f9aeb1.1655248076.git.delyank@fb.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    8c7dcb84
core.c 71.3 KB