Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp4062745rdg; Wed, 18 Oct 2023 13:56:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEe4FwuoTpe2npCICpC1n4BK5Rh+0g4TM4+35gFg4vgc9UIlmqrse4mrk83PI+3jEmBHn0J X-Received: by 2002:a17:90b:1b49:b0:27d:491d:2e40 with SMTP id nv9-20020a17090b1b4900b0027d491d2e40mr279058pjb.22.1697662568607; Wed, 18 Oct 2023 13:56:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697662568; cv=none; d=google.com; s=arc-20160816; b=Dt3E6+sVv67TO1zaNt7aqlbv3wx828kvcR5mfb3YvDfEhPy3oszt+JUJgujGC7JSgV tETGwAADvGh0h1z7Lj0sBfOLhdIgV/mpT3O7sn8WadoEP5Xdayj2QP466wjFkceD32ds bt8yGS/7sNFuulN478xYaMztNJInjh+oj2wrjYjx0esfmaovsjoOEsVeXWEfqyeIuNY8 tPVvuZ4uA5Xt4nSJTv5Ch6CG4acJE6vKE7qJ7RHnUjlXfAJuNEpklgmOaMZLBehCg4cI 8huViTLtI32wFveTtVrsS33CKrVlJil2mBouIjwCBGwHNreeKndan1AwtNF0DXF04axk XImQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=aM7Lcg58eaICcI7n9hqCMKVzpyeJKHwBAKrGqarbnys=; fh=obbV4tBmbn0HKyIv4CXXzzpsCH1Aa+cs5ZpYpGdb2L4=; b=rYXr0byIh6UBtXP7LCv/hOPwshPQB8xwdSf83n90IYy9yfOUbqnOoCBgs0uAFtzFiH A8Uj+CUx0hplpLlTQStQJUDVMcg/aje6AQovYUtMRIIM79CtL5F3gC/B5d/qmrFQNHba ygC63wuW2Kv2MKdg0jei0DGTNhlWtCDiGNGPRfSDonGB66VpV7sfOWTRN5Uy1PbbHGyF uSbuSTUtvhM0rtXL7EX8WZpHr+UsUpy6BEPB/1o+0koPi/uQPRmQSzOrN6gkYBtq/dGO Sy+27L1tyF4UTmAIf0rofg5603rmelj/PjcY5NnPoc2fdboOXhDlrWrDnwrN/oWIjPrY jUIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Jt1MunVf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id h23-20020a17090adb9700b002769b4b64e7si669585pjv.20.2023.10.18.13.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 13:56:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Jt1MunVf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 974BD808738D; Wed, 18 Oct 2023 13:55:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230051AbjJRUzN (ORCPT + 99 others); Wed, 18 Oct 2023 16:55:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230334AbjJRUzK (ORCPT ); Wed, 18 Oct 2023 16:55:10 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67FAEFE for ; Wed, 18 Oct 2023 13:55:08 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40566f8a093so67871085e9.3 for ; Wed, 18 Oct 2023 13:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697662507; x=1698267307; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=aM7Lcg58eaICcI7n9hqCMKVzpyeJKHwBAKrGqarbnys=; b=Jt1MunVfc6TYsSYjLZaO2H1XWruP/8h1fnCn4kvyuDEWf31xEENH/AW37PEijBO/H5 vHlcPazuPSeNfkq3Dhi/Hd59NcDn5oJ1LAoB/vL5U0Gp+FRC4PcCI27xcTzJ4IXRd/QP K7nxT1fxAHpR856s/X/gjevA6yqovE1LZAx8cYsywN7H4ID6rjcuEQiDy/BzxxXzjwHV H1PRw1A8XuXJo3VNYK+jR5V9wrbwI2pzzeepqlzthuVqWS+dQtWLIngdKHoUIoRnPW5p v/hb0+uPCVHzu5ZH3BMCv4iBZIzGDZkRxeET5AmR4lMRJTAXKe4xRC3C8/zmGs53Utqw U/Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697662507; x=1698267307; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aM7Lcg58eaICcI7n9hqCMKVzpyeJKHwBAKrGqarbnys=; b=UCsGEez3YqQGo7ZDBQuFbTe5dEb/ZTlUyhmd4doNvHBAO99slwzdv/1j208Ja0K5S9 /AJvDSzqzMAtTBpvRrK3MacpfewziMHZT8NCjE3CBlMcYOyUAxMM305L99l7/CGw4jeG YbchvnY8h5lvs2YkboLzc9ITaK4APW6ksMumuFlqdZSf1Twr2tDsTirMy1zUFG0y6TrP hU0bYZHkUFdT6Qnr+59mMTOJ3OA9wZ3u4eEre9VKRHDNzaiI0cJMuqYsMtmkTgRW8Vgw WKYDFtglHOY42tgKmBFKD7NH9WClbBX2CWqFA1/7d837OI3tj9wItFWV2WFUYJxnrcEW NmYA== X-Gm-Message-State: AOJu0YyTzFXxMarbX5xcDcHheSSOjJp/OCnBnxlLbBKcfUGeBYODqeV5 UnSiV05IjLpqD+obZdj9yLSl3nCNcmMmQUQsfeydQw== X-Received: by 2002:a05:6000:45:b0:32d:96a7:9551 with SMTP id k5-20020a056000004500b0032d96a79551mr137837wrx.36.1697662506602; Wed, 18 Oct 2023 13:55:06 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: <20231014000450.GA253713@monkey> From: Nick Desaulniers Date: Wed, 18 Oct 2023 13:54:52 -0700 Message-ID: Subject: Re: [PATCH] mm: hugetlb: Only prep and add allocated folios for non-gigantic pages To: Mike Kravetz Cc: Nathan Chancellor , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 18 Oct 2023 13:55:38 -0700 (PDT) On Fri, Oct 13, 2023 at 5:05=E2=80=AFPM Mike Kravetz wrote: > > On 10/12/23 17:12, Mike Kravetz wrote: > > On 10/12/23 07:53, Mike Kravetz wrote: > > > On 10/11/23 17:03, Nathan Chancellor wrote: > > > > On Mon, Oct 09, 2023 at 06:23:45PM -0700, Mike Kravetz wrote: > > > > > On 10/09/23 15:56, Usama Arif wrote: > > > > > > Thank you Nathan! That is very helpful. > > > > > > I will use this information to try and recreate. If I can recreate, = I > > > should be able to get to root cause. > > > > I could easily recreate the issue using the provided instructions. Fir= st > > thing I did was add a few printk's to check/verify state. The beginnin= g > > of gather_bootmem_prealloc looked like this: > > Hi Nathan, > > This is looking more and more like a Clang issue to me. I did a little > more problem isolation today. Here is what I did: > > - Check out commit "hugetlb: restructure pool allocations" in linux-next > - Fix the known issue with early disable/enable IRQs via locking by > applying: > > commit 266789498210dff6cf9a14b64fa3a5cb2fcc5858 > Author: Mike Kravetz > Date: Fri Oct 13 13:14:15 2023 -0700 > > fix prep_and_add_allocated_folios locking > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index c843506654f8..d8ab2d9b391b 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -2246,15 +2246,16 @@ static struct folio *alloc_fresh_hugetlb_folio(st= ruct hstate *h, > static void prep_and_add_allocated_folios(struct hstate *h, > struct list_head *folio_list) > { > + unsigned long flags; > struct folio *folio, *tmp_f; > > /* Add all new pool pages to free lists in one lock cycle */ > - spin_lock_irq(&hugetlb_lock); > + spin_lock_irqsave(&hugetlb_lock, flags); > list_for_each_entry_safe(folio, tmp_f, folio_list, lru) { > __prep_account_new_huge_page(h, folio_nid(folio)); > enqueue_hugetlb_folio(h, folio); > } > - spin_unlock_irq(&hugetlb_lock); > + spin_unlock_irqrestore(&hugetlb_lock, flags); > } > > /* > > - Add the following code which would only trigger a BUG if we were to > traverse an empty list; which should NEVER happen. > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index d8ab2d9b391b..be234831b33f 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -3294,11 +3294,21 @@ static void __init gather_bootmem_prealloc(void) > LIST_HEAD(folio_list); > struct huge_bootmem_page *m; > struct hstate *h, *prev_h =3D NULL; > + bool empty; > + > + empty =3D list_empty(&huge_boot_pages); > + if (empty) > + printk("gather_bootmem_prealloc: huge_boot_pages list emp= ty\n"); > > list_for_each_entry(m, &huge_boot_pages, list) { > struct page *page =3D virt_to_page(m); > struct folio *folio =3D (void *)page; > > + if (empty) { > + printk(" Traversing an empty list as if not em= pty!!!\n"); > + BUG(); > + } > + > h =3D m->hstate; > /* > * It is possible to have multiple huge page sizes (hstat= es) > > - As you have experienced, this will BUG if built with LLVM 17.0.2 and > CONFIG_INIT_STACK_NONE > > - It will NOT BUG if built with LLVM 13.0.1 but will BUG if built with > LLVM llvm-14.0.6-x86_64 and later. > > As mentioned in the previous email, the generated code for loop entry > looks wrong to my untrained eyes. Can you or someone on the llvm team > take a look? 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. --=20 Thanks, ~Nick Desaulniers