Re: [PATCH v3 2/8] x86/mm: Change the leave_mm() condition for local TLB flushes

From: Rik van Riel
Date: Fri May 26 2017 - 09:25:38 EST


On Thu, 2017-05-25 at 19:01 -0700, Andy Lutomirski wrote:
> On Thu, May 25, 2017 at 6:39 PM, Rik van Riel <riel@xxxxxxxxxx>
> wrote:
> > On Thu, 2017-05-25 at 17:47 -0700, Andy Lutomirski wrote:
> > >
> > > +++ b/arch/x86/mm/tlb.c
> > > @@ -311,7 +311,7 @@ void flush_tlb_mm_range(struct mm_struct *mm,
> > > unsigned long start,
> > > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂgoto out;
> > > ÂÂÂÂÂÂ}
> > >
> > > -ÂÂÂÂÂif (!current->mm) {
> > > +ÂÂÂÂÂif (this_cpu_read(cpu_tlbstate.state) != TLBSTATE_OK) {
> > > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂleave_mm(smp_processor_id());
> >
> > Unless -mm changed leave_mm (I did not check), this
> > is not quite correct yet.
> >
> > The reason is leave_mm (at least in the latest Linus
> > tree) ignores the cpu argument for one of its checks.
> >
> > You should probably fix that in an earlier patch,
> > assuming you haven't already done so in -mm.
> >
> > void leave_mm(int cpu)
> > {
> > ÂÂÂÂÂÂÂÂstruct mm_struct *active_mm =
> > this_cpu_read(cpu_tlbstate.active_mm);
> > ÂÂÂÂÂÂÂÂif (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂBUG();
> > ÂÂÂÂÂÂÂÂif (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcpumask_clear_cpu(cpu, mm_cpumask(active_mm));
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂload_cr3(swapper_pg_dir);
>
> I agree it's odd, but what's the bug?ÂÂBoth before and after,
> leave_mm
> needed to be called with cpu == smp_processor_id(), and
> smp_processor_id() warns if it's called in a preemptible context.

Indeed, you are right. Looking at too much code at once...