diff mbox series

[RFC,net-next,08/20] net/smc: optimize mutex_fback_rsn from mutex to spinlock

Message ID 1708412505-34470-9-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: 5224 this patch: 5224
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 2 maintainers not CCed: guangguan.wang@linux.alibaba.com dust.li@linux.alibaba.com
netdev/build_clang success Errors and warnings before: 1085 this patch: 1085
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: 5531 this patch: 5531
netdev/checkpatch warning CHECK: spinlock_t definition without comment
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>

The region protected by mutex_fback_rsn is simple enough and has no
potential blocking points. This change makes us can invoke
smc_stat_fallback() in any context, typically, in the context of
IRQ.

Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
---
 include/net/netns/smc.h | 2 +-
 net/smc/af_smc.c        | 4 ++--
 net/smc/smc_stats.c     | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/include/net/netns/smc.h b/include/net/netns/smc.h
index fc752a5..99bde74 100644
--- a/include/net/netns/smc.h
+++ b/include/net/netns/smc.h
@@ -10,7 +10,7 @@  struct netns_smc {
 	/* per cpu counters for SMC */
 	struct smc_stats __percpu	*smc_stats;
 	/* protect fback_rsn */
-	struct mutex			mutex_fback_rsn;
+	spinlock_t			mutex_fback_rsn;
 	struct smc_stats_rsn		*fback_rsn;
 
 	bool				limit_smc_hs;	/* constraint on handshake */
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 66306b7..1381ac1 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -769,7 +769,7 @@  static void smc_stat_fallback(struct smc_sock *smc)
 {
 	struct net *net = sock_net(&smc->sk);
 
-	mutex_lock(&net->smc.mutex_fback_rsn);
+	spin_lock_bh(&net->smc.mutex_fback_rsn);
 	if (smc->listen_smc) {
 		smc_stat_inc_fback_rsn_cnt(smc, net->smc.fback_rsn->srv);
 		net->smc.fback_rsn->srv_fback_cnt++;
@@ -777,7 +777,7 @@  static void smc_stat_fallback(struct smc_sock *smc)
 		smc_stat_inc_fback_rsn_cnt(smc, net->smc.fback_rsn->clnt);
 		net->smc.fback_rsn->clnt_fback_cnt++;
 	}
-	mutex_unlock(&net->smc.mutex_fback_rsn);
+	spin_unlock_bh(&net->smc.mutex_fback_rsn);
 }
 
 /* must be called under rcu read lock */
diff --git a/net/smc/smc_stats.c b/net/smc/smc_stats.c
index ca14c0f..64668e9 100644
--- a/net/smc/smc_stats.c
+++ b/net/smc/smc_stats.c
@@ -26,7 +26,7 @@  int smc_stats_init(struct net *net)
 	net->smc.smc_stats = alloc_percpu(struct smc_stats);
 	if (!net->smc.smc_stats)
 		goto err_stats;
-	mutex_init(&net->smc.mutex_fback_rsn);
+	spin_lock_init(&net->smc.mutex_fback_rsn);
 	return 0;
 
 err_stats:
@@ -387,7 +387,7 @@  int smc_nl_get_fback_stats(struct sk_buff *skb, struct netlink_callback *cb)
 	int snum = cb_ctx->pos[0];
 	bool is_srv = true;
 
-	mutex_lock(&net->smc.mutex_fback_rsn);
+	spin_lock_bh(&net->smc.mutex_fback_rsn);
 	for (k = 0; k < SMC_MAX_FBACK_RSN_CNT; k++) {
 		if (k < snum)
 			continue;
@@ -406,7 +406,7 @@  int smc_nl_get_fback_stats(struct sk_buff *skb, struct netlink_callback *cb)
 		if (rc_clnt == -ENODATA && rc_srv == -ENODATA)
 			break;
 	}
-	mutex_unlock(&net->smc.mutex_fback_rsn);
+	spin_unlock_bh(&net->smc.mutex_fback_rsn);
 	cb_ctx->pos[1] = skip_serv;
 	cb_ctx->pos[0] = k;
 	return skb->len;