Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7420571ybl; Wed, 15 Jan 2020 22:39:38 -0800 (PST) X-Google-Smtp-Source: APXvYqwsyKjXcWcZaHk7lzPc79j1f3HbNaCuKaTIEKsVdcZRl+UrkZBddf4rOZhpHlBI5V0Li0RQ X-Received: by 2002:a9d:3f61:: with SMTP id m88mr832703otc.56.1579156778021; Wed, 15 Jan 2020 22:39:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579156778; cv=none; d=google.com; s=arc-20160816; b=aYCm8IOrsud3NOKGucQEEiZV+XnTPCtQkUCNoHqFcEvlYkWcgYwWht09zJkG2WNKjA lIImI58TVSAtzfnsdX9C0XQ8Cy+UsSeg/Ap6t0qwjb9Xk1Dugbi/mlJqseEmb7XtUcYK am+orP64gV63yYFvHstYoD/GJ3MkSBgXr6AAnBTPJH53Eu5mMIzDmaE9hK8dEvTC7pf3 sYpBtLsVm4h3YPO6zTFY1pgtqOtI/6GPR5nmbGha2rIz36RcoGhBFPQFwi+9heDKt0Tt ESW5v/uLXI8CkBxAYxzvhH3vLVbWp28ukYblI+zh/8vcH7Qb3t512ZpXqdg8qym16rxs 1Aew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:to:from:dkim-signature; bh=WKW1w+CcC2FqpY8b0TGpy+sgtQ0YXf+QRcfeU5zoFqs=; b=h/uMjxbK9LnHExPzvDk4LnMmdCIKh8IsxqC5owGhkczsYgvUfiH6NsRwwVNRy2uRTd P7GtV2RxMXWMd6Z1POzgb1hE+4+5ouQedWWmHWZE/Zv3xlXL4PYaquA/oLVbLwGTOyTV R8J6olR9QeI9fNcP8NLLNtwLogD2w8tmmiyUPZfm65+km427eZiP+pR1mxGfvyBsYC0K 4dcJt3DYQJUOEv2cspIHg0P3ml+vd9zUuDKRW+sL5+KhVicDnDkN32Jwhx2qDi3sDJiW XMaeuNT1V0uY9u2tJNg8sJadDITOF2SGX417Jg+Yizmy3sS88Ikif3+WUYyIJweXi8oi 7Y+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=FqKdsNN0; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p71si10988242oic.138.2020.01.15.22.39.26; Wed, 15 Jan 2020 22:39:38 -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; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=FqKdsNN0; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726974AbgAPFxy (ORCPT + 99 others); Thu, 16 Jan 2020 00:53:54 -0500 Received: from ozlabs.org ([203.11.71.1]:41861 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726082AbgAPFxx (ORCPT ); Thu, 16 Jan 2020 00:53:53 -0500 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 47ytfm1x2Mz9sPW; Thu, 16 Jan 2020 16:53:52 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1579154032; bh=9RJsA4ixbU88RCAM8/QGkNN4hFo2PgW5OQD3mizTqI4=; h=From:To:Subject:In-Reply-To:References:Date:From; b=FqKdsNN0+BMLA/sv1/RKIUVNjSC86xzmMHFRbQrb//m3wbAbN4rnKXI9uln9OlG6o 5TlVgSy7N/4wJS42CWV1b2DqgfuWNNOAg9D2IDvHcioJiIYuaPbZHGMmTC+DYbj/Np ZX+/S7m/WmXN6ka4CEjNIYF0dVvZSEv5yMp2ooTpKtAqGPuvrTrjX6R97FYnJC/7d8 VHmD+JvS8o4D3g53Yb43H+3lA9R9U3fs+1+LVBrXTSiwkybYxVlDSinm6F7k5dVk+K JhXymh3j23dlNfXiEgcOfZQQnzvRDrXm8n9KZP5rPlvnfTz9ts+pKinLnyHlt5MbhP yj73JrISh1PRA== From: Michael Ellerman To: Michael Bringmann , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Gustavo Walbon , Paul Mackerras Subject: Re: [PATCH v2] Fix display of Maximum Memory In-Reply-To: <5577aef8-1d5a-ca95-ff0a-9c7b5977e5bf@linux.ibm.com> References: <5577aef8-1d5a-ca95-ff0a-9c7b5977e5bf@linux.ibm.com> Date: Thu, 16 Jan 2020 15:53:57 +1000 Message-ID: <8736cg9cay.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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