Hi, I got solution to my problem from linux-kernel mailing list . I m posting here for future reference.
On Tue, 1 Mar 2005, Prakash Bhurke wrote: > I am trying to map a vmalloc kernel buffer to user > space using remap_page_range(). In my module, this > function returns success if we call mmap() from user > space, but i can not access content of vmalloc buffer > from user space. Pointer returned by mmap() syscall > seems pointing to other memory page which contains > zeros. I am using linux 2.6.10 kernel on Pentium 4 > system. Look for "rvmalloc" in various drivers in the kernel source tree: you must SetPageReserved before remap_pfn_range (or remap_page_range) agrees to map the page, and ClearPageReserved before freeing after. Regards, --- Prakash Bhurke <[EMAIL PROTECTED]> wrote: > Hi , > > I am facing a problem -- memory mapping of proc > entry into user space using mmap syscall. > I have written a module which creates a proc entry > & > provides read, write, mmap, etc. > Normal read, write etc file operation works, but > mmap is not working. > I am trying to map a vmalloc kernel buffer to user > space using remap_page_range(). In my module, this > function returns success if we call mmap() from user > space, but i can not access content of vmalloc > buffer > from user space. Pointer returned by mmap() syscall > seems pointing to other memory page which contains > zeros. I am using linux 2.6.10 kernel on Pentium 4 > system. > > here is code of module_mmap(); > static inline unsigned long kvirt_to_pa(unsigned > long > adr) > { > unsigned long kva, ret; > > kva = (unsigned long) > page_address(vmalloc_to_page((void *)adr)); > kva |= adr & (PAGE_SIZE-1); /* restore the offset > */ > ret = __pa(kva); > return ret; > } > > static int module_mmap(struct file *file, struct > vm_area_struct *vma) > { > unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; > unsigned long len = vma->vm_end - vma->vm_start; > unsigned long pos = (unsigned long) test_tsc + > offset; > > printk(KERN_INFO "PROCINFO : in mmap started, > length > = %ld\n", len); > > if (!tscinfo) > return -ENODEV; > > if ((offset + len) > > PAGE_ALIGN(sizeof(sizeof(struct > test_tsc_info))))) > return -ENXIO; > > if ((vma->vm_flags & (VM_SHARED|VM_WRITE)) == > (VM_SHARED|VM_WRITE)) { > printk("PROCINFO : in mmap attempt to write to > mapping\n"); > return -EPERM; > } > > vma->vm_flags |= VM_SHM | VM_LOCKED ; > > if (remap_pfn_range(vma, vma->vm_start, > kvirt_to_pa(pos) >> PAGE_SHIFT, \ > len, vma->vm_page_prot)) { > printk(KERN_INFO "PROCINFO : in mmap > remap_pfn_range > returns error\n"); > return -EAGAIN; > } > > printk(KERN_INFO "PROCINFO : in mmap ret 0 end\n"); > > return 0; > } > > From user space program i mapping kernel memory like > this > proc_fd = open("/proc/"PROC_ENTRY_FILENAME, > O_RDONLY); > mem_base = mmap(NULL, sizeof(struct test_tsc_info), > PROT_READ, MAP_SHARED, proc_fd, 0); > > Please let me know what wrong thins i m doing. > > Regards, > Prakash. > > > > > __________________________________ > Do you Yahoo!? > Yahoo! Mail - now with 250MB free storage. Learn > more. > http://info.mail.yahoo.com/mail_250 > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- ______________________________________________________________________ Pune GNU/Linux Users Group Mailing List: (plug-mail@plug.org.in) List Information: http://plug.org.in/mailing-list/listinfo/plug-mail Send 'help' to [EMAIL PROTECTED] for mailing instructions.