lkml.org 
[lkml]   [2022]   [Jul]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe:Re: [PATCH V3] mm: prevent page_frag_alloc() from corrupting the memory

At 2022-07-18 21:50:41, "Maurizio Lombardi" <mlombard@redhat.com> wrote:
>po 18. 7. 2022 v 15:14 odesílatel Chen Lin <chen45464546@163.com> napsal:
>> ----------------------------------------
>> If we can accept adding a branch to this process, why not add it at the beginning like below?
>> The below changes are also more in line with the definition of "page fragment",
>> which i mean the above changes may make the allocation of more than one page successful.
>>
>> index 7a28f7d..9d09ea5 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -5551,6 +5551,8 @@ void *page_frag_alloc_align(struct page_frag_cache *nc,
>>
>> offset = nc->offset - fragsz;
>> if (unlikely(offset < 0)) {
>> + if (unlikely(fragsz > PAGE_SIZE))
>> + return NULL;
>> page = virt_to_page(nc->va);
>>
>> if (!page_ref_sub_and_test(page, nc->pagecnt_bias))
>>
>
>This will make *all* page_frag_alloc() calls with fragsz > PAGE_SIZE
>fail, so it will
>basically break all those drivers that are relying on the current behaviour.
>With my patch it will return NULL only if the cache isn't big enough.
>
>Maurizio.

But the original intention of page frag interface is indeed to allocate memory
less than one page. It's not a good idea to complicate the definition of
"page fragment".

Furthermore, the patch above is easier to synchronize to lower versions.
\
 
 \ /
  Last update: 2022-07-18 16:41    [W:0.079 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site