Skip to content

Commit 81cf4f4

Browse files
Ursula BraunJakub Kicinski
authored andcommitted
net/smc: remove close abort worker
With the introduction of the link group termination worker there is no longer a need to postpone smc_close_active_abort() to a worker. To protect socket destruction due to normal and abnormal socket closing, the socket refcount is increased. Signed-off-by: Ursula Braun <[email protected]> Signed-off-by: Karsten Graul <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f528ba2 commit 81cf4f4

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

net/smc/af_smc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ static int smc_release(struct socket *sock)
167167
if (!sk)
168168
goto out;
169169

170+
sock_hold(sk); /* sock_put below */
170171
smc = smc_sk(sk);
171172

172173
/* cleanup for a dangling non-blocking connect */
@@ -189,6 +190,7 @@ static int smc_release(struct socket *sock)
189190
sock->sk = NULL;
190191
release_sock(sk);
191192

193+
sock_put(sk); /* sock_hold above */
192194
sock_put(sk); /* final sock_put */
193195
out:
194196
return rc;
@@ -970,12 +972,14 @@ void smc_close_non_accepted(struct sock *sk)
970972
{
971973
struct smc_sock *smc = smc_sk(sk);
972974

975+
sock_hold(sk); /* sock_put below */
973976
lock_sock(sk);
974977
if (!sk->sk_lingertime)
975978
/* wait for peer closing */
976979
sk->sk_lingertime = SMC_MAX_STREAM_WAIT_TIMEOUT;
977980
__smc_release(smc);
978981
release_sock(sk);
982+
sock_put(sk); /* sock_hold above */
979983
sock_put(sk); /* final sock_put */
980984
}
981985

net/smc/smc_close.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ int smc_close_abort(struct smc_connection *conn)
113113
/* terminate smc socket abnormally - active abort
114114
* link group is terminated, i.e. RDMA communication no longer possible
115115
*/
116-
static void smc_close_active_abort(struct smc_sock *smc)
116+
void smc_close_active_abort(struct smc_sock *smc)
117117
{
118118
struct sock *sk = &smc->sk;
119+
bool release_clcsock = false;
119120

120121
if (sk->sk_state != SMC_INIT && smc->clcsock && smc->clcsock->sk) {
121122
sk->sk_err = ECONNABORTED;
@@ -137,11 +138,14 @@ static void smc_close_active_abort(struct smc_sock *smc)
137138
cancel_delayed_work_sync(&smc->conn.tx_work);
138139
lock_sock(sk);
139140
sk->sk_state = SMC_CLOSED;
141+
sock_put(sk); /* postponed passive closing */
140142
break;
141143
case SMC_PEERCLOSEWAIT1:
142144
case SMC_PEERCLOSEWAIT2:
143145
case SMC_PEERFINCLOSEWAIT:
144146
sk->sk_state = SMC_CLOSED;
147+
smc_conn_free(&smc->conn);
148+
release_clcsock = true;
145149
sock_put(sk); /* passive closing */
146150
break;
147151
case SMC_PROCESSABORT:
@@ -156,6 +160,12 @@ static void smc_close_active_abort(struct smc_sock *smc)
156160

157161
sock_set_flag(sk, SOCK_DEAD);
158162
sk->sk_state_change(sk);
163+
164+
if (release_clcsock) {
165+
release_sock(sk);
166+
smc_clcsock_release(smc);
167+
lock_sock(sk);
168+
}
159169
}
160170

161171
static inline bool smc_close_sent_any_close(struct smc_connection *conn)
@@ -328,12 +338,6 @@ static void smc_close_passive_work(struct work_struct *work)
328338
lock_sock(sk);
329339
old_state = sk->sk_state;
330340

331-
if (conn->killed) {
332-
/* abnormal termination */
333-
smc_close_active_abort(smc);
334-
goto wakeup;
335-
}
336-
337341
rxflags = &conn->local_rx_ctrl.conn_state_flags;
338342
if (rxflags->peer_conn_abort) {
339343
/* peer has not received all data */

net/smc/smc_close.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ int smc_close_shutdown_write(struct smc_sock *smc);
2525
void smc_close_init(struct smc_sock *smc);
2626
void smc_clcsock_release(struct smc_sock *smc);
2727
int smc_close_abort(struct smc_connection *conn);
28+
void smc_close_active_abort(struct smc_sock *smc);
2829

2930
#endif /* SMC_CLOSE_H */

net/smc/smc_core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,7 @@ static void smc_conn_kill(struct smc_connection *conn)
519519
smc_sk_wake_ups(smc);
520520
smc_lgr_unregister_conn(conn);
521521
smc->sk.sk_err = ECONNABORTED;
522-
sock_hold(&smc->sk); /* sock_put in close work */
523-
if (!schedule_work(&conn->close_work))
524-
sock_put(&smc->sk);
522+
smc_close_active_abort(smc);
525523
}
526524

527525
/* terminate link group */
@@ -544,9 +542,11 @@ static void __smc_lgr_terminate(struct smc_link_group *lgr)
544542
read_unlock_bh(&lgr->conns_lock);
545543
conn = rb_entry(node, struct smc_connection, alert_node);
546544
smc = container_of(conn, struct smc_sock, conn);
545+
sock_hold(&smc->sk); /* sock_put below */
547546
lock_sock(&smc->sk);
548547
smc_conn_kill(conn);
549548
release_sock(&smc->sk);
549+
sock_put(&smc->sk); /* sock_hold above */
550550
read_lock_bh(&lgr->conns_lock);
551551
node = rb_first(&lgr->conns_all);
552552
}

0 commit comments

Comments
 (0)