public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Nicholas Piggin <npiggin@gmail.com>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>,
	akpm@linux-foundation.org, jstancek@redhat.com, mgorman@suse.de,
	minchan@kernel.org, mm-commits@vger.kernel.org, namit@vmware.com,
	stable@vger.kernel.org, will.deacon@arm.com,
	yang.shi@linux.alibaba.com
Subject: Re: + mm-mmu_gather-remove-__tlb_reset_range-for-force-flush.patch added to -mm tree
Date: Fri, 31 May 2019 11:49:31 +0200	[thread overview]
Message-ID: <20190531094931.GM2623@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <1559270298.wiy8c3d4zs.astroid@bobo.none>

On Fri, May 31, 2019 at 12:46:56PM +1000, Nicholas Piggin wrote:
> Peter Zijlstra's on May 28, 2019 12:25 am:
> > On Mon, May 27, 2019 at 06:59:08PM +0530, Aneesh Kumar K.V wrote:
> >> On 5/27/19 4:31 PM, Peter Zijlstra wrote:
> >> > On Tue, May 21, 2019 at 04:18:33PM -0700, akpm@linux-foundation.org wrote:
> >> > > --- a/mm/mmu_gather.c~mm-mmu_gather-remove-__tlb_reset_range-for-force-flush
> >> > > +++ a/mm/mmu_gather.c
> >> > > @@ -245,14 +245,28 @@ void tlb_finish_mmu(struct mmu_gather *t
> >> > >   {
> >> > >   	/*
> >> > >   	 * If there are parallel threads are doing PTE changes on same range
> >> > > -	 * under non-exclusive lock(e.g., mmap_sem read-side) but defer TLB
> >> > > -	 * flush by batching, a thread has stable TLB entry can fail to flush
> >> > > -	 * the TLB by observing pte_none|!pte_dirty, for example so flush TLB
> >> > > -	 * forcefully if we detect parallel PTE batching threads.
> >> > > +	 * under non-exclusive lock (e.g., mmap_sem read-side) but defer TLB
> >> > > +	 * flush by batching, one thread may end up seeing inconsistent PTEs
> >> > > +	 * and result in having stale TLB entries.  So flush TLB forcefully
> >> > > +	 * if we detect parallel PTE batching threads.
> >> > > +	 *
> >> > > +	 * However, some syscalls, e.g. munmap(), may free page tables, this
> >> > > +	 * needs force flush everything in the given range. Otherwise this
> >> > > +	 * may result in having stale TLB entries for some architectures,
> >> > > +	 * e.g. aarch64, that could specify flush what level TLB.
> >> > >   	 */
> >> > >   	if (mm_tlb_flush_nested(tlb->mm)) {
> >> > > +		/*
> >> > > +		 * The aarch64 yields better performance with fullmm by
> >> > > +		 * avoiding multiple CPUs spamming TLBI messages at the
> >> > > +		 * same time.
> >> > > +		 *
> >> > > +		 * On x86 non-fullmm doesn't yield significant difference
> >> > > +		 * against fullmm.
> >> > > +		 */
> >> > > +		tlb->fullmm = 1;
> >> > >   		__tlb_reset_range(tlb);
> >> > > -		__tlb_adjust_range(tlb, start, end - start);
> >> > > +		tlb->freed_tables = 1;
> >> > >   	}
> >> > >   	tlb_flush_mmu(tlb);

> > Maybe, but given the patch that went into -mm, PPC will never hit that
> > branch I killed anymore -- and that really shouldn't be in architecture
> > code anyway.
> 
> Yeah well if mm/ does this then sure it's dead and can go.
> 
> I don't think it's very nice to set fullmm and freed_tables for this 
> case though. Is this concurrent zapping an important fast path? It
> must have been, in order to justify all this complexity to the mm, so
> we don't want to tie this boat anchor to it AFAIKS?

I'm not convinced its an important fast path, afaict it is an
unfortunate correctness issue caused by allowing concurrenct frees.

> Is the problem just that the freed page tables flags get cleared by
> __tlb_reset_range()? Why not just remove that then, so the bits are
> set properly for the munmap?

That's insufficient; as argued in my initial suggestion:

  https://lkml.kernel.org/r/20190509103813.GP2589@hirez.programming.kicks-ass.net

Since we don't know what was flushed by the concorrent flushes, we must
flush all state (page sizes, tables etc..).

But it looks like benchmarks (for the one test-case we have) seem to
favour flushing the world over flushing a smaller range.



  reply	other threads:[~2019-05-31  9:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-21 23:18 + mm-mmu_gather-remove-__tlb_reset_range-for-force-flush.patch added to -mm tree akpm
2019-05-27 11:01 ` Peter Zijlstra
2019-05-27 13:29   ` Aneesh Kumar K.V
2019-05-27 14:25     ` Peter Zijlstra
2019-05-30 21:55       ` Jan Stancek
2019-05-31  2:46       ` Nicholas Piggin
2019-05-31  9:49         ` Peter Zijlstra [this message]
2019-06-03  2:11           ` Nicholas Piggin
2019-06-03 10:30             ` Will Deacon
2019-06-03 14:10               ` Nicholas Piggin
2019-06-03 17:57                 ` Will Deacon
2019-06-04  8:18                   ` Nicholas Piggin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190531094931.GM2623@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=jstancek@redhat.com \
    --cc=mgorman@suse.de \
    --cc=minchan@kernel.org \
    --cc=mm-commits@vger.kernel.org \
    --cc=namit@vmware.com \
    --cc=npiggin@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=will.deacon@arm.com \
    --cc=yang.shi@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox