Bounded loops in BPF programs
Bounded loops in BPF programs
Posted Dec 3, 2018 23:16 UTC (Mon) by rvolgers (guest, #63218)Parent article: Bounded loops in BPF programs
This is why WebAssembly is explicit about control flow nesting and doesn't allow arbitrary jumps. Wouldn't be surprised at all if eventually BPF gets replaced with some fancy formally-verified minimal WebAssembly JIT from Google or something.
      Posted Dec 3, 2018 23:52 UTC (Mon)
                               by roc (subscriber, #30627)
                              [Link] (6 responses)
       
     
    
      Posted Dec 4, 2018 0:48 UTC (Tue)
                               by rvolgers (guest, #63218)
                              [Link] (2 responses)
       
Either way there is still the problem of doing something with those loops to make sure they complete within a certain number of iterations though. 
     
    
      Posted Dec 5, 2018 8:18 UTC (Wed)
                               by edeloget (subscriber, #88392)
                              [Link] (1 responses)
       
That, in turn, means that if I handcraft the code I send to the kernel, it will then have no way to perform the needed verifications :) Does not sound that great :) 
     
    
      Posted Dec 9, 2018 1:05 UTC (Sun)
                               by nteon (subscriber, #53899)
                              [Link] 
       
     
      Posted Dec 5, 2018 23:30 UTC (Wed)
                               by wahern (subscriber, #37304)
                              [Link] (2 responses)
       The Relooper algorithm isn't much better, if at all. Per the original paper, Emscripten: an LLVM-to-JavaScript compiler:
 Of course "almost all" code is amenable because very little code comprises the more critical, performant inner loops and state machines--the parts which often heavily rely on goto.
 Arguably if JavaScript had goto there likely never would have been a need to create and rely on the Relooper, and WebAssembly may have turned out differently. Lua 5.2 added a goto construct precisely because it made code generation so much easier. I suspect that eventually much BPF code will be generated from high-level DSLs. Not everybody will be using the same toolchains and libraries, and not having a goto construct is a serious headache when machine generating code. Generating performant assembly from a task-specific, declarative DSL is often trivial; much less so if you now need to implement a relooper or integrate a relooper library.
 WebAssembly was originally envisioned as a simple, pure stack-based VM where variable scoping and structured blocks naturally aligned with the overall design. A goto construct was unfathomable. But then WebAssembly got much more complex and the simple stack-based design fell away. I suspect adding a goto construct could have been possible after the original, simpler concept gave way, and I wouldn't rule out its addition in the future. Gotos (including computed gotos) are still very useful in performant C code because optimizing compilers still can't do the job--in real-world code the best switch-statement optimizations still can't come close to idiomatic use of gotos and computed gotos. Like with JIT compiling, microbenchmarks and theoretical optimizations never quite make the transition to the real-world undiminished. Performance demands may still necessitate goto.
      
           
     
    
      Posted Dec 6, 2018 0:30 UTC (Thu)
                               by wahern (subscriber, #37304)
                              [Link] (1 responses)
       
What I had in mind here was the transition from the AST-based bytecode format to the structured stack machine format. The transition shifted WASM in the direction of a model where you could contemplate adding gotos. The transition happened because implementations were *already* using modern compiler techniques, like SSA transforms. Adding a goto construct with a sophisticated verifier is much less of a leap than when your machine model is based directly on ASTs. 
For more context see https://github.com/WebAssembly/design/issues/755 and https://docs.google.com/document/d/1CieRxPy3Fp62LQdtWfhym... 
 
 
     
    
      Posted May 12, 2019 11:16 UTC (Sun)
                               by ibukanov (subscriber, #3942)
                              [Link] 
       
     
      Posted Dec 4, 2018 12:20 UTC (Tue)
                               by nix (subscriber, #2304)
                              [Link] (3 responses)
       
(And why would Google have a WASM JITter suitable for running in *kernelspace* anyway?) 
 
     
    
      Posted Dec 4, 2018 12:31 UTC (Tue)
                               by roc (subscriber, #30627)
                              [Link] (2 responses)
       
1) We have a framework X. 
Duplicating effort along the path of least resistance, one feature at a time. 
     
    
      Posted Dec 4, 2018 14:30 UTC (Tue)
                               by Herve5 (subscriber, #115399)
                              [Link] 
       
     
      Posted Dec 4, 2018 20:02 UTC (Tue)
                               by simcop2387 (subscriber, #101710)
                              [Link] 
       
     
    Bounded loops in BPF programs
      
Bounded loops in BPF programs
      
Bounded loops in BPF programs
      
Bounded loops in BPF programs
      
Bounded loops in BPF programs
      
In general though, this is not always easy or even practical –
there may not be a straightforward high-level loop structure
corresponding to the low-level one, if for example the original
C code relied heavily on goto instructions. In practice,
however, almost all real-world C and C++ code tends to be
amenable to loop recreation.
Bounded loops in BPF programs
      
Bounded loops in BPF programs
      
Bounded loops in BPF programs
      
Bounded loops in BPF programs
      
2) X is missing a small feature. Framework Y has that feature, and is overall great, but it's more complex than we need right now, and besides the cost of migrating from X to Y for just this one feature can't be justified.
3) Add feature to X.
4) Goto 1.
"duplicating effort along the path of least resistance"
      
Bounded loops in BPF programs
      
           