[RFC v1 1/3] mm/mmu_notifier: Add a new notifier for mapping updates (new pages)

Jason Gunthorpe jgg at nvidia.com
Tue Jul 25 22:53:15 UTC 2023


On Tue, Jul 25, 2023 at 10:44:09PM +0000, Kasireddy, Vivek wrote:
> > If you still need the memory mapped then you re-call hmm_range_fault
> > and re-obtain it. hmm_range_fault will resolve all the races and you
> > get new pages.

> IIUC, for my udmabuf use-case, it looks like calling hmm_range_fault
> immediately after an invalidate (range notification) would preemptively fault in
> new pages before a write. The problem with that is if a read occurs on those
> new pages, then the data is incorrect as a write may not have
> happened yet.

It cannot be, if you use hmm_range_fault correctly you cannot get
corruption no matter what is done to the mmap'd memfd. If there is
otherwise it is a hmm_range_fault bug plain and simple.

> Ideally, what I am looking for is for getting new pages at the time of or after
> a write; until then, it is ok to use the old pages given my use-case.

It is wrong, if you are synchronizing the vma then you must use the
latest copy. If your use case can tolerate it then keep a 'not
present' indication for the missing pages until you actually need
them, but dmabuf doesn't really provide an API for that.

> I think the difference comes down to whether we (udmabuf driver) want to
> grab the new pages after getting notified about a PTE update because
> of a fault

Why? You still haven't explained why you want this.

If you are writing to the pages then you have to do this

If you are reading from the pages then hmm_range_fault should return
the zero page for a hole until it is written too

Jason


More information about the dri-devel mailing list