From patchwork Mon Apr 29 07:24:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13646412 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 A509EC04FFE for ; Mon, 29 Apr 2024 07:24:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22EA56B008A; Mon, 29 Apr 2024 03:24:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DD986B008C; Mon, 29 Apr 2024 03:24:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A6C36B0092; Mon, 29 Apr 2024 03:24:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DC4886B008A for ; Mon, 29 Apr 2024 03:24:36 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9E814A25A6 for ; Mon, 29 Apr 2024 07:24:36 +0000 (UTC) X-FDA: 82061731752.28.5C8D6D8 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf15.hostedemail.com (Postfix) with ESMTP id 474DEA0004 for ; Mon, 29 Apr 2024 07:24:33 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714375475; h=from:from:sender: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=dPwSMqfyeRfZEvN7u+MuvciL8ss1iBEKKPOI5/l7uv4=; b=7DPl0FWF/U4c9ambzeNsSthVvtgt5NGuiiTpdRP+Ypjuf61cYj03fcIfIcnG3ejiT2OsX/ jXAF2I+/1UGqGdH4U+e5wkb57WWchxe5YYl41ygPXdZbvQUYcqEprkDTH6ERPxTcHcBoqg 7fMEUmJxtAaB65Uv0Yw6ml++62TYcR0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714375475; a=rsa-sha256; cv=none; b=WtPDkl9KBTVyweJP+f59xBqE9Yxd+x7kH01NunRez5LhVmn3g96mYg0eHxhnySL/S937Qj xn56pVcyXGwVayQqKMEHVJbE/4OfJizEHG/VsWk058pXidpccaNxLze/q5n/d2IhGVt5JQ 9Xm7j/4qOsennwVgdBB8ctdAE8GY1Rs= Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VSZWN5QPRzvPrW; Mon, 29 Apr 2024 15:21:20 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id CBA76140429; Mon, 29 Apr 2024 15:24:28 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 29 Apr 2024 15:24:28 +0800 From: Kefeng Wang To: Andrew Morton CC: "Matthew Wilcox (Oracle)" , , , Kefeng Wang Subject: [PATCH rfc 1/4] mm: memory: add prepare_range_pte_entry() Date: Mon, 29 Apr 2024 15:24:14 +0800 Message-ID: <20240429072417.2146732-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240429072417.2146732-1-wangkefeng.wang@huawei.com> References: <20240429072417.2146732-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Queue-Id: 474DEA0004 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: cj8c1ea1kprsorjgqstptb5ooecngq5p X-HE-Tag: 1714375473-449214 X-HE-Meta: U2FsdGVkX19Tq3XTup8Pn14rwclKnH4H3Dva/T6LPudE2c/H55BsF2fyQv4SDdCjHQhtF95aEeqrolmT2S/Gj22mpWnQ2wyRh4Zy6hOorKdMobsayM7vF9CMs0cTTPRW+gK5rz5xehr7rld5IsqBtLrptzFa+Zd4fWl1X+PhK9DB4OjpJKL9GhTfDOsVdG7SOks+1VIwoGbIrz1BkCyLBYUsni+s3UJgbU3GD/tp39dqTZlFke+Hp5nJksgxl5RLGYD0zwO0F2WQypRK7JKU13nYqUVNBXzrpe4ZSKij8d8s8sFlP5zGtPLHpzWzrmAw6wCbeaVcmCRdWlvbwj4Zi51gO/GuGc42oVyfy8QYQc+X6XBhs9qnkd6JE0mmk9K8aCZJlDLi7QuNOlc39UIe2rNLOvx5zqaZiNPdxFDhN2tYNVS1r9wafemw+VRZwdugehzvwXH9yFs3i4AWDhNaw0P+viZl22ckYlnu66nhEbwev6KSaOdkAjsIYqWzAyoleQ9nxq2Cx52KXGYvvE7wymKfp0JDkdBMkOsLXIlSmTIbYA7Uuu5GMYFWbglBdXbCRbzM7gowVDJ1bBq2uAmWsovlev00AdlXVL/KHXs14Ix0WLJTNiNvZnz0sdKKKTAMftOCEpNuZNQParkfRyvXh2E50sIUDTFZH9ko+MyLGiaa5IdoYxrIs9tr/dFXuWzoNpPhV9NM2PCc4WySNm6+eWmHiXIl3F/+BoGMBPMo6rP9HCdAFMBlczqdOywCTzrOPSH8IIQgEoO7ZGIEI94BZP1rYmmqathMXQiWjPdkdbyYRo/j7OvcGF7lCVk/GpM+gP7tZE1qQs9a12xQw6tmM7A3RlE3XYcaKItmzpStNFz0a8puVT88q9d7TRUV23cZ13IwYyw21WAqBmkrvF8nfSzb6/eLgUmyhl34goV3GIKsZikNXe/ugBH2o9JCKLRGrcny4ch3CE4yIxomAEl uUt4n6TV HFXg5YRvo8omiYdzj48x7/Ek3BthbSLhgVG7exw9gbiRRIyzhuNge1Qf5+WcNB8CVXZxNuZJpVt18IfeIU7hFGmzF8qGONKzwOxxZWZI4jK4aTHRj9miRGmgbHrSdSDrSVqK7zvCXhIMrZ2Htd4jFLZ01DFQmaCgSyEXWiy4ZZPi5otj+Z90lYREiqiTyT9xHhkiT 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: List-Subscribe: List-Unsubscribe: This is prepare for a separate filemap_set_pte_range(), add a prepare_range_pte_entry(), no functional changes. Signed-off-by: Kefeng Wang --- include/linux/mm.h | 2 ++ mm/memory.c | 33 ++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 9849dfda44d4..bcbeb8a4cd43 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1372,6 +1372,8 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) } vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page); +pte_t prepare_range_pte_entry(struct vm_fault *vmf, bool write, struct folio *folio, + struct page *page, unsigned int nr, unsigned long addr); void set_pte_range(struct vm_fault *vmf, struct folio *folio, struct page *page, unsigned int nr, unsigned long addr); diff --git a/mm/memory.c b/mm/memory.c index 6647685fd3c4..ccbeb58fa136 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4652,19 +4652,11 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) } #endif -/** - * set_pte_range - Set a range of PTEs to point to pages in a folio. - * @vmf: Fault decription. - * @folio: The folio that contains @page. - * @page: The first page to create a PTE for. - * @nr: The number of PTEs to create. - * @addr: The first address to create a PTE for. - */ -void set_pte_range(struct vm_fault *vmf, struct folio *folio, - struct page *page, unsigned int nr, unsigned long addr) +pte_t prepare_range_pte_entry(struct vm_fault *vmf, bool write, + struct folio *folio, struct page *page, + unsigned int nr, unsigned long addr) { struct vm_area_struct *vma = vmf->vma; - bool write = vmf->flags & FAULT_FLAG_WRITE; bool prefault = in_range(vmf->address, addr, nr * PAGE_SIZE); pte_t entry; @@ -4680,6 +4672,25 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio, entry = maybe_mkwrite(pte_mkdirty(entry), vma); if (unlikely(vmf_orig_pte_uffd_wp(vmf))) entry = pte_mkuffd_wp(entry); + + return entry; +} + +/** + * set_pte_range - Set a range of PTEs to point to pages in a folio. + * @vmf: Fault description. + * @folio: The folio that contains @page. + * @page: The first page to create a PTE for. + * @nr: The number of PTEs to create. + * @addr: The first address to create a PTE for. + */ +void set_pte_range(struct vm_fault *vmf, struct folio *folio, + struct page *page, unsigned int nr, unsigned long addr) +{ + struct vm_area_struct *vma = vmf->vma; + bool write = vmf->flags & FAULT_FLAG_WRITE; + pte_t entry = prepare_range_pte_entry(vmf, write, folio, page, nr, addr); + /* copy-on-write page */ if (write && !(vma->vm_flags & VM_SHARED)) { VM_BUG_ON_FOLIO(nr != 1, folio);