Message ID | 20221017202505.0e6a4fcd@imladris.surriel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1716157wrs; Mon, 17 Oct 2022 18:02:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5NttaQwO7X8Csb2M7I0uHTSDqXlZ/7COAeAfgqyrrhTpcg30CmtdTP2apMA89ZKkNwdkZE X-Received: by 2002:aa7:c144:0:b0:459:f897:793e with SMTP id r4-20020aa7c144000000b00459f897793emr361176edp.8.1666054927107; Mon, 17 Oct 2022 18:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666054927; cv=none; d=google.com; s=arc-20160816; b=KV7etuOao2l0MVxVPdpaEhm5Q8tzzFn4s1norYa8zWjzMJlR/3AvNquykNhAQZXnQG FclvTtqVNvlW82VPyrVQ25+khYZV2fR5rdaNnyCFSUX0RNIxL4yr+/TURkZ/Sjqk+L5y tuyxFeAGldyoLZxj9CYTktoPVrFno2uEC11Xkb/EN8t+Jub0p3e25x0NAylZtXbM9sWe CprWxs349g9nS6Y+W8tcVoCvlsScorzGCWUscsd8dO7fxwm9rDokeWuYjhg22N2xbOhx ywNXiLDGs2jDY1fFzS6kYj6zY5l+84TAXd+jbRkl8LQInNvwTqfF83Nty/kqZcrRUe8o LDBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:subject:cc:to:from:date; bh=vY9DzTal4pLD+ONd59GnhyzBaZdNj686DyyQp70t9uA=; b=AbjFRZ8q6Jg+i2Wo1N5LtLCybTMZCA3ZOT8EtKfjNq4TCo5Xvn7V4OpjxuuY8Ccbug KehK144zG7N114+2H68rI+BKUCD5U+vDkzrUQdyGHO7zHLnD74FiO63H+l133vLcbqeE HY35KBsdOmF5ph4Eyzdyt5HuDKzM5OeMdXkPUZP15MZh9+MW8Zoj8tDxzZrNi+IAkPll lN4vzAc0og7cBFp8e8K2SQUkm9urFCzqS3KC2x9H7hFHD6qxE275CFeGkOrVWQJVxM9O nhpMnLRcwKrTqgaFHeT/iDgSe8b9wtmRk6DKjGTw/GhbZhgmrgstF8LzRRbrd79jCOoH urmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb6-20020a170907960600b0078b96722000si12067866ejc.608.2022.10.17.18.01.39; Mon, 17 Oct 2022 18:02:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230437AbiJRA7p (ORCPT <rfc822;carlos.wei.hk@gmail.com> + 99 others); Mon, 17 Oct 2022 20:59:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230387AbiJRA7n (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 17 Oct 2022 20:59:43 -0400 X-Greylist: delayed 1078 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 17 Oct 2022 17:59:42 PDT Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7335EFD3C for <linux-kernel@vger.kernel.org>; Mon, 17 Oct 2022 17:59:41 -0700 (PDT) Received: from [2603:3005:d05:2b00:6e0b:84ff:fee2:98bb] (helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from <riel@shelob.surriel.com>) id 1okaPu-0003yC-18; Mon, 17 Oct 2022 20:25:10 -0400 Date: Mon, 17 Oct 2022 20:25:05 -0400 From: Rik van Riel <riel@surriel.com> To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, stable@kernel.org, Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>, Glen McCready <gkmccready@meta.com>, Mike Kravetz <mike.kravetz@oracle.com>, Muchun Song <songmuchun@bytedance.com>, Andrew Morton <akpm@linux-foundation.org>, kernel-team@meta.com Subject: [PATCH] mm,hugetlb: take hugetlb_lock before decrementing h->resv_huge_pages Message-ID: <20221017202505.0e6a4fcd@imladris.surriel.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: riel@shelob.surriel.com X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746985211232917814?= X-GMAIL-MSGID: =?utf-8?q?1746985211232917814?= |
Series |
mm,hugetlb: take hugetlb_lock before decrementing h->resv_huge_pages
|
|
Commit Message
Rik van Riel
Oct. 18, 2022, 12:25 a.m. UTC
The h->*_huge_pages counters are protected by the hugetlb_lock, but
alloc_huge_page has a corner case where it can decrement the counter
outside of the lock.
This could lead to a corrupted value of h->resv_huge_pages, which we
have observed on our systems.
Take the hugetlb_lock before decrementing h->resv_huge_pages to avoid
a potential race.
Fixes: a88c76954804 ("mm: hugetlb: fix hugepage memory leak caused by wrong reserve count")
Cc: stable@kernel.org
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Glen McCready <gkmccready@meta.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Rik van Riel <riel@surriel.com>
---
mm/hugetlb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 10/17/22 20:25, Rik van Riel wrote: > The h->*_huge_pages counters are protected by the hugetlb_lock, but > alloc_huge_page has a corner case where it can decrement the counter > outside of the lock. > > This could lead to a corrupted value of h->resv_huge_pages, which we > have observed on our systems. > > Take the hugetlb_lock before decrementing h->resv_huge_pages to avoid > a potential race. > > Fixes: a88c76954804 ("mm: hugetlb: fix hugepage memory leak caused by wrong reserve count") > Cc: stable@kernel.org > Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> > Cc: Glen McCready <gkmccready@meta.com> > Cc: Mike Kravetz <mike.kravetz@oracle.com> > Cc: Muchun Song <songmuchun@bytedance.com> > Cc: Andrew Morton <akpm@linux-foundation.org> > Signed-off-by: Rik van Riel <riel@surriel.com> > --- > mm/hugetlb.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Thanks Rik! That case did slip through the cracks. Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
diff --git a/mm/hugetlb.c b/mm/hugetlb.c index b586cdd75930..dede0337c07c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2924,11 +2924,11 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, page = alloc_buddy_huge_page_with_mpol(h, vma, addr); if (!page) goto out_uncharge_cgroup; + spin_lock_irq(&hugetlb_lock); if (!avoid_reserve && vma_has_reserves(vma, gbl_chg)) { SetHPageRestoreReserve(page); h->resv_huge_pages--; } - spin_lock_irq(&hugetlb_lock); list_add(&page->lru, &h->hugepage_activelist); set_page_refcounted(page); /* Fall through */