Skip to content

KFunc bpf_task_work_schedule_resume

v7.0

Schedule BPF callback using task_work_add with TWA_RESUME mode.

Note

This kfunc supersedes bpf_task_work_schedule_resume_impl, migrated to use implicit arguments in v7.0.

Definition

Parameters

task: Task struct for which callback should be scheduled

tw: Pointer to struct bpf_task_work in BPF map value for internal bookkeeping

map__map: map that embeds struct bpf_task_work in the values

callback: pointer to BPF subprogram to call

Signature

int bpf_task_work_schedule_resume(struct task_struct *task, struct bpf_task_work *tw, void *map__map, bpf_task_work_callback_t callback)

typedef int (*bpf_task_work_callback_t)(struct bpf_map *map, void *key, void *value);

Usage

This kfunc allows a BPF program that is being executed in a restricted context such as a Non Mask-able Interrupt (NMI) to schedule a callback on a task. This callback will be executed in a more permissible context (sleepable context) before that task resumes.

This is mostly useful for tools such as profilers. When a program is triggered in an NMI, the program and any helper/kfunc it executes is unable to sleep/wait or page fault. This means that some actions like reading userspace memory or even updating map values may fail. So by scheduling a callback you can do more things in the permissive context, while still passing info from the original execution context via a map value.

Program types

The following program types can make use of this kfunc:

Example

Docs could be improved

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