mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yazen Ghannam <yazen.ghannam@amd.com>
To: Steven Noonan <steven@uplinklabs.net>
Cc: linux-kernel@vger.kernel.org,
	Ariadne Conill <ariadne@ariadne.space>,
	x86@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/2] x86/amd_node: fix integer divide by zero during init
Date: Wed, 3 Dec 2025 15:45:19 -0500	[thread overview]
Message-ID: <20251203204519.GA741246@yaz-khff2.amd.com> (raw)
In-Reply-To: <20251114195730.1503879-1-steven@uplinklabs.net>

On Fri, Nov 14, 2025 at 07:57:35PM +0000, Steven Noonan wrote:

Thanks Steven for the patch.

> On a Xen dom0 boot, this feature does not behave, and we end up
> calculating:
> 
>     num_roots = 1
>     num_nodes = 2
>     roots_per_node = 0
> 
> This causes a divide-by-zero in the modulus inside the loop.

Can you please share more details of the system topology?

I think the list of PCI devices is a good start.

> 
> This change adds a couple of guards for invalid states where we might
> get a divide-by-zero.

This statement should be imperative, ex. "Add a couple of guards...".

Also, the commit message should generally be in a passive voice (no
"we"), ex. "...where a divide-by-zero may result."

> 
> Signed-off-by: Steven Noonan <steven@uplinklabs.net>
> Signed-off-by: Ariadne Conill <ariadne@ariadne.space>

The Signed-off-by lines should be in the order of handling. If you are
sending the patch, then your line should be last. If there are other
contributors, then they should have a Co-developed-by tag in addition to
Signed-off-by.

> CC: Yazen Ghannam <yazen.ghannam@amd.com>
> CC: x86@vger.kernel.org
> CC: stable@vger.kernel.org

There should be a Fixes tag along with "Cc: stable", if possible.

> ---
>  arch/x86/kernel/amd_node.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/arch/x86/kernel/amd_node.c b/arch/x86/kernel/amd_node.c
> index 3d0a4768d603c..cdc6ba224d4ad 100644
> --- a/arch/x86/kernel/amd_node.c
> +++ b/arch/x86/kernel/amd_node.c
> @@ -282,6 +282,17 @@ static int __init amd_smn_init(void)
>  		return -ENODEV;
>  
>  	num_nodes = amd_num_nodes();
> +
> +	if (!num_nodes)
> +		return -ENODEV;

This is generally a good check. But I think it is unnecessary in this
case, since the minimum value is '1'. The topology init code initializes
the factors used in amd_num_nodes() to '1' before trying to find the
true values from CPUID, etc.

> +
> +	/* Possibly a virtualized environment (e.g. Xen) where we wi

Multi-line comments should start on the next line according to kernel
coding style.

	/*
	 * Comment
	 * Info
	 */

> ll get
> +	 * roots_per_node=0 if the number of roots is fewer than number of
> +	 * nodes
> +	 */
> +	if (num_roots < num_nodes)
> +		return -ENODEV;

I think this is a fair check. But I'd like to understand how the
topology looks in this case.

Thanks,
Yazen

  parent reply	other threads:[~2025-12-03 20:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-14 19:57 Steven Noonan
2025-11-14 19:57 ` [PATCH 2/2] x86/amd_node: fix null pointer dereference if amd_smn_init failed Steven Noonan
2025-12-03 20:54   ` Yazen Ghannam
2025-12-03 20:45 ` Yazen Ghannam [this message]
2025-12-04 20:16   ` [PATCH 1/2] x86/amd_node: fix integer divide by zero during init Steven Noonan
2025-12-05 15:37     ` Yazen Ghannam
2025-12-03 21:18 ` Borislav Petkov
2025-12-04 16:45   ` Yazen Ghannam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251203204519.GA741246@yaz-khff2.amd.com \
    --to=yazen.ghannam@amd.com \
    --cc=ariadne@ariadne.space \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=steven@uplinklabs.net \
    --cc=x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®