* [PATCH v2 0/2] xen/mm: Reset PFN_ORDER for offlined buddy heads
@ 2026-06-03 15:11 Bernhard Kaindl
2026-06-03 15:11 ` [PATCH v2 1/2] xen/mm: reset " Bernhard Kaindl
2026-06-03 15:11 ` [PATCH v2 2/2] tools/tests/native: Add test for offlined buddy head PFN_ORDER Bernhard Kaindl
0 siblings, 2 replies; 5+ messages in thread
From: Bernhard Kaindl @ 2026-06-03 15:11 UTC (permalink / raw)
To: xen-devel
Cc: Bernhard Kaindl, Andrew Cooper, Anthony PERARD, Michal Orzel,
Jan Beulich, Julien Grall, Roger Pau Monné,
Stefano Stabellini
This series fixes an inconsistency in the PFN_ORDER annotation for
pages that are offlined when they are the head of a free buddy.
When reserve_offlined_page() splits a buddy and moves offlined
sub-pages to the offlined lists, the former buddy head would be
left annotated with its original order even though it is now a
single page. While this does not cause functional regressions,
it is misleading.
You can pull this series with the regression test environment to run it:
$ git pull git@gitlab.com:bernhardkaindl/xen.git offline-head-order-v2
$ make -C tools/tests/native TARGETS=offline-head-order test
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@citrix.com>
Bernhard Kaindl (2):
xen/mm: reset PFN_ORDER for offlined buddy heads
tools/tests/native: Add test for offlined buddy head PFN_ORDER
tools/tests/native/offline-head-order.c | 74 +++++++++++++++++++++++++
xen/common/page_alloc.c | 6 ++
2 files changed, 80 insertions(+)
create mode 100644 tools/tests/native/offline-head-order.c
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] xen/mm: reset PFN_ORDER for offlined buddy heads
2026-06-03 15:11 [PATCH v2 0/2] xen/mm: Reset PFN_ORDER for offlined buddy heads Bernhard Kaindl
@ 2026-06-03 15:11 ` Bernhard Kaindl
2026-06-03 15:25 ` Jan Beulich
2026-06-03 15:11 ` [PATCH v2 2/2] tools/tests/native: Add test for offlined buddy head PFN_ORDER Bernhard Kaindl
1 sibling, 1 reply; 5+ messages in thread
From: Bernhard Kaindl @ 2026-06-03 15:11 UTC (permalink / raw)
To: xen-devel
Cc: Bernhard Kaindl, Andrew Cooper, Anthony PERARD, Michal Orzel,
Jan Beulich, Julien Grall, Roger Pau Monné,
Stefano Stabellini
Ensure offlined buddy head pages are annotated as order-0 pages.
When a buddy containing pages marked for offlining is processed,
reserve_offlined_page() rebuilds any surviving healthy buddies
and moves the offlined subpages onto the offlined lists.
If the buddy head itself is offlined it was previously left
annotated with the original buddy order even though it has
been split into a single page.
This has no functional impact as the order of an offlined
page is not used for any decision making and onlining, but
it is misleading when inspecting the page's metadata.
Set PFN_ORDER(cur_head) to 0 for all pages moved to the
lists of offlined and broken pages so the page's stored
order reflects its actual size.
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
v2:
- Fix isolated from the new test and moved it ahead of the test.
- Unconditionally store 0 as the PFN_ORDER() of the offlined
pages to make the code more robust against future changes.
---
xen/common/page_alloc.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index e01ac3e99c72..6c4e26004b2a 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -1251,6 +1251,12 @@ static int reserve_offlined_page(struct page_info *head)
ASSERT(total_avail_pages > 0);
total_avail_pages--;
+ /*
+ * All offlined pages are standalone pages: If this offlined page was
+ * the head of a higher-order buddy, we need to reset its order to 0:
+ */
+ PFN_ORDER(cur_head) = 0;
+
page_list_add_tail(cur_head,
test_bit(_PGC_broken, &cur_head->count_info) ?
&page_broken_list : &page_offlined_list);
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2 1/2] xen/mm: reset PFN_ORDER for offlined buddy heads
2026-06-03 15:11 ` [PATCH v2 1/2] xen/mm: reset " Bernhard Kaindl
@ 2026-06-03 15:25 ` Jan Beulich
2026-06-03 15:29 ` Bernhard Kaindl
0 siblings, 1 reply; 5+ messages in thread
From: Jan Beulich @ 2026-06-03 15:25 UTC (permalink / raw)
To: Bernhard Kaindl
Cc: Andrew Cooper, Anthony PERARD, Michal Orzel, Julien Grall,
Roger Pau Monné, Stefano Stabellini, xen-devel
On 03.06.2026 17:11, Bernhard Kaindl wrote:
> Ensure offlined buddy head pages are annotated as order-0 pages.
>
> When a buddy containing pages marked for offlining is processed,
> reserve_offlined_page() rebuilds any surviving healthy buddies
> and moves the offlined subpages onto the offlined lists.
>
> If the buddy head itself is offlined it was previously left
> annotated with the original buddy order even though it has
> been split into a single page.
>
> This has no functional impact as the order of an offlined
> page is not used for any decision making and onlining, but
> it is misleading when inspecting the page's metadata.
As per this, ...
> --- a/xen/common/page_alloc.c
> +++ b/xen/common/page_alloc.c
> @@ -1251,6 +1251,12 @@ static int reserve_offlined_page(struct page_info *head)
> ASSERT(total_avail_pages > 0);
> total_avail_pages--;
>
> + /*
> + * All offlined pages are standalone pages: If this offlined page was
> + * the head of a higher-order buddy, we need to reset its order to 0:
... is it really "need to"? I'd suggest simply dropping "we need to". Also
unless there's really a good reason, comments better wouldn't end in colons.
Can make adjustments while committing, as long as you agree.
Jan
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH v2 1/2] xen/mm: reset PFN_ORDER for offlined buddy heads
2026-06-03 15:25 ` Jan Beulich
@ 2026-06-03 15:29 ` Bernhard Kaindl
0 siblings, 0 replies; 5+ messages in thread
From: Bernhard Kaindl @ 2026-06-03 15:29 UTC (permalink / raw)
To: Jan Beulich; +Cc: xen-devel@lists.xenproject.org
> ... is it really "need to"? I'd suggest simply dropping "we need to". Also
> unless there's really a good reason, comments better wouldn't end in colons.
> Can make adjustments while committing, as long as you agree.
Of course, correct!
Bernhard
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] tools/tests/native: Add test for offlined buddy head PFN_ORDER
2026-06-03 15:11 [PATCH v2 0/2] xen/mm: Reset PFN_ORDER for offlined buddy heads Bernhard Kaindl
2026-06-03 15:11 ` [PATCH v2 1/2] xen/mm: reset " Bernhard Kaindl
@ 2026-06-03 15:11 ` Bernhard Kaindl
1 sibling, 0 replies; 5+ messages in thread
From: Bernhard Kaindl @ 2026-06-03 15:11 UTC (permalink / raw)
To: xen-devel; +Cc: Bernhard Kaindl, Anthony PERARD
Add a regression test to check that the PFN_ORDER(pg) of buddy heads
is reset to 0 when they become offline single pages which have been
moved of the offlined page lists.
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@citrix.com>
---
tools/tests/native/offline-head-order.c | 74 +++++++++++++++++++++++++
1 file changed, 74 insertions(+)
create mode 100644 tools/tests/native/offline-head-order.c
diff --git a/tools/tests/native/offline-head-order.c b/tools/tests/native/offline-head-order.c
new file mode 100644
index 000000000000..20c4f36526c1
--- /dev/null
+++ b/tools/tests/native/offline-head-order.c
@@ -0,0 +1,74 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Tests using offline_page() to verify reserve_offlined_page()
+ *
+ * The workflow tested here is offlining a free page:
+ *
+ * 1. offline_page() calls mark_page_offlined() to mark the page.
+ * 2. It calls reserve_heap_page() to find the containing buddy.
+ * 3. It calls reserve_offlined_page() to reserve the marked pages within
+ * that buddy.
+ *
+ * reserve_offlined_page() then:
+ *
+ * 1. Removes the buddy, a 2^order group of pages, from the free list.
+ * 2. Finds size-aligned spans of healthy pages within it.
+ * 3. Rebuilds healthy buddies from those spans and
+ * adds them back to the free list via page_list_add_scrub().
+ * 4. Moves offlined subpages to the offlined page lists.
+ *
+ * Copyright (C) 2026 Cloud Software Group
+ */
+#define CONFIG_SYSCTL
+#include "harness/native.h"
+
+static void test_offline_head_order(int start_mfn)
+{
+ struct page_info *page = frame_table + start_mfn;
+ uint32_t status = 0;
+
+ /* Seed a single order-1 buddy onto the heap. */
+ test_page_list_add_buddy(page, order1);
+ ASSERT(PFN_ORDER(page) == 1);
+ /* Offline the head page. */
+ ASSERT(offline_page(page_to_mfn(page), 0, &status) == 0);
+ ASSERT(status == PG_OFFLINE_OFFLINED);
+
+ /* Check the order of the offlined head page. */
+ ASSERT(PFN_ORDER(page) == 0);
+
+ /*
+ * Allocate the successor page of the offlined page. This prevents
+ * the normal successor page merge when the page is re-onlined below.
+ */
+ struct page_info *pg = alloc_domheap_pages(dom1, order0, 0);
+ ASSERT(pg == page + 1);
+ ASSERT(FREE_PAGES == 0);
+
+ /* Online the offlined former head page. */
+ ASSERT(online_page(page_to_mfn(page), &status) == 0);
+ ASSERT(status & PG_ONLINE_ONLINED);
+ ASSERT(FREE_PAGES == 1);
+
+ /*
+ * Confirm the order of the onlined former head page is 0, independently
+ * of the order returned by PFN_ORDER() for the offlined page. This should
+ * always be successful because page_offlined_list only contains single
+ * pages and online_page() ignores PFN_ORDER(pg) of the page. It calls
+ * free_heap_pages() passing the order hardcoded to 0. This causes it to
+ * pass the given order 0 to page_list_add_scrub(). This causes it to set
+ * the order of the page to 0 before it adds the page to the free list.
+ */
+ ASSERT(PFN_ORDER(page) == 0);
+}
+
+int main(int argc, char *argv[])
+{
+ const char *topic = "Test offlined head page to be updated to PFN_ORDER 0";
+ if ( !parse_args(argc, argv, topic) )
+ return EXIT_FAILURE;
+
+ init_page_alloc_tests();
+ RUN_TESTCASE("TOHP", test_offline_head_order, 2);
+ return test_complete();
+}
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-06-03 15:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03 15:11 [PATCH v2 0/2] xen/mm: Reset PFN_ORDER for offlined buddy heads Bernhard Kaindl
2026-06-03 15:11 ` [PATCH v2 1/2] xen/mm: reset " Bernhard Kaindl
2026-06-03 15:25 ` Jan Beulich
2026-06-03 15:29 ` Bernhard Kaindl
2026-06-03 15:11 ` [PATCH v2 2/2] tools/tests/native: Add test for offlined buddy head PFN_ORDER Bernhard Kaindl
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.