All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/8] bpf: Allow bpf tcp iter to do bpf_setsockopt
@ 2021-06-25 20:04 Martin KaFai Lau
  2021-06-25 20:04 ` [PATCH bpf-next 1/8] tcp: seq_file: Avoid skipping sk during tcp_seek_last_pos Martin KaFai Lau
                   ` (8 more replies)
  0 siblings, 9 replies; 18+ messages in thread
From: Martin KaFai Lau @ 2021-06-25 20:04 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Eric Dumazet, kernel-team,
	Neal Cardwell, netdev, Yonghong Song, Yuchung Cheng

This set is to allow bpf tcp iter to call bpf_setsockopt.

With bpf-tcp-cc, new algo rollout happens more often.  Instead of
restarting the applications to pick up the new tcp-cc, this set
allows the bpf tcp iter with the netadmin cap to call
bpf_setsockopt(TCP_CONGESTION).  It is not limited to TCP_CONGESTION
and the bpf tcp iter can call bpf_setsockopt() with other options.
The bpf tcp iter can read into all the fields of a tcp_sock, so
there is a lot of flexibility to select the desired sk to do
setsockopt(), e.g. it can test for TCP_LISTEN only and leave
the established connections untouched, or check the addr/port,
or check the current tcp-cc name, ...etc.

Patch 1-4 are some cleanup and prep work in the tcp and bpf seq_file.

Patch 5 is to have the tcp seq_file iterate on the
port+addr lhash2 instead of the port only listening_hash.

Patch 6 is to have the bpf tcp iter doing batching which
then allows lock_sock.  lock_sock is needed for setsockopt.

Patch 7 allows the bpf tcp iter to call bpf_setsockopt.

Martin KaFai Lau (8):
  tcp: seq_file: Avoid skipping sk during tcp_seek_last_pos
  tcp: seq_file: Refactor net and family matching
  bpf: tcp: seq_file: Remove bpf_seq_afinfo from tcp_iter_state
  tcp: seq_file: Add listening_get_first()
  tcp: seq_file: Replace listening_hash with lhash2
  bpf: tcp: bpf iter batching and lock_sock
  bpf: tcp: Support bpf_setsockopt in bpf tcp iter
  bpf: selftest: Test batching and bpf_setsockopt in bpf tcp iter

 include/linux/bpf.h                           |   7 +
 include/net/inet_hashtables.h                 |   6 +
 include/net/tcp.h                             |   1 -
 kernel/bpf/bpf_iter.c                         |  22 +
 kernel/trace/bpf_trace.c                      |   7 +-
 net/core/filter.c                             |  17 +
 net/ipv4/tcp_ipv4.c                           | 409 ++++++++++++++----
 tools/testing/selftests/bpf/network_helpers.c |  85 +++-
 tools/testing/selftests/bpf/network_helpers.h |   4 +
 .../bpf/prog_tests/bpf_iter_setsockopt.c      | 226 ++++++++++
 .../selftests/bpf/progs/bpf_iter_setsockopt.c |  76 ++++
 .../selftests/bpf/progs/bpf_tracing_net.h     |   4 +
 12 files changed, 767 insertions(+), 97 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_iter_setsockopt.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_setsockopt.c

-- 
2.30.2


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next 6/8] bpf: tcp: bpf iter batching and lock_sock
@ 2021-06-26  5:21 kernel test robot
  0 siblings, 0 replies; 18+ messages in thread
From: kernel test robot @ 2021-06-26  5:21 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 7767 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210625200523.726854-1-kafai@fb.com>
References: <20210625200523.726854-1-kafai@fb.com>
TO: Martin KaFai Lau <kafai@fb.com>
TO: bpf(a)vger.kernel.org
CC: Alexei Starovoitov <ast@kernel.org>
CC: Daniel Borkmann <daniel@iogearbox.net>
CC: Eric Dumazet <edumazet@google.com>
CC: kernel-team(a)fb.com
CC: Neal Cardwell <ncardwell@google.com>
CC: netdev(a)vger.kernel.org
CC: Yonghong Song <yhs@fb.com>
CC: Yuchung Cheng <ycheng@google.com>

