mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* memory mapping of vmalloc
@ 2005-03-01 13:08 Prakash Bhurke
  2005-03-01 17:17 ` Hugh Dickins
  0 siblings, 1 reply; 3+ messages in thread
From: Prakash Bhurke @ 2005-03-01 13:08 UTC (permalink / raw)
  To: linux-kernel

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;
}

>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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-03-02 14:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-01 13:08 memory mapping of vmalloc Prakash Bhurke
2005-03-01 17:17 ` Hugh Dickins
2005-03-02 14:28   ` Prakash Bhurke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®