Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp400441pxb; Thu, 17 Feb 2022 06:35:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJyAauwHPGD8DbhiVsdoFpFvuA0njpiRCAEZpgZ/wIpP2sjMHRPreOeN5U9oDam9SKZ9efk0 X-Received: by 2002:a17:903:2451:b0:14f:b91:fe3c with SMTP id l17-20020a170903245100b0014f0b91fe3cmr3214102pls.120.1645108543385; Thu, 17 Feb 2022 06:35:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645108543; cv=none; d=google.com; s=arc-20160816; b=AF4GLM23nBu1wwmUVXWdJzG5DBK5VBWvQP9oh8ukJcS6/CUIj7BgeZtS6fylAd08Yr KgxUXnmmqwMgnXr5MHdXncg2MH+52KvwS3/W70wGfYt/Lj6V3u9tLjMXlSUQDhptvhht 5dh0fYWKT9ybB8GI/dxI9W3/atERZrGfqNOReLxXGkl3FQC6+oCRL6F4RDHoiNqs/TW2 u7f7xY7D6bTrnR7D53jvyb9kFinDZVY+Cty/iWgGbPdkHX04WhX+4KDgbfShD2zaB4gh lAAB/UZp3l0Hi7J+8yMVBmwEOKFnrDM3NX+B7GCypUfUbQXjX/b7r/smwWP8sM+68Xri jdSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=JSwIX/NYsZ0hu1H4cWPLct5FZqQSU6n5RuasJx3jNYU=; b=oGJwplKK5tRu54VnxNQyfQ+9FnVilpv4pKrpEm8pQaDab6mQkv6SQizRfHNfeI2Vi6 oRZvMrM0u/lY66Rh71fweUm0SNnARWb+39pUJJIOAdptpnhCqoMyCc5qQBxoMCv1iZJE 3GIq/JXozqVBpe0x1E0BK8OaXlyVF1g+UgudT4Pm9+dN1siebHoHVz9iPOGVj+/pUPds rl/SH0mXERy3JnowHgZYwZRlFzzGUrd8Id0egv/xFoZi2ueSL+OCmREYeH1fZsW1WY3d W0ivvSt7QEXdCv9jOKafpEmTJwmZnrY8i4iNHUlba8JiUwTsU26sIrN0zJ9Wm3ysj9aC euOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FYI6wf5r; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x9si9489199pgu.748.2022.02.17.06.35.26; Thu, 17 Feb 2022 06:35:43 -0800 (PST) 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; dkim=pass header.i=@google.com header.s=20210112 header.b=FYI6wf5r; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230304AbiBQBZr (ORCPT + 99 others); Wed, 16 Feb 2022 20:25:47 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230345AbiBQBZp (ORCPT ); Wed, 16 Feb 2022 20:25:45 -0500 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FBC31F227A for ; Wed, 16 Feb 2022 17:25:32 -0800 (PST) Received: by mail-qv1-xf2c.google.com with SMTP id x3so5457805qvd.8 for ; Wed, 16 Feb 2022 17:25:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=JSwIX/NYsZ0hu1H4cWPLct5FZqQSU6n5RuasJx3jNYU=; b=FYI6wf5rAV7stlDCNtzPtDrK1dHkqGs7MmcJ89nBm65MP2Jvub4XNSSk5HywC2U6lI XRZQg4uxL8R9+5lROLpwIQODTFYRZO5cWvoCJdPBg5SP78CjJXMh7DIAeK9QM9HKnUmI /ceJRHrJhbUuJWWN6Hxy/P8v0QguslJtOfb1lSOrevd9jgowjV4UJ6rijrqO1Vy70H1z yW0aZrxTHZZry3QdUoyGk74AtvQEFrmGt6vLqQQiDpa17ggZbUII4iFsgEtLbA8spb14 obsc/6yIsOPF3eB+8z3us5wnWZEt0604uHto0CVsg5Yg+7O2m+bR0pr8o+R3ztndiZGm 2Jkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=JSwIX/NYsZ0hu1H4cWPLct5FZqQSU6n5RuasJx3jNYU=; b=V++1lQGCpDVJV9EvwzKERzlQOHgCGr9hYXsgWhH5fy5FERFxOWu5UMhOdINjHf+7IJ f1WizZla1AeJ2kShNSNiBkqij9pVsjnL3imNMpGtzIHQggE7q4IwnZ3Fy/hI27R5MJ5w z6gDBEf4es1F2UmVJSGSkJ5qQEQMIViOwpmQgdNJx7+KTRHPuzYBcjcuomqU4/t6sM1Y eZm0hC/uk3yz1SDwdLk3ZwkUu1ywWhSgXPBnJ2pk4DbHA4dXp2dj5muIwHnsWl+FZO6y H5Tb9kBrNFhKtcmJ2aTnL2qtfRqD8h5MtAqsXf3BcMwIqU3NDxkwjzHoOeP3st/IBS02 /arQ== X-Gm-Message-State: AOAM5338wScbFczzAA5Ivc7hBFcZOr3WB+nJB9At/MTnw9P64JxOFai1 vIXuG+tK5QDyp4/B0U4lti4dqg== X-Received: by 2002:a05:622a:4f:b0:2c9:a3f9:debd with SMTP id y15-20020a05622a004f00b002c9a3f9debdmr544892qtw.689.1645061131319; Wed, 16 Feb 2022 17:25:31 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id c21sm22843184qte.68.2022.02.16.17.25.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 17:25:30 -0800 (PST) Date: Wed, 16 Feb 2022 17:25:17 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Mike Kravetz cc: cgel.zte@gmail.com, hughd@google.com, kirill@shutemov.name, songliubraving@fb.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, yang.yang29@zte.com.cn, wang.yong12@zte.com.cn, Zeal Robot Subject: Re: [PATCH linux-next] Fix shmem huge page failed to set F_SEAL_WRITE attribute problem In-Reply-To: <1f486393-3829-4618-39a1-931afc580835@oracle.com> Message-ID: References: <20220215073743.1769979-1-cgel.zte@gmail.com> <1f486393-3829-4618-39a1-931afc580835@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 16 Feb 2022, Mike Kravetz wrote: > On 2/14/22 23:37, cgel.zte@gmail.com wrote: > > From: wangyong > > > > After enabling tmpfs filesystem to support transparent hugepage with the > > following command: > > echo always > /sys/kernel/mm/transparent_hugepage/shmem_enabled > > The docker program adds F_SEAL_WRITE through the following command will > > prompt EBUSY. > > fcntl(5, F_ADD_SEALS, F_SEAL_WRITE)=-1. > > > > It is found that in memfd_wait_for_pins function, the page_count of > > hugepage is 512 and page_mapcount is 0, which does not meet the > > conditions: > > page_count(page) - page_mapcount(page) != 1. > > But the page is not busy at this time, therefore, the page_order of > > hugepage should be taken into account in the calculation. > > > > Reported-by: Zeal Robot > > Signed-off-by: wangyong > > --- > > mm/memfd.c | 16 +++++++++++++--- > > 1 file changed, 13 insertions(+), 3 deletions(-) > > > > diff --git a/mm/memfd.c b/mm/memfd.c > > index 9f80f162791a..26d1d390a22a 100644 > > --- a/mm/memfd.c > > +++ b/mm/memfd.c > > @@ -31,6 +31,7 @@ > > static void memfd_tag_pins(struct xa_state *xas) > > { > > struct page *page; > > + int count = 0; > > unsigned int tagged = 0; > > > > lru_add_drain(); > > @@ -39,8 +40,12 @@ static void memfd_tag_pins(struct xa_state *xas) > > xas_for_each(xas, page, ULONG_MAX) { > > if (xa_is_value(page)) > > continue; > > + > > page = find_subpage(page, xas->xa_index); > > - if (page_count(page) - page_mapcount(page) > 1) > > + count = page_count(page); > > + if (PageTransCompound(page)) > > PageTransCompound() is true for hugetlb pages as well as THP. And, hugetlb > pages will not have a ref per subpage as THP does. So, I believe this will > break hugetlb seal usage. Yes, I think so too; and that is not the only issue with the patch (I don't think page_mapcount is enough, I had to use total_mapcount). It's a good find, and thank you WangYong for the report. I found the same issue when testing my MFD_HUGEPAGE patch last year, and devised a patch to fix it (and keep MFD_HUGETLB working) then; but never sent that in because there wasn't time to re-present MFD_HUGEPAGE. I'm currently retesting my patch: just found something failing which I thought should pass; but maybe I'm confused, or maybe the xarray is working differently now. I'm rushing to reply now because I don't want others to waste their own time on it. Andrew, please expect a replacement patch for this issue, but I certainly have more testing and checking to do before sending. Hugh > > I was trying to do some testing via the memfd selftests, but those have some > other issues for hugetlb that need to be fixed. :( > -- > Mike Kravetz