From: sashiko-bot@kernel.org
To: "Lin Wang" <wanglin@open-hieco.net>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v5 7/8] x86/amd_node: Restrict SMN setup to AMD CPUs
Date: Thu, 10 Sep 2026 08:43:49 +0000 [thread overview]
Message-ID: <20260910084350.1768A1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260910082734.3771675-8-wanglin@open-hieco.net>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The `amd_roots` array stores dangling pointers to PCI devices because their reference counts are incorrectly dropped during the iteration loop.
--
commit 263066910679f0796c85e4dd7d844bda35fa7403
Author: Lin Wang <wanglin@open-hieco.net>
x86/amd_node: Restrict SMN setup to AMD CPUs
amd_smn_init() divides host bridge roots among amd_num_nodes() entries
in PCI enumeration order. This restricts AMD SMN setup and root discovery
to AMD CPUs.
> diff --git a/arch/x86/kernel/amd_node.c b/arch/x86/kernel/amd_node.c
> index 762585775b5a2..a7190cec69954 100644
> --- a/arch/x86/kernel/amd_node.c
> +++ b/arch/x86/kernel/amd_node.c
> @@ -229,8 +229,7 @@ static struct pci_dev *get_next_root(struct pci_dev *root)
> if (root->devfn)
> continue;
>
> - if (root->vendor != PCI_VENDOR_ID_AMD &&
> - root->vendor != PCI_VENDOR_ID_HYGON)
> + if (root->vendor != PCI_VENDOR_ID_AMD)
> continue;
>
> break;
[Severity: High]
This isn't a bug introduced by this patch, but does the amd_roots array
store dangling pointers to PCI devices because their reference counts are
incorrectly dropped during the iteration loop?
This function delegates to pci_get_class(), which by design drops the
reference count of the device passed to it. In the second loop of
amd_smn_init(), a newly matched root device is stored into amd_roots
without acquiring an additional reference:
arch/x86/kernel/amd_node.c:amd_smn_init() {
...
while (node < num_nodes && (root = get_next_root(root))) {
/* Use one root for each node and skip the rest. */
if (count++ % roots_per_node)
continue;
pci_dbg(root, "is root for AMD node %u\n", node);
amd_roots[node++] = root;
}
...
}
In the next iteration, the loop condition root = get_next_root(root) passes
that same root back to pci_get_class(), immediately decrementing its
reference count. This leaves the amd_roots array populated with dangling
pointers.
Conversely, the reference count of the very last device retrieved is leaked
because the loop terminates when node < num_nodes fails before it can be
passed back into get_next_root().
While host bridges are typically not hot-removable in this architecture, could
this be a structural use-after-free and reference leak?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260910082734.3771675-1-wanglin@open-hieco.net?part=7
next prev parent reply other threads:[~2026-09-10 8:43 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 8:27 [PATCH v5 0/8] x86/hygon: Add Family 0x18 DF node enumeration and SMN access Lin Wang
2026-09-10 8:27 ` [PATCH v5 1/8] x86/hygon: Add Family 0x18 DF node enumeration Lin Wang
2026-09-10 8:32 ` sashiko-bot
2026-09-10 8:27 ` [PATCH v5 2/8] x86/hygon: Map CPU NodeIds to DF nodes Lin Wang
2026-09-10 8:32 ` sashiko-bot
2026-09-10 8:27 ` [PATCH v5 3/8] EDAC/amd64: Stop matching Hygon CPUs Lin Wang
2026-09-10 8:33 ` sashiko-bot
2026-09-10 8:27 ` [PATCH v5 4/8] RAS/AMD/ATL: Match AMD CPUs only Lin Wang
2026-09-10 8:34 ` sashiko-bot
2026-09-10 8:27 ` [PATCH v5 5/8] hwmon: (k10temp) Stop matching Hygon devices Lin Wang
2026-09-10 8:36 ` sashiko-bot
2026-09-11 0:52 ` Guenter Roeck
2026-09-11 1:10 ` Lin Wang
2026-09-10 8:27 ` [PATCH v5 6/8] x86/amd_nb: Restrict the northbridge framework to AMD CPUs Lin Wang
2026-09-10 8:37 ` sashiko-bot
2026-09-10 8:27 ` [PATCH v5 7/8] x86/amd_node: Restrict SMN setup " Lin Wang
2026-09-10 8:43 ` sashiko-bot [this message]
2026-09-10 8:27 ` [PATCH v5 8/8] x86/hygon: Add Family 0x18 SMN access Lin Wang
2026-09-10 8:38 ` sashiko-bot
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=20260910084350.1768A1F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wanglin@open-hieco.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.