Commit ab2e83ead4eca9e045daac4cbf66eb1e7a244bb2

Authored by Paul Mundt
Committed by David Howells
1 parent 0f3e442a40

NOMMU: Teach kobjsize() about VMA regions.

Now that we no longer use compound pages for all large allocations,
kobjsize() actively breaks things like binfmt_flat by always handing
back PAGE_SIZE for mmap'ed regions. Fix this up by looking up the
VMA region for non-compounds.

Ideally binfmt_flat wants to get rid of kobjsize() completely, but
this is an incremental step.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Signed-off-by: David Howells <dhowells@redhat.com>
Tested-by: Mike Frysinger <vapier.adi@gmail.com>

Showing 1 changed file with 14 additions and 0 deletions Side-by-side Diff

... ... @@ -149,6 +149,20 @@
149 149 return ksize(objp);
150 150  
151 151 /*
  152 + * If it's not a compound page, see if we have a matching VMA
  153 + * region. This test is intentionally done in reverse order,
  154 + * so if there's no VMA, we still fall through and hand back
  155 + * PAGE_SIZE for 0-order pages.
  156 + */
  157 + if (!PageCompound(page)) {
  158 + struct vm_area_struct *vma;
  159 +
  160 + vma = find_vma(current->mm, (unsigned long)objp);
  161 + if (vma)
  162 + return vma->vm_end - vma->vm_start;
  163 + }
  164 +
  165 + /*
152 166 * The ksize() function is only guaranteed to work for pointers
153 167 * returned by kmalloc(). So handle arbitrary pointers here.
154 168 */