net/smc: fix cleanup for linkgroup setup failures

If an SMC connection to a certain peer is setup the first time,
a new linkgroup is created. In case of setup failures, such a
linkgroup is unusable and should disappear. As a first step the
linkgroup is removed from the linkgroup list in smc_lgr_forget().

There are 2 problems:
smc_listen_decline() might be called before linkgroup creation
resulting in a crash due to calling smc_lgr_forget() with
parameter NULL.
If a setup failure occurs after linkgroup creation, the connection
is never unregistered from the linkgroup, preventing linkgroup
freeing.

This patch introduces an enhanced smc_lgr_cleanup_early() function
which
* contains a linkgroup check for early smc_listen_decline()
  invocations
* invokes smc_conn_free() to guarantee unregistering of the
  connection.
* schedules fast linkgroup removal of the unusable linkgroup

And the unused function smcd_conn_free() is removed from smc_core.h.

Fixes: 3b2dec2603 ("net/smc: restructure client and server code in af_smc")
Fixes: 2a0674fffb ("net/smc: improve abnormal termination of link groups")
Signed-off-by: Ursula Braun <ubraun@linux.ibm.com>
Signed-off-by: Karsten Graul <kgraul@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Ursula Braun 2020-02-25 16:34:36 +01:00 committed by David S. Miller
parent 402482a6a7
commit 51e3dfa890
3 changed files with 28 additions and 11 deletions

View File

