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 783BBEDF052 for ; Thu, 12 Feb 2026 07:40:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7811810E6E7; Thu, 12 Feb 2026 07:40:43 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="MmFidTEP"; dkim-atps=neutral Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010068.outbound.protection.outlook.com [40.93.198.68]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9D8A210E063; Thu, 12 Feb 2026 07:40:41 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=a0Ci6ITj0vibniHxcFOEKiv+h9JUc6K//emKqrTiEstBr8pvFyLtl1yrXWTx67OsOudIB73Gpwuo7wNwd17V6FIuiZ7cKtQad3zjXNuL/PQ/FeaEr6vN8iut8VNs2NVAuSu/CTCGDEO2w3rXMlaCvE7OnCztrvCroyQ+Xkxj+09f9lEHuxvI9RIwuBzwTSkOo1YtbDog/eaRFms5kjut9zB2qkIhvhDD9SY5wB+anIN+bsKRO+dU89TryZqCH5HIi0mkaYg5vCtF8kF0352TOOL9dFmapnbSPZeDZzvWrrQ7syxhUYgy02RHT2eYdt1A0uqr6/EjJm6bcSXR7+5vDg== 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=NG6kEKXECdKPZwYl/5ciS40d3I1CqARrFi2egaatcvA=; b=lhArxx50qhIDxi/QRRh3wQg2CiJnMCT2uwq3X0qJfgmJPaHl+hJniKvXsYZbl07V4N9vsjg7kiHavB8ihNwn9fsMatSp7w3bZ2sHd/p9Tn19p1sp8rU08OZyvlABCpYAq78rhRDo+kgKDMmmzgiWX7+JGSdNF43eS1FlH69bu5Ufnf8dSoB2K2eA+OfW5rhT+HlnnFHK7CssarTOkT2YtCyQz86FJuZuUSH9oY3FwD0V/cbjOKPZQPZ5ptH9wxDV6NuCAc6XZa751UGckQa3bZUStsvJsqc4RNJuJ40WWtiadKLle+9Zodr4Vpg3vVaVwlnWA2q0KBOvvHg6KZx82Q== 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=NG6kEKXECdKPZwYl/5ciS40d3I1CqARrFi2egaatcvA=; b=MmFidTEPK460+DzW46XuPJOivJ5FzqWo8K0yDKFBgQcNoKsuw1Zgnm5BtxcPpVq1OdQhVmu9MVZbXuuBK01Z/awDyD9CM2O4o4ohvtpCtRIazoCEC0zf2YhUm6W9Cfi7MIMSznVjeeWe4NdPrrYdYHCvgeIkrzwFVehcItYFRsg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from PH8PR12MB7301.namprd12.prod.outlook.com (2603:10b6:510:222::12) by CH3PR12MB8657.namprd12.prod.outlook.com (2603:10b6:610:172::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9611.10; Thu, 12 Feb 2026 07:40:38 +0000 Received: from PH8PR12MB7301.namprd12.prod.outlook.com ([fe80::8434:dc50:a68d:7bdd]) by PH8PR12MB7301.namprd12.prod.outlook.com ([fe80::8434:dc50:a68d:7bdd%4]) with mapi id 15.20.9611.008; Thu, 12 Feb 2026 07:40:38 +0000 Message-ID: <3a205ac1-5917-4e24-b6e6-f8989678a54d@amd.com> Date: Thu, 12 Feb 2026 13:10:32 +0530 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/2] drm/buddy: Add kernel-doc for allocator structures and flags From: Arunpravin Paneer Selvam To: Sanjay Yadav , dri-devel@lists.freedesktop.org Cc: intel-xe@lists.freedesktop.org, =?UTF-8?Q?Christian_K=C3=B6nig?= , Matthew Auld References: <20260211053123.260037-4-sanjay.kumar.yadav@intel.com> <20260211053123.260037-5-sanjay.kumar.yadav@intel.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: MA5P287CA0168.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:1ba::10) To PH8PR12MB7301.namprd12.prod.outlook.com (2603:10b6:510:222::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR12MB7301:EE_|CH3PR12MB8657:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a0c4ac2-13f8-4301-aeb2-08de6a0a03ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024|7053199007; X-Microsoft-Antispam-Message-Info: =?utf-8?B?ZlJIM1NwOVA5dURGNkxySTlMUDNDMElGc3QybzRpV2d4a05ZVDNFWnplSDls?= =?utf-8?B?dUFjeHF6OXhMVTBLWnhpOWhhMDlkbnRxdW5oemVqV0x6c045cnVhcTMzMDhx?= =?utf-8?B?WXpmME1naE90a2pZL3pQOENrM21KamlvaWE0WXZoMFRPN1FL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k1KcE9XQ3JBVmJPK3lVQ3RBSUE0WlROL0JqRTBFbEU3V0pW?= =?utf-8?B?K2twZEVUbVdGN1B2d2VjUXkvUUp1bFNnaTRlbzQ5OTlmc3hCdWpDWmtYNExr?= =?utf-8?B?NVNJNUEwZy93T2VHbE5oMURYTEZFK3YyWThkWGQwTWZ2TDdJQ3BQVTBKSUh6?= =?utf-8?Q?nAgY=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH8PR12MB7301.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(366016)(1800799024)(7053199007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?cEhNL1FXT3JnSkpYSldxOEY2NjhxMGRzb1F4bG1DY3MzeTMveU9RV2pmdTk1?= =?utf-8?B?Y3RoRjdscnNaNUlnbC9INFFiYmN1eDR4USt3azEvUE9mYlUxRmVpUHlhRlJy?= =?utf-8?B?VFdOdUFNQlVRQ21FUXFDTDBIZCtJWXQwaFhHRDNDd2NOZFVBbm5UQ3JKczFn?= =?utf-8?B?VksrMXNOK3VPbHJzZnRRRXRVRFRZRGVJZm5aM0Y0LzBhL25SdXN3ZGRIMjNt?= =?utf-8?B?VG4renNFZnBLRSswMk90UFhPdWJ6VXFoSWJNS2M1dHpaSkRPNmVpcGpBQStI?= =?utf-8?B?MzFoRWgvTHpiak9WMXMrc3YzanFrTDZtamZOK3FTWDE1N2E3Vmp5TURKN0pO?= =?utf-8?B?Q1pwVHJKUnVmMGpMa1dDQ1BuWExLbHJvck1HUWwwMUNOUlRrVmFIb05nc3hO?= =?utf-8?B?a3hGb1MxdjVtY2lYWDJuR2RFWHBHL0FJeUZuNkMvVDJWOHBVQUVWT1FMTStl?= =?utf-8?B?R1QxZTl6VUNMSHMwWkZGR0FWK1E0WGgwZkJUd3dnOGtSO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8?B?MzJRQ0d0NGZBbXZWaTRlcitQcFVEazcwSit2Nk53dDJaQWhlcTkydz09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a0c4ac2-13f8-4301-aeb2-08de6a0a03ae X-MS-Exchange-CrossTenant-AuthSource: PH8PR12MB7301.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2026 07:40:38.0680 (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: xwjhA4L17OXJHhweh3DcS3GDPDo8Qt6L7+FdvoHNhUFsn/qnGmMcH52V6EgyvtgBYX2/AcKDIwzyVXbt3EADgg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8657 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On 2/12/2026 1:08 PM, Arunpravin Paneer Selvam wrote: > > > On 2/11/2026 11:01 AM, Sanjay Yadav wrote: >> Add missing kernel-doc for GPU buddy allocator flags, >> gpu_buddy_block, and gpu_buddy. The documentation covers block >> header fields, allocator roots, free trees, and allocation flags >> such as RANGE, TOPDOWN, CONTIGUOUS, CLEAR, and TRIM_DISABLE. >> Private members are marked with kernel-doc private markers >> and documented with regular comments. >> >> No functional changes. >> >> v2: >> - Corrected GPU_BUDDY_CLEAR_TREE and GPU_BUDDY_DIRTY_TREE index values (Arun) >> - Rebased after DRM buddy allocator moved to drivers/gpu/ >> - Updated commit message >> >> Cc: Christian König >> Cc: Arunpravin Paneer Selvam >> Suggested-by: Matthew Auld >> Signed-off-by: Sanjay Yadav >> --- >> include/linux/gpu_buddy.h | 122 +++++++++++++++++++++++++++++++------- >> 1 file changed, 102 insertions(+), 20 deletions(-) >> >> diff --git a/include/linux/gpu_buddy.h b/include/linux/gpu_buddy.h >> index 07ac65db6d2e..b06241c78437 100644 >> --- a/include/linux/gpu_buddy.h >> +++ b/include/linux/gpu_buddy.h >> @@ -12,11 +12,58 @@ >> #include >> #include >> >> +/** >> + * GPU_BUDDY_RANGE_ALLOCATION - Allocate within a specific address range >> + * >> + * When set, allocation is restricted to the range [start, end) specified >> + * in gpu_buddy_alloc_blocks(). Without this flag, start/end are ignored >> + * and allocation can use any free space. >> + */ >> #define GPU_BUDDY_RANGE_ALLOCATION BIT(0) >> + >> +/** >> + * GPU_BUDDY_TOPDOWN_ALLOCATION - Allocate from top of address space >> + * >> + * Allocate starting from high addresses and working down. Useful for >> + * separating different allocation types (e.g., kernel vs userspace) >> + * to reduce fragmentation. >> + */ >> #define GPU_BUDDY_TOPDOWN_ALLOCATION BIT(1) >> + >> +/** >> + * GPU_BUDDY_CONTIGUOUS_ALLOCATION - Require physically contiguous blocks >> + * >> + * The allocation must be satisfied with a single contiguous block. >> + * If the requested size cannot be allocated contiguously, the >> + * allocation fails with -ENOSPC. >> + */ >> #define GPU_BUDDY_CONTIGUOUS_ALLOCATION BIT(2) >> + >> +/** >> + * GPU_BUDDY_CLEAR_ALLOCATION - Prefer pre-cleared (zeroed) memory >> + * >> + * Attempt to allocate from the clear tree first. If insufficient clear >> + * memory is available, falls back to dirty memory. Useful when the >> + * caller needs zeroed memory and wants to avoid GPU clear operations. >> + */ >> #define GPU_BUDDY_CLEAR_ALLOCATION BIT(3) >> + >> +/** >> + * GPU_BUDDY_CLEARED - Mark returned blocks as cleared >> + * >> + * Used with gpu_buddy_free_list() to indicate that the memory being >> + * freed has been cleared (zeroed). The blocks will be placed in the >> + * clear tree for future GPU_BUDDY_CLEAR_ALLOCATION requests. >> + */ >> #define GPU_BUDDY_CLEARED BIT(4) >> + >> +/** >> + * GPU_BUDDY_TRIM_DISABLE - Disable automatic block trimming >> + * >> + * By default, if an allocation is smaller than the allocated block, >> + * excess memory is trimmed and returned to the free pool. This flag >> + * disables trimming, keeping the full power-of-two block size. >> + */ >> #define GPU_BUDDY_TRIM_DISABLE BIT(5) >> >> enum gpu_buddy_free_tree { >> @@ -28,7 +75,27 @@ enum gpu_buddy_free_tree { >> #define for_each_free_tree(tree) \ >> for ((tree) = 0; (tree) < GPU_BUDDY_MAX_FREE_TREES; (tree)++) >> >> +/** >> + * struct gpu_buddy_block - Block within a buddy allocator >> + * >> + * Each block in the buddy allocator is represented by this structure. >> + * Blocks are organized in a binary tree where each parent block can be >> + * split into two children (left and right buddies). The allocator manages >> + * blocks at various orders (power-of-2 sizes) from chunk_size up to the >> + * largest contiguous region. >> + * >> + * @private: Private data owned by the allocator user (e.g., driver-specific data) >> + * @link: List node for user ownership while block is allocated >> + */ >> struct gpu_buddy_block { >> +/* private: */ >> + /* >> + * Header bit layout: >> + * - Bits 63:12: block offset within the address space >> + * - Bits 11:10: state (ALLOCATED, FREE, or SPLIT) >> + * - Bit 9: clear bit (1 if memory is zeroed) > I think we should add > - Bits 8:9: reserved it should be -Bits 8:6: reserved > > Apart from that, looks good to me. > Reviewed-by: Arunpravin Paneer Selvam >> + * - Bits 5:0: order (log2 of size relative to chunk_size) >> + */ >> #define GPU_BUDDY_HEADER_OFFSET GENMASK_ULL(63, 12) >> #define GPU_BUDDY_HEADER_STATE GENMASK_ULL(11, 10) >> #define GPU_BUDDY_ALLOCATED (1 << 10) >> @@ -43,7 +110,7 @@ struct gpu_buddy_block { >> struct gpu_buddy_block *left; >> struct gpu_buddy_block *right; >> struct gpu_buddy_block *parent; >> - >> +/* public: */ >> void *private; /* owned by creator */ >> >> /* >> @@ -53,43 +120,58 @@ struct gpu_buddy_block { >> * gpu_buddy_free* ownership is given back to the mm. >> */ >> union { >> +/* private: */ >> struct rb_node rb; >> +/* public: */ >> struct list_head link; >> }; >> - >> +/* private: */ >> struct list_head tmp_link; >> }; >> >> /* Order-zero must be at least SZ_4K */ >> #define GPU_BUDDY_MAX_ORDER (63 - 12) >> >> -/* >> - * Binary Buddy System. >> +/** >> + * struct gpu_buddy - GPU binary buddy allocator >> + * >> + * The buddy allocator provides efficient power-of-two memory allocation >> + * with fast allocation and free operations. It is commonly used for GPU >> + * memory management where allocations can be split into power-of-two >> + * block sizes. >> * >> - * Locking should be handled by the user, a simple mutex around >> - * gpu_buddy_alloc* and gpu_buddy_free* should suffice. >> + * Locking should be handled by the user; a simple mutex around >> + * gpu_buddy_alloc_blocks() and gpu_buddy_free_block()/gpu_buddy_free_list() >> + * should suffice. >> + * >> + * @n_roots: Number of root blocks in the roots array. >> + * @max_order: Maximum block order (log2 of largest block size / chunk_size). >> + * @chunk_size: Minimum allocation granularity in bytes. Must be at least SZ_4K. >> + * @size: Total size of the address space managed by this allocator in bytes. >> + * @avail: Total free space currently available for allocation in bytes. >> + * @clear_avail: Free space available in the clear tree (zeroed memory) in bytes. >> + * This is a subset of @avail. >> */ >> struct gpu_buddy { >> - /* Maintain a free list for each order. */ >> - struct rb_root **free_trees; >> - >> +/* private: */ >> /* >> - * Maintain explicit binary tree(s) to track the allocation of the >> - * address space. This gives us a simple way of finding a buddy block >> - * and performing the potentially recursive merge step when freeing a >> - * block. Nodes are either allocated or free, in which case they will >> - * also exist on the respective free list. >> + * Array of red-black trees for free block management. >> + * Indexed as free_trees[clear/dirty][order] where: >> + * - Index 0 (GPU_BUDDY_CLEAR_TREE): blocks with zeroed content >> + * - Index 1 (GPU_BUDDY_DIRTY_TREE): blocks with unknown content >> + * Each tree holds free blocks of the corresponding order. >> */ >> - struct gpu_buddy_block **roots; >> - >> + struct rb_root **free_trees; >> /* >> - * Anything from here is public, and remains static for the lifetime of >> - * the mm. Everything above is considered do-not-touch. >> + * Array of root blocks representing the top-level blocks of the >> + * binary tree(s). Multiple roots exist when the total size is not >> + * a power of two, with each root being the largest power-of-two >> + * that fits in the remaining space. >> */ >> + struct gpu_buddy_block **roots; >> +/* public: */ >> unsigned int n_roots; >> unsigned int max_order; >> - >> - /* Must be at least SZ_4K */ >> u64 chunk_size; >> u64 size; >> u64 avail; >