All of lore.kernel.org
 help / color / mirror / Atom feed
* A question on vma_address()
@ 2017-10-16 15:54 Perr Zhang
  2017-10-17  3:54 ` Thibaut SAUTEREAU
  0 siblings, 1 reply; 2+ messages in thread
From: Perr Zhang @ 2017-10-16 15:54 UTC (permalink / raw)
  To: kernelnewbies


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/?id=a8fa41ad

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?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* A question on vma_address()
  2017-10-16 15:54 A question on vma_address() Perr Zhang
@ 2017-10-17  3:54 ` Thibaut SAUTEREAU
  0 siblings, 0 replies; 2+ messages in thread
From: Thibaut SAUTEREAU @ 2017-10-17  3:54 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-17  3:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-16 15:54 A question on vma_address() Perr Zhang
2017-10-17  3:54 ` Thibaut SAUTEREAU

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.