[PATCH 39/42] x86, 64bit: add pfn_range_is_highmapped()
From: Yinghai Lu
Date: Tue Jul 07 2015 - 16:24:39 EST
Need to use it to support holes in highmap when remove not
used range in highmap.
Signed-off-by: Yinghai Lu <yinghai@xxxxxxxxxx>
---
arch/x86/include/asm/pgtable_64.h | 2 ++
arch/x86/mm/init_64.c | 22 ++++++++++++++++++++++
arch/x86/mm/pageattr.c | 16 +---------------
3 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
index 2ee7811..6b2aae2 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -158,6 +158,8 @@ static inline int pgd_large(pgd_t pgd) { return 0; }
extern int kern_addr_valid(unsigned long addr);
extern void cleanup_highmap(void);
+int pfn_range_is_highmapped(unsigned long start_pfn, unsigned long end_pfn);
+
#define HAVE_ARCH_UNMAPPED_AREA
#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 3b7453a..2507b98 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -290,6 +290,23 @@ void __init init_extra_mapping_uc(unsigned long phys, unsigned long size)
__init_extra_mapping(phys, size, _PAGE_CACHE_MODE_UC);
}
+/* three holes at most*/
+#define NR_RANGE 4
+static struct range pfn_highmapped[NR_RANGE];
+static int nr_pfn_highmapped;
+
+int pfn_range_is_highmapped(unsigned long start_pfn, unsigned long end_pfn)
+{
+ int i;
+
+ for (i = 0; i < nr_pfn_highmapped; i++)
+ if ((start_pfn >= pfn_highmapped[i].start) &&
+ (end_pfn <= pfn_highmapped[i].end))
+ return 1;
+
+ return 0;
+}
+
/*
* The head.S code sets up the kernel high mapping:
*
@@ -324,6 +341,11 @@ void __init cleanup_highmap(void)
if (vaddr < (unsigned long) _text || vaddr > end)
set_pmd(pmd, __pmd(0));
}
+
+ nr_pfn_highmapped = add_range(pfn_highmapped, NR_RANGE,
+ nr_pfn_highmapped,
+ __pa_symbol(_text) >> PAGE_SHIFT,
+ __pa_symbol(roundup(_brk_end, PMD_SIZE)) >> PAGE_SHIFT);
}
static unsigned long __meminit
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 727158c..06a0116 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -90,20 +90,6 @@ void arch_report_meminfo(struct seq_file *m)
static inline void split_page_count(int level) { }
#endif
-#ifdef CONFIG_X86_64
-
-static inline unsigned long highmap_start_pfn(void)
-{
- return __pa_symbol(_text) >> PAGE_SHIFT;
-}
-
-static inline unsigned long highmap_end_pfn(void)
-{
- return __pa_symbol(roundup(_brk_end, PMD_SIZE)) >> PAGE_SHIFT;
-}
-
-#endif
-
#ifdef CONFIG_DEBUG_PAGEALLOC
# define debug_pagealloc 1
#else
@@ -1271,7 +1257,7 @@ static int cpa_process_alias(struct cpa_data *cpa)
* to touch the high mapped kernel as well:
*/
if (!within(vaddr, (unsigned long)_text, _brk_end) &&
- within(cpa->pfn, highmap_start_pfn(), highmap_end_pfn())) {
+ pfn_range_is_highmapped(cpa->pfn, 1)) {
unsigned long temp_cpa_vaddr = (cpa->pfn << PAGE_SHIFT) +
__START_KERNEL_map - phys_base;
alias_cpa = *cpa;
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/