From: "Bryan O'Sullivan" <bos@serpentine.com>

For compound pages, page_count needs to be sure to reference the head page.

This affects code that plays tricks with memory mappings into userspace,
which would mostly involve video drivers.



 include/linux/mm.h |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletion(-)

diff -puN include/linux/mm.h~compound-page-page_count-fix include/linux/mm.h
--- 25/include/linux/mm.h~compound-page-page_count-fix	2004-01-01 23:21:16.000000000 -0800
+++ 25-akpm/include/linux/mm.h	2004-01-01 23:21:16.000000000 -0800
@@ -223,7 +223,6 @@ struct page {
 		atomic_dec_and_test(&(p)->count);	\
 	})
 
-#define page_count(p)		atomic_read(&(p)->count)
 #define set_page_count(p,v) 	atomic_set(&(p)->count, v)
 #define __put_page(p)		atomic_dec(&(p)->count)
 
@@ -231,6 +230,13 @@ extern void FASTCALL(__page_cache_releas
 
 #ifdef CONFIG_HUGETLB_PAGE
 
+static inline int page_count(struct page *p)
+{
+	if (PageCompound(p))
+		p = (struct page *)p->lru.next;
+	return atomic_read(&(p)->count);
+}
+
 static inline void get_page(struct page *page)
 {
 	if (PageCompound(page))
@@ -257,6 +263,8 @@ static inline void put_page(struct page 
 
 #else		/* CONFIG_HUGETLB_PAGE */
 
+#define page_count(p)		atomic_read(&(p)->count)
+
 static inline void get_page(struct page *page)
 {
 	atomic_inc(&page->count);

_