Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796254414; b=AfVKb1FI16gltsvgyGZvNS3wLpimFDpscoRCfe6M25qMZlzyNN0U/+aCeCmAfYpH+SLQ oC2kClVpe5QtVy3AKPDs3Y5nEt167MQjcyI3hntX2nLsAqD/yUk38xiJ6/oUm45OWuXH+ YWEeBqIbicNPWUgFQWwkm69yTjM3FznEYOxxUP0iVKxvWvrxZvCLvwkfwCH2IM4SMHRah EYm80YQRsgWif8XAKNrqvw2tAwcEaW9f9IhLaHFiBs3wFq8fhlq/DEpRX3+GZPLjdoPaR KhBLCrW7QmmmYH+LT5K4tMKPcBXVkgTJH/GCxoHoOLFd5kRJ0OZ24Hsz7zb1g0fktMg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796254414; 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=MAgDBTs/VnlU6glCCNlBittbVC8+GTLShSj+V26d4QE=; b=h3y3EZtM1YEv7PZNrAfhIPfEbeZDZWbmitw8oQsoq1QpucPORecrEDdex80/BVKjzAqx BToPIcQN802jp0wogQs+UeRXsGvP35ksAeoSZ2f6YL/XWfIl6YNkjFvWqOY90vIp0reLW aJaVeFPsf20+i69tjVmhptWc3GPYNu9EB1ew2a6uC0f95VAwW8Hcoz9e8bvfLLJwImymD r0rmpEZ0puo1m9zWyG1CbtrlmkHMpTvANuXfYLx4KW+vIDL1jWNvYkH+pa1CuyVM/ATtd 4QXiX+UMBGbdB/WVcEGadF5IF6K74HU9dK1JxMlkw6iEFRGFz650SbcabDVkQi4WTog== 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=gz9LskE5; arc=none smtp.remote-ip=192.198.163.17 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 9433760A2602 for ; Wed, 2 Dec 2026 23:33:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9433760A2602 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=gz9LskE5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796254414; x=1827790414; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MAgDBTs/VnlU6glCCNlBittbVC8+GTLShSj+V26d4QE=; b=gz9LskE5po0v386ZNvqlB809VtfKBdJPDnXSNIPTwX/4WngJqlp9Q8/L C+g2gS7ILTG+dzI4DjAad1wBBXk7tmYznS8Ft+AzyzlGACcnvMZfliGiT YQQb2EPx/bRE1yNFqQkL7LUiT+Fcp4ajY+lWGwLiJFmd8aXp7QFKbVMXT Lfq58VYvfwtljB3YoXtbaIWInsk1SPoYTb4XGbANJYHeQufgQ/7BDNIEL 4gMqmEAqU0MMkcqS5lLgTrx6WV6g7RFHwNkXOtk5NEAqMBxs1cL4agAWO kLZIwRoAU0tF/pknZSS9OZKCbOXI6IuSi8LkKZ1xukqgltFN/GB+dS/Wk w==; X-CSE-ConnectionGUID: zyAnLXo3Qz6egaMyCufPfA== X-CSE-MsgGUID: kPAp5q6+Qqe+Eh0sVQfU8w== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5203187" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5203187" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 15:33:30 -0800 X-CSE-ConnectionGUID: Uj9HYgEjT3q65ohDppAn4w== X-CSE-MsgGUID: ym57b1qjSKCMFsomfJQ0sA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13484068" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 15:33:29 -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 v5 16/36] drm/xe: Handle defrag moves in xe_bo_move() Date: Wed, 2 Dec 2026 15:33:03 -0800 Message-Id: <20261202233323.3743190-17-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261202233323.3743190-1-matthew.brost@intel.com> References: <20261202233323.3743190-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 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 98c0b32e9543..4c735ec8754e 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -1291,6 +1291,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; @@ -1331,6 +1332,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); @@ -1374,9 +1382,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; } @@ -1463,6 +1474,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