I am reading codes on reverse mapping. The code of vma_address() was last changed at 2017-02-24 17:46:55 -0800 The link of the commit is: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... The definition of vma_address(): http://elixir.free-electrons.com/linux/latest/source/mm/internal.h#L343 The code of vma_address() looks like this: ------------------------------------------------------------------------------------ static inline unsigned long __vma_address(struct page *page, struct vm_area_struct *vma) { pgoff_t pgoff = page_to_pgoff(page); return vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT); } static inline unsigned long vma_address(struct page *page, struct vm_area_struct *vma) { unsigned long start, end; start = __vma_address(page, vma); ... return max(start, vma->vm_start); } ------------------------------------------------------------------------------------ This function is only called by rmap_walk_file() and rmap_walk_anon() which ensure the page used by vma_address() is in an anon_vma or in an address_space. Why should we use the function max() on 'start' and 'vma->vm_start'? Could the 'start' be less than 'vma->vm_start'? If it is so, isn't it wrong to just return vma->vm_start but report an error?
Hi Perr, On Mon, Oct 16, 2017 at 11:54:47PM +0800, Perr Zhang wrote:
Why should we use the function max() on 'start' and 'vma->vm_start'? Could the 'start' be less than 'vma->vm_start'? If it is so, isn't it wrong to just return vma->vm_start but report an error?
The vma_address() function was recently changed in commit a8fa41ad2f6f7. In the previous version, having the return value of __vma_address() lower than vma->vm_start was actually triggering a VM_BUG_ON_VMA. Taking a look at this commit and understanding why such changes had to be done might help you find an answer to your question :) -- Thibaut SAUTEREAU
participants (2)
-
Perr Zhang -
Thibaut SAUTEREAU