public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix an overflow in range_to_mtrr func
@ 2012-05-28 12:29 Zhenzhong Duan
  2012-05-29 17:18 ` Yinghai Lu
  0 siblings, 1 reply; 4+ messages in thread
From: Zhenzhong Duan @ 2012-05-28 12:29 UTC (permalink / raw)
  To: mingo, x86, yinghai, tglx, hpa; +Cc: Feng Jin, ethan.zhao, linux-kernel

When boot x86_64 kernel on sun G5+ with 4T mem, see an overflow in mtrr cleanup as below.

*BAD*gran_size: 2G      chunk_size: 2G  num_reg: 10     lose cover RAM:
-18014398505283592M

This is because 1<<31 sign extended.
Use explicit type conversion to force a 64bit constant to fix it.
Useful for mem larger than or equal to 4T.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
---
 arch/x86/kernel/cpu/mtrr/cleanup.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/cleanup.c
index ac140c7..853a4c6 100644
--- a/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -266,7 +266,7 @@ range_to_mtrr(unsigned int reg, unsigned long range_startk,
 		if (align > max_align)
 			align = max_align;
 
-		sizek = 1 << align;
+		sizek = (unsigned long)1 << align;
 		if (debug_print) {
 			char start_factor = 'K', size_factor = 'K';
 			unsigned long start_base, size_base;
-- 
1.7.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix an overflow in range_to_mtrr func
  2012-05-28 12:29 [PATCH] Fix an overflow in range_to_mtrr func Zhenzhong Duan
@ 2012-05-29 17:18 ` Yinghai Lu
  2012-05-30  4:52   ` [PATCH v2] " zhenzhong.duan
  0 siblings, 1 reply; 4+ messages in thread
From: Yinghai Lu @ 2012-05-29 17:18 UTC (permalink / raw)
  To: Zhenzhong Duan; +Cc: mingo, x86, tglx, hpa, Feng Jin, ethan.zhao, linux-kernel

On Mon, May 28, 2012 at 5:29 AM, Zhenzhong Duan
<zhenzhong.duan@oracle.com> wrote:
> When boot x86_64 kernel on sun G5+ with 4T mem, see an overflow in mtrr cleanup as below.
>
> *BAD*gran_size: 2G      chunk_size: 2G  num_reg: 10     lose cover RAM:
> -18014398505283592M
>
> This is because 1<<31 sign extended.
> Use explicit type conversion to force a 64bit constant to fix it.
> Useful for mem larger than or equal to 4T.
>
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
> ---
>  arch/x86/kernel/cpu/mtrr/cleanup.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/cleanup.c
> index ac140c7..853a4c6 100644
> --- a/arch/x86/kernel/cpu/mtrr/cleanup.c
> +++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
> @@ -266,7 +266,7 @@ range_to_mtrr(unsigned int reg, unsigned long range_startk,
>                if (align > max_align)
>                        align = max_align;
>
> -               sizek = 1 << align;
> +               sizek = (unsigned long)1 << align;

how about

            sizek = 1UL << align;


>                if (debug_print) {
>                        char start_factor = 'K', size_factor = 'K';
>                        unsigned long start_base, size_base;
> --
> 1.7.3
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] Fix an overflow in range_to_mtrr func
  2012-05-29 17:18 ` Yinghai Lu
@ 2012-05-30  4:52   ` zhenzhong.duan
  2012-05-30 23:22     ` [tip:x86/urgent] x86, mtrr: Fix a type " tip-bot for zhenzhong.duan
  0 siblings, 1 reply; 4+ messages in thread
From: zhenzhong.duan @ 2012-05-30  4:52 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: zhenzhong.duan, mingo, x86, tglx, hpa, Feng Jin, ethan.zhao,
	linux-kernel

When boot on sun G5+ with 4T mem, see an overflow in mtrr cleanup as below.

*BAD*gran_size: 2G      chunk_size: 2G  num_reg: 10     lose cover RAM:
-18014398505283592M

This is because 1<<31 sign extended. Use 64bit constant to fix it.
Useful for mem larger than or equal to 4T.

-v2: Use 64bit constant instead of explicit type conversion as suggested
by Yinghai. Description updated too.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
---
  arch/x86/kernel/cpu/mtrr/cleanup.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c
b/arch/x86/kernel/cpu/mtrr/cleanup.c
index ac140c7..853a4c6 100644
--- a/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -266,7 +266,7 @@ range_to_mtrr(unsigned int reg, unsigned long
range_startk,
  		if (align > max_align)
  			align = max_align;

-		sizek = 1 << align;
+		sizek = 1UL << align;
  		if (debug_print) {
  			char start_factor = 'K', size_factor = 'K';
  			unsigned long start_base, size_base;
-- 1.7.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [tip:x86/urgent] x86, mtrr: Fix a type overflow in range_to_mtrr func
  2012-05-30  4:52   ` [PATCH v2] " zhenzhong.duan
@ 2012-05-30 23:22     ` tip-bot for zhenzhong.duan
  0 siblings, 0 replies; 4+ messages in thread
From: tip-bot for zhenzhong.duan @ 2012-05-30 23:22 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, zhenzhong.duan, tglx

Commit-ID:  2da06af8106f8f35318bb084baf8448797ef058a
Gitweb:     http://git.kernel.org/tip/2da06af8106f8f35318bb084baf8448797ef058a
Author:     zhenzhong.duan <zhenzhong.duan@oracle.com>
AuthorDate: Wed, 30 May 2012 12:52:15 +0800
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Wed, 30 May 2012 14:37:00 -0700

x86, mtrr: Fix a type overflow in range_to_mtrr func

When boot on sun G5+ with 4T mem, see an overflow in mtrr cleanup as below.

*BAD*gran_size: 2G      chunk_size: 2G  num_reg: 10     lose cover RAM:
-18014398505283592M

This is because 1<<31 sign extended. Use an unsigned long constant to
fix it.  Useful for mem larger than or equal to 4T.

-v2: Use 64bit constant instead of explicit type conversion as suggested
by Yinghai. Description updated too.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
Link: http://lkml.kernel.org/r/4FC5A77F.6060505@oracle.com
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 arch/x86/kernel/cpu/mtrr/cleanup.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/cleanup.c
index ac140c7..bdda2e6 100644
--- a/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -266,7 +266,7 @@ range_to_mtrr(unsigned int reg, unsigned long range_startk,
 		if (align > max_align)
 			align = max_align;
 
-		sizek = 1 << align;
+		sizek = 1UL << align;
 		if (debug_print) {
 			char start_factor = 'K', size_factor = 'K';
 			unsigned long start_base, size_base;

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-05-30 23:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-28 12:29 [PATCH] Fix an overflow in range_to_mtrr func Zhenzhong Duan
2012-05-29 17:18 ` Yinghai Lu
2012-05-30  4:52   ` [PATCH v2] " zhenzhong.duan
2012-05-30 23:22     ` [tip:x86/urgent] x86, mtrr: Fix a type " tip-bot for zhenzhong.duan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox