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 BE3E6606A336 for ; Thu, 3 Dec 2026 20:24:27 +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=a3WrEOQS Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6FA81112BBD; Thu, 3 Dec 2026 20:24:22 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 75470112BC1; Thu, 3 Dec 2026 20:24:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796329457; x=1827865457; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BZP/jZBDzEk1G2wmIek3iZtrxItWPGyRnZDsf1sEoMo=; b=a3WrEOQSKy2AqXWRx3W/As2RcguWJ8jdI26CB84NTbbbcSHJmfhMMGQf XwFDQ00DG8w3B6d35sHxQ5uNbjASqa9AwXNmRXGkpzva8v0OPL6bbd3KB XvtOr6+O4+L+P3K8ehd3Hg6FLvHVJWqgD57g7aaw/+qbElQ6ODVy6pcOT fYC3LBqTo/fBDaqlvHXIhR3biyzc22lvPYf43Xov0xM72OmZqwPMrZbGR 9feildkS43TJLzO+VWfYPDif0n+ShVRm5cMavbqQSrBPk+nymbmnx5TsA vlCDVNR577h+xK9OYqWRi6p2ar78dKspTMPYegWk7p63r0J7a8Q0O5WVa w==; X-CSE-ConnectionGUID: x7ppCFytT424wSjQqtV+GQ== X-CSE-MsgGUID: ECKWOlU7SKWNtP2GehmlTw== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5351111" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5351111" 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-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 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