Hi Martin,

I love your patch! Perhaps something to improve:

[auto build test WARNING on bpf-next/master]

url:    https://github.com/0day-ci/linux/commits/Martin-KaFai-Lau/bpf-Allow-bpf-tcp-iter-to-do-bpf_setsockopt/20210626-040650
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
:::::: branch date: 9 hours ago
:::::: commit date: 9 hours ago
config: x86_64-randconfig-s031-20210622 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.3-341-g8af24329-dirty
        # https://github.com/0day-ci/linux/commit/5f78445efda4708980f0d1cb4c59a35000205232
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Martin-KaFai-Lau/bpf-Allow-bpf-tcp-iter-to-do-bpf_setsockopt/20210626-040650
        git checkout 5f78445efda4708980f0d1cb4c59a35000205232
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)
   net/ipv4/tcp_ipv4.c:3084:41: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *data @@     got struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control @@
   net/ipv4/tcp_ipv4.c:3084:41: sparse:     expected void const *data
   net/ipv4/tcp_ipv4.c:3084:41: sparse:     got struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control
   net/ipv4/tcp_ipv4.c:3193:45: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *data @@     got struct tcp_congestion_ops const [noderef] __rcu *extern [addressable] [toplevel] tcp_congestion_control @@
   net/ipv4/tcp_ipv4.c:3193:45: sparse:     expected void const *data
   net/ipv4/tcp_ipv4.c:3193:45: sparse:     got struct tcp_congestion_ops const [noderef] __rcu *extern [addressable] [toplevel] tcp_congestion_control
   net/ipv4/tcp_ipv4.c:3197:50: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control @@     got struct tcp_congestion_ops * @@
   net/ipv4/tcp_ipv4.c:3197:50: sparse:     expected struct tcp_congestion_ops const [noderef] __rcu *tcp_congestion_control
   net/ipv4/tcp_ipv4.c:3197:50: sparse:     got struct tcp_congestion_ops *
   net/ipv4/tcp_ipv4.c:1619:25: sparse: sparse: context imbalance in 'tcp_v4_syn_recv_sock' - unexpected unlock
   net/ipv4/tcp_ipv4.c:1893:17: sparse: sparse: context imbalance in 'tcp_add_backlog' - unexpected unlock
   net/ipv4/tcp_ipv4.c:2125:21: sparse: sparse: context imbalance in 'tcp_v4_rcv' - different lock contexts for basic block
   net/ipv4/tcp_ipv4.c:2294:13: sparse: sparse: context imbalance in 'listening_get_first' - wrong count at exit
   net/ipv4/tcp_ipv4.c:2342:9: sparse: sparse: context imbalance in 'listening_get_next' - unexpected unlock
   net/ipv4/tcp_ipv4.c:2373:13: sparse: sparse: context imbalance in 'established_get_first' - wrong count at exit
   net/ipv4/tcp_ipv4.c:2414:40: sparse: sparse: context imbalance in 'established_get_next' - unexpected unlock
   net/ipv4/tcp_ipv4.c:2545:36: sparse: sparse: context imbalance in 'tcp_seq_stop' - unexpected unlock
   net/ipv4/tcp_ipv4.c:2763:20: sparse: sparse: context imbalance in 'bpf_iter_tcp_listening_batch' - unexpected unlock
   net/ipv4/tcp_ipv4.c:2790:40: sparse: sparse: context imbalance in 'bpf_iter_tcp_established_batch' - unexpected unlock
>> net/ipv4/tcp_ipv4.c:2932:9: sparse: sparse: context imbalance in 'bpf_iter_tcp_seq_show' - different lock contexts for basic block
   net/ipv4/tcp_ipv4.c:3085:41: sparse: sparse: dereference of noderef expression
   net/ipv4/tcp_ipv4.c:3085:41: sparse: sparse: dereference of noderef expression
   net/ipv4/tcp_ipv4.c:3194:45: sparse: sparse: dereference of noderef expression
   net/ipv4/tcp_ipv4.c:3194:45: sparse: sparse: dereference of noderef expression

