From patchwork Tue Feb 20 03:48:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13563360 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 AFB19C48BC3 for ; Tue, 20 Feb 2024 03:48:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B11D36B0085; Mon, 19 Feb 2024 22:48:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ABF518D0003; Mon, 19 Feb 2024 22:48:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AEA06B0087; Mon, 19 Feb 2024 22:48:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8E0716B007B for ; Mon, 19 Feb 2024 22:48:47 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5413140554 for ; Tue, 20 Feb 2024 03:48:47 +0000 (UTC) X-FDA: 81810800694.21.7A5ECA9 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf07.hostedemail.com (Postfix) with ESMTP id BF45640007 for ; Tue, 20 Feb 2024 03:48:44 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708400925; 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=fr65SOWCv23X2MiY+qvdBo27LS6DAuaxHnQjCbyPxrg=; b=CGyN8vI25imCAxuQ2306712bdUQomZ3dk86TInEVRQNWLvz62zYBmQ4gW+k3qHhgxD3uD4 5IJip6jEO6LNyX3LQGt4+0KlQIFEiihDw1bT5ZD2lnm0cz6fAwB0B1JK6oyhwWJdLkMolH EGAf8EWCaooRGDgj9S9ztczXtM7FJCU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708400925; a=rsa-sha256; cv=none; b=C8YBvCSdRvOwiwfQ/OpB5NrztQyn0S5SRkaUZBh/DXl/msbAzP4yCCbmsFbVNj+WFoyeQ+ u+CHHfssQJs9cTJdTqDFG4SUWVgvvomQE4rtnz+t6TO4k818/jEcHC35VvD5FTmSCT8ZWI ILq9pIIxLJ9pViikEkZP/kE9kEMojB4= Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Tf4yF70nMz1FKnT; Tue, 20 Feb 2024 11:43:49 +0800 (CST) Received: from dggpemd200001.china.huawei.com (unknown [7.185.36.224]) by mail.maildlp.com (Postfix) with ESMTPS id 50EA11402DE; Tue, 20 Feb 2024 11:48:40 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemd200001.china.huawei.com (7.185.36.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.28; Tue, 20 Feb 2024 11:48:39 +0800 From: Wupeng Ma To: , , , , , CC: , , , , , , , Subject: [PATCH v4 1/3] x86/mm/pat: Move follow_phys to pat-related file Date: Tue, 20 Feb 2024 11:48:33 +0800 Message-ID: <20240220034835.507022-2-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240220034835.507022-1-mawupeng1@huawei.com> References: <20240220034835.507022-1-mawupeng1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemd200001.china.huawei.com (7.185.36.224) X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BF45640007 X-Stat-Signature: pdcuozmhj9ue4srrugewawex6ukz3fnk X-HE-Tag: 1708400924-785263 X-HE-Meta: U2FsdGVkX18XJJshSbgcIl2eqm1mEJmsIBCzbpVzvXbwgHlHAATY1xaXDJSiJIi14yGLPep0pYLFveaGr7/PLQ5JyUNIArnvujCtxKZCLOv6NU6o2RZwnMT3XpBckaas3jq8JaK5ed1UzlzKoUWQUSDSF9gvfLeST3ywmPkbs3n85/MGFLZcdEme/JwblWvXG49jwrOJW4Mu+J2CAFd6VVGqVhA1sIHYX9kys6MM7hPVSFDhdHAwGCTOA/Rrkpavj3456d3OjlAVqKdtgVuJoV/65L9iswy9dC1yO4AhJm3bHbJ245APqdZ3LKso7c1qo+THbxLcRw/8ZPPgtSUYh+vm3vLqp4H4M96pSI3phKkUqVdeNIYNVDdMqsaQs7gyifVFkDix90Ubaprq3+zjD2oID8EKRNc0+zsukHcv9vjCZId0Wv5ZJMuLuNQvm1XtflrE3F1B1pDfyYur2IVVzmHm5/oJ9bh+7OsFRFq5fA7o6Dpe553pW8idfG79N1KDj/oMld0skeoxw7OLfTcbNI6u199DwHqRIleTsrzUIWJdQYOoNyuqyAebXyJdj31B2c1auG9ltgv6cMC4JmmilCSr7FNPlU5mVXl8IpcZjhMi+Z9fuI5Ct3siEcbwQNraGMFB8V0q6TMBmHimyAWyk9ai96EaMmrua/1AGxW6wqpRldGkAPg0ZP5lu3MmfagMobRZPCm9P0sisPS/g9VmSA4NRYcVlI59cMpHbNMwnifQop3dNM2shDJdLlfYzBGKDuq6mIadxTSrBmV9HsBYTxz9W0pJWKdv604VA8NkCnQJewhT5NjgwfoHSXNjU32URW9Yt0+uq7a+PF9+ByGOLs8PFeH7fwZuP+fwO9SpvllhkWo+TiLf1LQMFI079mSkhYUY3sjNru5tagCsHHoFS7tfll9bpUnbuX+XKN7wBfPGYt85Ts8qFjln82h+RHqO46ZITnsSU2h0cqoG+d5 D4cc74hz sqruhdjsEUWc++nQqpjRQjKwOIj7ImklTuSImcjH6bU+uq9LrifbYNRqVFc5VGSX/ko64fEPCmIFwgGa8ZVvJ4ps+UYYn7WadOoRT6D0HYgHd18RGficmAhAklXlvFDUw3PZOsF00jhPp3OyhtlL9IlBf6RgxGBgg46PHY3qVs7h4jhwI6t//2qbZb7F93JztNp/A 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: From: Ma Wupeng Since only PAT in x86 use follow_phys(), move this to from memory.c to memtype.c and make it static. Since config HAVE_IOREMAP_PROT is selected by x86, drop this config macro. Signed-off-by: Ma Wupeng --- arch/x86/mm/pat/memtype.c | 28 ++++++++++++++++++++++++++++ include/linux/mm.h | 2 -- mm/memory.c | 28 ---------------------------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 0904d7e8e126..d8c37aaaf041 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -950,6 +950,34 @@ static void free_pfn_range(u64 paddr, unsigned long size) memtype_free(paddr, paddr + size); } +static int follow_phys(struct vm_area_struct *vma, + unsigned long address, unsigned int flags, + unsigned long *prot, resource_size_t *phys) +{ + int ret = -EINVAL; + pte_t *ptep, pte; + spinlock_t *ptl; + + if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) + goto out; + + if (follow_pte(vma->vm_mm, address, &ptep, &ptl)) + goto out; + pte = ptep_get(ptep); + + if ((flags & FOLL_WRITE) && !pte_write(pte)) + goto unlock; + + *prot = pgprot_val(pte_pgprot(pte)); + *phys = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT; + + ret = 0; +unlock: + pte_unmap_unlock(ptep, ptl); +out: + return ret; +} + /* * track_pfn_copy is called when vma that is covering the pfnmap gets * copied through copy_page_range(). diff --git a/include/linux/mm.h b/include/linux/mm.h index f5a97dec5169..75c683f2f5ae 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2375,8 +2375,6 @@ int follow_pte(struct mm_struct *mm, unsigned long address, pte_t **ptepp, spinlock_t **ptlp); int follow_pfn(struct vm_area_struct *vma, unsigned long address, unsigned long *pfn); -int follow_phys(struct vm_area_struct *vma, unsigned long address, - unsigned int flags, unsigned long *prot, resource_size_t *phys); int generic_access_phys(struct vm_area_struct *vma, unsigned long addr, void *buf, int len, int write); diff --git a/mm/memory.c b/mm/memory.c index 15f8b10ea17c..86ad7f1ca3af 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5802,34 +5802,6 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address, EXPORT_SYMBOL(follow_pfn); #ifdef CONFIG_HAVE_IOREMAP_PROT -int follow_phys(struct vm_area_struct *vma, - unsigned long address, unsigned int flags, - unsigned long *prot, resource_size_t *phys) -{ - int ret = -EINVAL; - pte_t *ptep, pte; - spinlock_t *ptl; - - if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) - goto out; - - if (follow_pte(vma->vm_mm, address, &ptep, &ptl)) - goto out; - pte = ptep_get(ptep); - - if ((flags & FOLL_WRITE) && !pte_write(pte)) - goto unlock; - - *prot = pgprot_val(pte_pgprot(pte)); - *phys = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT; - - ret = 0; -unlock: - pte_unmap_unlock(ptep, ptl); -out: - return ret; -} - /** * generic_access_phys - generic implementation for iomem mmap access * @vma: the vma to access