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 D245EEA7943 for ; Wed, 4 Feb 2026 19:46:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8779710E14A; Wed, 4 Feb 2026 19:46:04 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="l1H4yzaQ"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0855B10E14A for ; Wed, 4 Feb 2026 19:46:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770234364; x=1801770364; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=dZsj2gkGB9FSM5IZGv0ylSdxssSZYZCGjrKbSj3RCX8=; b=l1H4yzaQKE2/zoPST/xx/nhqyJn0kHSJ8U5U8M24CP5TYFhIvlLWz8/C /uQHNqFQLnfduhGVjHycSE7/LnPBEgGmlU5NXoPqOUcNUTmOfWSjsnYQ/ H0wqbqf2agzm1wBfC8pUSPwDUDaQ3KCTwUzVllaTXRIlPuq9PR8DN+wdf nvZ/1yrRLgCbTkXmeaZUgZWRFuuYV+xb11c0rJrK7HmGxXeFhBkc/x3zc Rkd1aZ1oGSNacHYfNrXA8OVYt5+1DwTL0Vq8iKGIscVsO5gOHDorfjWki 691+PkSy/YJcoh3fMUq5EjRI2HjnKoFLO+SY7qbD+izrTtMNKhOcEHs0p Q==; X-CSE-ConnectionGUID: qxh8YTHZSdecUNlysR9Rnw== X-CSE-MsgGUID: jTsjziy+T4m6dqsnAZFU9A== X-IronPort-AV: E=McAfee;i="6800,10657,11691"; a="94079555" X-IronPort-AV: E=Sophos;i="6.21,273,1763452800"; d="scan'208";a="94079555" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2026 11:46:03 -0800 X-CSE-ConnectionGUID: tdKFMOcqQd2UmmSQmn/AnA== X-CSE-MsgGUID: X4Zoy1O4SBOXzsF1s/x/Bg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,273,1763452800"; d="scan'208";a="209555670" Received: from orsmsx901.amr.corp.intel.com ([10.22.229.23]) by orviesa010.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2026 11:46:03 -0800 Received: from ORSMSX901.amr.corp.intel.com (10.22.229.23) by ORSMSX901.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.35; Wed, 4 Feb 2026 11:46:03 -0800 Received: from ORSEDG902.ED.cps.intel.com (10.7.248.12) by ORSMSX901.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.35 via Frontend Transport; Wed, 4 Feb 2026 11:46:03 -0800 Received: from CY3PR05CU001.outbound.protection.outlook.com (40.93.201.1) by edgegateway.intel.com (134.134.137.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.35; Wed, 4 Feb 2026 11:46:03 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wP2UaMATWG+3S5mlNSLYWorMZHWbhvGGbA8dae89fRf7rMgNp8fLNWqLkyEMi9Ik0k1Gwb2FgrFtE4XfgwmwS6MGdlSH6AGJeN3qtJ2JVbqrmC8BUfHRs5pj1co/AM5u+qwoJx1bv9f/tOX2jyuE2kc6ZdEBs51VGhRilk2n03aV4a/GKcT/ak5McV9WTHC1Gya4JGbsK/nP67wLn3tT8lrfZWQ62R2vA5ccvrl93hVvU/8bj0WhkaPMM7rmwfKHYbYi4EtNgfjgW4DOOax0UPWGnnbdBMiHiPrnpX/H/guOMQS3KHdhhUCsOJ6gnbzMUBNrktrTYlNyfY7BUuLA6A== 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=14FyRP2VuBJMektSKf73JMLU9ii8VRjT46/7CPLAaoM=; b=ROt8We9uZUQIOoRf5S6q/QLlY511a5wBoD+MNwQY8M7E44aijDLZCP/ZdYzg6rQI8JLqduKlPgAcwqyjGielCCQVj/L+6501UIO6AKLstUNbgG+v7QW5eP8TFft/rHP+gZME5RGl3pcE7eZ5haj1hzbi4454kEW3t4zepUhoehOcyHGy4JQsLjx9E+T7/p8vnCUR8glCwk+NNqepz1F3HDwIgYPTUH375PO+aHRKlix8+Pc3kiKXfTLRUZaLvzFvutmogjVvlLWeWcKjR8XV28gX8b7p2BYnI19fRkz0ks2RB5XSGb+++aSvvbZ1txvnsfsZdjCIJxGyJNwwT/EepA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from BL3PR11MB6508.namprd11.prod.outlook.com (2603:10b6:208:38f::5) by CH3PR11MB8414.namprd11.prod.outlook.com (2603:10b6:610:17e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9587.12; Wed, 4 Feb 2026 19:45:59 +0000 Received: from BL3PR11MB6508.namprd11.prod.outlook.com ([fe80::53c9:f6c2:ffa5:3cb5]) by BL3PR11MB6508.namprd11.prod.outlook.com ([fe80::53c9:f6c2:ffa5:3cb5%3]) with mapi id 15.20.9564.016; Wed, 4 Feb 2026 19:45:59 +0000 Date: Wed, 4 Feb 2026 11:45:56 -0800 From: Matthew Brost To: Satyanarayana K V P CC: , Thomas =?iso-8859-1?Q?Hellstr=F6m?= , Michal Wajdeczko , Matthew Auld Subject: Re: [PATCH v2 1/3] drm/sa: Split drm_suballoc_new() into SA alloc and init helpers Message-ID: References: <20260204164642.3509298-5-satyanarayana.k.v.p@intel.com> <20260204164642.3509298-6-satyanarayana.k.v.p@intel.com> Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260204164642.3509298-6-satyanarayana.k.v.p@intel.com> X-ClientProxiedBy: SJ0PR13CA0039.namprd13.prod.outlook.com (2603:10b6:a03:2c2::14) To BL3PR11MB6508.namprd11.prod.outlook.com (2603:10b6:208:38f::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL3PR11MB6508:EE_|CH3PR11MB8414:EE_ X-MS-Office365-Filtering-Correlation-Id: dd75c050-73ca-4c00-20fa-08de6426052c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?iso-8859-1?Q?3qceJr8lpRNu849OcyHWJ0++ul9gyRROidSj5BjunmA3YGOgMni2ynQMPv?= =?iso-8859-1?Q?MXoKzVINGfdh0i4uJxnSFInzwrpYsTOm6TAbLjyVI2zHO/f2kevO+1urJL?= =?iso-8859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FDLYzyDfowNJgXOwvrAuTg1J?= =?iso-8859-1?Q?+TDriYF6z4JALSFAeO+FAYZ0pTHQYGjKyJ2z6DXh/s1cz5jF1Jwuw02eky?= =?iso-8859-1?Q?DB2wzfTE03VhwRP7bDRM4nduLBTSCSVyWiPubggz5ypmF8ZZeUhfn5//6m?= =?iso-8859-1?Q?CbPZKm+/9OrUM0zqN/NFfPUkCBG88e7XzMUZpyzeT59hlz6H96MZbEhUw6?= =?iso-8859-1?Q?Dwt3FMeaD5DHP8gvhUUG8BhXV+VAvOYhX4/LJtBP84AkfnsZG+I34K0PSj?= =?iso-8859-1?Q?BWUnnka5zZUsOgsK/YSS6aXHPHj1M2yaaZfwQZe0SC3fITZzbt3FUHJDWm?= =?iso-8859-1?Q?ipxuBHwPqnyI6syeRDqi8+lh/ZftLsVFlf5Ous5pmLZFniuwMzl2B85X3t?= =?iso-8859-1?Q?lmt7Egq5geM+/s9mEMSdTtBk7abLn6s6UTEF5DAueBW+GfVnNATg4hJXIN?= =?iso-8859-1?Q?ytEY08CYa9Ogrl5qbI7GR9FlNAUSrTTJzQBSznhSewLXYScOcNhokdTjaN?= =?iso-8859-1?Q?h94oY4FXn14c+dfA/5DQqSfySDGBAtqJDQ+Bvl6bHaq+DPOtQ0Cv7wIZxc?= =?iso-8859-1?Q?9vEllXwhNNrzzIv3nIuXIj2EEZBRAFm1lknBsLjYmtGBgd/CVoctpp4j7y?= =?iso-8859-1?Q?Qa6T5NiolD54Q=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL3PR11MB6508.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?SopJ0I9EJTqErgA9fNhjqVg03FZTM8y+nsTFxHk6PMtH+ACJ6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mA?= =?iso-8859-1?Q?KA590lajzQDbtrA8EeWMQGeTj7xr2xQ=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: dd75c050-73ca-4c00-20fa-08de6426052c X-MS-Exchange-CrossTenant-AuthSource: BL3PR11MB6508.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2026 19:45:59.5403 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ci9HdFOZrBhcEEny2XNa2pYBiEYgKzg7wWsI6FZnq8r2FZhj86S0BxIDsxOJdatIWTGkev2V3LeuVJPVEOwkMw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR11MB8414 X-OriginatorOrg: intel.com X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" On Wed, Feb 04, 2026 at 04:46:44PM +0000, Satyanarayana K V P wrote: > drm_suballoc_new() currently both allocates the SA object using kmalloc() > and searches for a suitable hole in the sub-allocator for the requested > size. Since kmalloc() may take internal locks, performing memory > allocation while holding the sub-allocator mutex can trigger lockdep > deadlock warnings. The above isn't quite right. By spliting the kmalloc step outside of the init step, this allows kmalloc to be reclaim unsafe (GFP_KERNEL) and the enter a reclaim unsafe section (e.g., take a reclaim tainted lock) during init. > > Fix this by splitting SA allocation from drm_suballoc_new(), separating > object allocation from sub-allocator initialization and hole selection. > I'd also mention that a timeout argument is provided in init too, with use cases in mind where the suballocator is sized to never fail finding a hole or if does, it won't hang forever. Matt > Signed-off-by: Satyanarayana K V P > Suggested-by: Matthew Brost > Cc: Thomas Hellström > Cc: Michal Wajdeczko > Cc: Matthew Auld > > --- > V1 -> V2: > - Splitted drm_suballoc_new() into drm_suballoc_alloc() and > drm_suballoc_init() (Thomas). > --- > drivers/gpu/drm/drm_suballoc.c | 135 +++++++++++++++++++++++++-------- > include/drm/drm_suballoc.h | 8 ++ > 2 files changed, 112 insertions(+), 31 deletions(-) > > diff --git a/drivers/gpu/drm/drm_suballoc.c b/drivers/gpu/drm/drm_suballoc.c > index 879ea33dbbc4..6f21f9e048d6 100644 > --- a/drivers/gpu/drm/drm_suballoc.c > +++ b/drivers/gpu/drm/drm_suballoc.c > @@ -123,7 +123,7 @@ static void drm_suballoc_remove_locked(struct drm_suballoc *sa) > list_del_init(&sa->olist); > list_del_init(&sa->flist); > dma_fence_put(sa->fence); > - kfree(sa); > + drm_suballoc_release(sa); > } > > static void drm_suballoc_try_free(struct drm_suballoc_manager *sa_manager) > @@ -293,45 +293,75 @@ static bool drm_suballoc_next_hole(struct drm_suballoc_manager *sa_manager, > } > > /** > - * drm_suballoc_new() - Make a suballocation. > + * drm_suballoc_alloc() - Allocate uninitialized suballoc object. > + * @gfp: gfp flags used for memory allocation. > + * > + * Allocate memory for an uninitialized suballoc object. Intended usage is > + * allocate memory for suballoc object outside of a reclaim tainted context > + * and then be initialized at a later time in a reclaim tainted context. > + * > + * @drm_suballoc_release should be used to release the memory if returned > + * suballoc object is in uninitialized state. > + * > + * Return: a new uninitialized suballoc object, or an ERR_PTR(-ENOMEM). > + */ > +struct drm_suballoc *drm_suballoc_alloc(gfp_t gfp) > +{ > + struct drm_suballoc *sa; > + > + sa = kmalloc(sizeof(*sa), gfp); > + if (!sa) > + return ERR_PTR(-ENOMEM); > + > + return sa; > +} > +EXPORT_SYMBOL(drm_suballoc_alloc); > + > +/** > + * drm_suballoc_release() - Release memory for suballocation. > + * @sa: The struct drm_suballoc. > + */ > +void drm_suballoc_release(struct drm_suballoc *sa) > +{ > + kfree(sa); > +} > +EXPORT_SYMBOL(drm_suballoc_release); > + > +/** > + * drm_suballoc_init() - Initialize a suballocation. > * @sa_manager: pointer to the sa_manager > + * @sa: The struct drm_suballoc. > * @size: number of bytes we want to suballocate. > - * @gfp: gfp flags used for memory allocation. Typically GFP_KERNEL but > - * the argument is provided for suballocations from reclaim context or > - * where the caller wants to avoid pipelining rather than wait for > - * reclaim. > * @intr: Whether to perform waits interruptible. This should typically > * always be true, unless the caller needs to propagate a > * non-interruptible context from above layers. > * @align: Alignment. Must not exceed the default manager alignment. > * If @align is zero, then the manager alignment is used. > + * @timeout: Time to a wait suballocation to become available. > * > - * Try to make a suballocation of size @size, which will be rounded > - * up to the alignment specified in specified in drm_suballoc_manager_init(). > + * Try to make a suballocation on a pre-allocated suballoc object of size @size, > + * which will be rounded up to the alignment specified in specified in > + * drm_suballoc_manager_init(). > * > - * Return: a new suballocated bo, or an ERR_PTR. > + * Return: zero on success, errno on failure. > */ > -struct drm_suballoc * > -drm_suballoc_new(struct drm_suballoc_manager *sa_manager, size_t size, > - gfp_t gfp, bool intr, size_t align) > +int drm_suballoc_init(struct drm_suballoc_manager *sa_manager, > + struct drm_suballoc *sa, size_t size, > + bool intr, size_t align, signed long timeout) > { > struct dma_fence *fences[DRM_SUBALLOC_MAX_QUEUES]; > unsigned int tries[DRM_SUBALLOC_MAX_QUEUES]; > unsigned int count; > int i, r; > - struct drm_suballoc *sa; > > if (WARN_ON_ONCE(align > sa_manager->align)) > - return ERR_PTR(-EINVAL); > + return -EINVAL; > if (WARN_ON_ONCE(size > sa_manager->size || !size)) > - return ERR_PTR(-EINVAL); > + return -EINVAL; > > if (!align) > align = sa_manager->align; > > - sa = kmalloc(sizeof(*sa), gfp); > - if (!sa) > - return ERR_PTR(-ENOMEM); > sa->manager = sa_manager; > sa->fence = NULL; > INIT_LIST_HEAD(&sa->olist); > @@ -339,6 +369,8 @@ drm_suballoc_new(struct drm_suballoc_manager *sa_manager, size_t size, > > spin_lock(&sa_manager->wq.lock); > do { > + long t; > + > for (i = 0; i < DRM_SUBALLOC_MAX_QUEUES; ++i) > tries[i] = 0; > > @@ -348,7 +380,7 @@ drm_suballoc_new(struct drm_suballoc_manager *sa_manager, size_t size, > if (drm_suballoc_try_alloc(sa_manager, sa, > size, align)) { > spin_unlock(&sa_manager->wq.lock); > - return sa; > + return 0; > } > > /* see if we can skip over some allocations */ > @@ -359,34 +391,75 @@ drm_suballoc_new(struct drm_suballoc_manager *sa_manager, size_t size, > fences[count++] = dma_fence_get(fences[i]); > > if (count) { > - long t; > - > spin_unlock(&sa_manager->wq.lock); > t = dma_fence_wait_any_timeout(fences, count, intr, > - MAX_SCHEDULE_TIMEOUT, > - NULL); > + timeout, NULL); > for (i = 0; i < count; ++i) > dma_fence_put(fences[i]); > > - r = (t > 0) ? 0 : t; > spin_lock(&sa_manager->wq.lock); > } else if (intr) { > + spin_unlock(&sa_manager->wq.lock); > /* if we have nothing to wait for block */ > - r = wait_event_interruptible_locked > + r = wait_event_interruptible_timeout > (sa_manager->wq, > - __drm_suballoc_event(sa_manager, size, align)); > + __drm_suballoc_event(sa_manager, size, align), > + timeout); > + spin_lock(&sa_manager->wq.lock); > } else { > spin_unlock(&sa_manager->wq.lock); > - wait_event(sa_manager->wq, > - drm_suballoc_event(sa_manager, size, align)); > - r = 0; > + t = wait_event_timeout > + (sa_manager->wq, > + drm_suballoc_event(sa_manager, size, align), > + timeout); > spin_lock(&sa_manager->wq.lock); > } > + r = (t > 0) ? 0 : !r ? -ETIME : t; > } while (!r); > > spin_unlock(&sa_manager->wq.lock); > - kfree(sa); > - return ERR_PTR(r); > + return r; > +} > +EXPORT_SYMBOL(drm_suballoc_init); > + > +/** > + * drm_suballoc_new() - Make a suballocation. > + * @sa_manager: pointer to the sa_manager > + * @size: number of bytes we want to suballocate. > + * @gfp: gfp flags used for memory allocation. Typically GFP_KERNEL but > + * the argument is provided for suballocations from reclaim context or > + * where the caller wants to avoid pipelining rather than wait for > + * reclaim. > + * @intr: Whether to perform waits interruptible. This should typically > + * always be true, unless the caller needs to propagate a > + * non-interruptible context from above layers. > + * @align: Alignment. Must not exceed the default manager alignment. > + * If @align is zero, then the manager alignment is used. > + * > + * Try to make a suballocation of size @size, which will be rounded > + * up to the alignment specified in specified in drm_suballoc_manager_init(). > + * > + * Return: a new suballocated bo, or an ERR_PTR. > + */ > +struct drm_suballoc * > +drm_suballoc_new(struct drm_suballoc_manager *sa_manager, size_t size, > + gfp_t gfp, bool intr, size_t align) > +{ > + struct drm_suballoc *sa; > + int err; > + > + sa = drm_suballoc_alloc(gfp); > + if (IS_ERR(sa)) > + return sa; > + > + err = drm_suballoc_init(sa_manager, sa, size, intr, align, > + MAX_SCHEDULE_TIMEOUT); > + if (err) { > + drm_suballoc_release(sa); > + return ERR_PTR(err); > + } > + > + return sa; > } > EXPORT_SYMBOL(drm_suballoc_new); > > diff --git a/include/drm/drm_suballoc.h b/include/drm/drm_suballoc.h > index 7ba72a81a808..cff0e14556d1 100644 > --- a/include/drm/drm_suballoc.h > +++ b/include/drm/drm_suballoc.h > @@ -53,6 +53,14 @@ void drm_suballoc_manager_init(struct drm_suballoc_manager *sa_manager, > > void drm_suballoc_manager_fini(struct drm_suballoc_manager *sa_manager); > > +struct drm_suballoc *drm_suballoc_alloc(gfp_t gfp); > + > +void drm_suballoc_release(struct drm_suballoc *sa); > + > +int drm_suballoc_init(struct drm_suballoc_manager *sa_manager, > + struct drm_suballoc *sa, size_t size, bool intr, > + size_t align, signed long timeout); > + > struct drm_suballoc * > drm_suballoc_new(struct drm_suballoc_manager *sa_manager, size_t size, > gfp_t gfp, bool intr, size_t align); > -- > 2.43.0 >