On 1/17/23 07:58, Jason Gunthorpe wrote:
This is always required, but we can't have a proper unguarded assertion
because of a shortcut in fork. So, cover as much as we can for now.
Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
---
mm/gup.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/mm/gup.c b/mm/gup.c
index 9e332e3f6ea8e2..d203e268793b9c 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1350,6 +1350,14 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm,
return -EAGAIN;
lock_dropped = true;
*locked = 1;
+ } else if (flags & FOLL_PIN) {
+ /*
+ * The mmap lock must be held when calling this function. This
+ * is true even for non-pin modes, but due to a shortcut in fork
+ * not taking the lock for the new mm we cannot check this
+ * comprehensively.
I get that fork doesn't lock the newly created mm. But I'm having
trouble finding the calling path from fork to __get_user_pages_locked()
that leads to this comment, can you provide a hint? Both the comment
and the commit log are rather coy about where this happens.
+ */
+ mmap_assert_locked(mm);
}
if (flags & FOLL_PIN)
thanks,
--
John Hubbard
NVIDIA