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 519D4606A330 for ; Thu, 3 Dec 2026 19:05:38 +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=iwApwCjT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E209C10EB15; Thu, 3 Dec 2026 19:05:32 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8A03510EB15 for ; Thu, 3 Dec 2026 19:05:26 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id F3B9045080; Thu, 3 Dec 2026 19:05:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 518E31F000CE; Thu, 3 Dec 2026 19:05:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796324724; bh=72BxwiTs7RMdCOKmoBxXxZbWqW19wBjHQQ0wcl823RQ=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=iwApwCjTZXGkVaTpaPO+oc6k7wrhcS51sgmx9Fops9lV2M1GauJk3xVnEuRPtYp8t MdDihXdLxvcKQqmziOs4erQRjYSvGkKt2uUCLHGCiF4A3PgOoazWrbEg9yBuznuSKa M3cEK9BPDU6T2Xb0UVSUMVb9YvCHpl/OBCxArlo+oNyYnT6hdNGk36P19s4Z6h21Tl Eq4wZa3daVEXKgC6Kmm6awxRaFzZWoP7ydXCc1dWk7Ko1bADTOlC1ExVDCDL9GT5BV hZKI+KSp6GqYnzu/6TBXTIUhKUjTy2W/1FyXpzUaWAP+Y21a5FCw3KNYkqsafWj0bA AXLKa5Wpo1ACQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/2] drm/amdgpu: implement IOCTL specific skip resume list To: "Shahyan Soltani" , amd-gfx@lists.freedesktop.org In-Reply-To: <20261203175200.1774878-2-shahyan.soltani@amd.com> References: <20261203175200.1774878-1-shahyan.soltani@amd.com> <20261203175200.1774878-2-shahyan.soltani@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 19:05:24 +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=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,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 9 potential issues to consider: - [High] drm/amdgpu: missing runtime PM resume for DRM_IOCTL_AMDGPU_VM - [High] drm/amdgpu: missing runtime PM resume for DRM_IOCTL_AMDGPU_CTX free path - [High] drm/amdgpu: amdgpu_kms_compat_ioctl() breaks 32-bit x86 DRM_IOCTL_MODE_ADDFB2 - [Medium] drm/amdgpu: spurious runtime resume on non-DRM ioctls and unplugged devices - [Medium] drm/amdgpu: DRM_IOCTL_AMDGPU_UALINK_HANDLE skips runtime PM resume - [Medium] drm/amdgpu: amdgpu_ioctls_skip_resume[] omits syncobj and cap IOCTLs - [Low] drm/amdgpu: invalid kernel-doc syntax on amdgpu_ioctls_skip_resume[] - [Low] drm/amdgpu: unnecessary external linkage for amdgpu_drm_ioctl() and macro - [Low] drm/amdgpu: missing array_index_nospec() in amdgpu_ioctls_skip_resume[] lookup -- commit d5dc7cf8e3ca9fa610a736900cd13686834c705d Author: Shahyan Soltani drm/amdgpu: implement IOCTL specific skip resume list This patch introduces amdgpu_ioctls_skip_resume[] so amdgpu_drm_ioctl() and amdgpu_kms_compat_ioctl() only acquire a runtime PM reference for ioctls not on the list, and moves amdgpu_kms_compat_ioctl() into amdgpu_drv.c. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/am= d/amdgpu/amdgpu_drv.c > index 11c782a4914ed..0b1359c5125df 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > @@ -3041,25 +3041,105 @@ static int amdgpu_drm_release(struct inode *inod= e, struct file *filp) > return drm_release(inode, filp); > } > =20 > +/** > + * amdgpu_ioctls_skip_resume[] - List of IOCTLs that do not require hard= ware access. [Severity: Low] Will this /** comment trigger a kernel-doc warning during make htmldocs and W=3D1 builds? Documentation/gpu/amdgpu/module-parameters.rst runs kernel-doc over amdgpu_drv.c, and the trailing [] without a kernel-doc keyword is rejected. Since amdgpu_ioctls_skip_resume[] is a static table, a regular /* comment avoids the warning. [ ... ] > +static const bool amdgpu_ioctls_skip_resume[] =3D { > + /* DRM IOCTLs */ > + AMDGPU_IOCTL_SKIP_RESUME(DRM_IOCTL_VERSION), > + AMDGPU_IOCTL_SKIP_RESUME(DRM_IOCTL_GET_CLIENT), > + AMDGPU_IOCTL_SKIP_RESUME(DRM_IOCTL_MODE_GETPROPERTY), > + AMDGPU_IOCTL_SKIP_RESUME(DRM_IOCTL_MODE_GETRESOURCES), > + AMDGPU_IOCTL_SKIP_RESUME(DRM_IOCTL_MODE_LIST_LESSEES), > + AMDGPU_IOCTL_SKIP_RESUME(DRM_IOCTL_MODE_GETPLANE), > + AMDGPU_IOCTL_SKIP_RESUME(DRM_IOCTL_MODE_OBJ_GETPROPERTIES), > + AMDGPU_IOCTL_SKIP_RESUME(DRM_IOCTL_MODE_GETPROPBLOB), [Severity: Medium] Should the software-only DRM_IOCTL_SYNCOBJ_* ioctls along with DRM_IOCTL_GET_CAP, DRM_IOCTL_SET_CLIENT_CAP, and DRM_IOCTL_SET_CLIENT_NAME also be on this list? Leaving them out means every syncobj ioctl takes dev->power.lock in __pm_runtime_resume() and wakes a suspended GPU, while blocking waits in drm_syncobj_array_wait_timeout() hold a runtime PM reference for the entire wait and prevent autosuspend. Similarly, DRM_IOCTL_GET_CAP during client probing wakes a suspended GPU even though drm_getcap() only reads in-memory state. > + /* AMDGPU IOCTLs */ > + AMDGPU_IOCTL_SKIP_RESUME(DRM_IOCTL_AMDGPU_GEM_CREATE), > + AMDGPU_IOCTL_SKIP_RESUME(DRM_IOCTL_AMDGPU_CTX), [Severity: High] Can skipping runtime resume for DRM_IOCTL_AMDGPU_CTX cause amdgpu_ctx_fini() to access SMU and CG/PG hardware while the GPU is suspended? amdgpu_ctx_stable_pstate() drops its runtime PM reference immediately after assigning adev->pm.stable_pstate_ctx =3D ctx, so the GPU can autosuspend while that context is still alive. A subsequent AMDGPU_CTX_OP_FREE_CTX then runs amdgpu_ctx_fini() -> __amdgpu_ctx_set_stable_pstate() -> amdgpu_dpm_force_performance_level() without holding a runtime PM reference, risking SMU timeouts or GPU hangs. > + AMDGPU_IOCTL_SKIP_RESUME(DRM_IOCTL_AMDGPU_VM), [Severity: High] Does skipping runtime resume for DRM_IOCTL_AMDGPU_VM allow direct GFXHUB MMIO writes and TLB flushes against a suspended GPU? Neither amdgpu_vm_ioctl() nor its callees take a runtime PM reference, yet AMDGPU_VM_OP_RESERVE_VMID and AMDGPU_VM_OP_UNRESERVE_VMID call amdgpu_gmc_bind_vmid(), which programs VM page-table base registers via setup_vm_pt_regs() and flushes the GPU TLB via amdgpu_gmc_flush_gpu_tlb(). Running them while runtime-suspended risks PCIe bus errors or GPU hangs. [ ... ] > + AMDGPU_IOCTL_SKIP_RESUME(DRM_IOCTL_AMDGPU_UALINK_HANDLE), > +}; [Severity: Medium] Can DRM_IOCTL_AMDGPU_UALINK_HANDLE issue LSDMA MMIO transfers or submit SDMA jobs while the GPU is runtime-suspended? ualink_v1_0_ip_funcs has no .suspend callback, so accel_state stays AMDGPU_UALINK_ACCEL_STATE_ACTIVE across runtime suspend. When DRM_AMDGPU_UALINK_HANDLE_OP_IMPORT runs without a runtime PM reference, amdgpu_ualink_import_handle() reaches amdgpu_ualink_send_command() and calls amdgpu_lsdma_copy_mem() or amdgpu_job_submit() against a powered-down device, causing LSDMA errors or SDMA fence timeouts. > long amdgpu_drm_ioctl(struct file *filp, > unsigned int cmd, unsigned long arg) > { > struct drm_file *file_priv =3D filp->private_data; > struct drm_device *dev; > + unsigned int nr =3D DRM_IOCTL_NR(cmd); > + bool pm_ref =3D nr >=3D ARRAY_SIZE(amdgpu_ioctls_skip_resume) ? > + true : !amdgpu_ioctls_skip_resume[nr]; [Severity: Low] Should this lookup (and the copy in amdgpu_kms_compat_ioctl()) use array_index_nospec() or size amdgpu_ioctls_skip_resume[] to [_IOC_NRMASK + 1]? Since nr is a user-controlled 8-bit value and the table has 200 entries, speculative execution past the bounds check can read out of bounds in .rodata. > long ret; > =20 > - dev =3D file_priv->minor->dev; > - ret =3D pm_runtime_get_sync(dev->dev); > - if (ret < 0) > - goto out; > + if (pm_ref) { > + dev =3D file_priv->minor->dev; > + ret =3D pm_runtime_resume_and_get(dev->dev); > + if (ret < 0) > + goto out; > + } [Severity: Medium] Can non-DRM ioctls or calls on an unplugged device spuriously invoke pm_runtime_resume_and_get() before drm_ioctl() rejects them? Both amdgpu_drm_ioctl() and amdgpu_kms_compat_ioctl() check only DRM_IOCTL_NR(cmd), not DRM_IOCTL_TYPE(cmd) =3D=3D DRM_IOCTL_BASE or drm_dev_is_unplugged(dev). A routine probe such as TCGETS from isatty() will wake a suspended GPU only for drm_ioctl() to return -ENOTTY, and calls on a hot-unplugged device will attempt a runtime resume instead of immediately returning -ENODEV. [ ... ] > +#ifdef CONFIG_COMPAT > +static long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,= unsigned long arg) > +{ > + struct drm_file *file_priv =3D filp->private_data; > + struct drm_device *dev; > + unsigned int nr =3D DRM_IOCTL_NR(cmd); > + bool pm_ref =3D nr >=3D ARRAY_SIZE(amdgpu_ioctls_skip_resume) ? > + true : !amdgpu_ioctls_skip_resume[nr]; > + long ret; > + > + if (nr < DRM_COMMAND_BASE) { > + if (pm_ref) { > + dev =3D file_priv->minor->dev; > + ret =3D pm_runtime_resume_and_get(dev->dev); > + if (ret < 0) > + goto out; > + } > + > + ret =3D drm_compat_ioctl(filp, cmd, arg); > + if (pm_ref) > + pm_runtime_put_autosuspend(dev->dev); > + } else { > + ret =3D amdgpu_drm_ioctl(filp, cmd, arg); > + } > +out: > + return ret; > +} > +#endif [Severity: High] Does routing nr >=3D DRM_COMMAND_BASE to amdgpu_drm_ioctl() break 32-bit x86 DRM_IOCTL_MODE_ADDFB2 calls? Core KMS ioctls live in 0xA0..0xFF, and drm_compat_ioctls[] registers compat_drm_mode_addfb2() at 0xB8 on CONFIG_X86. Bypassing drm_compat_ioctl() copies the packed 32-bit struct directly into the 64-bit struct drm_mode_fb_cmd2 without the alignment padding before modifier[4], corrupting the framebuffer modifiers. Since drm_compat_ioctl() already falls through to drm_ioctl() for ioctls without a compat handler, this wrapper can call drm_compat_ioctl() directly for all ioctls and share the runtime PM helper with amdgpu_drm_ioctl(). > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.h b/drivers/gpu/drm/am= d/amdgpu/amdgpu_drv.h > index 2d86cc6f7f4dd..434bb3bf1c946 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.h > @@ -43,10 +43,9 @@ > =20 > extern const struct drm_driver amdgpu_partition_driver; > =20 > +#define AMDGPU_IOCTL_SKIP_RESUME(ioctl) [DRM_IOCTL_NR(ioctl)] =3D true > + > long amdgpu_drm_ioctl(struct file *filp, > unsigned int cmd, unsigned long arg); [Severity: Low] Now that amdgpu_ioc32.c is gone, can amdgpu_drm_ioctl() be made static and both its prototype and AMDGPU_IOCTL_SKIP_RESUME() be moved out of amdgpu_drv.h? Neither is used outside amdgpu_drv.c, and amdgpu_drv.h does not include drm/drm_ioctl.h for DRM_IOCTL_NR(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203175200.1774= 878-1-shahyan.soltani@amd.com?part=3D2