All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrey Ryabinin <a.ryabinin@samsung.com>
To: Sasha Levin <sasha.levin@oracle.com>, akpm@linux-foundation.org
Cc: n-horiguchi@ah.jp.nec.com, aarcange@redhat.com, mgorman@suse.de,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH] mm, hugetlb: correct bit shift in hstate_sizelog
Date: Wed, 22 Oct 2014 09:42:46 +0400	[thread overview]
Message-ID: <544743D6.6040103@samsung.com> (raw)
In-Reply-To: <1413915307-20536-1-git-send-email-sasha.levin@oracle.com>

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.


>  }
>  
>  static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
> 

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

WARNING: multiple messages have this Message-ID (diff)
From: Andrey Ryabinin <a.ryabinin@samsung.com>
To: Sasha Levin <sasha.levin@oracle.com>, akpm@linux-foundation.org
Cc: n-horiguchi@ah.jp.nec.com, aarcange@redhat.com, mgorman@suse.de,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH] mm, hugetlb: correct bit shift in hstate_sizelog
Date: Wed, 22 Oct 2014 09:42:46 +0400	[thread overview]
Message-ID: <544743D6.6040103@samsung.com> (raw)
In-Reply-To: <1413915307-20536-1-git-send-email-sasha.levin@oracle.com>

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.


>  }
>  
>  static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
> 


  reply	other threads:[~2014-10-22  5:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-21 18:15 [PATCH] mm, hugetlb: correct bit shift in hstate_sizelog Sasha Levin
2014-10-21 18:15 ` Sasha Levin
2014-10-22  5:42 ` Andrey Ryabinin [this message]
2014-10-22  5:42   ` Andrey Ryabinin
2014-10-22 18:44   ` Andrew Morton
2014-10-22 18:44     ` Andrew Morton
2014-10-22 18:50     ` Sasha Levin
2014-10-22 18:50       ` Sasha Levin
2014-10-22 20:13       ` Andrew Morton
2014-10-22 20:13         ` Andrew Morton
2014-10-22 20:26         ` Andrey Ryabinin
2014-10-22 20:26           ` Andrey Ryabinin
2014-10-22 19:04     ` Andrey Ryabinin
2014-10-22 19:04       ` Andrey Ryabinin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=544743D6.6040103@samsung.com \
    --to=a.ryabinin@samsung.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=n-horiguchi@ah.jp.nec.com \
    --cc=sasha.levin@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.