bpf timer design

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, all

I have been thinking about eBPF timer APIs, it looks harder than I thought.

The API's themselves are not hard, here is what I have:

int bpf_timer_setup(struct bpf_timer *timer, void *callback_fn,
                    void *callback_ctx, u64 flags);
int bpf_timer_mod(struct bpf_timer *timer, u64 expires);
int bpf_timer_del(struct bpf_timer *timer);

which is pretty much similar to the current kernel timer API's.

The struct bpf_timer is a bit tricky, we still have to save the kernel timer
there but we do not want eBPF programs to touch it. So I simply save a pointer
to kernel timer inside:

struct bpf_timer {
       void *ptr;
};

but we obviously have to prevent eBPF programs from dereferencing it
with the verifier.

The hardest part is on the verifier side, we have to check:

1. Whether a timer is initialized before use. For example:

struct bpf_timer t;
bpf_timer_mod(&t, bpf_jiffies64() + HZ);

2. Whether a timer is still active before exiting. For example:

struct bpf_timer t;
bpf_setup_timer(&t, ....);
bpf_timer_mod(&t, bpf_jiffies64() + HZ);
//end of the eBPF program

I do not see any existing mechanism for checks like these, so potentially need
a lot of work.

And, unlike bpf_for_each_map_elem(), the timer callback is asynchronous, this
makes it harder to check its callback context etc..

Any thoughts and suggestions?

Thanks!



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux