title: How to find the virtual address of a page (including vmalloc situation) in linux kernel?
body: <p>There is <code>page_address()</code> in linux kernel to get the virtual address of a <code>page</code>.
  However I find that it is not work when a page is allocted by <code>vmalloc()</code> in following demo.</p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;linux/init.h&gt;
  #include &lt;linux/module.h&gt;
  #include &lt;linux/kernel.h&gt;
  #include &lt;linux/vmalloc.h&gt;
  #include &lt;linux/mm.h&gt;
  #include &lt;linux/slab.h&gt;
  
  MODULE_LICENSE(&quot;GPL&quot;);\
  char *p1,*p2;
  
  static void check_vmalloc(const void *addr)
  {
      if(is_vmalloc_addr(addr))
      {
          struct page *p=vmalloc_to_page(addr);
          printk(&quot;%lx from vmalloc. PFN %lu. VirtualAddr %lx&quot;,(unsigned long)addr,page_to_pfn(p),page_address(p));
          if(is_vmalloc_addr(page_address(p)))
          {
              printk(&quot;VirtualAddr %lx is vmalloc&quot;,page_address(p));
          }
          else
          {
              printk(&quot;VirtualAddr %lx is not vmalloc&quot;,page_address(p));
          }
      }
      else
      {
          printk(&quot;%lx not from vmalloc\n&quot;,(unsigned long)addr);
      }
  }
  
  static int __init lkm_example_init(void) {
      printk(&quot;pid %d\n&quot;,current-&gt;pid);
  
      p1=vmalloc(10);
      *p1=123;
      check_vmalloc(p1);
  
      p2=kmalloc(10,GFP_KERNEL);
      *p2=123;
      check_vmalloc(p2);
      
      return 0;
  }
  
  static void __exit lkm_example_exit(void) {
   printk(&quot;Goodbye\n&quot;);
   vfree(p1);
   kfree(p2);
  }
  
  module_init(lkm_example_init);
  module_exit(lkm_example_exit);
  </code></pre>
  <p><a href="https://i.stack.imgur.com/CIfbx.png" rel="nofollow noreferrer">output</a></p>
  <p>So, if I want to find the virtual address of a page which is allocated by <code>vmalloc()</code>, what should I do?
  And could you tell me how to judge whether a page is allocated by <code>vmalloc()</code>?</p>