lkml.org 
[lkml]   [2013]   [Sep]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC PATCH RESEND] mm: munlock: Prevent walking off the end of a pagetable in no-pmd configuration
On 09/18/2013 03:17 AM, Bob Liu wrote:
> On 09/17/2013 10:22 PM, Vlastimil Babka wrote:

>> --- a/mm/mlock.c
>> +++ b/mm/mlock.c
>> @@ -379,10 +379,14 @@ static unsigned long __munlock_pagevec_fill(struct pagevec *pvec,
>>
>> /*
>> * Initialize pte walk starting at the already pinned page where we
>> - * are sure that there is a pte.
>> + * are sure that there is a pte, as it was pinned under the same
>> + * mmap_sem write op.
>> */
>> pte = get_locked_pte(vma->vm_mm, start, &ptl);
>> - end = min(end, pmd_addr_end(start, end));
>> + /* Make sure we do not cross the page table boundary */
>> + end = pgd_addr_end(start, end);
>> + end = pud_addr_end(start, end);
>> + end = pmd_addr_end(start, end);
>>
>
> Nitpick, how about unfolding pmd_addr_end(start, end) directly? Like:
>
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -376,13 +376,14 @@ static unsigned long __munlock_pagevec_fill(struct
> pagevec *pvec,
> {
> pte_t *pte;
> spinlock_t *ptl;
> + unsigned long pmd_end = (start + PMD_SIZE) & PMD_MASK;
> + end = (pmd_end - 1 < end - 1) ? pmd_end : end;
>
> /*
> * Initialize pte walk starting at the already pinned page where we
> * are sure that there is a pte.
> */
> pte = get_locked_pte(vma->vm_mm, start, &ptl);
> - end = min(end, pmd_addr_end(start, end));
>
> /* The page next to the pinned page is the first we will try to
> get */
> start += PAGE_SIZE;
>

That should also work but for maintainability reasons I wouldn't like to
special case it like this, instead of using standard functions as they
would be used in a full pagewalk.

> Anyway,
> Reviewed-by: Bob Liu <bob.liu@oracle.com>

Thanks.

Vlastimil




\
 
 \ /
  Last update: 2013-09-20 11:21    [W:0.072 / U:1.684 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site