Doubt about no_page method in VMA



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.

.



Relevant Pages

  • Re: help regarding development of common interface of application with devices..
    ... > You do know this is a Linux newsgroup right? ... > approach in Linux would be done via an mmap. ... The device driver could ... which would help with the synchronization ...
    (comp.os.linux.development.system)
  • mmap returns EINVAL
    ... I was trying to write a device driver for one of my PCI board on Linux. ... I try to mmap the 6 PCI BARs to the user space by implementing the mmap ...
    (comp.os.linux.development.system)
  • RE: Using remap_pfn_range causes system hang on app close in 2.6.15 & up
    ... What I did not mention in my original post is that my driver performed a sort of custom protocol when mmap() is called. ... I don't believe there should be an issue with calling remap_pfn_range outside of the driver's mmaproutine, but I am not a kernel developer, so I could be wrong in my assumption. ... Buffer Allocation Code ...
    (Linux-Kernel)
  • Re: Accessing file mapped data inside the kernel
    ... > Just try to understand the kernel filesystem. ... > looking at mmap supplied by the filesystem, ... when the user tries to access the memory, does a page fault occur (because ... address belonging to the same page) are direct memory accesses. ...
    (Linux-Kernel)
  • Re: [malware-list] [RFC 0/5] [TALPA] Intro to alinuxinterfaceforon access scanning
    ... reliable virus scanning. ... ...or do you have a reasonable solution for mmap? ... Your scanner runs with privilege and passes ... (with the appropriate kernel support) ...
    (Linux-Kernel)