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=1796329443; b=0RCi3p9Xsi7VqYdUUE3oQkWxKtQO/NOjYE9jLbifUinrxXSYuVOb6zvnnkCqJJwXg2X5 IfZQHo7UnUqmKwZqHs8KJad/HENEhd4NLuiIlu9CfFfMzvcquS8/ym8LsqeQZ2bRyTtye 34mvpilj2YV70sJLff/TjZnOHAmRLC0CNrrn4PyiMKzK77ejaVWlTX5zN2+8e6LAXv+NW 2zumS1qPocEOlFqTAuUuUsSXX6lIM7rBiYqj7oCIRIKWPm8u5LmI8lSKJifXrVDiZmqq7 8Tv5Xeqiv9/G/OURXIs5COQhbHYcKARJ7ZeBQJ+i8LbxO5XwMjzyp2/R3NkjeFvmK/A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796329443; 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=BZP/jZBDzEk1G2wmIek3iZtrxItWPGyRnZDsf1sEoMo=; b=uIEfFkZryGLWa4f6b9xzT16oOY0UdFWqyGnenTM4bFL4ebqCbR5nPLYW/hx/8yQLCCyD +KwGsq52AuuWI3YrJsmtWvkiDxa8MjhPu4uxsv/bHGA7UcMhhQA7++w4oOPQJATwIgjuK j9jHLntHSIbBnhFMfwiakquWsK5Sp4dX2+KAsl8O+7iDBTYvq55qdtmnPwvzEZPUV7Hgu TBd2B73cOA//IkdEBCnUqRQVG+4bIS/NxLoKmypcq6xzTpoOedFBuDCKF9qQpRs1qb19U KJSO+QGsU1S1rw8Xa1iqpG843XEGhmiVDACSw8RsboWdtEO9tQgs+Z95idiiKJfwDpw== 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=DLSLgRhF; 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 14079606A33F for ; Thu, 3 Dec 2026 20:24:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 14079606A33F 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=DLSLgRhF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796329444; x=1827865444; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BZP/jZBDzEk1G2wmIek3iZtrxItWPGyRnZDsf1sEoMo=; b=DLSLgRhF69/iXiRM9l0e47veW1sXaY6UKZYpl7eBPBC6ksR5X2SSR1gA C4RrM+OKfcHidtjHeyQiEerYe1ik2mb+zgvLBTs5KJTInusreHicQ5/5p ylukkFsr+UJyQ4psigohsax6oYITkegoG+P1HduiqCXBrfs5PZtJvIDhw +GPDqJSY4oroPWTsqE/vi5sq5MLlabAXWyHj93RmmNaBnaR+aRH0w11RW jF7PFzRtG6kNk0t0rUva9LKt/JYABg4ZwtxALWFc2DxTMytXDfahtWSc6 +PFrezlA5hkXZfJ8WOnWFulJmZ6RtOEIaR/5jGl7aG5SRQCpQ6sx3cVvv Q==; X-CSE-ConnectionGUID: UAF2nx+sScO6x8oXjSWufw== X-CSE-MsgGUID: +G2qGOfARbKDytdMF1ag/A== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5351116" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5351116" 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:03 -0800 X-CSE-ConnectionGUID: l6lw/vfeQzqQ1nWNXXZDEw== X-CSE-MsgGUID: Ypx1sDIXRVOy6Sa1kmJ94A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="15862471" 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:02 -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 16/35] drm/xe: Handle defrag moves in xe_bo_move() Date: Thu, 3 Dec 2026 12:23:33 -0800 Message-Id: <20261203202352.4153159-17-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 Teach xe_bo_move() to service a defrag move, where TTM reallocates a BO's backing at the device's beneficial order and hands the old, still populated tt to the move via the BO's defrag_old_tt. A defrag move always has existing contents to copy, so force move_lacks_source false and fall through the XE_PL_TT -> XE_PL_TT no-op shortcut so the copy path runs. The relocation is performed entirely on the GPU via xe_migrate_copy_defrag(), reading the old pages from the stashed tt's sg table and writing the freshly reallocated backing. Both copy passes run in order on the same migrate queue and are captured by the returned fence, so the teardown is pipelined via ttm_bo_move_accel_cleanup(): the old tt is handed to a ghost object and only unpopulated and freed once the fence signals, so the move need not block. v6: - Assert defrag BOs have system placement (Sashiko) 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/xe/xe_bo.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index 382f4664287c..886029c0f90d 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -1299,6 +1299,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict, bool move_lacks_source; bool tt_has_data; bool needs_clear; + bool has_defrag_old_tt = !!ttm_bo->defrag_old_tt; bool handle_system_ccs = (!IS_DGFX(xe) && xe_bo_needs_ccs_pages(bo) && ttm && ttm_tt_is_populated(ttm)) ? true : false; int ret = 0; @@ -1339,6 +1340,17 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict, move_lacks_source = !old_mem || (handle_system_ccs ? (!bo->ccs_cleared) : (!mem_type_is_vram(old_mem_type) && !tt_has_data)); + /* + * A defrag move always copies the existing contents from the stashed + * old tt into the freshly (re)allocated backing. Only BOs with system + * placement are defragged (see xe_bo_needs_defrag()), so the tt never + * carries DGFX FlatCCS backup pages the copy would drop. + */ + if (has_defrag_old_tt) { + xe_assert(xe, bo->flags & XE_BO_FLAG_SYSTEM); + move_lacks_source = false; + } + needs_clear = (ttm && ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC) || (!ttm && ttm_bo->type == ttm_bo_type_device); @@ -1382,9 +1394,12 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict, /* * Failed multi-hop where the old_mem is still marked as * TTM_PL_FLAG_TEMPORARY, should just be a dummy move. + * + * For a defrag move the old and new tt differ, so continue to the + * copy path instead of treating it as a no-op. */ if (old_mem_type == XE_PL_TT && - new_mem->mem_type == XE_PL_TT) { + new_mem->mem_type == XE_PL_TT && !has_defrag_old_tt) { ttm_bo_move_null(ttm_bo, new_mem); goto out; } @@ -1471,6 +1486,12 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict, fence = xe_migrate_clear(migrate, bo, new_mem, flags, ctx->interruptible); + } else if (has_defrag_old_tt) { + struct xe_ttm_tt *old_xe_tt = + container_of(ttm_bo->defrag_old_tt, struct xe_ttm_tt, ttm); + + fence = xe_migrate_copy_defrag(migrate, bo, old_mem, new_mem, + old_xe_tt->sg, handle_system_ccs); } else { fence = xe_migrate_copy(migrate, bo, bo, old_mem, new_mem, handle_system_ccs, ctx->interruptible); -- 2.34.1