Consolidate the mmu notifier interval_tree and locking
Am 17.10.2019 18:26 schrieb "Yang, Philip" <[email protected]>:
Quoted 52 lines · Christian König
Am 16.10.19 um 18:04 schrieb Jason Gunthorpe:
Quoted 27 lines · Christian König
Quoted 17 lines
Am 15.10.19 um 20:12 schrieb Jason Gunthorpe:
Quoted 16 lines
From: Jason Gunthorpe <[email protected]>
8 of the
mmu_notifierusing drivers (i915_gem,radeon_mn,umem_odp, hfi1,scif_dma, vhost, gntdev, hmm) drivers are using a common pattern where they only use invalidate_range_start/end and immediately check the invalidating range against some driver data structure to tell if the driver is interested. Half of them use aninterval_tree, the others are simple linear search lists.Of the ones I checked they largely seem to have various kinds of races, bugs and poor implementation. This is a result of the complexity in how the notifier interacts with
get_user_pages(). It is extremely difficult to
use it correctly.Quoted 6 lines
Quoted 4 lines
Consolidate all of this code together into the core
mmu_notifierand provide a locking scheme similar tohmm_mirrorthat allows the user to safely useget_user_pages()and reliably know if the page list still matches the mm.That sounds really good, but could you outline for a moment how that is archived?
It uses the same basic scheme as hmm and rdma odp, outlined in the revisions to
hmm.rstlater on.Quoted 6 lines
Basically,
seq = mmu_range_read_begin(&mrn);// This is a speculative region
.. get_user_pages()/hmm_range_fault() ..How do we enforce that this get_user_pages()/hmm_range_fault() doesn't see outdated page table information?
In other words how the the following race prevented:
CPU A CPU B
invalidate_range_start()mmu_range_read_begin() get_user_pages()/hmm_range_fault()Updating the ptes
invalidate_range_end()I mean
get_user_pages()tries to circumvent this issue by grabbing a reference to the pages in question, but that isn't sufficient for the SVM use case.
Quoted 5 lines
That's the reason why we had this horrible solution with a r/w lock and a linked list of BOs in an interval tree.
Regards,
Christian.
get_user_pages/hmm_range_fault() and invalidate_range_start() both are called while holding mm->map_sem, so they are always serialized.
Not even remotely.
For calling get_user_pages()/hmm_range_fault() you only need to hold the mmap_sem in read mode.
And IIRC invalidate_range_start() is sometimes called without holding the mmap_sem at all.
So again how are they serialized?
Regards,
Christian.
Philip
Quoted 29 lines
Quoted 20 lines
// Result cannot be derferenced
take_lock(driver->update); if (mmu_range_read_retry(&mrn, range.notifier_seq) { // collision! The results are not correct goto again }// no collision, and now under lock. Now we can de-reference the
pages/etc
// program HW
// Now the invalidate callback is responsible to synchronize against
changes
unlock(driver->update)Basically, anything that was using
hmm_mirrorcorrectly transisions over fairly trivially, just with the modification to store a sequence number to close that race described in the hmm commit.Quoted 8 lines
For something like AMD gpu I expect it to transition to use
dma_fencefrom the notifier for coherency right before it unlocksdriver->update.Jason
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx