Files
android_kernel_xiaomi_sm8450/include/linux
Martin KaFai Lau 085c20cacf bpf: inet_diag: Dump bpf_sk_storages in inet_diag_dump()
This patch will dump out the bpf_sk_storages of a sk
if the request has the INET_DIAG_REQ_SK_BPF_STORAGES nlattr.

An array of SK_DIAG_BPF_STORAGE_REQ_MAP_FD can be specified in
INET_DIAG_REQ_SK_BPF_STORAGES to select which bpf_sk_storage to dump.
If no map_fd is specified, all bpf_sk_storages of a sk will be dumped.

bpf_sk_storages can be added to the system at runtime.  It is difficult
to find a proper static value for cb->min_dump_alloc.

This patch learns the nlattr size required to dump the bpf_sk_storages
of a sk.  If it happens to be the very first nlmsg of a dump and it
cannot fit the needed bpf_sk_storages,  it will try to expand the
skb by "pskb_expand_head()".

Instead of expanding it in inet_sk_diag_fill(), it is expanded at a
sleepable context in __inet_diag_dump() so __GFP_DIRECT_RECLAIM can
be used.  In __inet_diag_dump(), it will retry as long as the
skb is empty and the cb->min_dump_alloc becomes larger than before.
cb->min_dump_alloc is bounded by KMALLOC_MAX_SIZE.  The min_dump_alloc
is also changed from 'u16' to 'u32' to accommodate a sk that may have
a few large bpf_sk_storages.

The updated cb->min_dump_alloc will also be used to allocate the skb in
the next dump.  This logic already exists in netlink_dump().

Here is the sample output of a locally modified 'ss' and it could be made
more readable by using BTF later:
[root@arch-fb-vm1 ~]# ss --bpf-map-id 14 --bpf-map-id 13 -t6an 'dst [::1]:8989'
State Recv-Q Send-Q Local Address:Port  Peer Address:PortProcess
ESTAB 0      0              [::1]:51072        [::1]:8989
	 bpf_map_id:14 value:[ 3feb ]
	 bpf_map_id:13 value:[ 3f ]
ESTAB 0      0              [::1]:51070        [::1]:8989
	 bpf_map_id:14 value:[ 3feb ]
	 bpf_map_id:13 value:[ 3f ]

[root@arch-fb-vm1 ~]# ~/devshare/github/iproute2/misc/ss --bpf-maps -t6an 'dst [::1]:8989'
State         Recv-Q         Send-Q                   Local Address:Port                    Peer Address:Port         Process
ESTAB         0              0                                [::1]:51072                          [::1]:8989
	 bpf_map_id:14 value:[ 3feb ]
	 bpf_map_id:13 value:[ 3f ]
	 bpf_map_id:12 value:[ 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000... total:65407 ]
ESTAB         0              0                                [::1]:51070                          [::1]:8989
	 bpf_map_id:14 value:[ 3feb ]
	 bpf_map_id:13 value:[ 3f ]
	 bpf_map_id:12 value:[ 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000... total:65407 ]

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20200225230427.1976129-1-kafai@fb.com
2020-02-27 18:50:19 -08:00
..
2020-02-16 18:30:41 -08:00
2019-09-16 09:56:27 -07:00
2019-12-11 09:12:38 +01:00
2019-11-12 11:43:29 -05:00
2020-01-27 14:35:32 +01:00
2020-01-23 12:37:18 +00:00
2020-02-04 03:05:26 +00:00
2020-02-04 03:05:26 +00:00
2020-02-27 18:50:19 -08:00
2019-11-26 10:26:26 +01:00
2020-01-23 00:35:50 +01:00
2019-10-09 19:33:43 -07:00
2019-12-03 11:20:37 +01:00
2019-09-05 19:52:33 -06:00
2020-01-27 11:09:31 +01:00
2020-01-17 16:48:07 -08:00
2020-01-18 09:19:18 -05:00
2020-01-13 21:48:42 +01:00
2019-11-20 09:40:10 +01:00
2019-12-01 12:59:06 -08:00
2019-09-05 11:40:54 +02:00
2019-10-04 12:31:46 -07:00
2019-10-15 13:34:25 +02:00
2019-11-11 09:02:56 +01:00
2019-12-04 19:44:14 -08:00
2020-01-31 17:33:54 +00:00
2020-02-20 21:17:24 +01:00
2019-12-11 09:12:38 +01:00
2019-09-02 11:43:54 +01:00
2019-09-05 12:32:05 +02:00
2020-02-04 07:24:48 +00:00
2019-12-09 10:55:03 +01:00
2019-11-14 19:06:47 -08:00
2020-01-15 10:54:33 -05:00
2020-01-14 12:20:48 +01:00
2019-12-11 16:37:02 +08:00
2019-11-13 19:09:47 +08:00
2020-01-16 17:09:18 +01:00
2020-01-15 16:30:28 +00:00
2020-01-29 17:00:02 -06:00
2019-12-06 10:47:28 +01:00
2020-01-13 18:16:43 -08:00
2020-01-10 14:00:58 -08:00
2020-01-24 10:24:31 -08:00
2020-01-24 10:24:31 -08:00
2019-11-14 13:07:48 +08:00
2019-10-10 14:55:24 -07:00
2020-02-16 19:50:02 -08:00
2020-02-04 03:05:24 +00:00
2019-11-13 12:15:34 -08:00
2020-01-13 18:31:48 -08:00
2020-02-04 03:05:26 +00:00
2019-11-13 00:33:21 +11:00
2019-08-30 07:27:17 -07:00
2020-02-21 11:22:15 -08:00
2020-01-14 12:20:48 +01:00
2019-11-14 12:20:02 +08:00
2020-01-17 22:33:37 -05:00