Skip to content

Commit b9f227c

Browse files
Hans Wippeldavem330
authored andcommitted
net/smc: lock smc_lgr_list in port_terminate()
Currently, smc_port_terminate() is not holding the lock of the lgr list while it is traversing the list. This patch adds locking to this function and changes smc_lgr_terminate() accordingly. Signed-off-by: Hans Wippel <[email protected]> Signed-off-by: Ursula Braun <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2351abe commit b9f227c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

net/smc/smc_core.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ void smc_lgr_forget(struct smc_link_group *lgr)
346346
}
347347

348348
/* terminate linkgroup abnormally */
349-
void smc_lgr_terminate(struct smc_link_group *lgr)
349+
static void __smc_lgr_terminate(struct smc_link_group *lgr)
350350
{
351351
struct smc_connection *conn;
352352
struct smc_sock *smc;
@@ -355,7 +355,8 @@ void smc_lgr_terminate(struct smc_link_group *lgr)
355355
if (lgr->terminating)
356356
return; /* lgr already terminating */
357357
lgr->terminating = 1;
358-
smc_lgr_forget(lgr);
358+
if (!list_empty(&lgr->list)) /* forget lgr */
359+
list_del_init(&lgr->list);
359360
smc_llc_link_inactive(&lgr->lnk[SMC_SINGLE_LINK]);
360361

361362
write_lock_bh(&lgr->conns_lock);
@@ -377,16 +378,25 @@ void smc_lgr_terminate(struct smc_link_group *lgr)
377378
smc_lgr_schedule_free_work(lgr);
378379
}
379380

381+
void smc_lgr_terminate(struct smc_link_group *lgr)
382+
{
383+
spin_lock_bh(&smc_lgr_list.lock);
384+
__smc_lgr_terminate(lgr);
385+
spin_unlock_bh(&smc_lgr_list.lock);
386+
}
387+
380388
/* Called when IB port is terminated */
381389
void smc_port_terminate(struct smc_ib_device *smcibdev, u8 ibport)
382390
{
383391
struct smc_link_group *lgr, *l;
384392

393+
spin_lock_bh(&smc_lgr_list.lock);
385394
list_for_each_entry_safe(lgr, l, &smc_lgr_list.list, list) {
386395
if (lgr->lnk[SMC_SINGLE_LINK].smcibdev == smcibdev &&
387396
lgr->lnk[SMC_SINGLE_LINK].ibport == ibport)
388-
smc_lgr_terminate(lgr);
397+
__smc_lgr_terminate(lgr);
389398
}
399+
spin_unlock_bh(&smc_lgr_list.lock);
390400
}
391401

392402
/* Determine vlan of internal TCP socket.

0 commit comments

Comments
 (0)