AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Felix Kuehling <felix.kuehling@amd.com>
To: Zhu Lingshan <lingshan.zhu@amd.com>, alexander.deucher@amd.com
Cc: ray.huang@amd.com, amd-gfx@lists.freedesktop.org
Subject: Re: [RESEND] amdkfd: check ret code for ioctls
Date: Mon, 4 Nov 2024 15:50:57 -0500	[thread overview]
Message-ID: <76ef68f6-dd23-41b3-8dec-d35e6874de01@amd.com> (raw)
In-Reply-To: <2ca21e92-6324-413f-9df9-0bfcf638c669@amd.com>



On 2024-10-31 22:35, Zhu Lingshan wrote:
> On 10/31/2024 11:30 PM, Felix Kuehling wrote:
>>
>> On 2024-10-31 6:50, Zhu Lingshan wrote:
>>> The ioctl functions may fail, causing the args unreliable.
>>> Therefore, the args should not be copied to user space.
>>>
>>> The return code provides enough information for
>>> error handling in user space.
>>>
>>> This commit checks the return code of the ioctl functions
>>> and handles errors appropriately when they fail.
>> I have reviewed and rejected this patch before. My opinion has not changed. The existing code copies the ioctl arg structure back to user mode even in error cases because user mode needs additional information from that structure for some ioctls.
> how can the user space program distinguish the "good informational parameters" from the  "bad default legacy parameters"? There can be other user space programs other than thunk.
> 
> what if the user space program doing pulling mode, it can pull the args changes because ioctl is usually slower, our code should be robust.
> 
> usually the return code provides enough information for the user space programs.

I don't understand your concern. Even without your patch, the failing ioctl still returns the error code to user mode. User mode can safely ignore additional information returned in the argument structure. You are raising concerns about performance or robustness. I don't see that either of those are negatively impacted by copying additional information in the argument struct to user mode.

You mention that there can be other user mode clients other than Thunk. That's true. E.g. rocm-gdb calls KFD ioctls directly. And it depends on some of the additional information about errors. If you know of other user mode clients that are broken by the current behaviour, please point them out.

Before anything else, we do not break existing user mode. Your patch breaks that rule. There is really no room for discussion here. I'm not seeing any reasonable argument to even consider your proposal.

Regards,
  Felix

> 
> Thanks
> Lingshan
>>
>> Regards,
>>   Felix
>>
>>> Signed-off-by: Zhu Lingshan <lingshan.zhu@amd.com>
>>> ---
>>>  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 3 +++
>>>  1 file changed, 3 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
>>> index 3e6b4736a7fe..a184ca0023b5 100644
>>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
>>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
>>> @@ -3327,6 +3327,8 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
>>>  	}
>>>  
>>>  	retcode = func(filep, process, kdata);
>>> +	if (retcode)
>>> +		goto err_retcode;
>>>  
>>>  	if (cmd & IOC_OUT)
>>>  		if (copy_to_user((void __user *)arg, kdata, usize) != 0)
>>> @@ -3340,6 +3342,7 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
>>>  	if (kdata != stack_kdata)
>>>  		kfree(kdata);
>>>  
>>> +err_retcode:
>>>  	if (retcode)
>>>  		dev_dbg(kfd_device, "ioctl cmd (#0x%x), arg 0x%lx, ret = %d\n",
>>>  				nr, arg, retcode);
> 

  reply	other threads:[~2024-11-04 20:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-31 10:50 [RESEND] amdkfd: check ret code for ioctls Zhu Lingshan
2024-10-31 15:30 ` Felix Kuehling
2024-11-01  2:35   ` Zhu Lingshan
2024-11-04 20:50     ` Felix Kuehling [this message]
2024-11-11  8:08       ` Zhu Lingshan
2024-11-11 22:21         ` Felix Kuehling
2024-11-12  7:35           ` Zhu Lingshan
2024-11-12 23:46             ` Felix Kuehling
2024-11-13  3:35               ` Zhu Lingshan

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=76ef68f6-dd23-41b3-8dec-d35e6874de01@amd.com \
    --to=felix.kuehling@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=lingshan.zhu@amd.com \
    --cc=ray.huang@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