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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 1020AC433E0 for ; Tue, 26 Jan 2021 06:11:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7013F22B37 for ; Tue, 26 Jan 2021 06:11:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7013F22B37 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CB50C8D0092; Tue, 26 Jan 2021 01:11:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C648E8D0076; Tue, 26 Jan 2021 01:11:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7A9B8D0092; Tue, 26 Jan 2021 01:11:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id A25D78D0076 for ; Tue, 26 Jan 2021 01:11:18 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6B4BD180ACF0D for ; Tue, 26 Jan 2021 06:11:18 +0000 (UTC) X-FDA: 77746903836.02.hands63_5203d5c2758c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 4613410097AA0 for ; Tue, 26 Jan 2021 06:11:18 +0000 (UTC) X-HE-Tag: hands63_5203d5c2758c X-Filterd-Recvd-Size: 4951 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Tue, 26 Jan 2021 06:11:17 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id a20so1417778pjs.1 for ; Mon, 25 Jan 2021 22:11:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ofSELr0g41+S/wAw3xUz/6AdS5ttG052FfoGVJVMa5Q=; b=bILGxlB47kIhXwRWllAtOsJDXq1D44Np3y2XBbrmDSS0huIuZvwiEMXPTWNx1d5sQK I8CMHgjfEPvlrsqswpl3e9Q/61LViVjIu9pWJGjaFv2O7S9UGqOe3fm2q2YIJ+lt5b9e 98q/TYG+kyTRBNzl/chArtL/7111QjEBH7shEk9Eu1DYwBoK3JDDz4Uu12QMOmZgZ1GN 3FqaDuRrSiEaHeLiAlv+uP78EjTyqsTunE1svH6sReSPMKyTv1/3kRmQaaskITmAenir MdgMILFDGAxPp2EkmKJjIRXEpR45HtXarB9maMuNLcIIRg9F/WG6zgm5moDwmLKIgBYg Vj6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ofSELr0g41+S/wAw3xUz/6AdS5ttG052FfoGVJVMa5Q=; b=TJL0+iEA5N3UkQvfe3mZpEfoJsQS8HxqvbXBPKEcvRjKH9BDw5EA9qGePOviWYmnwI pqJH4kJsWZ6meXDRSWM+Zx61HHf54LX4J34YiuO2gPAl4fqZIr/zGHef0tJihMx0sbhh ytx8beWxy0p0wLJsrfKnAtpN34AEig6IghJNlFHXrAZf1d7nSJDcZq9j9wexQ2rA8Jd5 qHPuQkAsLyfq2o9qhX3zy7+oM2HUKH5qngyPKgZFIRkEPhfEBzhvoNInXBNCFXSej9Xa /JZSrVcSkSHW07CpshLaD71fhFBIiQQQhStLIwVpEkfLEk3LcVxVdyy0BPEb5+sH3LD8 e86w== X-Gm-Message-State: AOAM532dqbEX8Up7PAlPFjST2NBqND6l2RTSLgTKzzIUcKfl+2XvBOcU b4gP6BPAaSnrRpyBJO/O5jewwczmU6Wu4QMAwTPCmg== X-Google-Smtp-Source: ABdhPJyLCHgfCC70u4HOxxVDs+uHV5Nmsr//xCGybvnz30Ufog35rQHYCZhHYjMe9eYjblkzVR3QBZOZUB+TUHb0W8c= X-Received: by 2002:a17:90a:3e81:: with SMTP id k1mr4517001pjc.13.1611641476408; Mon, 25 Jan 2021 22:11:16 -0800 (PST) MIME-Version: 1.0 References: <20210126031009.96266-1-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Tue, 26 Jan 2021 14:10:39 +0800 Message-ID: Subject: Re: [External] Re: [PATCH] mm: hugetlb: fix missing put_page in gather_surplus_pages() To: Mike Kravetz Cc: Andrew Morton , Hui Su , Linux Memory Management List , LKML , linux- stable Content-Type: text/plain; charset="UTF-8" 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 Tue, Jan 26, 2021 at 12:31 PM Mike Kravetz wrote: > > On 1/25/21 7:10 PM, Muchun Song wrote: > > The VM_BUG_ON_PAGE avoids the generation of any code, even if that > > expression has side-effects when !CONFIG_DEBUG_VM. > > > > Fixes: e5dfacebe4a4 ("mm/hugetlb.c: just use put_page_testzero() instead of page_count()") > > Signed-off-by: Muchun Song > > Cc: > > --- > > mm/hugetlb.c | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > Thanks for finding and fixing this! My bad for not noticing when the bug > was introduced. > > > > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > > index a6bad1f686c5..082ed643020b 100644 > > --- a/mm/hugetlb.c > > +++ b/mm/hugetlb.c > > @@ -2047,13 +2047,16 @@ static int gather_surplus_pages(struct hstate *h, long delta) > > > > /* Free the needed pages to the hugetlb pool */ > > list_for_each_entry_safe(page, tmp, &surplus_list, lru) { > > + int zeroed; > > + > > if ((--needed) < 0) > > break; > > /* > > * This page is now managed by the hugetlb allocator and has > > * no users -- drop the buddy allocator's reference. > > */ > > - VM_BUG_ON_PAGE(!put_page_testzero(page), page); > > + zeroed = put_page_testzero(page); > > + VM_BUG_ON_PAGE(!zeroed, page); > > enqueue_huge_page(h, page); > > I was wondering why this was not causing any problems. We are putting the > hugetlb page on the free list with a count of 1. There is no check in the > enqueue code. When we dequeue the page, set_page_refcounted() is used to > set the count to 1 without looking at the current value. And, all the other > VM_DEBUG macros are off so we mostly do not notice the bug. Yeah. You are right. I also thought about this question. It is a very hidden bug. > > Thanks again, > > Reviewed-by: Mike Kravetz > > -- > Mike Kravetz > > > } > > free: > >