Skip to content

Commit 2ce4d4c

Browse files
Jack Steinertorvalds
authored andcommitted
gru: fix GRU interrupt race at deallocate
Fix a race where an interrupt could be received for a GRU context that has been deallocated. Signed-off-by: Jack Steiner <steiner@sgi.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 74ccd09 commit 2ce4d4c

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

‎drivers/misc/sgi-gru/grufault.c‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ static void gru_preload_tlb(struct gru_state *gru,
360360
* < 0 = error code
361361
*
362362
*/
363-
static int gru_try_dropin(struct gru_thread_state *gts,
363+
static int gru_try_dropin(struct gru_state *gru,
364+
struct gru_thread_state *gts,
364365
struct gru_tlb_fault_handle *tfh,
365366
struct gru_instruction_bits *cbk)
366367
{
@@ -432,7 +433,7 @@ static int gru_try_dropin(struct gru_thread_state *gts,
432433
}
433434

434435
if (unlikely(cbe) && pageshift == PAGE_SHIFT) {
435-
gru_preload_tlb(gts->ts_gru, gts, atomic, vaddr, asid, write, tlb_preload_count, tfh, cbe);
436+
gru_preload_tlb(gru, gts, atomic, vaddr, asid, write, tlb_preload_count, tfh, cbe);
436437
gru_flush_cache_cbe(cbe);
437438
}
438439

@@ -442,7 +443,7 @@ static int gru_try_dropin(struct gru_thread_state *gts,
442443
gru_dbg(grudev,
443444
"%s: gid %d, gts 0x%p, tfh 0x%p, vaddr 0x%lx, asid 0x%x, indexway 0x%x,"
444445
" rw %d, ps %d, gpa 0x%lx\n",
445-
atomic ? "atomic" : "non-atomic", gts->ts_gru->gs_gid, gts, tfh, vaddr, asid,
446+
atomic ? "atomic" : "non-atomic", gru->gs_gid, gts, tfh, vaddr, asid,
446447
indexway, write, pageshift, gpa);
447448
STAT(tlb_dropin);
448449
return 0;
@@ -528,6 +529,7 @@ static irqreturn_t gru_intr(int chiplet, int blade)
528529
struct gru_tlb_fault_map imap, dmap;
529530
struct gru_thread_state *gts;
530531
struct gru_tlb_fault_handle *tfh = NULL;
532+
struct completion *cmp;
531533
int cbrnum, ctxnum;
532534

533535
STAT(intr);
@@ -547,9 +549,11 @@ static irqreturn_t gru_intr(int chiplet, int blade)
547549

548550
for_each_cbr_in_tfm(cbrnum, dmap.fault_bits) {
549551
STAT(intr_cbr);
550-
complete(gru->gs_blade->bs_async_wq);
552+
cmp = gru->gs_blade->bs_async_wq;
553+
if (cmp)
554+
complete(cmp);
551555
gru_dbg(grudev, "gid %d, cbr_done %d, done %d\n",
552-
gru->gs_gid, cbrnum, gru->gs_blade->bs_async_wq->done);
556+
gru->gs_gid, cbrnum, cmp ? cmp->done : -1);
553557
}
554558

555559
for_each_cbr_in_tfm(cbrnum, imap.fault_bits) {
@@ -566,14 +570,20 @@ static irqreturn_t gru_intr(int chiplet, int blade)
566570
ctxnum = tfh->ctxnum;
567571
gts = gru->gs_gts[ctxnum];
568572

573+
/* Spurious interrupts can cause this. Ignore. */
574+
if (!gts) {
575+
STAT(intr_spurious);
576+
continue;
577+
}
578+
569579
/*
570580
* This is running in interrupt context. Trylock the mmap_sem.
571581
* If it fails, retry the fault in user context.
572582
*/
573583
if (!gts->ts_force_cch_reload &&
574584
down_read_trylock(&gts->ts_mm->mmap_sem)) {
575585
gts->ustats.fmm_tlbdropin++;
576-
gru_try_dropin(gts, tfh, NULL);
586+
gru_try_dropin(gru, gts, tfh, NULL);
577587
up_read(&gts->ts_mm->mmap_sem);
578588
} else {
579589
tfh_user_polling_mode(tfh);
@@ -619,7 +629,7 @@ static int gru_user_dropin(struct gru_thread_state *gts,
619629
wait_event(gms->ms_wait_queue,
620630
atomic_read(&gms->ms_range_active) == 0);
621631
prefetchw(tfh); /* Helps on hdw, required for emulator */
622-
ret = gru_try_dropin(gts, tfh, cb);
632+
ret = gru_try_dropin(gts->ts_gru, gts, tfh, cb);
623633
if (ret <= 0)
624634
return ret;
625635
STAT(call_os_wait_queue);

‎drivers/misc/sgi-gru/gruprocfs.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static int statistics_show(struct seq_file *s, void *p)
6666
printstat(s, intr);
6767
printstat(s, intr_cbr);
6868
printstat(s, intr_tfh);
69+
printstat(s, intr_spurious);
6970
printstat(s, intr_mm_lock_failed);
7071
printstat(s, call_os);
7172
printstat(s, call_os_wait_queue);

‎drivers/misc/sgi-gru/grutables.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ struct gru_stats_s {
192192
atomic_long_t intr;
193193
atomic_long_t intr_cbr;
194194
atomic_long_t intr_tfh;
195+
atomic_long_t intr_spurious;
195196
atomic_long_t intr_mm_lock_failed;
196197
atomic_long_t call_os;
197198
atomic_long_t call_os_wait_queue;

0 commit comments

Comments
 (0)