Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796254412; b=KZbwCqdSxuicMQhqZnLa+VDNrNBAIT0fQtWL/hw+L9CXWX62dGItu5UroZnW9UAvrGgF dLioxm4bo8ePu2sJJW5alKs2hIuoIYDTZDY6GDlhaN9oHl4iqEseLfflkrdZdKBh9kdBi dCeMxH6eBXRY5YpQMciC2r19KDwJoFmwxgEm3d8RQZV7F7G2JNx2HEW6anL2JdX9O40ez /z9jz+zU6OhbHmcFcyNhWKc3nO/gzq0l1BQb/ki2GKPRik3IDvHZY5f2ADRNinVj1Bu8N 3gfBYyCqH7Zqe2DV+GJWUFwmOx9nc97pPAUsCKAhwTzfSVAKh/IGp2As+pgKhpQkStw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796254412; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=PGs4n98kL90cEilNm4QdmDaOG7YYv/zdk1OvFZR0N/I=; b=CwMOJdaC7G6IHKfNgv965nFCxWmE1K0FSaveIwLMaoCFgyUcrbSaXMzro4dxbrYznZwv 8vlX2ywgrlAJhaEgusUcb3Ljqk8unX+pDutA38r9SyFUO4XF9OgjmdzBjsMIRWXD1HjGr 0342SFm47UvrtW7//FMYTUJS4WHL+Kd9ROaWm33GmZoOweL3ST8ssi72BY08jlaEnjaFK 6lDE4FHmaZd57aw3pwHCmyaOZDHMjnsZq+/ofmM4T06hMgqBySO2LAXvFJLre6DhFKKb8 zCSGPxX4xctSEQDRnEffqXKirgociePDEohtbPyRpI6FZDoFNCw2ibs17GfTiVtXWGw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=dZwCAwDp; arc=none smtp.remote-ip=192.198.163.17 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92A1E606A33E for ; Wed, 2 Dec 2026 23:33:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 92A1E606A33E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com 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=dZwCAwDp DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796254412; x=1827790412; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PGs4n98kL90cEilNm4QdmDaOG7YYv/zdk1OvFZR0N/I=; b=dZwCAwDpI5ZTxFd6Cl4fRJO1of0KyQY6WQifxVg/Mj24WKjd6ZGxwbv5 J0/JyPYNNBLahonr8IppPzZsZU+FvAqX6JsqYQevWEdfYtB6s4oKCLsEN qVwNoDc87lGVj7NDJM+vuc7S3hyfVhIeTvt5TQAYgXGizfNt5H76SXM/P b29oROyJvVl9H0nZao/iyDJV/ZOoqnwCLoIIrUnJiJw4/guDlkoyNHyoT wcvwuWYsfS0Q0czz3lL8PqNBXcslZINpJ/i0+AdzhUbm/JXvB0FW5KjhP Nc3RLEBkFG8kOx2rhXw0WBazUAympPwfQwzckpwB7QA1AkEjly9tTE4A4 w==; X-CSE-ConnectionGUID: Fh25j2hlR8yvsTZxxR6hnw== X-CSE-MsgGUID: KySOsf/tTu2/ZsEHZfAlPw== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5203108" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5203108" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 15:33:29 -0800 X-CSE-ConnectionGUID: b2t4x5gOSeKjCyIkn6jC6g== X-CSE-MsgGUID: i4uBiL08TOK9CBwOfOv6OQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13484039" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 15:33:28 -0800 From: Matthew Brost To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Carlos Santa , Ryan Neph , Natalie Vock , Arun Pravin , Matthew Auld , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , linux-kernel@vger.kernel.org, =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Niranjana Vishwanathapura Subject: [PATCH v5 06/36] drm/ttm: Add fault injection for beneficial-order allocation failures Date: Wed, 2 Dec 2026 15:32:53 -0800 Message-Id: <20261202233323.3743190-7-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261202233323.3743190-1-matthew.brost@intel.com> References: <20261202233323.3743190-1-matthew.brost@intel.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a beneficial_order_fault_inject debugfs fault attribute, mirroring backup_fault_inject, that forces allocation at (or above) the device's beneficial order to fail in __ttm_pool_alloc(). When triggered, both the pool take and the system page allocation are skipped for that order, so the allocation falls into the existing lower-the-order path that sets the TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED tt page flag (and bails out with -ENOMEM for defrag moves). This lets the TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED tracking and the driver-side defrag path be exercised deterministically, without having to drive the system into real memory fragmentation to provoke a sub-optimal backing. The knob is registered at /sys/kernel/debug/ttm/beneficial_order_fault_inject and compiles out when CONFIG_FAULT_INJECTION is disabled. Cc: Carlos Santa Cc: Ryan Neph Cc: Natalie Vock Cc: Arun Pravin Cc: Matthew Auld Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: David Airlie Cc: Simona Vetter Cc: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org Cc: Thomas Hellström Signed-off-by: Matthew Brost Reviewed-by: Niranjana Vishwanathapura --- drivers/gpu/drm/ttm/ttm_pool.c | 35 ++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c index 182e84efcd92..4e146798848a 100644 --- a/drivers/gpu/drm/ttm/ttm_pool.c +++ b/drivers/gpu/drm/ttm/ttm_pool.c @@ -53,6 +53,7 @@ #ifdef CONFIG_FAULT_INJECTION #include static DECLARE_FAULT_ATTR(backup_fault_inject); +static DECLARE_FAULT_ATTR(beneficial_order_fault_inject); /* * Exposed to ttm_backup.c so a mid-compound subpage can be made to fail @@ -827,21 +828,34 @@ struct ttm_pool_alloc_iter { unsigned int order; enum ttm_caching page_caching; bool allow_pools; + bool fail_beneficial; struct page *p; }; /* * Acquire a single page for the current order, leaving it in @it->p (NULL on - * failure). Tries a same-order pool page, then a fresh system allocation. + * failure). Tries a same-order pool page, then a fresh system allocation. Fault + * injection can force the beneficial-order paths to "fail". */ static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it) { struct ttm_pool_type *pt; - /* First, try to allocate a page from a pool if one exists. */ it->p = NULL; + + /* + * Fault injection: pretend allocation at (or above) the device's + * beneficial order failed, forcing a sub-optimal backing. Exercises the + * beneficial_order_failed tracking and the driver defrag path without + * driving the system into real fragmentation. + */ + it->fail_beneficial = IS_ENABLED(CONFIG_FAULT_INJECTION) && + it->beneficial_order && it->order >= it->beneficial_order && + should_fail(&beneficial_order_fault_inject, 1); + + /* First, try to allocate a page from a pool if one exists. */ pt = ttm_pool_select_type(it->pool, it->page_caching, it->order); - if (!it->p && pt && it->allow_pools) + if (!it->p && pt && it->allow_pools && !it->fail_beneficial) it->p = ttm_pool_type_take(pt, ttm_pool_nid(it->pool)); /* @@ -849,7 +863,7 @@ static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it) * this also disallows additional pool allocations using write-back * cached pools of the same order. */ - if (!it->p) { + if (!it->p && !it->fail_beneficial) { it->page_caching = ttm_cached; it->allow_pools = false; it->p = ttm_pool_alloc_page(it->pool, it->gfp_flags, it->order, @@ -866,6 +880,9 @@ static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it) */ static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it) { + bool at_beneficial = it->beneficial_order && + it->order == it->beneficial_order; + if (!it->order) return -ENOMEM; @@ -875,7 +892,7 @@ static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it) * pages. Record it so the driver can later try to defragment the object * back to beneficial order. */ - if (it->beneficial_order && it->order == it->beneficial_order) { + if (it->fail_beneficial || at_beneficial) { it->tt->page_flags |= TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED; /* @@ -886,7 +903,10 @@ static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it) return -ENOMEM; } - it->order--; + if (it->fail_beneficial) + it->order = it->beneficial_order - 1; + else + it->order--; it->page_caching = it->tt->caching; it->allow_pools = true; @@ -1623,6 +1643,9 @@ int ttm_pool_mgr_init(void) #ifdef CONFIG_FAULT_INJECTION fault_create_debugfs_attr("backup_fault_inject", ttm_debugfs_root, &backup_fault_inject); + fault_create_debugfs_attr("beneficial_order_fault_inject", + ttm_debugfs_root, + &beneficial_order_fault_inject); #endif #endif -- 2.34.1