linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Fix display of Maximum Memory
@ 2020-01-15 14:53 Michael Bringmann
  2020-01-15 14:55 ` Christophe Leroy
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Michael Bringmann @ 2020-01-15 14:53 UTC (permalink / raw)
  To: linuxppc-dev, linux-kernel, Michael Ellerman, Gustavo Walbon,
	Paul Mackerras

Correct overflow problem in calculation+display of Maximum Memory
value to syscfg where 32bits is insufficient.

Signed-off-by: Michael Bringmann <mwb@linux.ibm.com>
---
 arch/powerpc/platforms/pseries/lparcfg.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/lparcfg.c b/arch/powerpc/platforms/pseries/lparcfg.c
index e33e8bc..f00411c 100644
--- a/arch/powerpc/platforms/pseries/lparcfg.c
+++ b/arch/powerpc/platforms/pseries/lparcfg.c
@@ -433,12 +433,12 @@ static void parse_em_data(struct seq_file *m)
 
 static void maxmem_data(struct seq_file *m)
 {
-	unsigned long maxmem = 0;
+	u64 maxmem = 0;
 
-	maxmem += drmem_info->n_lmbs * drmem_info->lmb_size;
-	maxmem += hugetlb_total_pages() * PAGE_SIZE;
+	maxmem += (u64)drmem_info->n_lmbs * drmem_info->lmb_size;
+	maxmem += (u64)hugetlb_total_pages() * PAGE_SIZE;
 
-	seq_printf(m, "MaxMem=%ld\n", maxmem);
+	seq_printf(m, "MaxMem=%llu\n", maxmem);
 }
 
 static int pseries_lparcfg_data(struct seq_file *m, void *v)
-- 
1.8.3.1


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

* Re: [PATCH v2] Fix display of Maximum Memory
  2020-01-15 14:53 [PATCH v2] Fix display of Maximum Memory Michael Bringmann
@ 2020-01-15 14:55 ` Christophe Leroy
  2020-01-16  0:07 ` Tyrel Datwyler
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Christophe Leroy @ 2020-01-15 14:55 UTC (permalink / raw)
  To: Michael Bringmann, linuxppc-dev, linux-kernel, Michael Ellerman,
	Gustavo Walbon, Paul Mackerras



Le 15/01/2020 à 15:53, Michael Bringmann a écrit :
> Correct overflow problem in calculation+display of Maximum Memory
> value to syscfg where 32bits is insufficient.
> 
> Signed-off-by: Michael Bringmann <mwb@linux.ibm.com>

Reviewed-by: Christophe Leroy <christophe.leroy@c-s.fr>

> ---
>   arch/powerpc/platforms/pseries/lparcfg.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/pseries/lparcfg.c b/arch/powerpc/platforms/pseries/lparcfg.c
> index e33e8bc..f00411c 100644
> --- a/arch/powerpc/platforms/pseries/lparcfg.c
> +++ b/arch/powerpc/platforms/pseries/lparcfg.c
> @@ -433,12 +433,12 @@ static void parse_em_data(struct seq_file *m)
>   
>   static void maxmem_data(struct seq_file *m)
>   {
> -	unsigned long maxmem = 0;
> +	u64 maxmem = 0;
>   
> -	maxmem += drmem_info->n_lmbs * drmem_info->lmb_size;
> -	maxmem += hugetlb_total_pages() * PAGE_SIZE;
> +	maxmem += (u64)drmem_info->n_lmbs * drmem_info->lmb_size;
> +	maxmem += (u64)hugetlb_total_pages() * PAGE_SIZE;
>   
> -	seq_printf(m, "MaxMem=%ld\n", maxmem);
> +	seq_printf(m, "MaxMem=%llu\n", maxmem);
>   }
>   
>   static int pseries_lparcfg_data(struct seq_file *m, void *v)
> 

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

* Re: [PATCH v2] Fix display of Maximum Memory
  2020-01-15 14:53 [PATCH v2] Fix display of Maximum Memory Michael Bringmann
  2020-01-15 14:55 ` Christophe Leroy
