Skip to contentSkip to conversation

drm/amdkfd: return -ENOTTY for unsupported IOCTLs

PATCH In review Geoffrey McRae 5 participants 9 messages Jul 8, 2025 – Aug 5, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/amdkfd: return -ENOTTY for unsupported IOCTLs

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.

---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +6 -2
index a2149afa5803..36396b7318e7 100644
@@ -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);
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 3 lines · Geoffrey McRae

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.

Quoted 34 lines
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +6 -2
index a2149afa5803..36396b7318e7 100644
@@ -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);
 
#2 lore raw

[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 <[email protected]>
Sent: Tuesday, 8 July 2025 5:01 PM
To: McRae, Geoffrey <[email protected]>; Kuehling, Felix <[email protected]>
Cc: Deucher, Alexander <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Subject: Re: [PATCH v2 1/1] drm/amdkfd: return -ENOTTY for unsupported IOCTLs

Quoted 3 lines · Geoffrey McRae

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.

Quoted 34 lines
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +6 -2
index a2149afa5803..36396b7318e7 100644
@@ -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);
 
#3 lore raw

[Public]

I seem to recall -ENOTSUPP being frowned upon for IOCTLs.

Alex

From: McRae, Geoffrey <[email protected]>
Sent: Tuesday, July 8, 2025 5:13 AM
To: Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>
Cc: Deucher, Alexander <[email protected]>; [email protected]; [email protected]
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 <[email protected]<mailto:[email protected]>>
Sent: Tuesday, 8 July 2025 5:01 PM
To: McRae, Geoffrey <[email protected]<mailto:[email protected]>>; Kuehling, Felix <[email protected]<mailto:[email protected]>>
Cc: Deucher, Alexander <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Subject: Re: [PATCH v2 1/1] drm/amdkfd: return -ENOTTY for unsupported IOCTLs

Quoted 3 lines · Geoffrey McRae

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.

Quoted 34 lines
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +6 -2
index a2149afa5803..36396b7318e7 100644
@@ -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);
 
#4 lore raw
Quoted 6 lines · Alexander

[Public]

I seem to recall -ENOTSUPP being frowned upon for IOCTLs.

Going by documentation -
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html

EOPNOTSUPP:
Feature (like PRIME, modesetting, GEM) is not supported by the driver.

"Note that ENOTTY has the slightly unintuitive meaning of “this IOCTL does not exist”, and is used exactly as such in DRM"

Since KFD ioctls could eventually be supported in drm node, it seems better to go with ENOTTY.

Thanks,
Lijo

Quoted 94 lines

Alex

*From:*McRae, Geoffrey <[email protected]>
*Sent:* Tuesday, July 8, 2025 5:13 AM
*To:* Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>
*Cc:* Deucher, Alexander <[email protected]>; amd- [email protected]; [email protected] *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 <[email protected] <mailto:[email protected]>>
*Sent:* Tuesday, 8 July 2025 5:01 PM
*To:* McRae, Geoffrey <[email protected] <mailto:[email protected]>>; Kuehling, Felix <[email protected] <mailto:[email protected]>> *Cc:* Deucher, Alexander <[email protected] <mailto:[email protected]>>; [email protected] <mailto:[email protected]> <[email protected] <mailto:[email protected]>>; [email protected] <mailto:[email protected]> <dri- [email protected] <mailto:[email protected]>> *Subject:* Re: [PATCH v2 1/1] drm/amdkfd: return -ENOTTY for unsupported IOCTLs

Quoted 3 lines · Geoffrey McRae

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.

Quoted 34 lines
Signed-off-by Geoffrey McRae <[email protected] <mailto:[email protected]>>

---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 ++++++--

  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
index a2149afa5803..36396b7318e7 100644
@@ -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;

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
@@ -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);

maintainer
#5 lore raw
Quoted 10 lines · Lijo
Quoted 6 lines · Alexander

[Public]

I seem to recall -ENOTSUPP being frowned upon for IOCTLs.

Going by documentation -
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html

Good point.

Quoted 7 lines

EOPNOTSUPP:
Feature (like PRIME, modesetting, GEM) is not supported by the driver.

"Note that ENOTTY has the slightly unintuitive meaning of “this IOCTL does not exist”, and is used exactly as such in DRM"

Since KFD ioctls could eventually be supported in drm node,

That's certainly not going to happen.

We are currently in the process of deprecating the KFD IOCTLs and either using the existing DRM render node ones or coming up with new IOCTL/additions to the existing ones.

Background is that some of the KFD IOCTLs have design flaws which are unfix able.

Regards,
Christian.

Quoted 101 lines

