diff mbox series

[RFC,net-next,14/20] net/smc: allow to access the state of inet smc sock

Message ID 1708412505-34470-15-git-send-email-alibuda@linux.alibaba.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series Introduce IPPROTO_SMC | expand

Checks

Context Check Description
netdev/series_format fail Series longer than 15 patches (and no cover letter)
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 940 this patch: 940
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 957 this patch: 957
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 957 this patch: 957
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns WARNING: line length of 87 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

D. Wythe Feb. 20, 2024, 7:01 a.m. UTC
From: "D. Wythe" <alibuda@linux.alibaba.com>

As we know, in inet version of smc, smc_sock and tcp_sock coexist,
this will result in the sk_state field has been accessed and modified by
both protocols, which can cause obvious exceptions. Therefore, this
patch modify the state macro for reading and setting the smc state,
using the icsk field to determine which is the very field needed to
be accessed or changed.

Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
---
 net/smc/smc.h | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/net/smc/smc.h b/net/smc/smc.h
index 932d61f..e54a30c 100644
--- a/net/smc/smc.h
+++ b/net/smc/smc.h
@@ -38,9 +38,6 @@ 
 #define KERNEL_HAS_ATOMIC64
 #endif
 
-#define smc_sk_state(sk)		((sk)->sk_state)
-#define smc_sk_set_state(sk, state)	(smc_sk_state(sk) = (state))
-
 enum smc_state {		/* possible states of an SMC socket */
 	SMC_ACTIVE	= 1,
 	SMC_INIT	= 2,
@@ -254,6 +251,7 @@  struct smc_sock {				/* smc sock container */
 		struct sock sk;
 	};
 	struct socket		*clcsock;	/* internal tcp socket */
+	unsigned char		smc_state;	/* smc state used in smc via inet_sk */
 	void			(*clcsk_state_change)(struct sock *sk);
 						/* original stat_change fct. */
 	void			(*clcsk_data_ready)(struct sock *sk);
@@ -397,6 +395,20 @@  static __always_inline bool smc_sock_is_inet_sock(const struct sock *sk)
 	return inet_test_bit(IS_ICSK, sk);
 }
 
+#define smc_sk_state(sk)	({				\
+	struct sock *__sk = (sk);				\
+	smc_sock_is_inet_sock(__sk) ?				\
+		smc_sk(__sk)->smc_state : (__sk)->sk_state;	\
+})
+
+static __always_inline void smc_sk_set_state(struct sock *sk, unsigned char state)
+{
+	if (smc_sock_is_inet_sock(sk))
+		smc_sk(sk)->smc_state = state;
+	else
+		sk->sk_state = state;
+}
+
 #define smc_sock_flag(sk, flag)	sock_flag(sk, flag)
 
 #endif	/* __SMC_H */