Skip to content

Commit ecf9155

Browse files
DeanLuickrleon
authored andcommitted
IB/hfi1: Reserve user expected TIDs
To avoid a race, reserve the number of user expected TIDs before setup. Fixes: 7e7a436 ("staging/hfi1: Add TID entry program function body") Signed-off-by: Dean Luick <[email protected]> Signed-off-by: Dennis Dalessandro <[email protected]> Link: https://lore.kernel.org/r/167328547636.1472310.7419712824785353905.stgit@awfm-02.cornelisnetworks.com Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 0a0a6e8 commit ecf9155

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

drivers/infiniband/hw/hfi1/user_exp_rcv.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,13 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
282282
/* Find sets of physically contiguous pages */
283283
tidbuf->n_psets = find_phys_blocks(tidbuf, pinned);
284284

285-
/*
286-
* We don't need to access this under a lock since tid_used is per
287-
* process and the same process cannot be in hfi1_user_exp_rcv_clear()
288-
* and hfi1_user_exp_rcv_setup() at the same time.
289-
*/
285+
/* Reserve the number of expected tids to be used. */
290286
spin_lock(&fd->tid_lock);
291287
if (fd->tid_used + tidbuf->n_psets > fd->tid_limit)
292288
pageset_count = fd->tid_limit - fd->tid_used;
293289
else
294290
pageset_count = tidbuf->n_psets;
291+
fd->tid_used += pageset_count;
295292
spin_unlock(&fd->tid_lock);
296293

297294
if (!pageset_count)
@@ -400,10 +397,11 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
400397
nomem:
401398
hfi1_cdbg(TID, "total mapped: tidpairs:%u pages:%u (%d)", tididx,
402399
mapped_pages, ret);
400+
/* adjust reserved tid_used to actual count */
401+
spin_lock(&fd->tid_lock);
402+
fd->tid_used -= pageset_count - tididx;
403+
spin_unlock(&fd->tid_lock);
403404
if (tididx) {
404-
spin_lock(&fd->tid_lock);
405-
fd->tid_used += tididx;
406-
spin_unlock(&fd->tid_lock);
407405
tinfo->tidcnt = tididx;
408406
tinfo->length = mapped_pages * PAGE_SIZE;
409407

0 commit comments

Comments
 (0)