Re: [RFC 6/8] userfaultfd: hook userfault handler to write protection fault

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 19, 2015 at 02:33:51PM -0800, Shaohua Li wrote:
> There are several cases write protection fault happens. It could be a write
> to zero page, swaped page or userfault write protected page. When the
> fault happens, there is no way to know if userfault write protect the
> page before. Here we just blindly issue a userfault notification for vma
> with VM_UFFD_WP regardless if app write protects it yet. Application
> should be ready to handle such wp fault.
> 
> Cc: Andrea Arcangeli <aarcange@xxxxxxxxxx>
> Cc: Pavel Emelyanov <xemul@xxxxxxxxxxxxx>
> Cc: Rik van Riel <riel@xxxxxxxxxx>
> Cc: Kirill A. Shutemov <kirill@xxxxxxxxxxxxx>
> Cc: Mel Gorman <mgorman@xxxxxxx>
> Cc: Hugh Dickins <hughd@xxxxxxxxxx>
> Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
> Signed-off-by: Shaohua Li <shli@xxxxxx>
> ---
>  mm/memory.c | 66 +++++++++++++++++++++++++++++++++++++++++++++----------------
>  1 file changed, 49 insertions(+), 17 deletions(-)
> 
> diff --git a/mm/memory.c b/mm/memory.c
> index deb679c..5d16a31 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -1994,10 +1994,11 @@ static inline int wp_page_reuse(struct mm_struct *mm,
>  			struct vm_area_struct *vma, unsigned long address,
>  			pte_t *page_table, spinlock_t *ptl, pte_t orig_pte,
>  			struct page *page, int page_mkwrite,
> -			int dirty_shared)
> +			int dirty_shared, unsigned int flags)
>  	__releases(ptl)
>  {
>  	pte_t entry;
> +	bool do_uffd = false;
>  	/*
>  	 * Clear the pages cpupid information as the existing
>  	 * information potentially belongs to a now completely
> @@ -2008,10 +2009,16 @@ static inline int wp_page_reuse(struct mm_struct *mm,
>  
>  	flush_cache_page(vma, address, pte_pfn(orig_pte));
>  	entry = pte_mkyoung(orig_pte);
> -	entry = maybe_mkwrite(pte_mkdirty(entry), vma);
> +	if (userfaultfd_wp(vma) && page) {
> +		entry = pte_mkdirty(entry);


Why do you pte_mkdirty() it makes no sense to me unless i am missing something.
In fact, IIRC, userfaultd is only concerning private anonymous vma so you should
only need to modify 3 places. do_anonymous_page(), do_swap_page() and do_wp_page()

You also want to hook in wp_huge_pmd() and __do_huge_pmd_anonymous_page() to
properly cover THP.

So i think you need to simplify this patch and make sure you handle THP properly.

Cheers,
Jérôme

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]