Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8562432ybl; Thu, 16 Jan 2020 19:39:57 -0800 (PST) X-Google-Smtp-Source: APXvYqyzcj7ERNdDV4NFcAcxZsMsAtPuXVjsCbYcHrztR0swFn65gHMNTY2cbMUsxEFl1IO5EatV X-Received: by 2002:a9d:730e:: with SMTP id e14mr4522853otk.62.1579232397030; Thu, 16 Jan 2020 19:39:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579232397; cv=none; d=google.com; s=arc-20160816; b=Wto7zw/63oz1LH6NPxkBwJUlLPaTsc4q+JuinR72vewE9KVdrRZIs+rjfoF5l+4xD4 YAHPGUwEEYsMPJ5c8oGhDYEKjXOjzLRZkeyEvfnzZlZeztw3LhchtDSmJthdZAVE5nWL 6igz27ZyK7J9lZokNLXETLO6XKO0AVOtMliN7rWfWN1Pp9tTVg8aIXWhQOONbRtnhIuj JFj67sRHdaCbLilINKB8x7O3lLSXsKL+S6NFugaSEvsh+aEa1NVCWEGjdyVlgTIct5fa 0LWgQYwPDUvGtNWIfuXUB2zi4A/iIGeDO8ZpgiZp4T3GPgiXcC/JjGT7X8DwS5AxFk7F kIhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:openpgp:from:references:to:subject; bh=05YwRi0i+aAsvfImtV49K0OaJDM+LSEShmufWwJUU54=; b=xePzOkykEDen/kzKMLmEnq9gzLTju/W6EqIbEcfwK+KQ9ur0BCo+c56QU3c59DynwB HJcMBm20HbNWplR15kEN2/0vSOxDp4gO+HfU1BrDqfzsaSGg1IicieAbx3elV7ukFA8I gpDCLqzcj/PMkhJIowDYlMhAIJNkp+m0cYdpJYTTx5bE56dYtR13VnCnfRuyX/Ik9lcO WhshlCwOyHtModr78BjaZYtfeiKRVPym5bZ+Ghm2JGIVuSiqDcs+VF4q2BOWgiRrHYj4 dRb5LovSt5QrtrmD+NPkZeMmNBM4fUlzLJuCw4TZbrOKA0ulRIYOOCB9Q4P+wG/N3AUL 5iCQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m7si12444974oih.7.2020.01.16.19.39.44; Thu, 16 Jan 2020 19:39:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387531AbgAPXwe (ORCPT + 99 others); Thu, 16 Jan 2020 18:52:34 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37038 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729565AbgAPXwd (ORCPT ); Thu, 16 Jan 2020 18:52:33 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 00GNbqqp011853; Thu, 16 Jan 2020 18:52:18 -0500 Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com with ESMTP id 2xk0qs1p3p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Jan 2020 18:52:18 -0500 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 00GNqGHf029549; Thu, 16 Jan 2020 23:52:17 GMT Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by ppma02dal.us.ibm.com with ESMTP id 2xjvwnty1e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Jan 2020 23:52:17 +0000 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 00GNqFpH55705958 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Jan 2020 23:52:15 GMT Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BCB0C136051; Thu, 16 Jan 2020 23:52:15 +0000 (GMT) Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 68694136053; Thu, 16 Jan 2020 23:52:14 +0000 (GMT) Received: from oc8380061452.ibm.com (unknown [9.80.209.6]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP; Thu, 16 Jan 2020 23:52:13 +0000 (GMT) Subject: Re: [PATCH v2] Fix display of Maximum Memory To: Michael Ellerman , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Gustavo Walbon , Paul Mackerras References: <5577aef8-1d5a-ca95-ff0a-9c7b5977e5bf@linux.ibm.com> <8736cg9cay.fsf@mpe.ellerman.id.au> From: Michael Bringmann Openpgp: preference=signencrypt Organization: IBM Linux Technology Center Message-ID: Date: Thu, 16 Jan 2020 17:52:13 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: <8736cg9cay.fsf@mpe.ellerman.id.au> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-01-16_06:2020-01-16,2020-01-16 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 malwarescore=0 suspectscore=0 impostorscore=0 priorityscore=1501 adultscore=0 phishscore=0 mlxscore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1910280000 definitions=main-2001160189 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/15/20 11:53 PM, Michael Ellerman wrote: > Michael Bringmann writes: >> Correct overflow problem in calculation+display of Maximum Memory >> value to syscfg where 32bits is insufficient. >> >> Signed-off-by: Michael Bringmann >> --- >> 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