Question about backward jump in bpf


Zhiting Zhu
 

Hi,

What's the use case for backward jump of ebpf? The verifier will reject the backward edge which makes the backward jump not useful. Am I missing something?

Also, from what I read online, some slides said ebpf allows backward jump and some said doesn't. From the bytecode, it seems it allows it. I want some classification here. Thanks!

Best,
Zhiting


Alexei Starovoitov
 

On Tue, Oct 3, 2017 at 9:26 PM, zhiting zhu via iovisor-dev
<iovisor-dev@...> wrote:
Hi,

What's the use case for backward jump of ebpf? The verifier will reject the
backward edge which makes the backward jump not useful. Am I missing
something?

Also, from what I read online, some slides said ebpf allows backward jump
and some said doesn't. From the bytecode, it seems it allows it. I want some
classification here. Thanks!
There is no such thing as 'backward edge'.
In graph theory there is 'back edge' which is the same as saying
there is a loop in control flow graph.
The kernel verifier has logic to detect back edges and reject such programs.
Backwards jumps are allowed, since backward jump != loop.


Zhiting Zhu
 

Thanks for the classification.

On Tue, Oct 3, 2017 at 11:30 PM, Alexei Starovoitov <alexei.starovoitov@...> wrote:
On Tue, Oct 3, 2017 at 9:26 PM, zhiting zhu via iovisor-dev
<iovisor-dev@...> wrote:
> Hi,
>
> What's the use case for backward jump of ebpf? The verifier will reject the
> backward edge which makes the backward jump not useful. Am I missing
> something?
>
> Also, from what I read online, some slides said ebpf allows backward jump
> and some said doesn't. From the bytecode, it seems it allows it. I want some
> classification here. Thanks!

There is no such thing as 'backward edge'.
In graph theory there is 'back edge' which is the same as saying
there is a loop in control flow graph.
The kernel verifier has logic to detect back edges and reject such programs.
Backwards jumps are allowed, since backward jump != loop.