Doubt about no_page method in VMA
- From: "Mozis" <chokshi.jaydeep@xxxxxxxxx>
- Date: 29 Dec 2005 04:21:31 -0800
In linux device driver book, I read the section of implementation of
mmap in our device driver. they mentioned two methods to build the page
tables,
method_1. remap_pfn_range ( vma, virt_adr, pfn, size,
protection);
Here they have said that in most cases the we will get the *pfn* from
the vma->vm_pgoff member. but when I read the /linux/mm.h, it's written
that vm_pgoff contains the offset in multiple of PAGE_SIZE, that is if
PAGE_SIZE is 4k then if user has provided offset in mmap() as 8192,
then vm_pgoff wub be 2(correct me if I'm wrong).
So I thought that remap_pfn_range(...) wud be providing linear mapping
to user address, so we can consider the vm_pgoff as the actual *pfn*
which is passed in remap_pfn_range.
method_2. struct page* (*nopage) (vma, address, *type)
Here we will be returning a page at a time. So here whenever a process
attempt to access a page which is in the VMA,but not in main memory,
then this metod will be called to return page. Now I have some doubts
here,
1. they have calculated the *pfn* here as follows,
struct page* nopage(vma,address,*type)
{
1. struct page *pageptr;
2 offset = vma->vm_pgoff << PAGE_SHIFT ; // to get
the page address
3 phyaddr = address - vma->vm_start + offset ;
4 pagefram = phyaddr >> PAGE_SHIFT ;
5
6 if ( !pfn_valid (pagefram) )
7 return NOPAGE_SIGBUS ;
8 pageptr = pfn_to_page (pagefram) ;
9 get_page (pageptr) ; // increment the page
referece counter
10 if (type)
11 *type = VM_FAULT_MINOR ;
12 return pageptr ;
}
here I'm not getting the essense of line 3, i mean, by line 1, we get
the virtual start address of page. suppose vm_pgoff is 2 then it will
be the virtual address 2nd page. now how come we get the physical
address of page from line 3, I mean I am not able to visualize the
matter and what pfn_valid do and can't we giv error
NOPAGE_SIGSGV(segmentation fault as what mmap() returns)
Please any can understand me giving some example. Another thing is, in
remap_pfn_range, we build page table of all VMA so can kernel return
the mapped vma->vm_start to user address. but if we implement mmap()
with nopage method, how come kernel give return value of mmap()
because generally we'll do nothing in nopage_mmap() method. all we
will do while page fault occures.
I know its going a bit long but u know its important.
Regards,
Mozis.
.
- Prev by Date: Re: process switch...
- Next by Date: Re: How does rpm command compare 2 rpm files' version?
- Previous by thread: to enable C or C++ syntax highlighting in Vi Editor
- Next by thread: Tigon3 basic control over NIC Help!
- Index(es):
Relevant Pages
|