Skip to contentSkip to conversation

memory mapping of vmalloc

DISCUSSION Prakash Bhurke 2 participants 3 messages Mar 1, 2005 – Mar 2, 2005

lore
Share & tools
lore
#0 lore raw

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;
}
Quoted 1 line

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 thing i m doing.

Regards,
Prakash.

__________________________________
Do you Yahoo!?
Yahoo! Sports - Sign up for Fantasy Baseball.
http://baseball.fantasysports.yahoo.com/

#1 lore raw
Quoted 8 lines · Prakash Bhurke

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.

Hugh

#2 lore raw

Hi Hugh,

rvmallaoc is working.
Very Very Thanks.

Regards,
Prakash

Quoted 21 lines · --- Hugh Dickins
Quoted 1 line · Prakash Bhurke

I am trying to map a vmalloc kernel buffer to

user

Quoted 2 lines

space using remap_page_range(). In my module, this function returns success if we call mmap() from

user

Quoted 1 line

space, but i can not access content of vmalloc

buffer

Quoted 1 line

from user space. Pointer returned by mmap()

syscall

Quoted 3 lines

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.

Quoted 9 lines

Hugh
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected] More majordomo info at
http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

__________________________________
Celebrate Yahoo!'s 10th Birthday!
Yahoo! Netrospective: 100 Moments of the Web
http://birthday.yahoo.com/netrospective/