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 65854606A322 for ; Wed, 2 Dec 2026 21:20:06 +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=P9jtGuef Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AE7A3112574; Wed, 2 Dec 2026 21:20:00 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7987611257A; Wed, 2 Dec 2026 21:19:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796246395; x=1827782395; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=iTfSHp0Lr2vNzO/rQffVkX+aL6yfrL9WOGrYppd0R6k=; b=P9jtGuefoZkFvZ+nJTCnqNASAsXm0ECq6wBHOS2Ef+7II11T+aq9fcS5 lnWtYul+1GKSq6eBkxyDbF+ICZwctZbfdvLTWBGbpKSOL7/+txra3kN1y iHVnJmiMqrCX6ukIFGo5EFz4oJRT1MlNRcRM1+nMtqMUZi7ThUv83o81z ryoF3IsOLEhTlsQT3xgIOFCuWZsHZ618XToKoNqeEQY76rwGRqVmhBjYI UdLjsBcYkg1NE1aK7QL+0w6f8sW7qHZBsjxJi6E2DpGbWEVXFrrgYG5Sg jQyeVtYETIpRve6AftLma+YPlbbTo201/rgcYrU5/1s1t7gw/2v+l14qX g==; X-CSE-ConnectionGUID: dOA1Ho4YSdOFMGdA4AHapg== X-CSE-MsgGUID: HMLEJXEzT+G9xdSHf8u8Sw== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5186940" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5186940" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 13:19:54 -0800 X-CSE-ConnectionGUID: sz9YThJkQ8ybw5+sk+dv3w== X-CSE-MsgGUID: myT7jxIESZmVwW5FG+nMKA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="14012434" Received: from fmsmsx903.amr.corp.intel.com ([10.18.126.92]) by orviesa009.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 13:19:54 -0800 Received: from FMSMSX901.amr.corp.intel.com (10.18.126.90) by fmsmsx903.amr.corp.intel.com (10.18.126.92) 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:19:53 -0800 Received: from fmsedg903.ED.cps.intel.com (10.1.192.145) by FMSMSX901.amr.corp.intel.com (10.18.126.90) 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:19:53 -0800 Received: from BN8PR05CU002.outbound.protection.outlook.com (52.101.57.24) by edgegateway.intel.com (192.55.55.83) 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:19:52 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Tw+vfqE2szv9nJIxNxSYagU5QelgyBWzeDlU55SCxbQjB6gJ/J+1PEzYO8lU9WlnY8pjV4MlaqtgFQCOlRp7lHZ+Bn15U3nkPGZ6Dn+1iAYeW1OJMIo273qbEUWMbgT9HqyvV4LvP5Ckq8h1gpPVA0Dw0oxedFDoEIRGGutMQMGgb/wcBeGP2zB6o+Gh0YgvI86eju6aGDCUaz6cEUle1YgaOVey/k3G1mw/inOmNfsyvCXAXznNHXnUqMXtx+ekSWXqFe4aWWVwrATLuFRxTkvmlP667os2Ea8AyNKLPScbzDtVDDw+vntEDPRYn36BCJKpHMfHKr3HS7iECW120g== 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=DuShhtIdYhT9dXOLwyKTXX6LPmn7oNNwza5t/VsUHeE=; b=klOgBBnea6NH9EVfNd3Zv5AO6XY3dp4d9VKRQWjT4AksRxohKyBRyeF4FzeNuBsymlE4/DTXQsl+Yv2/nMF8VfLRSt498dUcOkH5DYC55w6Y4Wt34GjRMiKvaDWvlUp8XwXRxLus4rsakclK2SG1/r5t9Ed/T4ABfi7zE4rhoNhahr7bZaFC7Z+jWloO5ZtuJnPSrPTmY+UYFZ/wYmv7GPmuFr5MJd+mc4KeU8lZEiv+Jag4A4XeebCCEovx6d+ZpAincprKGbY53PkGKmidoSj4v5du3aW+Jb8DHSNh7XG3zCQEUF8tiXkvl3WNKumv+wvhaJVchuvdLAgoMCDNRA== 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 DM4PR11MB5232.namprd11.prod.outlook.com (2603:10b6:5:38b::14) 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:19:50 +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:19:50 +0000 Date: Wed, 2 Dec 2026 13:19:48 -0800 From: Matthew Brost To: CC: , Subject: Re: [PATCH v4 18/33] drm/xe: Add a page defragmentation worker Message-ID: References: <20261201234915.3305331-1-matthew.brost@intel.com> <20261201234915.3305331-19-matthew.brost@intel.com> Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: MW4PR04CA0136.namprd04.prod.outlook.com (2603:10b6:303:84::21) 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_|DM4PR11MB5232:EE_ X-MS-Office365-Filtering-Correlation-Id: ba889b16-273b-4e90-537c-08df50b9ffec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|23010399003|366016|1800799024|376014|5023799004|11063799006|4143699003|18002099003|6133799003|261009221227099003|261009223027099003|3023799007|22082099003|56012099006|261026140227099003|261026121527099003|261021121427099003|261021123027099003|261102123227099003|261028144727099003|10067099003|261022075727099003|261022105027099003; X-Microsoft-Antispam-Message-Info: R7F9L5h3EWMwCGbKjYiLxZ1mOJOS6iM1RS46rVls8TBnhvn+xuSo5oqguAI/qWMHQk580hmJhqWdivY3OUI3cDMGDlww8xFmskZ+SGQGwrvYPSrXgSHAxiat9qHan257hKZRkF9vfKBspppmmuODzzW8zeHycjfberN4mgSiyTsjIVrRF3kEK1uzX1Ep01gOhSoEjXxD9eK7IbUME1/AJ61mxDIoNW5bXUP7yxVE9JLz6IcVz9GWKaG/Ax06rhohDQrQRV5aZ433upQ2Qqme238OdfpLSWTQKWjZsZeo85+Tbgp7n8w44n68aJFkMvgqyV/HCCH4cB6WIfOA2Dlb2qqRDeAe9sqJRaPXhcLPQWoyxDTcmqdFWG34Wdin2wXs2GKtSPeSNQk3zh2QBRKYK0LHm8obbeSnCYaie1erR0Ahe5RA5Mwhh4BDALzZjbkujsb4r+4LqTF6tGA7EXi+7xcJdoi26xRjdWGFMBgGd4BodZX1bAWAEfbCpqf9Dko/vHG+EjdmMD2jkKTfEIiPe7KQTojRxmhp/9Va6M8OOldVIclBy5RBe+PMqGWb+Gg/Zz5bSSix4m92c/gqAQPmn1dhfShY+rhEKwgFBvPOnak= 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)(23010399003)(366016)(1800799024)(376014)(5023799004)(11063799006)(4143699003)(18002099003)(6133799003)(261009221227099003)(261009223027099003)(3023799007)(22082099003)(56012099006)(261026140227099003)(261026121527099003)(261021121427099003)(261021123027099003)(261102123227099003)(261028144727099003)(10067099003)(261022075727099003)(261022105027099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?pXBSx7z9OIgvrrcxbmEQkGfdIF17XY7QtHoWHoLY6HAM+nq6hgvrsqviAJ?= =?iso-8859-1?Q?/gGbkC3a+I6hO9jtxuweMO9UB0Hpr9y69CaccuyjKLq3iQf74mS0PePrhz?= =?iso-8859-1?Q?2/1xr5sLJjWcBnCZdEE4Mg9vsgWYlmsbr608l50aOEXZkt10HbCIXSTrsN?= =?iso-8859-1?Q?YlU6yoHzrrPogsghKE+4JmhMGC6zaVAiXDPKT43dMo/4fYNEHo/BBvtX+x?= =?iso-8859-1?Q?RZ0EIdtTFjj3CsWYre4Z9PaKTjaTdkXULMVvVxSeY0fzncHhvFXR2hiYk7?= =?iso-8859-1?Q?oo62vcACoueU+/GovUt65dUaUjuwFeDguJG5b7eJ0d3t1oSMiTvSUXUs5V?= =?iso-8859-1?Q?Jal1ENQL5tfaHz7UIoyuv95glJowbiwT3w7nNyv5OS7uwZFgwWprSdudXK?= =?iso-8859-1?Q?bqHLIrxPozfCvsGYaXp+u+VKb9mQhQEyWUK6EJDiHZaiy0oOeXD9//Xa/n?= =?iso-8859-1?Q?MWet2CPzsliYBRf/fHoMfjCQQhlxMoJ+88VAwBPswqlFZ9ZFHemTiyn4jX?= =?iso-8859-1?Q?TcjgNuJRPMgEQEOntk2zqT397SDlDKVY0B05Ss0/a1SiDdOHVaNykB3XKr?= =?iso-8859-1?Q?zn87SPF9bWsb0rCOOplOTfbion5V1q5zF7kkcpsNNDz1sQm21n+RmnvkNx?= =?iso-8859-1?Q?730cB/HJMy0KrdJm9WEnpjZCLghOCERJAVeAjgYZ94lXd9ZNU1wRVKtYne?= =?iso-8859-1?Q?V0sF160lKiNfVgAyHVoVoQ0qF0DLPXe9EraCpAxWGWwKheSuOeVozdg/cE?= =?iso-8859-1?Q?370CXcGbXPH8VBca9zfQJn26QojIPeS9537vXzfbXQktSz/JhK3Md8GuR0?= =?iso-8859-1?Q?vW/CXsRaPQQWV+c3y9lmnr1Bu+w9X4jFshFlHnEj2GT5kQ6hozYs72jBD8?= =?iso-8859-1?Q?R4YlgDSiE7hmEGp56XGDK6cHOghsY9yQi6oN5cpQP2JEeJOQbAOc31/on4?= =?iso-8859-1?Q?25Aeq7yzyHzsHkmtMyvYRL2j1gvgKsiwRpwH0QwyngTipULVhJyZCimw8s?= =?iso-8859-1?Q?6fSgQgqxY78X9QNWh8AKUh4S7a55/jQjgwmMKlrrtWdvjr5sUFXSLm1y+f?= =?iso-8859-1?Q?Z22Qj8Tddzntf8JLyLbvhsv8mIYKG5jRpM/y2ROxOD6qo3dLG1gtuhwTwA?= =?iso-8859-1?Q?B5uNVbX975VafHmtz1QcsZT7JPH05z1NrTN/Msc8vLJ5Ll3WvnvzzweeQ+?= =?iso-8859-1?Q?B6sL1aOKn7mQA3bPtdHdxTKuQyHxu9zvzlkT0J4BAwpKQ0mubNfuQlA3yU?= =?iso-8859-1?Q?vdKgoCHOYpfB9M4mb896YJ3dEXzgViMV4byoaq3ZJ9a/GEvsupC0phr1xf?= =?iso-8859-1?Q?KJoyuXO3akv3Gl0I2yqFusf68/isQsEU0edskFTq8GfweyLxHbeYkthvwQ?= =?iso-8859-1?Q?xPl8ibN+TQnBqnRJ4hl57drws+NDowGwNNCxNsZkW414f51E2Bi+YdvRzo?= =?iso-8859-1?Q?5OK/FoNXuVQ2KkP6aIj0DexFl0q5opElMLRfFVCBfJs8lviBoLUh2QGiNq?= =?iso-8859-1?Q?hLi5NUsI4D2SnUggLAtIcnlz3MMq0mRD64CVRyy+YeIirC3tiGB58RVjoV?= =?iso-8859-1?Q?Pdfq/+HyrwZ8GMr9ZcVafMCZh9vInWBLsbi2FubT04foaFZTllzrVdHqF4?= =?iso-8859-1?Q?53Nj2f3i8sHgiHHYZMRy8HTpG3irkMHb42eRmMWufmpq5nZi2jHHwcc5K9?= =?iso-8859-1?Q?3n2POttBKtU4+f9zQidIW07jnXsuH899HtYKbM/5iBD3JEz3CNPvk3FMCE?= =?iso-8859-1?Q?266mB3O+U+tuSrEH6BXLPyN9rIuYHEXoju4Ry0sHc8mcUNymKodoJkr57H?= =?iso-8859-1?Q?tY2Rw6l2hw=3D=3D?= X-Exchange-RoutingPolicyChecked: a/qAyRhj+tsLiPFTgfVFGftqqC+SkgYU3/SlQFx+8szny9gV5Co2yFXuXiI6i4np0mXt515/R9kq36bOmKxDqtntjqme05xktO2UIQjev192oFJ6I8UhZ33yMKXvkimjjQDTezgwRbfUL9NqSjefojhu2uyIrZj8/rtV42BhcXCl++8i4bV6RI2EXJoAYpJKYjOIyAeQSmWecNMpl0fNwOOOpKU9aQcZL92p/Eb+gn1Z0y5mkaxtAdNR4muB569f3E8Ub49jFtkwb/DBAmEzBSwED93z6nOvB2D042TsNei3owHwn9TaE5p9AZ8NGK8bpaSQhdfvkf9EbCNhfLDC1w== X-MS-Exchange-CrossTenant-Network-Message-Id: ba889b16-273b-4e90-537c-08df50b9ffec 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:19:50.4259 (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: z5966REJw5bpa+DKC2GAwvW8N+DWOi1HJWlm8YXTHNv5qVJgfMdoibW9HIUcofTSEU0xYZn80sWvPSKMM/DFPg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5232 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:23:05AM +0000, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 6 potential > issues to consider: > - [High] drm/xe: missing suspend and FLR synchronization in > xe_bo_defrag_worker() > - [High] drm/xe: TTM_PL_FLAG_TEMPORARY left on resource in > xe_bo_defrag_one() > - [High] drm/xe: defrag worker stalls on active device in > xe_bo_defrag_worker() > - [Medium] drm/xe: BO lost from defrag list on move failure in > xe_bo_move() > - [Medium] drm/xe: defrag worker not re-armed on xe_pm_runtime_suspend() > failure Above here all real. Will fix. > - [Low] drm/xe: unlocked interval_ms read and stale timer in > xe_bo_defrag_schedule() This one not real. Matt > -- > > commit 1c62d5735db470f5d28289297de300836bbb6ef4 > Author: Matthew Brost > > drm/xe: Add a page defragmentation worker > > This commit adds a per-device delayed worker that walks the list of buffer > objects backed by sub-optimal TT page orders and forces a TTM move to > reallocate their backing pages at the device's beneficial order, bounded > by a per-run byte budget. > > > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c > > index 689804916d6ba..37d13c7a715c7 100644 > > --- a/drivers/gpu/drm/xe/xe_bo.c > > +++ b/drivers/gpu/drm/xe/xe_bo.c > > [ ... ] > > > @@ -1201,17 +1238,85 @@ int xe_ttm_bo_purge(struct ttm_buffer_object *ttm_bo, struct ttm_operation_ctx * > > +static void xe_bo_defrag_schedule(struct xe_device *xe) > > +{ > > + schedule_delayed_work(&xe->mem.defrag.worker, > > + msecs_to_jiffies(xe->mem.defrag.interval_ms)); > > +} > > [Severity: Low] > Should xe_bo_defrag_schedule() read xe->mem.defrag.interval_ms under > xe->mem.defrag.lock (or pass the interval in) and use mod_delayed_work() > instead of schedule_delayed_work()? > > All writes to interval_ms hold xe->mem.defrag.lock, whereas > xe_bo_defrag_schedule() reads it after dropping the lock. In addition, if > a failed pass backs off interval_ms (up to 15 seconds) and schedules the > delayed work, and all BOs are then removed before a new BO is added via > xe_bo_defrag_add() (or xe_bo_defrag_resume() runs), interval_ms is reset > to 25 ms under the lock, but schedule_delayed_work() is a no-op while the > backed-off timer is still pending. > > [ ... ] > > > @@ -1301,6 +1415,211 @@ static void xe_bo_defrag_update(struct xe_bo *bo) > > +static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo, > > + u64 budget, u64 *consumed, bool *needs_more) > > +{ > > + struct ttm_operation_ctx ctx = { > > + .gfp_retry_mayfail = true, > > + .defrag = true, > > + .defrag_bytes_remaining = budget, > > + }; > > + struct ttm_buffer_object *ttm_bo = &bo->ttm; > > + struct ttm_placement placement; > > + struct ttm_place place; > > + int ret = 0; > > + > > + *consumed = 0; > > + *needs_more = false; > > + > > + 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; > > + } > > + > > + xe_place_from_ttm_type(ttm_bo->resource->mem_type, &place); > > + place.flags |= TTM_PL_FLAG_TEMPORARY; > > + placement.num_placement = 1; > > + placement.placement = &place; > > + > > + /* > > + * On success the move reallocates the backing at beneficial order and > > + * drops the BO from the defrag list. On failure the BO keeps its > > + * original backing and stays on the list for a later retry. > > + */ > > + ret = ttm_bo_validate(ttm_bo, &placement, &ctx); > > [Severity: High] > Does passing TTM_PL_FLAG_TEMPORARY in place.flags leave > TTM_PL_FLAG_TEMPORARY permanently set on ttm_bo->resource->placement after > ttm_bo_validate() succeeds? > > When xe_ttm_sys_mgr_new() allocates the replacement XE_PL_TT resource, > ttm_resource_init() copies place->flags into res->placement. Because the > defrag move calls xe_bo_move_notify() -> xe_bo_trigger_rebind(), the BO is > re-validated on the next submission or in preempt_rebind_work_func(). > ttm_resource_compatible() unconditionally returns false whenever > res->placement & TTM_PL_FLAG_TEMPORARY is set, forcing ttm_bo_validate() > to reject the freshly defragmented resource, tear down CPU mappings a > second time, and temporarily double-charge the BO's size against > xe->mem.sys_mgr while the old resource is still allocated (which can fail > with -ENOSPC/-ENOMEM when usage exceeds man->size and kill an LR VM in > preempt_rebind_work_func()). > > [Severity: Medium] > Can a BO be lost from xe->mem.defrag.list if ttm_bo_populate() succeeds > at the beneficial order during a defrag move, but xe_bo_move() subsequently > fails? > > In ttm_bo_handle_move_mem(), TTM stashes the old sub-optimal ttm_tt in > bo->defrag_old_tt, populates the new bo->ttm (with > TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED clear), and calls xe_bo_move(). If > xe_bo_move() fails (for example in xe_tt_map_sg(), xe_bo_move_notify(), or > xe_migrate_copy_defrag()), its error exit runs xe_bo_defrag_update(bo) > while bo->ttm.ttm still points to the new ttm_tt: > > drivers/gpu/drm/ttm/ttm_bo.c:ttm_bo_handle_move_mem() { > ... > ret = bdev->funcs->move(bo, evict, ctx, mem, hop); > if (ret) { > if (ret == -EMULTIHOP) > return ret; > goto out_err; > } > ... > out_err: > if (bo->defrag_old_tt) { > ttm_tt_defrag_disown_borrowed(bo->ttm, bo->defrag_old_tt); > ttm_bo_tt_destroy(bo); > bo->ttm = bo->defrag_old_tt; > bo->defrag_old_tt = NULL; > } > } > > Because xe_bo_defrag_update(bo) sees the temporary new ttm_tt before > out_err restores bo->ttm = bo->defrag_old_tt, it removes the BO from > xe->mem.defrag.list, and xe_bo_defrag_one() does not re-run > xe_bo_defrag_update(bo) after ttm_bo_validate() returns the error. > > > + > > + /* > > + * The pool allocator decremented defrag_bytes_remaining as it > > + * (re)allocated pages, so the unused budget tells us how much was spent. > > + * Only meaningful when the move succeeded. A successful move may spend > > + * nothing - e.g. when the object was already fully upgraded and every > > + * chunk is harvested (borrowed) from the old backing for free - so a > > + * zero spend is legitimate and must be charged as zero, not the whole > > + * budget. > > + */ > > + if (!ret) { > > + s64 spent = (s64)budget - ctx.defrag_bytes_remaining; > > + > > + *consumed = spent > 0 ? spent : 0; > > + } > > + > > + xe_dbg(xe, "Defrag attempt on BO size=%zu: ret=%pe consumed=%llu\n", > > + xe_bo_size(bo), ERR_PTR(ret), *consumed); > > + > > + if (!ret && ttm_tt_is_beneficial_order_failed(bo->ttm.ttm)) > > + *needs_more = true; > > + > > +unlock: > > + xe_bo_unlock(bo); > > + return ret; > > +} > > + > > +static void xe_bo_defrag_worker(struct work_struct *w) > > +{ > > + struct delayed_work *dwork = to_delayed_work(w); > > + struct xe_device *xe = > > + container_of(dwork, struct xe_device, mem.defrag.worker); > > + u64 defrag_bytes = 0; > > + bool requeue = false; > > + int idx; > > + > > + if (!drm_dev_enter(&xe->drm, &idx)) > > + return; > > + > > + if (!xe_pm_runtime_get_if_in_use(xe)) { > > + /* > > + * The device is (runtime) suspending/suspended. Do not spin a > > + * wakeup timer here: the worker is re-armed from the PM resume > > + * path (xe_bo_defrag_resume()) once the device is active again, > > + * so tracked BOs are picked up without polling while suspended. > > + */ > > + drm_dev_exit(idx); > > + return; > > + } > > [Severity: High] > Can xe_bo_defrag_worker() run concurrently with or after > xe_device_suspend() during system suspend, hibernation, or PCI FLR? > > xe_bo_defrag_schedule() queues xe->mem.defrag.worker on system_percpu_wq > (not WQ_FREEZABLE), and neither xe_pm_notifier_callback(), > xe_pm_suspend(), nor xe_device_suspend() cancels or disables the worker, > nor does xe_bo_defrag_worker() check try_wait_for_completion(&xe->pm_block). > During system suspend/hibernation, device_prepare() and > xe_pm_notifier_callback(PM_SUSPEND_PREPARE) hold runtime PM usage > references while runtime_status remains RPM_ACTIVE until > device_suspend_late(), and evicting user VRAM BOs to XE_PL_TT in > xe_bo_evict_all_user() / xe_bo_evict_all() can call xe_bo_defrag_add() and > arm the 25 ms timer: > > CPU0 (system suspend / FLR) CPU1 (system_percpu_wq) > xe_pm_notifier_callback() > xe_pm_runtime_get(xe) > xe_bo_evict_all_user(xe) > ... > xe_bo_defrag_add() > xe_bo_defrag_schedule() > xe_pm_suspend() > xe_device_suspend() > xe_bo_evict_all(xe) > xe_gt_suspend(gt) > xe_irq_suspend(xe) > xe_bo_defrag_worker() > xe_pm_runtime_get_if_in_use(xe) -> true > xe_bo_defrag_one() > ... > xe_migrate_copy_defrag() > <-- submits GPU job while GT > is suspended / kernel BOs > are evicted > > In addition, xe_pci_reset_done() calls xe_device_resume(xe, true) directly > rather than xe_pm_resume(), so xe_bo_defrag_resume(xe) is not called after > an FLR. > > [Severity: High] > Does using xe_pm_runtime_get_if_in_use(xe) here stall background > defragmentation while the device is active in its autosuspend window? > > Normal DRM ioctls hold a runtime PM usage reference only for the duration > of the syscall, leaving dev->power.runtime_status == RPM_ACTIVE with > dev->power.usage_count == 0 during the 1000 ms autosuspend delay. When > xe_bo_defrag_worker() fires 25 ms after an ioctl adds a BO, > xe_pm_runtime_get_if_in_use(xe) returns false whenever usage_count is 0 > (unlike xe_pm_runtime_get_if_active(xe)), and the worker exits without > rescheduling. Because the device is already RPM_ACTIVE, subsequent GPU > activity before autosuspend does not trigger xe_pm_runtime_resume() -> > xe_bo_defrag_resume(), and because xe->mem.defrag.list is already > non-empty, subsequent calls to xe_bo_defrag_add() see > list_empty(&xe->mem.defrag.list) == false and never re-kick the worker. > > > diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c > > index f73f68bd449b8..f76ab97ca49e2 100644 > > --- a/drivers/gpu/drm/xe/xe_pm.c > > +++ b/drivers/gpu/drm/xe/xe_pm.c > > [ ... ] > > > @@ -689,6 +691,8 @@ int xe_pm_runtime_resume(struct xe_device *xe) > > if (xe->d3cold.allowed) > > xe_late_bind_pm_resume(&xe->late_bind); > > > > + xe_bo_defrag_resume(xe); > > + > > out: > > xe_rpm_lockmap_release(xe); > > xe_pm_write_callback_task(xe, NULL); > > [Severity: Medium] > If xe_bo_defrag_worker() fires while runtime_status is RPM_SUSPENDING and > exits early, what re-arms it if xe_pm_runtime_suspend() subsequently fails? > > When xe_pm_runtime_suspend() fails and unwinds through out_resume or out, > rpm_suspend() reverts dev->power.runtime_status back to RPM_ACTIVE without > calling xe_pm_runtime_resume(), leaving a non-empty xe->mem.defrag.list > without a scheduled worker until the next full runtime suspend/resume > cycle. > > -- > Sashiko AI review · https://sashiko.dev/#/patchset/20261201234915.3305331-1-matthew.brost@intel.com?part=18