From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80AD8606A32C for ; Wed, 2 Dec 2026 21:52:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=B3D2nef9 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D37D610E641; Wed, 2 Dec 2026 21:52:29 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by gabe.freedesktop.org (Postfix) with ESMTPS id AE8B310EAEA; Wed, 2 Dec 2026 21:52:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796248344; x=1827784344; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=y14ejv7FILSDiVBLAvrPYD+e+NnNreRMk5rGLk7I/0k=; b=B3D2nef9pqRJFeZr2Pq407W2YP9wP6hVVyXHcq5Nd3p7mdCxz+SoSyhI 6zoNRE8SS8kY6Ru6bTLCwvg5Dj0AIxd1W3yNOvqrk1J5t2+jThAF0dN4z GkmAP65cgRR4+ttwT4qSlaaa0P+iS/1Q8jvCCBbibLoyJNQ7EK35mcqj9 3CF0ccj4zE23YW+d6kEE5iFf+XNYDR7V8//AX2QBInS/Hx5oX9rkDxcHs sYcpnkokKTLb11JRTo1ppiFhciF8R4dTDudrZcQRhC8R3wMUgETY+DcZw bD//uh8M+GoiHn/5oemJfwb1NitMWOQnJ202x9+imhXk8QCxlxii1tve9 g==; X-CSE-ConnectionGUID: olT2spnlReqZySyj3714Rg== X-CSE-MsgGUID: mqqyhXLBQUKxqT1Wy9HtEA== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5035475" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5035475" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 13:52:22 -0800 X-CSE-ConnectionGUID: JoLN8knTQKStkzhCLLuWIQ== X-CSE-MsgGUID: MFW9Q0miQciy15sFY+6/qA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13659443" Received: from orsmsx901.amr.corp.intel.com ([10.22.229.23]) by orviesa007.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 13:52:23 -0800 Received: from ORSMSX902.amr.corp.intel.com (10.22.229.24) 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.57; Wed, 2 Dec 2026 13:52:22 -0800 Received: from ORSEDG903.ED.cps.intel.com (10.7.248.13) by ORSMSX902.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Wed, 2 Dec 2026 13:52:22 -0800 Received: from SJ2PR03CU001.outbound.protection.outlook.com (52.101.43.63) by edgegateway.intel.com (134.134.137.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 13:52:22 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DgYuJO1RY/mYd4JFZnfE96BjHsw7HVAIrPhzJ8jQZo9JYeYzBjusdbJt33l/FOSzCxKXdRjivwwpi75BIp68zYMryUU3CfvEgy1+qufRJ+0m7ozmMt9ERv53H/rlGMi8nLmigxD8BcLvUiiug20uMLB5EhmZrU/nqkgrOYRfCxFHocQkmdnBImne/v+CPLCGYsNgghHNWCfjYy0v7JfNvxbGA8oZ4eSX8vdcJEMNK2FXiFUZTw5zjObQ4cbHN4anGacJGXu9L0pC7gpIvSv7I2X9j5xwPlGZPXAwjqzue9vp1clR1WhMfmd91G5kJNwGx86JaT9LCCIp8/CYKD0ByQ== 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=oKZ0w39QbcnJCvlMA72iPMlPg2gI8OgCsgjrvncIyqY=; b=yIVNIv2oXqNibgEp4EQlyR3gzAVCKfK4PgX9ftCK1qj5tOdqcMyFr/DMI6iGfMEp2N9/SSIw5yZ7dY+WgA55qXFhXT8QzlhanjbwoLRqCDsHUGrNGNyQEqZbosm79iP4rMUGB2c1BmgqXFy5IOyRb82S4D0et1YcyGWn0XakHEIjCFbYRlr5Cx3/PlUZIR/iHcDZtfveKzlRFpvyMpB3LyDq7WBwohVxFjR/0dswC/fT/i5zzXfJxmj0y675qgv0oPz8ZeG78gYfiNduXeMxNBkAdq0ZxpLrZe1vRYB3ur55Os3d6AhZZdlMbwOwad2zcCT6vLTjsUUJZG73gGcMug== 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: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from CO1PR11MB4787.namprd11.prod.outlook.com (2603:10b6:303:95::23) by DS6PR11MB622039.namprd11.prod.outlook.com (2603:10b6:8:52b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 21:52:18 +0000 Received: from CO1PR11MB4787.namprd11.prod.outlook.com ([fe80::e7eb:a872:53d1:21fd]) by CO1PR11MB4787.namprd11.prod.outlook.com ([fe80::e7eb:a872:53d1:21fd%4]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 21:52:18 +0000 Date: Wed, 2 Dec 2026 13:52:16 -0800 From: Matthew Brost To: CC: , Subject: Re: [PATCH v4 21/33] drm/xe: Defrag using out-of-lock page preallocation Message-ID: References: <20261201234915.3305331-1-matthew.brost@intel.com> <20261201234915.3305331-22-matthew.brost@intel.com> Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: MW4PR04CA0337.namprd04.prod.outlook.com (2603:10b6:303:8a::12) To CO1PR11MB4787.namprd11.prod.outlook.com (2603:10b6:303:95::23) X-Archived-By: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR11MB4787:EE_|DS6PR11MB622039:EE_ X-MS-Office365-Filtering-Correlation-Id: 1ee85161-d05b-43fb-3a24-08df50be890f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|366016|23010399003|11063799006|4143699003|6133799003|261009223027099003|261009221727099003|261009220027099003|261009221227099003|261009223327099003|18002099003|22082099003|56012099006|261102123227099003|261026121527099003|261028144727099003|261026140227099003|261021121427099003|261022075727099003|10067099003|261022105027099003; X-Microsoft-Antispam-Message-Info: LSXs6PSQ9dmmOi4wFuzaDQpWgYKaySPLdQQpHrJlcZQmFJcz7qcInHJ54jeArMC977DfPiDxL/TC4AiO7d+NnsebnrMinbF5KfuC21uMLT2mpqNG/lyewDmdsK+RsHTfaS+9Cy42OqW+V2sotX6geIjw8e7iaFSdFbACWLBFgoOyshxHse/gmQeZsuVWLZtmWG1tzFl/4cwW34eOEyMudsuS+1M6RDV8lw15xeOnHsy4WnXap+3z2Em+0JsKPECwEP2DFfyAzHv3WIt8vGBbHV+8JofnI54gCyOaWltMr+rwqpnEC2GEo3YWBPtpdsS6JaLc2YSL3X2soVQliMn2U2/73+9otozyXYj4vmtIbH7siA92Cp5IQE7qZMZYeilEfCuGW7tpQq4TV4Q4hTTj4whWHhqfAO6Zfe3OOiudlLZbtSYJSzooWMacZoGddOmTIwjeNSRTm+35onMwFw1V3pO3ZM8JWPZN4iQ8LRC1yLhuF5qqEPIbr+cNmUZyGwadnjJOlDhAW6fnOljdskHgfd7JMCeuCVkXUW0nyWhK6jNYLy1EvFirLP7XVhyxdUEpbykWnGN5Pg0ypPP4/JLsrxze5vG9wTKC6O3aAiJ6dnM= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO1PR11MB4787.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016)(23010399003)(11063799006)(4143699003)(6133799003)(261009223027099003)(261009221727099003)(261009220027099003)(261009221227099003)(261009223327099003)(18002099003)(22082099003)(56012099006)(261102123227099003)(261026121527099003)(261028144727099003)(261026140227099003)(261021121427099003)(261022075727099003)(10067099003)(261022105027099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?s6AEnxxSTI3h9/ozncrf9b0/lZaqZVvAJh8Gh5D6NeerO83EyX+mG7O4sg?= =?iso-8859-1?Q?6+QM9d7Vm5F9daqAvYJtjygnyImqv1qWI31Drr7BqEtrxWDFLCSwUl/Nfa?= =?iso-8859-1?Q?GPpfUtbAaWexqrOJdCmLT8hd2ngj6vNRvFy6La9FkOIJftqkppOt8LSkiW?= =?iso-8859-1?Q?Fcf5KY9hdwVTl2kdLA8Iz0ojNBY3U8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hNu19hCoq5TI5Z5c33mCa+buSQnKVlNe+LRe+Qum0bdv8dKuOQ1jy46DBjlu1PGekc3DKPmSrbgInEBP4YhvkQ7FxeWd91lcuudVvTa7bTvBrYnant+A+7u/7ed7PVhDdeaL5G0aNE+r7MZwrJ95k1QCbzpdP6Z9QXv8gbtDt9Uhg4W6reez8cwt6++0mO/x0yCJDdlktZijNag== X-MS-Exchange-CrossTenant-Network-Message-Id: 1ee85161-d05b-43fb-3a24-08df50be890f X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4787.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 21:52:18.4633 (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: RsvuYto3NNnGT4Ns6H2RroU9ItY9w2S5b2AELkKjb2N6ox7n6fWUwfoaLJxpC/oE4hE0uEsVy2PzefmLW68uYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS6PR11MB622039 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "dri-devel" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Wed, Dec 02, 2026 at 12:24:29AM +0000, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 3 potential > issues to consider: > - [Medium] drm/xe: uninitialized prealloc bag used when want is 0 in > xe_bo_defrag_one() > - [Medium] drm/xe: TTM WC/UC page pool bypass in xe_bo_defrag_one() > preallocation > - [Low] drm/xe: xe_bo_defrag_one() over-preallocates 2MB chunk on > unaligned or CCS tail These are valid but one way around fixed by changes suggest by Sashiko on earlier patches. Matt > -- > > commit 02f1b3d24f540fb63f990c585582303a91d27ddc > Author: Matthew Brost > > drm/xe: Defrag using out-of-lock page preallocation > > This commit converts xe_bo_defrag_one() to preallocate beneficial-order > pages and apply CPU cache mode changes outside the BO dma-resv lock before > validating the buffer object. > > > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c > > index 9725c79af5f1f..3ea90cfb27e41 100644 > > --- a/drivers/gpu/drm/xe/xe_bo.c > > +++ b/drivers/gpu/drm/xe/xe_bo.c > > @@ -1468,16 +1468,56 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo, > > .defrag_bytes_remaining = budget, > > }; > > struct ttm_buffer_object *ttm_bo = &bo->ttm; > > + struct ttm_pool *pool = &ttm_bo->bdev->pool; > > + struct ttm_pool_prealloc pp = {}; > > struct ttm_placement placement; > > struct ttm_place place; > > + enum ttm_caching tt_caching; > > + unsigned int order, want = 0; > > int ret = 0; > > > > *consumed = 0; > > *needs_more = false; > > > > + /* > > + * Phase 1: under the BO lock, re-check eligibility and estimate how > > + * many beneficial-order chunks the move will (re)allocate, bounded by > > + * the run's byte budget. Then drop the lock so the high-order, possibly > > + * reclaim/compaction stalling allocations happen unlocked. > > + */ > > + xe_bo_lock(bo, false); > > + if (!xe_bo_needs_defrag(bo)) { > > + xe_bo_defrag_remove(bo); > > + xe_bo_unlock(bo); > > + goto out; > > + } > > + tt_caching = bo->ttm.ttm->caching; > > + order = ttm_pool_prealloc_order(pool); > > + if (order && ttm_bo->ttm) { > > + u32 suboptimal = ttm_tt_suboptimal_pages(ttm_bo->ttm); > > + u64 cap = min_t(u64, budget, xe_bo_size(bo)) >> PAGE_SHIFT; > > + > > + /* Prealloc only the beneficial-order chunks the move replaces. */ > > + want = DIV_ROUND_UP_ULL(min_t(u64, suboptimal, cap), 1UL << order); > > [Severity: Low] > Does DIV_ROUND_UP_ULL() over-preallocate an extra beneficial-order chunk > when the BO has an unaligned trailing tail or FlatCCS extra_pages? > > __ttm_pool_alloc() counts every chunk with it.order < it.beneficial_order > in nr_suboptimal_pages, including any trailing pages where the remaining > size is smaller than 1 << order. During a defrag move, > ttm_pool_iter_reuse_old() always harvests that sub-beneficial tail from > defrag_old_tt rather than consuming a preallocated beneficial-order chunk: > > drivers/gpu/drm/ttm/ttm_pool.c:ttm_pool_iter_reuse_old() { > ... > if (harvest_order < it->beneficial_order && > it->order >= it->beneficial_order) > return TTM_POOL_ITER_FILL; > ... > } > > Rounding suboptimal up by 1 << order allocates and cache-converts an extra > 2MB chunk that __ttm_pool_alloc() cannot consume and that > ttm_pool_prealloc_fini() immediately restores to write-back and frees. > > > + } > > + xe_bo_unlock(bo); > > + > > + /* Phase 2: preallocate outside the lock; */ > > + if (want) { > > + ret = ttm_pool_prealloc_fill(pool, tt_caching, &pp, want); > > + if (ret || !pp.count) { > > + ret = ret ?: -ENOMEM; > > + xe_gt_stats_incr(xe_root_mmio_gt(xe), > > + XE_GT_STATS_ID_DEFRAG_FAILED_COUNT, 1); > > + goto out_err; > > + } > > + } > > [Severity: Medium] > Does preallocating via ttm_pool_prealloc_fill() bypass the TTM > write-combined and uncached page pools? > > Previously, ttm_bo_validate() ran with ctx.prealloc == NULL, so > ttm_pool_iter_acquire_page() drew pre-cached beneficial-order pages from > ttm_pool_select_type() / ttm_pool_type_take() before falling back to > ttm_pool_alloc_page(). Unlike ttm_pool_prealloc_fill_full() (which calls > ttm_pool_take_page()), ttm_pool_prealloc_fill() calls > ttm_pool_alloc_page() directly and then runs > ttm_pool_prealloc_apply_caching(), while ttm_pool_prealloc_fini() frees > unconsumed pages back to the buddy allocator via ttm_pool_free_page(). > > For write-combined or uncached BOs on x86, defragmentation now ignores > idle beneficial-order pages already sitting in the TTM pool, forcing fresh > order-9 buddy allocations and synchronous cross-CPU PAT/TLB shootdowns via > set_pages_array_wc() or failing with -ENOMEM when buddy allocation fails. > > > + > > + /* > > + * Phase 3: re-take the lock, re-check, and validate using the prealloc. > > + */ > > xe_bo_lock(bo, false); > > > > - /* Re-check eligibility under the BO lock. */ > > if (!xe_bo_needs_defrag(bo)) { > > xe_bo_defrag_remove(bo); > > goto unlock; > > @@ -1487,6 +1527,7 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo, > > place.flags |= TTM_PL_FLAG_TEMPORARY; > > placement.num_placement = 1; > > placement.placement = &place; > > + ctx.prealloc = &pp; > > [Severity: Medium] > If want is 0, ttm_pool_prealloc_fill() is skipped and pp remains > zero-initialized with pp.caching == ttm_uncached. Won't passing > ctx.prealloc = &pp to ttm_bo_validate() then trigger WARN_ON(ctx->prealloc > && ctx->prealloc->caching != tt->caching) in ttm_pool_alloc() and fail > with -EINVAL? > > A populated TT can have TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED set while > ttm_tt_suboptimal_pages() is 0 after a swap-in retry in > ttm_pool_restore_and_alloc(), because ttm_pool_restore_commit() snapshots > restore->snapshot_alloc before __ttm_pool_alloc() increments > alloc->nr_suboptimal_pages and retry does not clear > TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED. When this happens on a > ttm_cached or ttm_write_combined BO, ttm_bo_validate() fails with -EINVAL > and leaves the BO at the head of xe->mem.defrag.list, blocking > defragmentation of all BOs behind it and repeating the warning on every > worker run. Setting ctx.prealloc = want ? &pp : NULL (or initializing > pp.caching = tt_caching) avoids this. > > -- > Sashiko AI review · https://sashiko.dev/#/patchset/20261201234915.3305331-1-matthew.brost@intel.com?part=21