Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp168751pxb; Wed, 27 Oct 2021 00:17:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOmVbrjdv5LpzQiSb4vRSHMrxmPXdDA26BubVy84OlX6LqEJHJbsZQJCe0b9RmwbRYaXlN X-Received: by 2002:a17:902:dad0:b0:140:3cd8:5901 with SMTP id q16-20020a170902dad000b001403cd85901mr21865391plx.74.1635319021651; Wed, 27 Oct 2021 00:17:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635319021; cv=none; d=google.com; s=arc-20160816; b=Y6oTodpLQjB/R61+aG/akueNWNvpyUDnaACnebCjAz+9f7NFwTl9k/LfxiXLcbS1j5 fy/sOaVKOCdr5skVeVHdl15FBDaqsgK6vzmD480o5Z5LiF+iwck92c//2fRC2dYEiRxV 5qy9mwvRwJyEhsS7GK35iTW+6pJaiXDyeFjdCKft6Wr0o9boyRKWcExf3LSrUdH2XUEj WucP5Q/eT2k8wc6ca0ptQFoTJzyj8eeh1XHhKGQxGL7/YvOI6bGJZNUwfzlswW1tFU7N QGUw+NdsY8ysKVzb8L16cuq9fJ09/QjNMYy1uyeSofMXXhSA0yYTRZsfix0mh6pPN2Ox gKQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=BP4NAe7ddaJVYhsIxokjyZQ5JW8fdTP3tJwi3u/Bta8=; b=AQcFrEFqLRbzGxNEZBRTLltY1wzKO3hPsWHCGpHy30kPwPMOihb9vA3mXNxQdNacIe rY2mBxmNskXvImZ/hEb3FgrqpW1QH7QyTHZvNkCfTHfD+I7Uv54N7H13zq+eIOH6KHPL zBgaLFnIlPbYCx0H9ulzJqeu5gppwUoye9y7fO1UviNVGrj6fAmDY5uR4tlbieBT2mb1 KYz4N5mJ7hjifGAQy4rDq88JDBruziIdGQgnC+cXCdBF9koC68HOItyewLXsHnCo27QW N72PBi7kZShkQu2fsaZYQk6GFnScpGfSbB7OgjFoKoGLRBGGbPpuDMiHySMzFEe5Yw7c shOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b="OT/TeaF5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d1si11356349plh.456.2021.10.27.00.16.24; Wed, 27 Oct 2021 00:17:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b="OT/TeaF5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236780AbhJZSx3 (ORCPT + 99 others); Tue, 26 Oct 2021 14:53:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236886AbhJZSxK (ORCPT ); Tue, 26 Oct 2021 14:53:10 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2809C061767 for ; Tue, 26 Oct 2021 11:50:44 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id j2so882384lfg.3 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=Y/mhUzTXspa+PlWhB8GCkfYOG3hrsMzE9pCrWgAUf6QCPMb0YeFZMyiwAgsczvzMPh JoeM4Xx6X7Fvj6WLI4Thgnd0CqEyVhxPSrs4dJD9xGpJBCvTP7TZ/sDgERCz2dtJNZAT ldoayU/hfkvx11pEERkjy/xhBsNlno2nVX2+A9NHgmQxjSExYDaqS1WAFxCedtFCXhwh NxQ2EV/SzJlmtc5WyKkWCS2rtYrQynfka+8XuRHGFSScEbl5gE91lwThvrqz+Mm0/6Ez XUIQDA2LKz20fX6d8+bbBiNn05QNyzoVvx6smy/SrUpqq2/q1xlFxBn7Er62f16ruXYu D94Q== X-Gm-Message-State: AOAM533bdMGvrw1wbsXaVhR6p3qhp8NUm5SPTrKlSV3cEtS9gE70n0+w IXg1dpOrv8hGxzOLJwvkKIaHfmt9cMy8Xi23gHSBMg== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); > >