Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Mmap kernel <-> userspace

    Hello, all. I have kernel module that using mmap to communicte with usepscae program. Full code of this module Compiliting ok, but when i try to read data drom userspace program(full code of userspace program i get error "invalid address"
    struct page *mmap_nopage(struct vm_area_struct *vma, unsigned long address, int *type)
        struct page *page;
        struct mmap_info *info;
        /* is the address valid? */
        if (address > vma->vm_end) {
            printk("invalid address\n");
            return NULL;
    Please, help me to fix this mistake. Thank you
    Last edited by dasalam; 08-06-2011 at 03:01 PM.

  2. #2
    struct vm_operations_struct mmap_vm_ops = {
    .open = mmap_open,
    .close = mmap_close,
    .fault = mmap_nopage,

    Check the prototype of the fault. it is int (*fault)(struct vm_area_struct *vma, struct vm_fault *vmf);, I think you are referring to nopage method. But nopage method is not there in latest kernels.
    Last edited by oz; 08-09-2011 at 03:38 PM. Reason: removed spam redirect

  3. #3
    Thank you for answer. I tryed to use remap_pfn_range method. My code i borrowed it from LDD 3 ( . But i can't get data from kernel with userspace program.
    PS. It's normal that vma->vm_pgoff << PAGE_SHIFT in mmap_open = 0 ?

    PPS. I wrote working module using chrdev. Module code User space code (/dev/simple char device created with "mknod /dev/simple c 241 0"). I understand how to read and write info from userspace, but i dont khow how do it from kernel space. Can anybody explain me?
    Last edited by dasalam; 08-09-2011 at 04:02 PM.

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts