From: Michael Bringmann <mwb@linux.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
Gustavo Walbon <gwalbon@linux.ibm.com>,
Paul Mackerras <paulus@samba.org>
Subject: Re: [PATCH v2] Fix display of Maximum Memory
Date: Thu, 16 Jan 2020 17:52:13 -0600 [thread overview]
Message-ID: <bf5c536a-6ca4-0a1a-043d-69b002a34c17@linux.ibm.com> (raw)
In-Reply-To: <8736cg9cay.fsf@mpe.ellerman.id.au>
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
next prev parent reply other threads:[~2020-01-16 23:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2020-01-29 5:17 ` Michael Ellerman
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=bf5c536a-6ca4-0a1a-043d-69b002a34c17@linux.ibm.com \
--to=mwb@linux.ibm.com \
--cc=gwalbon@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=paulus@samba.org \
/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 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).