Welcome! Log In Create A New Profile

kmap problem

Posted by Viral 
kmap problem
February 20, 2009 06:44AM
Hi All,
I am writing a kernel module. And I am facing a problem relate to Kmap.

I am retriving Kernel Virtual Address for a specific Page using kmap() and then after some time I am doing kunmap().
Now, I know that kmap can give A LIMITED NUMBER OF MAPPINGS and so such mapping should NOT be held longer. But in my case it is absolutely necessary to hold more than 1024 such mappings.

The same code is NOT working on 2.6.10 kernel and IS WORKING on 2.6.18 kernel. The system is same and there are two kernels that I am playing with.

My only question is what is so changed in 2.6.18 kernel from 2.6.10 that the same code is working and evidently kmap can hold more than 1024 virtual address mappings.

The other thing I would like to know if there is ANY generic way to handle this situation in 2.6.10 kernel.

Thanks,
Viral
Re: kmap problem
March 19, 2009 02:29AM
Not sure what is your meaning of "kernel virtual address", but reading kmap() API:

void *kmap(struct page *page)
{
might_sleep();
if (!PageHighMem(page))
return page_address(page);
return kmap_high(page);
}

the input NECESSARILY must be a highmem address, whereas the word "kernel" in lots of places implicitly meant that it CANNOT BE a highmem address:

First look at kernel_map_pages():

void kernel_map_pages(struct page *page, int numpages, int enable)
{
if (PageHighMem(page))
return;
if (!enable) {
debug_check_no_locks_freed(page_address(page),
numpages * PAGE_SIZE);
}

So it cannot be a highmem page, and the API is used in mm/slab.c and mm/page_alloc.c.

But the short answer is really: all "kernel" address (as returned from alloc_pages() or kmalloc()) does not need to be "kmap()" - because the pagetable already has its PTE entry.

Thanks.



It is a pattern that kernel does not use highmem address for its own processing, so as to facilitate identity mapping (and so many other reasons).....without which page table walking is really painful.
Re: kmap problem
April 18, 2010 01:27PM
There appear to be two kinds of virtual address linux on x86 seem to be dealing with when mapping a physical address. So long as physical address is within ZONE_DMA and ZONE_NORMAL which stretch to about 0 to 896MB, kmalloc() allocator *must* be used. In this case the virtual address (in kernel space) that lives in 3 to 4GB will have a constant offset from its physical counter part in o to 896MB. This seems to be being referred to as logical address.

And the other beast, What if the physical memory is above ZONE_NORMAL? It is this case one is expected to use kmap/kunmap to get the kernel mapping. This constant offsetting as in the case of 0-896MB no longer applies and the virtual address has no direct liner relation to the physical address. This appears to be getting referred to as "Kernel virtual address"

Geesh! What a poor choice of names!
Re: kmap problem
April 26, 2010 03:15PM
On 32-bit system, only low memory (ZONE_NORMAL) is directly mapped to kernel virtual address space.
To access high memory page, manual mapping is required.
Author:

Your Email:


Subject:


Message: