Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp685614pxv; Thu, 22 Jul 2021 09:42:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyjQzaSj2fpjnLpw8bYi9Bq9OHYdaG+v5WtehB22U25CdcjI4CmkraVZrxXTAOz+HjCBXS X-Received: by 2002:a02:8529:: with SMTP id g38mr393891jai.88.1626972144595; Thu, 22 Jul 2021 09:42:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626972144; cv=none; d=google.com; s=arc-20160816; b=rSc5TIMmwqNlTP+lIjiYHEg+e/i86W9iXhFTsDyF15MZvQtZg+2PAuXpVxj8dSdhOV lAfKUiOI2idFb6KXbIaoU3pUN52xAU/C00IyXVdwFNtXdNgpxeuaJZ2qQJgt/PvrnSxy LxotpBusxKrbYeUn5hdt8ieyk1kPNmLB6hWD3ZFjsohrRTyedCUEs7Di/akygm1m4zrb 3x1MZmmR2CqH/Sm5/vb4JShsxCml2yXoVDu5zAoPQ2P2g+rkYG7oeA1/JGhlRYWtM8Um 8F7R39iYheE/IKMhv3qCctEF8urKgbyCkdCHfep+H8xstQEOfHoOypPXqiTaxDWk/LFP OxMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=k9E+LzLz/RNAqdxk/BYT0q7iJFQjErffiHfEornONrU=; b=uxCI9bj6bMmDsjaS5s2kZ12KKQahdqpL6lMGCs5V854hoyZvwWQyuDEC/uIWKLx7Rs GAodg9FFqBEgkWPTQjXHetZRxjBgN0alof9zuke98ifMJP4g+HkjqE2TbXIYIgCZMjGt 2fzqC+On0zZZGja28Qus6LR3THRg2kt1kuga9IUq8ym44OhZUdtWhnMJba/bLoHFQJRN GI+KZjWltaxR3Rc3P9GDpqCmOPnBQn4pAge50dDxHVMSnr6w2AdO+3q5WiNhYIj+p3QP /zLtfoI4NsdeQPwEz1Mj89lqCSNyT4qBzBJj4RNOblP2ZrCnX3HRMmn5WNVqhNu7Zf+t FaTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d0UKGADs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q5si22885763ilt.55.2021.07.22.09.42.13; Thu, 22 Jul 2021 09:42:24 -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=@linuxfoundation.org header.s=korg header.b=d0UKGADs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233830AbhGVQAw (ORCPT + 99 others); Thu, 22 Jul 2021 12:00:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:35570 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233043AbhGVP6X (ORCPT ); Thu, 22 Jul 2021 11:58:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 434FE61378; Thu, 22 Jul 2021 16:38:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626971938; bh=cCJn7qnt/0tEtvAPVPNZbSBA+jKoq+PJrCuPUMae/dE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d0UKGADsAQ/3XyBCn6rfe5S9pa63qCCfGcktL84m7ohF+dN3Ae/EWI/Osi6kQZbj6 TgbPPNau1PwK0h1kIcKS6hD5blD28tI9i5NyZC1fjedYcE/lXzrST0egVRpjkAkGxy m9EJqIHj9H/CI9DYdZR67PO5egmERwWhHX3W7jNU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Xu , "Kirill A. Shutemov" , Mike Rapoport , Axel Rasmussen , Andrea Arcangeli , Hugh Dickins , Jerome Glisse , Alexander Viro , Brian Geffon , "Dr . David Alan Gilbert" , Joe Perches , Lokesh Gidra , Mina Almasry , Oliver Upton , Shaohua Li , Shuah Khan , Stephen Rothwell , Wang Qing , Andrew Morton , Linus Torvalds , Mike Kravetz Subject: [PATCH 5.10 085/125] mm/thp: simplify copying of huge zero page pmd when fork Date: Thu, 22 Jul 2021 18:31:16 +0200 Message-Id: <20210722155627.513082888@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210722155624.672583740@linuxfoundation.org> References: <20210722155624.672583740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Xu commit 5fc7a5f6fd04bc18f309d9f979b32ef7d1d0a997 upstream. 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 patches Patch 2-4: misc fixes for uffd-wp here and there; please refer to each patch 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, patch 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 it should share most codes with a normal thp page. Trying to share more code 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 Signed-off-by: Greg Kroah-Hartman --- mm/huge_memory.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1074,17 +1074,13 @@ int copy_huge_pmd(struct mm_struct *dst_ * 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 = mm_get_huge_zero_page(dst_mm); - set_huge_zero_page(pgtable, dst_mm, vma, addr, dst_pmd, - zero_page); - ret = 0; - goto out_unlock; + mm_get_huge_zero_page(dst_mm); + goto out_zero_page; } src_page = pmd_page(pmd); @@ -1110,6 +1106,7 @@ int copy_huge_pmd(struct mm_struct *dst_ 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);