@ 2020-01-16  0:07 ` Tyrel Datwyler
  2020-01-16  5:53 ` Michael Ellerman
  2020-01-29  5:17 ` Michael Ellerman
  3 siblings, 0 replies; 6+ messages in thread
From: Tyrel Datwyler @ 2020-01-16  0:07 UTC (permalink / raw)
  To: Michael Bringmann, linuxppc-dev, linux-kernel, Michael Ellerman,
	Gustavo Walbon, Paul Mackerras

On 1/15/20 6:53 AM, Michael Bringmann wrote:
> Correct overflow problem in calculation+display of Maximum Memory
> value to syscfg where 32bits is insufficient.
> 

Probably needs the following Fixes tag:

Fixes: 772b039fd9a7 ("powerpc/pseries: Export maximum memory value")

otherwise,

Reviewed-by: Tyrel Datwyler <tyreld@linux.ibm.com>

> Signed-off-by: Michael Bringmann <mwb@linux.ibm.com>
> ---
>  arch/powerpc/platforms/pseries/lparcfg.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/pseries/lparcfg.c b/arch/powerpc/platforms/pseries/lparcfg.c
> index e33e8bc..f00411c 100644
> --- a/arch/powerpc/platforms/pseries/lparcfg.c
> +++ b/arch/powerpc/platforms/pseries/lparcfg.c
> @@ -433,12 +433,12 @@ static void parse_em_data(struct seq_file *m)
> 
>  static void maxmem_data(struct seq_file *m)
>  {
> -	unsigned long maxmem = 0;
> +	u64 maxmem = 0;
> 
> -	maxmem += drmem_info->n_lmbs * drmem_info->lmb_size;
> -	maxmem += hugetlb_total_pages() * PAGE_SIZE;
> +	maxmem += (u64)drmem_info->n_lmbs * drmem_info->lmb_size;
> +	maxmem += (u64)hugetlb_total_pages() * PAGE_SIZE;
> 
> -	seq_printf(m, "MaxMem=%ld\n", maxmem);
> +	seq_printf(m, "MaxMem=%llu\n", maxmem);
>  }
> 
>  static int pseries_lparcfg_data(struct seq_file *m, void *v)
> 


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

* Re: [PATCH v2] Fix display of Maximum Memory
  2020-01-15 14:53 [PATCH v2] Fix display of Maximum Memory Michael Bringmann
  2020-01-15 14:55 ` Christophe Leroy
  2020-01-16  0:07 ` Tyrel Datwyler
@ 2020-01-16  5:53 ` Michael Ellerman
  2020-01-16 23:52   ` Michael Bringmann
  2020-01-29  5:17 ` Michael Ellerman
  3 siblings, 1 reply; 6+ messages in thread
From: Michael Ellerman @ 2020-01-16  5:53 UTC (permalink / raw)
  To: Michael Bringmann, linuxppc-dev, linux-kernel, Gustavo Walbon,
	Paul Mackerras

Michael Bringmann <mwb@linux.ibm.com> writes:
> Correct overflow problem in calculation+display of Maximum Memory
> value to syscfg where 32bits is insufficient.
>
> Signed-off-by: Michael Bringmann <mwb@linux.ibm.com>
> ---
>  arch/powerpc/platforms/pseries/lparcfg.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/arch/powerpc/platforms/pseries/lparcfg.c b/arch/powerpc/platforms/pseries/lparcfg.c
> index e33e8bc..f00411c 100644
> --- a/arch/powerpc/platforms/pseries/lparcfg.c
> +++ b/arch/powerpc/platforms/pseries/lparcfg.c
> @@ -433,12 +433,12 @@ static void parse_em_data(struct seq_file *m)
>  
>  static void maxmem_data(struct seq_file *m)
>  {
> -	unsigned long maxmem = 0;
> +	u64 maxmem = 0;

This is 64-bit only code, so u64 == unsigned long.

> -	maxmem += drmem_info->n_lmbs * drmem_info->lmb_size;
> -	maxmem += hugetlb_total_pages() * PAGE_SIZE;
> +	maxmem += (u64)drmem_info->n_lmbs * drmem_info->lmb_size;

The only problem AFAICS is n_lmbs is int and lmb_size is u32, so this
multiplication will overflow.

> +	maxmem += (u64)hugetlb_total_pages() * PAGE_SIZE;

hugetlb_total_pages() already returns unsigned long.

> -	seq_printf(m, "MaxMem=%ld\n", maxmem);
> +	seq_printf(m, "MaxMem=%llu\n", maxmem);
>  }

This should be sufficient?

diff --git a/arch/powerpc/platforms/pseries/lparcfg.c b/arch/powerpc/platforms/pseries/lparcfg.c
index e33e8bc4b69b..38c306551f76 100644
--- a/arch/powerpc/platforms/pseries/lparcfg.c
+++ b/arch/powerpc/platforms/pseries/lparcfg.c
@@ -435,10 +435,10 @@ static void maxmem_data(struct seq_file *m)
 {
        unsigned long maxmem = 0;
 
-       maxmem += drmem_info->n_lmbs * drmem_info->lmb_size;
+       maxmem += (unsigned long)drmem_info->n_lmbs * drmem_info->lmb_size;
        maxmem += hugetlb_total_pages() * PAGE_SIZE;
 
-       seq_printf(m, "MaxMem=%ld\n", maxmem);
+       seq_printf(m, "MaxMem=%lu\n", maxmem);
 }
 
 static int pseries_lparcfg_data(struct seq_file *m, void *v)


