mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									f3c1deddb2
								
							
						
					
					
						commit
						026c381fb4
					
				
					 2 changed files with 31 additions and 5 deletions
				
			
		| 
						 | 
					@ -245,8 +245,28 @@ static void smc_lgr_terminate_work(struct work_struct *work)
 | 
				
			||||||
	__smc_lgr_terminate(lgr, true);
 | 
						__smc_lgr_terminate(lgr, true);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int smcr_link_init(struct smc_link *lnk, u8 link_id,
 | 
					/* return next unique link id for the lgr */
 | 
				
			||||||
			  struct smc_init_info *ini)
 | 
					static u8 smcr_next_link_id(struct smc_link_group *lgr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						u8 link_id;
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (1) {
 | 
				
			||||||
 | 
							link_id = ++lgr->next_link_id;
 | 
				
			||||||
 | 
							if (!link_id)	/* skip zero as link_id */
 | 
				
			||||||
 | 
								link_id = ++lgr->next_link_id;
 | 
				
			||||||
 | 
							for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
 | 
				
			||||||
 | 
								if (lgr->lnk[i].state != SMC_LNK_INACTIVE &&
 | 
				
			||||||
 | 
								    lgr->lnk[i].link_id == link_id)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return link_id;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk,
 | 
				
			||||||
 | 
								  u8 link_idx, struct smc_init_info *ini)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	u8 rndvec[3];
 | 
						u8 rndvec[3];
 | 
				
			||||||
	int rc;
 | 
						int rc;
 | 
				
			||||||
| 
						 | 
					@ -254,7 +274,8 @@ static int smcr_link_init(struct smc_link *lnk, u8 link_id,
 | 
				
			||||||
	get_device(&ini->ib_dev->ibdev->dev);
 | 
						get_device(&ini->ib_dev->ibdev->dev);
 | 
				
			||||||
	atomic_inc(&ini->ib_dev->lnk_cnt);
 | 
						atomic_inc(&ini->ib_dev->lnk_cnt);
 | 
				
			||||||
	lnk->state = SMC_LNK_ACTIVATING;
 | 
						lnk->state = SMC_LNK_ACTIVATING;
 | 
				
			||||||
	lnk->link_id = link_id;
 | 
						lnk->link_id = smcr_next_link_id(lgr);
 | 
				
			||||||
 | 
						lnk->link_idx = link_idx;
 | 
				
			||||||
	lnk->smcibdev = ini->ib_dev;
 | 
						lnk->smcibdev = ini->ib_dev;
 | 
				
			||||||
	lnk->ibport = ini->ib_port;
 | 
						lnk->ibport = ini->ib_port;
 | 
				
			||||||
	lnk->path_mtu = ini->ib_dev->pattr[ini->ib_port - 1].active_mtu;
 | 
						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)
 | 
				
			||||||
	struct list_head *lgr_list;
 | 
						struct list_head *lgr_list;
 | 
				
			||||||
	struct smc_link *lnk;
 | 
						struct smc_link *lnk;
 | 
				
			||||||
	spinlock_t *lgr_lock;
 | 
						spinlock_t *lgr_lock;
 | 
				
			||||||
 | 
						u8 link_idx;
 | 
				
			||||||
	int rc = 0;
 | 
						int rc = 0;
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -338,6 +360,7 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
 | 
				
			||||||
		INIT_LIST_HEAD(&lgr->sndbufs[i]);
 | 
							INIT_LIST_HEAD(&lgr->sndbufs[i]);
 | 
				
			||||||
		INIT_LIST_HEAD(&lgr->rmbs[i]);
 | 
							INIT_LIST_HEAD(&lgr->rmbs[i]);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						lgr->next_link_id = 0;
 | 
				
			||||||
	smc_lgr_list.num += SMC_LGR_NUM_INCR;
 | 
						smc_lgr_list.num += SMC_LGR_NUM_INCR;
 | 
				
			||||||
	memcpy(&lgr->id, (u8 *)&smc_lgr_list.num, SMC_LGR_ID_SIZE);
 | 
						memcpy(&lgr->id, (u8 *)&smc_lgr_list.num, SMC_LGR_ID_SIZE);
 | 
				
			||||||
	INIT_DELAYED_WORK(&lgr->free_work, smc_lgr_free_work);
 | 
						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)
 | 
				
			||||||
		memcpy(lgr->peer_systemid, ini->ib_lcl->id_for_peer,
 | 
							memcpy(lgr->peer_systemid, ini->ib_lcl->id_for_peer,
 | 
				
			||||||
		       SMC_SYSTEMID_LEN);
 | 
							       SMC_SYSTEMID_LEN);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		lnk = &lgr->lnk[SMC_SINGLE_LINK];
 | 
							link_idx = SMC_SINGLE_LINK;
 | 
				
			||||||
		rc = smcr_link_init(lnk, SMC_SINGLE_LINK, ini);
 | 
							lnk = &lgr->lnk[link_idx];
 | 
				
			||||||
 | 
							rc = smcr_link_init(lgr, lnk, link_idx, ini);
 | 
				
			||||||
		if (rc)
 | 
							if (rc)
 | 
				
			||||||
			goto free_lgr;
 | 
								goto free_lgr;
 | 
				
			||||||
		lgr_list = &smc_lgr_list.list;
 | 
							lgr_list = &smc_lgr_list.list;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -115,6 +115,7 @@ struct smc_link {
 | 
				
			||||||
	u8			peer_mac[ETH_ALEN];	/* = gid[8:10||13:15] */
 | 
						u8			peer_mac[ETH_ALEN];	/* = gid[8:10||13:15] */
 | 
				
			||||||
	u8			peer_gid[SMC_GID_SIZE];	/* gid of peer*/
 | 
						u8			peer_gid[SMC_GID_SIZE];	/* gid of peer*/
 | 
				
			||||||
	u8			link_id;	/* unique # within link group */
 | 
						u8			link_id;	/* unique # within link group */
 | 
				
			||||||
 | 
						u8			link_idx;	/* index in lgr link array */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	enum smc_link_state	state;		/* state of link */
 | 
						enum smc_link_state	state;		/* state of link */
 | 
				
			||||||
	struct workqueue_struct *llc_wq;	/* single thread work queue */
 | 
						struct workqueue_struct *llc_wq;	/* single thread work queue */
 | 
				
			||||||
| 
						 | 
					@ -222,6 +223,7 @@ struct smc_link_group {
 | 
				
			||||||
						/* remote addr/key pairs */
 | 
											/* remote addr/key pairs */
 | 
				
			||||||
			DECLARE_BITMAP(rtokens_used_mask, SMC_RMBS_PER_LGR_MAX);
 | 
								DECLARE_BITMAP(rtokens_used_mask, SMC_RMBS_PER_LGR_MAX);
 | 
				
			||||||
						/* used rtoken elements */
 | 
											/* used rtoken elements */
 | 
				
			||||||
 | 
								u8			next_link_id;
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
		struct { /* SMC-D */
 | 
							struct { /* SMC-D */
 | 
				
			||||||
			u64			peer_gid;
 | 
								u64			peer_gid;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue