[v3,1/3] x86/mm/pat: Move follow_phys to pat-related file
Commit Message
From: Ma Wupeng <mawupeng1@huawei.com>
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 <mawupeng1@huawei.com>
---
arch/x86/mm/pat/memtype.c | 28 ++++++++++++++++++++++++++++
include/linux/mm.h | 2 --
mm/memory.c | 28 ----------------------------
3 files changed, 28 insertions(+), 30 deletions(-)
Comments
Hi Wupeng,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on tip/x86/mm tip/master linus/master v6.7 next-20240112]
[cannot apply to tip/auto-latest]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Wupeng-Ma/x86-mm-pat-Move-follow_phys-to-pat-related-file/20240111-201305
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20240111120929.2694440-2-mawupeng1%40huawei.com
patch subject: [PATCH v3 1/3] x86/mm/pat: Move follow_phys to pat-related file
config: i386-randconfig-012-20240112 (https://download.01.org/0day-ci/archive/20240112/202401122234.MfmlPf9b-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240112/202401122234.MfmlPf9b-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401122234.MfmlPf9b-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from include/linux/mm.h:29,
from include/linux/memblock.h:12,
from arch/x86/mm/pat/memtype.c:35:
arch/x86/mm/pat/memtype.c: In function 'follow_phys':
>> include/linux/pgtable.h:103:9: error: implicit declaration of function 'kunmap_local' [-Werror=implicit-function-declaration]
103 | kunmap_local((pte)); \
| ^~~~~~~~~~~~
include/linux/mm.h:2965:9: note: in expansion of macro 'pte_unmap'
2965 | pte_unmap(pte); \
| ^~~~~~~~~
arch/x86/mm/pat/memtype.c:976:9: note: in expansion of macro 'pte_unmap_unlock'
976 | pte_unmap_unlock(ptep, ptl);
| ^~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/kunmap_local +103 include/linux/pgtable.h
974b9b2c68f3d3 Mike Rapoport 2020-06-08 98
0d940a9b270b92 Hugh Dickins 2023-06-08 99 #ifdef CONFIG_HIGHPTE
0d940a9b270b92 Hugh Dickins 2023-06-08 100 #define __pte_map(pmd, address) \
0d940a9b270b92 Hugh Dickins 2023-06-08 101 ((pte_t *)kmap_local_page(pmd_page(*(pmd))) + pte_index((address)))
0d940a9b270b92 Hugh Dickins 2023-06-08 102 #define pte_unmap(pte) do { \
0d940a9b270b92 Hugh Dickins 2023-06-08 @103 kunmap_local((pte)); \
a349d72fd9efc8 Hugh Dickins 2023-07-11 104 rcu_read_unlock(); \
0d940a9b270b92 Hugh Dickins 2023-06-08 105 } while (0)
974b9b2c68f3d3 Mike Rapoport 2020-06-08 106 #else
0d940a9b270b92 Hugh Dickins 2023-06-08 107 static inline pte_t *__pte_map(pmd_t *pmd, unsigned long address)
0d940a9b270b92 Hugh Dickins 2023-06-08 108 {
0d940a9b270b92 Hugh Dickins 2023-06-08 109 return pte_offset_kernel(pmd, address);
0d940a9b270b92 Hugh Dickins 2023-06-08 110 }
0d940a9b270b92 Hugh Dickins 2023-06-08 111 static inline void pte_unmap(pte_t *pte)
0d940a9b270b92 Hugh Dickins 2023-06-08 112 {
a349d72fd9efc8 Hugh Dickins 2023-07-11 113 rcu_read_unlock();
0d940a9b270b92 Hugh Dickins 2023-06-08 114 }
974b9b2c68f3d3 Mike Rapoport 2020-06-08 115 #endif
974b9b2c68f3d3 Mike Rapoport 2020-06-08 116
@@ -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().
@@ -2364,8 +2364,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);
@@ -5697,34 +5697,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