Netdev List
 help / color / mirror / Atom feed
* [PATCH bpf] libbpf: fix XDP program load regression for old kernels
@ 2020-09-24 17:17 Andrii Nakryiko
  2020-09-24 17:34 ` Alexei Starovoitov
  0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2020-09-24 17:17 UTC (permalink / raw)
  To: bpf, netdev, ast, daniel
  Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko, Nikita Shirokov,
	Udip Pant

Fix regression in libbpf, introduced by XDP link change, which causes XDP
programs to fail to be loaded into kernel due to specified BPF_XDP
expected_attach_type. While kernel doesn't enforce expected_attach_type for
BPF_PROG_TYPE_XDP, some old kernels already support XDP program, but they
don't yet recognize expected_attach_type field in bpf_attr, so setting it to
non-zero value causes program load to fail.

Luckily, libbpf already has a mechanism to deal with such cases, so just make
expected_attach_type optional for XDP programs.

Reported-by: Nikita Shirokov <tehnerd@tehnerd.com>
Reported-by: Udip Pant <udippant@fb.com>
Fixes: dc8698cac7aa ("libbpf: Add support for BPF XDP link")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 7253b833576c..e493d6048143 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -6925,7 +6925,7 @@ static const struct bpf_sec_def section_defs[] = {
 						BPF_XDP_DEVMAP),
 	BPF_EAPROG_SEC("xdp_cpumap/",		BPF_PROG_TYPE_XDP,
 						BPF_XDP_CPUMAP),
-	BPF_EAPROG_SEC("xdp",			BPF_PROG_TYPE_XDP,
+	BPF_APROG_SEC("xdp",			BPF_PROG_TYPE_XDP,
 						BPF_XDP),
 	BPF_PROG_SEC("perf_event",		BPF_PROG_TYPE_PERF_EVENT),
 	BPF_PROG_SEC("lwt_in",			BPF_PROG_TYPE_LWT_IN),
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] libbpf: fix XDP program load regression for old kernels
  2020-09-24 17:17 [PATCH bpf] libbpf: fix XDP program load regression for old kernels Andrii Nakryiko
@ 2020-09-24 17:34 ` Alexei Starovoitov
  2020-09-24 17:42   ` Andrii Nakryiko
  0 siblings, 1 reply; 3+ messages in thread
From: Alexei Starovoitov @ 2020-09-24 17:34 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: bpf, Network Development, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Kernel Team, Nikita Shirokov, Udip Pant

On Thu, Sep 24, 2020 at 10:18 AM Andrii Nakryiko <andriin@fb.com> wrote:
>
> Fix regression in libbpf, introduced by XDP link change, which causes XDP
> programs to fail to be loaded into kernel due to specified BPF_XDP
> expected_attach_type. While kernel doesn't enforce expected_attach_type for
> BPF_PROG_TYPE_XDP, some old kernels already support XDP program, but they
> don't yet recognize expected_attach_type field in bpf_attr, so setting it to
> non-zero value causes program load to fail.
>
> Luckily, libbpf already has a mechanism to deal with such cases, so just make
> expected_attach_type optional for XDP programs.
>
> Reported-by: Nikita Shirokov <tehnerd@tehnerd.com>
> Reported-by: Udip Pant <udippant@fb.com>
> Fixes: dc8698cac7aa ("libbpf: Add support for BPF XDP link")
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Applied. Thanks

Looks like libbpf CI needs to add a few old kernels.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] libbpf: fix XDP program load regression for old kernels
  2020-09-24 17:34 ` Alexei Starovoitov
@ 2020-09-24 17:42   ` Andrii Nakryiko
  0 siblings, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2020-09-24 17:42 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Andrii Nakryiko, bpf, Network Development, Alexei Starovoitov,
	Daniel Borkmann, Kernel Team, Nikita Shirokov, Udip Pant

On Thu, Sep 24, 2020 at 10:34 AM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Thu, Sep 24, 2020 at 10:18 AM Andrii Nakryiko <andriin@fb.com> wrote:
> >
> > Fix regression in libbpf, introduced by XDP link change, which causes XDP
> > programs to fail to be loaded into kernel due to specified BPF_XDP
> > expected_attach_type. While kernel doesn't enforce expected_attach_type for
> > BPF_PROG_TYPE_XDP, some old kernels already support XDP program, but they
> > don't yet recognize expected_attach_type field in bpf_attr, so setting it to
> > non-zero value causes program load to fail.
> >
> > Luckily, libbpf already has a mechanism to deal with such cases, so just make
> > expected_attach_type optional for XDP programs.
> >
> > Reported-by: Nikita Shirokov <tehnerd@tehnerd.com>
> > Reported-by: Udip Pant <udippant@fb.com>
> > Fixes: dc8698cac7aa ("libbpf: Add support for BPF XDP link")
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
>
> Applied. Thanks

Thanks!

>
> Looks like libbpf CI needs to add a few old kernels.

Yeah. We have 4.9 which is very old and only a few selftests can even
succeed there. Then we jump to 5.5, which is too recent to detect this
issue. This issue happened on 4.15, would that be a good version to
stick to? Any opinions?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-24 17:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-24 17:17 [PATCH bpf] libbpf: fix XDP program load regression for old kernels Andrii Nakryiko
2020-09-24 17:34 ` Alexei Starovoitov
2020-09-24 17:42   ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox