linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Jens Axboe <axboe@kernel.dk>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	Amir Goldstein <amir73il@gmail.com>, Kees Cook <kees@kernel.org>,
	Josef Bacik <josef@toxicpanda.com>,
	Matthew Wilcox <willy@infradead.org>,
	Vlastimil Babka <vbabka@suse.cz>, Jann Horn <jannh@google.com>,
	Pedro Falcato <pfalcato@suse.de>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-mm@kvack.org, David Hildenbrand <david@redhat.com>
Subject: Re: [PATCH 00/10] convert the majority of file systems to mmap_prepare
Date: Fri, 1 Aug 2025 13:29:30 -0300	[thread overview]
Message-ID: <20250801162930.GB184255@nvidia.com> (raw)
In-Reply-To: <3cf76128-390a-4ef2-85a7-e3ee21ba04b5@lucifer.local>

On Fri, Aug 01, 2025 at 03:12:48PM +0100, Lorenzo Stoakes wrote:
> > I would like to suggest we add a vma->prepopulate() callback which is
> > where the remap_pfn should go. Once the VMA is finalized and fully
> > operational the vma_ops have the opportunity to prepopulate any PTEs.
> 
> I assume you mean vma->vm_ops->prepopulate ?

Yes

> We also have to think about other places where we prepopulate also, for
> instance the perf mmap call now prepopulates (ahem that was me).

Yes, vfio would also like to do this but can't due to the below issue.

> > This could then actually be locked properly so it is safe with
> > concurrent unmap_mapping_range() (current mmap callback is not safe)
> 
> Which lock in particular is problematic? You'd want to hold an rmap write
> lock to avoid racing zap?

I have forgotten, but there was a race with how the current mmap op
was called relative to when the VMA was tracked.

ie we should be able to do 

     CPU0                              CPU1
vm_ops_prepopulate()
   mutex_lock()
   if (!is_mapping_valid)
      return -EINVAL;                                       
   <fill ptes>
   mutex_unlock()
                                        mutex_lock()
					is_mapping_valid = false
					unmap_mapping_range()	  
                                        mutex_unlock()

And be sure there are no races. Use the lock of your choice for the
mutex.

The above is not true today under mmap, IIRC the VMA is not added to
the lists that unmap_mapping_range walks until after mmap() returns.

Jason


      parent reply	other threads:[~2025-08-01 16:29 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-16 19:33 Lorenzo Stoakes
2025-06-16 19:33 ` [PATCH 01/10] mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare Lorenzo Stoakes
2025-06-17  5:10   ` Christoph Hellwig
2025-06-17  5:29     ` Lorenzo Stoakes
2025-06-17 18:57   ` Vlastimil Babka
2025-06-16 19:33 ` [PATCH 02/10] mm/nommu: use file_has_valid_mmap_hooks() helper Lorenzo Stoakes
2025-06-17 10:05   ` Jan Kara
2025-06-17 18:58   ` Vlastimil Babka
2025-06-16 19:33 ` [PATCH 03/10] fs: consistently " Lorenzo Stoakes
2025-06-16 20:01   ` Kees Cook
2025-06-17  5:11   ` Christoph Hellwig
2025-06-17  5:25     ` Lorenzo Stoakes
2025-06-17  5:29       ` Christoph Hellwig
2025-06-17 10:08       ` Jan Kara
2025-06-17 11:48         ` Christian Brauner
2025-06-16 19:33 ` [PATCH 04/10] fs/dax: make it possible to check dev dax support without a VMA Lorenzo Stoakes
2025-06-16 20:26   ` Matthew Wilcox
2025-06-17 11:43     ` Christian Brauner
2025-06-16 19:33 ` [PATCH 05/10] fs/ext4: transition from deprecated .mmap hook to .mmap_prepare Lorenzo Stoakes
2025-06-17 10:11   ` Jan Kara
2025-06-16 19:33 ` [PATCH 06/10] fs/xfs: " Lorenzo Stoakes
2025-06-17  5:08   ` Christoph Hellwig
2025-06-17 11:45     ` Christian Brauner
2025-06-16 19:33 ` [PATCH 07/10] mm/filemap: introduce generic_file_*_mmap_prepare() helpers Lorenzo Stoakes
2025-06-17 10:12   ` Jan Kara
2025-06-17 19:00   ` Vlastimil Babka
2025-06-16 19:33 ` [PATCH 08/10] fs: convert simple use of generic_file_*_mmap() to .mmap_prepare() Lorenzo Stoakes
2025-06-16 23:26   ` Viacheslav Dubeyko
2025-06-17 10:14   ` Jan Kara
2025-06-17 14:07   ` Dave Kleikamp
2025-06-16 19:33 ` [PATCH 09/10] fs: convert most other generic_file_*mmap() users " Lorenzo Stoakes
2025-06-17 10:23   ` Jan Kara
2025-06-17 11:54     ` Christian Brauner
2025-06-16 19:33 ` [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings Lorenzo Stoakes
2025-06-16 22:51   ` Damien Le Moal
2025-06-16 23:24   ` Viacheslav Dubeyko
2025-06-17 10:28   ` Jan Kara
2025-06-17 11:57     ` Christian Brauner
2025-06-18 17:06   ` David Sterba
2025-06-19 17:47   ` Ryusuke Konishi
2025-06-16 19:56 ` [PATCH 00/10] convert the majority of file systems to mmap_prepare Kent Overstreet
2025-06-16 20:41 ` Al Viro
2025-06-17 13:45   ` Jeff Layton
2025-06-17 13:46     ` Lorenzo Stoakes
2025-06-16 23:11 ` Andrew Morton
2025-06-17 11:31   ` Christian Brauner
2025-06-17 11:58 ` Christian Brauner
2025-06-17 14:05 ` David Howells
2025-06-17 14:17   ` Lorenzo Stoakes
2025-08-01 14:00 ` Jason Gunthorpe
2025-08-01 14:12   ` Lorenzo Stoakes
2025-08-01 14:23     ` David Hildenbrand
2025-08-01 16:29     ` Jason Gunthorpe [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=20250801162930.GB184255@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=amir73il@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=david@redhat.com \
    --cc=jack@suse.cz \
    --cc=jannh@google.com \
    --cc=josef@toxicpanda.com \
    --cc=kees@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=pfalcato@suse.de \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox