Skip to contentSkip to conversation

mm: page_alloc: avoid false page outside zone error info

PATCH Applied Miaohe Lin 3 participants 5 messages Jul 4, 2023 – Jul 5, 2023

Subsystems (2)
lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH 1/1 mm: page_alloc: avoid false page outside zone error info

If pfn is outside zone boundaries in the first round, ret will be set to 1. But if pfn is changed to inside the zone boundaries in zone span seqretry path, ret is still set to 1 leading to false page outside zone error info.

---
 mm/page_alloc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/page_alloc.c +3 -1
index 7d3460c7a480..40a9f3ed25e9 100644
@@ -459,7 +459,7 @@ void set_pageblock_migratetype(struct page *page, int migratetype)
 #ifdef CONFIG_DEBUG_VM
 static int page_outside_zone_boundaries(struct zone *zone, struct page *page)
 {
-	int ret = 0;
+	int ret;
 	unsigned seq;
 	unsigned long pfn = page_to_pfn(page);
 	unsigned long sp, start_pfn;
@@ -470,6 +470,8 @@ static int page_outside_zone_boundaries(struct zone *zone, struct page *page)
 		sp = zone->spanned_pages;
 		if (!zone_spans_pfn(zone, pfn))
 			ret = 1;
+		else
+			ret = 0;
 	} while (zone_span_seqretry(zone, seq));
 
 	if (ret)
Signature · 1 line
2.33.0
#1 lore raw

mm/page_alloc.c static int page_outside_zone_boundaries(struct zone *zone, struct page *page) · line 474

Quoted 6 lines · Miaohe Lin
mm/page_alloc.c +2 -0
@@ -470,6 +470,8 @@ static int page_outside_zone_boundaries(struct zone *zone, struct page *page)
 		sp = zone->spanned_pages;
 		if (!zone_spans_pfn(zone, pfn))
 			ret = 1;
+		else
+			ret = 0;

Surely 'ret = zone_spans_pfn(zone, pfn);' ?

Also, did you spot this by inspection or do you have a test-case or bug report? Should this have a Fixes: tag?

author
#2 lore raw
Quoted 9 lines · Matthew Wilcox

mm/page_alloc.c static int page_outside_zone_boundaries(struct zone *zone, struct page *page) · line 474

Quoted 6 lines · Miaohe Lin
mm/page_alloc.c +2 -0
@@ -470,6 +470,8 @@ static int page_outside_zone_boundaries(struct zone *zone, struct page *page)
 		sp = zone->spanned_pages;
 		if (!zone_spans_pfn(zone, pfn))
 			ret = 1;
+		else
+			ret = 0;

Surely 'ret = zone_spans_pfn(zone, pfn);' ?

Do you mean 'ret = !zone_spans_pfn(zone, pfn);'? This format looks fine to me.

Quoted 3 lines

Also, did you spot this by inspection or do you have a test-case or bug report? Should this have a Fixes: tag?

This is from code inspection. The race window should be really small thus hard to trigger in real world. And yes, it seems Fixes tag is a really ancient commit:

Fixes bdc8cb984576 ("[PATCH] memory hotplug locking: zone span seqlock")

Thanks for your comment and reply.

maintainer
#3 lore raw
Quoted 14 lines · On Tue, 4 Jul 2023 20:36:00 +0800 Miaohe Lin <[email protected]> wrote:
Quoted 9 lines · Matthew Wilcox

Review static int page_outside_zone_boundaries(struct zone *zone, struct page *page) · line 474

Quoted 6 lines · Miaohe Lin
(quoted diff) +2 -0
@@ -470,6 +470,8 @@ static int page_outside_zone_boundaries(struct zone *zone, struct page *page)
 		sp = zone->spanned_pages;
 		if (!zone_spans_pfn(zone, pfn))
 			ret = 1;
+		else
+			ret = 0;

Surely 'ret = zone_spans_pfn(zone, pfn);' ?

Do you mean 'ret = !zone_spans_pfn(zone, pfn);'? This format looks fine to me.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Also, did you spot this by inspection or do you have a test-case or bug report? Should this have a Fixes: tag?

This is from code inspection. The race window should be really small thus hard to trigger in real world. And yes, it seems Fixes tag is a really ancient commit:

Fixes bdc8cb984576 ("[PATCH] memory hotplug locking: zone span seqlock")

Thanks. I updated the changelog:

: If pfn is outside zone boundaries in the first round, ret will be set to : 1. But if pfn is changed to inside the zone boundaries in zone span : seqretry path, ret is still set to 1 leading to false page outside zone : error info.
:
: This is from code inspection. The race window should be really small thus : hard to trigger in real world.
:
: Link: https://lkml.kernel.org/r/[email protected]
: Fixes: bdc8cb984576 ("[PATCH] memory hotplug locking: zone span seqlock")

and I made the change suggested by Matthew:

mm/page_alloc.c renamed from mm/page_alloc.c~mm-page_alloc-avoid-false-page-outside-zone-error-info-fix +1 -4
@@ -468,10 +468,7 @@ static int page_outside_zone_boundaries(
 		seq = zone_span_seqbegin(zone);
 		start_pfn = zone->zone_start_pfn;
 		sp = zone->spanned_pages;
-		if (!zone_spans_pfn(zone, pfn))
-			ret = 1;
-		else
-			ret = 0;
+		ret = !zone_spans_pfn(zone, pfn);
 	} while (zone_span_seqretry(zone, seq));
 
 	if (ret)

_

author
#4 lore raw
Quoted 43 lines · Andrew Morton
Quoted 14 lines · On Tue, 4 Jul 2023 20:36:00 +0800 Miaohe Lin <[email protected]> wrote:
Quoted 9 lines · Matthew Wilcox

Review static int page_outside_zone_boundaries(struct zone *zone, struct page *page) · line 474

Quoted 6 lines · Miaohe Lin
(quoted diff) +2 -0
@@ -470,6 +470,8 @@ static int page_outside_zone_boundaries(struct zone *zone, struct page *page)
 		sp = zone->spanned_pages;
 		if (!zone_spans_pfn(zone, pfn))
 			ret = 1;
+		else
+			ret = 0;

Surely 'ret = zone_spans_pfn(zone, pfn);' ?

Do you mean 'ret = !zone_spans_pfn(zone, pfn);'? This format looks fine to me.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Also, did you spot this by inspection or do you have a test-case or bug report? Should this have a Fixes: tag?

This is from code inspection. The race window should be really small thus hard to trigger in real world. And yes, it seems Fixes tag is a really ancient commit:

Fixes bdc8cb984576 ("[PATCH] memory hotplug locking: zone span seqlock")

Thanks. I updated the changelog:

: If pfn is outside zone boundaries in the first round, ret will be set to : 1. But if pfn is changed to inside the zone boundaries in zone span : seqretry path, ret is still set to 1 leading to false page outside zone : error info.
:
: This is from code inspection. The race window should be really small thus : hard to trigger in real world.
:
: Link: https://lkml.kernel.org/r/[email protected]
: Fixes: bdc8cb984576 ("[PATCH] memory hotplug locking: zone span seqlock")

and I made the change suggested by Matthew:

mm/page_alloc.c static int page_outside_zone_boundaries( · line 472

Quoted 9 lines
mm/page_alloc.c renamed from mm/page_alloc.c~mm-page_alloc-avoid-false-page-outside-zone-error-info-fix +1 -4
@@ -468,10 +468,7 @@ static int page_outside_zone_boundaries(
 		seq = zone_span_seqbegin(zone);
 		start_pfn = zone->zone_start_pfn;
 		sp = zone->spanned_pages;
-		if (!zone_spans_pfn(zone, pfn))
-			ret = 1;
-		else
-			ret = 0;
+		ret = !zone_spans_pfn(zone, pfn);
 	} while (zone_span_seqretry(zone, seq));

These changes look good to me. Thanks for doing this.