Skip to content

bpf: Fix program size issue with host firewall in IPv4-only mode#14232

Merged
kkourt merged 1 commit intomasterfrom
pr/pchaigno/fix-ipv4-only-hostfw-regression
Dec 2, 2020
Merged

bpf: Fix program size issue with host firewall in IPv4-only mode#14232
kkourt merged 1 commit intomasterfrom
pr/pchaigno/fix-ipv4-only-hostfw-regression

Conversation

@pchaigno
Copy link
Copy Markdown
Member

@pchaigno pchaigno commented Dec 1, 2020

Running Cilium in IPv4-only mode with the host firewall and our kube-proxy replacement enabled causes program to-netdev from bpf_host to have an excessive size (>4096 instructions):

level=warning msg="Prog section 'to-netdev' rejected: Argument list too long (7)!" subsys=datapath-loader
level=warning msg=" - Type:         3" subsys=datapath-loader
level=warning msg=" - Attach Type:  0" subsys=datapath-loader
level=warning msg=" - Instructions: 4179 (83 over limit)" subsys=datapath-loader
level=warning msg=" - License:      GPL" subsys=datapath-loader

The section in question consists in particular of the host firewall enforcement and the NAT+service handling via nodeport_nat_fwd(). That last function is only split into several programs via tail calls when both IPv4 and IPv6 are enabled.

To reduce the program size, this pull request also splits nodeport_nat_fwd() into several BPF programs via tail calls when the host firewall is enabled. We also need to check for HOST_EP_ID to only split if we're calling nodeport_nat_fwd() from bpf_host.

Fixes: #14231

@pchaigno pchaigno 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. area/host-firewall Impacts the host firewall or the host endpoint. needs-backport/1.9 labels Dec 1, 2020
@pchaigno pchaigno requested review from a team and kkourt December 1, 2020 14:31
@pchaigno pchaigno marked this pull request as draft December 1, 2020 14:41
@pchaigno pchaigno force-pushed the pr/pchaigno/fix-ipv4-only-hostfw-regression branch from 291fece to 8795edc Compare December 1, 2020 14:56
@pchaigno pchaigno marked this pull request as ready for review December 1, 2020 15:15
Comment thread bpf/bpf_host.c Outdated
#include <node_config.h>
#include <ep_config.h>

#define IS_BPF_HOST 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: maybe just use #define IS_BPF_HOST here since the check is #if defined(IS_BPF_HOST)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That change seemed so obvious I didn't retest the patch after it. Bad idea.

Turns out the 1 is needed here because of how we define is_defined. I'll send a fix.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fix ready at #14255, with a test this time 🙂

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry about that!
It might make sense to replace #if defined(IS_BPF_HOST) with #if IS_BPF_HOST == 1 at some point.

Running Cilium in IPv4-only mode with the host firewall and our
kube-proxy replacement enabled causes program to-netdev from bpf_host to
have an excessive size (>4096 instructions):

    level=warning msg="Prog section 'to-netdev' rejected: Argument list too long (7)!" subsys=datapath-loader
    level=warning msg=" - Type:         3" subsys=datapath-loader
    level=warning msg=" - Attach Type:  0" subsys=datapath-loader
    level=warning msg=" - Instructions: 4179 (83 over limit)" subsys=datapath-loader
    level=warning msg=" - License:      GPL" subsys=datapath-loader

The section in question consists in particular of the host firewall
enforcement and the NAT+service handling via nodeport_nat_fwd(). That
last function is only split into several programs via tail calls when
both IPv4 and IPv6 are enabled.

To reduce the program size, this commit also splits nodeport_nat_fwd()
into several BPF programs via tail calls when the host firewall is
enabled. We also need to check for IS_BPF_HOST to only split if we're
calling nodeport_nat_fwd() from bpf_host.

Signed-off-by: Paul Chaignon <paul@cilium.io>
@pchaigno pchaigno force-pushed the pr/pchaigno/fix-ipv4-only-hostfw-regression branch from 8795edc to d19bcd0 Compare December 1, 2020 20:54
@maintainer-s-little-helper maintainer-s-little-helper Bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Dec 2, 2020
@kkourt kkourt merged commit bf635d8 into master Dec 2, 2020
@kkourt kkourt deleted the pr/pchaigno/fix-ipv4-only-hostfw-regression branch December 2, 2020 16:53
@aanm aanm mentioned this pull request Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/host-firewall Impacts the host firewall or the host endpoint. area/loader Impacts the loading of BPF programs into the kernel. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. 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.

Program size regression with host firewall in IPv4-only mode

2 participants