lkml.org 
[lkml]   [2014]   [Oct]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] mm, hugetlb: correct bit shift in hstate_sizelog
From
2014-10-22 22:44 GMT+04:00 Andrew Morton <akpm@linux-foundation.org>:
> On Wed, 22 Oct 2014 09:42:46 +0400 Andrey Ryabinin <a.ryabinin@samsung.com> wrote:
>
>> On 10/21/2014 10:15 PM, Sasha Levin wrote:
>> > hstate_sizelog() would shift left an int rather than long, triggering
>> > undefined behaviour and passing an incorrect value when the requested
>> > page size was more than 4GB, thus breaking >4GB pages.
>>
>> >
>> > Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
>> > ---
>> > include/linux/hugetlb.h | 3 ++-
>> > 1 file changed, 2 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
>> > index 65e12a2..57e0dfd 100644
>> > --- a/include/linux/hugetlb.h
>> > +++ b/include/linux/hugetlb.h
>> > @@ -312,7 +312,8 @@ static inline struct hstate *hstate_sizelog(int page_size_log)
>> > {
>> > if (!page_size_log)
>> > return &default_hstate;
>> > - return size_to_hstate(1 << page_size_log);
>> > +
>> > + return size_to_hstate(1UL << page_size_log);
>>
>> That still could be undefined on 32-bits. Either use 1ULL or reduce SHM_HUGE_MASK on 32bits.
>>
>
> But
>
> struct hstate *size_to_hstate(unsigned long size)
>

What's wrong? On 32 bits, if page_size_log >= 32, then (unsingned
long)(1ULL << page_size_log) will be truncated to 0. I guess it's ok.
size_to_hstate will just return NULL in that case.


--
Best regards,
Andrey Ryabinin


\
 
 \ /
  Last update: 2014-10-22 21:41    [W:0.068 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site