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 76EC5606A336 for ; Thu, 3 Dec 2026 20:24:19 +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=gsd5Rv6A Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3740D112B90; Thu, 3 Dec 2026 20:24:14 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id DFC4110E4D0; Thu, 3 Dec 2026 20:24:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796329448; x=1827865448; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6cjLROI1wcODg5a4tEq/sK2a923soSOZWJj9uw+xcZU=; b=gsd5Rv6AkKKLfW1C9O+HaWAk/BEaHqdp2thDFScCnLdFvkw+vA9OSJ+m DiSWMhRU1UPgnss8ETv1kPS5nuJ99Be1dR5loUkxnZvpGcI+cxpaozM/c gMwzXVEabWK6OHRtvbYzII4wVpz1E+AWeUdaWVVeNfilsNnmny3bL7mQB fQx8lNZaRl7PWRMQW7+ejP46BtqjCHcZvnzPGHQIj9wb5EGHUUBrmDkIC V7y+C3ZIyKXS+VbUWsMlYi+ztUnWFRuSJ2BHxzzOcKunm3ngqYQOodWAh 8kBuXci09dyK+ZkKBameUqjsxVlKKMsMS+H7a/Uw25pRFbqabHq5rdLRa Q==; X-CSE-ConnectionGUID: EZtWYD58SGqYowcWd+46lA== X-CSE-MsgGUID: DAIxftM9QQqiVQoUUVgpaQ== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5351038" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5351038" Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 12:24:00 -0800 X-CSE-ConnectionGUID: xiXowr17SzmxVQB2m5ZuiQ== X-CSE-MsgGUID: L3Yecs/wSVmnXpII65Y1PA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="15862426" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 12:24:00 -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?= Subject: [PATCH v6 07/35] drm/ttm/pool: Keep chunks self-aligned when resuming an interrupted restore Date: Thu, 3 Dec 2026 12:23:24 -0800 Message-Id: <20261203202352.4153159-8-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261203202352.4153159-1-matthew.brost@intel.com> References: <20261203202352.4153159-1-matthew.brost@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT 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 __ttm_pool_alloc() fills a tt with a non-increasing order walk starting at MAX_PAGE_ORDER, so every order-k chunk lands at a 2^k-aligned offset in the tt. ttm_pool_restore_and_alloc() however may be interrupted (e.g. -EINTR from ttm_pool_restore_commit()) and later resume __ttm_pool_alloc() at a non-zero offset. The walk then restarts at MAX_PAGE_ORDER, bounded only by the number of remaining pages, and can place a large chunk at an unaligned offset (e.g. an order-9 chunk at offset 256 after an order-8 fallback). That is harmless today, but upcoming defragmentation support relies on chunks being self-aligned to borrow whole chunks from an old tt at the same offset. Cap the starting order by the alignment of the offset being resumed at, which keeps the invariant at negligible cost: at worst an interrupted restore misses a single larger order. 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 --- drivers/gpu/drm/ttm/ttm_pool.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c index 4e146798848a..5c7fec62aa30 100644 --- a/drivers/gpu/drm/ttm/ttm_pool.c +++ b/drivers/gpu/drm/ttm/ttm_pool.c @@ -927,6 +927,8 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt, .page_caching = tt->caching, .allow_pools = true, }; + pgoff_t off = tt->num_pages - alloc->remaining_pages; + unsigned int start_order = MAX_PAGE_ORDER; gfp_t gfp_flags = GFP_USER; pgoff_t caching_divide; int r; @@ -947,7 +949,17 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt, it.gfp_flags = gfp_flags; - for (it.order = ttm_pool_alloc_find_order(MAX_PAGE_ORDER, alloc); + /* + * Keep chunks self-aligned (an order-k chunk at a 2^k-aligned offset): + * the order walk below is non-increasing, so that holds as long as it + * starts at an order @off is aligned to. @off is only non-zero when + * resuming an interrupted restore, which would otherwise restart at + * MAX_PAGE_ORDER and could place a large chunk at an unaligned offset. + */ + if (off) + start_order = min_t(unsigned int, start_order, __ffs(off)); + + for (it.order = ttm_pool_alloc_find_order(start_order, alloc); alloc->remaining_pages; it.order = ttm_pool_alloc_find_order(it.order, alloc)) { /* Acquire a page (pool / system) for this order. */ -- 2.34.1