linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH 1/3] mm/page_alloc: correct start page when guard page debug is enabled
  2023-08-10  9:53 ` [PATCH 1/3] mm/page_alloc: correct start page when guard page debug is enabled Kemeng Shi
@ 2023-08-10  9:10   ` David Hildenbrand
  2023-08-11  3:13     ` Kemeng Shi
  0 siblings, 1 reply; 6+ messages in thread
From: David Hildenbrand @ 2023-08-10  9:10 UTC (permalink / raw)
  To: Kemeng Shi, linux-mm, linux-kernel, akpm, baolin.wang, mgorman, willy

On 10.08.23 11:53, Kemeng Shi wrote:
> When guard page debug is enabled and set_page_guard returns success, we miss
> to forward page to point to start of next split range and we will do split
> unexpectedly in page range without target page. Move start page update
> before set_page_guard to fix this.
> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
>   mm/page_alloc.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 96b7c1a7d1f2..fd93d1396ccd 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -6557,6 +6557,7 @@ static void break_down_buddy_pages(struct zone *zone, struct page *page,
>   			next_page = page;
>   			current_buddy = page + size;
>   		}
> +		page = next_page;
>   
>   		if (set_page_guard(zone, current_buddy, high, migratetype))
>   			continue;
> @@ -6564,7 +6565,6 @@ static void break_down_buddy_pages(struct zone *zone, struct page *page,
>   		if (current_buddy != target) {
>   			add_to_free_list(current_buddy, zone, high, migratetype);
>   			set_buddy_order(current_buddy, high);
> -			page = next_page;
>   		}
>   	}
>   }

Is this worth a Fixes: tag?

What is the user-visible result?

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 0/3] Fixes and cleanups to break_down_buddy_pages in
@ 2023-08-10  9:53 Kemeng Shi
  2023-08-10  9:53 ` [PATCH 1/3] mm/page_alloc: correct start page when guard page debug is enabled Kemeng Shi
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Kemeng Shi @ 2023-08-10  9:53 UTC (permalink / raw)
  To: linux-mm, linux-kernel, akpm, baolin.wang, mgorman, david, willy
  Cc: shikemeng

Hi all, this series contains one bugfix and two cleanups to
break_down_buddy_pages in page_alloc.
Patch 1 corrects page forward in case guard page debug is enabled. Patch
2 and 3 remove unnecessary check and local variable.
More details can be found in respective patches. Thanks!

Kemeng Shi (3):
  mm/page_alloc: correct start page when guard page debug is enabled
  mm/page_alloc: remove unnecessary check in break_down_buddy_pages
  mm/page_alloc: remove unnecessary next_page in break_down_buddy_pages

 mm/page_alloc.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

-- 
2.30.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] mm/page_alloc: correct start page when guard page debug is enabled
  2023-08-10  9:53 [PATCH 0/3] Fixes and cleanups to break_down_buddy_pages in Kemeng Shi
@ 2023-08-10  9:53 ` Kemeng Shi
  2023-08-10  9:10   ` David Hildenbrand
  2023-08-10  9:53 ` [PATCH 2/3] mm/page_alloc: remove unnecessary check in break_down_buddy_pages Kemeng Shi
  2023-08-10  9:53 ` [PATCH 3/3] mm/page_alloc: remove unnecessary next_page " Kemeng Shi
  2 siblings, 1 reply; 6+ messages in thread
From: Kemeng Shi @ 2023-08-10  9:53 UTC (permalink / raw)
  To: linux-mm, linux-kernel, akpm, baolin.wang, mgorman, david, willy
  Cc: shikemeng

When guard page debug is enabled and set_page_guard returns success, we miss
to forward page to point to start of next split range and we will do split
unexpectedly in page range without target page. Move start page update
before set_page_guard to fix this.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 mm/page_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 96b7c1a7d1f2..fd93d1396ccd 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6557,6 +6557,7 @@ static void break_down_buddy_pages(struct zone *zone, struct page *page,
 			next_page = page;
 			current_buddy = page + size;
 		}
+		page = next_page;
 
 		if (set_page_guard(zone, current_buddy, high, migratetype))
 			continue;
@@ -6564,7 +6565,6 @@ static void break_down_buddy_pages(struct zone *zone, struct page *page,
 		if (current_buddy != target) {
 			add_to_free_list(current_buddy, zone, high, migratetype);
 			set_buddy_order(current_buddy, high);
-			page = next_page;
 		}
 	}
 }
-- 
2.30.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/3] mm/page_alloc: remove unnecessary check in break_down_buddy_pages
  2023-08-10  9:53 [PATCH 0/3] Fixes and cleanups to break_down_buddy_pages in Kemeng Shi
  2023-08-10  9:53 ` [PATCH 1/3] mm/page_alloc: correct start page when guard page debug is enabled Kemeng Shi
@ 2023-08-10  9:53 ` Kemeng Shi
  2023-08-10  9:53 ` [PATCH 3/3] mm/page_alloc: remove unnecessary next_page " Kemeng Shi
  2 siblings, 0 replies; 6+ messages in thread
From: Kemeng Shi @ 2023-08-10  9:53 UTC (permalink / raw)
  To: linux-mm, linux-kernel, akpm, baolin.wang, mgorman, david, willy
  Cc: shikemeng

1. We always have target in range started with next_page and full free
range started with current_buddy.
2. The last splited range size is 1 << low and low should be >= 0, then
size >= 1, then page + size and page will not interleave.
As summary, current_page will not equal to target page.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 mm/page_alloc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index fd93d1396ccd..d0b400733031 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6562,10 +6562,8 @@ static void break_down_buddy_pages(struct zone *zone, struct page *page,
 		if (set_page_guard(zone, current_buddy, high, migratetype))
 			continue;
 
-		if (current_buddy != target) {
-			add_to_free_list(current_buddy, zone, high, migratetype);
-			set_buddy_order(current_buddy, high);
-		}
+		add_to_free_list(current_buddy, zone, high, migratetype);
+		set_buddy_order(current_buddy, high);
 	}
 }
 
-- 
2.30.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/3] mm/page_alloc: remove unnecessary next_page in break_down_buddy_pages
  2023-08-10  9:53 [PATCH 0/3] Fixes and cleanups to break_down_buddy_pages in Kemeng Shi
  2023-08-10  9:53 ` [PATCH 1/3] mm/page_alloc: correct start page when guard page debug is enabled Kemeng Shi
  2023-08-10  9:53 ` [PATCH 2/3] mm/page_alloc: remove unnecessary check in break_down_buddy_pages Kemeng Shi
@ 2023-08-10  9:53 ` Kemeng Shi
  2 siblings, 0 replies; 6+ messages in thread
From: Kemeng Shi @ 2023-08-10  9:53 UTC (permalink / raw)
  To: linux-mm, linux-kernel, akpm, baolin.wang, mgorman, david, willy
  Cc: shikemeng

The next_page is only used to forward page in case target is in second
harf range. Move forward page directly to remove unnecessary next_page.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 mm/page_alloc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d0b400733031..e884d3fd0d06 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6544,20 +6544,18 @@ static void break_down_buddy_pages(struct zone *zone, struct page *page,
 				   int migratetype)
 {
 	unsigned long size = 1 << high;
-	struct page *current_buddy, *next_page;
+	struct page *current_buddy;
 
 	while (high > low) {
 		high--;
 		size >>= 1;
 
 		if (target >= &page[size]) {
-			next_page = page + size;
 			current_buddy = page;
+			page = page + size;
 		} else {
-			next_page = page;
 			current_buddy = page + size;
 		}
-		page = next_page;
 
 		if (set_page_guard(zone, current_buddy, high, migratetype))
 			continue;
-- 
2.30.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] mm/page_alloc: correct start page when guard page debug is enabled
  2023-08-10  9:10   ` David Hildenbrand
@ 2023-08-11  3:13     ` Kemeng Shi
  0 siblings, 0 replies; 6+ messages in thread
From: Kemeng Shi @ 2023-08-11  3:13 UTC (permalink / raw)
  To: David Hildenbrand, linux-mm, linux-kernel, akpm, baolin.wang,
	mgorman, willy



on 8/10/2023 5:10 PM, David Hildenbrand wrote:
> On 10.08.23 11:53, Kemeng Shi wrote:
>> When guard page debug is enabled and set_page_guard returns success, we miss
>> to forward page to point to start of next split range and we will do split
>> unexpectedly in page range without target page. Move start page update
>> before set_page_guard to fix this.
>>
>> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
>> ---
>>   mm/page_alloc.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index 96b7c1a7d1f2..fd93d1396ccd 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -6557,6 +6557,7 @@ static void break_down_buddy_pages(struct zone *zone, struct page *page,
>>               next_page = page;
>>               current_buddy = page + size;
>>           }
>> +        page = next_page;
>>             if (set_page_guard(zone, current_buddy, high, migratetype))
>>               continue;
>> @@ -6564,7 +6565,6 @@ static void break_down_buddy_pages(struct zone *zone, struct page *page,
>>           if (current_buddy != target) {
>>               add_to_free_list(current_buddy, zone, high, migratetype);
>>               set_buddy_order(current_buddy, high);
>> -            page = next_page;
>>           }
>>       }
>>   }
> 
> Is this worth a Fixes: tag?
> 
Sure, I will add this in next version.
> What is the user-visible result?
> 
As we split to wrong target page, then splited pages are not able to merge
back to originial order when target page is put back and splited pages except
target page is not usable. To be specific:

Consider target page is the third page in buddy page with order 2.
| buddy-2 | Page | Target | Page |

After break down to target page, we will only set first page to Guard
because of bug.
| Guard   | Page | Target | Page |

When we try put_page_back_buddy with target page, the buddy page of target
if neither guard nor buddy, Then it's not able to construct original page
with order 2
| Guard | Page | buddy-0 | Page |

All pages except target page is not in free list and is not usable.



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-08-11  3:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-10  9:53 [PATCH 0/3] Fixes and cleanups to break_down_buddy_pages in Kemeng Shi
2023-08-10  9:53 ` [PATCH 1/3] mm/page_alloc: correct start page when guard page debug is enabled Kemeng Shi
2023-08-10  9:10   ` David Hildenbrand
2023-08-11  3:13     ` Kemeng Shi
2023-08-10  9:53 ` [PATCH 2/3] mm/page_alloc: remove unnecessary check in break_down_buddy_pages Kemeng Shi
2023-08-10  9:53 ` [PATCH 3/3] mm/page_alloc: remove unnecessary next_page " Kemeng Shi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox