Re: [PATCH v2 05/10] mm/hugetlb: Make userfaultfd_huge_must_wait() safe to pmd unshare

From: John Hubbard
Date: Wed Dec 07 2022 - 18:54:56 EST


On 12/7/22 15:44, Peter Xu wrote:
The part that matters in the comment is "need to be before setting current
state".

blocking_state = userfaultfd_get_blocking_state(vmf->flags);
if (is_vm_hugetlb_page(vma))
hugetlb_vma_lock_read(vma);
set_current_state(blocking_state);

down_read() can sleep and also modify the task state, we cannot take the
lock after that point because otherwise the task state will be messed up.


OK, how about:

/*
* Take the vma lock now, in order to safely call
* userfaultfd_huge_must_wait() a little bit later. Because acquiring
* the (sleepable) vma lock potentially modifies the current task state,
* that must be before explicitly calling set_current_state().
*/

Other than that, the patch looks good, so:

Reviewed-by: John Hubbard <jhubbard@xxxxxxxxxx>

thanks,
--
John Hubbard
NVIDIA