lkml.org 
[lkml]   [2022]   [Sep]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v1 02/12] mm: check page validity when find a buddy page in a non-contiguous zone
Date
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 --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;
--
2.35.1
\
 
 \ /
  Last update: 2022-09-22 03:13    [W:0.080 / U:0.012 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site