Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpf: manually handle the perf read state memory allocation #1304

Merged
merged 1 commit into from Aug 13, 2017
Merged

bpf: manually handle the perf read state memory allocation #1304

merged 1 commit into from Aug 13, 2017

Conversation

aalemayhu
Copy link
Contributor

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 second 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
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 solutions 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.

Closes: #409 (Crash in cilium monitor (ring buffer overflow?))
Signed-off-by: Alexander Alemayhu alexander@alemayhu.com

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>
@aalemayhu
Copy link
Contributor Author

Previous failure is unrelated, re triggered build

[K8s multi node Tests] ------------------------------------------------------------------------
[K8s multi node Tests]                           K8s Test Failed
[K8s multi node Tests] Error: could not connect from reviews-v1 to ratings:9080/health service
[K8s multi node Tests] 
[K8s multi node Tests] ------------------------------------------------------------------------
[K8s multi node Tests] + set +x
[K8s multi node Tests] ------------------------------------------------------------------------

@aalemayhu aalemayhu merged commit 9bd5652 into cilium:master Aug 13, 2017
@aalemayhu aalemayhu deleted the monitor-crash-409 branch August 13, 2017 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants