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 458CBC00140 for ; Wed, 24 Aug 2022 08:10:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD8936B0072; Wed, 24 Aug 2022 04:10:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C601D940009; Wed, 24 Aug 2022 04:10:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B01A4940008; Wed, 24 Aug 2022 04:10:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9DF226B0072 for ; Wed, 24 Aug 2022 04:10:26 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 779F28013E for ; Wed, 24 Aug 2022 08:10:26 +0000 (UTC) X-FDA: 79833764052.11.94A2C51 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf16.hostedemail.com (Postfix) with ESMTP id 2E8B5180012 for ; Wed, 24 Aug 2022 08:10:25 +0000 (UTC) Received: by mail-pl1-f178.google.com with SMTP id v23so9732334plo.9 for ; Wed, 24 Aug 2022 01:10:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc; bh=9/eyKaPfuteIwHEnAMNI1rBDayjT1OLnm5QHb0/XnpM=; b=cPxFHkHRNoi1QBAXIZO2yurpDn3w+3l34l7pBPurq8rCROhaUjmamifjcijzDGua/m YRIcg6wAzqTPTsp320ufVQc0Kb8NnQtL8yx25moUm5SswdFzVU9kYjWoc5jiCIF3uM2r 3DyVOi1J8LAaxEvuVcahNa7DE7YdictCKevdI2TcRCvNDOUrIbX47U+KCKlVtPTWh9X6 F6N3hXERQBk9dAvoiTRiFLR02mSYLOKIvrv9rnQst77WFHPvwKGYFm7utnSPnackgNwb LmYnZiPxuBIGZVPiSGBTcZINkXsugVVl2OktUjldWgZtHgmsxdOzfAyVEOkEYQRcr6GR ZcqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=9/eyKaPfuteIwHEnAMNI1rBDayjT1OLnm5QHb0/XnpM=; b=Uo/GgMJSZ328cMGGhVKm+hejUuKl9ZBmCQgWI1OGDac9LjDzXxeZ/f2Fq8NHhKSMy3 /hjUjqd0kOMbFa36oayautH3CwutoKq3rPaX/Ju9Tl2IcFJgHuzi4qgMx2UnyxPa1Qcb 3VZTnUFaoN8bnKZWl7GEBZNQS4aeJpe7t57k255n4O2ai48uJtnF29vKhFnwbLAaxynj wtnn1YIzDSvDAgW7d4pGM7LjFnndp9+GyFWnruFx6X4AOF/k6/PkqHj3LbhhafmQhody rJ03/ZI4ndrksC08IK1O5ZnEK+w4MWObMrEP4pjmZHd4/k8DKFoN1vgXpnunAeCY8JEq IASg== X-Gm-Message-State: ACgBeo3xR/jDNpoDFRvbz5AVR1pPrSvEtxYMy+SfrMWtqt6994XVx8LV AQo+QuK8dQ9XvQpgyQq2jvEHM7KjRxqWnTp4ih8= X-Google-Smtp-Source: AA6agR7mOlL6iWB+csFRao6aJppvPwxrM+PSC03oib3/MwvPJvTec2P0Wk4/CsnZda2KXSiwddkoqNaUXpxd2g1w8jk= X-Received: by 2002:a17:90b:4a05:b0:1f5:62d5:4155 with SMTP id kk5-20020a17090b4a0500b001f562d54155mr7417749pjb.6.1661328623952; Wed, 24 Aug 2022 01:10:23 -0700 (PDT) MIME-Version: 1.0 References: <20220824055637.10676-1-zhouzhouyi@gmail.com> <8d8bfc81-b584-20f4-65ae-d626f019cdf4@csgroup.eu> <66f0770d-83ee-34cb-2dea-b8d957613c7f@csgroup.eu> In-Reply-To: <66f0770d-83ee-34cb-2dea-b8d957613c7f@csgroup.eu> From: Zhouyi Zhou Date: Wed, 24 Aug 2022 16:10:12 +0800 Message-ID: Subject: Re: [PATCH linux-next] mm: fix used but uninitialized variable To: Christophe Leroy Cc: "akpm@linux-foundation.org" , "nathan@kernel.org" , "ndesaulniers@google.com" , "trix@redhat.com" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "llvm@lists.linux.dev" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661328625; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9/eyKaPfuteIwHEnAMNI1rBDayjT1OLnm5QHb0/XnpM=; b=clW5fwG55dkwLboq/KYthMpVqXKIlAEH3v5B8+m33JPknFXWjfrYrZ8fBxzagglIZh7wHs DZYUYp3PyD6wr2MbqosomU0rG1curyWmcbkSyG5MMH5y6zY+nLc+N+NQkwwhJeaxJEhouQ jdOvLwRObZMPPhmeWMG9qWrUYhbgKBA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=cPxFHkHR; spf=pass (imf16.hostedemail.com: domain of zhouzhouyi@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=zhouzhouyi@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661328625; a=rsa-sha256; cv=none; b=VFFnqRpLtShcZgnNPdsIo0J0ALyQlenwMc1sTRz2wEG7/ufsMZpYgx6s89WaMiq5sGRMKZ l06/xofmW1kudVkxFnjYPULzMRQFsRZQD6OILNcGkpFoOfZP+JcGmR7chX72C2/uQEoAdF X8fr4VoUk/5wR0NOhuFGoyaCmjAUGEc= Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=cPxFHkHR; spf=pass (imf16.hostedemail.com: domain of zhouzhouyi@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=zhouzhouyi@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Stat-Signature: yz31bsbxk1hortueeua5w5rpz1ryytxn X-Rspamd-Queue-Id: 2E8B5180012 X-Rspamd-Server: rspam10 X-HE-Tag: 1661328625-734247 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 Wed, Aug 24, 2022 at 2:49 PM Christophe Leroy wrote: > > > > Le 24/08/2022 =C3=A0 08:41, Zhouyi Zhou a =C3=A9crit : > > Thank Christophe for reviewing my patch > > > > On Wed, Aug 24, 2022 at 2:10 PM Christophe Leroy > > wrote: > >> > >> > >> > >> Le 24/08/2022 =C3=A0 07:56, Zhouyi Zhou a =C3=A9crit : > >>> In function walk_hugetlb_range, the local variable err may > >>> be used uninitialzed when: > >>> ops->pte_hole in side of "else if (ops->pte_hole)" is false. > >>> > >>> Signed-off-by: Zhouyi Zhou > >>> --- > >>> Dear mm Developers: > >>> > >>> When I build kernel using "make CC=3Dclang-14" > >>> the compiler complains following: > >>> > >>> CC mm/pagewalk.o > >>> mm/pagewalk.c:318:12: error: variable 'err' is used uninitialized whe= never 'if' condition is false [-Werror,-Wsometimes-uninitialized] > >>> else if (ops->pte_hole) > >>> ^~~~~~~~~~~~~ > >>> mm/pagewalk.c:321:7: note: uninitialized use occurs here > >>> if (err) > >>> ^~~ > >>> mm/pagewalk.c:318:8: note: remove the 'if' if its condition is always= true > >>> else if (ops->pte_hole) > >>> ^~~~~~~~~~~~~~~~~~ > >>> mm/pagewalk.c:311:10: note: initialize the variable 'err' to silence = this warning > >>> int err; > >>> ^ > >>> =3D 0 > >>> 1 error generated. > >>> make[1]: *** [scripts/Makefile.build:250: mm/pagewalk.o] Error 1 > >>> make: *** [Makefile:2006: mm] Error 2 > >>> > >>> I initialize that variable outside of the for loop because we can ass= ign 0 to err > >>> only once in this function. > >>> > >>> After my fix, I can compile the kernel. > >>> > >>> Many Thanks > >>> Zhouyi > >>> -- > >>> mm/pagewalk.c | 2 +- > >>> 1 file changed, 1 insertion(+), 1 deletion(-) > >>> > >>> diff --git a/mm/pagewalk.c b/mm/pagewalk.c > >>> index 54b2a1beeeb3..b6eb330e8ecd 100644 > >>> --- a/mm/pagewalk.c > >>> +++ b/mm/pagewalk.c > >>> @@ -306,9 +306,9 @@ static int walk_hugetlb_range(unsigned long addr,= unsigned long end, > >>> unsigned long hmask =3D huge_page_mask(h); > >>> unsigned long sz =3D huge_page_size(h); > >>> const struct mm_walk_ops *ops =3D walk->ops; > >>> + int err =3D 0; > >> > >> Why do you move it back outside of the for loop allthough it is > >> exclusively used inside the loop ? > > I move it outside of the for loop for performance consideration. Becaus= e > > if we initialize err inside, there will be an assignment statement > > every iteration. > > I think GCC is smart enough to do the assignment only when necessary, > maybe have a look at the generated assembly in order to confirm. Thank Christophe for your guidance, I disassembled the GCC generated code, it optimized away int err =3D 0 on both X86 and PowerPC platforms. The disassembled instructions are quite long, so I prefer not to paste in my email unless someone asks me to do so ;-) > > >> > >>> > >>> for (; addr < end; addr =3D next) { > >>> - int err; > >> > >> Another solution would be to add an explicit else, setting err =3D 0 i= n > >> the if/else if sequence. > > Thank Christophe for your valuable advice, I am going to prepare a 2nd = version > Thank Christophe for your reminder, I only subscribed to the RCU mailing list currently, so I submitted duplicated work. I should be more devoted to the Linux community. I am sorry. > Don't spend too much time on that, there are already other people > looking at it, see > https://lore.kernel.org/linux-mm/20220823153055.2517764-1-nathan@kernel.o= rg/T/ > > > > > Thanks > > Zhouyi Many thanks Zhouyi > >> > >>> pte_t *pte =3D huge_pte_offset(walk->mm, addr & hmask,= sz); > >>> > >>> next =3D hugetlb_entry_end(h, addr, end);