@@ -282,16 +282,13 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
282
282
/* Find sets of physically contiguous pages */
283
283
tidbuf -> n_psets = find_phys_blocks (tidbuf , pinned );
284
284
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. */
290
286
spin_lock (& fd -> tid_lock );
291
287
if (fd -> tid_used + tidbuf -> n_psets > fd -> tid_limit )
292
288
pageset_count = fd -> tid_limit - fd -> tid_used ;
293
289
else
294
290
pageset_count = tidbuf -> n_psets ;
291
+ fd -> tid_used += pageset_count ;
295
292
spin_unlock (& fd -> tid_lock );
296
293
297
294
if (!pageset_count )
@@ -400,10 +397,11 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
400
397
nomem :
401
398
hfi1_cdbg (TID , "total mapped: tidpairs:%u pages:%u (%d)" , tididx ,
402
399
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 );
403
404
if (tididx ) {
404
- spin_lock (& fd -> tid_lock );
405
- fd -> tid_used += tididx ;
406
- spin_unlock (& fd -> tid_lock );
407
405
tinfo -> tidcnt = tididx ;
408
406
tinfo -> length = mapped_pages * PAGE_SIZE ;
409
407
0 commit comments