From nobody Sat Apr 11 13:01:22 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F8CDC64EC4 for ; Tue, 7 Mar 2023 02:26:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229983AbjCGC0b (ORCPT ); Mon, 6 Mar 2023 21:26:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229653AbjCGC02 (ORCPT ); Mon, 6 Mar 2023 21:26:28 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 177425CC23 for ; Mon, 6 Mar 2023 18:26:12 -0800 (PST) Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PVzlp5YjczKqKs; Tue, 7 Mar 2023 10:24:06 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 7 Mar 2023 10:26:10 +0800 From: Wupeng Ma To: , , , CC: , , , Subject: [PATCH v2 -next 1/3] x86/mm/pat: Move follow_phys to pat-related file Date: Tue, 7 Mar 2023 10:26:04 +0800 Message-ID: <20230307022606.2367399-2-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230307022606.2367399-1-mawupeng1@huawei.com> References: <20230307022606.2367399-1-mawupeng1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 de10800cd4dd..4fb1e89f32e4 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 si= ze) memtype_free(paddr, paddr + size); } =20 +static int follow_phys(struct vm_area_struct *vma, unsigned long address, + unsigned int flags, unsigned long *prot, + resource_size_t *phys) +{ + int ret =3D -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 =3D *ptep; + + if ((flags & FOLL_WRITE) && !pte_write(pte)) + goto unlock; + + *prot =3D pgprot_val(pte_pgprot(pte)); + *phys =3D (resource_size_t)pte_pfn(pte) << PAGE_SHIFT; + + ret =3D 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 5f16263d176d..226f2f7cefd7 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2311,8 +2311,6 @@ int follow_pte(struct mm_struct *mm, unsigned long ad= dress, 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); =20 diff --git a/mm/memory.c b/mm/memory.c index 0adf23ea5416..93ad6b45f426 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5454,34 +5454,6 @@ int follow_pfn(struct vm_area_struct *vma, unsigned = long address, EXPORT_SYMBOL(follow_pfn); =20 #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 =3D -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 =3D *ptep; - - if ((flags & FOLL_WRITE) && !pte_write(pte)) - goto unlock; - - *prot =3D pgprot_val(pte_pgprot(pte)); - *phys =3D (resource_size_t)pte_pfn(pte) << PAGE_SHIFT; - - ret =3D 0; -unlock: - pte_unmap_unlock(ptep, ptl); -out: - return ret; -} - /** * generic_access_phys - generic implementation for iomem mmap access * @vma: the vma to access --=20 2.25.1 From nobody Sat Apr 11 13:01:22 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95A35C64EC4 for ; Tue, 7 Mar 2023 02:26:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229988AbjCGC0d (ORCPT ); Mon, 6 Mar 2023 21:26:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229914AbjCGC02 (ORCPT ); Mon, 6 Mar 2023 21:26:28 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59CDF4D606 for ; Mon, 6 Mar 2023 18:26:13 -0800 (PST) Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4PVzl115ntz16PDB; Tue, 7 Mar 2023 10:23:25 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 7 Mar 2023 10:26:10 +0800 From: Wupeng Ma To: , , , CC: , , , Subject: [PATCH v2 -next 2/3] x86/mm/pat: Cleanup unused parameter in follow_phys Date: Tue, 7 Mar 2023 10:26:05 +0800 Message-ID: <20230307022606.2367399-3-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230307022606.2367399-1-mawupeng1@huawei.com> References: <20230307022606.2367399-1-mawupeng1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Ma Wupeng Parameter flags is always zero in caller untrack_pfn() and track_pfn_copy(). let's drop it. Signed-off-by: Ma Wupeng --- arch/x86/mm/pat/memtype.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 4fb1e89f32e4..3ec025011c90 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -951,8 +951,7 @@ static void free_pfn_range(u64 paddr, unsigned long siz= e) } =20 static int follow_phys(struct vm_area_struct *vma, unsigned long address, - unsigned int flags, unsigned long *prot, - resource_size_t *phys) + unsigned long *prot, resource_size_t *phys) { int ret =3D -EINVAL; pte_t *ptep, pte; @@ -965,9 +964,6 @@ static int follow_phys(struct vm_area_struct *vma, unsi= gned long address, goto out; pte =3D *ptep; =20 - if ((flags & FOLL_WRITE) && !pte_write(pte)) - goto unlock; - *prot =3D pgprot_val(pte_pgprot(pte)); *phys =3D (resource_size_t)pte_pfn(pte) << PAGE_SHIFT; =20 @@ -997,7 +993,7 @@ int track_pfn_copy(struct vm_area_struct *vma) * reserve the whole chunk covered by vma. We need the * starting address and protection from pte. */ - if (follow_phys(vma, vma->vm_start, 0, &prot, &paddr)) { + if (follow_phys(vma, vma->vm_start, &prot, &paddr)) { WARN_ON_ONCE(1); return -EINVAL; } @@ -1084,7 +1080,7 @@ void untrack_pfn(struct vm_area_struct *vma, unsigned= long pfn, /* free the chunk starting from pfn or the whole chunk */ paddr =3D (resource_size_t)pfn << PAGE_SHIFT; if (!paddr && !size) { - if (follow_phys(vma, vma->vm_start, 0, &prot, &paddr)) { + if (follow_phys(vma, vma->vm_start, &prot, &paddr)) { WARN_ON_ONCE(1); return; } --=20 2.25.1 From nobody Sat Apr 11 13:01:22 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72CBEC61DA4 for ; Tue, 7 Mar 2023 02:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbjCGC0g (ORCPT ); Mon, 6 Mar 2023 21:26:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229976AbjCGC03 (ORCPT ); Mon, 6 Mar 2023 21:26:29 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B17466A428 for ; Mon, 6 Mar 2023 18:26:13 -0800 (PST) Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PVzl062xwznWTK; Tue, 7 Mar 2023 10:23:24 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 7 Mar 2023 10:26:11 +0800 From: Wupeng Ma To: , , , CC: , , , Subject: [PATCH v2 -next 3/3] x86/mm/pat: Remove WARN_ON_ONCE if follow_phys fails Date: Tue, 7 Mar 2023 10:26:06 +0800 Message-ID: <20230307022606.2367399-4-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230307022606.2367399-1-mawupeng1@huawei.com> References: <20230307022606.2367399-1-mawupeng1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Ma Wupeng WARN_ON_ONCE here is not useful for solving problem since why this PA is not valid is still unknown if follow_phys fails in track_pfn_copy/untrack_pfn, Drop it. Signed-off-by: Ma Wupeng --- arch/x86/mm/pat/memtype.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 3ec025011c90..bda4b6b910c2 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -993,10 +993,9 @@ int track_pfn_copy(struct vm_area_struct *vma) * reserve the whole chunk covered by vma. We need the * starting address and protection from pte. */ - if (follow_phys(vma, vma->vm_start, &prot, &paddr)) { - WARN_ON_ONCE(1); + if (follow_phys(vma, vma->vm_start, &prot, &paddr)) return -EINVAL; - } + pgprot =3D __pgprot(prot); return reserve_pfn_range(paddr, vma_size, &pgprot, 1); } @@ -1080,10 +1079,8 @@ void untrack_pfn(struct vm_area_struct *vma, unsigne= d long pfn, /* free the chunk starting from pfn or the whole chunk */ paddr =3D (resource_size_t)pfn << PAGE_SHIFT; if (!paddr && !size) { - if (follow_phys(vma, vma->vm_start, &prot, &paddr)) { - WARN_ON_ONCE(1); + if (follow_phys(vma, vma->vm_start, &prot, &paddr)) return; - } =20 size =3D vma->vm_end - vma->vm_start; } --=20 2.25.1