From patchwork Tue Feb 15 07:37:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: CGEL X-Patchwork-Id: 12746563 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 34EA0C433EF for ; Tue, 15 Feb 2022 07:37:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 976B76B0078; Tue, 15 Feb 2022 02:37:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 925F66B007B; Tue, 15 Feb 2022 02:37:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 814CB6B007D; Tue, 15 Feb 2022 02:37:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0111.hostedemail.com [216.40.44.111]) by kanga.kvack.org (Postfix) with ESMTP id 7261F6B0078 for ; Tue, 15 Feb 2022 02:37:53 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 33FE9903C2 for ; Tue, 15 Feb 2022 07:37:53 +0000 (UTC) X-FDA: 79144210026.30.328BF93 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by imf03.hostedemail.com (Postfix) with ESMTP id CA2CE20002 for ; Tue, 15 Feb 2022 07:37:52 +0000 (UTC) Received: by mail-qk1-f181.google.com with SMTP id o12so16597878qke.5 for ; Mon, 14 Feb 2022 23:37:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=F0LAKoVYl1MZjeStkRC8r6GRhivZgElOJcOkTtD3oHM=; b=UrKdO7iAVP05Udr/yHw9mtXB74ZzhFVugvZUCBwKtyzUlNBB8LrM73EScng7W54qvp U6DGBzIG1kASMH4hmaIuCsz4JjiZTe9ZFwK8Jmh1sg9q9mHVcKjTPj50iNb76kvOykS8 BKGdl0ojsCoZdGPj9xcsqWMSnFsBZB7VZbtsPy7VxpG9dUSqeASXLC7Y7hC9f3/haIaP fUQoII7cuBmp4qt7QufPabSr7qketWiYvApkk1XAmsc63DnlP7Tay04MqrE6bUbeNQm6 laTV16SwXwP4lX2Nh7Wlk498o3QHtx2PeWJ3Hte5hoNW7MnZQ/qlwxcaPQfF9cm19sRz FZgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=F0LAKoVYl1MZjeStkRC8r6GRhivZgElOJcOkTtD3oHM=; b=m/ijPET7tWYSVvAIS31BpE5xQEminrlys0ZN1zDOnFjriHgcWBeNYkVWglmObh3b5W dZk8XZJRr6cbbendEi/lty8K076GxWMiD5aeb8Ki1UKGzoAjLpnA1eMr4ay7ft0FcB3V GPc1o5sgmO+pe9tJWYf0B9o1z5pSuMoOKUwZLD/Ic0xv8wtq+ZFtQ9sWxgrOyFYn7sLW aZBW2gZzLV7HtQmHcEd1kmqXeb+aeDwBmGpkE6wXbki8Zw6NsYxIbgNix58cAWtRX0E6 4MoYrIY7DpzrxfzFS+X+z1dGjM+bW1TaZZaaoqy19Tc6emCL2nKtrpgG11eeGumfkF15 AxYQ== X-Gm-Message-State: AOAM531+wduLD0sTm/USYeckQEtRojGgOEs/Jptmw4iSD6NQa9HGx0cm ONBbZmpwHAvCEFtO8k1PoqQ= X-Google-Smtp-Source: ABdhPJz0/j8DkupPrdaGaUjXGHFu2oCDBSGC0sqidg2/kdymnXTBSpLoE9Uk1tN/YIAMhuh0cXJnMA== X-Received: by 2002:a05:620a:12ae:: with SMTP id x14mr1361641qki.610.1644910672135; Mon, 14 Feb 2022 23:37:52 -0800 (PST) Received: from localhost.localdomain ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id e1sm10644995qtw.71.2022.02.14.23.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 23:37:51 -0800 (PST) From: cgel.zte@gmail.com To: hughd@google.com, mike.kravetz@oracle.com, kirill@shutemov.name, songliubraving@fb.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, yang.yang29@zte.com.cn, wang.yong12@zte.com.cn, Zeal Robot Subject: [PATCH linux-next] Fix shmem huge page failed to set F_SEAL_WRITE attribute problem Date: Tue, 15 Feb 2022 07:37:43 +0000 Message-Id: <20220215073743.1769979-1-cgel.zte@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: CA2CE20002 X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=UrKdO7iA; spf=pass (imf03.hostedemail.com: domain of cgel.zte@gmail.com designates 209.85.222.181 as permitted sender) smtp.mailfrom=cgel.zte@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: acqsspo3cqtz1aezi5yptbqtrgz74iro X-Rspamd-Server: rspam11 X-HE-Tag: 1644910672-362463 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: 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)) + count -= (1 << compound_order(compound_head(page))) - 1; + if (count - page_mapcount(page) > 1) xas_set_mark(xas, MEMFD_TAG_PINNED); if (++tagged % XA_CHECK_SCHED) @@ -67,11 +72,12 @@ static int memfd_wait_for_pins(struct address_space *mapping) { XA_STATE(xas, &mapping->i_pages, 0); struct page *page; - int error, scan; + int error, scan, count; memfd_tag_pins(&xas); error = 0; + count = 0; for (scan = 0; scan <= LAST_SCAN; scan++) { unsigned int tagged = 0; @@ -89,8 +95,12 @@ static int memfd_wait_for_pins(struct address_space *mapping) bool clear = true; 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)) + count -= (1 << compound_order(compound_head(page))) - 1; + if (count - page_mapcount(page) != 1) { /* * On the last scan, we clean up all those tags * we inserted; but make a note that we still