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 X-Spam-Level: X-Spam-Status: No, score=-13.3 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93234C43465 for ; Fri, 18 Sep 2020 16:17:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0D398238A1 for ; Fri, 18 Sep 2020 16:17:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="AJyl8b9x" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D398238A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 517DE6B005A; Fri, 18 Sep 2020 12:17:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C73C6B005C; Fri, 18 Sep 2020 12:17:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38F746B005D; Fri, 18 Sep 2020 12:17:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0155.hostedemail.com [216.40.44.155]) by kanga.kvack.org (Postfix) with ESMTP id 22F666B005A for ; Fri, 18 Sep 2020 12:17:32 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id CDCB9180AD83B for ; Fri, 18 Sep 2020 16:17:31 +0000 (UTC) X-FDA: 77276687502.18.glass23_2a00ebf2712c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id A8B6510112C08 for ; Fri, 18 Sep 2020 16:17:31 +0000 (UTC) X-HE-Tag: glass23_2a00ebf2712c X-Filterd-Recvd-Size: 3948 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Fri, 18 Sep 2020 16:17:31 +0000 (UTC) Received: from embeddedor (187-162-31-110.static.axtel.net [187.162.31.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6D73220795; Fri, 18 Sep 2020 16:17:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600445850; bh=vDSPwR6Bgtsv8lo5GFN8iaXaPRe2BXebWktgtOo/fdk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AJyl8b9xSfvFZR6HGhRH7nsb/iGQhawLhTeyE87loXOdqeZDCPnlqAnzziOzh2HKO tEmmVbzqbqqa1hgzl39wro5uexKcys69WtEYsVMnjGqqYJo1e8RdOXQmdcb6+lB6BK ZkSODultj5cguRFUnMJryTY07P3jVkmWZE8SKw2A= Date: Fri, 18 Sep 2020 11:23:05 -0500 From: "Gustavo A. R. Silva" To: Linus Torvalds Cc: Dennis Zhou , Tejun Heo , Christoph Lameter , Linux-MM , Linux Kernel Mailing List Subject: Re: [GIT PULL] percpu fix for v5.9-rc6 Message-ID: <20200918162305.GB25599@embeddedor> References: <20200917204514.GA2880159@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Sep 17, 2020 at 06:05:13PM -0700, Linus Torvalds wrote: > On Thu, Sep 17, 2020 at 1:45 PM Dennis Zhou wrote: > > > > > > diff --git a/mm/percpu.c b/mm/percpu.c > > index f4709629e6de..1ed1a349eab8 100644 > > --- a/mm/percpu.c > > +++ b/mm/percpu.c > > @@ -1316,7 +1316,7 @@ static struct pcpu_chunk * __init pcpu_alloc_fi= rst_chunk(unsigned long tmp_addr, > > > > /* allocate chunk */ > > alloc_size =3D sizeof(struct pcpu_chunk) + > > - BITS_TO_LONGS(region_size >> PAGE_SHIFT); > > + BITS_TO_LONGS(region_size >> PAGE_SHIFT) * sizeof(uns= igned long); >=20 > Hmm. >=20 > Wouldn't this be cleaner as >=20 > alloc_size =3Dstruct_size(chunk, populated, > BITS_TO_LONGS(region_size >> PAGE_SHIFT) ); Yeah; the above is much better. Please, use that helper. > and looking at this, I realize that I thought we enabled warnings for > 'sizeof()' of flexible array structures to avoid these kinds of > mistakes, but that must clearly have happened only in a dream of mine. If you were to try to apply the sizeof() operator to the flexible-array m= ember alone: sizeof(chunk->populated); you would get a warning because such arr= ays have incomplete type, see below: mm/percpu.c: In function =E2=80=98pcpu_alloc_first_chunk=E2=80=99: mm/percpu.c:1320:52: error: invalid application of =E2=80=98sizeof=E2=80=99= to incomplete type =E2=80=98long unsigned int[]=E2=80=99 1320 | BITS_TO_LONGS(region_size >> PAGE_SHIFT) * sizeof(chunk->popula= ted); | ^ However, in this case, sizeof() is being applied to the object type, whic= h doesn't cause a warning, but still is an error-prone coding practice. For instanc= e, this is the bugfix[1], for a 4-year old bug introduced by the combination of w= eak code and this commit[2]. This bug could have been prevented by either adopting= better coding practices or through the use[3] of the recent struct_size() helper= . So please, whenever you can use it, do so. :) Thanks -- Gustavo [1] https://git.kernel.org/linus/cffaaf0c816238c45cd2d06913476c83eb50f682 [2] https://git.kernel.org/linus/57384592c43375d2c9a14d82aebbdc95fdda9e9d [3] https://git.kernel.org/linus/553d66cb1e8667aadb57e3804775c5ce1724a49b