Re: [PATCH v2] mm: Fix use_mm() vs TLB invalidate

From: Jens Axboe
Date: Wed Feb 26 2020 - 09:13:41 EST


On 2/26/20 6:21 AM, Peter Zijlstra wrote:
>
> For SMP systems using IPI based TLB invalidation, looking at
> current->active_mm is entirely reasonable. This then presents the
> following race condition:
>
>
> CPU0 CPU1
>
> flush_tlb_mm(mm) use_mm(mm)
> <send-IPI>
> tsk->active_mm = mm;
> <IPI>
> if (tsk->active_mm == mm)
> // flush TLBs
> </IPI>
> switch_mm(old_mm,mm,tsk);
>
>
> Where it is possible the IPI flushed the TLBs for @old_mm, not @mm,
> because the IPI lands before we actually switched.
>
> Avoid this by disabling IRQs across changing ->active_mm and
> switch_mm().
>
> [ There are all sorts of reasons this might be harmless for various
> architecture specific reasons, but best not leave the door open at
> all. ]

Not that I'm worried about it breaking anything, but ran it through
the usual testing and might as well report:

Tested-by: Jens Axboe <axboe@xxxxxxxxx>

--
Jens Axboe