From: Jeff Kuskin <jsk@atheros.com>
To: linux-kernel@vger.kernel.org
Subject: Finding a physical address from userspace?
Date: Sun, 27 Oct 2002 14:29:00 -0800 [thread overview]
Message-ID: <15804.26796.800934.718945@byte.users.atheros.com> (raw)
Assume I run this code from userspace as root (I'll omit all error checking
and assume the page size is known to be 4KB to keep the code short):
#define PAGECNT 10
#define PAGESIZE 4096
int
main(int argc, char *argv[])
{
char * cp;
char * physaddr[PAGECNT];
cp = malloc(PAGECNT*PAGESIZE);
mlock(cp, PAGECNT*PAGESIZE);
for (i = 0; i < PAGECNT; i++) {
physaddr[i] = USERSPACE_VIRT_TO_PHYS(cp + i * PAGESIZE);
}
}
Two questions:
(1) The mlock() manpage says only that it will lock the pages into memory.
It's not clear if the pages also are guaranteed not to change physical
addresses while the mlock() is in effect. I realize that, in theory,
the pages could move in physical memory, but in the real world of
kernel 2.4.x, could the physical addresses of mlock()'ed pages ever
change?
(2) Is there any way to write the 'USERSPACE_VIRT_TO_PHYS' function? I
realize I could write a simple character device driver to accomplish
the task, but I was hoping there would be a purely userspace solution
that would not require writing (and installing) a kernel module.
Suggestions? It seems like this would a FAQ, but I couldn't find a
mention of it in the LKML archives.
(How about something "insane" like mmap()'ing /dev/mem starting at
offset zero, filling the block pointed to by 'cp' with a known pattern,
and then running through the mmap()'ed /dev/mem looking for the known
pattern? Is this crazy/stupid enough to work?)
Thanks.
reply other threads:[~2002-10-27 22:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=15804.26796.800934.718945@byte.users.atheros.com \
--to=jsk@atheros.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
Powered by JetHome