vim +/bpf_iter_tcp_seq_show +2932 net/ipv4/tcp_ipv4.c

5f78445efda470 Martin KaFai Lau 2021-06-25  2893  
52d87d5f6418ba Yonghong Song    2020-06-23  2894  static int bpf_iter_tcp_seq_show(struct seq_file *seq, void *v)
52d87d5f6418ba Yonghong Song    2020-06-23  2895  {
52d87d5f6418ba Yonghong Song    2020-06-23  2896  	struct bpf_iter_meta meta;
52d87d5f6418ba Yonghong Song    2020-06-23  2897  	struct bpf_prog *prog;
52d87d5f6418ba Yonghong Song    2020-06-23  2898  	struct sock *sk = v;
5f78445efda470 Martin KaFai Lau 2021-06-25  2899  	bool slow;
52d87d5f6418ba Yonghong Song    2020-06-23  2900  	uid_t uid;
5f78445efda470 Martin KaFai Lau 2021-06-25  2901  	int ret;
52d87d5f6418ba Yonghong Song    2020-06-23  2902  
52d87d5f6418ba Yonghong Song    2020-06-23  2903  	if (v == SEQ_START_TOKEN)
52d87d5f6418ba Yonghong Song    2020-06-23  2904  		return 0;
52d87d5f6418ba Yonghong Song    2020-06-23  2905  
5f78445efda470 Martin KaFai Lau 2021-06-25  2906  	if (sk_fullsock(sk))
5f78445efda470 Martin KaFai Lau 2021-06-25  2907  		slow = lock_sock_fast(sk);
5f78445efda470 Martin KaFai Lau 2021-06-25  2908  
5f78445efda470 Martin KaFai Lau 2021-06-25  2909  	if (unlikely(sk_unhashed(sk))) {
5f78445efda470 Martin KaFai Lau 2021-06-25  2910  		ret = SEQ_SKIP;
5f78445efda470 Martin KaFai Lau 2021-06-25  2911  		goto unlock;
5f78445efda470 Martin KaFai Lau 2021-06-25  2912  	}
5f78445efda470 Martin KaFai Lau 2021-06-25  2913  
52d87d5f6418ba Yonghong Song    2020-06-23  2914  	if (sk->sk_state == TCP_TIME_WAIT) {
52d87d5f6418ba Yonghong Song    2020-06-23  2915  		uid = 0;
52d87d5f6418ba Yonghong Song    2020-06-23  2916  	} else if (sk->sk_state == TCP_NEW_SYN_RECV) {
52d87d5f6418ba Yonghong Song    2020-06-23  2917  		const struct request_sock *req = v;
52d87d5f6418ba Yonghong Song    2020-06-23  2918  
52d87d5f6418ba Yonghong Song    2020-06-23  2919  		uid = from_kuid_munged(seq_user_ns(seq),
52d87d5f6418ba Yonghong Song    2020-06-23  2920  				       sock_i_uid(req->rsk_listener));
52d87d5f6418ba Yonghong Song    2020-06-23  2921  	} else {
52d87d5f6418ba Yonghong Song    2020-06-23  2922  		uid = from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk));
52d87d5f6418ba Yonghong Song    2020-06-23  2923  	}
52d87d5f6418ba Yonghong Song    2020-06-23  2924  
52d87d5f6418ba Yonghong Song    2020-06-23  2925  	meta.seq = seq;
52d87d5f6418ba Yonghong Song    2020-06-23  2926  	prog = bpf_iter_get_info(&meta, false);
5f78445efda470 Martin KaFai Lau 2021-06-25  2927  	ret = tcp_prog_seq_show(prog, &meta, v, uid);
5f78445efda470 Martin KaFai Lau 2021-06-25  2928  
5f78445efda470 Martin KaFai Lau 2021-06-25  2929  unlock:
5f78445efda470 Martin KaFai Lau 2021-06-25  2930  	if (sk_fullsock(sk))
5f78445efda470 Martin KaFai Lau 2021-06-25  2931  		unlock_sock_fast(sk, slow);
5f78445efda470 Martin KaFai Lau 2021-06-25 @2932  	return ret;
5f78445efda470 Martin KaFai Lau 2021-06-25  2933  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 47145 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next 6/8] bpf: tcp: bpf iter batching and lock_sock
@ 2021-06-26 14:42 kernel test robot
  0 siblings, 0 replies; 18+ messages in thread
From: kernel test robot @ 2021-06-26 14:42 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 4332 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210625200523.726854-1-kafai@fb.com>
References: <20210625200523.726854-1-kafai@fb.com>
TO: Martin KaFai Lau <kafai@fb.com>
TO: bpf(a)vger.kernel.org
CC: Alexei Starovoitov <ast@kernel.org>
CC: Daniel Borkmann <daniel@iogearbox.net>
CC: Eric Dumazet <edumazet@google.com>
CC: kernel-team(a)fb.com
CC: Neal Cardwell <ncardwell@google.com>
CC: netdev(a)vger.kernel.org
CC: Yonghong Song <yhs@fb.com>
CC: Yuchung Cheng <ycheng@google.com>

Hi Martin,

I love your patch! Perhaps something to improve:

[auto build test WARNING on bpf-next/master]

url:    https://github.com/0day-ci/linux/commits/Martin-KaFai-Lau/bpf-Allow-bpf-tcp-iter-to-do-bpf_setsockopt/20210626-040650
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
:::::: branch date: 19 hours ago
:::::: commit date: 19 hours ago
config: x86_64-randconfig-m001-20210625 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
net/ipv4/tcp_ipv4.c:2931 bpf_iter_tcp_seq_show() error: uninitialized symbol 'slow'.

vim +/slow +2931 net/ipv4/tcp_ipv4.c

5f78445efda470 Martin KaFai Lau 2021-06-25  2893  
52d87d5f6418ba Yonghong Song    2020-06-23  2894  static int bpf_iter_tcp_seq_show(struct seq_file *seq, void *v)
52d87d5f6418ba Yonghong Song    2020-06-23  2895  {
52d87d5f6418ba Yonghong Song    2020-06-23  2896  	struct bpf_iter_meta meta;
52d87d5f6418ba Yonghong Song    2020-06-23  2897  	struct bpf_prog *prog;
52d87d5f6418ba Yonghong Song    2020-06-23  2898  	struct sock *sk = v;
5f78445efda470 Martin KaFai Lau 2021-06-25  2899  	bool slow;
52d87d5f6418ba Yonghong Song    2020-06-23  2900  	uid_t uid;
5f78445efda470 Martin KaFai Lau 2021-06-25  2901  	int ret;
52d87d5f6418ba Yonghong Song    2020-06-23  2902  
52d87d5f6418ba Yonghong Song    2020-06-23  2903  	if (v == SEQ_START_TOKEN)
52d87d5f6418ba Yonghong Song    2020-06-23  2904  		return 0;
52d87d5f6418ba Yonghong Song    2020-06-23  2905  
5f78445efda470 Martin KaFai Lau 2021-06-25  2906  	if (sk_fullsock(sk))
5f78445efda470 Martin KaFai Lau 2021-06-25  2907  		slow = lock_sock_fast(sk);
5f78445efda470 Martin KaFai Lau 2021-06-25  2908  
5f78445efda470 Martin KaFai Lau 2021-06-25  2909  	if (unlikely(sk_unhashed(sk))) {
5f78445efda470 Martin KaFai Lau 2021-06-25  2910  		ret = SEQ_SKIP;
5f78445efda470 Martin KaFai Lau 2021-06-25  2911  		goto unlock;
5f78445efda470 Martin KaFai Lau 2021-06-25  2912  	}
5f78445efda470 Martin KaFai Lau 2021-06-25  2913  
52d87d5f6418ba Yonghong Song    2020-06-23  2914  	if (sk->sk_state == TCP_TIME_WAIT) {
52d87d5f6418ba Yonghong Song    2020-06-23  2915  		uid = 0;
52d87d5f6418ba Yonghong Song    2020-06-23  2916  	} else if (sk->sk_state == TCP_NEW_SYN_RECV) {
52d87d5f6418ba Yonghong Song    2020-06-23  2917  		const struct request_sock *req = v;
52d87d5f6418ba Yonghong Song    2020-06-23  2918  
52d87d5f6418ba Yonghong Song    2020-06-23  2919  		uid = from_kuid_munged(seq_user_ns(seq),
52d87d5f6418ba Yonghong Song    2020-06-23  2920  				       sock_i_uid(req->rsk_listener));
52d87d5f6418ba Yonghong Song    2020-06-23  2921  	} else {
52d87d5f6418ba Yonghong Song    2020-06-23  2922  		uid = from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk));
52d87d5f6418ba Yonghong Song    2020-06-23  2923  	}
52d87d5f6418ba Yonghong Song    2020-06-23  2924  
52d87d5f6418ba Yonghong Song    2020-06-23  2925  	meta.seq = seq;
52d87d5f6418ba Yonghong Song    2020-06-23  2926  	prog = bpf_iter_get_info(&meta, false);
5f78445efda470 Martin KaFai Lau 2021-06-25  2927  	ret = tcp_prog_seq_show(prog, &meta, v, uid);
5f78445efda470 Martin KaFai Lau 2021-06-25  2928  
5f78445efda470 Martin KaFai Lau 2021-06-25  2929  unlock:
5f78445efda470 Martin KaFai Lau 2021-06-25  2930  	if (sk_fullsock(sk))
5f78445efda470 Martin KaFai Lau 2021-06-25 @2931  		unlock_sock_fast(sk, slow);
5f78445efda470 Martin KaFai Lau 2021-06-25  2932  	return ret;
5f78445efda470 Martin KaFai Lau 2021-06-25  2933  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 39072 bytes --]

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

