CPA open codes the direct map range check in five places, and the generic
CPA core will need the same check.

Move the check to cpa_is_direct_map().

No functional change.

Signed-off-by: Mike Rapoport (Microsoft) <[email protected]>
---
 arch/x86/mm/pat/set_memory.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index f4d3e2d9c3c9..cbbc51be4de7 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -245,6 +245,12 @@ within(unsigned long addr, unsigned long start, unsigned 
long end)
        return addr >= start && addr < end;
 }
 
+static inline bool cpa_is_direct_map(unsigned long addr)
+{
+       return within(addr, PAGE_OFFSET,
+                     PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT));
+}
+
 #ifdef CONFIG_X86_64
 
 static inline int
@@ -1224,8 +1230,7 @@ __split_large_page(struct cpa_data *cpa, struct cpa_leaf 
*leaf, pte_t *pbase)
        for (i = 0; i < PTRS_PER_PTE; i++, pfn += pfninc)
                set_pte(pbase + i, cpa_pte(level - 1, pfn, prot));
 
-       if (within(address, PAGE_OFFSET,
-                  PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT)))
+       if (cpa_is_direct_map(address))
                split_page_count(level);
 
        /*
@@ -1375,8 +1380,7 @@ static int collapse_pmd_page(pmd_t *pmd, unsigned long 
addr,
                }
        }
 
-       if (within(addr, PAGE_OFFSET,
-                  PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT)))
+       if (cpa_is_direct_map(addr))
                collapse_page_count(PGTABLE_LEVEL_PMD);
 
        return 1;
@@ -1423,8 +1427,7 @@ static int collapse_pud_page(pud_t *pud, unsigned long 
addr,
        list_add(&page_ptdesc(pud_page(*pud))->pt_list, pgtables);
        set_pud(pud, pfn_pud(pfn, pmd_pgprot(first)));
 
-       if (within(addr, PAGE_OFFSET,
-                  PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT)))
+       if (cpa_is_direct_map(addr))
                collapse_page_count(PGTABLE_LEVEL_PUD);
 
        return 1;
@@ -1887,8 +1890,7 @@ static int __cpa_process_fault(struct cpa_data *cpa, 
unsigned long vaddr)
         * one virtual address page and its pfn. TBD: numpages can be set based
         * on the initial value and the level returned by lookup_address().
         */
-       if (within(vaddr, PAGE_OFFSET,
-                  PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT))) {
+       if (cpa_is_direct_map(vaddr)) {
                cpa->numpages = 1;
                cpa->pfn = __pa(vaddr) >> PAGE_SHIFT;
                return 0;
@@ -1977,8 +1979,7 @@ static int cpa_process_alias(struct cpa_data *cpa)
         * mapping already:
         */
        vaddr = __cpa_addr(cpa, cpa->curpage);
-       if (!(within(vaddr, PAGE_OFFSET,
-                   PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT)))) {
+       if (!cpa_is_direct_map(vaddr)) {
 
                alias_cpa = *cpa;
                alias_cpa.addr = (unsigned long)__va(cpa->pfn << PAGE_SHIFT);

-- 
2.53.0


Reply via email to