[PATCH v2 1/1] drm/amdkfd: return -ENOTTY for unsupported IOCTLs
Deucher, Alexander
Alexander.Deucher at amd.com
Tue Jul 8 15:10:17 UTC 2025
[Public]
I seem to recall -ENOTSUPP being frowned upon for IOCTLs.
Alex
From: McRae, Geoffrey <Geoffrey.McRae at amd.com>
Sent: Tuesday, July 8, 2025 5:13 AM
To: Koenig, Christian <Christian.Koenig at amd.com>; Kuehling, Felix <Felix.Kuehling at amd.com>
Cc: Deucher, Alexander <Alexander.Deucher at amd.com>; amd-gfx at lists.freedesktop.org; dri-devel at lists.freedesktop.org
Subject: Re: [PATCH v2 1/1] drm/amdkfd: return -ENOTTY for unsupported IOCTLs
[AMD Official Use Only - AMD Internal Distribution Only]
I am happy to use EOPNOTSUPP but I must point out that this is not the pattern used across the kernel, the standard is to use ENOTTY, which is also the default that fs/ioctl.c returns when no handler is present. Userspace tooling such as strace and glibc specifically expectect ENOTTY to indicate invalid or unsupported IOCTL.
________________________________
From: Koenig, Christian <Christian.Koenig at amd.com<mailto:Christian.Koenig at amd.com>>
Sent: Tuesday, 8 July 2025 5:01 PM
To: McRae, Geoffrey <Geoffrey.McRae at amd.com<mailto:Geoffrey.McRae at amd.com>>; Kuehling, Felix <Felix.Kuehling at amd.com<mailto:Felix.Kuehling at amd.com>>
Cc: Deucher, Alexander <Alexander.Deucher at amd.com<mailto:Alexander.Deucher at amd.com>>; amd-gfx at lists.freedesktop.org<mailto:amd-gfx at lists.freedesktop.org> <amd-gfx at lists.freedesktop.org<mailto:amd-gfx at lists.freedesktop.org>>; dri-devel at lists.freedesktop.org<mailto:dri-devel at lists.freedesktop.org> <dri-devel at lists.freedesktop.org<mailto:dri-devel at lists.freedesktop.org>>
Subject: Re: [PATCH v2 1/1] drm/amdkfd: return -ENOTTY for unsupported IOCTLs
On 08.07.25 06:22, Geoffrey McRae wrote:
> Some kfd ioctls may not be available depending on the kernel version the
> user is running, as such we need to report -ENOTTY so userland can
> determine the cause of the ioctl failure.
In general sounds like a good idea, but ENOTTY is potentially a bit misleading.
We usually use EOPNOTSUPP for that even if its not the original meaning of that error code.
Regards,
Christian.
>
> Signed-off-by: Geoffrey McRae <geoffrey.mcrae at amd.com<mailto:geoffrey.mcrae at amd.com>>
> ---
> drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index a2149afa5803..36396b7318e7 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -3253,8 +3253,10 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
> int retcode = -EINVAL;
> bool ptrace_attached = false;
>
> - if (nr >= AMDKFD_CORE_IOCTL_COUNT)
> + if (nr >= AMDKFD_CORE_IOCTL_COUNT) {
> + retcode = -ENOTTY;
> goto err_i1;
> + }
>
> if ((nr >= AMDKFD_COMMAND_START) && (nr < AMDKFD_COMMAND_END)) {
> u32 amdkfd_size;
> @@ -3267,8 +3269,10 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
> asize = amdkfd_size;
>
> cmd = ioctl->cmd;
> - } else
> + } else {
> + retcode = -ENOTTY;
> goto err_i1;
> + }
>
> dev_dbg(kfd_device, "ioctl cmd 0x%x (#0x%x), arg 0x%lx\n", cmd, nr, arg);
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/amd-gfx/attachments/20250708/a1c9301c/attachment.htm>
More information about the amd-gfx
mailing list