end of thread, other threads:[~2021-06-29 19:04 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25 20:04 [PATCH bpf-next 0/8] bpf: Allow bpf tcp iter to do bpf_setsockopt Martin KaFai Lau
2021-06-25 20:04 ` [PATCH bpf-next 1/8] tcp: seq_file: Avoid skipping sk during tcp_seek_last_pos Martin KaFai Lau
2021-06-25 20:04 ` [PATCH bpf-next 2/8] tcp: seq_file: Refactor net and family matching Martin KaFai Lau
2021-06-25 20:05 ` [PATCH bpf-next 3/8] bpf: tcp: seq_file: Remove bpf_seq_afinfo from tcp_iter_state Martin KaFai Lau
2021-06-25 20:05 ` [PATCH bpf-next 4/8] tcp: seq_file: Add listening_get_first() Martin KaFai Lau
2021-06-25 20:05 ` [PATCH bpf-next 5/8] tcp: seq_file: Replace listening_hash with lhash2 Martin KaFai Lau
2021-06-25 20:05 ` [PATCH bpf-next 6/8] bpf: tcp: bpf iter batching and lock_sock Martin KaFai Lau
2021-06-29 17:27   ` Yonghong Song
2021-06-29 17:44     ` Martin KaFai Lau
2021-06-29 17:57       ` Yonghong Song
2021-06-29 18:06         ` Martin KaFai Lau
2021-06-29 18:55           ` Yonghong Song
2021-06-25 20:05 ` [PATCH bpf-next 7/8] bpf: tcp: Support bpf_setsockopt in bpf tcp iter Martin KaFai Lau
2021-06-25 20:05 ` [PATCH bpf-next 8/8] bpf: selftest: Test batching and " Martin KaFai Lau
2021-06-29 19:00   ` Yonghong Song
2021-06-29 19:04 ` [PATCH bpf-next 0/8] bpf: Allow bpf tcp iter to do bpf_setsockopt Yonghong Song
2021-06-26  5:21 [PATCH bpf-next 6/8] bpf: tcp: bpf iter batching and lock_sock kernel test robot
2021-06-26 14:42 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.