net/smc: Introduce BPF injection capability
Subsystems (8)
D. Wythe
maintainercover net/smc: Introduce BPF injection capability
From: "D. Wythe" <[email protected]>
This PATCHes attempts to introduce BPF injection capability for SMC, and add selftest to ensure code stability.
As we all know that the SMC protocol is not suitable for all scenarios, especially for short-lived. However, for most applications, they cannot guarantee that there are no such scenarios at all. Therefore, apps may need some specific strategies to decide shall we need to use SMC or not, for example, apps can limit the scope of the SMC to a specific IP address or port.
Based on the consideration of transparent replacement, we hope that apps can remain transparent even if they need to formulate some specific strategies for SMC using. That is, do not need to recompile their code.
On the other hand, we need to ensure the scalability of strategies implementation. Although it is simple to use socket options or sysctl, it will bring more complexity to subsequent expansion.
Fortunately, BPF can solve these concerns very well, users can write thire own strategies in eBPF to choose whether to use SMC or not. And it's quite easy for them to modify their strategies in the future.
This PATCHes implement injection capability for SMC via struct_ops. In that way, we can add new injection scenarios in the future.
D. Wythe (2):
net/smc: Introduce BPF injection capability for SMC bpf/selftests: Test for SMC protocol negotiate
include/linux/btf_ids.h | 15 ++ include/net/smc.h | 254 ++++++++++++++++++ kernel/bpf/bpf_struct_ops_types.h | 4 + net/Makefile | 5 + net/smc/af_smc.c | 10 +- net/smc/bpf_smc_struct_ops.c | 146 +++++++++++ net/smc/smc.h | 220 ---------------- tools/testing/selftests/bpf/prog_tests/bpf_smc.c | 39 +++ tools/testing/selftests/bpf/progs/bpf_smc.c | 315 +++++++++++++++++++++++ 9 files changed, 787 insertions(+), 221 deletions(-) create mode 100644 net/smc/bpf_smc_struct_ops.c create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_smc.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_smc.c
Signature · 1 line
1.8.3.1
D. Wythe
maintainerPATCH 1/2 net/smc: Introduce BPF injection capability for SMC
From: "D. Wythe" <[email protected]>
This PATCH attempts to introduce BPF injection capability for SMC. As we all know that the SMC protocol is not suitable for all scenarios, especially for short-lived. However, for most applications, they cannot guarantee that there are no such scenarios at all. Therefore, apps may need some specific strategies to decide shall we need to use SMC or not, for example, apps can limit the scope of the SMC to a specific IP address or port.
Based on the consideration of transparent replacement, we hope that apps can remain transparent even if they need to formulate some specific strategies for SMC using. That is, do not need to recompile their code.
On the other hand, we need to ensure the scalability of strategies implementation. Although it is simple to use socket options or sysctl, it will bring more complexity to subsequent expansion.
Fortunately, BPF can solve these concerns very well, users can write thire own strategies in eBPF to choose whether to use SMC or not. And it's quite easy for them to modify their strategies in the future.
This PATCH implement injection capability for SMC via struct_ops. In that way, we can add new injection scenarios in the future.
--- include/linux/btf_ids.h | 15 +++ include/net/smc.h | 254 ++++++++++++++++++++++++++++++++++++++ kernel/bpf/bpf_struct_ops_types.h | 4 + net/Makefile | 5 + net/smc/af_smc.c | 10 +- net/smc/bpf_smc_struct_ops.c | 146 ++++++++++++++++++++++ net/smc/smc.h | 220 --------------------------------- 7 files changed, 433 insertions(+), 221 deletions(-) create mode 100644 net/smc/bpf_smc_struct_ops.c
include/linux/btf_ids.h +15 -0
@@ -264,6 +264,21 @@ enum { MAX_BTF_TRACING_TYPE, }; +#if IS_ENABLED (CONFIG_SMC ) +#define BTF_SMC_TYPE_xxx \ + BTF_SMC_TYPE(BTF_SMC_TYPE_SOCK, smc_sock) \ + BTF_SMC_TYPE(BTF_SMC_TYPE_CONNECTION, smc_connection) \ + BTF_SMC_TYPE(BTF_SMC_TYPE_HOST_CURSOR, smc_host_cursor) + +enum { +#define BTF_SMC_TYPE(name, type) name, +BTF_SMC_TYPE_xxx +#undef BTF_SMC_TYPE +MAX_BTF_SMC_TYPE , +}; +extern u32 btf_smc_ids[]; +#endif +extern u32 btf_tracing_ids[];extern u32 bpf_cgroup_btf_id[];extern u32 bpf_local_storage_map_btf_id[];
include/net/smc.h +254 -0
271 lines not on this page · raw message
kernel/bpf/bpf_struct_ops_types.h +4 -0
@@ -9,4 +9,8 @@#include <net/tcp.h> BPF_STRUCT_OPS_TYPE(tcp_congestion_ops)#endif +#if IS_ENABLED (CONFIG_SMC ) +#include <net/smc.h> +BPF_STRUCT_OPS_TYPE(smc_sock_negotiator_ops) +#endif #endif
net/Makefile +5 -0
@@ -52,6 +52,11 @@ obj-$(CONFIG_TIPC) += tipc/ obj-$(CONFIG_NETLABEL) += netlabel/ obj-$(CONFIG_IUCV) += iucv/ obj-$(CONFIG_SMC) += smc/ +ifneq ($(CONFIG_SMC),) +ifeq ($(CONFIG_BPF_SYSCALL),y) +obj-y += smc/bpf_smc_struct_ops.o +endif +endif obj-$(CONFIG_RFKILL) += rfkill/ obj-$(CONFIG_NET_9P) += 9p/ obj-$(CONFIG_CAIF) += caif/
net/smc/af_smc.c +9 -1
@@ -166,6 +166,9 @@ static bool smc_hs_congested(const struct sock *sk)if (workqueue_congested (WORK_CPU_UNBOUND , smc_hs_wq))return true; +if (!smc_sock_should_select_smc (smc)) +return true; +return false; }
@@ -320,6 +323,9 @@ static int smc_release(struct socket *sock)sock_hold (sk);/* sock_put below */ smc =smc_sk (sk); +/* trigger info gathering if needed.*/ +smc_sock_perform_collecting_info (smc,SMC_SOCK_CLOSED_TIMING ); + old_state = sk->sk_state;/* cleanup for a dangling non-blocking connect */
@@ -1627,7 +1633,9 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr, }smc_copy_sock_settings_to_clc (smc); -tcp_sk (smc->clcsock->sk)->syn_smc =1 ; +tcp_sk (smc->clcsock->sk)->syn_smc = (smc_sock_should_select_smc (smc) ==SK_PASS ) ? +1 :0 ; +if (smc->connect_nonblock) { rc = -EALREADY ; goto out;
net/smc/bpf_smc_struct_ops.c new file +146 -0
146 lines not on this page · raw message
net/smc/smc.h +0 -220
232 lines not on this page · raw message
Signature · 1 line
1.8.3.1
kernel test robot
build botRe: [PATCH bpf-next 1/2] net/smc: Introduce BPF injection capability for SMC
Thank you for the patch! Yet something to improve:
Hi Wythe,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/D-Wythe/net-smc-Introduce-BPF-injection-capability-for-SMC/20230221-155712 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/1676966191-47736-2-git-send-email-alibuda%40linux.alibaba.com patch subject: [PATCH bpf-next 1/2] net/smc: Introduce BPF injection capability for SMC config: i386-randconfig-a013-20230220 (https://download.01.org/0day-ci/archive/20230221/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/e2b31aece49068d7a07ca4bbd5fbdbd92f45a25e
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review D-Wythe/net-smc-Introduce-BPF-injection-capability-for-SMC/20230221-155712 git checkout e2b31aece49068d7a07ca4bbd5fbdbd92f45a25e
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash net/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> net/smc/bpf_smc_struct_ops.c:61:33: error: use of undeclared identifier 'BTF_SMC_TYPE_MAX'; did you mean 'BTF_SMC_TYPE_SOCK'?
BTF_ID_LIST_GLOBAL(btf_smc_ids, BTF_SMC_TYPE_MAX)
^~~~~~~~~~~~~~~~
BTF_SMC_TYPE_SOCK
include/linux/btf_ids.h:211:61: note: expanded from macro 'BTF_ID_LIST_GLOBAL'
#define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n];
^
include/linux/btf_ids.h:275:1: note: 'BTF_SMC_TYPE_SOCK' declared here
BTF_SMC_TYPE_xxx
^
include/linux/btf_ids.h:269:15: note: expanded from macro 'BTF_SMC_TYPE_xxx'
BTF_SMC_TYPE(BTF_SMC_TYPE_SOCK, smc_sock) \
^1 error generated.
vim +61 net/smc/bpf_smc_struct_ops.c
59
60 /* define global smc ID for smc_struct_ops */
> 61 BTF_ID_LIST_GLOBAL(btf_smc_ids, BTF_SMC_TYPE_MAX)
62 #define BTF_SMC_TYPE(name, type) BTF_ID(struct, type)
63 BTF_SMC_TYPE_xxx
64 #undef BTF_SMC_TYPE
65 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
D. Wythe
maintainerRe: [PATCH bpf-next 1/2] net/smc: Introduce BPF injection capability for SMC
Thanks! I will repost a fixed patch.
Quoted 56 lines · kernel test robot
Hi Wythe,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/D-Wythe/net-smc-Introduce-BPF-injection-capability-for-SMC/20230221-155712 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/1676966191-47736-2-git-send-email-alibuda%40linux.alibaba.com patch subject: [PATCH bpf-next 1/2] net/smc: Introduce BPF injection capability for SMC config: i386-randconfig-a013-20230220 (https://download.01.org/0day-ci/archive/20230221/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/e2b31aece49068d7a07ca4bbd5fbdbd92f45a25e
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review D-Wythe/net-smc-Introduce-BPF-injection-capability-for-SMC/20230221-155712 git checkoute2b31aece49068d7a07ca4bbd5fbdbd92f45a25e
# save the config file
mkdirbuild_dir&& cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bashnet/If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/All errors (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
net/smc/bpf_smc_struct_ops.c:61:33: error: use of undeclared identifier 'BTF_SMC_TYPE_MAX'; did you mean 'BTF_SMC_TYPE_SOCK'?BTF_ID_LIST_GLOBAL(btf_smc_ids, BTF_SMC_TYPE_MAX) ^~~~~~~~~~~~~~~~ BTF_SMC_TYPE_SOCK include/linux/btf_ids.h:211:61: note: expanded from macro 'BTF_ID_LIST_GLOBAL' #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n]; ^ include/linux/btf_ids.h:275:1: note: 'BTF_SMC_TYPE_SOCK' declared here BTF_SMC_TYPE_xxx ^ include/linux/btf_ids.h:269:15: note: expanded from macro 'BTF_SMC_TYPE_xxx' BTF_SMC_TYPE(BTF_SMC_TYPE_SOCK, smc_sock) \ ^ 1 error generated.vim +61
net/smc/bpf_smc_struct_ops.c59
60 /* define global smc ID forsmc_struct_ops*/Quoted 1 line
61
BTF_ID_LIST_GLOBAL(btf_smc_ids, BTF_SMC_TYPE_MAX)62 #define BTF_SMC_TYPE(name, type) BTF_ID(struct, type) 63 BTF_SMC_TYPE_xxx 64 #undef BTF_SMC_TYPE 65
kernel test robot
build botRe: [PATCH bpf-next 1/2] net/smc: Introduce BPF injection capability for SMC
In reply to D. WytheThank you for the patch! Yet something to improve:
Hi Wythe,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/D-Wythe/net-smc-Introduce-BPF-injection-capability-for-SMC/20230221-155712 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/1676966191-47736-2-git-send-email-alibuda%40linux.alibaba.com patch subject: [PATCH bpf-next 1/2] net/smc: Introduce BPF injection capability for SMC config: x86_64-randconfig-a004-20230220 (https://download.01.org/0day-ci/archive/20230221/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/e2b31aece49068d7a07ca4bbd5fbdbd92f45a25e git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review D-Wythe/net-smc-Introduce-BPF-injection-capability-for-SMC/20230221-155712 git checkout e2b31aece49068d7a07ca4bbd5fbdbd92f45a25e # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=x86_64 olddefconfig make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "smc_sock_perform_collecting_info" [net/smc/smc.ko] undefined! >> ERROR: modpost: "smc_sock_should_select_smc" [net/smc/smc.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
D. Wythe
maintainerPATCH 2/2 bpf/selftests: Test for SMC protocol negotiate
In reply to D. WytheFrom: "D. Wythe" <[email protected]>
This PATCH adds a tiny selftest for SMC bpf capability, making decisions on whether to use SMC by collecting certain information from kernel smc sock.
Follow the steps below to run this test.
make -C tools/testing/selftests/bpf
cd tools/testing/selftests/bpf
sudo ./test_progs -t bpf_smc
Results shows:
18 bpf_smc:OK
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
--- tools/testing/selftests/bpf/prog_tests/bpf_smc.c | 39 +++ tools/testing/selftests/bpf/progs/bpf_smc.c | 315 +++++++++++++++++++++++ 2 files changed, 354 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_smc.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_smc.c
tools/testing/selftests/bpf/prog_tests/bpf_smc.c new file +39 -0
@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2019 Facebook */ + +#include <linux/err.h> +#include <netinet/tcp.h> +#include <test_progs.h> +#include "bpf_smc.skel.h" + +void test_bpf_smc (void ) +{ +struct bpf_smc *smc_skel; +struct bpf_link *link; +int err; + + smc_skel =bpf_smc__open (); +if (!ASSERT_OK_PTR (smc_skel,"skel_open" )) +return ; + + err =bpf_map__set_type (smc_skel->maps.negotiator_map,BPF_MAP_TYPE_HASH ); +if (!ASSERT_OK (err,"bpf_map__set_type" )) + goto error; + + err =bpf_map__set_max_entries (smc_skel->maps.negotiator_map,1 ); +if (!ASSERT_OK (err,"bpf_map__set_type" )) + goto error; + + err =bpf_smc__load (smc_skel); +if (!ASSERT_OK (err,"skel_load" )) + goto error; + + link =bpf_map__attach_struct_ops (smc_skel->maps.ops); +if (!ASSERT_OK_PTR (link,"bpf_map__attach_struct_ops" )) + goto error; + +bpf_link__destroy (link); +error: +bpf_smc__destroy (smc_skel); +} +
tools/testing/selftests/bpf/progs/bpf_smc.c new file +315 -0
315 lines not on this page · raw message
Signature · 1 line
1.8.3.1