Skip to content

Commit 82087c0

Browse files
Ursula Braundavem330
authored andcommitted
net/smc: switch smcd_dev_list spinlock to mutex
The similar smc_ib_devices spinlock has been converted to a mutex. Protecting the smcd_dev_list by a mutex is possible as well. This patch converts the smcd_dev_list spinlock to a mutex. Fixes: c6ba7c9 ("net/smc: add base infrastructure for SMC-D and ISM") Signed-off-by: Ursula Braun <[email protected]> Signed-off-by: Karsten Graul <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 92f3cb0 commit 82087c0

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

net/smc/smc_core.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,11 +1971,11 @@ static void smc_core_going_away(void)
19711971
}
19721972
mutex_unlock(&smc_ib_devices.mutex);
19731973

1974-
spin_lock(&smcd_dev_list.lock);
1974+
mutex_lock(&smcd_dev_list.mutex);
19751975
list_for_each_entry(smcd, &smcd_dev_list.list, list) {
19761976
smcd->going_away = 1;
19771977
}
1978-
spin_unlock(&smcd_dev_list.lock);
1978+
mutex_unlock(&smcd_dev_list.mutex);
19791979
}
19801980

19811981
/* Clean up all SMC link groups */
@@ -1987,10 +1987,10 @@ static void smc_lgrs_shutdown(void)
19871987

19881988
smc_smcr_terminate_all(NULL);
19891989

1990-
spin_lock(&smcd_dev_list.lock);
1990+
mutex_lock(&smcd_dev_list.mutex);
19911991
list_for_each_entry(smcd, &smcd_dev_list.list, list)
19921992
smc_smcd_terminate_all(smcd);
1993-
spin_unlock(&smcd_dev_list.lock);
1993+
mutex_unlock(&smcd_dev_list.mutex);
19941994
}
19951995

