From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA48B30FF05 for ; Sat, 11 Jul 2026 02:56:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783738597; cv=none; b=jBaauVbdXi4pGP1ZjfJRSF7x+9H+ZQQfeOEfcsxv8pdljNd1o0pxG8bC9EsZhVN1Q1lUEEalNBXoKI0+IJmmRk4u6MSVBM+UOlYpZDRJc17YXx/vd2/3ydlA7+WHQbxuhpxeEMe18BcMWairZ9NP4tHv4DxLM5b9WUyzZx17+dI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783738597; c=relaxed/simple; bh=ciSlVXpYrCjcPlqK/uZOBqxyhDyuJvmKWHVgK/hH22Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=euAAU4pkZEZDQuokxNf6GwljLK3pG7O/s9Ld4eRbFIJLpIOHmnmMyC8bXWQ25azZJNFLLJsH/4F1r+t1xCWPxu7hcnE1ZQ9+GRCBoWkAxiCeXzUuMIIvKEWdMcaXtp/Ck9OFIp7D2S2oiQXOfuwdgzPGFJ3nEyT5m59SqAeZcTw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=k2ou7sZI; arc=none smtp.client-ip=192.198.163.8 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.b="k2ou7sZI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783738596; x=1815274596; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ciSlVXpYrCjcPlqK/uZOBqxyhDyuJvmKWHVgK/hH22Q=; b=k2ou7sZICNgGa7olFkB4Qgqhv30/XZH+oEtyVS8zjuTJSPK39ibNvS9w 4AnbEUJg3lpf9ouR5zEiAfdaOydKkd9CGtZHhStsHmbGFqL3UFFSgWFKV OblaBN1slJg+5EBwLw9MsICFJbg3UuRwHDjTZD+75cDUqFNFN8GYKBscc c7PTroQCa+eluBkc/b2YvqJP56IOUB3tXvTE0M7TzufWrWUW9i3tgJAd7 ydrN3cCNTtGSZHkaWD4HHk0yg5n1eCA28SzuwwC/SfIGqE5FVaB/QkiXA j2v1tsBgaChCr06MwNUciyFY9QxbUmKGcVIw+yl3PS6XLoOr+nAGwrP72 g==; X-CSE-ConnectionGUID: 9F5bZKuaTMWm3Dt04SRtIw== X-CSE-MsgGUID: T/VfaXSVSbejVeepa5yIOQ== X-IronPort-AV: E=McAfee;i="6800,10657,11841"; a="101986286" X-IronPort-AV: E=Sophos;i="6.25,154,1779174000"; d="scan'208";a="101986286" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2026 19:56:30 -0700 X-CSE-ConnectionGUID: w6pn5VBVRfutTHEAjhFa1g== X-CSE-MsgGUID: 4swA/E6eQIy8i8PFVbBlVg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,154,1779174000"; d="scan'208";a="256987729" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2026 19:56:29 -0700 From: Matthew Brost To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Carlos Santa , Ryan Neph , Christian Koenig , Huang Rui , 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 v3 18/33] drm/xe: Handle defrag moves in xe_bo_move() Date: Fri, 10 Jul 2026 19:56:04 -0700 Message-Id: <20260711025619.2540575-19-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260711025619.2540575-1-matthew.brost@intel.com> References: <20260711025619.2540575-1-matthew.brost@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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. The VF CCS attach/detach handling is extended to treat a defrag move (ctx->defrag) like the XE_PL_SYSTEM <-> XE_PL_TT transitions it mirrors. Cc: Carlos Santa Cc: Ryan Neph Cc: Christian Koenig Cc: Huang Rui 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 Assisted-by: GitHub_Copilot:claude-opus-4.8 Signed-off-by: Matthew Brost --- drivers/gpu/drm/xe/xe_bo.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index 02395968d613..bdcc9bed5d36 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -1170,6 +1170,13 @@ 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. + */ + if (ttm_bo->defrag_old_tt) + move_lacks_source = false; + needs_clear = (ttm && ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC) || (!ttm && ttm_bo->type == ttm_bo_type_device); @@ -1206,9 +1213,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 fallthrough 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 && !ttm_bo->defrag_old_tt) { ttm_bo_move_null(ttm_bo, new_mem); goto out; } @@ -1279,6 +1289,12 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict, flags |= XE_MIGRATE_CLEAR_FLAG_CCS_DATA; fence = xe_migrate_clear(migrate, bo, new_mem, flags); + } else if (ttm_bo->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); @@ -1315,13 +1331,13 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict, * BBs from BO as it is no longer needed. */ if (IS_VF_CCS_READY(xe) && old_mem_type == XE_PL_TT && - new_mem->mem_type == XE_PL_SYSTEM) + (new_mem->mem_type == XE_PL_SYSTEM || ctx->defrag)) xe_sriov_vf_ccs_detach_bo(bo); if (IS_VF_CCS_READY(xe) && ((move_lacks_source && new_mem->mem_type == XE_PL_TT) || - (old_mem_type == XE_PL_SYSTEM && new_mem->mem_type == XE_PL_TT)) && - handle_system_ccs) + ((old_mem_type == XE_PL_SYSTEM || ctx->defrag) && + new_mem->mem_type == XE_PL_TT)) && handle_system_ccs) ret = xe_sriov_vf_ccs_attach_bo(bo); out: -- 2.34.1