I have a chunk of memory allocated from user space (say 4.M..I give this address to a driver module through an IOCTL.I want to map the physical memory to the Virtual address space of another process.I know that I can use a shared memroy for this but my project requires that mapping be done from the kernel space.

In the kernel space I do the following.

1.I use get_user_pages() to get the list of pages which corrosponds to the physical memory.(the allocated space is mlocked())
-this function returns the correct number of pages so i assume it is correct.

2.I want to map the page list thus obtained to the Virtual Address Space of Process 2.

I tried the following two approaches

Approach 1:
for (loop = 0 ;loop < number_pages ; loop++)
err = vm_insert_page(vma,(vma->vm_start + (loop & PAGE_MASK)<< PAGE_SHIFT)),page_list[loop]);
DD(("error value %d\n",err));

mmap function from user process 2 is failing.

Approach 2:
for(loop = 0 ;loop < number_pages ; loop++)
unsigned long pfn = page_to_pfn(page_list[loop]);
DD(("loop %d pfn %x\n",loop,pfn));
if ((err = remap_pfn_range(vma, start, pfn, PAGE_SIZE,
PAGE_SHARED)) < 0) {
DA( (KERN_WARNING "dag%u: Failed remap!\n", sc->unit) );
return -EAGAIN;

start += PAGE_SIZE;
length -= PAGE_SIZE;

I am not able to get the semaphore i assume.If i try without the lock there is a kernel panic.

I am a linux kernel newbie.I would really appreciate any help t this problem.