19961996
static int smc_core_reboot_event(struct notifier_block *this,

net/smc/smc_ism.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <linux/spinlock.h>
10+
#include <linux/mutex.h>
1011
#include <linux/slab.h>
1112
#include <asm/page.h>
1213

@@ -17,7 +18,7 @@
1718

1819
struct smcd_dev_list smcd_dev_list = {
1920
.list = LIST_HEAD_INIT(smcd_dev_list.list),
20-
.lock = __SPIN_LOCK_UNLOCKED(smcd_dev_list.lock)
21+
.mutex = __MUTEX_INITIALIZER(smcd_dev_list.mutex)
2122
};
2223

2324
/* Test if an ISM communication is possible. */
@@ -317,9 +318,9 @@ EXPORT_SYMBOL_GPL(smcd_alloc_dev);
317318

318319
int smcd_register_dev(struct smcd_dev *smcd)
319320
{
320-
spin_lock(&smcd_dev_list.lock);
321+
mutex_lock(&smcd_dev_list.mutex);
321322
list_add_tail(&smcd->list, &smcd_dev_list.list);
322-
spin_unlock(&smcd_dev_list.lock);
323+
mutex_unlock(&smcd_dev_list.mutex);
323324

324325
pr_warn_ratelimited("smc: adding smcd device %s with pnetid %.16s%s\n",
325326
dev_name(&smcd->dev), smcd->pnetid,
@@ -333,9 +334,9 @@ void smcd_unregister_dev(struct smcd_dev *smcd)
333334
{
334335
pr_warn_ratelimited("smc: removing smcd device %s\n",
335336
dev_name(&smcd->dev));
336-
spin_lock(&smcd_dev_list.lock);
337+
mutex_lock(&smcd_dev_list.mutex);
337338
list_del_init(&smcd->list);
338-
spin_unlock(&smcd_dev_list.lock);
339+
mutex_unlock(&smcd_dev_list.mutex);
339340
smcd->going_away = 1;
340341
smc_smcd_terminate_all(smcd);
341342
flush_workqueue(smcd->event_wq);

net/smc/smc_ism.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
#define SMCD_ISM_H
1111

1212
#include <linux/uio.h>
13+
#include <linux/mutex.h>
1314

1415
#include "smc.h"
1516

1617
struct smcd_dev_list { /* List of SMCD devices */
1718
struct list_head list;
18-
spinlock_t lock; /* Protects list of devices */
19+
struct mutex mutex; /* Protects list of devices */
1920
};
2021

2122
extern struct smcd_dev_list smcd_dev_list; /* list of smcd devices */

net/smc/smc_pnet.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static int smc_pnet_remove_by_pnetid(struct net *net, char *pnet_name)
152152
}
153153
mutex_unlock(&smc_ib_devices.mutex);
154154
/* remove smcd devices */
155-
spin_lock(&smcd_dev_list.lock);
155+
mutex_lock(&smcd_dev_list.mutex);
156156
list_for_each_entry(smcd_dev, &smcd_dev_list.list, list) {
157157
if (smcd_dev->pnetid_by_user &&
158158
(!pnet_name ||
@@ -166,7 +166,7 @@ static int smc_pnet_remove_by_pnetid(struct net *net, char *pnet_name)
166166
rc = 0;
167167
}
168168
}
169-
spin_unlock(&smcd_dev_list.lock);
169+
mutex_unlock(&smcd_dev_list.mutex);
170170
return rc;
171171
}
172172

@@ -259,13 +259,13 @@ static bool smc_pnet_apply_smcd(struct smcd_dev *smcd_dev, char *pnet_name)
259259
u8 pnet_null[SMC_MAX_PNETID_LEN] = {0};
260260
bool applied = false;
261261

262-
spin_lock(&smcd_dev_list.lock);
262+
mutex_lock(&smcd_dev_list.mutex);
263263
if (smc_pnet_match(smcd_dev->pnetid, pnet_null)) {
264264
memcpy(smcd_dev->pnetid, pnet_name, SMC_MAX_PNETID_LEN);
265265
smcd_dev->pnetid_by_user = true;
266266
applied = true;
267267
}
268-
spin_unlock(&smcd_dev_list.lock);
268+
mutex_unlock(&smcd_dev_list.mutex);
269269
return applied;
270270
}
271271

@@ -321,15 +321,15 @@ static struct smcd_dev *smc_pnet_find_smcd(char *smcd_name)
321321
{
322322
struct smcd_dev *smcd_dev;
323323

324-
spin_lock(&smcd_dev_list.lock);
324+
mutex_lock(&smcd_dev_list.mutex);
325325
list_for_each_entry(smcd_dev, &smcd_dev_list.list, list) {
326326
if (!strncmp(dev_name(&smcd_dev->dev), smcd_name,
327327
IB_DEVICE_NAME_MAX - 1))
328328
goto out;
329329
}
330330
smcd_dev = NULL;
331331
out:
332-
spin_unlock(&smcd_dev_list.lock);
332+
mutex_unlock(&smcd_dev_list.mutex);
333333
return smcd_dev;
334334
}
335335

@@ -925,15 +925,15 @@ static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev,
925925
smc_pnet_find_ndev_pnetid_by_table(ndev, ndev_pnetid))
926926
return; /* pnetid could not be determined */
927927

928-
spin_lock(&smcd_dev_list.lock);
928+
mutex_lock(&smcd_dev_list.mutex);
929929
list_for_each_entry(ismdev, &smcd_dev_list.list, list) {
930930
if (smc_pnet_match(ismdev->pnetid, ndev_pnetid) &&
931931
!ismdev->going_away) {
932932
ini->ism_dev = ismdev;
933933
break;
934934
}
935935
}
936-
spin_unlock(&smcd_dev_list.lock);
936+
mutex_unlock(&smcd_dev_list.mutex);
937937
}
938938

939939
/* PNET table analysis for a given sock:

0 commit comments

Comments
 (0)