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=Cs7ij3poxLVBWICuUAJf0xBF3F8HPiKJsE4Zdo+XAKeC+KWaqENefqe1uX7q5C/7GY8P YQW9mvONmDv2Y/PxkyrB+yS49uIB35OVZ95qFKowNU/XxUT3/XnGpRS3f5/vNaJ5l34rP hdJrR/RA6rDtThCM9YHLeZX7Qp+WpBW7sWZTwc5HtRKj5ctqScRaDA+2o5rxt4+XQsynz Snas6De4ulZPY6hQXB/zyg7dqCooVdSO5w3/Xer+lBfF4htlqgZK2+0hVETJG/neqhT+q 2koFgAeyN3oc89QHL2T7J3DCEyAbXF/E+kSprNghmTLjy92MchCSliZo5BpRHUjkP9w== 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=6cjLROI1wcODg5a4tEq/sK2a923soSOZWJj9uw+xcZU=; b=RBw1HO8E75dJ26x2iVUoVHVe68MMTArmik1FCyLZNs24BVLw9bg5H6tKcWy1BLUrvs6H aTC7SgZx+PP05X1xujFBFjLIaABazYRDAIjqEuh7ioTGq8a1xpss47HWFbZkkYBy4o32Z ddBWU7TMfVUZwV6fuZn85LohpyHm/ham9Q9HuSZihbnOoU0rRFsJtHUvimAKz5lExEa0H mYEWLKs9xK4hl0BMaS2/wky5hukezkZVydHTJW3Ma3+qAAbhdeoP6aRUbYZkf0oJWqtgD /Uc07nUcdAaozTzfCaX2oJmd7gQcobN4fvgOVGSB6ZZgZig36pGygyYTTHa3PqQ5hxg== 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=E1FLAAD7; 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 BA251606A683 for ; Wed, 2 Dec 2026 23:33:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BA251606A683 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=E1FLAAD7 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=6cjLROI1wcODg5a4tEq/sK2a923soSOZWJj9uw+xcZU=; b=E1FLAAD7hSV/hp1vFpUsJ6+dZC9yzEdrU03Tf4ur5BrLw9IOVZT6kf87 J0Od9KhJmToe7fRzFCobMfviZqKq9rexXbrlBP0oieyId1oZmMFh/7Nv6 3+TBhcfogeJIuetsz0ajgqcv0Rq0HyjEFhzVoj3Y5js+EUPnEmzzxNhQC V5lwQWPRnfavXcGRQlIO4++P0Oa2E2/445Vba8g82bhJeNAesIFW3KQQ0 ymDLuV2b3E/DBaPwoKs6LGZAFYxOuCl55BXQPZ2knX3FyYgfOqD3IV+4r 7zYv8fykaiacEmBDXc7Wyb1St4+RRYO9NThTy6gF0CsI0YS7/b6SN6Wpe A==; X-CSE-ConnectionGUID: RsrulzGnQrazmlJ4KMt34A== X-CSE-MsgGUID: DD7/0xbLSjmM5xEPvALuYw== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5203117" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5203117" 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: CrOeH4JmT9i1WLtm2507tw== X-CSE-MsgGUID: XGwLQzgMQUiJ6WoqQKxQKw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13484042" 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?= Subject: [PATCH v5 07/36] drm/ttm/pool: Keep chunks self-aligned when resuming an interrupted restore Date: Wed, 2 Dec 2026 15:32:54 -0800 Message-Id: <20261202233323.3743190-8-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 __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