linux-kernelebpfbpf

Regarding the ebpf question, bpf_ringbuf_submit is not in effect


Why does the user-mode callback function fail to respond to a successful call to kernel mode bpf_ringbuf_submit(data, 0)? but the user-mode callback function responds successfully when the parameter is changed to bpf_ringbuf_submit(data, 2),thank you!


Solution

  • That second argument is a flag to determine if/when notifications for new data are sent. From the helpers man page:

    void bpf_ringbuf_submit(void *data, u64 flags)
    
        Description
            Submit reserved ring buffer sample, pointed to by
            data.  If BPF_RB_NO_WAKEUP is specified in flags,
            no notification of new data availability is sent.
            If BPF_RB_FORCE_WAKEUP is specified in flags,
            notification of new data availability is sent
            unconditionally.
    

    Value 2 is BPF_RB_FORCE_WAKEUP and forces the notification.


    Behavior of each flag

    We can find the logic for the different flag in bpf_ringbuf_commit():