Skip to content

bpf: use ebpf.VariableSpec API for rewriting global constants#35988

Merged
ti-mo merged 3 commits intocilium:mainfrom
ti-mo:tb/datapath-runtime-config
Dec 2, 2024
Merged

bpf: use ebpf.VariableSpec API for rewriting global constants#35988
ti-mo merged 3 commits intocilium:mainfrom
ti-mo:tb/datapath-runtime-config

Conversation

@ti-mo
Copy link
Copy Markdown
Contributor

@ti-mo ti-mo commented Nov 14, 2024

bpf: remove const inlining, use ebpf.VariableSpec API for rewriting globals

This commit removes compatibility with kernels 5.1 and older. From this point on,
Cilium relies on a read-only map to hold its datapath configuration data, and
config values will no longer be inlined into the bytecode.

This patch uses the new ebpf.VariableSpec abstraction for applying configuration
data to a CollectionSpec.

It also expands supported data types for runtime substitution to signed integers
and booleans, where before only unsigned integers were allowed.
bpf: inject THIS_INTERFACE_IFINDEX at runtime, replace NATIVE_DEV_IFINDEX

This is an example of converting a legacy preprocessor macro to a runtime configurable.

The default value of a configurable after declaring it with DECLARE_CONFIG() is zero,
so no need to assign dummy values.

Use ASSIGN_CONFIG to override the contents in tests after importing a declaration.

To avoid large refactors and churn, define e.g. THIS_INTERFACE_IFINDEX as a macro
around an accessor like CONFIG(interface_ifindex).

@ti-mo ti-mo added area/loader Impacts the loading of BPF programs into the kernel. release-note/misc This PR makes changes that have no direct user impact. labels Nov 14, 2024
@ti-mo ti-mo force-pushed the tb/datapath-runtime-config branch from 43cd12b to 8329972 Compare November 14, 2024 16:59
@ti-mo
Copy link
Copy Markdown
Contributor Author

ti-mo commented Nov 14, 2024

/test

@ti-mo ti-mo force-pushed the tb/datapath-runtime-config branch from 8329972 to a312d6f Compare November 18, 2024 21:34
@ti-mo
Copy link
Copy Markdown
Contributor Author

ti-mo commented Nov 18, 2024

/test

@ti-mo ti-mo force-pushed the tb/datapath-runtime-config branch from a312d6f to bc75729 Compare November 18, 2024 21:49
@ti-mo
Copy link
Copy Markdown
Contributor Author

ti-mo commented Nov 18, 2024

/test

@ti-mo ti-mo force-pushed the tb/datapath-runtime-config branch from bc75729 to 5bf52ac Compare November 19, 2024 13:12
@ti-mo
Copy link
Copy Markdown
Contributor Author

ti-mo commented Nov 19, 2024

/test

@ti-mo ti-mo marked this pull request as ready for review November 20, 2024 10:37
@ti-mo ti-mo requested review from a team as code owners November 20, 2024 10:37
@ti-mo ti-mo force-pushed the tb/datapath-runtime-config branch from 5bf52ac to acfbdff Compare November 28, 2024 16:20
@ti-mo
Copy link
Copy Markdown
Contributor Author

ti-mo commented Nov 28, 2024

/test

@ti-mo ti-mo force-pushed the tb/datapath-runtime-config branch 2 times, most recently from 00a6ad6 to d4587e3 Compare November 28, 2024 19:41
@ti-mo
Copy link
Copy Markdown
Contributor Author

ti-mo commented Nov 28, 2024

/test

@ti-mo ti-mo force-pushed the tb/datapath-runtime-config branch from d4587e3 to 451e557 Compare November 28, 2024 20:06
@ti-mo
Copy link
Copy Markdown
Contributor Author

ti-mo commented Nov 28, 2024

/test

Copy link
Copy Markdown
Member

@julianwiedmann julianwiedmann left a comment

Choose a reason for hiding this comment

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

Changes lgtm, one nit below. But CI is not very happy ...

You'd also need to rebase once more, I just added an additional NATIVE_DEV_IFINDEX usage in the datapath :disappear:.

@julianwiedmann julianwiedmann added the dont-merge/needs-rebase This PR needs to be rebased because it has merge conflicts. label Nov 29, 2024
Copy link
Copy Markdown
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.

Changes look good to me

@ti-mo ti-mo force-pushed the tb/datapath-runtime-config branch from 451e557 to e9a85d5 Compare December 2, 2024 12:56
@ti-mo
Copy link
Copy Markdown
Contributor Author

ti-mo commented Dec 2, 2024

Changes lgtm, one nit below. But CI is not very happy ...

Looks like I wrongly removed the ifindex override from hostRewrites. Doesn't pop up locally as it only gets exercised on specific kind setups iirc.

You'd also need to rebase once more, I just added an additional NATIVE_DEV_IFINDEX usage in the datapath :disappear:.

All good, thanks for the heads up. 👍

@ti-mo
Copy link
Copy Markdown
Contributor Author

ti-mo commented Dec 2, 2024

/test

@ti-mo ti-mo enabled auto-merge December 2, 2024 12:58
@ti-mo ti-mo removed the dont-merge/needs-rebase This PR needs to be rebased because it has merge conflicts. label Dec 2, 2024
Copy link
Copy Markdown
Member

@sayboras sayboras left a comment

Choose a reason for hiding this comment

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

Looks good for ebpf go.mod, understand that the v0.17.0 will be released soon.

@julianwiedmann
Copy link
Copy Markdown
Member

One more rebase to pick up #36235 should heal CI 🤞

Copy link
Copy Markdown
Member

@julianwiedmann julianwiedmann left a comment

Choose a reason for hiding this comment

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

thank you!

ti-mo added 3 commits December 2, 2024 15:53
…lobals

This commit removes compatibility with kernels 5.1 and older. From this point on,
Cilium relies on a read-only map to hold its datapath configuration data, and
config values will no longer be inlined into the bytecode.

This patch uses the new ebpf.VariableSpec abstraction for applying configuration
data to a CollectionSpec.

It also expands supported data types for runtime substitution to signed integers
and booleans, where before only unsigned integers were allowed.

Signed-off-by: Timo Beckers <[email protected]>
…NDEX

This is an example of converting a legacy preprocessor macro to a runtime configurable.

The default value of a configurable after declaring it with DECLARE_CONFIG() is zero,
so no need to assign dummy values.

Use ASSIGN_CONFIG to override the contents in tests after importing a declaration.

To avoid large refactors and churn, define e.g. THIS_INTERFACE_IFINDEX as a macro
around an accessor like CONFIG(interface_ifindex).

The section in TestWriteStaticData was removed because it only really checked whether
the logic in loader.ELFVariableSubstitutions roughly matches the one in cfg.writeStaticData,
which is of dubious benefit. A follow-up patch will remove ELFVariableSubstitutions,
so let's put it out of its misery instead of rejigging it even more.

Signed-off-by: Timo Beckers <[email protected]>
@ti-mo ti-mo force-pushed the tb/datapath-runtime-config branch from e9a85d5 to 39bc851 Compare December 2, 2024 14:54
@ti-mo
Copy link
Copy Markdown
Contributor Author

ti-mo commented Dec 2, 2024

/test

@ti-mo ti-mo added this pull request to the merge queue Dec 2, 2024
Merged via the queue into cilium:main with commit df5501e Dec 2, 2024
@ti-mo ti-mo deleted the tb/datapath-runtime-config branch December 2, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/loader Impacts the loading of BPF programs into the kernel. release-note/misc This PR makes changes that have no direct user impact.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants