Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.20 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796329441; b=ZwPbIeJc/WYM4pkzaEIXlQEaPzqwpseIGuTXHSlPSAXwcnchDGuc4K8xQuvqwzv8jRbY L3f9gZuxIysZ1wT+yR4BsQJFieQjLbn2gh+d8qHd/JsGi4IF7TkSXYS2BF9bN19rRc5t+ uDJGwt6y6RSGfUKgRZyZ7f+d7sXPuQpOlJEWaFCP6QAmwUWujvcPnnwn1hdAXiBfkP/MG XEaKfV0yhDZmWB03CsZDh8HJTxlu/qc0O+27T6S9HVguMoPmmXrhZGNx3v2R+kC/G/CVj XF4lKmF7KJg5SWtspFtPc6qJtHggAtA73LIIyCBYDZslZv3Mwkrt2bf1ZjZpHA3t28Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796329441; 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=2VVRgKmOdZN3q7FQ8dN36p/dVq28QKQIXGVPPjJhMHEZeqBRceETkFUFOQ40kt6l7g4Z gWGCVkmVYm1NgPQQiyuxGiy8TTlUQQLQ2humnuF67n5aK/ja43t1D1vQ/sstnUvPMCeTP ygrDSlp0iPYGYfvEn0K8RCwBkbYmHXCbHfQUjznhFMfh8PbdjPn5njXGuLjXJ3RunNrUb kPtdn+r+ERUlvHcmz1DM351Bi8QYJql80tY+R7UiWZWLObouloGLMtVqevC1FW0GdDi8G rXTnhbwWh2foVUAKTRo7GD08NQBR4B4n1dEqyJGufGzNXotf2YHfMqPe2MnExHtGpXA== 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=FhI9ynSp; arc=none smtp.remote-ip=198.175.65.20 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 6390A606A693 for ; Thu, 3 Dec 2026 20:24:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6390A606A693 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=FhI9ynSp DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796329441; x=1827865441; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6cjLROI1wcODg5a4tEq/sK2a923soSOZWJj9uw+xcZU=; b=FhI9ynSpnHpePTqVUYDsQfxGtU+ZX03ekgKEXC2vBEZEAhyMGJ+AIbXm Fu5kT84e6jJleD2Im1yX+agCGuvYX+zdzA5Yzlvg7cvQ00iOdBh/YqgZK PGsvWMxWRn+gsHyFtpS2QdSpByLsclbUXcIuU84G/ZgI9cmxTHA8KFs8I oXU14k+xoEc64BpTNk4T6Hd/d7y0ji+GqLP56zzD5NRAXYWOKrCOwBkfr y6Y+qCSygcZLPV2CM6VzlkQGkCF070X2JelYdajtdudDJu9U9Y2kYidno WSGfGSSaMuQChiTT8Jd7Q5wmDfBZwdiDhX1WG8ls2T1vRSJiUGOSek1ER Q==; X-CSE-ConnectionGUID: 8vDyoHM+QQyBv1yJIGoTQw== X-CSE-MsgGUID: GYvJwXmRRSiaEQ7EjcI+DA== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5351043" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5351043" 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-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