Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C28ADE98E10 for ; Mon, 23 Feb 2026 09:56:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3AA4410E096; Mon, 23 Feb 2026 09:56:13 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=ursulin.net header.i=@ursulin.net header.b="j9Vx9mEc"; dkim-atps=neutral Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by gabe.freedesktop.org (Postfix) with ESMTPS id 636FA10E096 for ; Mon, 23 Feb 2026 09:56:12 +0000 (UTC) Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4806f3fc50bso46594755e9.0 for ; Mon, 23 Feb 2026 01:56:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin.net; s=google; t=1771840571; x=1772445371; darn=lists.freedesktop.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=0+ldAiILCHdMAAYpNzBd7JgnIi3K8AdetuMoJmvzHiI=; b=j9Vx9mEcwwHXiICJhpZzTYei3BhwY3YlWvaZAgGB2kE8pPUrSocgNtJ8UhOB94+Jy1 Dn9H2sYXhtgYyJNg70oAppfxDiqygrvvKvH+YbgGpfp7QsPp3Z9PxQNz74MGLuaKzo3L JFmrroIKbVTgYPkMRdu/pl8vuiZXlBFiMm4fzjH4ANZGu09cXZsgZxBeXFyV/yyDwkPo dZbdNc6Yk7ALj7KyDrrntEYCWqm2QQxk4sN4Jeacnhecn6KR5EN+ui4sRtRBdFLHwur7 R9Y3AZ4euEPKmqi/ABfaF/9QfY3tvAiaqm9Sya234gws64Zb2WsvRcruaX8azUl76oPq CO3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771840571; x=1772445371; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0+ldAiILCHdMAAYpNzBd7JgnIi3K8AdetuMoJmvzHiI=; b=A1XzRleeDhEyHx83PUz/3K0hqD45MBIPWUpHZPmx8zJvmSWiEIC2aSFJM/ZcUnA/tM 2kts4Bl75ipq5edw0VbRWcI3Y9F9WRR92TxV2BTRBXsfW8A92EiwQDW/hSCBxlsJU8oG M2+ZxC6oQr85KQpgYo3Gzm9Q2GZNkFokanWcqtPat+DSyQm5hpYgcW2hDAu+mQVLGIHO okNwarb7FKJ6vMm6NUBwBFMAF6SMmgZuvBGDIlq+l92UygiwZLmDmPnP4qY0Tx3f0qf8 ePJY7omBk9l1Pvh2ERkgD//ccHmdNoMwtRLSdDfJ7kHO9XazO59sMXI7fOq4czJcA7+k WMqA== X-Gm-Message-State: AOJu0YxmDapbCx3lFSD3Jh2US63M4gYSR8N9m7ssVZOv1T8H3AC2AjM7 rAH3QyCKBXA7IS3uVPrJEBuXKVw1vQpy2BiuH1dIyKbajDzIpOscLSA62OB1rDDFosDYCRd6uQf gc7emYI0= X-Gm-Gg: AZuq6aKAYnCuwFSJHr/HKx0ePc1YxCW8amnkNHD/vl9UE1AiRbVnE11c72RffuZ05Y1 ViOdtzyqNV8giG7rSotyH4F01MzMbNDYGQqEIkL//d9KT8j6OF/kKk3WWIeSPODQL32ColIJR1w NfgB/2A6qdr/+izR+Yrntnj4FILRJqZF3/HN7eSaJVpDuaruoHZ1kJ8cREX16I7TrKxO8kRqZA5 84sxLbDj5T0ATauG3R2VAlAtz6DdFAsCD3urOYaY5OBxqZM0kD2/tbQvvAW9cFuGPHm/XXEO7+a 0OLxUTc9TWjwLYcZLHHyC+sgDhh/LVQYbCzCo2fNt1FkNZFiq/o/RPH8w977XEr0kIj48/T42rl gRONd4WGqEFSx6WSzdozr72fPpXGjBG1F/qKJlYXVRRGFqFTjKixFDq6z5fTVKKGpCQ/GIN6Ea+ owMuwDfeZZKXklHZn7loCZcXZ96ZckxqWaQ2sc7+rU/oWyLhWcp/Uyr4U= X-Received: by 2002:a05:600c:6217:b0:47b:de05:aa28 with SMTP id 5b1f17b1804b1-483a95eb4d5mr139457755e9.2.1771840570168; Mon, 23 Feb 2026 01:56:10 -0800 (PST) Received: from [192.168.0.101] ([90.240.106.137]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43970d4c977sm19007384f8f.32.2026.02.23.01.56.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Feb 2026 01:56:09 -0800 (PST) Message-ID: Date: Mon, 23 Feb 2026 09:56:09 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 1/2] drm/amdgpu: update memdup_user with memdup_array_user To: "Khatri, Sunil" , Sunil Khatri , Alex Deucher , =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: amd-gfx@lists.freedesktop.org References: <20260220082840.2192325-1-sunil.khatri@amd.com> <3c7f24f3-d1f7-4724-bf2e-8540fa2e2648@ursulin.net> <4a824f5e-5279-4cb7-b6a9-fb4c6f87cd91@amd.com> <3c4c8c6c-5bcd-426a-bd39-fb24db8fc5f5@amd.com> Content-Language: en-GB From: Tvrtko Ursulin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" On 23/02/2026 08:21, Khatri, Sunil wrote: > > On 23-02-2026 01:41 pm, Tvrtko Ursulin wrote: >> >> >> On 23/02/2026 04:31, Khatri, Sunil wrote: >>> Applied the changes @Tvrtko Ursulin >> >> Thank you! I am glad they still applied! >> >> Also, you were suggesting in your last week's reply to "Please make >> sure the changes are made for all memdup_user". There are also patches >> in that series which convert to drm_gem_objects_lookup() which remove >> some more, but, for those I think I need to check if they need >> tweaking after >> dbce431756f8 ("drm/gem: Make drm_gem_objects_lookup() self-cleaning on >> failure v6"). Maybe it just works though. I will wait until the ones >> you merge appear in some branch and check. > > I am in process to merge only two changes patch no 6 and 7 in the > series. There were conflicts but i fixed those but still there are some > more memdup_user which i will fix with a patch which are left after > these 2 patches gets merged. The before mentioned object lookup and syncpoint lookup. For the latter I also had cleanup back in December but did not send it: commit ddb4985391907155a9cf5ef6f5262c1cc8f334c6 Author: Tvrtko Ursulin Date: Thu Dec 4 13:56:56 2025 +0000 use syncobj lookup helper in amdgpu_userq_signal_ioctl Signed-off-by: Tvrtko Ursulin commit b21686063a5858833a09bb8f84cfbae2376f0c18 Author: Tvrtko Ursulin Date: Thu Dec 4 13:36:15 2025 +0000 export sync obj lookup helper Signed-off-by: Tvrtko Ursulin Those two I was planning to send together with some more syncobj patches: 27cf1f1dabfc drm/syncobj: Add a fast path to drm_syncobj_array_find e7efbf50342b drm/syncobj: Add a fast path to drm_syncobj_array_wait_timeout 363279cd8eb4 drm/syncobj: Use vmemdup_array_user in drm_syncobj_array_find Which are interesting for graphics since four stack fast path slots avoid 99% of temporary allocations. Not sure for user queues how many sync points are typical. > Also if you want to take that up its ok with me. Let me know. ¯\_(ツ)_/¯ Not sure if you want to re-do it because what I sent has a flaw somewhere or something else? Regards, Tvrtko >>> On 20-02-2026 06:49 pm, Khatri, Sunil wrote: >>>> >>>> On 20-02-2026 04:54 pm, Tvrtko Ursulin wrote: >>>>> >>>>> On 20/02/2026 08:28, Sunil Khatri wrote: >>>>>> memdup_user could return invalid memory allocation if >>>>>> there is an integer overflow. Using memdup_array_user >>>>>> make sure we validate the size requirements upfront >>>>>> and return with an error. >>>>> >>>>> FYI: >>>>> >>>>> https://lore.kernel.org/amd-gfx/20251205134035.91551-1- >>>>> tvrtko.ursulin@igalia.com/ >>>> Are you awaiting for anything to merge the changes Tvrtko or they >>>> are merged in drm upstream already? Since issue is reported now so >>>> we need to fix this. >>>> >>>>> >>>>> And later: >>>>> >>>>> https://lore.kernel.org/amd-gfx/20260202125149.2067-7- >>>>> christian.koenig@amd.com/. >>>> Yeah i am aware of these Christian changes and we decided we will >>>> fix the issues first and reorganize the code later as needed along >>>> with Christian changes. So we are going to push the changes >>>> >>>> on the existing code base first. >>>> >>>> regards >>>> Sunil khatri >>>> >>>>> >>>>> Regards, >>>>> >>>>> Tvrtko >>>>> >>>>>> >>>>>> Signed-off-by: Sunil Khatri >>>>>> --- >>>>>>   .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 32 ++++++++ >>>>>> +---------- >>>>>>   1 file changed, 16 insertions(+), 16 deletions(-) >>>>>> >>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c b/ >>>>>> drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c >>>>>> index 212056d4ddf0..a6eb703b62c4 100644 >>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c >>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c >>>>>> @@ -480,8 +480,8 @@ int amdgpu_userq_signal_ioctl(struct >>>>>> drm_device *dev, void *data, >>>>>>           return -ENOTSUPP; >>>>>>         num_syncobj_handles = args->num_syncobj_handles; >>>>>> -    syncobj_handles = memdup_user(u64_to_user_ptr(args- >>>>>> >syncobj_handles), >>>>>> -                      size_mul(sizeof(u32), num_syncobj_handles)); >>>>>> +    syncobj_handles = memdup_array_user(u64_to_user_ptr(args- >>>>>> >syncobj_handles), >>>>>> +                        num_syncobj_handles, sizeof(u32)); >>>>>>       if (IS_ERR(syncobj_handles)) >>>>>>           return PTR_ERR(syncobj_handles); >>>>>>   @@ -501,8 +501,8 @@ int amdgpu_userq_signal_ioctl(struct >>>>>> drm_device *dev, void *data, >>>>>>       } >>>>>>         num_read_bo_handles = args->num_bo_read_handles; >>>>>> -    bo_handles_read = memdup_user(u64_to_user_ptr(args- >>>>>> >bo_read_handles), >>>>>> -                      sizeof(u32) * num_read_bo_handles); >>>>>> +    bo_handles_read = memdup_array_user(u64_to_user_ptr(args- >>>>>> >bo_read_handles), >>>>>> +                        num_read_bo_handles, sizeof(u32)); >>>>>>       if (IS_ERR(bo_handles_read)) { >>>>>>           r = PTR_ERR(bo_handles_read); >>>>>>           goto free_syncobj; >>>>>> @@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct >>>>>> drm_device *dev, void *data, >>>>>>       } >>>>>>         num_write_bo_handles = args->num_bo_write_handles; >>>>>> -    bo_handles_write = memdup_user(u64_to_user_ptr(args- >>>>>> >bo_write_handles), >>>>>> -                       sizeof(u32) * num_write_bo_handles); >>>>>> +    bo_handles_write = memdup_array_user(u64_to_user_ptr(args- >>>>>> >bo_write_handles), >>>>>> +                         num_write_bo_handles, sizeof(u32)); >>>>>>       if (IS_ERR(bo_handles_write)) { >>>>>>           r = PTR_ERR(bo_handles_write); >>>>>>           goto put_gobj_read; >>>>>> @@ -666,37 +666,37 @@ int amdgpu_userq_wait_ioctl(struct >>>>>> drm_device *dev, void *data, >>>>>>           return -ENOTSUPP; >>>>>>         num_read_bo_handles = wait_info->num_bo_read_handles; >>>>>> -    bo_handles_read = memdup_user(u64_to_user_ptr(wait_info- >>>>>> >bo_read_handles), >>>>>> -                      size_mul(sizeof(u32), num_read_bo_handles)); >>>>>> +    bo_handles_read = >>>>>> memdup_array_user(u64_to_user_ptr(wait_info- >bo_read_handles), >>>>>> +                        num_read_bo_handles, sizeof(u32)); >>>>>>       if (IS_ERR(bo_handles_read)) >>>>>>           return PTR_ERR(bo_handles_read); >>>>>>         num_write_bo_handles = wait_info->num_bo_write_handles; >>>>>> -    bo_handles_write = memdup_user(u64_to_user_ptr(wait_info- >>>>>> >bo_write_handles), >>>>>> -                       size_mul(sizeof(u32), num_write_bo_handles)); >>>>>> +    bo_handles_write = >>>>>> memdup_array_user(u64_to_user_ptr(wait_info- >bo_write_handles), >>>>>> +                         num_write_bo_handles, sizeof(u32)); >>>>>>       if (IS_ERR(bo_handles_write)) { >>>>>>           r = PTR_ERR(bo_handles_write); >>>>>>           goto free_bo_handles_read; >>>>>>       } >>>>>>         num_syncobj = wait_info->num_syncobj_handles; >>>>>> -    syncobj_handles = memdup_user(u64_to_user_ptr(wait_info- >>>>>> >syncobj_handles), >>>>>> -                      size_mul(sizeof(u32), num_syncobj)); >>>>>> +    syncobj_handles = >>>>>> memdup_array_user(u64_to_user_ptr(wait_info- >syncobj_handles), >>>>>> +                        num_syncobj, sizeof(u32)); >>>>>>       if (IS_ERR(syncobj_handles)) { >>>>>>           r = PTR_ERR(syncobj_handles); >>>>>>           goto free_bo_handles_write; >>>>>>       } >>>>>>         num_points = wait_info->num_syncobj_timeline_handles; >>>>>> -    timeline_handles = memdup_user(u64_to_user_ptr(wait_info- >>>>>> >syncobj_timeline_handles), >>>>>> -                       sizeof(u32) * num_points); >>>>>> +    timeline_handles = >>>>>> memdup_array_user(u64_to_user_ptr(wait_info- >>>>>> >syncobj_timeline_handles), >>>>>> +                         num_points, sizeof(u32)); >>>>>>       if (IS_ERR(timeline_handles)) { >>>>>>           r = PTR_ERR(timeline_handles); >>>>>>           goto free_syncobj_handles; >>>>>>       } >>>>>>   -    timeline_points = memdup_user(u64_to_user_ptr(wait_info- >>>>>> >syncobj_timeline_points), >>>>>> -                      sizeof(u32) * num_points); >>>>>> +    timeline_points = >>>>>> memdup_array_user(u64_to_user_ptr(wait_info- >>>>>> >syncobj_timeline_points), >>>>>> +                        num_points, sizeof(u32)); >>>>>>       if (IS_ERR(timeline_points)) { >>>>>>           r = PTR_ERR(timeline_points); >>>>>>           goto free_timeline_handles; >>>>> >>