net/smc: avoid conflict with sockmap after fallback
Subsystems (6)
D. Wythe
maintainerRFC PATCH 1/1 net/smc: avoid conflict with sockmap after fallback
Currently, after fallback, SMC will occupy the sk_user_data of the TCP sock(clcsk) to forward events. As a result, we cannot use sockmap after that, since sockmap also requires the use of the sk_user_data. Even more, in some cases, this may result in abnormal panic.
To enable sockmap after SMC fallback , we need to avoid using sk_user_data and instead introduce an additional smc_ctx in tcp_sock to index from TCP sock to SMC sock.
Additionally, we bind the lifecycle of the SMC sock to that of the TCP sock, ensuring that the indexing to the SMC sock remains valid throughout the lifetime of the TCP sock.
One key reason is that SMC overrides inet_connection_sock_af_ops, which introduces potential dependencies. We must ensure that the af_ops remain visible throughout the lifecycle of the TCP socket. In addition, this also resolves potential issues in some scenarios where the SMC sock might be invalid.
--- include/linux/tcp.h | 1 + net/smc/af_smc.c | 53 ++++++++++++++++++++++----------------------- net/smc/smc.h | 8 +++---- net/smc/smc_close.c | 1 - 4 files changed, 30 insertions(+), 33 deletions(-)
include/linux/tcp.h +1 -0
@@ -478,6 +478,7 @@ struct tcp_sock {#if IS_ENABLED (CONFIG_SMC )bool syn_smc;/* SYN includes SMC */ bool (*smc_hs_congested)(const struct sock *sk); +void *smc_ctx;#endif #if defined(CONFIG_TCP_MD5SIG ) || defined(CONFIG_TCP_AO )
net/smc/af_smc.c +26 -27
147 lines not on this page · raw message
net/smc/smc.h +3 -5
@@ -296,6 +296,8 @@ struct smc_sock { /* smc sock container *//* original write_space fct. */ void (*clcsk_error_report)(struct sock *sk);/* original error_report fct. */ +void (*clcsk_destruct)(struct sock *sk); +/* original destruct fct. */ struct smc_connection conn;/* smc connection */ struct smc_sock *listen_smc;/* listen parent */ struct work_struct connect_work;/* handle non-blocking connect*/
@@ -340,11 +342,7 @@ static inline void smc_init_saved_callbacks(struct smc_sock *smc) smc->clcsk_error_report =NULL ; } -static inline struct smc_sock *smc_clcsock_user_data (const struct sock *clcsk) -{ -return (struct smc_sock *) - ((uintptr_t )clcsk->sk_user_data & ~SK_USER_DATA_NOCOPY ); -} +#define smc_sk_from_clcsk (sk) (tcp_sk(sk)->smc_ctx)/* save target_cb in saved_cb, and replace target_cb with new_cb */ static inline void smc_clcsock_replace_cb(void (**target_cb)(struct sock *),
net/smc/smc_close.c +0 -1
@@ -218,7 +218,6 @@ int smc_close_active(struct smc_sock *smc)write_lock_bh (&smc->clcsock->sk->sk_callback_lock);smc_clcsock_restore_cb (&smc->clcsock->sk->sk_data_ready, &smc->clcsk_data_ready); - smc->clcsock->sk->sk_user_data =NULL ;write_unlock_bh (&smc->clcsock->sk->sk_callback_lock); rc =kernel_sock_shutdown (smc->clcsock,SHUT_RDWR ); }
Signature · 1 line
2.45.0
Dust Li
maintainerQuoted 4 lines · D. Wythe
Currently, after fallback, SMC will occupy the
sk_user_dataof the TCP sock(clcsk) to forward events. As a result, we cannot use sockmap after that, since sockmap also requires the use of thesk_user_data. Even more, in some cases, this may result in abnormal panic.
Looks like this is a bugfix more then a feature.
Quoted 55 lines
To enable sockmap after SMC fallback , we need to avoid using
sk_user_dataand instead introduce an additionalsmc_ctxintcp_sockto index from TCP sock to SMC sock.Additionally, we bind the lifecycle of the SMC sock to that of the TCP sock, ensuring that the indexing to the SMC sock remains valid throughout the lifetime of the TCP sock.
One key reason is that SMC overrides
inet_connection_sock_af_ops, which introduces potential dependencies. We must ensure that theaf_opsremain visible throughout the lifecycle of the TCP socket. In addition, this also resolves potential issues in some scenarios where the SMC sock might be invalid.Signed-off-by D. Wythe <[email protected]>---
include/linux/tcp.h | 1 + net/smc/af_smc.c | 53 ++++++++++++++++++++++----------------------- net/smc/smc.h | 8 +++---- net/smc/smc_close.c | 1 - 4 files changed, 30 insertions(+), 33 deletions(-)include/linux/tcp.h +1
-0@@ -478,6 +478,7 @@ struct tcp_sock {#if IS_ENABLED (CONFIG_SMC )bool syn_smc;/* SYN includes SMC */ bool (*smc_hs_congested)(const struct sock *sk); +void *smc_ctx;#endif #if defined(CONFIG_TCP_MD5SIG ) || defined(CONFIG_TCP_AO )net/smc/af_smc.c +1
-3@@ -127,7 +127,7 @@ static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk,struct smc_sock *smc;struct sock *child; - smc =smc_clcsock_user_data (sk); + smc =smc_sk_from_clcsk (sk);if (READ_ONCE (sk->sk_ack_backlog) +atomic_read (&smc->queued_smc_hs) > sk->sk_max_ack_backlog)@@ -143,8 +143,6 @@ static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk, own_req);/* child must not inherit smc or its ops */ if (child) { -rcu_assign_sk_user_data (child,NULL ); -/* v4-mapped sockets don't inherit parent ops. Don't restore. */ if (inet_csk (child)->icsk_af_ops ==inet_csk (sk)->icsk_af_ops)inet_csk (child)->icsk_af_ops = smc->ori_af_ops;
net/smc/af_smc.c static bool smc_hs_congested(const struct sock *sk) · line 162
Quoted 8 lines
net/smc/af_smc.c +1
-4@@ -161,10 +159,7 @@ static bool smc_hs_congested(const struct sock *sk) {const struct smc_sock *smc; - smc =smc_clcsock_user_data (sk); - -if (!smc) -return true; + smc =smc_sk_from_clcsk (sk);
I don't see any users of smc in this function. Seems it is redundant here.
Quoted 14 lines
net/smc/af_smc.c +0
-1if (workqueue_congested (WORK_CPU_UNBOUND , smc_hs_wq))return true;@@ -250,7 +245,6 @@ static void smc_fback_restore_callbacks(struct smc_sock *smc)struct sock *clcsk = smc->clcsock->sk;write_lock_bh (&clcsk->sk_callback_lock); - clcsk->sk_user_data =NULL ;smc_clcsock_restore_cb (&clcsk->sk_state_change, &smc->clcsk_state_change);smc_clcsock_restore_cb (&clcsk->sk_data_ready, &smc->clcsk_data_ready);@@ -832,11 +826,10 @@ static void smc_fback_forward_wakeup(struct smc_sock *smc, struct sock *clcsk,static void smc_fback_state_change (struct sock *clcsk)
net/smc/af_smc.c static void smc_fback_forward_wakeup(struct smc_sock *smc, struct sock *clcsk, · line 834
Quoted 10 lines
net/smc/af_smc.c +2
-3{ -struct smc_sock *smc; +struct smc_sock *smc =smc_sk_from_clcsk (clcsk);read_lock_bh (&clcsk->sk_callback_lock); - smc =smc_clcsock_user_data (clcsk); -if (smc) +if (smc->clcsk_state_change)smc_fback_forward_wakeup (smc, clcsk, smc->clcsk_state_change);
Since we checked the clcsock_callback everywhere, why not put it into smc_fback_forward_wakeup() ?
Best regards,
Dust