[tip: x86/urgent] x86/amd_node: Avoid divide by zero on virtualized systems
From: tip-bot2 for Jason Andryuk
Date: Mon Aug 31 2026 - 14:32:00 EST
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 72bd92bd8190d7869ecb462649ca40f297822a33
Gitweb: https://git.kernel.org/tip/72bd92bd8190d7869ecb462649ca40f297822a33
Author: Jason Andryuk <jason.andryuk@xxxxxxx>
AuthorDate: Tue, 25 Aug 2026 17:48:02 -04:00
Committer: Borislav Petkov (AMD) <bp@xxxxxxxxx>
CommitterDate: Sun, 30 Aug 2026 18:25:42 -07:00
x86/amd_node: Avoid divide by zero on virtualized systems
On a virtualized system, the number of nodes does not have a relationship to
the number of roots. A Xen PVH dom0 can calculate roots_per_node as 0, which
crashes with a divide by zero in:
if (count++ % roots_per_node)
because the underlying topology code on Xen ends up making num_nodes
2 and num_roots 1 and the integer division result is 0.
The issue is seen with Xen, but it could affect other systems.
Set roots_per_node to 1 in this case. Print a firmware bug when this is
performed for non-virtualized systems.
[ bp: Massage commit message. ]
Fixes: 0a4b61d9c2e4 ("x86/amd_node: Fix AMD root device caching")
Suggested-by: Borislav Petkov <bp@xxxxxxxxx>
Signed-off-by: Jason Andryuk <jason.andryuk@xxxxxxx>
Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Reviewed-by: Yazen Ghannam <yazen.ghannam@xxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Link: https://patch.msgid.link/20260825214805.39148-2-jason.andryuk@xxxxxxx
---
arch/x86/kernel/amd_node.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/x86/kernel/amd_node.c b/arch/x86/kernel/amd_node.c
index 0be0172..408b9fd 100644
--- a/arch/x86/kernel/amd_node.c
+++ b/arch/x86/kernel/amd_node.c
@@ -287,6 +287,11 @@ static int __init amd_smn_init(void)
return -ENOMEM;
roots_per_node = num_roots / num_nodes;
+ if (!roots_per_node) {
+ if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
+ pr_warn(FW_BUG "Error detecting roots per node.\n");
+ roots_per_node = 1;
+ }
count = 0;
node = 0;