Re: [PATCH] proc: nommu: fix empty /proc/<pid>/maps

From: Matthew Wilcox
Date: Fri Sep 15 2023 - 13:21:03 EST


On Fri, Sep 15, 2023 at 12:00:56PM -0400, Ben Wolsieffer wrote:
> On no-MMU, /proc/<pid>/maps reads as an empty file. This happens because
> find_vma(mm, 0) always returns NULL (assuming no vma actually contains
> the zero address, which is normally the case).

Your patch is correct, but this is a deeper problem. find_vma() on
MMU architectures returns the first VMA which is >= addr.

* Returns: The VMA associated with addr, or the next VMA.
* May return %NULL in the case of no VMA at addr or above.

But that's not how find_vma() behaves on nommu! And I'd be tempted to
blame the maple tree conversion, but this is how it looked before the
maple tree:

- /* trawl the list (there may be multiple mappings in which addr
- * resides) */
- for (vma = mm->mmap; vma; vma = vma->vm_next) {
- if (vma->vm_start > addr)
- return NULL;
- if (vma->vm_end > addr) {
- vmacache_update(addr, vma);
- return vma;
- }
- }

So calling find_vma(0) always returned NULL. Unless there was a VMA
at 0, which there probably wasn't.

Why does nommu behave differently? Dave, you introduced it back in 2005
(yes, I had to go to the git history tree for this one)