From: sashiko-bot@kernel.org
To: "Shahyan Soltani" <shahyan.soltani@amd.com>,
amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 2/2] drm/amdgpu: implement IOCTL specific skip resume list
Date: Thu, 03 Dec 2026 19:05:24 +0000 [thread overview]
Message-ID: <sashiko-outbox-248458@kernel.org> (raw)
In-Reply-To: <20261203175200.1774878-2-shahyan.soltani@amd.com>
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 <shahyan.soltani@amd.com>
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/amd/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 *inode, struct file *filp)
> return drm_release(inode, filp);
> }
>
> +/**
> + * amdgpu_ioctls_skip_resume[] - List of IOCTLs that do not require hardware access.
[Severity: Low]
Will this /** comment trigger a kernel-doc warning during make htmldocs
and W=1 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[] = {
> + /* 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 = 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 = filp->private_data;
> struct drm_device *dev;
> + unsigned int nr = DRM_IOCTL_NR(cmd);
> + bool pm_ref = nr >= 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;
>
> - dev = file_priv->minor->dev;
> - ret = pm_runtime_get_sync(dev->dev);
> - if (ret < 0)
> - goto out;
> + if (pm_ref) {
> + dev = file_priv->minor->dev;
> + ret = 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) == 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 = filp->private_data;
> + struct drm_device *dev;
> + unsigned int nr = DRM_IOCTL_NR(cmd);
> + bool pm_ref = nr >= ARRAY_SIZE(amdgpu_ioctls_skip_resume) ?
> + true : !amdgpu_ioctls_skip_resume[nr];
> + long ret;
> +
> + if (nr < DRM_COMMAND_BASE) {
> + if (pm_ref) {
> + dev = file_priv->minor->dev;
> + ret = pm_runtime_resume_and_get(dev->dev);
> + if (ret < 0)
> + goto out;
> + }
> +
> + ret = drm_compat_ioctl(filp, cmd, arg);
> + if (pm_ref)
> + pm_runtime_put_autosuspend(dev->dev);
> + } else {
> + ret = amdgpu_drm_ioctl(filp, cmd, arg);
> + }
> +out:
> + return ret;
> +}
> +#endif
[Severity: High]
Does routing nr >= 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/amd/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 @@
>
> extern const struct drm_driver amdgpu_partition_driver;
>
> +#define AMDGPU_IOCTL_SKIP_RESUME(ioctl) [DRM_IOCTL_NR(ioctl)] = 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().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203175200.1774878-1-shahyan.soltani@amd.com?part=2
next prev parent reply other threads:[~2026-12-03 19:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 17:51 [PATCH 1/2] Revert "drm/amdgpu: get rid of amdgpu_drm_ioctl" Shahyan Soltani
2026-12-03 17:52 ` [PATCH 2/2] drm/amdgpu: implement IOCTL specific skip resume list Shahyan Soltani
2026-12-03 18:09 ` Alex Deucher
2026-12-03 19:05 ` sashiko-bot [this message]
2026-12-03 18:40 ` [PATCH 1/2] Revert "drm/amdgpu: get rid of amdgpu_drm_ioctl" 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=sashiko-outbox-248458@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shahyan.soltani@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