@ -512,15 +512,18 @@ static int smc_connect_decline_fallback(struct smc_sock *smc, int reason_code)
static int smc_connect_abort(struct smc_sock *smc, int reason_code, static int smc_connect_abort(struct smc_sock *smc, int reason_code,
int local_contact) int local_contact)
{ {
bool is_smcd = smc->conn.lgr->is_smcd;
if (local_contact == SMC_FIRST_CONTACT) if (local_contact == SMC_FIRST_CONTACT)
smc_lgr_forget(smc->conn.lgr); smc_lgr_cleanup_early(&smc->conn);
if (smc->conn.lgr->is_smcd) else
smc_conn_free(&smc->conn);
if (is_smcd)
/* there is only one lgr role for SMC-D; use server lock */ /* there is only one lgr role for SMC-D; use server lock */
mutex_unlock(&smc_server_lgr_pending); mutex_unlock(&smc_server_lgr_pending);
else else
mutex_unlock(&smc_client_lgr_pending); mutex_unlock(&smc_client_lgr_pending);
smc_conn_free(&smc->conn);
smc->connect_nonblock = 0; smc->connect_nonblock = 0;
return reason_code; return reason_code;
} }
@ -1091,7 +1094,6 @@ static void smc_listen_out_err(struct smc_sock *new_smc)
if (newsmcsk->sk_state == SMC_INIT) if (newsmcsk->sk_state == SMC_INIT)
sock_put(&new_smc->sk); /* passive closing */ sock_put(&new_smc->sk); /* passive closing */
newsmcsk->sk_state = SMC_CLOSED; newsmcsk->sk_state = SMC_CLOSED;
smc_conn_free(&new_smc->conn);
smc_listen_out(new_smc); smc_listen_out(new_smc);
} }
@ -1102,12 +1104,13 @@ static void smc_listen_decline(struct smc_sock *new_smc, int reason_code,
{ {
/* RDMA setup failed, switch back to TCP */ /* RDMA setup failed, switch back to TCP */
if (local_contact == SMC_FIRST_CONTACT) if (local_contact == SMC_FIRST_CONTACT)
smc_lgr_forget(new_smc->conn.lgr); smc_lgr_cleanup_early(&new_smc->conn);
else
smc_conn_free(&new_smc->conn);
if (reason_code < 0) { /* error, no fallback possible */ if (reason_code < 0) { /* error, no fallback possible */
smc_listen_out_err(new_smc); smc_listen_out_err(new_smc);
return; return;
} }
smc_conn_free(&new_smc->conn);
smc_switch_to_fallback(new_smc); smc_switch_to_fallback(new_smc);
new_smc->fallback_rsn = reason_code; new_smc->fallback_rsn = reason_code;
if (reason_code && reason_code != SMC_CLC_DECL_PEERDECL) { if (reason_code && reason_code != SMC_CLC_DECL_PEERDECL) {
@ -1170,16 +1173,18 @@ static int smc_listen_ism_init(struct smc_sock *new_smc,
new_smc->conn.lgr->vlan_id, new_smc->conn.lgr->vlan_id,
new_smc->conn.lgr->smcd)) { new_smc->conn.lgr->smcd)) {
if (ini->cln_first_contact == SMC_FIRST_CONTACT) if (ini->cln_first_contact == SMC_FIRST_CONTACT)
smc_lgr_forget(new_smc->conn.lgr); smc_lgr_cleanup_early(&new_smc->conn);
smc_conn_free(&new_smc->conn); else
smc_conn_free(&new_smc->conn);
return SMC_CLC_DECL_SMCDNOTALK; return SMC_CLC_DECL_SMCDNOTALK;
} }
/* Create send and receive buffers */ /* Create send and receive buffers */
if (smc_buf_create(new_smc, true)) { if (smc_buf_create(new_smc, true)) {
if (ini->cln_first_contact == SMC_FIRST_CONTACT) if (ini->cln_first_contact == SMC_FIRST_CONTACT)
smc_lgr_forget(new_smc->conn.lgr); smc_lgr_cleanup_early(&new_smc->conn);
smc_conn_free(&new_smc->conn); else
smc_conn_free(&new_smc->conn);
return SMC_CLC_DECL_MEM; return SMC_CLC_DECL_MEM;
} }

View File

@ -162,6 +162,18 @@ static void smc_lgr_unregister_conn(struct smc_connection *conn)
conn->lgr = NULL; conn->lgr = NULL;
} }
void smc_lgr_cleanup_early(struct smc_connection *conn)
{
struct smc_link_group *lgr = conn->lgr;
if (!lgr)
return;
smc_conn_free(conn);
smc_lgr_forget(lgr);
smc_lgr_schedule_free_work_fast(lgr);
}
/* Send delete link, either as client to request the initiation /* Send delete link, either as client to request the initiation
* of the DELETE LINK sequence from server; or as server to * of the DELETE LINK sequence from server; or as server to
* initiate the delete processing. See smc_llc_rx_delete_link(). * initiate the delete processing. See smc_llc_rx_delete_link().

View File

@ -296,6 +296,7 @@ struct smc_clc_msg_accept_confirm;
struct smc_clc_msg_local; struct smc_clc_msg_local;
void smc_lgr_forget(struct smc_link_group *lgr); void smc_lgr_forget(struct smc_link_group *lgr);
void smc_lgr_cleanup_early(struct smc_connection *conn);
void smc_lgr_terminate(struct smc_link_group *lgr, bool soft); void smc_lgr_terminate(struct smc_link_group *lgr, bool soft);
void smc_port_terminate(struct smc_ib_device *smcibdev, u8 ibport); void smc_port_terminate(struct smc_ib_device *smcibdev, u8 ibport);
void smc_smcd_terminate(struct smcd_dev *dev, u64 peer_gid, void smc_smcd_terminate(struct smcd_dev *dev, u64 peer_gid,
@ -316,7 +317,6 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini);
void smc_conn_free(struct smc_connection *conn); void smc_conn_free(struct smc_connection *conn);
int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini); int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini);
void smcd_conn_free(struct smc_connection *conn);
void smc_lgr_schedule_free_work_fast(struct smc_link_group *lgr); void smc_lgr_schedule_free_work_fast(struct smc_link_group *lgr);
int smc_core_init(void); int smc_core_init(void);
void smc_core_exit(void); void smc_core_exit(void);