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

program, btf: probe correct log buffer size #1500

Merged
merged 2 commits into from
Jul 3, 2024
Merged

Conversation

lmb
Copy link
Collaborator

@lmb lmb commented Jul 2, 2024

ci: fix golangci-lint

For some reason the Action decided to break now, after being updated a
couple of weeks ago.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>

program, btf: probe correct log buffer size

The kernel exposes a log of operations to aid debugging a program or BTF
load. Until recently there was no way to know the size of that buffer, so
the library forces the user to specify a buffer size. From a cursory survey
on sourcegraph.com it seems that users either hardcode a large fixed buffer
or probe the correct size by doubling the buffer size when hitting ENOSPC.

Since commit 47a71c1f9af0 ("bpf: Add log_true_size output field to return
necessary log buffer size") the kernel does provide a hint to user space.

Move probing of the correct log buffer size into the library. On recent (>=
6.4) kernels this is guaranteed to work in a single call. On older kernels
we use the doubling strategy employed by cilium and tetragon.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>

@github-actions github-actions bot added the breaking-change Changes exported API label Jul 2, 2024
For some reason the Action decided to break now, after being updated
a couple of weeks ago.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
@lmb lmb force-pushed the prog-log-sizing branch 3 times, most recently from 0efaff5 to 7cfb785 Compare July 3, 2024 08:03
@lmb lmb marked this pull request as ready for review July 3, 2024 08:04
@lmb lmb requested review from dylandreimerink and a team as code owners July 3, 2024 08:04
prog_test.go Outdated Show resolved Hide resolved
Copy link
Member

@dylandreimerink dylandreimerink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than the bit Florian already pointed out

The kernel exposes a log of operations to aid debugging a program
or BTF load. Until recently there was no way to know the size of
that buffer, so the library forces the user to specify a buffer
size. From a cursory survey on sourcegraph.com it seems that
users either hardcode a large fixed buffer or probe the correct
size by doubling the buffer size when hitting ENOSPC.

Since commit 47a71c1f9af0 ("bpf: Add log_true_size output field
to return necessary log buffer size") the kernel does provide a
hint to user space.

Move probing of the correct log buffer size into the library. On
recent (>= 6.4) kernels this is guaranteed to work in a single
call. On older kernels we use the doubling strategy employed by
cilium and tetragon.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
@lmb lmb merged commit f2b2f6d into cilium:main Jul 3, 2024
17 checks passed
@lmb lmb deleted the prog-log-sizing branch July 3, 2024 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Changes exported API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants