Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

nommu: Correct kobjsize() page validity checks.

This implements a few changes on top of the recent kobjsize() refactoring
introduced by commit 6cfd53fc03670c7a544a56d441eb1a6cc800d72b.

As Christoph points out:

virt_to_head_page cannot return NULL. virt_to_page also
does not return NULL. pfn_valid() needs to be used to
figure out if a page is valid. Otherwise the page struct
reference that was returned may have PageReserved() set
to indicate that it is not a valid page.

As discussed further in the thread, virt_addr_valid() is the preferable
way to validate the object pointer in this case. In addition to fixing
up the reserved page case, it also has the benefit of encapsulating the
hack introduced by commit 4016a1390d07f15b267eecb20e76a48fd5c524ef on
the impacted platforms, allowing us to get rid of the extra checking in
kobjsize() for the platforms that don't perform this type of bizarre
memory_end abuse (every nommu platform that isn't blackfin). If blackfin
decides to get in line with every other platform and use PageReserved
for the DMA pages in question, kobjsize() will also continue to work
fine.

It also turns out that compound_order() will give us back 0-order for
non-head pages, so we can get rid of the PageCompound check and just
use compound_order() directly. Clean that up while we're at it.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Reviewed-by: Christoph Lameter <clameter@sgi.com>
Acked-by: David Howells <dhowells@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Paul Mundt and committed by
Linus Torvalds
5a1603be f969c567

+3 -18
+3 -18
mm/nommu.c
··· 104 104 unsigned int kobjsize(const void *objp) 105 105 { 106 106 struct page *page; 107 - int order = 0; 108 107 109 108 /* 110 109 * If the object we have should not have ksize performed on it, 111 110 * return size of 0 112 111 */ 113 - if (!objp) 114 - return 0; 115 - 116 - if ((unsigned long)objp >= memory_end) 112 + if (!objp || !virt_addr_valid(objp)) 117 113 return 0; 118 114 119 115 page = virt_to_head_page(objp); 120 - if (!page) 121 - return 0; 122 116 123 117 /* 124 118 * If the allocator sets PageSlab, we know the pointer came from ··· 123 129 124 130 /* 125 131 * The ksize() function is only guaranteed to work for pointers 126 - * returned by kmalloc(). So handle arbitrary pointers, that we expect 127 - * always to be compound pages, here. 132 + * returned by kmalloc(). So handle arbitrary pointers here. 128 133 */ 129 - if (PageCompound(page)) 130 - order = compound_order(page); 131 - 132 - /* 133 - * Finally, handle arbitrary pointers that don't set PageSlab. 134 - * Default to 0-order in the case when we're unable to ksize() 135 - * the object. 136 - */ 137 - return PAGE_SIZE << order; 134 + return PAGE_SIZE << compound_order(page); 138 135 } 139 136 140 137 /*