[PATCH 2/2] x86/amd_node: Avoid divide by zero on virtualized systems
From: Jason Andryuk
Date: Thu Aug 06 2026 - 12:05:24 EST
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)
On a virtualized system, default the value to 1. The issue is seen with
Xen, but it could affect other systems.
Fixes: 0a4b61d9c2e4 ("x86/amd_node: Fix AMD root device caching")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jason Andryuk <jason.andryuk@xxxxxxx>
---
X86_FEATURE_XENPV is only for PV, but this is observed with a PVH dom0.
---
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 ea553267e5fa..c5025e5291b6 100644
--- a/arch/x86/kernel/amd_node.c
+++ b/arch/x86/kernel/amd_node.c
@@ -286,6 +286,11 @@ static int __init amd_smn_init(void)
return -ENOMEM;
roots_per_node = num_roots / num_nodes;
+ if (roots_per_node == 0) {
+ if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
+ pr_err(FW_BUG "Error detecting roots per node.\n");
+ roots_per_node = 1;
+ }
count = 0;
node = 0;
--
2.55.0