All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Roman Gushchin <roman.gushchin@linux.dev>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Jann Horn <jannh@google.com>, Will Deacon <will@kernel.org>,
	"Aneesh Kumar K.V" <aneesh.kumar@kernel.org>,
	Nick Piggin <npiggin@gmail.com>, Hugh Dickins <hughd@google.com>,
	linux-arch@vger.kernel.org
Subject: Re: [PATCH v2] mmu_gather: move tlb flush for VM_PFNMAP/VM_MIXEDMAP vmas into free_pgtables()
Date: Mon, 27 Jan 2025 11:03:20 +0100	[thread overview]
Message-ID: <20250127100320.GC16742@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <Z5Q9KvugnVQv8QIO@google.com>

On Sat, Jan 25, 2025 at 01:23:54AM +0000, Roman Gushchin wrote:
> On Fri, Jan 24, 2025 at 09:22:50AM +0100, Peter Zijlstra wrote:
> > On Thu, Jan 23, 2025 at 11:12:33PM +0000, Roman Gushchin wrote:
> > 
> > > > +static inline void tlb_free_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
> > > >  {
> > > >  	if (tlb->fullmm)
> > > >  		return;
> > > >  
> > > >  	/*
> > > >  	 * VM_PFNMAP is more fragile because the core mm will not track the
> > > > +	 * page mapcount -- there might not be page-frames for these PFNs
> > > > +	 * after all.
> > > > +	 *
> > > > +	 * Specifically() there is a race between munmap() and
> > > > +	 * unmap_mapping_range(), where munmap() will unlink the VMA, such
> > > > +	 * that unmap_mapping_range() will no longer observe the VMA and
> > > > +	 * no-op, without observing the TLBI, returning prematurely.
> > > > +	 *
> > > > +	 * So if we're about to unlink such a VMA, and we have pending
> > > > +	 * TLBI for such a vma, flush things now.
> > > >  	 */
> > > > +	if ((vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) && tlb->vma_pfn)
> > > >  		tlb_flush_mmu_tlbonly(tlb);
> > > 
> > > Why do we need to re-check vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP) here?
> > 
> > No need, but an opportunity.
> > 
> > > In free_pgtables() we're iterating over multiple vma's. What if the first has
> > > no VM_PFNMAP set, but some other do? Idk if it's even possible, but it's not
> > > obvious that it's not possible either.
> > 
> > If we only need to flush PFN entries before unlinking PFN VMAs, then:
> > 
> >  - if there are no PFNs pending (vma_pfn), we don't need to flush;
> >  - if no PFN vma is being freed (vm_flags), we don't need to flush.
> 
> Right, but if I understand the code correctly, more than one vma can be
> freed by a single free_pgtables() invocation. Should we then check
> each vma's flags in the while loop in free_pgtables()? But then
> we're back to where we're now with multiple flushes.

Right, I misplaced it -- it should be in the vma loop.

> Do I misunderstand this?

I'm not sure how this would cause more flushes; notably it will not
cause flushes where no page-tables are dropped, eg. MADV, which was why
you started all this IIUC.


      reply	other threads:[~2025-01-27 10:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-22 23:27 [PATCH v2] mmu_gather: move tlb flush for VM_PFNMAP/VM_MIXEDMAP vmas into free_pgtables() Roman Gushchin
2025-01-23  7:42 ` Hugh Dickins
2025-01-23  8:06   ` Hugh Dickins
2025-01-23 16:45   ` Roman Gushchin
2025-01-23 21:45 ` Peter Zijlstra
2025-01-23 23:12   ` Roman Gushchin
2025-01-24  4:42     ` Hugh Dickins
2025-01-24  8:31       ` Peter Zijlstra
2025-01-24  9:04         ` Peter Zijlstra
2025-01-27  2:34         ` Hugh Dickins
2025-01-27  9:53           ` Peter Zijlstra
2025-01-24  8:22     ` Peter Zijlstra
2025-01-25  1:23       ` Roman Gushchin
2025-01-27 10:03         ` Peter Zijlstra [this message]

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=20250127100320.GC16742@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@kernel.org \
    --cc=hughd@google.com \
    --cc=jannh@google.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=npiggin@gmail.com \
    --cc=roman.gushchin@linux.dev \
    --cc=will@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.