From: sashiko-bot@kernel.org
To: "Siwei He" <siwei.he@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: add AMDGPU_INFO_CU_BITMAP query for per-XCC CU masks
Date: Thu, 03 Dec 2026 15:20:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-248096@kernel.org> (raw)
In-Reply-To: <20261203145332.802558-1-siwei.he@amd.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] drm/amdgpu: unlocked xcp_mgr and xcp_id read in
amdgpu_info_ioctl()
- [Medium] drm/amdgpu: stale partition fd exposes all XCCs in
amdgpu_info_ioctl()
- [Medium] drm/amdgpu: unsynchronized cu_info.bitmap read in
AMDGPU_INFO_CU_BITMAP
- [Low] drm/amdgpu: misleading XCC count logged in
amdgpu_gfx_get_cu_bitmap()
- [Low] drm/amdgpu: commit message lacks rationale for
AMDGPU_INFO_CU_BITMAP
--
commit 820593577ceaf63f676ad746f421ebe4e32b41a4
Author: Siwei He <siwei.he@amd.com>
> drm/amdgpu: add AMDGPU_INFO_CU_BITMAP query for per-XCC CU masks
>
> Add AMDGPU_INFO_CU_BITMAP, returning struct drm_amdgpu_info_cu_bitmap:
> a header carrying num_xcc, num_se, num_sa and xcc_mask, followed by a
> flexible array of num_xcc * num_se * num_sa active CU masks in un-folded
> [xcc][se][sa] order, indexed bitmap[(xcc * num_se + se) * num_sa + sa].
>
> Userspace for this can be found at:
> https://github.com/ROCm/rocm-systems/pull/14570
>
> Signed-off-by: Siwei He <siwei.he@amd.com>
[Severity: Low]
Could the commit message explain why a new permanent UAPI query is needed
instead of relying on the external PR link?
Briefly stating the limits of AMDGPU_INFO_DEV_INFO (its cu_bitmap[4][4]
array only covers XCC 0, folds >4 SEs with ASIC-specific packing, and
cannot report per-XCC or XCP-partition-scoped masks) would make the
rationale self-contained in git history.
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
> index 0ae6e990c3102..850de3be16599 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
[ ... ]
> +int amdgpu_gfx_get_cu_bitmap(struct amdgpu_device *adev, u32 inst_mask,
> + u32 *out, u32 max_entries)
> +{
[ ... ]
> + /* cu_info.bitmap[] only has AMDGPU_MAX_GC_INSTANCES slots */
> + if (inst_mask & ~GENMASK(AMDGPU_MAX_GC_INSTANCES - 1, 0)) {
> + dev_warn_once(adev->dev,
> + "CU bitmap: %u XCCs exceeds %u slots\n",
> + hweight32(inst_mask), AMDGPU_MAX_GC_INSTANCES);
> + return -EOPNOTSUPP;
> + }
[Severity: Low]
Does this warning print the wrong value when a single-XCC partition sits
above AMDGPU_MAX_GC_INSTANCES?
The check rejects any set bit at or above AMDGPU_MAX_GC_INSTANCES, but
hweight32(inst_mask) counts set bits. For inst_mask == BIT(8), this logs
"CU bitmap: 1 XCCs exceeds 8 slots". Logging fls(inst_mask) or the mask
itself would match the condition being checked.
[ ... ]
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index d442a2d963945..05b0702ac59cc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -1452,6 +1452,57 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
[ ... ]
> + case AMDGPU_INFO_CU_BITMAP: {
> + struct drm_amdgpu_info_cu_bitmap *cu_bitmap;
> + u32 num_xcc, num_se, num_sa, nent;
> + size_t sz;
> +
> + fpriv = (struct amdgpu_fpriv *)filp->driver_priv;
> +
> + /* scope the reply to the partition this fd was opened against */
> + if (adev->xcp_mgr && adev->xcp_mgr->num_xcps > 0 &&
> + fpriv->xcp_id < adev->xcp_mgr->num_xcps) {
> + xcp = &adev->xcp_mgr->xcp[fpriv->xcp_id];
> + ret = amdgpu_xcp_get_inst_details(xcp, AMDGPU_XCP_GFX,
> + &inst_mask);
> + if (ret)
> + return ret;
[Severity: Medium]
Can this race with a concurrent partition switch or fpriv->xcp_id
assignment because adev->xcp_mgr->xcp_lock is not held?
CPU0 CPU1
amdgpu_info_ioctl() amdgpu_gfx_set_compute_partition()
mutex_lock(&xcp_mgr->xcp_lock)
amdgpu_xcp_init()
xcp[i].valid = false
fpriv->xcp_id < num_xcps
amdgpu_xcp_get_inst_details()
if (!xcp->valid) <-- -EINVAL
__amdgpu_xcp_add_block(GFXHUB)
xcp->valid = true
__amdgpu_xcp_add_block(GFX)
num_xcps = new_num
mutex_unlock(&xcp_mgr->xcp_lock)
Because __amdgpu_xcp_add_block() sets xcp->valid on AMDGPU_XCP_GFXHUB
before updating AMDGPU_XCP_GFX, an unlocked reader can also see a stale
inst_mask. On a shared primary-node fd, amdgpu_xcp_select_scheds() also
steps fpriv->xcp_id through intermediate values under xcp_lock.
Acquiring adev->xcp_mgr->xcp_lock across the fpriv->xcp_id, num_xcps, and
amdgpu_xcp_get_inst_details() reads and releasing it before kzalloc()
would avoid the race.
> + } else {
> + /* inst_mask is a logical mask */
> + inst_mask = adev->gfx.xcc_mask ?
> + GENMASK(NUM_XCC(adev->gfx.xcc_mask) - 1, 0) : 1;
> + }
[Severity: Medium]
Does falling into the else branch expose every XCC on the device to a
stale partition fd?
amdgpu_xcp_open_device() sets fpriv->xcp_id to the partition index for a
partition render node and AMDGPU_XCP_NO_PARTITION otherwise. If a sysfs
mode switch (such as CPX to SPX) reduces num_xcps below fpriv->xcp_id,
this falls into the else branch and returns all XCCs instead of -ENODEV.
Checking fpriv->xcp_id == AMDGPU_XCP_NO_PARTITION separately from an
out-of-range partition index would preserve the partition-scoping
contract.
[ ... ]
> + ret = amdgpu_gfx_get_cu_bitmap(adev, inst_mask,
> + cu_bitmap->bitmap, nent);
[Severity: Medium]
Can amdgpu_gfx_get_cu_bitmap() read a zeroed or partially populated
cu_info.bitmap during runtime resume or GPU reset on GFX6-8?
CPU0 CPU1
amdgpu_info_ioctl() amdgpu_pmops_runtime_resume()
...
gfx_v8_0_get_cu_info()
memset(cu_info, 0, ...)
amdgpu_gfx_get_cu_bitmap()
reads cu_info.bitmap <-- all-zero or partial mask
repopulates cu_info->bitmap via MMIO
Because amdgpu_driver_open_kms() drops its runtime PM reference on open
and AMDGPU_INFO_CU_BITMAP neither acquires runtime PM nor takes
adev->reset_domain->sem, it can overlap gfx_v{6,7,8}_0_get_cu_info() and
return 0 with zeroed CU masks.
Acquiring runtime PM (PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND) and
down_read(&adev->reset_domain->sem), as AMDGPU_INFO_READ_MMR_REG does,
would serialize against both paths.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203145332.802558-1-siwei.he@amd.com?part=1
next prev parent reply other threads:[~2026-12-03 15:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 14:53 [PATCH] drm/amdgpu: add AMDGPU_INFO_CU_BITMAP query for per-XCC CU masks Siwei He
2026-12-03 15:20 ` sashiko-bot [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-10-22 16:18 Siwei He
2026-10-26 18:37 ` Alex Deucher
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=sashiko-outbox-248096@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=siwei.he@amd.com \
/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