From: Dave Hansen <haveblue@us.ibm.com>

People love to do comparisons with highmem_start_page.  However, where
CONFIG_HIGHMEM=y and there is no actual highmem, there's no real page at
*highmem_start_page.

That's usually not a problem, but CONFIG_NONLINEAR is a bit more strict and
catches the bogus address tranlations.  

There are about a gillion different ways to find out of a 'struct page' is
highmem or not.  Why not just check page_flags?  Just use PageHighMem()
wherever there used to be a highmem_start_page comparison.  Then, kill off
highmem_start_page.

This removes more code than it adds, and gets rid of some nasty 
#ifdefs in .c files.

Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/arch/i386/mm/discontig.c    |    5 -----
 25-akpm/arch/i386/mm/highmem.c      |    6 +++---
 25-akpm/arch/i386/mm/init.c         |    1 -
 25-akpm/arch/i386/mm/pageattr.c     |    5 +----
 25-akpm/arch/mips/mm/highmem.c      |    6 +++---
 25-akpm/arch/mips/mm/init.c         |    1 -
 25-akpm/arch/ppc/mm/init.c          |    1 -
 25-akpm/arch/sparc/mm/highmem.c     |    2 +-
 25-akpm/arch/sparc/mm/init.c        |    2 --
 25-akpm/arch/um/kernel/mem.c        |    2 --
 25-akpm/include/asm-ppc/highmem.h   |    6 +++---
 25-akpm/include/asm-sparc/highmem.h |    4 ++--
 25-akpm/include/linux/highmem.h     |    2 --
 25-akpm/mm/memory.c                 |    2 --
 25-akpm/net/core/dev.c              |    2 +-
 15 files changed, 14 insertions(+), 33 deletions(-)

