net/smc: Introduce smc_hs_ctrl
Subsystems (8)
D. Wythe
maintainerv4 cover net/smc: Introduce smc_hs_ctrl
This patch aims to introduce BPF injection capabilities for SMC and includes a self-test to ensure code stability.
Since the SMC protocol isn't ideal for every situation, especially short-lived ones, most applications can't guarantee the absence of such scenarios. Consequently, applications may need specific strategies to decide whether to use SMC. For example, an application might limit SMC usage to certain IP addresses or ports.
To maintain the principle of transparent replacement, we want applications to remain unaffected even if they need specific SMC strategies. In other words, they should not require recompilation of their code.
Additionally, we need to ensure the scalability of strategy implementation. While using socket options or sysctl might be straightforward, it could complicate future expansions.
Fortunately, BPF addresses these concerns effectively. Users can write their own strategies in eBPF to determine whether to use SMC, and they can easily modify those strategies in the future.
This is a rework of the series from [1]. Changes since [1] are limited to the SMC parts:
1. Rename smc_ops to smc_hs_ctrl and change interface name.
2. Squash SMC patches, removing standalone non-BPF hook capability.
3. Fix typos
[1]: https://lore.kernel.org/bpf/[email protected]/#t
v2 -> v1:
- Removed the fixes patch, which have already been merged on current branch.
- Fixed compilation warning of smc_call_hsbpf() when CONFIG_SMC_HS_CTRL_BPF is not enabled.
- Changed the default value of CONFIG_SMC_HS_CTRL_BPF to Y.
- Fix typo and renamed some variables
v3 -> v2:
- Removed the libbpf patch, which have already been merged on current branch.
- Fixed sparse warning of smc_call_hsbpf() and xchg().
v4 -> v3:
- Rebased on latest bpf-next, updated SMC loopback config from SMC_LO to DIBS_LO per upstream changes.
D. Wythe (3):
bpf: export necessary symbols for modules with struct_ops net/smc: bpf: Introduce generic hook for handshake flow bpf/selftests: add selftest for bpf_smc_hs_ctrl
include/net/netns/smc.h | 3 + include/net/smc.h | 53 +++ kernel/bpf/bpf_struct_ops.c | 2 + kernel/bpf/syscall.c | 1 + net/ipv4/tcp_output.c | 36 +- net/smc/Kconfig | 10 + net/smc/Makefile | 1 + net/smc/af_smc.c | 9 + net/smc/smc_hs_bpf.c | 137 ++++++ net/smc/smc_hs_bpf.h | 31 ++ net/smc/smc_sysctl.c | 91 ++++ tools/testing/selftests/bpf/config | 5 + .../selftests/bpf/prog_tests/test_bpf_smc.c | 396 ++++++++++++++++++ tools/testing/selftests/bpf/progs/bpf_smc.c | 117 ++++++ 14 files changed, 878 insertions(+), 14 deletions(-) create mode 100644 net/smc/smc_hs_bpf.c create mode 100644 net/smc/smc_hs_bpf.h create mode 100644 tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_smc.c
Signature · 1 line
2.45.0
D. Wythe
maintainerPATCH v4 1/3 bpf: export necessary symbols for modules with struct_ops
Exports three necessary symbols for implementing struct_ops with tristate subsystem.
To hold or release refcnt of struct_ops refcnt by inline funcs bpf_try_module_get and bpf_module_put which use bpf_struct_ops_get(put) conditionally.
And to copy obj name from one to the other with effective checks by bpf_obj_name_cpy.
--- kernel/bpf/bpf_struct_ops.c | 2 ++ kernel/bpf/syscall.c | 1 + 2 files changed, 3 insertions(+)
kernel/bpf/bpf_struct_ops.c +2 -0
@@ -1162,6 +1162,7 @@ bool bpf_struct_ops_get(const void *kdata) map =__bpf_map_inc_not_zero (&st_map->map, false);return !IS_ERR (map); } +EXPORT_SYMBOL_GPL (bpf_struct_ops_get);void bpf_struct_ops_put (const void *kdata) {
@@ -1173,6 +1174,7 @@ void bpf_struct_ops_put(const void *kdata)bpf_map_put (&st_map->map); } +EXPORT_SYMBOL_GPL (bpf_struct_ops_put);u32 bpf_struct_ops_id (const void *kdata) {
kernel/bpf/syscall.c +1 -0
@@ -1234,6 +1234,7 @@ int bpf_obj_name_cpy(char *dst, const char *src, unsigned int size)return src - orig_src; } +EXPORT_SYMBOL_GPL (bpf_obj_name_cpy); int map_check_no_btf(const struct bpf_map *map, const struct btf *btf,
Signature · 1 line
2.45.0
D. Wythe
maintainerPATCH v4 2/3 net/smc: bpf: Introduce generic hook for handshake flow
In reply to D. WytheThe introduction of IPPROTO_SMC enables eBPF programs to determine whether to use SMC based on the context of socket creation, such as network namespaces, PID and comm name, etc.
As a subsequent enhancement, to introduce a new generic hook that allows decisions on whether to use SMC or not at runtime, including but not limited to local/remote IP address or ports.
User can write their own implememtion via bpf_struct_ops now to choose whether to use SMC or not before TCP 3rd handshake to be comleted.
--- include/net/netns/smc.h | 3 + include/net/smc.h | 53 ++++++++++++++++ net/ipv4/tcp_output.c | 36 +++++++---- net/smc/Kconfig | 10 +++ net/smc/Makefile | 1 + net/smc/af_smc.c | 9 +++ net/smc/smc_hs_bpf.c | 137 ++++++++++++++++++++++++++++++++++++++++ net/smc/smc_hs_bpf.h | 31 +++++++++ net/smc/smc_sysctl.c | 91 ++++++++++++++++++++++++++ 9 files changed, 357 insertions(+), 14 deletions(-) create mode 100644 net/smc/smc_hs_bpf.c create mode 100644 net/smc/smc_hs_bpf.h
include/net/netns/smc.h +3 -0
@@ -17,6 +17,9 @@ struct netns_smc {#ifdef CONFIG_SYSCTL struct ctl_table_header *smc_hdr;#endif +#if IS_ENABLED (CONFIG_SMC_HS_CTRL_BPF ) +struct smc_hs_ctrl __rcu *hs_ctrl; +#endif /* CONFIG_SMC_HS_CTRL_BPF */ unsigned int sysctl_autocorking_size;unsigned int sysctl_smcr_buf_type;int sysctl_smcr_testlink_time;
include/net/smc.h +53 -0
63 lines not on this page · raw message
net/ipv4/tcp_output.c +22 -14
@@ -40,6 +40,7 @@#include <net/tcp.h> #include <net/tcp_ecn.h> #include <net/mptcp.h> +#include <net/smc.h> #include <net/proto_memory.h> #include <net/psp.h>
@@ -802,34 +803,41 @@ static void tcp_options_write(struct tcphdr *th, struct tcp_sock *tp,mptcp_options_write (th, ptr, tp, opts); } -static void smc_set_option (const struct tcp_sock *tp, +static void smc_set_option (struct tcp_sock *tp,struct tcp_out_options *opts,unsigned int *remaining) {#if IS_ENABLED (CONFIG_SMC ) -if (static_branch_unlikely (&tcp_have_smc)) { -if (tp->syn_smc) { -if (*remaining >=TCPOLEN_EXP_SMC_BASE_ALIGNED ) { - opts->options |=OPTION_SMC ; - *remaining -=TCPOLEN_EXP_SMC_BASE_ALIGNED ; - } +struct sock *sk = &tp->inet_conn.icsk_inet.sk; + +if (static_branch_unlikely (&tcp_have_smc) && tp->syn_smc) { + tp->syn_smc = !!smc_call_hsbpf (1 , sk, syn_option, tp); +/* re-check syn_smc */ +if (tp->syn_smc && + *remaining >=TCPOLEN_EXP_SMC_BASE_ALIGNED ) { + opts->options |=OPTION_SMC ; + *remaining -=TCPOLEN_EXP_SMC_BASE_ALIGNED ; } }#endif }static void smc_set_option_cond (const struct tcp_sock *tp, -const struct inet_request_sock *ireq, +struct inet_request_sock *ireq,struct tcp_out_options *opts,unsigned int *remaining) {#if IS_ENABLED (CONFIG_SMC ) -if (static_branch_unlikely (&tcp_have_smc)) { -if (tp->syn_smc && ireq->smc_ok) { -if (*remaining >=TCPOLEN_EXP_SMC_BASE_ALIGNED ) { - opts->options |=OPTION_SMC ; - *remaining -=TCPOLEN_EXP_SMC_BASE_ALIGNED ; - } +const struct sock *sk = &tp->inet_conn.icsk_inet.sk; + +if (static_branch_unlikely (&tcp_have_smc) && tp->syn_smc && ireq->smc_ok) { + ireq->smc_ok = !!smc_call_hsbpf (1 , sk, synack_option, + tp, ireq); +/* re-check smc_ok */ +if (ireq->smc_ok && + *remaining >=TCPOLEN_EXP_SMC_BASE_ALIGNED ) { + opts->options |=OPTION_SMC ; + *remaining -=TCPOLEN_EXP_SMC_BASE_ALIGNED ; } }#endif
net/smc/Kconfig +10 -0
@@ -19,3 +19,13 @@ config SMC_DIAG smcss. if unsure, say Y. + +config SMC_HS_CTRL_BPF + bool "Generic eBPF hook for SMC handshake flow" + depends on SMC && BPF_SYSCALL + default y + help + SMC_HS_CTRL_BPF enables support to register generic eBPF hook for SMC + handshake flow, which offer much greater flexibility in modifying the behavior + of the SMC protocol stack compared to a complete kernel-based approach. Select + this option if you want filtring the handshake process via eBPF programs.
net/smc/Makefile +1 -0
@@ -6,3 +6,4 @@ smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o smc_llc.o smc-y += smc_cdc.o smc_tx.o smc_rx.o smc_close.o smc_ism.o smc_netlink.o smc_stats.o smc-y += smc_tracepoint.o smc_inet.o smc-$(CONFIG_SYSCTL) += smc_sysctl.o +smc-$(CONFIG_SMC_HS_CTRL_BPF) += smc_hs_bpf.o
net/smc/af_smc.c +9 -0
@@ -58,6 +58,7 @@#include "smc_tracepoint.h" #include "smc_sysctl.h" #include "smc_inet.h" +#include "smc_hs_bpf.h" static DEFINE_MUTEX (smc_server_lgr_pending);/* serialize link group * creation on server
@@ -3600,8 +3601,16 @@ static int __init smc_init(void)pr_err ("%s: smc_inet_init fails with %d\n" , __func__, rc); goto out_ulp; } + rc =bpf_smc_hs_ctrl_init (); +if (rc) { +pr_err ("%s: bpf_smc_hs_ctrl_init fails with %d\n" , __func__, + rc); + goto out_inet; + }static_branch_enable (&tcp_have_smc);return 0 ; +out_inet: +smc_inet_exit (); out_ulp:tcp_unregister_ulp (&smc_ulp_ops); out_ib:
net/smc/smc_hs_bpf.c new file +137 -0
137 lines not on this page · raw message
net/smc/smc_hs_bpf.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Shared Memory Communications over RDMA (SMC-R) and RoCE +* +* Generic hook for SMC handshake flow. +* +* Copyright IBM Corp. 2016 +* Copyright (c) 2025, Alibaba Inc. +* +* Author: D. Wythe <[email protected]> +*/ + +#ifndef __SMC_HS_CTRL +#define __SMC_HS_CTRL + +#include <net/smc.h> + +/* Find hs_ctrl by the target name, which required to be a c-string. +* Return NULL if no such ctrl was found,otherwise, return a valid ctrl. +* +* Note: Caller MUST ensure it's was invoked under rcu_read_lock. +*/ +struct smc_hs_ctrl *smc_hs_ctrl_find_by_name (const char *name); + +#if IS_ENABLED (CONFIG_SMC_HS_CTRL_BPF ) +int bpf_smc_hs_ctrl_init (void ); +#else +static inline int bpf_smc_hs_ctrl_init (void ) {return 0 ; } +#endif /* CONFIG_SMC_HS_CTRL_BPF */ + +#endif /* __SMC_HS_CTRL */
net/smc/smc_sysctl.c +91 -0
133 lines not on this page · raw message
Signature · 1 line
2.45.0
D. Wythe
maintainerPATCH v4 3/3 bpf/selftests: add selftest for bpf_smc_hs_ctrl
In reply to D. WytheThis tests introduces a tiny smc_hs_ctrl for filtering SMC connections based on IP pairs, and also adds a realistic topology model to verify it.
Also, we can only use SMC loopback under CI test, so an additional configuration needs to be enabled.
Follow the steps below to run this test.
make -C tools/testing/selftests/bpf
cd tools/testing/selftests/bpf
sudo ./test_progs -t smc
Results shows:
Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED
--- tools/testing/selftests/bpf/config | 5 + .../selftests/bpf/prog_tests/test_bpf_smc.c | 396 ++++++++++++++++++ tools/testing/selftests/bpf/progs/bpf_smc.c | 117 ++++++ 3 files changed, 518 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_smc.c
tools/testing/selftests/bpf/config +5 -0
@@ -123,3 +123,8 @@ CONFIG_XDP_SOCKETS=y CONFIG_XFRM_INTERFACE=y CONFIG_TCP_CONG_DCTCP=y CONFIG_TCP_CONG_BBR=y +CONFIG_INFINIBAND=y +CONFIG_SMC=y +CONFIG_SMC_HS_CTRL_BPF=y +CONFIG_DIBS=y +CONFIG_DIBS_LO=y
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c new file +396 -0
396 lines not on this page · raw message
tools/testing/selftests/bpf/progs/bpf_smc.c new file +117 -0
117 lines not on this page · raw message
Signature · 1 line
2.45.0
[email protected]
AI reviewRe: [PATCH bpf-next v4 2/3] net/smc: bpf: Introduce generic hook for handshake flow
In reply to D. WytheAI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
``` commit b661eee197ec1c841de9195f171863daef37de34 Author: D. Wythe <[email protected]> net/smc: bpf: Introduce generic hook for handshake flow This patch introduces a BPF struct_ops mechanism that allows eBPF programs to control SMC protocol handshake decisions at runtime based on connection properties like IP addresses and ports. > diff --git a/net/smc/smc_sysctl.c b/net/smc/smc_sysctl.c > index 2fab6456f..918516734 100644 > --- a/net/smc/smc_sysctl.c > +++ b/net/smc/smc_sysctl.c [ ... ] > +#if IS_ENABLED(CONFIG_SMC_HS_CTRL_BPF) > +static int smc_net_replace_smc_hs_ctrl(struct net *net, const char *name) > +{ > + struct smc_hs_ctrl *ctrl = NULL; > + > + rcu_read_lock(); > + /* null or empty name ask to clear current ctrl */ > + if (name && name[0]) { > + ctrl = smc_hs_ctrl_find_by_name(name); > + if (!ctrl) { > + rcu_read_unlock(); > + return -EINVAL; > + } > + /* no change, just return */ > + if (ctrl == rcu_dereference(net->smc.hs_ctrl)) { > + rcu_read_unlock(); > + return 0; > + } > + if (!bpf_try_module_get(ctrl, ctrl->owner)) { > + rcu_read_unlock(); > + return -EBUSY; > + } > + } > + /* xhcg old ctrl with the new one atomically */ > + ctrl = unrcu_pointer(xchg(&net->smc.hs_ctrl, RCU_INITIALIZER(ctrl))); > + /* release old ctrl */ > + if (ctrl) > + bpf_module_put(ctrl, ctrl->owner); > + > + rcu_read_unlock(); > + return 0; > +} Can concurrent sysctl writes race in smc_net_replace_smc_hs_ctrl? If two threads both write the same ctrl name to the hs_ctrl sysctl: Thread A: finds ctrl, bpf_try_module_get(ctrl) succeeds (refcount++) Thread B: finds ctrl, bpf_try_module_get(ctrl) succeeds (refcount++) Thread A: xchg(&net->smc.hs_ctrl, ctrl) returns old_ctrl Thread B: xchg(&net->smc.hs_ctrl, ctrl) returns ctrl (from Thread A) Thread A: bpf_module_put(old_ctrl) Thread B: bpf_module_put(ctrl) <- drops ref on ctrl still in use This leaves ctrl with one less reference than needed while it's assigned to net->smc.hs_ctrl, and old_ctrl leaks a reference. The xchg is atomic but the overall get-xchg-put sequence is not. Would a mutex around the entire operation resolve this? > + > +static int proc_smc_hs_ctrl(const struct ctl_table *ctl, int write, > + void *buffer, size_t *lenp, loff_t *ppos) > +{ > + struct net *net = container_of(ctl->data, struct net, smc.hs_ctrl); > + char val[SMC_HS_CTRL_NAME_MAX]; > + const struct ctl_table tbl = { > + .data = val, > + .maxlen = SMC_HS_CTRL_NAME_MAX, > + }; > + struct smc_hs_ctrl *ctrl; > + int ret; > + > + rcu_read_lock(); > + ctrl = rcu_dereference(net->smc.hs_ctrl); > + if (ctrl) > + memcpy(val, ctrl->name, sizeof(ctrl->name)); > + else > + val[0] = '\0'; > + rcu_read_unlock(); > + > + ret = proc_dostring(&tbl, write, buffer, lenp, ppos); > + if (ret) > + return ret; > + > + if (write) > + ret = smc_net_replace_smc_hs_ctrl(net, val); > + return ret; > +} [ ... ] ```
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
In-Reply-To-Subject: net/smc: bpf: Introduce generic hook for handshake flow CI run summary: https://github.com/kernel-patches/bpf/actions/runs/19027307093
D. Wythe
maintainerRe: [PATCH bpf-next v4 2/3] net/smc: bpf: Introduce generic hook for handshake flow
Quoted 61 lines · On Mon, Nov 03, 2025 at 07:55:35AM +0000, [email protected] wrote:
```
commitb661eee197ec1c841de9195f171863daef37de34
Author: D. Wythe <[email protected]>net/smc: bpf: Introduce generic hook for handshake flow
This patch introduces a BPF
struct_opsmechanism that allows eBPF programs to control SMC protocol handshake decisions at runtime based on connection properties like IP addresses and ports.Quoted 4 lines
net/smc/smc_sysctl.c +0
-0[ ... ]
Quoted 22 lines
net/smc/smc_sysctl.c +22
-0+#if IS_ENABLED (CONFIG_SMC_HS_CTRL_BPF ) +static int smc_net_replace_smc_hs_ctrl (struct net *net,const char *name) +{ +struct smc_hs_ctrl *ctrl =NULL ; + +rcu_read_lock (); +/* null or empty name ask to clear current ctrl */ +if (name && name[0 ]) { + ctrl =smc_hs_ctrl_find_by_name (name); +if (!ctrl) { +rcu_read_unlock (); +return -EINVAL ; + } +/* no change, just return */ +if (ctrl ==rcu_dereference (net->smc.hs_ctrl)) { +rcu_read_unlock (); +return 0 ; + } +if (!bpf_try_module_get (ctrl, ctrl->owner)) { +rcu_read_unlock (); +return -EBUSY ; + }net/smc/smc_sysctl.c static int links_per_lgr_max = SMC_LINKS_ADD_LNK_MAX; · line 66
Quoted 10 lines
net/smc/smc_sysctl.c +10
-0+ } +/* xhcg old ctrl with the new one atomically */ + ctrl =unrcu_pointer (xchg (&net->smc.hs_ctrl,RCU_INITIALIZER (ctrl))); +/* release old ctrl */ +if (ctrl) +bpf_module_put (ctrl, ctrl->owner); + +rcu_read_unlock (); +return 0 ; +}Can concurrent sysctl writes race in
smc_net_replace_smc_hs_ctrl? If two threads both write the same ctrl name to thehs_ctrlsysctl:Thread A: finds ctrl,
bpf_try_module_get(ctrl)succeeds (refcount++) Thread B: finds ctrl,bpf_try_module_get(ctrl)succeeds (refcount++) Thread A:xchg(&net->smc.hs_ctrl, ctrl)returnsold_ctrlThread B:xchg(&net->smc.hs_ctrl, ctrl)returns ctrl (from Thread A) Thread A:bpf_module_put(old_ctrl)
Thread B:bpf_module_put(ctrl)<- drops ref on ctrl still in use
Quoted 5 lines
This leaves ctrl with one less reference than needed while it's assigned to
net->smc.hs_ctrl, andold_ctrlleaks a reference. The xchg is atomic but the overall get-xchg-put sequence is not. Would a mutex around the entire operation resolve this?
Hi claude,
I don't think this is a problem:
1. The first thread sets hs_ctrl = ctrl and keeps its reference.
2. The second thread sees hs_ctrl is already ctrl, so its xchg returns ctrl, and it drops its own redundant reference.
3. The final state is hs_ctrl = ctrl with refcount=1, which is correct.
In all cases:
- The reference held by hs_ctrl is the one acquired by the last writer.
- Other writers only drop their own temporary references.
D. Wythe
Martin KaFai Lau
reviewerRe: [PATCH bpf-next v4 2/3] net/smc: bpf: Introduce generic hook for handshake flow
In reply to D. Wytheinclude/net/smc.h struct smcd_dev { · line 96
Quoted 6 lines · D. Wythe
include/net/smc.h +6
-0+#if IS_ENABLED (CONFIG_SMC_HS_CTRL_BPF ) +#define smc_call_hsbpf (init_val, sk, func, ...) ({ \ + typeof(init_val) __ret = (init_val); \ + struct smc_hs_ctrl *ctrl; \ + rcu_read_lock(); \ + ctrl = rcu_dereference(sock_net(sk)->smc.hs_ctrl); \
The smc_hs_ctrl (and its ops) is called from the netns, so the bpf_struct_ops is attached to a netns. Attaching bpf_struct_ops to a netns has not been done before. More on this later.
Quoted 29 lines
include/net/smc.h +9
-0+if (ctrl && ctrl->func) \ + __ret = ctrl->func (__VA_ARGS__); \ +rcu_read_unlock (); \ + __ret; \ +}) +#else +#define smc_call_hsbpf (init_val, sk, ...) ({ (void)(sk); (init_val); }) +#endif /* CONFIG_SMC_HS_CTRL_BPF */ +#endif /* _SMC_H */ net/ipv4/tcp_output.c +2
-1@@ -40,6 +40,7 @@#include <net/tcp.h> #include <net/tcp_ecn.h> #include <net/mptcp.h> +#include <net/smc.h> #include <net/proto_memory.h> #include <net/psp.h> @@ -802,34 +803,41 @@ static void tcp_options_write(struct tcphdr *th, struct tcp_sock *tp,mptcp_options_write (th, ptr, tp, opts); } -static void smc_set_option(const struct tcp_sock *tp, +static void smc_set_option(struct tcp_sock *tp, struct tcp_out_options *opts,
net/ipv4/tcp_output.c static void tcp_options_write(struct tcphdr *th, struct tcp_sock *tp, · line 811
Quoted 10 lines
net/ipv4/tcp_output.c +1
-6unsigned int *remaining) {#if IS_ENABLED (CONFIG_SMC ) -if (static_branch_unlikely (&tcp_have_smc)) { -if (tp->syn_smc) { -if (*remaining >=TCPOLEN_EXP_SMC_BASE_ALIGNED ) { - opts->options |=OPTION_SMC ; - *remaining -=TCPOLEN_EXP_SMC_BASE_ALIGNED ; - } +struct sock *sk = &tp->inet_conn.icsk_inet.sk;
the sk is tp ...
net/ipv4/tcp_output.c static void tcp_options_write(struct tcphdr *th, struct tcp_sock *tp, · line 814
Quoted 3 lines
net/ipv4/tcp_output.c +3
-0+ +if (static_branch_unlikely (&tcp_have_smc) && tp->syn_smc) { + tp->syn_smc = !!smc_call_hsbpf (1 , sk, syn_option, tp);
... so just pass tp instead of passing both sk and tp?
[ ... ]
net/ipv4/tcp_output.c static void tcp_options_write(struct tcphdr *th, struct tcp_sock *tp, · line 817
Quoted 3 lines
net/ipv4/tcp_output.c +3
-0+static int smc_bpf_hs_ctrl_init (struct btf *btf) {return 0 ; } + +static int smc_bpf_hs_ctrl_reg (void *kdata,struct bpf_link *link)
More on attaching to netns. There is discussion on how to attach a bpf_struct_ops to a particular cgroup in a link. I think the link should be able to attach a bpf_struct_ops to a particular netns also.
I would suggest to reject link now. Later, link support can be added to attach to a particular netns. This will be the last non-link-only bpf_struct_ops addition, considering the blast radius is limited on smc_hs_ctrl and the smc effort was started a while ago. I could have missed things here. Other experts could chime in.
if (link) return -EOPNOTSUPP;
pw-bot: cr
Quoted 9 lines
net/ipv4/tcp_output.c +9
-0+{ +return smc_hs_ctrl_reg (kdata); +} + +static void smc_bpf_hs_ctrl_unreg (void *kdata,struct bpf_link *link) +{ +smc_hs_ctrl_unreg (kdata); +} +
Martin KaFai Lau
reviewerRe: [PATCH bpf-next v4 3/3] bpf/selftests: add selftest for bpf_smc_hs_ctrl
In reply to D. Wythetools/testing/selftests/bpf/prog_tests/test_bpf_smc.c line 233
Quoted 7 lines · D. Wythe
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c new file +7
-0+static bool setup_netns(void) +{ + test_netns = netns_new(TEST_NS, true); + if (!ASSERT_OK_PTR(test_netns, "open net namespace")) + goto fail_netns; + + if (!ASSERT_OK(system("ip addr add 127.0.1.0/8 dev lo"),
SYS(fail_ip, "ip addr add ...")
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c line 237
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c new file +4
-0+ "add server node")) + goto fail_ip; + + if (!ASSERT_OK(system("ip addr add 127.0.2.0/8 dev lo"),
same here.
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c new file +4
-0+ "server via risk path")) + goto fail_ip; + +return true;
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c line 251
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c new file +10
-0+fail_ip: +netns_free (test_netns); +fail_netns: +return false; +} + +static void cleanup_netns (void ) +{ +netns_free (test_netns); +remove_netns (TEST_NS );
remove_netns should not be needed. netns_free() should have removed it.
[ ... ]
Quoted 12 lines
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c new file +12
-0+static void test_topo (void ) +{ +struct bpf_smc *skel; +int rc, map_fd; + + skel =bpf_smc__open_and_load (); +if (!ASSERT_OK_PTR (skel,"bpf_smc__open_and_load" )) +return ; + + rc =bpf_smc__attach (skel); +if (!ASSERT_OK (rc,"bpf_smc__attach" )) + goto fail;
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c line 353
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c new file +10
-0+ + map_fd =bpf_map__fd (skel->maps.smc_policy_ip); +if (!ASSERT_OK_FD (map_fd,"bpf_map__fd" )) + goto fail; + +/* Mock the process of transparent replacement, since we will modify +* protocol to ipproto_smc accropding to it via +* fmod_ret/update_socket_protocol. +*/ +system ("sysctl -w net.smc.hs_ctrl=linkcheck" );
The "sysctl -w" will echo useless output to test_progs. just use write_sysctl().
D. Wythe
maintainerRe: [PATCH bpf-next v4 2/3] net/smc: bpf: Introduce generic hook for handshake flow
In reply to Martin KaFai LauQuoted 22 lines · Martin KaFai Lau
include/net/smc.h struct smcd_dev { · line 96
Quoted 6 lines · D. Wythe
include/net/smc.h +6
-0+#if IS_ENABLED (CONFIG_SMC_HS_CTRL_BPF ) +#define smc_call_hsbpf (init_val, sk, func, ...) ({ \ + typeof(init_val) __ret = (init_val); \ + struct smc_hs_ctrl *ctrl; \ + rcu_read_lock(); \ + ctrl = rcu_dereference(sock_net(sk)->smc.hs_ctrl); \The
smc_hs_ctrl(and its ops) is called from the netns, so thebpf_struct_opsis attached to a netns. Attachingbpf_struct_opsto a netns has not been done before. More on this later.include/net/smc.h struct smcd_dev {
Quoted 5 lines
include/net/smc.h +5
-0+if (ctrl && ctrl->func) \ + __ret = ctrl->func (__VA_ARGS__); \ + +if (static_branch_unlikely (&tcp_have_smc) && tp->syn_smc) { + tp->syn_smc = !!smc_call_hsbpf (1 , sk, syn_option, tp);... so just pass tp instead of passing both sk and tp?
Quoted 2 lines
[ ... ]
You're right, it is a bit redundant. However, if we merge the parameters, every user of this macro will be forced to pass tp. In fact, we’re already considering adding some callback functions that don’t take tp as a parameter.
I’ve been considering this: since smc_hs_ctrl is called from the netns, maybe we should replace the sk parameter with netns directly. After all, the only reason we pass sk here is to extract sock_net(sk). Doing so would remove the redundancy and also keep the interface more flexible for future extensions. What do you think?
Quoted 9 lines
net/smc/smc_hs_bpf.c line 72
Quoted 3 lines
net/smc/smc_hs_bpf.c new file +3
-0+static int smc_bpf_hs_ctrl_init (struct btf *btf) {return 0 ; } + +static int smc_bpf_hs_ctrl_reg (void *kdata,struct bpf_link *link)More on attaching to netns. There is discussion on how to attach a
bpf_struct_opsto a particular cgroup in a link. I think the link should be able to attach abpf_struct_opsto a particular netns also.
Quoted 8 lines
I would suggest to reject link now. Later, link support can be added to attach to a particular netns. This will be the last non-link-only
bpf_struct_opsaddition, considering the blast radius is limited onsmc_hs_ctrland the smc effort was started a while ago. I could have missed things here. Other experts could chime in.if (link) return -EOPNOTSUPP;
Got it. This approach looks good to me. I’ll send out the next version with this change.
D. Wythe
maintainerRe: [PATCH bpf-next v4 3/3] bpf/selftests: add selftest for bpf_smc_hs_ctrl
In reply to Martin KaFai LauQuoted 10 lines · Martin KaFai Lau
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c line 233
Quoted 7 lines · D. Wythe
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c new file +7
-0+static bool setup_netns(void) +{ + test_netns = netns_new(TEST_NS, true); + if (!ASSERT_OK_PTR(test_netns, "open net namespace")) + goto fail_netns; + + if (!ASSERT_OK(system("ip addr add 127.0.1.0/8 dev lo"),
SYS(fail_ip, "ip addr add ...")
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c line 237
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c new file +4
-0+ "add server node")) + goto fail_ip; + + if (!ASSERT_OK(system("ip addr add 127.0.2.0/8 dev lo"),same here.
Take it.
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c new file +8
-0+ "server via risk path")) + goto fail_ip; + +return true; +fail_ip: +netns_free (test_netns); +fail_netns: +return false;
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c line 251
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c new file +6
-0+} + +static void cleanup_netns (void ) +{ +netns_free (test_netns); +remove_netns (TEST_NS );
remove_netnsshould not be needed.netns_free()should have removed it.
Take it.
Quoted 8 lines
[ ... ]
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c line 353
Quoted 1 line
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c new file +1
-0+system ("sysctl -w net.smc.hs_ctrl=linkcheck" );The "sysctl -w" will echo useless output to
test_progs. just usewrite_sysctl().
Take it.
Thanks for the review, I'll address these points in the next version.
Best wishes,
D. Wythe
Martin KaFai Lau
reviewerRe: [PATCH bpf-next v4 2/3] net/smc: bpf: Introduce generic hook for handshake flow
In reply to D. WytheQuoted 23 lines · D. Wythe
Quoted 22 lines · Martin KaFai Lau
include/net/smc.h struct smcd_dev { · line 96
Quoted 6 lines · D. Wythe
include/net/smc.h +6
-0+#if IS_ENABLED (CONFIG_SMC_HS_CTRL_BPF ) +#define smc_call_hsbpf (init_val, sk, func, ...) ({ \ + typeof(init_val) __ret = (init_val); \ + struct smc_hs_ctrl *ctrl; \ + rcu_read_lock(); \ + ctrl = rcu_dereference(sock_net(sk)->smc.hs_ctrl); \The
smc_hs_ctrl(and its ops) is called from the netns, so thebpf_struct_opsis attached to a netns. Attachingbpf_struct_opsto a netns has not been done before. More on this later.include/net/smc.h struct smcd_dev {
Quoted 5 lines
include/net/smc.h +5
-0+if (ctrl && ctrl->func) \ + __ret = ctrl->func (__VA_ARGS__); \ + +if (static_branch_unlikely (&tcp_have_smc) && tp->syn_smc) { + tp->syn_smc = !!smc_call_hsbpf (1 , sk, syn_option, tp);... so just pass tp instead of passing both sk and tp?
Quoted 7 lines
Quoted 2 lines
[ ... ]
You're right, it is a bit redundant. However, if we merge the parameters, every user of this macro will be forced to pass tp. In fact, we’re already considering adding some callback functions that don’t take tp as a parameter.
If the struct_ops callback does not take tp, then don't pass it to the callback. I have a hard time to imagine why the bpf prog will not be interested in the tp/sk pointer though.
or you meant the caller does not have tp? and where is the future caller?
Quoted 6 lines
I’ve been considering this: since
smc_hs_ctrlis called from the netns, maybe we should replace the sk parameter with netns directly. After all, the only reason we pass sk here is to extractsock_net(sk). Doing so would remove the redundancy and also keep the interface more flexible for future extensions. What do you think?
The net can be obtained from the tp also.
Like in this patch, all the caller needs to type
"const struct sock *sk = &tp->inet_conn.icsk_inet.sk;". I can imagine all the callers will have to type "sock_net((struct sock *)tp)" if passing net. Why not just do that in the smc_hs_ctrl instead of asking all the callers to type that?
I meant something like this (untested):
-#define smc_call_hsbpf(init_val, sk, func, ...) ({ \
+#define smc_call_hsbpf(init_val, func, tp, ...) ({ \
typeof(init_val) __ret = (init_val); \
struct smc_hs_ctrl *ctrl; \
rcu_read_lock(); \
- ctrl = rcu_dereference(sock_net(sk)->smc.hs_ctrl); \
+ ctrl = rcu_dereference(sock_net((struct sock *)(tp))->smc.hs_ctrl); \
if (ctrl && ctrl->func) \
- __ret = ctrl->func(__VA_ARGS__); \
+ __ret = ctrl->func(tp, ##__VA_ARGS__); \
rcu_read_unlock(); \
__ret; \})
D. Wythe
maintainerRe: [PATCH bpf-next v4 2/3] net/smc: bpf: Introduce generic hook for handshake flow
Quoted 34 lines · Martin KaFai Lau
Quoted 23 lines · D. Wythe
Quoted 22 lines · Martin KaFai Lau
include/net/smc.h struct smcd_dev { · line 96
Quoted 6 lines · D. Wythe
include/net/smc.h +6
-0+#if IS_ENABLED (CONFIG_SMC_HS_CTRL_BPF ) +#define smc_call_hsbpf (init_val, sk, func, ...) ({ \ + typeof(init_val) __ret = (init_val); \ + struct smc_hs_ctrl *ctrl; \ + rcu_read_lock(); \ + ctrl = rcu_dereference(sock_net(sk)->smc.hs_ctrl); \The
smc_hs_ctrl(and its ops) is called from the netns, so thebpf_struct_opsis attached to a netns. Attachingbpf_struct_opsto a netns has not been done before. More on this later.include/net/smc.h struct smcd_dev {
Quoted 5 lines
include/net/smc.h +5
-0+if (ctrl && ctrl->func) \ + __ret = ctrl->func (__VA_ARGS__); \ + +if (static_branch_unlikely (&tcp_have_smc) && tp->syn_smc) { + tp->syn_smc = !!smc_call_hsbpf (1 , sk, syn_option, tp);... so just pass tp instead of passing both sk and tp?
Quoted 7 lines
Quoted 2 lines
[ ... ]
You're right, it is a bit redundant. However, if we merge the parameters, every user of this macro will be forced to pass tp. In fact, we’re already considering adding some callback functions that don’t take tp as a parameter.
Quoted 5 lines
If the
struct_opscallback does not take tp, then don't pass it to the callback. I have a hard time to imagine why the bpf prog will not be interested in the tp/sk pointer though.or you meant the caller does not have tp? and where is the future caller?
My initial concern was that certain ctrl->func callbacks might eventually need to operate on an smc_sock rather than a tcp_sock. Crucially, we cannot always derive the owning smc_sock from a given tcp_sock (at least not with the current design). Therefore, a macro unconditionally passing tp (a tcp_sock pointer) would be unable to handle future scenarios requiring operation on an smc_sock. This could create an awkward situation with an unconditional tp argument.
However, considering the current situation, I believe the proposed approach is workable. And for future cases where smc_sock-specific callbacks become necessary, we can certainly introduce a new, dedicated macro at that point to address it. Therefore, I'm happy to proceed with your suggested change.
Quoted 29 lines
Quoted 6 lines
I’ve been considering this: since
smc_hs_ctrlis called from the netns, maybe we should replace the sk parameter with netns directly. After all, the only reason we pass sk here is to extractsock_net(sk). Doing so would remove the redundancy and also keep the interface more flexible for future extensions. What do you think?The net can be obtained from the tp also.
Like in this patch, all the caller needs to type
"const struct sock *sk =&tp->inet_conn.icsk_inet.sk;". I can imagine all the callers will have to type "sock_net((struct sock *)tp)" if passing net. Why not just do that in thesmc_hs_ctrlinstead of asking all the callers to type that?I meant something like this (untested):
(quoted diff) +1
-1-#define smc_call_hsbpf(init_val, sk, func, ...) ({ \ +#define smc_call_hsbpf(init_val, func, tp, ...) ({ \typeof(init_val) __ret = (init_val); \ struct smc_hs_ctrl *ctrl; \ rcu_read_lock(); \(quoted diff) +1
-1- ctrl = rcu_dereference(sock_net(sk)->smc.hs_ctrl); \ + ctrl = rcu_dereference(sock_net((struct sock *)(tp))->smc.hs_ctrl); \if (ctrl && ctrl->func) \(quoted diff) +1
-1- __ret = ctrl->func(__VA_ARGS__); \ + __ret = ctrl->func(tp, ##__VA_ARGS__); \rcu_read_unlock(); \ __ret; \
Quoted 3 lines
})
Take it. I’ll send the updated version with this change.
Martin KaFai Lau
reviewerRe: [PATCH bpf-next v4 2/3] net/smc: bpf: Introduce generic hook for handshake flow
Quoted 35 lines · D. Wythe
Quoted 34 lines · Martin KaFai Lau
Quoted 30 lines · D. Wythe
Quoted 22 lines · Martin KaFai Lau
include/net/smc.h struct smcd_dev { · line 96
Quoted 6 lines · D. Wythe
include/net/smc.h +6
-0+#if IS_ENABLED (CONFIG_SMC_HS_CTRL_BPF ) +#define smc_call_hsbpf (init_val, sk, func, ...) ({ \ + typeof(init_val) __ret = (init_val); \ + struct smc_hs_ctrl *ctrl; \ + rcu_read_lock(); \ + ctrl = rcu_dereference(sock_net(sk)->smc.hs_ctrl); \The
smc_hs_ctrl(and its ops) is called from the netns, so thebpf_struct_opsis attached to a netns. Attachingbpf_struct_opsto a netns has not been done before. More on this later.include/net/smc.h struct smcd_dev {
Quoted 5 lines
include/net/smc.h +5
-0+if (ctrl && ctrl->func) \ + __ret = ctrl->func (__VA_ARGS__); \ + +if (static_branch_unlikely (&tcp_have_smc) && tp->syn_smc) { + tp->syn_smc = !!smc_call_hsbpf (1 , sk, syn_option, tp);... so just pass tp instead of passing both sk and tp?
Quoted 2 lines
[ ... ]
You're right, it is a bit redundant. However, if we merge the parameters, every user of this macro will be forced to pass tp. In fact, we’re already considering adding some callback functions that don’t take tp as a parameter.
Quoted 8 lines
Quoted 5 lines
If the
struct_opscallback does not take tp, then don't pass it to the callback. I have a hard time to imagine why the bpf prog will not be interested in the tp/sk pointer though.or you meant the caller does not have tp? and where is the future caller?
My initial concern was that certain
ctrl->funccallbacks might eventually need to operate on ansmc_sockrather than atcp_sock.
hmm...in that case, I think it first needs to understand where else the smc struct_ops is planned to be called in the future. I thought the smc struct_ops is something unique to the af_smc address family but I suspect the future ops addition may not be the case. Can you share some details on where the future callback will be? e.g. in smc_{connect, sendmsg, recvmsg...} that has the smc_sock?
D. Wythe
maintainerRe: [PATCH bpf-next v4 2/3] net/smc: bpf: Introduce generic hook for handshake flow
Quoted 47 lines · Martin KaFai Lau
Quoted 35 lines · D. Wythe
Quoted 34 lines · Martin KaFai Lau
Quoted 30 lines · D. Wythe
Quoted 22 lines · Martin KaFai Lau
include/net/smc.h struct smcd_dev { · line 96
Quoted 6 lines · D. Wythe
include/net/smc.h +6
-0+#if IS_ENABLED (CONFIG_SMC_HS_CTRL_BPF ) +#define smc_call_hsbpf (init_val, sk, func, ...) ({ \ + typeof(init_val) __ret = (init_val); \ + struct smc_hs_ctrl *ctrl; \ + rcu_read_lock(); \ + ctrl = rcu_dereference(sock_net(sk)->smc.hs_ctrl); \The
smc_hs_ctrl(and its ops) is called from the netns, so thebpf_struct_opsis attached to a netns. Attachingbpf_struct_opsto a netns has not been done before. More on this later.include/net/smc.h struct smcd_dev {
Quoted 5 lines
include/net/smc.h +5
-0+if (ctrl && ctrl->func) \ + __ret = ctrl->func (__VA_ARGS__); \ + +if (static_branch_unlikely (&tcp_have_smc) && tp->syn_smc) { + tp->syn_smc = !!smc_call_hsbpf (1 , sk, syn_option, tp);... so just pass tp instead of passing both sk and tp?
Quoted 2 lines
[ ... ]
You're right, it is a bit redundant. However, if we merge the parameters, every user of this macro will be forced to pass tp. In fact, we’re already considering adding some callback functions that don’t take tp as a parameter.
Quoted 8 lines
Quoted 5 lines
If the
struct_opscallback does not take tp, then don't pass it to the callback. I have a hard time to imagine why the bpf prog will not be interested in the tp/sk pointer though.or you meant the caller does not have tp? and where is the future caller?
My initial concern was that certain
ctrl->funccallbacks might eventually need to operate on ansmc_sockrather than atcp_sock.
Quoted 6 lines
hmm...in that case, I think it first needs to understand where else the smc
struct_opsis planned to be called in the future. I thought the smcstruct_opsis something unique to theaf_smcaddress family but I suspect the future ops addition may not be the case. Can you share some details on where the future callback will be? e.g. in smc_{connect, sendmsg, recvmsg...} that has thesmc_sock?
The design scope of hs_ctrl (handshake control) is limited to the SMC protocol's handshake phase. This means it will not be involved in data transmission functions like smc_sendmsg and smc_recvmsg, Instead, its focus is on:
1. During the TCP three-way handshake
2. During the SMC protocol's own handshake. (proposal -> confirm -> accept)
Within the SMC module, hs_ctrl's primary future call points are concentrated within the __smc_connect() and smc_listen_work(). These two functions cover the SMC protocol handshake process.
And we have a plan involving private extensions to the SMC protocol. In the SMC protocol, different implementers can extend protocol functionality based on their Vendor Organizationally Unique Identifier (vendor_oui). You might notice that currently, the SMC implementation only has this vendor_oui field, but without corresponding functionality. This is highly significant for our applications, as many of our internal features rely on these private extensions. However, due to their inherent nature, these private features cannot be upstreamed. Therefore, BPF is the best way to implement these. Since these private extensions are essentially part of the SMC handshake process, hs_ctrl has become our first choice.
Beyond that, we are also considering other minor extensions to be implemented via hs_ctrl. These include assisting in the selection of the appropriate SMC device type and making decisions regarding which RDMA GID to use. (also in __smc_connect() and smc_listen_work()).
Martin KaFai Lau
reviewerRe: [PATCH bpf-next v4 2/3] net/smc: bpf: Introduce generic hook for handshake flow
Quoted 79 lines · D. Wythe
Quoted 47 lines · Martin KaFai Lau
Quoted 35 lines · D. Wythe
Quoted 34 lines · Martin KaFai Lau
Quoted 30 lines · D. Wythe
Quoted 22 lines · Martin KaFai Lau
Review
Quoted 6 lines · D. Wythe
(quoted diff) +6
-0+#if IS_ENABLED(CONFIG_SMC_HS_CTRL_BPF) +#define smc_call_hsbpf(init_val, sk, func, ...) ({ \ + typeof(init_val) __ret = (init_val); \ + struct smc_hs_ctrl *ctrl; \ + rcu_read_lock(); \ + ctrl = rcu_dereference(sock_net(sk)->smc.hs_ctrl); \The
smc_hs_ctrl(and its ops) is called from the netns, so thebpf_struct_opsis attached to a netns. Attachingbpf_struct_opsto a netns has not been done before. More on this later.Review
Quoted 5 lines
(quoted diff) +5
-0+ if (ctrl && ctrl->func) \ + __ret = ctrl->func(__VA_ARGS__); \ + + if (static_branch_unlikely(&tcp_have_smc) && tp->syn_smc) { + tp->syn_smc = !!smc_call_hsbpf(1, sk, syn_option, tp);... so just pass tp instead of passing both sk and tp?
Quoted 2 lines
[ ... ]
You're right, it is a bit redundant. However, if we merge the parameters, every user of this macro will be forced to pass tp. In fact, we’re already considering adding some callback functions that don’t take tp as a parameter.
Quoted 8 lines
Quoted 5 lines
If the
struct_opscallback does not take tp, then don't pass it to the callback. I have a hard time to imagine why the bpf prog will not be interested in the tp/sk pointer though.or you meant the caller does not have tp? and where is the future caller?
My initial concern was that certain
ctrl->funccallbacks might eventually need to operate on ansmc_sockrather than atcp_sock.Quoted 6 lines
hmm...in that case, I think it first needs to understand where else the smc
struct_opsis planned to be called in the future. I thought the smcstruct_opsis something unique to theaf_smcaddress family but I suspect the future ops addition may not be the case. Can you share some details on where the future callback will be? e.g. in smc_{connect, sendmsg, recvmsg...} that has thesmc_sock?The design scope of
hs_ctrl(handshake control) is limited to the SMC protocol's handshake phase. This means it will not be involved in data transmission functions likesmc_sendmsgandsmc_recvmsg, Instead, its focus is on:1. During the TCP three-way handshake
2. During the SMC protocol's own handshake. (proposal -> confirm -> accept)Within the SMC module, hs_ctrl's primary future call points are concentrated within the
__smc_connect()andsmc_listen_work(). These two functions cover the SMC protocol handshake process.And we have a plan involving private extensions to the SMC protocol. In the SMC protocol, different implementers can extend protocol functionality based on their Vendor Organizationally Unique Identifier (
vendor_oui). You might notice that currently, the SMC implementation only has thisvendor_ouifield, but without corresponding functionality. This is highly significant for our applications, as many of our internal features rely on these private extensions. However, due to their inherent nature, these private features cannot be upstreamed. Therefore, BPF is the best way to implement these. Since these private extensions are essentially part of the SMC handshake process,hs_ctrlhas become our first choice.
Quoted 4 lines
Beyond that, we are also considering other minor extensions to be implemented via
hs_ctrl. These include assisting in the selection of the appropriate SMC device type and making decisions regarding which RDMA GID to use. (also in__smc_connect()andsmc_listen_work()).
Thanks for the details.
Regarding the "net" passing and the future smc_sock, the net can still be obtained from smc_sock. It seems like a naming change on "tp" is needed when it may be a smc_sock in the future. It is a nit, so I will leave it as a fruit of thought for you and feel free to ignore.
Please re-spin.
D. Wythe
maintainerRe: [PATCH bpf-next v4 2/3] net/smc: bpf: Introduce generic hook for handshake flow
Quoted 89 lines · Martin KaFai Lau
Quoted 79 lines · D. Wythe
Quoted 47 lines · Martin KaFai Lau
Quoted 35 lines · D. Wythe
Quoted 34 lines · Martin KaFai Lau
Quoted 30 lines · D. Wythe
Quoted 22 lines · Martin KaFai Lau
Review
Quoted 6 lines · D. Wythe
(quoted diff) +6
-0+#if IS_ENABLED(CONFIG_SMC_HS_CTRL_BPF) +#define smc_call_hsbpf(init_val, sk, func, ...) ({ \ + typeof(init_val) __ret = (init_val); \ + struct smc_hs_ctrl *ctrl; \ + rcu_read_lock(); \ + ctrl = rcu_dereference(sock_net(sk)->smc.hs_ctrl); \The
smc_hs_ctrl(and its ops) is called from the netns, so thebpf_struct_opsis attached to a netns. Attachingbpf_struct_opsto a netns has not been done before. More on this later.Review
Quoted 5 lines
(quoted diff) +5
-0+ if (ctrl && ctrl->func) \ + __ret = ctrl->func(__VA_ARGS__); \ + + if (static_branch_unlikely(&tcp_have_smc) && tp->syn_smc) { + tp->syn_smc = !!smc_call_hsbpf(1, sk, syn_option, tp);... so just pass tp instead of passing both sk and tp?
Quoted 2 lines
[ ... ]
You're right, it is a bit redundant. However, if we merge the parameters, every user of this macro will be forced to pass tp. In fact, we’re already considering adding some callback functions that don’t take tp as a parameter.
Quoted 8 lines
Quoted 5 lines
If the
struct_opscallback does not take tp, then don't pass it to the callback. I have a hard time to imagine why the bpf prog will not be interested in the tp/sk pointer though.or you meant the caller does not have tp? and where is the future caller?
My initial concern was that certain
ctrl->funccallbacks might eventually need to operate on ansmc_sockrather than atcp_sock.Quoted 6 lines
hmm...in that case, I think it first needs to understand where else the smc
struct_opsis planned to be called in the future. I thought the smcstruct_opsis something unique to theaf_smcaddress family but I suspect the future ops addition may not be the case. Can you share some details on where the future callback will be? e.g. in smc_{connect, sendmsg, recvmsg...} that has thesmc_sock?The design scope of
hs_ctrl(handshake control) is limited to the SMC protocol's handshake phase. This means it will not be involved in data transmission functions likesmc_sendmsgandsmc_recvmsg, Instead, its focus is on:1. During the TCP three-way handshake
2. During the SMC protocol's own handshake. (proposal -> confirm -> accept)Within the SMC module, hs_ctrl's primary future call points are concentrated within the
__smc_connect()andsmc_listen_work(). These two functions cover the SMC protocol handshake process.And we have a plan involving private extensions to the SMC protocol. In the SMC protocol, different implementers can extend protocol functionality based on their Vendor Organizationally Unique Identifier (
vendor_oui). You might notice that currently, the SMC implementation only has thisvendor_ouifield, but without corresponding functionality. This is highly significant for our applications, as many of our internal features rely on these private extensions. However, due to their inherent nature, these private features cannot be upstreamed. Therefore, BPF is the best way to implement these. Since these private extensions are essentially part of the SMC handshake process,hs_ctrlhas become our first choice.Quoted 4 lines
Beyond that, we are also considering other minor extensions to be implemented via
hs_ctrl. These include assisting in the selection of the appropriate SMC device type and making decisions regarding which RDMA GID to use. (also in__smc_connect()andsmc_listen_work()).Thanks for the details.
Quoted 7 lines
Regarding the "net" passing and the future
smc_sock, the net can still be obtained fromsmc_sock. It seems like a naming change on "tp" is needed when it may be asmc_sockin the future. It is a nit, so I will leave it as a fruit of thought for you and feel free to ignore.Please re-spin.
Thank you for the feedback. Your suggestions make sense. I'll follow your advice and remove the redundant parameter. For now, I'll keep tp as the parameter name, and we can adjust it later if needed for future extensions.