From: Prakash Bhurke <prakash_bhurke@yahoo.com>
To: linux-kernel@vger.kernel.org
Subject: memory mapping of vmalloc
Date: Tue, 1 Mar 2005 05:08:03 -0800 (PST) [thread overview]
Message-ID: <20050301130803.34688.qmail@web54610.mail.yahoo.com> (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;
}
>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/
next reply other threads:[~2005-03-01 13:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-01 13:08 Prakash Bhurke [this message]
2005-03-01 17:17 ` Hugh Dickins
2005-03-02 14:28 ` Prakash Bhurke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050301130803.34688.qmail@web54610.mail.yahoo.com \
--to=prakash_bhurke@yahoo.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®