xen/pdx: fix merging of a range contained in the previous one
PATCH 1/1 xen/pdx: fix merging of a range contained in the previous one
From: Weiqi Wang <[email protected]>
When sorting and merging overlapping ranges in pfn_pdx_compression_setup(), the merged range is set to end where the second range ends. If the second range is fully contained in the first, this truncates the first range, and the tail of it is then neither compressible nor translated correctly.
Keep the end of the merged range as the maximum of both ends.
On x86 the ranges come from the SRAT memory affinity entries, and overlapping entries for the same node are tolerated with a warning by the NUMA code. The caller's subsequent coverage check catches the truncated range, so the effect is that PDX compression is disabled with a "RAM region ... not covered" message rather than memory being mistranslated.
Add a test case that fails without this change.
Found with the ESBMC bounded model checker. The counterexample was confirmed by running it natively against the unmodified code.
---
Notes:
Also seen in a real boot: the hypervisor alone under QEMU (pc, 8 GiB),
built from defconfig, with no -numa and a hand-built SRAT passed with
-acpitable. Memory affinity entries, all PXM 0:
[0, 3G) [4G, 9G) [5G, 6G) [1T, 1T+1G)
The third entry lies inside the second. The NUMA code prints "overlaps
with itself" for it and accepts it. Without this patch:
(XEN) PFN compression using lookup table shift 23 and region size 0x200000
(XEN) range 0 [0000000000000, 000000017ffff] PFN IDX 0 : 0000000000000
(XEN) range 1 [0000010000000, 000001003ffff] PFN IDX 32 : 000000fe00000
(XEN) PFN compression disabled, RAM region [0x100000000, 0x23fffffff] not covered
With it, the same output as without the third entry:
(XEN) PFN compression using lookup table shift 28 and region size 0x400000
(XEN) range 0 [0000000000000, 000000023ffff] PFN IDX 0 : 0000000000000
(XEN) range 1 [0000010000000, 000001003ffff] PFN IDX 1 : 000000fc00000tools/tests/pdx/test-pdx.c | 12 ++++++++++++ xen/common/pdx.c | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-)
tools/tests/pdx/test-pdx.c +12 -0
@@ -87,6 +87,18 @@ int main(int argc, char **argv) }, .compress = true, }, + /* Range contained in a previous one. */ + { + .ranges = { + { .start = 0, + .end = (1UL << MAX_ORDER) * 1 }, + { .start = (1UL << (MAX_ORDER * 2)) | 0, + .end = (1UL << (MAX_ORDER * 2)) | (1UL << MAX_ORDER) * 4 }, + { .start = (1UL << (MAX_ORDER * 2)) | (1UL << MAX_ORDER) * 1, + .end = (1UL << (MAX_ORDER * 2)) | (1UL << MAX_ORDER) * 2 }, + }, + .compress = true, + }, #endif /* PDX compression, 2 ranges covered by the lower mask. */ {
xen/common/pdx.c +3 -2
@@ -393,8 +393,9 @@ bool __init pfn_pdx_compression_setup(paddr_t base) (ranges[i - 1].base_pfn + ranges[i - 1].pages) )continue ; - ranges[i -1 ].pages = ranges[i].base_pfn + ranges[i].pages - - ranges[i -1 ].base_pfn; + ranges[i -1 ].pages =max (ranges[i -1 ].pages, + ranges[i].base_pfn + ranges[i].pages - + ranges[i -1 ].base_pfn);if ( i +1 < nr_ranges ) memmove(&ranges[i], &ranges[i + 1],
Signature · 1 line
2.34.1
Quoted 4 lines · Weiqi Wang
From: Weiqi Wang <[email protected]>
When sorting and merging overlapping ranges in
pfn_pdx_compression_setup(),
As we have two distinct instances of this function, at least one of title or description want to clarify that it's the offset-compression one.
Quoted 5 lines
tools/tests/pdx/test-pdx.c +0
-0@@ -87,6 +87,18 @@ int main(int argc, char **argv) }, .compress = true,
tools/tests/pdx/test-pdx.c int main(int argc, char **argv) · line 98
Quoted 10 lines
tools/tests/pdx/test-pdx.c +9
-0}, +/* Range contained in a previous one. */ + { + .ranges = { + { .start = 0, + .end = (1UL << MAX_ORDER) * 1 }, + { .start = (1UL << (MAX_ORDER * 2)) | 0, + .end = (1UL << (MAX_ORDER * 2)) | (1UL << MAX_ORDER) * 4 }, + { .start = (1UL << (MAX_ORDER * 2)) | (1UL << MAX_ORDER) * 1, + .end = (1UL << (MAX_ORDER * 2)) | (1UL << MAX_ORDER) * 2 },
Nit: The multiplications also want parenthesizing against the binary ORs.
Jan