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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EED5C433EF for ; Tue, 26 Oct 2021 18:50:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 040DF600CD for ; Tue, 26 Oct 2021 18:50:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 040DF600CD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 8C42E940008; Tue, 26 Oct 2021 14:50:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8724C940007; Tue, 26 Oct 2021 14:50:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 739FD940008; Tue, 26 Oct 2021 14:50:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0252.hostedemail.com [216.40.44.252]) by kanga.kvack.org (Postfix) with ESMTP id 6188D940007 for ; Tue, 26 Oct 2021 14:50:45 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1826B3A7C6 for ; Tue, 26 Oct 2021 18:50:45 +0000 (UTC) X-FDA: 78739480050.24.3B86C2B Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by imf03.hostedemail.com (Postfix) with ESMTP id AF0DD30000BC for ; Tue, 26 Oct 2021 18:50:40 +0000 (UTC) Received: by mail-lf1-f51.google.com with SMTP id u11so910479lfs.1 for ; Tue, 26 Oct 2021 11:50:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BP4NAe7ddaJVYhsIxokjyZQ5JW8fdTP3tJwi3u/Bta8=; b=OT/TeaF5L09lQEvDVMETii9ZF1FekcmI9FniessxiwaCY0/2c1/fU9X5X2m68fW9/U qzQVQDMGq77TMKFFikymTD2XE2u05CbKQGlQpbNI/BWvyvPveGGs3ngxEM5n2QOBeTHl mwF0G1HhAq6spGex+GCN3LXQEQ6VP23pvpQmFaEr/rN1tsQZ8Yqi/dZx6ZCN+kUbjYIx vEXsauZp23Pe2R112F8jObaUOfG3GygDQTUzRtanX4RtuwliVgXLR1IntFRHfOlF1pUk 9dWQEtfBQTmHBrfKOPbY+vAeLSCf02bKk8pvLZk56yE4XTzHWKfi2qJK9H0uCUmhkA5i Zkdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BP4NAe7ddaJVYhsIxokjyZQ5JW8fdTP3tJwi3u/Bta8=; b=HVsRThFYpF8hIdyAoKwU7LNe7dLCK/C9HTCuHnoM6w6xNi9odXAD3wm53qKGvqCbO1 HBCDFwcMGhqlclk92hDRbRtQLx0G3eKbmbNBmy/c2tDpi8SO2GKbx7ZS/MUNVxZLjicz GUk7VyHzWUlAbKl8m9VLQTBSFJk5MwO4Jg8OkVVZ/UVzK6inxB/FTqD5WNr91Ye3i6gE BxCCWFXM27EoSk+LaMlaJxPNbV8JaNWrQH3up2g4Pgap4jfZ5hFvBq5OpT+MmMIUqi9m oOTUpICjXZyFwTbbRAawarPxSKQ6hVIKlh8Hwvi0zDBgSEiQmrVYuX/fsg26AmFmh1KO iaLw== X-Gm-Message-State: AOAM532LVZiT4sZXQ9Uxr9TjpKQgDVtI82VPkg3sya0Cbe5YlXHDmepF YmSP6J3xcI9yG+QSnqSaCRyaD9MmV1WrH3xw3ljvig== X-Google-Smtp-Source: ABdhPJzK4Dha/q6HSrHHxcz81bIchY+vvTwR3f0p68xpNbHqCeDhn3qKld2X233U664gN+hNMB3NXO/CSZIYQpq8xAo= X-Received: by 2002:ac2:59cc:: with SMTP id x12mr7735816lfn.501.1635274243249; Tue, 26 Oct 2021 11:50:43 -0700 (PDT) MIME-Version: 1.0 References: <20211026173822.502506-1-pasha.tatashin@soleen.com> <20211026173822.502506-3-pasha.tatashin@soleen.com> <57fbf167-b2e8-69f6-7f79-8e989162c889@oracle.com> In-Reply-To: <57fbf167-b2e8-69f6-7f79-8e989162c889@oracle.com> From: Pasha Tatashin Date: Tue, 26 Oct 2021 14:50:06 -0400 Message-ID: Subject: Re: [RFC 2/8] mm/hugetlb: remove useless set_page_count() To: Mike Kravetz Cc: LKML , linux-mm , linux-m68k@lists.linux-m68k.org, Anshuman Khandual , Matthew Wilcox , Andrew Morton , william.kucharski@oracle.com, Vlastimil Babka , Geert Uytterhoeven , schmitzmic@gmail.com, Steven Rostedt , Ingo Molnar , Johannes Weiner , Roman Gushchin , songmuchun@bytedance.com, weixugc@google.com, Greg Thelen Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: AF0DD30000BC X-Stat-Signature: sgyqz18y5cxqoiyi3fcyzdhidedtibws Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="OT/TeaF5"; dmarc=none; spf=pass (imf03.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.167.51 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-HE-Tag: 1635274240-347355 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, Oct 26, 2021 at 2:45 PM Mike Kravetz wrote: > > On 10/26/21 10:38 AM, Pasha Tatashin wrote: > > prep_compound_gigantic_page() calls set_page_count(0, p), but it is not > > needed because page_ref_freeze(p, 1) already sets refcount to 0. > > > > Using, set_page_count() is dangerous, because it unconditionally resets > > refcount from the current value to unrestrained value, and therefore > > should be minimized. > > > > Signed-off-by: Pasha Tatashin > > Thanks! > > My bad for not removing the set_page_count when adding the page_ref_freeze. > > FYI, there have been additional changes to this routine in Andrew's > tree. Not really sure if we want/need the VM_BUG_ON_PAGE as that would > only check if there was a 'bug' in page_ref_freeze. I would like to keep it. Part of the idea of this series is to reduce reliance on comments such as: /* No worries, refcount is A therefore we can do B */ And instead enforce that via VM_BUG_ON(). It should be able to prevent existing and future _refcount related bugs from manifesting as memory corruptions. Pasha > > -- > Mike Kravetz > > > --- > > mm/hugetlb.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > > index 95dc7b83381f..7e3996c8b696 100644 > > --- a/mm/hugetlb.c > > +++ b/mm/hugetlb.c > > @@ -1707,7 +1707,7 @@ static bool prep_compound_gigantic_page(struct page *page, unsigned int order) > > pr_warn("HugeTLB page can not be used due to unexpected inflated ref count\n"); > > goto out_error; > > } > > - set_page_count(p, 0); > > + VM_BUG_ON_PAGE(page_count(p), p); > > set_compound_head(p, page); > > } > > atomic_set(compound_mapcount_ptr(page), -1); > >