diff -puN arch/i386/mm/discontig.c~kill-off-highmem_start_page arch/i386/mm/discontig.c
--- 25/arch/i386/mm/discontig.c~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/arch/i386/mm/discontig.c	Wed Nov 17 14:17:42 2004
@@ -464,11 +464,6 @@ void __init set_highmem_pages_init(int b
 void __init set_max_mapnr_init(void)
 {
 #ifdef CONFIG_HIGHMEM
-	struct zone *high0 = &NODE_DATA(0)->node_zones[ZONE_HIGHMEM];
-	if (high0->spanned_pages > 0)
-	      	highmem_start_page = high0->zone_mem_map;
-	else
-		highmem_start_page = pfn_to_page(max_low_pfn - 1) + 1;
 	num_physpages = highend_pfn;
 #else
 	num_physpages = max_low_pfn;
diff -puN arch/i386/mm/highmem.c~kill-off-highmem_start_page arch/i386/mm/highmem.c
--- 25/arch/i386/mm/highmem.c~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/arch/i386/mm/highmem.c	Wed Nov 17 14:17:42 2004
@@ -3,7 +3,7 @@
 void *kmap(struct page *page)
 {
 	might_sleep();
-	if (page < highmem_start_page)
+	if (!PageHighMem(page))
 		return page_address(page);
 	return kmap_high(page);
 }
@@ -12,7 +12,7 @@ void kunmap(struct page *page)
 {
 	if (in_interrupt())
 		BUG();
-	if (page < highmem_start_page)
+	if (!PageHighMem(page))
 		return;
 	kunmap_high(page);
 }
@@ -32,7 +32,7 @@ void *kmap_atomic(struct page *page, enu
 
 	/* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
 	inc_preempt_count();
-	if (page < highmem_start_page)
+	if (!PageHighMem(page))
 		return page_address(page);
 
 	idx = type + KM_TYPE_NR*smp_processor_id();
diff -puN arch/i386/mm/init.c~kill-off-highmem_start_page arch/i386/mm/init.c
--- 25/arch/i386/mm/init.c~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/arch/i386/mm/init.c	Wed Nov 17 14:17:42 2004
@@ -549,7 +549,6 @@ void __init test_wp_bit(void)
 static void __init set_max_mapnr_init(void)
 {
 #ifdef CONFIG_HIGHMEM
-	highmem_start_page = pfn_to_page(highstart_pfn);
 	max_mapnr = num_physpages = highend_pfn;
 #else
 	max_mapnr = num_physpages = max_low_pfn;
diff -puN arch/i386/mm/pageattr.c~kill-off-highmem_start_page arch/i386/mm/pageattr.c
--- 25/arch/i386/mm/pageattr.c~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/arch/i386/mm/pageattr.c	Wed Nov 17 14:17:42 2004
@@ -105,10 +105,7 @@ __change_page_attr(struct page *page, pg
 	unsigned long address;
 	struct page *kpte_page;
 
-#ifdef CONFIG_HIGHMEM
-	if (page >= highmem_start_page) 
-		BUG(); 
-#endif
+	BUG_ON(PageHighMem(page));
 	address = (unsigned long)page_address(page);
 
 	kpte = lookup_address(address);
diff -puN arch/mips/mm/highmem.c~kill-off-highmem_start_page arch/mips/mm/highmem.c
--- 25/arch/mips/mm/highmem.c~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/arch/mips/mm/highmem.c	Wed Nov 17 14:17:42 2004
@@ -8,7 +8,7 @@ void *__kmap(struct page *page)
 	void *addr;
 
 	might_sleep();
-	if (page < highmem_start_page)
+	if (!PageHighMem(page))
 		return page_address(page);
 	addr = kmap_high(page);
 	flush_tlb_one((unsigned long)addr);
@@ -20,7 +20,7 @@ void __kunmap(struct page *page)
 {
 	if (in_interrupt())
 		BUG();
-	if (page < highmem_start_page)
+	if (!PageHighMem(page))
 		return;
 	kunmap_high(page);
 }
@@ -41,7 +41,7 @@ void *__kmap_atomic(struct page *page, e
 
 	/* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
 	inc_preempt_count();
-	if (page < highmem_start_page)
+	if (!PageHighMem(page))
 		return page_address(page);
 
 	idx = type + KM_TYPE_NR*smp_processor_id();
diff -puN arch/mips/mm/init.c~kill-off-highmem_start_page arch/mips/mm/init.c
--- 25/arch/mips/mm/init.c~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/arch/mips/mm/init.c	Wed Nov 17 14:17:42 2004
@@ -204,7 +204,6 @@ void __init mem_init(void)
 	unsigned long tmp, ram;
 
 #ifdef CONFIG_HIGHMEM
-	highmem_start_page = mem_map + highstart_pfn;
 #ifdef CONFIG_DISCONTIGMEM
 #error "CONFIG_HIGHMEM and CONFIG_DISCONTIGMEM dont work together yet"
 #endif
diff -puN arch/ppc/mm/init.c~kill-off-highmem_start_page arch/ppc/mm/init.c
--- 25/arch/ppc/mm/init.c~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/arch/ppc/mm/init.c	Wed Nov 17 14:17:42 2004
@@ -419,7 +419,6 @@ void __init mem_init(void)
 	unsigned long highmem_mapnr;
 
 	highmem_mapnr = total_lowmem >> PAGE_SHIFT;
-	highmem_start_page = mem_map + highmem_mapnr;
 #endif /* CONFIG_HIGHMEM */
 	max_mapnr = total_memory >> PAGE_SHIFT;
 
diff -puN arch/sparc/mm/highmem.c~kill-off-highmem_start_page arch/sparc/mm/highmem.c
--- 25/arch/sparc/mm/highmem.c~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/arch/sparc/mm/highmem.c	Wed Nov 17 14:17:42 2004
@@ -36,7 +36,7 @@ void *kmap_atomic(struct page *page, enu
 
 	/* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
 	inc_preempt_count();
-	if (page < highmem_start_page)
+	if (!PageHighMem(page))
 		return page_address(page);
 
 	idx = type + KM_TYPE_NR*smp_processor_id();
diff -puN arch/sparc/mm/init.c~kill-off-highmem_start_page arch/sparc/mm/init.c
--- 25/arch/sparc/mm/init.c~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/arch/sparc/mm/init.c	Wed Nov 17 14:17:42 2004
@@ -402,8 +402,6 @@ void __init mem_init(void)
 	int reservedpages = 0;
 	int i;
 
-	highmem_start_page = pfn_to_page(highstart_pfn);
-
 	if (PKMAP_BASE+LAST_PKMAP*PAGE_SIZE >= FIXADDR_START) {
 		prom_printf("BUG: fixmap and pkmap areas overlap\n");
 		prom_printf("pkbase: 0x%lx pkend: 0x%lx fixstart 0x%lx\n",
diff -puN arch/um/kernel/mem.c~kill-off-highmem_start_page arch/um/kernel/mem.c
--- 25/arch/um/kernel/mem.c~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/arch/um/kernel/mem.c	Wed Nov 17 14:17:42 2004
@@ -49,8 +49,6 @@ static void setup_highmem(unsigned long 
 	unsigned long highmem_pfn;
 	int i;
 
-	highmem_start_page = virt_to_page(highmem_start);
-
 	highmem_pfn = __pa(highmem_start) >> PAGE_SHIFT;
 	for(i = 0; i < highmem_len >> PAGE_SHIFT; i++){
 		page = &mem_map[highmem_pfn + i];
diff -puN include/asm-ppc/highmem.h~kill-off-highmem_start_page include/asm-ppc/highmem.h
--- 25/include/asm-ppc/highmem.h~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/include/asm-ppc/highmem.h	Wed Nov 17 14:17:42 2004
@@ -56,7 +56,7 @@ extern void kunmap_high(struct page *pag
 static inline void *kmap(struct page *page)
 {
 	might_sleep();
-	if (page < highmem_start_page)
+	if (!PageHighMem(page))
 		return page_address(page);
 	return kmap_high(page);
 }
@@ -64,7 +64,7 @@ static inline void *kmap(struct page *pa
 static inline void kunmap(struct page *page)
 {
 	BUG_ON(in_interrupt());
-	if (page < highmem_start_page)
+	if (!PageHighMem(page))
 		return;
 	kunmap_high(page);
 }
@@ -82,7 +82,7 @@ static inline void *kmap_atomic(struct p
 
 	/* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
 	inc_preempt_count();
-	if (page < highmem_start_page)
+	if (!PageHighMem(page))
 		return page_address(page);
 
 	idx = type + KM_TYPE_NR*smp_processor_id();
diff -puN include/asm-sparc/highmem.h~kill-off-highmem_start_page include/asm-sparc/highmem.h
--- 25/include/asm-sparc/highmem.h~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/include/asm-sparc/highmem.h	Wed Nov 17 14:17:42 2004
@@ -57,7 +57,7 @@ extern void kunmap_high(struct page *pag
 static inline void *kmap(struct page *page)
 {
 	BUG_ON(in_interrupt());
-	if (page < highmem_start_page)
+	if (!PageHighMem(page))
 		return page_address(page);
 	return kmap_high(page);
 }
@@ -65,7 +65,7 @@ static inline void *kmap(struct page *pa
 static inline void kunmap(struct page *page)
 {
 	BUG_ON(in_interrupt());
-	if (page < highmem_start_page)
+	if (!PageHighMem(page))
 		return;
 	kunmap_high(page);
 }
diff -puN include/linux/highmem.h~kill-off-highmem_start_page include/linux/highmem.h
--- 25/include/linux/highmem.h~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/include/linux/highmem.h	Wed Nov 17 14:17:42 2004
@@ -9,8 +9,6 @@
 
 #ifdef CONFIG_HIGHMEM
 
-extern struct page *highmem_start_page;
-
 #include <asm/highmem.h>
 
 /* declarations for linux/mm/highmem.c */
diff -puN mm/memory.c~kill-off-highmem_start_page mm/memory.c
--- 25/mm/memory.c~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/mm/memory.c	Wed Nov 17 14:17:42 2004
@@ -76,11 +76,9 @@ unsigned long num_physpages;
  * and ZONE_HIGHMEM.
  */
 void * high_memory;
-struct page *highmem_start_page;
 unsigned long vmalloc_earlyreserve;
 
 EXPORT_SYMBOL(num_physpages);
-EXPORT_SYMBOL(highmem_start_page);
 EXPORT_SYMBOL(high_memory);
 EXPORT_SYMBOL(vmalloc_earlyreserve);
 
diff -puN net/core/dev.c~kill-off-highmem_start_page net/core/dev.c
--- 25/net/core/dev.c~kill-off-highmem_start_page	Wed Nov 17 14:17:42 2004
+++ 25-akpm/net/core/dev.c	Wed Nov 17 14:17:42 2004
@@ -1119,7 +1119,7 @@ static inline int illegal_highdma(struct
 		return 0;
 
 	for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
-		if (skb_shinfo(skb)->frags[i].page >= highmem_start_page)
+		if (PageHighMem(skb_shinfo(skb)->frags[i].page))
 			return 1;
 
 	return 0;
_