Fix display of Maximum Memory
PATCH v2 1/1 Fix display of Maximum Memory
Correct overflow problem in calculation+display of Maximum Memory value to syscfg where 32bits is insufficient.
--- arch/powerpc/platforms/pseries/lparcfg.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/powerpc/platforms/pseries/lparcfg.c +4 -4
@@ -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)
Signature · 1 line
1.8.3.1
Le 15/01/2020 à 15:53, Michael Bringmann a écrit :
Quoted 4 lines
Correct overflow problem in calculation+display of Maximum Memory value to syscfg where 32bits is insufficient.
Signed-off-by Michael Bringmann <[email protected]>
Quoted 26 lines
--- arch/powerpc/platforms/pseries/lparcfg.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)arch/powerpc/platforms/pseries/lparcfg.c +4
-4@@ -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)
Quoted 3 lines · Michael Bringmann
Correct overflow problem in calculation+display of Maximum Memory value to syscfg where 32bits is insufficient.
Probably needs the following Fixes tag:
otherwise,
Quoted 27 lines
Signed-off-by Michael Bringmann <[email protected]>--- arch/powerpc/platforms/pseries/lparcfg.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)arch/powerpc/platforms/pseries/lparcfg.c +4
-4@@ -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)
Michael Ellerman
reviewerQuoted 13 lines · Michael Bringmann
Correct overflow problem in calculation+display of Maximum Memory value to syscfg where 32bits is insufficient.
Signed-off-by Michael Bringmann <[email protected]>--- arch/powerpc/platforms/pseries/lparcfg.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)arch/powerpc/platforms/pseries/lparcfg.c +0
-0
arch/powerpc/platforms/pseries/lparcfg.c static void parse_em_data(struct seq_file *m) · line 436
Quoted 5 lines
arch/powerpc/platforms/pseries/lparcfg.c +1
-1@@ -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.
arch/powerpc/platforms/pseries/lparcfg.c static void parse_em_data(struct seq_file *m) · line 437
Quoted 3 lines
arch/powerpc/platforms/pseries/lparcfg.c +1
-2- 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.
arch/powerpc/platforms/pseries/lparcfg.c static void parse_em_data(struct seq_file *m) · line 438
Quoted 1 line
arch/powerpc/platforms/pseries/lparcfg.c +1
-0+ maxmem += (u64 )hugetlb_total_pages () *PAGE_SIZE ;
hugetlb_total_pages() already returns unsigned long.
arch/powerpc/platforms/pseries/lparcfg.c static void parse_em_data(struct seq_file *m) · line 440
Quoted 3 lines
arch/powerpc/platforms/pseries/lparcfg.c +1
-1-seq_printf (m,"MaxMem=%ld\n" , maxmem); +seq_printf (m,"MaxMem=%llu\n" , maxmem); }
This should be sufficient?
arch/powerpc/platforms/pseries/lparcfg.c +2 -2
@@ -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
Quoted 58 lines · Michael Ellerman
Quoted 13 lines · Michael Bringmann
Correct overflow problem in calculation+display of Maximum Memory value to syscfg where 32bits is insufficient.
Signed-off-by Michael Bringmann <[email protected]>--- arch/powerpc/platforms/pseries/lparcfg.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)arch/powerpc/platforms/pseries/lparcfg.c +0
-0arch/powerpc/platforms/pseries/lparcfg.c static void parse_em_data(struct seq_file *m) · line 436
Quoted 5 lines
arch/powerpc/platforms/pseries/lparcfg.c +1
-1@@ -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.
arch/powerpc/platforms/pseries/lparcfg.c static void parse_em_data(struct seq_file *m) · line 437
Quoted 3 lines
arch/powerpc/platforms/pseries/lparcfg.c +1
-2- 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_lmbsis int andlmb_sizeis u32, so this multiplication will overflow.arch/powerpc/platforms/pseries/lparcfg.c static void parse_em_data(struct seq_file *m) · line 438
Quoted 1 line
arch/powerpc/platforms/pseries/lparcfg.c +1
-0+ maxmem += (u64 )hugetlb_total_pages () *PAGE_SIZE ;
hugetlb_total_pages()already returns unsigned long.arch/powerpc/platforms/pseries/lparcfg.c static void maxmem_data(struct seq_file *m) · line 442
Quoted 3 lines
arch/powerpc/platforms/pseries/lparcfg.c +1
-1-seq_printf (m,"MaxMem=%ld\n" , maxmem); +seq_printf (m,"MaxMem=%llu\n" , maxmem); }This should be sufficient?
arch/powerpc/platforms/pseries/lparcfg.c +2
-2@@ -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)
Quoted 2 lines
cheers
Trying it out.
Signature · 7 lines
Michael W. Bringmann Linux Technology Center IBM Corporation Tie-Line 363-5196 External: (512) 286-5196 Cell: (512) 466-0650 [email protected]
Michael Ellerman
AppliedQuoted 4 lines · Michael Bringmann
Correct overflow problem in calculation+display of Maximum Memory value to syscfg where 32bits is insufficient.
Signed-off-by Michael Bringmann <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/f1dbc1c5c70d0d4c60b5d467ba941fba167c12f6
cheers