Calculating kernel logical address ..
Quoted 15 lines
adr =
user_address;pgd_offset(current->mm, adr);if (!pgd_none(*pgd)) { pmd = pmd_offset(pgd, adr); if (!pmd_none(*pmd)) { ptep = pte_offset(pmd, adr); pte = *ptep; if(pte_present(pte)) { kaddr = (unsigned long) page_address(pte_page(pte)); kaddr |= (adr & (PAGE_SIZE - 1)); } } }
Quoted 2 lines
Will this code always give me correct kernel logical address?
What about
kmalloc_buffer+(user_address-vma->vm_start)
?
A driver should avoid accessing the page tables.
--
Manfred
-----Original Message-----
From: Manfred Spraul [mailto:[email protected]]
Sent: Friday, September 06, 2002 8:44 AM
To: Imran Badr
Cc: [email protected]
Subject: Re: Calculating kernel logical address ..
Quoted 15 lines
adr =
user_address;pgd_offset(current->mm, adr);if (!pgd_none(*pgd)) { pmd = pmd_offset(pgd, adr); if (!pmd_none(*pmd)) { ptep = pte_offset(pmd, adr); pte = *ptep; if(pte_present(pte)) { kaddr = (unsigned long) page_address(pte_page(pte)); kaddr |= (adr & (PAGE_SIZE - 1)); } } }
Quoted 2 lines
Will this code always give me correct kernel logical address?
What about
kmalloc_buffer+(user_address-vma->vm_start)
?
A driver should avoid accessing the page tables.
--
Manfred
I was wondering if the code which I am using, will always give me addresses no matter whether HIGHMEM is defined in kernel configuration or not. I belive that it should not be problem because I am mmap'ing kmalloc'ed memory which always returns mapped memory. But whats happeing in my lab is different. If I define HIGHMEM in kernel configuration and install 2GB of memory in my server then I see a crash in the kernel where I try to access kaddr calculated bu above code. Any idea?
The problem with your suggestion is that at the point where user gives me an address for DMA, I do not know what kmalloc_buffer and vma->vm_start values are. Also, if there are more than one processes accessing the driver, then how am I going to keep track of all mmap'ed memory.
Thanks,
Imran.
Quoted 15 lines · Imran Badr
Quoted 15 lines
adr =
user_address;pgd_offset(current->mm, adr);if (!pgd_none(*pgd)) { pmd = pmd_offset(pgd, adr); if (!pmd_none(*pmd)) { ptep = pte_offset(pmd, adr); pte = *ptep; if(pte_present(pte)) { kaddr = (unsigned long) page_address(pte_page(pte)); kaddr |= (adr & (PAGE_SIZE - 1)); } } }
Quoted 4 lines
Quoted 1 line
Will this code always give me correct kernel logical address?
I was wondering if the code which I am using, will always give me addresses no matter whether HIGHMEM is defined in kernel configuration or not.
On second thought, this code does have problems with highmem. The page in question was never kmapped, so no kernel address was assigned if the page was a high memory page. Besides that, there are other other changes to page address that imply it can't be used with a high memory page. So the above code isn't generic.
Quoted 6 lines
I
belive that it should not be problem because I am mmap'ing kmalloc'ed memory which always returns mapped memory. But whats happeing in my lab is different. If I define HIGHMEM in kernel configuration and install 2GB of memory in my server then I see a crash in the kernel where I try to access kaddr calculated bu above code. Any idea?
Because of what I just said.
Quoted 4 lines
The problem with your suggestion is that at the point where user gives me an address for DMA, I do not know what
kmalloc_bufferandvma->vm_startvalues are. Also, if there are more than one processes accessing the driver, then how am I going to keep track of all mmap'ed memory.
Signature · 1 line
Daniel