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.