go-interpreter / wagon

wagon, a WebAssembly-based Go interpreter, for Go.
BSD 3-Clause "New" or "Revised" License
903 stars 148 forks source link

Implement global load/set, memory 64bit/32bit load #129

Closed twitchyliquid64 closed 5 years ago

twitchyliquid64 commented 5 years ago

This PR starts implementing more tablestakes.

All the complexity here is in mitigating Spectre. We use the same technique as v8, which is this:

This works because CPUs do not speculate through bitmask operations, and because if the bounds check was mis-speculated, the poison register would be set to zero. As a result, attacker-controlled instructions later on would always get a zero value for their speculation attack, so they cannot build any measurement primitives to determine the value from the speculated out-of-bounds access.

codecov-io commented 5 years ago

Codecov Report

Merging #129 into master will increase coverage by 1.05%. The diff coverage is 82.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #129      +/-   ##
==========================================
+ Coverage    66.5%   67.55%   +1.05%     
==========================================
  Files          41       41              
  Lines        4490     4787     +297     
==========================================
+ Hits         2986     3234     +248     
- Misses       1233     1281      +48     
- Partials      271      272       +1
Impacted Files Coverage Δ
exec/internal/compile/native.go 54.54% <ø> (ø) :arrow_up:
exec/internal/compile/scanner.go 0% <0%> (ø) :arrow_up:
exec/internal/compile/native_exec.go 100% <100%> (ø) :arrow_up:
exec/native_compile.go 58.92% <100%> (+3.57%) :arrow_up:
exec/internal/compile/backend_amd64.go 79.42% <85.46%> (+2.39%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 83c8885...41e25dd. Read the comment docs.

twitchyliquid64 commented 5 years ago

With these changes (and the last few PRs), the integer benchmark is now 50% faster than when it was introduced.

[xxx@xxx]:~/projects/wagon> go test -bench=BenchmarkU github.com/go-interpreter/wagon/exec
goos: linux
goarch: amd64
pkg: github.com/go-interpreter/wagon/exec
BenchmarkU64Arithmetic10Interpreted-8         100000         17064 ns/op
BenchmarkU64Arithmetic10Native-8              300000          3787 ns/op
BenchmarkU64Arithmetic50Interpreted-8          20000         76593 ns/op
BenchmarkU64Arithmetic50Native-8              100000         16423 ns/op
PASS
ok      github.com/go-interpreter/wagon/exec    9.162s