Skip to content

xen/mm: Fix off-by-one for tail merge in reserve_offlined_page()

Bernhard Kaindl xen-devel 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 3 repliesIn review
  2. v12 patches 2 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2xen/mm: Fix off-by-one preventing tail merge in reserve_offlined_page()xen/common/page_alloc.c+3 -13 replies
2/2tools/tests: Add regression test for tail buddy growthtools/tests/native/offline-merge-tail.c+81 -00 replies

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchJan BeulichOleksii Kurochko
1/2R-b Release-Acked-by Release-Acked-by
2/2

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/2] xen/mm: Fix off-by-one for tail merge in reserve_offlined_page()

After offlining pages, reserve_offlined_page() attempts to grow larger buddies between the offlined pages, but due to an off-by-one, this fails at the tail end of the span of pages of the containing buddy.

As requested for backporting the fix, the first patch fixes the issue while the second patch adds the regression test for it.

Consider an order-2 buddy (4 pages) with the following layout:

+---------------+---------------+---------------+---------------+
| head page       tail page 1,    tail page 2     tail page 3   |
| PFN_ORDER(pg)   marked as to                                  |
| == 2            be offlined                                   |
+---------------+---------------+---------------+---------------+

The expected result after removing tail page 1 and returning the remaining healthy pages to the free list would be:

+---------------+               +---------------+---------------+
| single page   | offlined page | head page       tail page     |
| PFN_ORDER(pg) | not returned  | PFN_ORDER(pg)                 |
| == 0          | to the heap   | == 1                          |
+---------------+               +---------------+---------------+

A trivial off-by-one error in the growth loop stops the growth loop early before the tail end of the original buddy and we end up with:

+---------------+               +---------------+---------------+
| single page   | offlined page | single page   | single page   |
| PFN_ORDER(pg) | not returned  | PFN_ORDER(pg) | PFN_ORDER(pg) |
| == 0          | to the heap   | == 0          | == 0          |
+---------------+               +---------------+---------------+

You can pull this series with the regression test environment to run it:

$ git pull [email protected]:bernhardkaindl/xen.git offline-merge-tail-v2
$ make -C tools/tests/native TARGETS=offline-merge-tail test
Fixes e4865c2315 ('Page offline support in Xen side')

Bernhard Kaindl (2):
xen/mm: Fix off-by-one preventing tail merge in
reserve_offlined_page()
tools/tests: Add regression test for tail buddy growth

 tools/tests/native/offline-merge-tail.c | 81 +++++++++++++++++++++++++
 xen/common/page_alloc.c                 |  4 +-
 2 files changed, 84 insertions(+), 1 deletion(-)
 create mode 100644 tools/tests/native/offline-merge-tail.c
Signature · 1 line
2.39.5