Re: [PATCH] x86: Avoid divide by 0 in amd_smn_init()

From: Borislav Petkov

Date: Tue Jun 23 2026 - 17:46:14 EST


On Tue, Jun 23, 2026 at 05:19:03PM -0400, Jason Andryuk wrote:
> Xen synthesizes the CPU topology, so the num_nodes and num_roots values
> may be surprising for amd_smn_init(). Specifically:
>
> roots_per_node = num_roots / num_nodes;
>
> may results in roots_per_node == 0 which leads to divide by zero in
>
> count % roots_per_node
>
> As an example, I have a system with a Xen PVH dom0 that reports:
> Found 1 AMD root devices
> Found 2 AMD nodes
>
> Ensure roots_per_node is at least 1 to avoid the divide by zero errors.
> num_nodes are allocated for amd_roots, so roots_per_node = 1 will
> populate all the entries.
>
> Also add a pr_debug() for the number of nodes.
>
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Jason Andryuk <jason.andryuk@xxxxxxx>
> ---
> This is an alternative to
> https://lore.kernel.org/xen-devel/20260506055528.476493-2-penny.zheng@xxxxxxx/
> but it leaves smn available for dom0.

Does this alternative work too?

https://lore.kernel.org/r/20260605230949.GBaiNXPZ2ztjVL7DBg@fat_crate.local

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette