mm/hmm: improve driver API to work and wait over a range

A common use case for HMM mirror is user trying to mirror a range and
before they could program the hardware it get invalidated by some core mm
event.  Instead of having user re-try right away to mirror the range
provide a completion mechanism for them to wait for any active
invalidation affecting the range.

This also changes how hmm_range_snapshot() and hmm_range_fault() works by
not relying on vma so that we can drop the mmap_sem when waiting and
lookup the vma again on retry.

Signed-off-by: Jérôme Glisse <>
Reviewed-by: Ralph Campbell <>
Cc: John Hubbard <>
Cc: Dan Williams <>
Cc: Dan Carpenter <>
Cc: Matthew Wilcox <>
Cc: Arnd Bergmann <>
Cc: Balbir Singh <>
Cc: Ira Weiny <>
Cc: Souptick Joarder <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>
3 files changed