it seems
better to go with ENOTTY.

Thanks,
Lijo

Quoted 94 lines

Alex

*From:*McRae, Geoffrey <[email protected]>
*Sent:* Tuesday, July 8, 2025 5:13 AM
*To:* Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>
*Cc:* Deucher, Alexander <[email protected]>; amd- [email protected]; [email protected] *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 <[email protected] <mailto:[email protected]>>
*Sent:* Tuesday, 8 July 2025 5:01 PM
*To:* McRae, Geoffrey <[email protected] <mailto:[email protected]>>; Kuehling, Felix <[email protected] <mailto:[email protected]>> *Cc:* Deucher, Alexander <[email protected] <mailto:[email protected]>>; [email protected] <mailto:[email protected]> <[email protected] <mailto:[email protected]>>; [email protected] <mailto:[email protected]> <dri- [email protected] <mailto:[email protected]>> *Subject:* Re: [PATCH v2 1/1] drm/amdkfd: return -ENOTTY for unsupported IOCTLs

Quoted 3 lines · Geoffrey McRae

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.

Quoted 34 lines
Signed-off-by Geoffrey McRae <[email protected] <mailto:[email protected]>>

---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 ++++++--

  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
index a2149afa5803..36396b7318e7 100644
@@ -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;

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
@@ -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);

#6 lore raw
Quoted 17 lines · Christian König
Quoted 10 lines · Lijo
Quoted 6 lines · Alexander

[Public]

I seem to recall -ENOTSUPP being frowned upon for IOCTLs.

Going by documentation -
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html

Good point.

Quoted 3 lines

EOPNOTSUPP:
Feature (like PRIME, modesetting, GEM) is not supported by the driver.

Quoted 9 lines
Quoted 4 lines

"Note that ENOTTY has the slightly unintuitive meaning of “this IOCTL does not exist”, and is used exactly as such in DRM"

Since KFD ioctls could eventually be supported in drm node,

That's certainly not going to happen.

We are currently in the process of deprecating the KFD IOCTLs and either using the existing DRM render node ones or coming up with new IOCTL/additions to the existing ones.

I really meant to convey this to justify using drm documentation as the background for picking error codes for KFD ones also. At least for any new error code returns, definitions will remain consistent across both.

Thanks,
Lijo

Quoted 107 lines

Background is that some of the KFD IOCTLs have design flaws which are unfix able.

Regards,
Christian.

Quoted 101 lines

it seems
better to go with ENOTTY.

Thanks,
Lijo

Quoted 94 lines

Alex

*From:*McRae, Geoffrey <[email protected]>
*Sent:* Tuesday, July 8, 2025 5:13 AM
*To:* Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>
*Cc:* Deucher, Alexander <[email protected]>; amd- [email protected]; [email protected] *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 <[email protected] <mailto:[email protected]>>
*Sent:* Tuesday, 8 July 2025 5:01 PM
*To:* McRae, Geoffrey <[email protected] <mailto:[email protected]>>; Kuehling, Felix <[email protected] <mailto:[email protected]>> *Cc:* Deucher, Alexander <[email protected] <mailto:[email protected]>>; [email protected] <mailto:[email protected]> <[email protected] <mailto:[email protected]>>; [email protected] <mailto:[email protected]> <dri- [email protected] <mailto:[email protected]>> *Subject:* Re: [PATCH v2 1/1] drm/amdkfd: return -ENOTTY for unsupported IOCTLs

Quoted 3 lines · Geoffrey McRae

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.

Quoted 34 lines
Signed-off-by Geoffrey McRae <[email protected] <mailto:[email protected]>>

---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 ++++++--

  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
index a2149afa5803..36396b7318e7 100644
@@ -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;

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
@@ -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);

maintainer Acked-by
#7 lore raw

[Public]

Quoted 37 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, July 9, 2025 5:02 AM
To: Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; McRae, Geoffrey <[email protected]>; Kuehling, Felix <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdkfd: return -ENOTTY for unsupported IOCTLs

Quoted 24 lines · Christian König
Quoted 10 lines · Lijo
Quoted 6 lines · Alexander

[Public]

I seem to recall -ENOTSUPP being frowned upon for IOCTLs.

Going by documentation -
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html

Good point.

Quoted 7 lines

EOPNOTSUPP:
Feature (like PRIME, modesetting, GEM) is not supported by the driver.

"Note that ENOTTY has the slightly unintuitive meaning of “this IOCTL does not exist”, and is used exactly as such in DRM"

Since KFD ioctls could eventually be supported in drm node,

That's certainly not going to happen.

Quoted 8 lines
Quoted 1 line

