From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76452C433F5 for ; Fri, 7 Jan 2022 09:16:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E72476B0071; Fri, 7 Jan 2022 04:15:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E22BE6B0073; Fri, 7 Jan 2022 04:15:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D12576B0074; Fri, 7 Jan 2022 04:15:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id C118A6B0071 for ; Fri, 7 Jan 2022 04:15:59 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6941E181C49D5 for ; Fri, 7 Jan 2022 09:15:59 +0000 (UTC) X-FDA: 79002934038.09.42A319A Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf22.hostedemail.com (Postfix) with ESMTP id C8622C000E for ; Fri, 7 Jan 2022 09:15:58 +0000 (UTC) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-283-imPCMXOvPNuWtN3LA9tbww-1; Fri, 07 Jan 2022 09:15:55 +0000 X-MC-Unique: imPCMXOvPNuWtN3LA9tbww-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Fri, 7 Jan 2022 09:15:54 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.026; Fri, 7 Jan 2022 09:15:54 +0000 From: David Laight To: "'cgel.zte@gmail.com'" , "akpm@linux-foundation.org" CC: "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Changcheng Deng , Zeal Robot Subject: RE: [PATCH] mm/page_alloc.c: Use div64_ul instead of do_div Thread-Topic: [PATCH] mm/page_alloc.c: Use div64_ul instead of do_div Thread-Index: AQHYA2zM76VKweVeN0S3fxclkHxO96xXRvoA Date: Fri, 7 Jan 2022 09:15:54 +0000 Message-ID: <665a758a3bd5421ea7cf9c01d154f718@AcuMS.aculab.com> References: <20220107021751.621522-1-deng.changcheng@zte.com.cn> In-Reply-To: <20220107021751.621522-1-deng.changcheng@zte.com.cn> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: C8622C000E X-Stat-Signature: png8d56m1wd16t6u5jrdfk5ddbk6t4wa Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=aculab.com X-HE-Tag: 1641546958-955581 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: cgel.zte@gmail.com > Sent: 07 January 2022 02:18 >=20 > do_div() does a 64-by-32 division. Here the divisor is an unsigned long > which on some platforms is 64 bit wide. So use div64_ul instead of do_div > to avoid a possible truncation. You really need to check the domain of the divisor, not its type. Just because the type is 64 bits doesn't mean that the value can be anywhere near even 32 bits. =09David >=20 > Reported-by: Zeal Robot > Signed-off-by: Changcheng Deng > --- > mm/page_alloc.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) >=20 > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 8dd6399bafb5..60469b616ac1 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -8431,7 +8431,7 @@ static void __setup_per_zone_wmarks(void) >=20 > =09=09spin_lock_irqsave(&zone->lock, flags); > =09=09tmp =3D (u64)pages_min * zone_managed_pages(zone); > -=09=09do_div(tmp, lowmem_pages); > +=09=09tmp =3D div64_ul(tmp, lowmem_pages); > =09=09if (is_highmem(zone)) { > =09=09=09/* > =09=09=09 * __GFP_HIGH and PF_MEMALLOC allocations usually don't > @@ -8804,7 +8804,7 @@ void *__init alloc_large_system_hash(const char *ta= blename, > =09/* limit allocation size to 1/16 total memory by default */ > =09if (max =3D=3D 0) { > =09=09max =3D ((unsigned long long)nr_all_pages << PAGE_SHIFT) >> 4; > -=09=09do_div(max, bucketsize); > +=09=09max =3D div64_ul(max, bucketsize); > =09} > =09max =3D min(max, 0x80000000ULL); >=20 > -- > 2.25.1 - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)