How to check if given page is a ZERO_PAGE in a kernel module?

526 Views Asked by At

I am writing a kernel module, where, inside a function I need to check if passed
struct page* maps to ZERO_PAGE or not.
I came up with following code to check the condition.

foo (struct page *pp, ..) {
     if(pp == ZERO_PAGE(0)) {
          //say, prefault the page.
     }
}

When I try to compile this , I get following warning message:

WARNING: "phys_base" [<path_to_'.ko'] undefined!

when I try to 'insmod' the '.ko' , It gives error "Unknown symbol".and prints
"Unknown symbol phys_base" in log buffer.
My Makefile:

obj-m :=zero_page.o

KDIR=/lib/modules/`uname -r`/build

all:
        make -C $(KDIR) M=`pwd` modules

The kernel version for which I am writing the module:
2.6.18-398.el5 (rhel 5.11)
I tried to find some other 'interfaces' inside kernel to check if page is ZERO_PAGE, but no luck.
Can some tell me how to get rid of this error.OR any other way to check this condition ?

NOTE: I came across this kernelnewbie thread which addressed the same issue. included <asm/pgtable.h> but no help.

1

There are 1 best solutions below

0
On

I was able to come up with a fix for this.
After browsing some kernel code , I found out , for ZERO_PAGE address_space ptr is NULL.
Hence fix looks something like this :

if(page->mapping == NULL) {
   // Its a ZERO_PAGE.
}

Thank you.