From mboxrd@z Thu Jan 1 00:00:00 1970 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 CEA99105F78C for ; Fri, 13 Mar 2026 11:55:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5B05A10EB87; Fri, 13 Mar 2026 11:55:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="A6t3GnIN"; dkim-atps=neutral Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010044.outbound.protection.outlook.com [52.101.193.44]) by gabe.freedesktop.org (Postfix) with ESMTPS id 21EFF10EB87 for ; Fri, 13 Mar 2026 11:55:07 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WSGfdbmwv1BBbBzL0b5R1VtKGhrN9z7TCJng596RykGSCMRGwtzMbzhM7UBv4HMHuDH8XQimH8Pq9DbmhFg/HxbLXyNthCcZLovHylOoyqpA8TmQDh29qbzYwCc8KwforCM+b4ga7PrMNI2syYnkbSDsL8hn+U0es80WoOhQ8koEqynQ2tPzhCT8Y9PoGPyCvJ5YrVrYJVbVKdgEamlpILsuIYNLzOuLfor0WISS3lwUo2BBAEu2Rbn74I1g6VMlBznx/CKWApZurlb5pGIt/ccvvaoKcgyhAaB/WuwXli8SgFTtriEO49FgjKZc8dnRYDuvUDsLFDil7PbipcT4UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AQNGRcURJ9DTr8gBxP8lrxynBIa+J1CouFhzE/8xOk4=; b=yhWH4RBJejJYfGO9x5c6IweAn0evFhK0KrvE+qh/x01Lkn9KXcquWUgScLhSt2bi1K9QjOGqY+uLjHEioOMO0v6Oxx1hAQF1WNvqhD7OzX4U4nQPbprmWaxrfyrl/8p2dv2Aw/C0OlNUPrFhEMTBIKVyeBilnfT6p/120hrnjvPBDiMe7zNJfA0W8DMI8yCKtwqYwRytq4Rw+58J6nx3mDU0pRl0Ke/GAC/ijAUmBs4Z5Ujt2cAzozxJdOz6CI4zOIPPI837nCAHdA6g3Ahabk5h7sMWGSyknR8yH0meWmfZ//TDhBrmFySrMyFtRPKxMML3hHDw3HgCCb9COJN0fA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AQNGRcURJ9DTr8gBxP8lrxynBIa+J1CouFhzE/8xOk4=; b=A6t3GnINKklL9TDwTSC5XT2ahzpCkSj4pEd/xZe9CfeRt/3gV50nqX2ui7d6ZYrjWc7GiacQBRcosyBzBLQOnHjwPgsosWzXnj4sxGS+pSQIBFK/fNRycYYX5KbtMTzPB/Gv1zDeX0nnVYu+kdvMWQIgV1Iixn2KoDjNvOsGDb8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from PH7PR12MB5685.namprd12.prod.outlook.com (2603:10b6:510:13c::22) by DM4PR12MB7598.namprd12.prod.outlook.com (2603:10b6:8:10a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.8; Fri, 13 Mar 2026 11:55:03 +0000 Received: from PH7PR12MB5685.namprd12.prod.outlook.com ([fe80::ce69:cfae:774d:a65c]) by PH7PR12MB5685.namprd12.prod.outlook.com ([fe80::ce69:cfae:774d:a65c%5]) with mapi id 15.20.9723.004; Fri, 13 Mar 2026 11:55:03 +0000 Message-ID: Date: Fri, 13 Mar 2026 12:54:59 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] drm/amdgpu: Limit BO list entry count to prevent resource exhaustion To: =?UTF-8?B?TWFyZWsgT2zFocOhaw==?= Cc: Alex Deucher , "Jesse.Zhang" , =?UTF-8?B?TWFyZWsgT2zFocOhaw==?= , amd-gfx@lists.freedesktop.org, Alexander.Deucher@amd.com References: <20260312101334.1500935-1-Jesse.Zhang@amd.com> Content-Language: en-US From: =?UTF-8?Q?Christian_K=C3=B6nig?= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: FR4P281CA0328.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:eb::7) To PH7PR12MB5685.namprd12.prod.outlook.com (2603:10b6:510:13c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH7PR12MB5685:EE_|DM4PR12MB7598:EE_ X-MS-Office365-Filtering-Correlation-Id: b7e902bb-6c2e-4091-2e6f-08de80f75cd1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|366016|22082099003|56012099003|18002099003; X-Microsoft-Antispam-Message-Info: LKFYdzMqTrNoRTypGNIV4NgjJ+gBQMdvQbgt7BKac/5RaCpBnhGkg6g8dGRht+xvmvGd/n3Xnx2gT0kJdP0y7A/vlXgPKEk5aAuat0HRxQH7tyntsDxKVkS8UJqP4itYu2tNARqcOC5qDGhDsilgJz127muXw7urH21i1Kr7l2VlrHmaU79G9lrOO7Sfcf4tjIqJsjZWJ9+niB1DTT3O4zmCYbEerNnMy2bmmIIde1dLmcg+Wo0U/ww3krRzbaJiQisgvI44akuyQoHIyvAJnQIq7qUHg4gsBBb15LGADl7K1C7jvnHKSOqjEJDS+xcPjWPF0secY3A+KlmZ7qSg63fXmm8lOzRCMH9rpsJIdBUSqrFzBJIhPaH433uPBIV4KrnV5CAnXBs2w4BYTbi2eX5cfUX64Krg7SV7Od0iqmLKEep4455WLjgdKcdGvsMrJjKqJH/nfmO+73zHSwFkg5SKzIIa8NOHEmdRalEpL5w8Pexp85gwBk+4dKqGPggIXo9a8UFaEg1kDv163F5lDnDDFjKKn+fJzcAKMSPwUuciuP/QWe6m8pEAffSnpz5edg30gSGXTr2f09FXaF3/kAnYX85MpatfTgpAMxpk3H/ZHBFg0y8eK2QXue3Lw/MzdOZ4TZUrL8yBwaS1rs9lFjD9/8P1Y6wVqsWG9QJ90LXVkoaXzdlMBSGCmeSlc96OCK6A1Kib6LicVqYVgoU9PYMD5z1qxhpycM2pB44YyhQ= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH7PR12MB5685.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016)(22082099003)(56012099003)(18002099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?M2gwUDJjTWlmM1c2OUdOc2tvQldYUG1lL1BIMjMreElMU3p1SDF1MmhqbVNH?= =?utf-8?B?TWF0Q1ZZQmFMenYyRzZYZ0pYWURsTDNrVWRlQ0hCTjRudkhhOTNxQWpnbnMv?= =?utf-8?B?V3AvdWcvd3hYcVdQNTJVbDVDZ1I3TC9EUy9rNFpLUGM1WURkbTQ4Sys2WmdR?= =?utf-8?B?a0VUYTlBbGxaSnJnNnQ0UWh5bk9rZytPdmhEL3dUd0tudUlIUVlGYm5yUFpQ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LdnVGam9GQWZEME5z?= =?utf-8?B?dTB0UkRrZjB6K2Q3Q09RUmU3Y0NwTnVKMDRxQmE0bzZCMExpVHhNTUJMZUlM?= =?utf-8?B?ZXFGdXdtei8xSGlpWk1uVTNRdXE2azNRTmdrbW1uTkI5SlFIV01mcmxtWlRL?= =?utf-8?B?QnBGNTJIaHdBRlRjR1NZY3FaS1pyZnp6bjJ3VWUwMmZiMFpuWkxMQWd2OXlt?= =?utf-8?B?WVZSTWlmNTdvRnFZL0NvaFRadjFXRitxK0FKRGNwc2tLTXpieTBCRUlUTWtH?= =?utf-8?Q?zxEm8zHs8rwZZIrOZ2?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b7e902bb-6c2e-4091-2e6f-08de80f75cd1 X-MS-Exchange-CrossTenant-AuthSource: PH7PR12MB5685.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2026 11:55:03.6974 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: R6GjlpMrMZRaWWIjHkjUiue2GPoRLDR2IcQU6WSbJB21kgQjeDd3B3C69v/zfppo X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7598 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" Yeah that matches my expectations. And yes we need to make sure not to completely overflow such arrays. Christian. On 3/12/26 21:43, Marek Olšák wrote: > I have just gathered real data on this and the result is surprising. > Viewperf 13, Viewperf 2020, Unigine benchmarks, and others have been > used to gather BO list data. > > The maximum number of BOs that has been observed in the CS ioctl for > radeonsi is 283, even though the actual number of OpenGL BOs can be on > the order of 50k. That's thanks to the slab allocator in the Mesa > amdgpu winsys. > > RADV uses VM_ALWAYS_VALID by default currently. radeonsi could also > start using it if the kernel memory management behaves optimally. > > Old Mesa drivers might use more BOs, especially RADV which doesn't > have a slab allocator. > > Some limit may also be needed for lists of sync objects in all our > ioctls and all arrays in general. > > Marek > > On Thu, Mar 12, 2026 at 1:59 PM Christian König > wrote: >> >> On 3/12/26 18:44, Alex Deucher wrote: >>> + Marek, >>> >>> This was the feedback from Marek the last time this was brought up: >>> >>> "USHRT_MAX seems too low. Traces for workstation apps create 20-30k >>> BOs, which is not very far from the limit. RADV doesn't suballocate >>> BOs. Neither GL nor VK has a ilmit on the number of BOs that can be >>> created. The hypothetical maximum number of BOs that can be allocated >>> on a GPU with 32GB of addressable memory is 8 million." >>> >>> Does 128K sound more reasonable? >> >> I think so, yes. Event 64k seems reasonable large to me considering that only BOs which are not per VM need to be in the list. >> >> E.g. RADV barely uses this feature as far as I know. >> >> Regards, >> Christian. >> >>> >>> Alex >>> On Thu, Mar 12, 2026 at 6:13 AM Jesse.Zhang wrote: >>>> >>>> Userspace can pass an arbitrary number of BO list entries via the >>>> bo_number field. Although the previous multiplication overflow check >>>> prevents out-of-bounds allocation, a large number of entries could still >>>> cause excessive memory allocation (up to potentially gigabytes) and >>>> unnecessarily long list processing times. >>>> >>>> Introduce a hard limit of 128k entries per BO list, which is more than >>>> sufficient for any realistic use case (e.g., a single list containing all >>>> buffers in a large scene). This prevents memory exhaustion attacks and >>>> ensures predictable performance. >>>> >>>> Return -EINVAL if the requested entry count exceeds the limit >>>> >>>> Suggested-by: Christian König >>>> Signed-off-by: Jesse Zhang >>>> --- >>>> drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 4 ++++ >>>> 1 file changed, 4 insertions(+) >>>> >>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c >>>> index 87ec46c56a6e..3270ea50bdc7 100644 >>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c >>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c >>>> @@ -36,6 +36,7 @@ >>>> >>>> #define AMDGPU_BO_LIST_MAX_PRIORITY 32u >>>> #define AMDGPU_BO_LIST_NUM_BUCKETS (AMDGPU_BO_LIST_MAX_PRIORITY + 1) >>>> +#define AMDGPU_BO_LIST_MAX_ENTRIES (128 * 1024) >>>> >>>> static void amdgpu_bo_list_free_rcu(struct rcu_head *rcu) >>>> { >>>> @@ -188,6 +189,9 @@ int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in, >>>> const uint32_t bo_number = in->bo_number; >>>> struct drm_amdgpu_bo_list_entry *info; >>>> >>>> + if (bo_number > AMDGPU_BO_LIST_MAX_ENTRIES) >>>> + return -EINVAL; >>>> + >>>> /* copy the handle array from userspace to a kernel buffer */ >>>> if (likely(info_size == bo_info_size)) { >>>> info = vmemdup_array_user(uptr, bo_number, info_size); >>>> -- >>>> 2.49.0 >>>> >>