diff mbox series

[v1,02/12] mm: check page validity when find a buddy page in a non-contiguous zone

Message ID 20220922011252.2266780-3-zi.yan@sent.com (mailing list archive)
State New
Headers show
Series Make MAX_ORDER adjustable as a kernel boot time parameter. | expand

Commit Message

Zi Yan Sept. 22, 2022, 1:12 a.m. UTC
From: Zi Yan <ziy@nvidia.com>

When MAX_ORDER > section size, buddy page might not be valid when the zone
is non-contiguous. Check it and return NULL if buddy page is not valid.

For PFNs that not aligned to MAX_ORDER (usually at the beginning and end
of a zone), __free_pages_memory() clamps down the order to make sure
invalid PFN will not show up as a buddy PFN.

Signed-off-by: Zi Yan <ziy@nvidia.com>
---
 mm/internal.h | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/mm/internal.h b/mm/internal.h
index b3002e03c28f..22fb1e6e3541 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -330,12 +330,16 @@  static inline struct page *find_buddy_page_pfn(struct page *page,
 			unsigned long pfn, unsigned int order, unsigned long *buddy_pfn)
 {
 	unsigned long __buddy_pfn = __find_buddy_pfn(pfn, order);
+	struct zone *zone = page_zone(page);
 	struct page *buddy;
 
 	buddy = page + (__buddy_pfn - pfn);
 	if (buddy_pfn)
 		*buddy_pfn = __buddy_pfn;
 
+	if (unlikely(!zone->contiguous && !pfn_valid(__buddy_pfn)))
+		return NULL;
+
 	if (page_is_buddy(page, buddy, order))
 		return buddy;
 	return NULL;