From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D648606A322 for ; Thu, 3 Dec 2026 15:20:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eq4LnWZ/ Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 35C0C11299A; Thu, 3 Dec 2026 15:20:16 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 762A111299A for ; Thu, 3 Dec 2026 15:20:09 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 9BA6A60AA2; Thu, 3 Dec 2026 15:20:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 368201F0089A; Thu, 3 Dec 2026 15:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796311208; bh=WZyyaOB82Zld2wgiWGkhWVoBMXi0GLGY8iDPhJk4mGE=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=eq4LnWZ/hIyfvyacHjxnn01nq9JPlM9vwLPzh+neMWn8CSKCLOakQDgKpB+E8ULRf YoIzd2T4ITtnR+244fE62esOnxHRTyMxGcW6gYPU7veo4ydpf751kcoxzBA2Ux4kvc 8RfjeJ1vn+utJoVbhEqz8dkVg14/yOqWdttK88Gtr/xWcmDYYBqoje2Qshxoz4mAag 0Kx6iJM43uLBzusFtv5eBpdyc33y4wkHNiwwFs9j8iPgPakeJKNFxtbFric2gYQ/DZ 6iWZm9cW1di/IE0CdEt8fEaTx4LfQPlHBs5nGnmOP0/cfxRDvfv4XmEWmtFc8M4rEx vDRZ4BojZPhZQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] drm/amdgpu: add AMDGPU_INFO_CU_BITMAP query for per-XCC CU masks To: "Siwei He" , amd-gfx@lists.freedesktop.org In-Reply-To: <20261203145332.802558-1-siwei.he@amd.com> References: <20261203145332.802558-1-siwei.he@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 15:20:07 +0000 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "amd-gfx" X-Spam-Status: No, score=-20.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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 > 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 [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/am= d/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 =3D=3D BIT(8), this lo= gs "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/am= d/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 =3D (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 =3D &adev->xcp_mgr->xcp[fpriv->xcp_id]; > + ret =3D 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 =3D false fpriv->xcp_id < num_xcps amdgpu_xcp_get_inst_details() if (!xcp->valid) <-- -EINVAL __amdgpu_xcp_add_block(GFXHUB) xcp->valid =3D true __amdgpu_xcp_add_block(GFX) num_xcps =3D 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 =3D 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 =3D=3D AMDGPU_XCP_NO_PARTITION separately from an out-of-range partition index would preserve the partition-scoping contract. [ ... ] > + ret =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203145332.8025= 58-1-siwei.he@amd.com?part=3D1