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 14E40606A322 for ; Wed, 2 Dec 2026 20:44:30 +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=amWkYMzY Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CA59110E62D; Wed, 2 Dec 2026 20:44:24 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id CC08B10E62D; Wed, 2 Dec 2026 20:44:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796244259; x=1827780259; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=b9d9F7Gn3L/j4nZK5quGhCtSjIlAf8osF5lWiJyF2z8=; b=amWkYMzYOQQSUrwC6Isjp8LC8PvH5jJ40n0xS9ZSLRCCVcRXHNWFBUjv to0HpZAQJ7Qsre/sbCeVqa+eRDLlSJvQ5AvqtwE42hlxX8AcSCQOvj6+z s/NBlUJ1NSBgEqk+PJECGoR8fxIp6tiba4qKV1Gm+39GOZnX7qBFdo96c LFEtxVT+5rOOhGIG8WbkfvzyRkaYerOXRalW/wLTx+4KKxIMw6xDfv0UN Gq/NbeuZmGxWIrLbk+a6rhUgWfIqClU/xeoyjQz1NVYYMtlBTOGmzWgAP QkA7r6ATCQc/iXEJyYOLPSgY6lfBA2C7jJyoyH5j8kD90kU//x7FMSqM5 g==; X-CSE-ConnectionGUID: 54pxZ6qSRy6KzR/cRcYZbQ== X-CSE-MsgGUID: /PQ0zL/JTkaBOIcfu6vPsQ== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5079847" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5079847" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 12:44:18 -0800 X-CSE-ConnectionGUID: O/XJkXXKSQyG3gBkRe+wig== X-CSE-MsgGUID: yQzMbUQEQ42O/4Hqg+HMhg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13642489" Received: from fmsmsx902.amr.corp.intel.com ([10.18.126.91]) by orviesa007.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 12:44:18 -0800 Received: from FMSMSX903.amr.corp.intel.com (10.18.126.92) by fmsmsx902.amr.corp.intel.com (10.18.126.91) 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 12:44:17 -0800 Received: from fmsedg901.ED.cps.intel.com (10.1.192.143) 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 via Frontend Transport; Wed, 2 Dec 2026 12:44:17 -0800 Received: from PH7PR06CU001.outbound.protection.outlook.com (52.101.201.54) by edgegateway.intel.com (192.55.55.81) 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 12:44:17 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HSapRw7M47Q4+JGhM0hgNO/RUcGSxrz2zco/8YzrK0v9/kvMzYaL7KXy2lPfjltKu9ZL5+ndXVvzSFv4Vgwqy+mkDBaXGph1QnJ/zUbyeCC+rF6lTj+Oty3u98SQdsIkFWtCPU3zasw2aq9AVfLGwWBSOZg8+dUreoipG+HmRo5fxhsIiCTbu7YM2m+vxT7gRfP4T71+JvU2oYTIZisZe6QgpHquVkLet3wO+OJjMc8wQHdjxoIiPuX3MbRb7c+JXHgpb5U6G4kYRrpKSXjmGHALYYI3hTh6gWuMdaiTFRNzyd2ZB2T8UHylMVkVd7Qstoo5JVE57VEOaWCLm0b4Gg== 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=M/DZ/efi1ZMc4FpFpwjzyTa1P6AkEuL0luBHjstUPc8=; b=tdHwHzSl4mpnbimKxvmC3nnKaaApBgAuQW3Ddg4s1AvjUL0iM6eiBR8LDAJV5xLYfg/azihTpvprteFnk7tI7CcVj9d4vS/RcB6LyGbRKATV+9CQcSJ47GWk74olOOxkeA7yQPO86RSgNN1Yu0cNpVCFYkDrj9SSknwB+gETY1X1ffUXRNoFMkxQzq54OOdzpMVF3XWGNx2xbzOPT1/0/i4dUHIldXCFw5nY8vGRnicHuW6Prmv7RpnjeokH4LcjZfahh9YuXh87PYFVDGtVBOQM43/uEXW8nYf03OGxsthzdKQvllnVg5Dqr/giOXSpGMlDt5jc2FqtYSdCpS12Dg== 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 PH0PR11MB4853.namprd11.prod.outlook.com (2603:10b6:510:40::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.11; Wed, 2 Dec 2026 20:44:15 +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 20:44:14 +0000 Date: Wed, 2 Dec 2026 12:44:12 -0800 From: Matthew Brost To: CC: , Subject: Re: [PATCH v4 14/33] drm/xe: Track BOs backed at a sub-optimal page order Message-ID: References: <20261201234915.3305331-1-matthew.brost@intel.com> <20261201234915.3305331-15-matthew.brost@intel.com> Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: MW4PR04CA0265.namprd04.prod.outlook.com (2603:10b6:303:88::30) 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_|PH0PR11MB4853:EE_ X-MS-Office365-Filtering-Correlation-Id: 65756013-46f4-4da3-ab7a-08df50b50701 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|23010399003|1800799024|376014|18002099003|22082099003|10067099003|56012099006|261026140227099003|261026121527099003|261021121427099003|261102123227099003|261028144727099003|261022075727099003|261022105027099003|261009223027099003|261009221227099003|4143699003|11063799006|6133799003; X-Microsoft-Antispam-Message-Info: PfByR+su9PgFCfK5qBl/+ezIBlaheRWek1BT7yBQZWH4Gva0WnD6fk4lCNPtDaN6uJ2/yoybgPWdQ/dqKnqE4tZKUH/lV/sRxSr1WcraepSNSp10LuRAat8N+I+oVQltjMMNAEenM7ESTXdGXU4Xk66RmfXyW3wIMGq9t3RTD0hICcG14CBiIuuXx+A6Qb1uUiTzKNljwaQwZOIIvSC/IVlbJbsv5+pMu00/nU6lEnEX42pW7tlVrIMObTMeeWsgz7KAKbLvQJaT5DLuG4Dka9+xSBVyGfOQFCYKyR1l8VFggGn/TsfCN6IrxdIW88SycToXSNooYLczgu6g1vW99+1Q6MbZRkmZchWqy6of6+6CmZnvjJdeqW8fxb2dyBWN/qq76Q6XzgyDqzHf0mj05S0pL2l889jcpOPB9I+ZrtmjTPQ6zQewr31Tad3Gr6b2ElkpPd2nmuQJYz+E5zNhzMe51+cShhgNvHQNPR3KDjpq5e6FEtGr0TTnX6eMAkE7jTPi7dqcgixVznnAjxb2zxrNLsdt9xFDWKAhOyh5GXwIJR2w9DShpyJy4jkT4hhbv4CCsQ6mvpsOQnz7KAI10Fehwmk2fGwWsKHy+nk0uQw= 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)(366016)(23010399003)(1800799024)(376014)(18002099003)(22082099003)(10067099003)(56012099006)(261026140227099003)(261026121527099003)(261021121427099003)(261102123227099003)(261028144727099003)(261022075727099003)(261022105027099003)(261009223027099003)(261009221227099003)(4143699003)(11063799006)(6133799003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?DOamaPLvp0hvTXOwAETyxhd8CXTUEPfBdmzfcMlozoz7/z7DUFPLsqrQpV?= =?iso-8859-1?Q?dfUKcqsfhqIbY/t0rTlVOnkGOAKGftfsWZHjdtbdm1O+Rtm+KPUo7y2JOa?= =?iso-8859-1?Q?DloLpdfvvO/kGl6b+0lyU13s/k1lgkR/JuuRFUH28c+0PLzeZuF63mULd5?= =?iso-8859-1?Q?t+IVy63lizVJ9NtG6MlGlF0ETOWzUWDPlxUB7Y45JVMBneiwRO4VqF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0kjK3AKCeCl1bMQQ0KtI5Z5rY4gHsoiWyZtpCgUzMZegrwAsTZpbMVR6fEPPs5AreUrkuGZtR0CxYlOeYCHFODzjEEOCoatHrG1pAuTKpMfvw4gRusD9EfaYh13XfKuUXJtrkO/oW4iL9cqLcr7Fb3goqtKHkGRyetwCX0b/1eK8d+3A== X-MS-Exchange-CrossTenant-Network-Message-Id: 65756013-46f4-4da3-ab7a-08df50b50701 X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4787.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 20:44:14.8393 (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: 5F+IDwWbfNiWDK+XH55Y7pMHtDwjuMmz64WZ3CQAmaTUNIpaVtBI1/arkeoLVLDEajBL2+hENfT4ryj3HT4ZHQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB4853 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-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" 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:17:07AM +0000, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 4 potential > issues to consider: > - [Medium] drm/xe: display fb pin/unpin in xe_bo_pin_account() bypasses > defrag tracking > - [Medium] drm/xe: unconditional xe_bo_defrag_update() in xe_bo_move() > drops failed BO > - [Medium] drm/xe: xe_bo_fault_migrate() contends on defrag lock and > misses SYSTEM BOs > - [Low] drm/xe: redundant xe_bo_defrag_remove() in xe_ttm_bo_purge() and > stale docs These are all valid aside from SYSTEM comment. Will fix. Matt > -- > > commit cb4a8fed0f656c3f34b03b2d3b239e7886b9b49f > Author: Matthew Brost > > drm/xe: Track BOs backed at a sub-optimal page order > > This commit adds per-device tracking for buffer objects whose backing TT > pages were allocated below the pool's beneficial order, maintaining them on > a device defrag list across moves, faults, pin/unpin, and purge transitions. > > > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c > > index 920b7b6094582..0351079eae64e 100644 > > --- a/drivers/gpu/drm/xe/xe_bo.c > > +++ b/drivers/gpu/drm/xe/xe_bo.c > [ ... ] > > @@ -1171,9 +1175,116 @@ int xe_ttm_bo_purge(struct ttm_buffer_object *ttm_bo, struct ttm_operation_ctx * > > /* Commit the state transition only once invalidation was queued */ > > xe_bo_set_purgeable_state(bo, XE_MADV_PURGEABLE_PURGED); > > > > + /* > > + * The backing store is gone, so the BO no longer needs defrag. Drop it > > + * from the defrag list here so the count stays accurate even for purge > > + * paths that don't pass through xe_bo_move() (e.g. swap_notify). > > + */ > > + xe_bo_defrag_remove(bo); > > + > > return 0; > > } > > > > +/** > > + * xe_bo_defrag_init_early() - Initialize the device defrag BO tracking > > + * @xe: The xe device > > + * > > + * Initialize the list, lock and count used to track BOs whose backing TT > > + * pages were allocated at a sub-optimal order. > > + */ > > +void xe_bo_defrag_init_early(struct xe_device *xe) > > +{ > > + spin_lock_init(&xe->mem.defrag.lock); > > + INIT_LIST_HEAD(&xe->mem.defrag.list); > > +} > > [Severity: Low] > This isn't a bug, but xe_bo_set_purgeable_state() right above already calls > xe_bo_defrag_update(bo), which removes the purged BO from the defrag list, > making the explicit xe_bo_defrag_remove(bo) here redundant. Also, the > comment here, the kernel-doc on xe_bo_defrag_init_early(), and the commit > message still mention a defrag count that was dropped in v4. > > [ ... ] > > > @@ -1426,6 +1537,8 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict, > > if (!ret && ttm_bo->resource && ttm_bo->resource->mem_type == XE_PL_TT) > > bo->lru_stamp = jiffies; > > > > + xe_bo_defrag_update(bo); > > + > > return ret; > > } > > [Severity: Medium] > Can an error in xe_bo_move() during a defrag move drop a still-fragmented > BO from xe->mem.defrag.list? > > During a defrag move, ttm_bo_handle_move_mem() stashes the sub-optimal TT > in bo->defrag_old_tt and sets bo->ttm to the newly allocated TT before > calling xe_bo_move(), only rolling bo->ttm back to bo->defrag_old_tt after > xe_bo_move() returns an error: > > drivers/gpu/drm/ttm/ttm_bo.c:ttm_bo_handle_move_mem() { > ... > 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) runs even when ret != 0, it inspects the > new bo->ttm (which lacks TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED) and removes > the BO from xe->mem.defrag.list before TTM restores the sub-optimal > defrag_old_tt. > > [ ... ] > > > @@ -2259,8 +2383,11 @@ static int xe_bo_fault_migrate(struct xe_bo *bo, struct ttm_operation_ctx *ctx, > > > > if (ttm_manager_type(tbo->bdev, tbo->resource->mem_type)->use_tt) { > > err = xe_bo_wait_usage_kernel(bo, ctx); > > - if (!err) > > + if (!err) { > > err = ttm_bo_populate(&bo->ttm, ctx); > > + if (!err) > > + xe_bo_defrag_update(bo); > > + } > > } else if (should_migrate_to_smem(bo)) { > > [Severity: Medium] > Does calling xe_bo_defrag_update(bo) here contend on xe->mem.defrag.lock on > every CPU fault for XE_PL_TT BOs while still missing BOs populated in > XE_PL_SYSTEM? > > For a sub-optimal BO already in XE_PL_TT, ttm_bo_populate() is a no-op and > the BO is already on xe->mem.defrag.list, yet every CPU page fault calls > xe_bo_defrag_add(bo), which unconditionally takes the device-wide > xe->mem.defrag.lock spinlock before checking list_empty(&bo->defrag_link). > Conversely, when ttm_bo_populate() actually populates an unpopulated BO on > a CPU fault (such as a XE_BO_FLAG_DEFER_BACKING or swapped-out BO), > tbo->resource->mem_type is XE_PL_SYSTEM, so xe_bo_needs_defrag(bo) returns > false and does not track it. > > [ ... ] > > > @@ -3464,6 +3592,8 @@ int xe_bo_pin_external(struct xe_bo *bo, bool in_place, struct drm_exec *exec) > > > > xe_bo_pin_account(bo); > > > > + xe_bo_defrag_remove(bo); > > + > > /* > > * FIXME: If we always use the reserve / unreserve functions for locking > > * we do not need this. > > @@ -3520,6 +3650,8 @@ int xe_bo_pin(struct xe_bo *bo, struct drm_exec *exec) > > > > xe_bo_pin_account(bo); > > > > + xe_bo_defrag_remove(bo); > > + > > /* > > * FIXME: If we always use the reserve / unreserve functions for locking > > * we do not need this. > > @@ -3548,6 +3680,7 @@ void xe_bo_unpin_external(struct xe_bo *bo) > > xe_assert(xe, xe_bo_is_user(bo)); > > > > xe_bo_unpin_account(bo); > > + xe_bo_defrag_update(bo); > > > > /* > > * FIXME: If we always use the reserve / unreserve functions for locking > > @@ -3578,6 +3711,7 @@ void xe_bo_unpin(struct xe_bo *bo) > > } > > } > > xe_bo_unpin_account(bo); > > + xe_bo_defrag_update(bo); > > } > > [Severity: Medium] > Should xe_bo_defrag_remove() and xe_bo_defrag_update() live inside > xe_bo_pin_account() and xe_bo_unpin_account() rather than their callers? > > Display framebuffer pinning in __xe_pin_fb_vma() and __xe_unpin_fb_vma() > pins and unpins user ttm_bo_type_device scanout BOs by calling > xe_bo_pin_account() and xe_bo_unpin_account() directly: > > drivers/gpu/drm/xe/display/xe_fb_pin.c:__xe_pin_fb_vma() { > ... > ret = xe_bo_validate(bo, NULL, true, &exec); > drm_exec_retry_on_contention(&exec); > xe_validation_retry_on_oom(&ctx, &ret); > if (!ret) > xe_bo_pin_account(bo); > ... > } > > On integrated GPUs where scanout BOs reside in XE_PL_TT, validating and > pinning a sub-optimal framebuffer BO leaves it on xe->mem.defrag.list while > pinned, and unpinning it via __xe_unpin_fb_vma() never calls > xe_bo_defrag_update() to re-add it once the last pin is dropped. > > -- > Sashiko AI review · https://sashiko.dev/#/patchset/20261201234915.3305331-1-matthew.brost@intel.com?part=14