Skip to contentSkip to conversation

net/smc: hold conns_lock before calling smc_lgr_register_conn()

PATCH Ursula Braun 1 participant 1 message Apr 16, 2019 s390

lore
Share & tools
lore
#0 lore raw
Quoted 9 lines · Huaping Zhou

After smc_lgr_create(), the newly created link group is added to smc_lgr_list, thus is accessible from other context. Although link group creation is serialized by smc_create_lgr_pending, the new link group may still be accessed concurrently. For example, if ib_device is no longer active, smc_ib_port_event_work() will call smc_port_terminate(), which in turn will call __smc_lgr_terminate() on every link group of this device. So conns_lock is required here.

Thanks, looks good. Your patch will be part of our next patch submission for the net-tree.

Regards, Ursula

Quoted 21 lines
---
 net/smc/smc_core.c | 3 +++
 1 file changed, 3 insertions(+)
net/smc/smc_core.c +3 -0
index 53a17cf..c4c3be4 100644
@@ -653,7 +653,10 @@ int smc_conn_create(struct smc_sock *smc, bool is_smcd, int srv_first_contact,
 				    lcl->id_for_peer, vlan_id, smcd, peer_gid);
 		if (rc)
 			goto out;
+		lgr = conn->lgr;
+		write_lock_bh(&lgr->conns_lock);
 		smc_lgr_register_conn(conn); /* add smc conn to lgr */
+		write_unlock_bh(&lgr->conns_lock);
 	}
 	conn->local_tx_ctrl.common.type = SMC_CDC_MSG_TYPE;
 	conn->local_tx_ctrl.len = SMC_WR_TX_SIZE;