diff mbox series

[RFC,net-next,06/20] net/smc: fast return on unconcernd TCP options

Message ID 1708412505-34470-7-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 success total: 0 errors, 0 warnings, 0 checks, 38 lines checked
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 fail Was 0 now: 1

Commit Message

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

SMC does not require additional processing of every TCP options,
hence that when options that do not require additional processing,
we can immediately return.

Note that options which are explicitly not supported require a try
to fallback, and shall not simplt returned.

Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
---
 net/smc/af_smc.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
diff mbox series

Patch

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index b7c9f5c..40cf0569 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -3054,6 +3054,28 @@  static inline bool smc_is_unsupport_tcp_sockopt(int optname)
 	return false;
 }
 
+/* Return true if smc might modify the semantics of
+ * the imcoming TCP options. Specifically, it includes
+ * unsupported TCP options.
+ */
+static inline bool smc_need_override_tcp_sockopt(struct sock *sk, int optname)
+{
+	switch (optname) {
+	case TCP_NODELAY:
+	case TCP_CORK:
+		if (smc_sk_state(sk) == SMC_INIT ||
+		    smc_sk_state(sk) == SMC_LISTEN ||
+		    smc_sk_state(sk) == SMC_CLOSED)
+			return false;
+		fallthrough;
+	case TCP_DEFER_ACCEPT:
+		return true;
+	default:
+		break;
+	}
+	return smc_is_unsupport_tcp_sockopt(optname);
+}
+
 static int smc_setsockopt_common(struct socket *sock, int level, int optname,
 				 sockptr_t optval, unsigned int optlen)
 {
@@ -3063,6 +3085,10 @@  static int smc_setsockopt_common(struct socket *sock, int level, int optname,
 
 	smc = smc_sk(sk);
 
+	/* Fast path, just go away if no extra action needed */
+	if (!smc_need_override_tcp_sockopt(sk, optname))
+		return 0;
+
 	if (optlen < sizeof(int))
 		return -EINVAL;
 	if (copy_from_sockptr(&val, optval, sizeof(int)))