LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 02-26-2013, 09:33 AM   #1
Shadew
LQ Newbie
 
Registered: Feb 2010
Posts: 5

Rep: Reputation: 0
How to remap (mmap) an address allocated with alloc_vm_area ?


Hello,

I'm trying to access to the kernel memory space from a user application. To achieve this, I'm using the customization of the mmap function.

I'm working with Xen and the pages I want to share are from dom0. I first allocated a memory space with alloc_vm_area :
Code:
v_start = alloc_vm_area(PAGE_SIZE*NUM_ALLOC*PAGES_PER_ALLOC,NULL);

if(v_start==0){
    printk(KERN_INFO "Problem allocating page\n");
    return -EFAULT;
}
and then I put pages from dom0 in this space :
Code:
if(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, ops, NUM_ALLOC*PAGES_PER_ALLOC)){
    printk(KERN_INFO "Hypervisor map grant failed\n");
    free_vm_area(v_start);
    return -EFAULT;
}
Finally, I implement the mmap file operation :
Code:
static int mmap_mmap(struct file * filp, struct vm_area_struct * vma){
        int ret;
        const size_t length = vma->vm_end - vma->vm_start;

        printk(KERN_INFO "Length : %lu, pages : %lu \n", length, length/PAGE_SIZE);

        if(length > NUM_ALLOC * PAGES_PER_ALLOC * PAGE_SIZE){
                printk("Request for a chunk of memory bigger than the available memory\n");
                return -EIO;
        }

        if((ret = remap_vmalloc_range(vma, v_start->addr, 0))<0){
                printk(KERN_INFO "Error in remap_vmalloc_range");
                return ret;
        }

        printk(KERN_INFO "MMaped\n");

        return 0;
}
I used a nod file to link applications with my module. I made a call to mmap in an application :
Code:
vadr = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
but the remap_vmalloc_range function failed and it returns the error :
mmap: Invalid argument
Does someone know how to remap such a memory space please ?

Thank you.

Last edited by Shadew; 02-26-2013 at 09:34 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Physical address being returned as 0 in mmap liny1984 Linux - Kernel 2 07-01-2011 08:21 PM
mmap a physical address fardad Programming 3 10-30-2008 11:30 AM
how to lookup the IP address blocks allocated to a domain DeuceNegative Linux - Networking 5 07-26-2008 11:44 AM
mmap refused with 0x80000000 virtual address fannyl Programming 2 08-03-2004 01:43 AM
how to get my ip address allocated by dhcp on dsl paledread Linux - Networking 2 03-09-2004 06:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration