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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0F9AC433EF for ; Sun, 27 Feb 2022 03:00:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8AC88D0016; Sat, 26 Feb 2022 22:00:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C3AB28D0007; Sat, 26 Feb 2022 22:00:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADABA8D0016; Sat, 26 Feb 2022 22:00:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0119.hostedemail.com [216.40.44.119]) by kanga.kvack.org (Postfix) with ESMTP id 9AA148D0007 for ; Sat, 26 Feb 2022 22:00:50 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 56B1D9791D for ; Sun, 27 Feb 2022 03:00:50 +0000 (UTC) X-FDA: 79187057460.22.E51A47C Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) by imf20.hostedemail.com (Postfix) with ESMTP id CD2561C0005 for ; Sun, 27 Feb 2022 03:00:49 +0000 (UTC) Received: by mail-oo1-f41.google.com with SMTP id u47-20020a4a9732000000b00316d0257de0so13244936ooi.7 for ; Sat, 26 Feb 2022 19:00:49 -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=2z1pRmn1T2Qq2g9KlTJ37xlcneIUSbISMr8g/idJeeo=; b=VClutb9yYCy5/JCAn1Xcv1/Q7zQD1CNaINyAtJw7xexLiht6HubWw0S0fyxvREGuAx AkQSzwxz6ZDsk7nE/vE+zic6fKtitlu65BvP5+SBQCso/Ev5PPCSxCBj6J+6Ga96BAVe sf/VU7deVwQwqSHao9RFYPX9zZNNhHNautK1DpKVj3dzqYALVXMc/Ri4hD6nQFBmOg0z FfVzf215oUQMDN+K4mwz1erGRgMOP9nffZwTuYU7uuE27oARoxM+05LlLnkUsO6Beicx NnCMfhKu0h1YH5yvdIYT7DNoAD1XxmcQYZvxuCEPOkNTnFv4D5uL4Nty6fQiMuJ70lft zcKw== 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=2z1pRmn1T2Qq2g9KlTJ37xlcneIUSbISMr8g/idJeeo=; b=EGNnl70IcHIHKWPMBjCmRYuXE7VgSoSB8aSbUAxUvCwBpryK3FF6vJoiozWCcrSbiD PokU5E8xVMTwRf+rkCeZDNAJ8AeCnA+KIY3u9P8Kb8Nsgl4DjHr3lQdLH/b4s+Z6xIWo KqlHax0OhfLI6WATSVqmUbERd9ZfpKtREdicW6VENZgviaCP2QuNwBiYkCcQJIrqf73f aJ3O215HvFJDlrbBIi8XnE4NmilI3jRDrFD/1KYjTjXTZzonSPW2ADcrtq8/U8pqX2l3 tOPhHkpY++hh++0nHf6+m356HPl96P0RjA7bt1KjkvN+V96h96yaQc/dECrnkViCihAq dbTA== X-Gm-Message-State: AOAM531VeEzYBnrsOz0lWsKPLcnDl1YYhD59RWIptdj0IizKsfAGEhq7 qhBIzFvQTQTs8gACFi8qFOUM0Q== X-Google-Smtp-Source: ABdhPJxwMtTS/A+ZsASHAfYUz5ChWEMPKqwDCApb92U8vWxlucGbX1KrxSno8Vgh5CpRhelf9PBr9Q== X-Received: by 2002:a4a:ad41:0:b0:319:462a:9c0c with SMTP id s1-20020a4aad41000000b00319462a9c0cmr5971065oon.76.1645930848911; Sat, 26 Feb 2022 19:00:48 -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 i5-20020a056870578500b000d6e1a022e4sm2726725oap.32.2022.02.26.19.00.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 19:00:48 -0800 (PST) Date: Sat, 26 Feb 2022 19:00:37 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Mike Kravetz , Matthew Wilcox cc: Hugh Dickins , cgel.zte@gmail.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: Message-ID: <8986d97-3933-8fa7-abba-aabd67924bc2@google.com> 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-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: CD2561C0005 X-Stat-Signature: pa8fzhq3eqjr1aig91f7dm7bofjbfpjx Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=VClutb9y; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of hughd@google.com designates 209.85.161.41 as permitted sender) smtp.mailfrom=hughd@google.com X-HE-Tag: 1645930849-877909 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 Thu, 17 Feb 2022, Matthew Wilcox wrote: > On Wed, Feb 16, 2022 at 05:25:17PM -0800, Hugh Dickins wrote: > > On Wed, 16 Feb 2022, Mike Kravetz wrote: > > > On 2/14/22 23:37, cgel.zte@gmail.com wrote: ... > > > > @@ -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). Mike, we had the same instinctive reaction to seeing a PageTransCompound check in code also exposed to PageHuge pages; but in fact that seems to have worked correctly - those hugetlbfs pages are hard to predict! But it was not working on pte maps of THPs. > > > > 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. > > I did change how the XArray works for THP recently. > > Kirill's original patch stored: > > 512: p > 513: p+1 > 514: p+2 > ... > 1023: p+511 > > A couple of years ago, I changed it to store: > > 512: p > 513: p > 514: p > ... > 1023: p > > And in January, Linus merged the commit which changes it to: > > 512-575: p > 576-639: (sibling of 512) > 640-703: (sibling of 512) > ... > 960-1023: (sibling of 512) > > That is, I removed a level of the tree and store sibling entries > rather than duplicate entries. That wasn't for fun; I needed to do > that in order to make msync() work with large folios. Commit > 6b24ca4a1a8d has more detail and hopefully can inspire whatever > changes you need to make to your patch. Matthew, thanks for the very detailed info, you shouldn't have taken so much trouble over it: I knew you had done something of that kind, and yes, that's where my suspicion lay at the time of writing. But you'll be relieved to know that the patch I wrote before your changes turned out to be unaffected, and just as valid after your changes. "just found something failing which I thought should pass" was me forgetting, again and again, just how limited are the allowed possibilities for F_SEAL_WRITE when mmaps are outstanding. One thinks that a PROT_READ, MAP_SHARED mapping would be allowed; but of course all the memfds are automatically O_RDWR, so mprotect (no sealing hook) allows it to be changed to PROT_READ|PROT_WRITE, so F_SEAL_WRITE is forbidden on any MAP_SHARED mapping: only allowed on MAP_PRIVATEs. I'll now re-read the commit message I wrote before, update if necessary, and then send to Andrew, asking him to replace the one in this thread. Hugh