cheers

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

* Re: [PATCH v2] Fix display of Maximum Memory
  2020-01-16  5:53 ` Michael Ellerman
@ 2020-01-16 23:52   ` Michael Bringmann
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Bringmann @ 2020-01-16 23:52 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev, linux-kernel, Gustavo Walbon,
	Paul Mackerras

On 1/15/20 11:53 PM, Michael Ellerman wrote:
> Michael Bringmann <mwb@linux.ibm.com> writes:
>> Correct overflow problem in calculation+display of Maximum Memory
>> value to syscfg where 32bits is insufficient.
>>
>> Signed-off-by: Michael Bringmann <mwb@linux.ibm.com>
>> ---
>>  arch/powerpc/platforms/pseries/lparcfg.c | 8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/powerpc/platforms/pseries/lparcfg.c b/arch/powerpc/platforms/pseries/lparcfg.c
>> index e33e8bc..f00411c 100644
>> --- a/arch/powerpc/platforms/pseries/lparcfg.c
>> +++ b/arch/powerpc/platforms/pseries/lparcfg.c
>> @@ -433,12 +433,12 @@ static void parse_em_data(struct seq_file *m)
>>  
>>  static void maxmem_data(struct seq_file *m)
>>  {
>> -	unsigned long maxmem = 0;
>> +	u64 maxmem = 0;
> 
> This is 64-bit only code, so u64 == unsigned long.
> 
>> -	maxmem += drmem_info->n_lmbs * drmem_info->lmb_size;
>> -	maxmem += hugetlb_total_pages() * PAGE_SIZE;
>> +	maxmem += (u64)drmem_info->n_lmbs * drmem_info->lmb_size;
> 
> The only problem AFAICS is n_lmbs is int and lmb_size is u32, so this
> multiplication will overflow.
> 
>> +	maxmem += (u64)hugetlb_total_pages() * PAGE_SIZE;
> 
> hugetlb_total_pages() already returns unsigned long.
> 
>> -	seq_printf(m, "MaxMem=%ld\n", maxmem);
>> +	seq_printf(m, "MaxMem=%llu\n", maxmem);
>>  }
> 
> This should be sufficient?
> 
> diff --git a/arch/powerpc/platforms/pseries/lparcfg.c b/arch/powerpc/platforms/pseries/lparcfg.c
> index e33e8bc4b69b..38c306551f76 100644
> --- a/arch/powerpc/platforms/pseries/lparcfg.c
> +++ b/arch/powerpc/platforms/pseries/lparcfg.c
> @@ -435,10 +435,10 @@ static void maxmem_data(struct seq_file *m)
>  {
>         unsigned long maxmem = 0;
>  
> -       maxmem += drmem_info->n_lmbs * drmem_info->lmb_size;
> +       maxmem += (unsigned long)drmem_info->n_lmbs * drmem_info->lmb_size;
>         maxmem += hugetlb_total_pages() * PAGE_SIZE;
>  
> -       seq_printf(m, "MaxMem=%ld\n", maxmem);
> +       seq_printf(m, "MaxMem=%lu\n", maxmem);
>  }
>  
>  static int pseries_lparcfg_data(struct seq_file *m, void *v)
> 
> 
> cheers
> 

Trying it out.

-- 
Michael W. Bringmann
Linux Technology Center
IBM Corporation
Tie-Line  363-5196
External: (512) 286-5196
Cell:       (512) 466-0650
mwb@linux.ibm.com

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

* Re: [PATCH v2] Fix display of Maximum Memory
  2020-01-15 14:53 [PATCH v2] Fix display of Maximum Memory Michael Bringmann
                   ` (2 preceding siblings ...)
  2020-01-16  5:53 ` Michael Ellerman
@ 2020-01-29  5:17 ` Michael Ellerman
  3 siblings, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2020-01-29  5:17 UTC (permalink / raw)
  To: Michael Bringmann, linuxppc-dev, linux-kernel, Gustavo Walbon,
	Paul Mackerras

On Wed, 2020-01-15 at 14:53:59 UTC, Michael Bringmann wrote:
> Correct overflow problem in calculation+display of Maximum Memory
> value to syscfg where 32bits is insufficient.
> 
> Signed-off-by: Michael Bringmann <mwb@linux.ibm.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/f1dbc1c5c70d0d4c60b5d467ba941fba167c12f6

cheers

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

end of thread, other threads:[~2020-01-29  5:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15 14:53 [PATCH v2] Fix display of Maximum Memory Michael Bringmann
2020-01-15 14:55 ` Christophe Leroy
2020-01-16  0:07 ` Tyrel Datwyler
2020-01-16  5:53 ` Michael Ellerman
2020-01-16 23:52   ` Michael Bringmann
2020-01-29  5:17 ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).