Skip to content

Commit 026c381

Browse files
karstengrdavem330
authored andcommitted
net/smc: introduce link_idx for link group array
The link_id is the index of the link in the array of the link group. When a link in the array is reused for a new link, a different unique link_id should be used, otherwise the index in the array could collide with the previous link at this array position. Use a new variable link_idx as array index, and make link_id an increasing unique id value. Signed-off-by: Karsten Graul <kgraul@linux.ibm.com> Reviewed-by: Ursula Braun <ubraun@linux.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f3c1ded commit 026c381

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

‎net/smc/smc_core.c‎

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,37 @@ static void smc_lgr_terminate_work(struct work_struct *work)
245245
__smc_lgr_terminate(lgr, true);
246246
}
247247

248-
static int smcr_link_init(struct smc_link *lnk, u8 link_id,
249-
struct smc_init_info *ini)
248+
/* return next unique link id for the lgr */
249+
static u8 smcr_next_link_id(struct smc_link_group *lgr)
250+
{
251+
u8 link_id;
252+
int i;
253+
254+
while (1) {
255+
link_id = ++lgr->next_link_id;
256+
if (!link_id) /* skip zero as link_id */
257+
link_id = ++lgr->next_link_id;
258+
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
259+
if (lgr->lnk[i].state != SMC_LNK_INACTIVE &&
260+
lgr->lnk[i].link_id == link_id)
261+
continue;
262+
}
263+
break;
264+
}
265+
return link_id;
266+
}
267+
268+
static int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk,
269+
u8 link_idx, struct smc_init_info *ini)
250270
{
251271
u8 rndvec[3];
252272
int rc;
253273

254274
get_device(&ini->ib_dev->ibdev->dev);
255275
atomic_inc(&ini->ib_dev->lnk_cnt);
256276
lnk->state = SMC_LNK_ACTIVATING;
257-
lnk->link_id = link_id;
277+
lnk->link_id = smcr_next_link_id(lgr);
278+
lnk->link_idx = link_idx;
258279
lnk->smcibdev = ini->ib_dev;
259280
lnk->ibport = ini->ib_port;
260281
lnk->path_mtu = ini->ib_dev->pattr[ini->ib_port - 1].active_mtu;
@@ -310,6 +331,7 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
310331
struct list_head *lgr_list;
311332
struct smc_link *lnk;
312333
spinlock_t *lgr_lock;
334+
u8 link_idx;
313335
int rc = 0;
314336
int i;
315337

@@ -338,6 +360,7 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
338360
INIT_LIST_HEAD(&lgr->sndbufs[i]);
339361
INIT_LIST_HEAD(&lgr->rmbs[i]);
340362
}
363+
lgr->next_link_id = 0;
341364
smc_lgr_list.num += SMC_LGR_NUM_INCR;
342365
memcpy(&lgr->id, (u8 *)&smc_lgr_list.num, SMC_LGR_ID_SIZE);
343366
INIT_DELAYED_WORK(&lgr->free_work, smc_lgr_free_work);
@@ -358,8 +381,9 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
358381
memcpy(lgr->peer_systemid, ini->ib_lcl->id_for_peer,
359382
SMC_SYSTEMID_LEN);
360383

361-
lnk = &lgr->lnk[SMC_SINGLE_LINK];
362-
rc = smcr_link_init(lnk, SMC_SINGLE_LINK, ini);
384+
link_idx = SMC_SINGLE_LINK;
385+
lnk = &lgr->lnk[link_idx];
386+
rc = smcr_link_init(lgr, lnk, link_idx, ini);
363387
if (rc)
364388
goto free_lgr;
365389
lgr_list = &smc_lgr_list.list;

‎net/smc/smc_core.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ struct smc_link {
115115
u8 peer_mac[ETH_ALEN]; /* = gid[8:10||13:15] */
116116
u8 peer_gid[SMC_GID_SIZE]; /* gid of peer*/
117117
u8 link_id; /* unique # within link group */
118+
u8 link_idx; /* index in lgr link array */
118119

119120
enum smc_link_state state; /* state of link */
120121
struct workqueue_struct *llc_wq; /* single thread work queue */
@@ -222,6 +223,7 @@ struct smc_link_group {
222223
/* remote addr/key pairs */
223224
DECLARE_BITMAP(rtokens_used_mask, SMC_RMBS_PER_LGR_MAX);
224225
/* used rtoken elements */
226+
u8 next_link_id;
225227
};
226228
struct { /* SMC-D */
227229
u64 peer_gid;

0 commit comments

Comments
 (0)