[PATCH mptcp-next] Squash to "bpf: add bpf_skc_to_mptcp_sock_proto"

Geliang Tang posted 1 patch 3 years, 4 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/multipath-tcp/mptcp_net-next tags/patchew/a412b57378176f189e112a36443ac133fa90566c.1650947043.git.geliang.tang@suse.com
Maintainers: Matthieu Baerts <matthieu.baerts@tessares.net>, Yonghong Song <yhs@fb.com>, Daniel Borkmann <daniel@iogearbox.net>, Alexei Starovoitov <ast@kernel.org>, "David S. Miller" <davem@davemloft.net>, John Fastabend <john.fastabend@gmail.com>, Ingo Molnar <mingo@redhat.com>, Song Liu <songliubraving@fb.com>, Paolo Abeni <pabeni@redhat.com>, Andrii Nakryiko <andrii@kernel.org>, Mat Martineau <mathew.j.martineau@linux.intel.com>, Steven Rostedt <rostedt@goodmis.org>, KP Singh <kpsingh@kernel.org>, Martin KaFai Lau <kafai@fb.com>, Jakub Kicinski <kuba@kernel.org>
There is a newer version of this series
include/linux/bpf.h      | 1 +
include/net/mptcp.h      | 2 +-
kernel/bpf/verifier.c    | 1 +
kernel/trace/bpf_trace.c | 2 ++
net/core/filter.c        | 3 ++-
net/mptcp/Makefile       | 2 --
6 files changed, 7 insertions(+), 4 deletions(-)
[PATCH mptcp-next] Squash to "bpf: add bpf_skc_to_mptcp_sock_proto"
Posted by Geliang Tang 3 years, 4 months ago
Update as Daniel suggested.

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 include/linux/bpf.h      | 1 +
 include/net/mptcp.h      | 2 +-
 kernel/bpf/verifier.c    | 1 +
 kernel/trace/bpf_trace.c | 2 ++
 net/core/filter.c        | 3 ++-
 net/mptcp/Makefile       | 2 --
 6 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index bdb5298735ce..2493f9601842 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2249,6 +2249,7 @@ extern const struct bpf_func_proto bpf_skc_to_tcp_timewait_sock_proto;
 extern const struct bpf_func_proto bpf_skc_to_tcp_request_sock_proto;
 extern const struct bpf_func_proto bpf_skc_to_udp6_sock_proto;
 extern const struct bpf_func_proto bpf_skc_to_unix_sock_proto;
+extern const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto;
 extern const struct bpf_func_proto bpf_copy_from_user_proto;
 extern const struct bpf_func_proto bpf_snprintf_btf_proto;
 extern const struct bpf_func_proto bpf_snprintf_proto;
diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index 6b07011c060d..4d761ad530c9 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -284,7 +284,7 @@ static inline int mptcpv6_init(void) { return 0; }
 static inline void mptcpv6_handle_mapped(struct sock *sk, bool mapped) { }
 #endif
 
-#if defined(CONFIG_MPTCP) && defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF_SYSCALL)
+#if defined(CONFIG_MPTCP) && defined(CONFIG_BPF_SYSCALL)
 struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk);
 #else
 static inline struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk) { return NULL; }
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 9c1a02b82ecd..40602ec20c6a 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -517,6 +517,7 @@ static bool is_ptr_cast_function(enum bpf_func_id func_id)
 		func_id == BPF_FUNC_skc_to_tcp_sock ||
 		func_id == BPF_FUNC_skc_to_tcp6_sock ||
 		func_id == BPF_FUNC_skc_to_udp6_sock ||
+		func_id == BPF_FUNC_skc_to_mptcp_sock ||
 		func_id == BPF_FUNC_skc_to_tcp_timewait_sock ||
 		func_id == BPF_FUNC_skc_to_tcp_request_sock;
 }
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index b26f3da943de..c7bf10cf2fa5 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -1685,6 +1685,8 @@ tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 		return &bpf_skc_to_udp6_sock_proto;
 	case BPF_FUNC_skc_to_unix_sock:
 		return &bpf_skc_to_unix_sock_proto;
+	case BPF_FUNC_skc_to_mptcp_sock:
+		return &bpf_skc_to_mptcp_sock_proto;
 	case BPF_FUNC_sk_storage_get:
 		return &bpf_sk_storage_get_tracing_proto;
 	case BPF_FUNC_sk_storage_delete:
diff --git a/net/core/filter.c b/net/core/filter.c
index 4bcf13b1d0e2..a0dd6f6b17f8 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -11282,10 +11282,11 @@ const struct bpf_func_proto bpf_skc_to_unix_sock_proto = {
 
 BPF_CALL_1(bpf_skc_to_mptcp_sock, struct sock *, sk)
 {
+	BTF_TYPE_EMIT(struct mptcp_sock);
 	return (unsigned long)bpf_mptcp_sock_from_subflow(sk);
 }
 
-static const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto = {
+const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto = {
 	.func		= bpf_skc_to_mptcp_sock,
 	.gpl_only	= false,
 	.ret_type	= RET_PTR_TO_BTF_ID_OR_NULL,
diff --git a/net/mptcp/Makefile b/net/mptcp/Makefile
index 4004347db47e..6e7df47c9584 100644
--- a/net/mptcp/Makefile
+++ b/net/mptcp/Makefile
@@ -11,6 +11,4 @@ mptcp_crypto_test-objs := crypto_test.o
 mptcp_token_test-objs := token_test.o
 obj-$(CONFIG_MPTCP_KUNIT_TEST) += mptcp_crypto_test.o mptcp_token_test.o
 
-ifeq ($(CONFIG_BPF_JIT),y)
 obj-$(CONFIG_BPF_SYSCALL) += bpf.o
-endif
-- 
2.34.1


Re: [PATCH mptcp-next] Squash to "bpf: add bpf_skc_to_mptcp_sock_proto"
Posted by Mat Martineau 3 years, 4 months ago
On Tue, 26 Apr 2022, Geliang Tang wrote:

> Update as Daniel suggested.
>
> Signed-off-by: Geliang Tang <geliang.tang@suse.com>

Looks good to squash, thanks. The 'base' bpf tests pass, which is what 
Daniel noted as failing.

- Mat


> ---
> include/linux/bpf.h      | 1 +
> include/net/mptcp.h      | 2 +-
> kernel/bpf/verifier.c    | 1 +
> kernel/trace/bpf_trace.c | 2 ++
> net/core/filter.c        | 3 ++-
> net/mptcp/Makefile       | 2 --
> 6 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index bdb5298735ce..2493f9601842 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -2249,6 +2249,7 @@ extern const struct bpf_func_proto bpf_skc_to_tcp_timewait_sock_proto;
> extern const struct bpf_func_proto bpf_skc_to_tcp_request_sock_proto;
> extern const struct bpf_func_proto bpf_skc_to_udp6_sock_proto;
> extern const struct bpf_func_proto bpf_skc_to_unix_sock_proto;
> +extern const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto;
> extern const struct bpf_func_proto bpf_copy_from_user_proto;
> extern const struct bpf_func_proto bpf_snprintf_btf_proto;
> extern const struct bpf_func_proto bpf_snprintf_proto;
> diff --git a/include/net/mptcp.h b/include/net/mptcp.h
> index 6b07011c060d..4d761ad530c9 100644
> --- a/include/net/mptcp.h
> +++ b/include/net/mptcp.h
> @@ -284,7 +284,7 @@ static inline int mptcpv6_init(void) { return 0; }
> static inline void mptcpv6_handle_mapped(struct sock *sk, bool mapped) { }
> #endif
>
> -#if defined(CONFIG_MPTCP) && defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF_SYSCALL)
> +#if defined(CONFIG_MPTCP) && defined(CONFIG_BPF_SYSCALL)
> struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk);
> #else
> static inline struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk) { return NULL; }
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 9c1a02b82ecd..40602ec20c6a 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -517,6 +517,7 @@ static bool is_ptr_cast_function(enum bpf_func_id func_id)
> 		func_id == BPF_FUNC_skc_to_tcp_sock ||
> 		func_id == BPF_FUNC_skc_to_tcp6_sock ||
> 		func_id == BPF_FUNC_skc_to_udp6_sock ||
> +		func_id == BPF_FUNC_skc_to_mptcp_sock ||
> 		func_id == BPF_FUNC_skc_to_tcp_timewait_sock ||
> 		func_id == BPF_FUNC_skc_to_tcp_request_sock;
> }
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index b26f3da943de..c7bf10cf2fa5 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -1685,6 +1685,8 @@ tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
> 		return &bpf_skc_to_udp6_sock_proto;
> 	case BPF_FUNC_skc_to_unix_sock:
> 		return &bpf_skc_to_unix_sock_proto;
> +	case BPF_FUNC_skc_to_mptcp_sock:
> +		return &bpf_skc_to_mptcp_sock_proto;
> 	case BPF_FUNC_sk_storage_get:
> 		return &bpf_sk_storage_get_tracing_proto;
> 	case BPF_FUNC_sk_storage_delete:
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 4bcf13b1d0e2..a0dd6f6b17f8 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -11282,10 +11282,11 @@ const struct bpf_func_proto bpf_skc_to_unix_sock_proto = {
>
> BPF_CALL_1(bpf_skc_to_mptcp_sock, struct sock *, sk)
> {
> +	BTF_TYPE_EMIT(struct mptcp_sock);
> 	return (unsigned long)bpf_mptcp_sock_from_subflow(sk);
> }
>
> -static const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto = {
> +const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto = {
> 	.func		= bpf_skc_to_mptcp_sock,
> 	.gpl_only	= false,
> 	.ret_type	= RET_PTR_TO_BTF_ID_OR_NULL,
> diff --git a/net/mptcp/Makefile b/net/mptcp/Makefile
> index 4004347db47e..6e7df47c9584 100644
> --- a/net/mptcp/Makefile
> +++ b/net/mptcp/Makefile
> @@ -11,6 +11,4 @@ mptcp_crypto_test-objs := crypto_test.o
> mptcp_token_test-objs := token_test.o
> obj-$(CONFIG_MPTCP_KUNIT_TEST) += mptcp_crypto_test.o mptcp_token_test.o
>
> -ifeq ($(CONFIG_BPF_JIT),y)
> obj-$(CONFIG_BPF_SYSCALL) += bpf.o
> -endif
> -- 
> 2.34.1
>
>
>

--
Mat Martineau
Intel

[PATCH mptcp-next] Squash to "selftests: bpf: test bpf_skc_to_mptcp_sock"
Posted by Geliang Tang 3 years, 4 months ago
Add CONFIG_MPTCP check.

When CONFIG_MPTCP is not enabled, we'll get a clearer error message:

libbpf: extern CONFIG_MPTCP (strong) not resolved
libbpf: failed to load object './mptcp_sock.o'

The message before is like this:

libbpf: prog '_sockops': BPF program load failed: Invalid argument
libbpf: prog '_sockops': -- BEGIN PROG LOAD LOG --

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 tools/testing/selftests/bpf/progs/mptcp_sock.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c b/tools/testing/selftests/bpf/progs/mptcp_sock.c
index 5cfaec4e7245..7b6a25e37de8 100644
--- a/tools/testing/selftests/bpf/progs/mptcp_sock.c
+++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c
@@ -7,6 +7,7 @@
 
 char _license[] SEC("license") = "GPL";
 __u32 _version SEC("version") = 1;
+extern bool CONFIG_MPTCP __kconfig;
 
 struct mptcp_storage {
 	__u32 invoked;
@@ -46,6 +47,9 @@ int _sockops(struct bpf_sock_ops *ctx)
 		if (!storage)
 			return 1;
 	} else {
+		if (!CONFIG_MPTCP)
+			return 1;
+
 		msk = bpf_skc_to_mptcp_sock(sk);
 		if (!msk)
 			return 1;
-- 
2.34.1


Re: [PATCH mptcp-next] Squash to "selftests: bpf: test bpf_skc_to_mptcp_sock"
Posted by Matthieu Baerts 3 years, 4 months ago
Hi Geliang, Mat,

On 26/04/2022 06:26, Geliang Tang wrote:
> Add CONFIG_MPTCP check.
> 
> When CONFIG_MPTCP is not enabled, we'll get a clearer error message:
> 
> libbpf: extern CONFIG_MPTCP (strong) not resolved
> libbpf: failed to load object './mptcp_sock.o'
> 
> The message before is like this:
> 
> libbpf: prog '_sockops': BPF program load failed: Invalid argument
> libbpf: prog '_sockops': -- BEGIN PROG LOAD LOG --

Thank you for the two patches and reviews!

Now in our tree:

- f456d87ca214: "squashed" in "bpf: add bpf_skc_to_mptcp_sock_proto"
- 8aa57e042f44: "squashed" in "selftests: bpf: test bpf_skc_to_mptcp_sock"
- Results: c2a1191f33d3..440ea2eff5af (export)

Builds and tests are now in progress:

https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20220427T162930
https://github.com/multipath-tcp/mptcp_net-next/actions/workflows/build-validation.yml?query=branch:export

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net

Re: [PATCH mptcp-next] Squash to "selftests: bpf: test bpf_skc_to_mptcp_sock"
Posted by Mat Martineau 3 years, 4 months ago
On Tue, 26 Apr 2022, Geliang Tang wrote:

> Add CONFIG_MPTCP check.
>
> When CONFIG_MPTCP is not enabled, we'll get a clearer error message:
>
> libbpf: extern CONFIG_MPTCP (strong) not resolved
> libbpf: failed to load object './mptcp_sock.o'
>
> The message before is like this:
>
> libbpf: prog '_sockops': BPF program load failed: Invalid argument
> libbpf: prog '_sockops': -- BEGIN PROG LOAD LOG --
>
> Signed-off-by: Geliang Tang <geliang.tang@suse.com>
> ---
> tools/testing/selftests/bpf/progs/mptcp_sock.c | 4 ++++
> 1 file changed, 4 insertions(+)
>

Looks like this also requires CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC, 
can you also add those to tools/testing/selftests/bpf/config? Maybe that 
should be a separate commit, since other bpf test progs appear to rely on 
this undocumented config requirement.

- Mat

> diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c b/tools/testing/selftests/bpf/progs/mptcp_sock.c
> index 5cfaec4e7245..7b6a25e37de8 100644
> --- a/tools/testing/selftests/bpf/progs/mptcp_sock.c
> +++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c
> @@ -7,6 +7,7 @@
>
> char _license[] SEC("license") = "GPL";
> __u32 _version SEC("version") = 1;
> +extern bool CONFIG_MPTCP __kconfig;
>
> struct mptcp_storage {
> 	__u32 invoked;
> @@ -46,6 +47,9 @@ int _sockops(struct bpf_sock_ops *ctx)
> 		if (!storage)
> 			return 1;
> 	} else {
> +		if (!CONFIG_MPTCP)
> +			return 1;
> +
> 		msk = bpf_skc_to_mptcp_sock(sk);
> 		if (!msk)
> 			return 1;
> -- 
> 2.34.1
>
>
>

--
Mat Martineau
Intel

Re: [PATCH mptcp-next] Squash to "selftests: bpf: test bpf_skc_to_mptcp_sock"
Posted by Geliang Tang 3 years, 4 months ago
Hi Mat,

Mat Martineau <mathew.j.martineau@linux.intel.com> 于2022年4月27日周三 08:20写道:
>
> On Tue, 26 Apr 2022, Geliang Tang wrote:
>
> > Add CONFIG_MPTCP check.
> >
> > When CONFIG_MPTCP is not enabled, we'll get a clearer error message:
> >
> > libbpf: extern CONFIG_MPTCP (strong) not resolved
> > libbpf: failed to load object './mptcp_sock.o'
> >
> > The message before is like this:
> >
> > libbpf: prog '_sockops': BPF program load failed: Invalid argument
> > libbpf: prog '_sockops': -- BEGIN PROG LOAD LOG --
> >
> > Signed-off-by: Geliang Tang <geliang.tang@suse.com>
> > ---
> > tools/testing/selftests/bpf/progs/mptcp_sock.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
>
> Looks like this also requires CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC,
> can you also add those to tools/testing/selftests/bpf/config? Maybe that
> should be a separate commit, since other bpf test progs appear to rely on
> this undocumented config requirement.

In my test, this bpf base test still works without CONFIG_IKCONFIG and
CONFIG_IKCONFIG_PROC:

> ls /proc/config.gz
ls: cannot access '/proc/config.gz': No such file or directory
> sudo ./test_progs -n 103
#103 mptcp:OK
Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED

Thanks,
-Geliang




>
> - Mat
>
> > diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c b/tools/testing/selftests/bpf/progs/mptcp_sock.c
> > index 5cfaec4e7245..7b6a25e37de8 100644
> > --- a/tools/testing/selftests/bpf/progs/mptcp_sock.c
> > +++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c
> > @@ -7,6 +7,7 @@
> >
> > char _license[] SEC("license") = "GPL";
> > __u32 _version SEC("version") = 1;
> > +extern bool CONFIG_MPTCP __kconfig;
> >
> > struct mptcp_storage {
> >       __u32 invoked;
> > @@ -46,6 +47,9 @@ int _sockops(struct bpf_sock_ops *ctx)
> >               if (!storage)
> >                       return 1;
> >       } else {
> > +             if (!CONFIG_MPTCP)
> > +                     return 1;
> > +
> >               msk = bpf_skc_to_mptcp_sock(sk);
> >               if (!msk)
> >                       return 1;
> > --
> > 2.34.1
> >
> >
> >
>
> --
> Mat Martineau
> Intel
>

Re: [PATCH mptcp-next] Squash to "selftests: bpf: test bpf_skc_to_mptcp_sock"
Posted by Mat Martineau 3 years, 4 months ago
On Wed, 27 Apr 2022, Geliang Tang wrote:

> Hi Mat,
>
> Mat Martineau <mathew.j.martineau@linux.intel.com> 于2022年4月27日周三 08:20写道:
>>
>> On Tue, 26 Apr 2022, Geliang Tang wrote:
>>
>>> Add CONFIG_MPTCP check.
>>>
>>> When CONFIG_MPTCP is not enabled, we'll get a clearer error message:
>>>
>>> libbpf: extern CONFIG_MPTCP (strong) not resolved
>>> libbpf: failed to load object './mptcp_sock.o'
>>>
>>> The message before is like this:
>>>
>>> libbpf: prog '_sockops': BPF program load failed: Invalid argument
>>> libbpf: prog '_sockops': -- BEGIN PROG LOAD LOG --
>>>
>>> Signed-off-by: Geliang Tang <geliang.tang@suse.com>
>>> ---
>>> tools/testing/selftests/bpf/progs/mptcp_sock.c | 4 ++++
>>> 1 file changed, 4 insertions(+)
>>>
>>
>> Looks like this also requires CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC,
>> can you also add those to tools/testing/selftests/bpf/config? Maybe that
>> should be a separate commit, since other bpf test progs appear to rely on
>> this undocumented config requirement.
>
> In my test, this bpf base test still works without CONFIG_IKCONFIG and
> CONFIG_IKCONFIG_PROC:
>
>> ls /proc/config.gz
> ls: cannot access '/proc/config.gz': No such file or directory
>> sudo ./test_progs -n 103
> #103 mptcp:OK
> Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED
>

Huh, I wonder what's going on? It fails for me:

$ sudo ./test_progs -v -a mptcp
bpf_testmod.ko is already unloaded.
Loading bpf_testmod.ko...
Successfully loaded bpf_testmod.ko.
libbpf: failed to open system Kconfig
libbpf: failed to load object './mptcp_sock.o'
run_test:FAIL:165
test_base:FAIL:227
libbpf: failed to open system Kconfig
libbpf: failed to load object './mptcp_sock.o'
run_test:FAIL:165
test_base:FAIL:244
#103/1 mptcp/base:FAIL
(cgroup_helpers.c:146: errno: Device or resource busy) Removing cgroup: /mnt/cgroup-test-work-dir831/mptcp
(cgroup_helpers.c:146: errno: Device or resource busy) Removing cgroup: /mnt/cgroup-test-work-dir831
#103 mptcp:FAIL

All error logs:
#103 mptcp:FAIL

Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED

This is with Fedora 35. I'll check the BPF CI to see if there's any 
information about their configuration that might explain the difference.


- Mat

>
>
>>
>> - Mat
>>
>>> diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c b/tools/testing/selftests/bpf/progs/mptcp_sock.c
>>> index 5cfaec4e7245..7b6a25e37de8 100644
>>> --- a/tools/testing/selftests/bpf/progs/mptcp_sock.c
>>> +++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c
>>> @@ -7,6 +7,7 @@
>>>
>>> char _license[] SEC("license") = "GPL";
>>> __u32 _version SEC("version") = 1;
>>> +extern bool CONFIG_MPTCP __kconfig;
>>>
>>> struct mptcp_storage {
>>>       __u32 invoked;
>>> @@ -46,6 +47,9 @@ int _sockops(struct bpf_sock_ops *ctx)
>>>               if (!storage)
>>>                       return 1;
>>>       } else {
>>> +             if (!CONFIG_MPTCP)
>>> +                     return 1;
>>> +
>>>               msk = bpf_skc_to_mptcp_sock(sk);
>>>               if (!msk)
>>>                       return 1;
>>> --
>>> 2.34.1
>>>
>>>
>>>
>>
>> --
>> Mat Martineau
>> Intel
>>
>

--
Mat Martineau
Intel
Re: [PATCH mptcp-next] Squash to "selftests: bpf: test bpf_skc_to_mptcp_sock"
Posted by Geliang Tang 3 years, 4 months ago
Hi Mat,


Mat Martineau <mathew.j.martineau@linux.intel.com> 于2022年4月28日周四 05:47写道:
>
> On Wed, 27 Apr 2022, Geliang Tang wrote:
>
> > Hi Mat,
> >
> > Mat Martineau <mathew.j.martineau@linux.intel.com> 于2022年4月27日周三 08:20写道:
> >>
> >> On Tue, 26 Apr 2022, Geliang Tang wrote:
> >>
> >>> Add CONFIG_MPTCP check.
> >>>
> >>> When CONFIG_MPTCP is not enabled, we'll get a clearer error message:
> >>>
> >>> libbpf: extern CONFIG_MPTCP (strong) not resolved
> >>> libbpf: failed to load object './mptcp_sock.o'
> >>>
> >>> The message before is like this:
> >>>
> >>> libbpf: prog '_sockops': BPF program load failed: Invalid argument
> >>> libbpf: prog '_sockops': -- BEGIN PROG LOAD LOG --
> >>>
> >>> Signed-off-by: Geliang Tang <geliang.tang@suse.com>
> >>> ---
> >>> tools/testing/selftests/bpf/progs/mptcp_sock.c | 4 ++++
> >>> 1 file changed, 4 insertions(+)
> >>>
> >>
> >> Looks like this also requires CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC,
> >> can you also add those to tools/testing/selftests/bpf/config? Maybe that
> >> should be a separate commit, since other bpf test progs appear to rely on
> >> this undocumented config requirement.
> >
> > In my test, this bpf base test still works without CONFIG_IKCONFIG and
> > CONFIG_IKCONFIG_PROC:
> >
> >> ls /proc/config.gz
> > ls: cannot access '/proc/config.gz': No such file or directory
> >> sudo ./test_progs -n 103
> > #103 mptcp:OK
> > Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED
> >
>
> Huh, I wonder what's going on? It fails for me:
>
> $ sudo ./test_progs -v -a mptcp
> bpf_testmod.ko is already unloaded.
> Loading bpf_testmod.ko...
> Successfully loaded bpf_testmod.ko.
> libbpf: failed to open system Kconfig
> libbpf: failed to load object './mptcp_sock.o'
> run_test:FAIL:165
> test_base:FAIL:227
> libbpf: failed to open system Kconfig
> libbpf: failed to load object './mptcp_sock.o'
> run_test:FAIL:165
> test_base:FAIL:244
> #103/1 mptcp/base:FAIL
> (cgroup_helpers.c:146: errno: Device or resource busy) Removing cgroup: /mnt/cgroup-test-work-dir831/mptcp
> (cgroup_helpers.c:146: errno: Device or resource busy) Removing cgroup: /mnt/cgroup-test-work-dir831
> #103 mptcp:FAIL
>
> All error logs:
> #103 mptcp:FAIL
>
> Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED
>
> This is with Fedora 35. I'll check the BPF CI to see if there's any
> information about their configuration that might explain the difference.

I figure it out. libbpf reads /boot/config-* first, then /proc/config.gz:

 1840 static int bpf_object__read_kconfig_file(struct bpf_object *obj,
void *data)
 1841 {
 1842         char buf[PATH_MAX];
 1843         struct utsname uts;
 1844         int len, err = 0;
 1845         gzFile file;
 1846
 1847         uname(&uts);
 1848         len = snprintf(buf, PATH_MAX, "/boot/config-%s", uts.release);
 1849         if (len < 0)
 1850                 return -EINVAL;
 1851         else if (len >= PATH_MAX)
 1852                 return -ENAMETOOLONG;
 1853
 1854         /* gzopen also accepts uncompressed files. */
 1855         file = gzopen(buf, "r");
 1856         if (!file)
 1857                 file = gzopen("/proc/config.gz", "r");

So we do need to add CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC in
config. I'll send a v2 as a dedicated patch.

Thanks,
-Geliang


>
>
> - Mat
>
> >
> >
> >>
> >> - Mat
> >>
> >>> diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c b/tools/testing/selftests/bpf/progs/mptcp_sock.c
> >>> index 5cfaec4e7245..7b6a25e37de8 100644
> >>> --- a/tools/testing/selftests/bpf/progs/mptcp_sock.c
> >>> +++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c
> >>> @@ -7,6 +7,7 @@
> >>>
> >>> char _license[] SEC("license") = "GPL";
> >>> __u32 _version SEC("version") = 1;
> >>> +extern bool CONFIG_MPTCP __kconfig;
> >>>
> >>> struct mptcp_storage {
> >>>       __u32 invoked;
> >>> @@ -46,6 +47,9 @@ int _sockops(struct bpf_sock_ops *ctx)
> >>>               if (!storage)
> >>>                       return 1;
> >>>       } else {
> >>> +             if (!CONFIG_MPTCP)
> >>> +                     return 1;
> >>> +
> >>>               msk = bpf_skc_to_mptcp_sock(sk);
> >>>               if (!msk)
> >>>                       return 1;
> >>> --
> >>> 2.34.1
> >>>
> >>>
> >>>
> >>
> >> --
> >> Mat Martineau
> >> Intel
> >>
> >
>
> --
> Mat Martineau
> Intel

Re: [PATCH mptcp-next] Squash to "selftests: bpf: test bpf_skc_to_mptcp_sock"
Posted by Mat Martineau 3 years, 4 months ago
On Tue, 26 Apr 2022, Mat Martineau wrote:

> On Tue, 26 Apr 2022, Geliang Tang wrote:
>
>> Add CONFIG_MPTCP check.
>> 
>> When CONFIG_MPTCP is not enabled, we'll get a clearer error message:
>> 
>> libbpf: extern CONFIG_MPTCP (strong) not resolved
>> libbpf: failed to load object './mptcp_sock.o'
>> 
>> The message before is like this:
>> 
>> libbpf: prog '_sockops': BPF program load failed: Invalid argument
>> libbpf: prog '_sockops': -- BEGIN PROG LOAD LOG --
>> 
>> Signed-off-by: Geliang Tang <geliang.tang@suse.com>
>> ---
>> tools/testing/selftests/bpf/progs/mptcp_sock.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>> 
>
> Looks like this also requires CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC, can 
> you also add those to tools/testing/selftests/bpf/config? Maybe that should 
> be a separate commit, since other bpf test progs appear to rely on this 
> undocumented config requirement.
>

I hit 'send' too soon... We should still squash this, and add that second 
commit for the config information.

- Mat

>
>> diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c 
>> b/tools/testing/selftests/bpf/progs/mptcp_sock.c
>> index 5cfaec4e7245..7b6a25e37de8 100644
>> --- a/tools/testing/selftests/bpf/progs/mptcp_sock.c
>> +++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c
>> @@ -7,6 +7,7 @@
>> 
>> char _license[] SEC("license") = "GPL";
>> __u32 _version SEC("version") = 1;
>> +extern bool CONFIG_MPTCP __kconfig;
>> 
>> struct mptcp_storage {
>> 	__u32 invoked;
>> @@ -46,6 +47,9 @@ int _sockops(struct bpf_sock_ops *ctx)
>> 		if (!storage)
>> 			return 1;
>> 	} else {
>> +		if (!CONFIG_MPTCP)
>> +			return 1;
>> +
>> 		msk = bpf_skc_to_mptcp_sock(sk);
>> 		if (!msk)
>> 			return 1;
>> -- 
>> 2.34.1
>> 
>> 
>> 
>
> --
> Mat Martineau
> Intel
>
>

--
Mat Martineau
Intel