Re: [PATCH 1/2] mm: bring in additional flag for fixup_user_fault to signal unlock

From: Andrea Arcangeli
Date: Fri Dec 04 2015 - 16:51:31 EST


On Thu, Nov 26, 2015 at 06:27:01PM +0100, Dominik Dingel wrote:
> @@ -599,6 +603,10 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
> if (!(vm_flags & vma->vm_flags))
> return -EFAULT;
>
> + if (unlocked)
> + fault_flags |= FAULT_FLAG_ALLOW_RETRY;
> +
> +retry:

This should move up before find_extend_vma, otherwise the vma used
below could be a dangling pointer after the "goto retry".

> ret = handle_mm_fault(mm, vma, address, fault_flags);
> if (ret & VM_FAULT_ERROR) {
> if (ret & VM_FAULT_OOM)
> @@ -609,12 +617,21 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
> return -EFAULT;
> BUG();
> }
> - if (tsk) {
> + if (tsk && !(fault_flags & FAULT_FLAG_TRIED)) {
> if (ret & VM_FAULT_MAJOR)
> tsk->maj_flt++;
> else
> tsk->min_flt++;
> }

It'd look cleaner if we'd move the tsk update after the retry check in
case the FAULT_FLAG_TRIED second attempt actually fails, to avoid
recording a fault for a non-really-faulting VM_FAULT_RETRY
attempt. This is what the real page fault does at least so it sounds
cleaner do the same here, but then in practice it makes very little
difference.

> + if (ret & VM_FAULT_RETRY) {
> + down_read(&mm->mmap_sem);
> + if (!(fault_flags & FAULT_FLAG_TRIED)) {
> + *unlocked = true;
> + fault_flags &= ~FAULT_FLAG_ALLOW_RETRY;
> + fault_flags |= FAULT_FLAG_TRIED;
> + goto retry;
> + }
> + }
> return 0;
> }

Rest looks great.

The futex.c should be patched to pass the unlocked pointer in a later
patch but we can also postpone it to a different patchset.

Thanks,
Andrea
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/