Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.12 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796168966; b=CAhOXTT+YFwcqSLKUPQhNiOJICZb91tVRJwLuMH1DNDrPWC2cirS91DdaJAVgrAogcLR yLan7rDsAQSmhvAVoflUCJ9aWNBf9d+pPnAN5Vs7Cb1cqc04alzrHhrMAuIBbk9xcRrrN 0ekIPfbsRBoRTryBB1kqzI7hydYgeVQsInQkQIu01y6r7mSYho5zvzhkh9K6BArfr0yJo lvof96CtA/wQsmJyaIiqgwdBSJwmubQ0QHOsJIOOdzz73xlyxCCgIyE5a+uDvJo/bU+VQ svc+0ugR0ekI9dvdv4C053vyXgmn0gwwDFhFnuTk7eyukgqUapDRU8uEWCR5ov/KpGg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796168966; 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=pNIzNJ0pFZLKsI5mhcMkS6VJeNA01fq93xSB4lD+zxk=; b=pYaG2OUHGxxDJVIM3N5XMuUqfJ7WDMuM6J5twfNdocuZlLl3O1fgxvJfW1IZLbSYm1j4 w1G6VqJ5dLOdtipHh1tzBiYSX9dTByVHuhdWsaGcldKdurotyfGJBU4UOjuIEuRWLfSRK Gosg1EMcnveOvTKior2iBR5e1CAVmHw5ERyDmJjevSgmC4ouujff9nOu4PFN99G+rvRKc F4faF2lA0QROiLWOBGQUVTBS05OWAhL4PxrPF1s6FPNjHddqj+ZhdhRntwA4EX80ITMaK C9rvsjZWw5FHVsr88Zsv6HmdbPqT/YhJXRHCZh17XiB2d/T3LV5DAPcX6oZV/5feK9g== 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=VTlhc5TH; arc=none smtp.remote-ip=192.198.163.12 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 3A21260A2603 for ; Tue, 1 Dec 2026 23:49:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3A21260A2603 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=VTlhc5TH DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796168966; x=1827704966; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pNIzNJ0pFZLKsI5mhcMkS6VJeNA01fq93xSB4lD+zxk=; b=VTlhc5TH8dg3q3lZRbIYeiT0Nxa6ZpyM8SZ6DZYgqNI6PG8PS9o+6mL1 RM+snJgynhROfuY0vVb25CCnGzT3nmgZlZoRXQRphhn6Z7JUAraPcxI3v 8lHK2gd3YyEU/kan+hgXnAvc/U6buMHuNfwxBqHdUCgjR9VhOkkaBnJks kiFqwyKJ6PfO2xVCvpPxWjCCc2xi3ABGZFV6GYjD5Rk03v9MXJV6LPX+3 LYlqaWf+GodvvVzaT3CjG8g/9X27UTp5RHbAVawqJT8Zls9KyyvPvbE9R oaNEmgLuMFVC9YjX2rTAktPjxtIqUeh6iv/Aw44MrfBrhGVvqek7kbN/8 Q==; X-CSE-ConnectionGUID: gtmcvUzrR9CZLFv7qrCKKA== X-CSE-MsgGUID: 0ptWSXkSSOqkB4M2TMVnyA== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="4977454" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="4977454" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 15:49:26 -0800 X-CSE-ConnectionGUID: oB3VFO4+TfGiP3rMW4OsVw== X-CSE-MsgGUID: ytVP64oASIKODtn0VVny0w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13919948" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 15:49:25 -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 v4 16/33] drm/xe: Handle defrag moves in xe_bo_move() Date: Tue, 1 Dec 2026 15:48:58 -0800 Message-Id: <20261201234915.3305331-17-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261201234915.3305331-1-matthew.brost@intel.com> References: <20261201234915.3305331-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. 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 Assisted-by: LLM Signed-off-by: Matthew Brost --- drivers/gpu/drm/xe/xe_bo.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index 0351079eae64..7448e43eedf5 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -1300,6 +1300,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; @@ -1340,6 +1341,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 (has_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); @@ -1383,9 +1391,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 && !has_defrag_old_tt) { ttm_bo_move_null(ttm_bo, new_mem); goto out; } @@ -1472,6 +1483,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