Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpf: manually handle the perf read state memory allocation
When the Cilium monitor is under heavy load we see the following crash panic: runtime error: cgo argument has Go pointer to Go pointer The crash is occurring near the call to `C.perf_event_read(...)`. At some point in time the state struct instance contains a Go pointer to Go pointer. According to the [Rules for passing pointers between Go and C][0] this is not allowed. >Go code may pass a Go pointer to C provided that the Go memory to which it points does not contain any Go pointers. I have not studied the Go source well enough to back up any suspicions that something is wrong in the runtime code, but looking at workarounds we could bypass the crasher by disabling the cgo runtime checks, but that doesn't really make sense considering that it requires a user to make a change. The other approach, which this patch does is instead of relying on `struct_read_state` to do the right thing, we fallback to malloc / free so we can reduce the chance of mismatch between Go and C memory. After this patch I am not able to reproduce the crasher. [0]: https://github.com/golang/proposal/blob/master/design/12416-cgo-pointers.md Closes: #409 (Crash in cilium monitor (ring buffer overflow?)) Signed-off-by: Alexander Alemayhu <alexander@alemayhu.com>
- Loading branch information