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 X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A90EAC07E95 for ; Tue, 20 Jul 2021 15:52:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5471E610FB for ; Tue, 20 Jul 2021 15:52:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5471E610FB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0F9246B006C; Tue, 20 Jul 2021 11:52:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D16A6B0070; Tue, 20 Jul 2021 11:52:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB2F86B0071; Tue, 20 Jul 2021 11:52:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id C6A876B006C for ; Tue, 20 Jul 2021 11:52:02 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 4A0E0185282AC for ; Tue, 20 Jul 2021 15:52:01 +0000 (UTC) X-FDA: 78383407242.07.C6550D1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id E6E94100A7EB for ; Tue, 20 Jul 2021 15:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626796320; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7D01Sf7WyFpDy5iBOSB8keAwNmDOKVpIqWY7HiG+shw=; b=i4SZyGeBhYKgnJN13+G6GaueDE/A/sBlwpgi3Rn1Qo2Ye/fu0HdX+MKImZCnY9N2E4v4c8 BRrvu5YSMo7cmZPK8MdhEnKooSAqkm1qejsKSIvcdyec08Wt0WO9PsMszeH68rg55Lzbny bQAj1hgmU2LYGpc6HdkBecN2ROfOduA= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-532-MY_91Ly0Oaa6niNigJRGwA-1; Tue, 20 Jul 2021 11:51:56 -0400 X-MC-Unique: MY_91Ly0Oaa6niNigJRGwA-1 Received: by mail-qv1-f71.google.com with SMTP id l4-20020a0ce8440000b02902d89f797d08so19629401qvo.17 for ; Tue, 20 Jul 2021 08:51:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7D01Sf7WyFpDy5iBOSB8keAwNmDOKVpIqWY7HiG+shw=; b=TQ4j2vADot4uFtg7DZgjFTAhw/igbBL8WADBAS57oZCLwwK9KH8G6p/vkNcdmBcc0p bVHgieSNIsBl/iLa0W4IdIku8nEdcmgR9E6VnO9x9DT1pPBnQhyfwDgJ7aKDI5Xi1GMk jBZGzNABsjTKFDQkblIjWpBEYHonm4ZbHshJvGyip8sWyYbesFQCb738Latuex4yr6BH +AchkFA/8UJMczJmd3UAit8Tl8elF47uVFBGLgZuUL8SSrtczgfXS1MVQgvoLM71JEAr yacO4sgt3Xl0NLrJwWRmhTlI8NMF5eznNmgaXjUq1qWOuP9vV4Ei5+mUxMewNTm6LJOF GANg== X-Gm-Message-State: AOAM532oLnc3sEa47tttC0i3kqvmeyF6K4DpRWl+lKLNkmvs9zI7Fvlv 9Pp5a7fjafXiyVROmxckBbiV4o3AIuEoq9Vy1p02gjwWYYkkqWw2iFKfTp7SVxFYkSUbfDs6cBS H3DZ+Ut1/uVE= X-Received: by 2002:a37:dcc2:: with SMTP id v185mr29847460qki.167.1626796316444; Tue, 20 Jul 2021 08:51:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9NUWZkskDEWU7mGn9bqckF/hMB20JHvsawHIkAgaxaveiacbm2PLft2c6YquFp8IjnR6I+Q== X-Received: by 2002:a37:dcc2:: with SMTP id v185mr29847443qki.167.1626796316237; Tue, 20 Jul 2021 08:51:56 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id c15sm5467012qtc.37.2021.07.20.08.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 08:51:55 -0700 (PDT) From: Peter Xu To: stable@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hugh Dickins , Axel Rasmussen , Andrew Morton , peterx@redhat.com, Hillf Danton , Igor Raits Subject: [PATCH stable 5.13.y/5.12.y 1/2] mm/thp: simplify copying of huge zero page pmd when fork Date: Tue, 20 Jul 2021 11:51:49 -0400 Message-Id: <20210720155150.497148-2-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210720155150.497148-1-peterx@redhat.com> References: <796cbb7-5a1c-1ba0-dde5-479aba8224f2@google.com> <20210720155150.497148-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="US-ASCII" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E6E94100A7EB X-Stat-Signature: r3ccb7d1kpjx6jtzao78n3fjfwfw4udm Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i4SZyGeB; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf07.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com X-HE-Tag: 1626796320-23052 Content-Transfer-Encoding: quoted-printable 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: Patch series "mm/uffd: Misc fix for uffd-wp and one more test". This series tries to fix some corner case bugs for uffd-wp on either thp or fork(). Then it introduced a new test with pagemap/pageout. Patch layout: Patch 1: cleanup for THP, it'll slightly simplify the follow up patche= s Patch 2-4: misc fixes for uffd-wp here and there; please refer to each p= atch Patch 5: add pagemap support for uffd-wp Patch 6: add pagemap/pageout test for uffd-wp The last test introduced can also verify some of the fixes in previous patches, as the test will fail without the fixes. However it's not easy to verify all the changes in patch 2-4, but hopefully they can still be properly reviewed. Note that if considering the ongoing uffd-wp shmem & hugetlbfs work, patc= h 5 will be incomplete as it's missing e.g. hugetlbfs part or the special swap pte detection. However that's not needed in this series, and since that series is still during review, this series does not depend on that one (the last test only runs with anonymous memory, not file-backed). So this series can be merged even before that series. This patch (of 6): Huge zero page is handled in a special path in copy_huge_pmd(), however i= t should share most codes with a normal thp page. Trying to share more cod= e with it by removing the special path. The only leftover so far is the huge zero page refcounting (mm_get_huge_zero_page()), because that's separately done with a global counter. This prepares for a future patch to modify the huge pmd to be installed, so that we don't need to duplicate it explicitly into huge zero page case too. Link: https://lkml.kernel.org/r/20210428225030.9708-1-peterx@redhat.com Link: https://lkml.kernel.org/r/20210428225030.9708-2-peterx@redhat.com Signed-off-by: Peter Xu Cc: Kirill A. Shutemov Cc: Mike Kravetz , peterx@redhat.com Cc: Mike Rapoport Cc: Axel Rasmussen Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: Jerome Glisse Cc: Alexander Viro Cc: Brian Geffon Cc: "Dr . David Alan Gilbert" Cc: Joe Perches Cc: Lokesh Gidra Cc: Mina Almasry Cc: Oliver Upton Cc: Shaohua Li Cc: Shuah Khan Cc: Stephen Rothwell Cc: Wang Qing Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds (cherry picked from commit 5fc7a5f6fd04bc18f309d9f979b32ef7d1d0a997) Signed-off-by: Peter Xu --- mm/huge_memory.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 8857ef1543eb..4cea1e218b48 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1088,17 +1088,13 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struc= t mm_struct *src_mm, * a page table. */ if (is_huge_zero_pmd(pmd)) { - struct page *zero_page; /* * get_huge_zero_page() will never allocate a new page here, * since we already have a zero page to copy. It just takes a * reference. */ - zero_page =3D mm_get_huge_zero_page(dst_mm); - set_huge_zero_page(pgtable, dst_mm, vma, addr, dst_pmd, - zero_page); - ret =3D 0; - goto out_unlock; + mm_get_huge_zero_page(dst_mm); + goto out_zero_page; } =20 src_page =3D pmd_page(pmd); @@ -1122,6 +1118,7 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct = mm_struct *src_mm, get_page(src_page); page_dup_rmap(src_page, true); add_mm_counter(dst_mm, MM_ANONPAGES, HPAGE_PMD_NR); +out_zero_page: mm_inc_nr_ptes(dst_mm); pgtable_trans_huge_deposit(dst_mm, dst_pmd, pgtable); =20 --=20 2.31.1