lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20110628170953.GA3482@redhat.com>
Date:	Tue, 28 Jun 2011 20:09:53 +0300
From:	Gleb Natapov <gleb@...hat.com>
To:	Steven Rostedt <rostedt@...dmis.org>
Cc:	linux-kernel@...r.kernel.org, linux-mm@...ck.org,
	Andrew Morton <akpm@...ux-foundation.org>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Russell King <rmk+kernel@....linux.org.uk>,
	Thomas Gleixner <tglx@...utronix.de>,
	Peter Zijlstra <peterz@...radead.org>,
	Hugh Dickins <hughd@...gle.com>,
	Rik van Riel <riel@...hat.com>,
	Michel Lespinasse <walken@...gle.com>,
	Avi Kivity <avi@...hat.com>,
	Marcelo Tosatti <mtosatti@...hat.com>
Subject: Re: [PATCH 2/2] mm: Document handle_mm_fault()

On Tue, Jun 28, 2011 at 12:47:52PM -0400, Steven Rostedt wrote:
> From: Steven Rostedt <srostedt@...hat.com>
> 
> The function handle_mm_fault() is long overdue for comments.
> Adding a kernel doc header for the function and explaining the subtle
> use of the flags with respect to mmap_sem will prove useful in the
> future when others work with this code.
> 
> Russell King noticed that the code in arch/x86/mm/fault.c looked
> buggy as the do_page_fault() code would grab the mmap_sem multiple
> times without letting it go. But it only did this when the
> handle_mm_fault() would return VM_FAULT_RETRY.
> 
> Examining the code and reading the git change logs, it was discovered
> that commit d065bd810b6deb67d4897a14bfe21f8eb526ba99
>   mm: retry page fault when blocking on disk transfer
> added code to remove contention with the mmap_sem when the page_lock
> was being held for IO. As waiting on IO holding the mmap_sem can
> cause lots of contention between threads. The flag
> FAULT_FLAG_ALLOW_RETRY was added to let handle_mm_fault() know
> that it can safely release the mmap_sem.
> 
> Adding to the confusion here with handle_mm_fault(), another
>   commit 318b275fbca1ab9ec0862de71420e0e92c3d1aa7
>   mm: allow GUP to fail instead of waiting on a page
> was added that would not release the mmap_sem, even if
> FAULT_FLAG_ALLOW_RETRY was set and the page_lock was not taken
> and VM_FAULT_RETRY was returned, if FAULT_FLAGS_RETRY_NOWAIT was
> set.
> 
> All of this is poorly documented and makes using or modifying
> handle_mm_fault() fragile. Documenting all of these subtle changes
> at the head of handle_mm_fault() should help future developers
> understand what is happening.
> 
> Reported-by: Russell King <rmk+kernel@....linux.org.uk>
> Cc: Gleb Natapov <gleb@...hat.com>
> Cc: Linus Torvalds <torvalds@...ux-foundation.org>
> Cc: Hugh Dickins <hughd@...gle.com>
> Cc: Rik van Riel <riel@...hat.com>
> Cc: Michel Lespinasse <walken@...gle.com>
> Cc: Avi Kivity <avi@...hat.com>
> Cc: Marcelo Tosatti <mtosatti@...hat.com>
> Cc: Andrew Morton <akpm@...ux-foundation.org>
> Signed-off-by: Steven Rostedt <rostedt@...dmis.org>
> ---
>  mm/memory.c |   22 ++++++++++++++++++++--
>  1 files changed, 20 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/memory.c b/mm/memory.c
> index 5371b5e..3cf30f6 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -3378,8 +3378,26 @@ unlock:
>  	return 0;
>  }
>  
> -/*
> - * By the time we get here, we already hold the mm semaphore
> +/**
> + * handle_mm_fault - main routine for handling page faults
> + * @mm:		the mm_struct of the target address space
> + * @vma:	vm_area_struct holding the applicable pages
> + * @address:	the address that took the fault
> + * @flags:	flags modifying lookup behaviour
> + *
> + * Must have @mm->mmap_sem held.
> + *
> + * Note: if @flags has FAULT_FLAG_ALLOW_RETRY set then the mmap_sem
> + *       may be released if it failed to arquire the page_lock. If the
> + *       mmap_sem is released then it will return VM_FAULT_RETRY set.
> + *       This is to keep the time mmap_sem is held when the page_lock
> + *       is taken for IO.
> + * Exception: If FAULT_FLAG_RETRY_NOWAIT is set, then it will
> + *       not release the mmap_sem, but will still return VM_FAULT_RETRY
> + *       if it failed to acquire the page_lock.
I wouldn't describe it like that. It tells handle_mm_fault() to start
IO if needed, but do not wait for its completion.

> + *       This is for helping virtualization. See get_user_page_nowait().
The virtialization is the only user right now, but I wouldn't describe
this flag as virtialization specific. Why should we put this in the
comment?  The comment will become outdated when other users arise
and meanwhile a simple grep will reveal the above information anyway.

> + *
> + * Returns status flags based on the VM_FAULT_* flags in <linux/mm.h>
>   */
>  int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
>  		unsigned long address, unsigned int flags)
> -- 
> 1.7.5.4
> 

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