RE: VM: Bizzare MM tricks...

From: Raj, Ashok (ashok.raj@intel.com)
Date: Wed Apr 26 2000 - 20:16:13 EST


There is one additional gotcha to perform mmap on kernel memory. One needs
to do what is shown below. atleast with 2.2.x (upto redhat 6.1 and 6.2) if
this is not correct please let me know. Additionally since mmap needs
contiguous memory, this memory cannot be vmalloced space, so it has to be
physically contiguous.. i.e allocated thro __get_free_pages() etc.

one would need to do
----------------------- caddr is the kernel allocated memory.
                    for (i = MAP_NR(caddr); i <= MAP_NR(caddr + size-1);
                                                                    i++) {
                        set_bit(PG_reserved, &mem_map[i].flags);
                    }
--------------------

to get system addr from user addr, first you need to lock the user pages,
then
you can do this to get a kernel virtual addr once the pages are pinned down.

    pgd = pgd_offset(current->mm, (unsigned long)addr);
    pmd = pmd_offset(pgd, (unsigned long) addr);
    pte = pte_offset(pmd, (unsigned long) addr);
    phys_addr = pte_page (*pte);

    kern_addr = (void *)(phys_addr | ((unsigned long) addr & (~PAGE_MASK)));

-----Original Message-----
From: Manfred Spraul [mailto:manfreds@colorfullife.com]
Sent: Wednesday, April 26, 2000 2:09 PM
To: jmcmullan@linuxcare.com
Cc: linux-kernel@vger.rutgers.edu
Subject: Re: VM: Bizzare MM tricks...

jmcmullan@linuxcare.com wrote:
>
> I'm working on a port of a driver from NT to Linux, and was
> wondering how to best go about mapping kernel memory to
> user space and vice versa. mmap(2) is a possibility, but would
> require a vast rework of the code, and break the ability of
> the customer to use their existing code base in NT/95.
>
What's the problem with mmap?
You could also call do_mmap() from within your ioctl, but I don't why
you want to do that. (it seems to be a one line change in the user space
app)

--
	Manfred

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Apr 30 2000 - 21:00:12 EST