Commit 3af6d494 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] fix page counting for compound pages

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.
parent b58f2e6f
...@@ -223,7 +223,6 @@ struct page { ...@@ -223,7 +223,6 @@ struct page {
atomic_dec_and_test(&(p)->count); \ 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 set_page_count(p,v) atomic_set(&(p)->count, v)
#define __put_page(p) atomic_dec(&(p)->count) #define __put_page(p) atomic_dec(&(p)->count)
...@@ -231,6 +230,13 @@ extern void FASTCALL(__page_cache_release(struct page *)); ...@@ -231,6 +230,13 @@ extern void FASTCALL(__page_cache_release(struct page *));
#ifdef CONFIG_HUGETLB_PAGE #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) static inline void get_page(struct page *page)
{ {
if (PageCompound(page)) if (PageCompound(page))
...@@ -257,6 +263,8 @@ static inline void put_page(struct page *page) ...@@ -257,6 +263,8 @@ static inline void put_page(struct page *page)
#else /* CONFIG_HUGETLB_PAGE */ #else /* CONFIG_HUGETLB_PAGE */
#define page_count(p) atomic_read(&(p)->count)
static inline void get_page(struct page *page) static inline void get_page(struct page *page)
{ {
atomic_inc(&page->count); atomic_inc(&page->count);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment