Skip to content

Commit a70ed0f

Browse files
kwan-intcjgunthorpe
authored andcommitted
IB/hfi1: Acquire lock to release TID entries when user file is closed
Each user context is allocated a certain number of RcvArray (TID) entries and these entries are managed through TID groups. These groups are put into one of three lists in each user context: tid_group_list, tid_used_list, and tid_full_list, depending on the number of used TID entries within each group. When TID packets are expected, one or more TID groups will be allocated. After the packets are received, the TID groups will be freed. Since multiple user threads may access the TID groups simultaneously, a mutex exp_mutex is used to synchronize the access. However, when the user file is closed, it tries to release all TID groups without acquiring the mutex first, which risks a race condition with another thread that may be releasing its TID groups, leading to data corruption. This patch addresses the issue by acquiring the mutex first before releasing the TID groups when the file is closed. Fixes: 3abb33a ("staging/hfi1: Add TID cache receive init and free funcs") Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Mike Marciniszyn <[email protected]> Signed-off-by: Kaike Wan <[email protected]> Signed-off-by: Dennis Dalessandro <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 8a4f300 commit a70ed0f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/infiniband/hw/hfi1/user_exp_rcv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,12 @@ void hfi1_user_exp_rcv_free(struct hfi1_filedata *fd)
142142
{
143143
struct hfi1_ctxtdata *uctxt = fd->uctxt;
144144

145+
mutex_lock(&uctxt->exp_mutex);
145146
if (!EXP_TID_SET_EMPTY(uctxt->tid_full_list))
146147
unlock_exp_tids(uctxt, &uctxt->tid_full_list, fd);
147148
if (!EXP_TID_SET_EMPTY(uctxt->tid_used_list))
148149
unlock_exp_tids(uctxt, &uctxt->tid_used_list, fd);
150+
mutex_unlock(&uctxt->exp_mutex);
149151

150152
kfree(fd->invalid_tids);
151153
fd->invalid_tids = NULL;

0 commit comments

Comments
 (0)