From 94fa7e1626fd755a4cf70904ca463ed068eea6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Mon, 20 Jul 2026 13:29:16 +0200 Subject: [PATCH] xen/numa: fix setup of non-aligned memory affinity ranges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The logic to populate memnodemap in populate_memnodemap() assumes that all ranges are aligned to the hash shift, this however is only true for the first address in a memory affinity node. Any subsequent ranges belonging to the same node might not be aligned to the hash shift value. Such lack of alignment causes issues to the logic in populate_memnodemap(), as then the tail of the range might not be properly accounted for and setup in memnodemap. Fix this by forcing the start address of all regions to be aligned to the hash shift; if such alignment causes a region overlap it would always be between regions on the same node, and hence will never cause setup issues of the memnodemap array. Fixes: 1666086b0044 ("x86/NUMA: improve memnode_shift calculation for multi node system") Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich Reviewed-by: Andrew Cooper master commit: 188d5305297f4e842511d1374c7121ac8a37c169 master date: 2026-06-05 19:13:47 +0200 --- xen/common/numa.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xen/common/numa.c b/xen/common/numa.c index ad75955a16..e2c89bf55b 100644 --- a/xen/common/numa.c +++ b/xen/common/numa.c @@ -403,6 +403,12 @@ static int __init populate_memnodemap(const struct node *nodes, if ( (epdx >> shift) >= memnodemapsize ) return 0; + /* + * Round down start address: if start is not aligned to the memnodemap + * chunk size the tail remainder might not be added. Overlaps created + * by rounding will fall into the same NUMA region. + */ + spdx = ROUNDDOWN(spdx, 1UL << shift); do { if ( memnodemap[spdx >> shift] != NUMA_NO_NODE && (!nodeids || memnodemap[spdx >> shift] != nodeids[i]) )