We are currently in the process of deprecating the KFD IOCTLs and either using

the existing DRM render node ones or coming up with new IOCTL/additions to the existing ones.

Quoted 1 line

I really meant to convey this to justify using drm documentation as the background for picking error codes for KFD ones also. At least for any new error code returns, definitions will remain consistent across both.

In this case, I think -ENOTTY makes sense per the documentation. Patch is:

Quoted 122 lines

Thanks,
Lijo

Quoted 1 line

Background is that some of the KFD IOCTLs have design flaws which are unfix

able.

Quoted 116 lines

Regards,
Christian.

Quoted 111 lines

it seems
better to go with ENOTTY.

Thanks,
Lijo

Quoted 104 lines

Alex

*From:*McRae, Geoffrey <[email protected]>
*Sent:* Tuesday, July 8, 2025 5:13 AM
*To:* Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>
*Cc:* Deucher, Alexander <[email protected]>; amd- [email protected]; [email protected] *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 <[email protected] <mailto:[email protected]>>
*Sent:* Tuesday, 8 July 2025 5:01 PM
*To:* McRae, Geoffrey <[email protected] <mailto:[email protected]>>; Kuehling, Felix <[email protected] <mailto:[email protected]>> *Cc:* Deucher, Alexander <[email protected] <mailto:[email protected]>>; [email protected] <mailto:[email protected]> <[email protected] <mailto:[email protected]>>; [email protected] <mailto:[email protected]> <dri- [email protected] <mailto:[email protected]>>
*Subject:* Re: [PATCH v2 1/1] drm/amdkfd: return -ENOTTY for unsupported IOCTLs

Quoted 3 lines · Geoffrey McRae

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.

Quoted 40 lines

<mailto:[email protected]>>

---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +3 -1
index a2149afa5803..36396b7318e7 100644
@@ -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;
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +3 -1
@@ -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);

maintainer Reviewed-by
#8 lore raw
Quoted 37 lines · Alexander

[Public]

Quoted 35 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, July 9, 2025 5:02 AM
To: Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; McRae, Geoffrey <[email protected]>; Kuehling, Felix <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdkfd: return -ENOTTY for unsupported IOCTLs

Quoted 22 lines · Christian König
Quoted 10 lines · Lijo
Quoted 6 lines · Alexander

[Public]

I seem to recall -ENOTSUPP being frowned upon for IOCTLs.

Going by documentation -
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html

Good point.

Quoted 7 lines

EOPNOTSUPP:
Feature (like PRIME, modesetting, GEM) is not supported by the driver.

"Note that ENOTTY has the slightly unintuitive meaning of “this IOCTL does not exist”, and is used exactly as such in DRM"

Since KFD ioctls could eventually be supported in drm node,

That's certainly not going to happen.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

We are currently in the process of deprecating the KFD IOCTLs and either using

the existing DRM render node ones or coming up with new IOCTL/additions to the existing ones.
I really meant to convey this to justify using drm documentation as the background for picking error codes for KFD ones also. At least for any new error code returns, definitions will remain consistent across both.

In this case, I think -ENOTTY makes sense per the documentation. Patch is:

I agree.

Quoted 116 lines
Quoted 116 lines

Thanks,
Lijo

Quoted 1 line

Background is that some of the KFD IOCTLs have design flaws which are unfix

able.

Quoted 109 lines

Regards,
Christian.

Quoted 106 lines

it seems
better to go with ENOTTY.

Thanks,
Lijo

Quoted 100 lines

Alex

*From:*McRae, Geoffrey <[email protected]>
*Sent:* Tuesday, July 8, 2025 5:13 AM
*To:* Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>
*Cc:* Deucher, Alexander <[email protected]>; amd- [email protected]; [email protected] *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 <[email protected] <mailto:[email protected]>>
*Sent:* Tuesday, 8 July 2025 5:01 PM
*To:* McRae, Geoffrey <[email protected] <mailto:[email protected]>>; Kuehling, Felix <[email protected] <mailto:[email protected]>> *Cc:* Deucher, Alexander <[email protected] <mailto:[email protected]>>; [email protected] <mailto:[email protected]> <[email protected] <mailto:[email protected]>>; [email protected] <mailto:[email protected]> <dri- [email protected] <mailto:[email protected]>>
*Subject:* Re: [PATCH v2 1/1] drm/amdkfd: return -ENOTTY for unsupported IOCTLs

Quoted 3 lines · Geoffrey McRae

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.

Quoted 39 lines

<mailto:[email protected]>>

---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +3 -1
index a2149afa5803..36396b7318e7 100644
@@ -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;
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +3 -1
@@ -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);