mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Finding a physical address from userspace?
@ 2002-10-27 22:29 Jeff Kuskin
  0 siblings, 0 replies; only message in thread
From: Jeff Kuskin @ 2002-10-27 22:29 UTC (permalink / raw)
  To: linux-kernel

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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-10-27 22:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-27 22:29 Finding a physical address from userspace? Jeff Kuskin

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