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 0F551CDB465 for ; Thu, 19 Oct 2023 14:21:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 732568D00AF; Thu, 19 Oct 2023 10:21:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7084F8D009F; Thu, 19 Oct 2023 10:21:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61E338D00AF; Thu, 19 Oct 2023 10:21:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 563588D009F for ; Thu, 19 Oct 2023 10:21:05 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 19BED1CB73B for ; Thu, 19 Oct 2023 14:21:05 +0000 (UTC) X-FDA: 81362422890.14.72980AD Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf26.hostedemail.com (Postfix) with ESMTP id 5B792140009 for ; Thu, 19 Oct 2023 14:21:01 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JgD2mszF; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of nathan@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=nathan@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697725263; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=N4J2Sklbey47B55XuOoMuYtqWhxMBxsw8SZPXLMhk/E=; b=yfmm0LLY/BSujejAd2QEasPEhj78JB78GEw6SAvsy4w2bmIci7YpV+5LibuUfmd94IfMlO 1iUZjZN1SXKIgb1jmGymMt0KKaXZIxkfxWrR8UPF5JiLRChgf1c8SrhsA/44EC+Y2XsfDY SG4ktIP4oOlkHvhISQIs6VFEbL++u90= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JgD2mszF; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of nathan@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=nathan@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697725263; a=rsa-sha256; cv=none; b=1S+mZ1ah0pSG6VMF2+hjqbcPGxDbk2zKKyjDnqso8sr05E1oomWeU6Q47nvQY4AgAlrd8h Lnp9EpV2RRAppR7Q69q3VpP2tsasb0RAXfv/7NKcaN/kQMats5hPxfqZ2xifLycR25co64 Gtp/M/84nIXV9trxqeudF+58Li5U3Jc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id C8396CE2DB3; Thu, 19 Oct 2023 14:20:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25F70C433C7; Thu, 19 Oct 2023 14:20:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697725256; bh=SYQufYvEZp9QNGvUcctMCtYxQ/T4Y0G7ziduh+OoWz8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JgD2mszFwXbGqZjltRRw8W7Bx7zE5dcFMSEro4HKnBpuRrCYwv4bEWSooANfsPsVM dxnaVVc83hzYSVEWHLiciE9bwVsPDhttdIEZuGvQguCnj+YIT9iFYQtE5yqyHU9j+P ufs9cTOUT07f7ddLgKb9TuF/xoVRRNxqbiy4KZGtMpabk8AftSOj82yqqamIVIkDTH 1nHzpeiAZ9alKDeMtfUjhnNy89NOOFeh9DXOqv/hmqZqL2mym64yIHJvjuEfuAFUrw rYWA9mK6OKwjJrdgOQ4qFCQAJFB+LCLV1DTx6R6o0uB03wyt/3k9e4nJqoab2lc4K4 LS3UnXH9gIvjA== Date: Thu, 19 Oct 2023 07:20:54 -0700 From: Nathan Chancellor To: Sergey Senozhatsky Cc: Mike Kravetz , Nick Desaulniers , Usama Arif , linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, muchun.song@linux.dev, songmuchun@bytedance.com, fam.zheng@bytedance.com, liangma@liangbit.com, punit.agrawal@bytedance.com, Konrad Dybcio , llvm@lists.linux.dev Subject: Re: [PATCH] mm: hugetlb: Only prep and add allocated folios for non-gigantic pages Message-ID: <20231019142054.GA60597@dev-arch.thelio-3990X> References: <20231009145605.2150897-1-usama.arif@bytedance.com> <20231010012345.GA108129@monkey> <20231012000327.GA1855399@dev-arch.thelio-3990X> <20231012145318.GA5127@monkey> <20231013001203.GA3812@monkey> <20231014000450.GA253713@monkey> <20231018222003.GA21776@monkey> <20231019043305.GB14965@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231019043305.GB14965@google.com> X-Rspam-User: X-Stat-Signature: tx69euc4uzugtg1tmqhe7z7uhk69j71a X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5B792140009 X-HE-Tag: 1697725261-41526 X-HE-Meta: U2FsdGVkX18sLCB+tAQltN823VHEJI4EE5hhcNE+2uUlSODl/SesXHYn3dSCPk9f7uoXrSPkEGNFA1Rmhhpuu3Tj7x/d2wjXJqHs7VWcWjny/gSwyOz9wKsEYJqc762iszkGzbu7lKCPYzSOR4SkEMw+/f7WamKQ4x7YE6Rk4YwOEANgEwAnvwQrhc6X4243VS5zBBn+jTTBCQNby5oFU+Qz+WflOfKdtNluMVdOqXFWDaQyjWJ4Mz2i4SsbeSS9lt3vaJ6dcaqo9AtTTkVK/omwHtqx2ksoMf20iA6DQ/Xw8q1HPvKB414hDL4wmQDeTb6x8NayvU7w9Twt9ACcuZHMbrtgCppLxCCyEoEq4AWBoBaWGxKS9OUE2RgjsrYK7Z55EaWTjcO1oMq/OSgJztG3meS1NHyfE+zoUEwsCsCYlvbP+gbtEWfeHM9ol/vi4ya8j3NH3cy5Bq3NqSwfy4klhia+Ixj6JgIKXkoAL+yYGjZeZNSSQ9/B/xZsHCvHzx3nm0NbNqQi1G2cDs82qZoCfxpuAX4A19dzL5f1yDtNlurNnY9iXJSESrgH7+ZnKKp153jj4emHFZqx4QnbNEt2aH9Qc8FLwyFLm/VkJ89zkYFbvcrJWlba/ifvajeY/iahWoey/cBgATkIPpWQLexzKZf6NcfG/UuT48EaYWoPb967U9furNrkm7ya8O6gFzj12UGf7p2vC8NBrt+RDxbVOd0KF6BM0SgnWoPBJ62vqb2tjNPGHV+lFI+vKKS7sEECvlvd7zmhBk98HEMBvGH2J5qmXcndE+ijwenr3z427d+J8PYE7N8iy1sC7brhAWrXhZU3UomE8Fv1gfgujCNKz49W5ZVsFcyI8k3GyUhsJcEVOWknbqHvmeLvWpoacRtLYSEl+lfQUw32cK4Cfivk0qPNN/UkQCAgsE05djBBraTP2lVa4+1ipq6xuOOJA/9yyXa80zLx+Vt6ciZ 4DrP8b7R eWsQ/UlgjJWfG55uCW66G0Vdww/Mo2KX8LZvdofNHL6c3RgPTt5CO0EB3WZwTIKbd8a23QfcmCw24Jh8qI8fJAtpmPY3ZzhwPq1p9vyRKllFznCiVyk598owiRTDc5v0jawNQtS2Q2X27iUC0XXsNuioI4KqJ33cGei/cWg+6jNC/MhCIxS5iCWIDfCQxh4ctRc2aANZgxCYqM3qgTwX9tThq0g== 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, Oct 19, 2023 at 01:33:05PM +0900, Sergey Senozhatsky wrote: > On (23/10/18 15:20), Mike Kravetz wrote: > > > I think you need to initialize h, otherwise what value is passed to > > > prep_and_add_bootmem_folios if the loop is not run because the list is > > > empty. The compiler sees `h` is only given a value in the loop, so > > > the loop must be run. That's obviously hazardous, but the compiler > > > assumes there's no UB. At least that's my limited understanding > > > looking at the IR diff Nathan got me in > > > https://github.com/ClangBuiltLinux/linux/issues/1946. > > > > Thanks for looking closer at this Nick and Nathan! > > > > I think you are saying the compiler is running the loop because it wants > > to initialize h before passing the value to another function. It does > > this even if the explicit loop entry condition is false. Is that correct? > > The loop is getting promoted to "infinite" loop, there is no > &pos->member != (head) condition check in the generated code > at all (at least on my machine). > > I wish we could at least get the "possibly uninitialized variable" > warning from the compiler in this case, which we'd translate to > "hold my beer, I'm going to try one thing". GCC would warn about this under -Wmaybe-uninitialized but it has been disabled in a normal build for the past three years, see commit 78a5255ffb6a ("Stop the ad-hoc games with -Wno-maybe-initialized"). In function 'gather_bootmem_prealloc', inlined from 'hugetlb_init' at mm/hugetlb.c:4299:2: mm/hugetlb.c:3203:9: warning: 'h' may be used uninitialized [-Wmaybe-uninitialized] 3203 | prep_and_add_allocated_folios(h, &folio_list); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mm/hugetlb.c: In function 'hugetlb_init': mm/hugetlb.c:3166:24: note: 'h' was declared here 3166 | struct hstate *h, *prev_h = NULL; | ^ Clang's -Wconditional-uninitialized would have flagged it too but it suffers from the same problems as -Wmaybe-uninitialized. mm/hugetlb.c:3203:32: warning: variable 'h' may be uninitialized when used here [-Wconditional-uninitialized] 3203 | prep_and_add_allocated_folios(h, &folio_list); | ^ mm/hugetlb.c:3166:18: note: initialize the variable 'h' to silence this warning 3166 | struct hstate *h, *prev_h = NULL; | ^ | = NULL I know clang has some handling for loops in -Wsometimes-uninitialized, I wonder why that does not trigger here... Cheers, Nathan