From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=192.198.163.12 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1796418819; b=O5lYk/7uvLsHz7b8+BaVa7tGEhNQVNfoYNcPEH/FksX5hXFgkIjw62hWSpXiLbgKGrdu HzZO0gbedNMpVb5laY3EzwPKwt//JziCi3pr8XcHwrDjfgyzMTlTx9taAhi9RQ22IncmD nKnvKTy/4eh7lA+e2Qekee2tKxI3BbUq+iFNxv/y5wbdKmRQHg1MoYLr8iUoTWSXUyKph kC9Vz+6b4Dabn4G2Kpos5Qc9Soqybo2Fl68FtT5rCQLZrPwin2iUjggxw/LT+Sd7Rq7dt vQSgGp7dD7mwYlPSTw3jNt0YxQJdKxu6qZunpqjGkbpzA2TBYyFPFb60t3q9SoawWfA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796418819; 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:Received:Received: Received:Received:Received:Date:From:To:CC:Subject:Message-ID: References:Content-Type:Content-Disposition:Content-Transfer-Encoding: In-Reply-To:X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-LD-Processed:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-Exchange-RoutingPolicyChecked: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; bh=08+jk6vqN7tqua5AGJtr3wgIBfDAYgsVhGOjmdrD7fI=; b=X0JH8B0goxX1NHi8kCoYiSTjqi1g4PbBjDjwb0TnVgpTFb9d1cNSZuAcp3cYDl+ZzPC3 qw/Q0yz5eljwAA1eT4o3Dek6xMqP21ic+jxm3K2Oi+SRQuA9ONWKVDMokkrsjnjq+yQOP tOYv1HQc/CtBQJuoJGmwwwz3YpX2Rea9gL9fPyxvfMAA6hQT41nqfbeLbfFIy6bbG/Vyl 0z+XTA5CQNQijl93MyommxnuQte9PDE/pVQAxMtLqseRuCw9nXAt3DDaJMEkK64X3QV6l +IqKvc2KmCGTolo5NXmA89HGz6Izy/ukC5lBsKMKD+91fg3MxKi3oQk9ez2qpRQvdjw== ARC-Authentication-Results: i=2; 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=FOlSipvM; arc=fail 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 46EBE606A32C for ; Fri, 4 Dec 2026 21:13:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 46EBE606A32C 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=FOlSipvM DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796418819; x=1827954819; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=08+jk6vqN7tqua5AGJtr3wgIBfDAYgsVhGOjmdrD7fI=; b=FOlSipvM9+ZxAFjWc1PHY0WAakjxgA/zoG5AGoQm9WLgf+L8/GKwUUwq chAmlam6AbiwFAjISrs5US9eeuLQC4MoTZA1eVNVrITVWNhA5+qevujbT MOywqY0PXcD+02N1dNmGb8bZJ6RGhRgfdP7z+YtUz9XLNO71gP0Fbjj24 IVfZZqZp+iWaDJ0KIhQClss7kRuJPux0BtDjjpx5mT6c7sB4Pn+plOkWR Hd/ZyY/6DeUzeTYGF/hcKeU5vSYNnBizvOOLxoftJHcIGqPSA/+k3B8Dr qLUwe5Kifdt9a3Uazt4sEffvNGjAEccBxjSNu26DswA+areg00W4w9ANo Q==; X-CSE-ConnectionGUID: fbrrXKK3SaCtgT6qGJAbrg== X-CSE-MsgGUID: FPUTRTtrQ6KweGHNgZoAAg== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5313075" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5313075" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 13:13:38 -0800 X-CSE-ConnectionGUID: jYmikLSTQZyIHLCEC0vuZQ== X-CSE-MsgGUID: gTQbx0/xQDOvkHtU4vHAJg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="14735998" Received: from fmsmsx901.amr.corp.intel.com ([10.18.126.90]) by fmviesa010.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 13:13:38 -0800 Received: from FMSMSX902.amr.corp.intel.com (10.18.126.91) by fmsmsx901.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Fri, 4 Dec 2026 13:13:36 -0800 Received: from fmsedg903.ED.cps.intel.com (10.1.192.145) by FMSMSX902.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Fri, 4 Dec 2026 13:13:36 -0800 Received: from MW6PR02CU001.outbound.protection.outlook.com (52.101.48.47) by edgegateway.intel.com (192.55.55.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Fri, 4 Dec 2026 13:13:36 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Nob7ByDAdTc2lHS75zgNs9T/j3Uh808q3qV2n3PVpJNE6ECwaY8h79Pyd+49YBEGtrHx3STziqEiabSbdE/13mgt1p2GssR11sgF3Qq6OH9v671w03psf2BgrVOSKwR3LglQdaiYK4UWOhRDVRzLKWyjV35CwLP1wW2GVcD51tJepnhOzlZfPwSp/2ZdhfSZALNdlTtRSGUCB3em/pVsufbgV2aHAhC5NmpOsxOklEr956cSXqia17er+PoP2gOrtmE5r0+v/zKAnHP0QFklmhtUXxE9aKcIgTvgf8NmRdie1z2uE4grXFK5/DlMwxqe+Q822thRvO34nF+38xKHgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hLydVxFcVYfpNA0MuJz48Espo955zB3+YrMTNgeQgs4=; b=bziXc2hYpINB4HSvW6IyhKDAGFLvu35bvrFxBsQkeQouYIeECQCICrSlnb4PpV7yBNXudI+4l+CPZQbcCCztcp6bQUYmLvKiWDNYzxxgNkLrezh7czKMB46uhSGdb99MewFazOEArZjV4l4kq46kRFKDzK5RyCHta1nugLZyyjKi39bbpo2W/9ecPVIMMC1T5iElJ2Q1D02J9+A23F8LYBACuDl1e4Oil01c+ROO1Txur6QoRVEA873KiDS+Q3HzrHe6yp6+kVypZIjwcLqmcF+rJh/PfqxyvL6GQaiGryOUIg59HDrphvN1Mji3r5TLfHJ9Fz/3jdvN0d7HNMzq1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from MW3PR11MB4684.namprd11.prod.outlook.com (2603:10b6:303:5d::14) by CH3PR11MB7867.namprd11.prod.outlook.com (2603:10b6:610:12a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.11; Fri, 4 Dec 2026 21:13:30 +0000 Received: from MW3PR11MB4684.namprd11.prod.outlook.com ([fe80::2f5a:96ce:f7e4:c315]) by MW3PR11MB4684.namprd11.prod.outlook.com ([fe80::2f5a:96ce:f7e4:c315%7]) with mapi id 15.21.0688.011; Fri, 4 Dec 2026 21:13:30 +0000 Date: Fri, 4 Dec 2026 13:13:27 -0800 From: Niranjana Vishwanathapura To: Matthew Brost CC: , , Carlos Santa , Ryan Neph , Natalie Vock , Arun Pravin , Matthew Auld , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , , Thomas =?iso-8859-1?Q?Hellstr=F6m?= Subject: Re: [PATCH v6 17/35] drm/xe: Skip self-copies for borrowed pages on defrag moves Message-ID: References: <20261203202352.4153159-1-matthew.brost@intel.com> <20261203202352.4153159-18-matthew.brost@intel.com> Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261203202352.4153159-18-matthew.brost@intel.com> X-ClientProxiedBy: SJ0PR13CA0015.namprd13.prod.outlook.com (2603:10b6:a03:2c0::20) To MW3PR11MB4684.namprd11.prod.outlook.com (2603:10b6:303:5d::14) 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 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW3PR11MB4684:EE_|CH3PR11MB7867:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d46c48d-ec41-46b8-03f7-08df524b71d2 X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|23010399003|366016|4143699003|6133799003|18002099003|22082099003|3023799007|5023799004|11063799006|56012099006|261021123027099003|261026121527099003|261028144727099003|10067099003|261026140227099003|261009223027099003|261102123227099003|261022105027099003|261021121427099003; X-Microsoft-Antispam-Message-Info: 5iGy6qw3SQG8a7s5RfbB7YYp65c3pwcyp5EF6Lqzz9y9TwX5qpUTu/k/N/ItcfRmTt1rfbLD7eBSLPxCV/VduCCJk6UDy/tkywTHnpFMgS+c7C7xWh7zWDEEofewmBMhmHSQCUEA0T4tt88azG8rHN9Pg7B+sISveq8Ply63GD5JgwqEg6JTP2TVnCunsBIyGQ/eUedzZupvOxEZ2yEwjJaJA5QYZXDwfukHyTGc2sdd7/PQJlDvE384Nu5WoZYGWvtqP/VVsVAEC8T7VvDgpP5oBlzx/ZTjZlwfQtOeX3/xYviE3TxRJy91sHOqMvzvf8Okw6+vIZmP3jI0oa0h1IaK4l45zIUESacTSrshdB1jlKad/WF1mmIoGGT2zBt36O7NnPjU0656Z2jSEhZ5sjltAUVW2qY6VTlbPrUgKUQErKJGVQm4xykR7C61X/1El1Wsr9ENbtd+n8mvbBsgwAw1lki4w77yQjAaLEJCuQ3/vL2OOssiJxk/ObHIK94Lrg9azdRIXn09CYHowLd0+lsRly/6ndc9+iqGauBEGEqXUmrAUp3xKC/xL5FD+DUqoIZPveJm0e81GSjvrimrbGZUqzZIrswGCKdRJyRM/VRFmCzNfnP9ctiPWH6N08GkCY9ixoVGJLq1s1jTFV0OVNJr/bCzF1fK0NwWV3KWohU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW3PR11MB4684.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(23010399003)(366016)(4143699003)(6133799003)(18002099003)(22082099003)(3023799007)(5023799004)(11063799006)(56012099006)(261021123027099003)(261026121527099003)(261028144727099003)(10067099003)(261026140227099003)(261009223027099003)(261102123227099003)(261022105027099003)(261021121427099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?fTH6ilPvFT01D/9OefGOI73gzO0rcPOwGuExZ7UeM9HfSH2MXANHasRviJ?= =?iso-8859-1?Q?RT1tHdnXeaVgTkK19gCxWrK0mOKNuyn2wh9GfsAcpOXQP97fbXYF2RTd1/?= =?iso-8859-1?Q?OGwI1rlq2LJaxi2iilT5IURcrdAJchUQRXUQRGSCMROZp1683nPU7q5Ilv?= =?iso-8859-1?Q?wzJSZ1w1A/KAqXSfS2Voof01h0UynqD6/j73JlNytNuvkWKj05tPMfo+Bu?= =?iso-8859-1?Q?jTF/o4MZFVOoOf3/D17AbYFB1duU1ZZnbxp9vyglNqkkc18UIQ+Ce5rIJI?= =?iso-8859-1?Q?cHb2gCwPv3PyamO1bDeszngVKyaQeUf+Q/8NK9D+Qu8jxiK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6bzq46roqwxX0xJ9hrGzU5NqPbmwzvycgU6sMnVAUOIN69gGWbg0KtKvrLDoD6MsvCQQ== X-MS-Exchange-CrossTenant-Network-Message-Id: 6d46c48d-ec41-46b8-03f7-08df524b71d2 X-MS-Exchange-CrossTenant-AuthSource: MW3PR11MB4684.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 21:13:30.1696 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SkZnkhhEW32FA6karp5KK+69hiApHf8CntIsuA+ODYnPGM89z54Q1DdgjGm+zsIGRF/TEwOMRVOtBx3e8Bu/E/ubvb+PAzbIBB7a5wB/Ohj7l53mOuwde+jwvYUBc2Xt X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR11MB7867 X-OriginatorOrg: intel.com On Thu, Dec 03, 2026 at 12:23:34PM -0800, Matthew Brost wrote: >A defrag move may harvest already beneficial-order chunks from the old >tt, so the freshly reallocated backing borrows (references) some of the >same physical pages. For those pages the source and destination GPU >mappings alias the same memory, making the data blit a pointless >self-copy. > >Pass the source (old) tt into __xe_migrate_copy() instead of just its sg >table, so the data pass can compare the src and dst tt page arrays at the >matching offset and only blit runs of pages that actually differ. A new >emit_copy_chunks() helper walks each L0 chunk, skips borrowed-page runs, >and coalesces contiguous to-copy pages into a single emit_copy(). It runs >twice per chunk: once with a NULL batch buffer to count the blits for >batch sizing, then again to emit them. > >When an entire L0 chunk turns out to be borrowed, skip it outright: no >batch buffer is allocated and no GPU commands are issued, the cursors are >just advanced past the chunk. A defrag move always reallocates at least >one chunk, so a job carrying the resv dependencies is emitted unless that >chunk lies wholly in the trailing CCS backup pages beyond the BO data, >whose contents are stale while in TT. Then no copy is needed and the BO's >existing resv fences are returned as a singleton, so the old tt is not >torn down under in-flight GPU work. > >The comparison is a cheap per-page pointer test (src page != dst page) >that coalesces contiguous to-copy pages into a single blit. PTEs are >still emitted for partially borrowed chunks, since that setup is cheap and >only the data copies are worth skipping. Only the defrag data pass is >affected; the separate CCS pass still migrates all aux state. > >Since the Xe tt sg lives in the xe_ttm_tt subclass rather than the base >ttm_tt, add an xe_tt_sg() helper to fetch it from a struct ttm_tt. > >v3: > - Fix start_page page-shift and blit pitch for src-natural to > dst-packed copies (Sashiko) >v4: > - Drop L0 naming (Niranjana) > - Assert src_tt/dst_tt (Niranjana) >v5: > - Assert a copy always occurs (Sashiko) >v6: > - Return resv singleton when only CCS backup pages were reallocated, > fix commit message (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 LGTM. Reviewed-by: Niranjana Vishwanathapura >--- > drivers/gpu/drm/xe/xe_bo.c | 22 ++++- > drivers/gpu/drm/xe/xe_bo.h | 2 + > drivers/gpu/drm/xe/xe_migrate.c | 161 ++++++++++++++++++++++++++++---- > drivers/gpu/drm/xe/xe_migrate.h | 3 +- > 4 files changed, 163 insertions(+), 25 deletions(-) > >diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c >index 886029c0f90d..01667dfba78f 100644 >--- a/drivers/gpu/drm/xe/xe_bo.c >+++ b/drivers/gpu/drm/xe/xe_bo.c >@@ -496,6 +496,22 @@ struct sg_table *xe_bo_sg(struct xe_bo *bo) > return xe_tt->sg; > } > >+/** >+ * xe_tt_sg() - Return the DMA scatter-gather table backing a ttm_tt. >+ * @tt: The ttm_tt to query. >+ * >+ * Like xe_bo_sg(), but takes the ttm_tt directly. Used by the defrag copy >+ * path which needs the old (source) tt's sg table without a backing xe_bo. >+ * >+ * Return: The sg table, or NULL if the tt is not currently mapped. >+ */ >+struct sg_table *xe_tt_sg(struct ttm_tt *tt) >+{ >+ struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm); >+ >+ return xe_tt->sg; >+} >+ > /* > * Account ttm pages against the device shrinker's shrinkable and > * purgeable counts. >@@ -1487,11 +1503,9 @@ 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); >+ ttm_bo->defrag_old_tt, >+ handle_system_ccs); > } else { > fence = xe_migrate_copy(migrate, bo, bo, old_mem, new_mem, > handle_system_ccs, ctx->interruptible); >diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h >index 4ec3a2dbaf68..f6b8b71228c6 100644 >--- a/drivers/gpu/drm/xe/xe_bo.h >+++ b/drivers/gpu/drm/xe/xe_bo.h >@@ -114,6 +114,7 @@ enum xe_madv_purgeable_state { > > struct drm_printer; > struct sg_table; >+struct ttm_tt; > > struct xe_bo *xe_bo_alloc(void); > void xe_bo_free(struct xe_bo *bo); >@@ -565,6 +566,7 @@ void xe_bo_dev_init(struct xe_bo_dev *bo_device); > void xe_bo_dev_fini(struct xe_bo_dev *bo_device); > > struct sg_table *xe_bo_sg(struct xe_bo *bo); >+struct sg_table *xe_tt_sg(struct ttm_tt *tt); > > /** > * xe_bo_sg_is_contiguous() - Check if a BO's DMA address space is contiguous. >diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c >index e1ca896c0f31..1516985c9387 100644 >--- a/drivers/gpu/drm/xe/xe_migrate.c >+++ b/drivers/gpu/drm/xe/xe_migrate.c >@@ -1228,6 +1228,63 @@ static void emit_copy(struct xe_gt *gt, struct xe_bb *bb, > emit_xy_fast_copy(gt, bb, src_ofs, dst_ofs, size, pitch); > } > >+/* >+ * emit_copy_chunks() - Emit the data blits for one defrag chunk, skipping >+ * borrowed pages. >+ * @gt: The GT. >+ * @bb: The batch buffer to emit into, or NULL to only count the blits needed. >+ * @src_ofs: GPU offset of the source pages mapped for this chunk. >+ * @dst_ofs: GPU offset of the destination pages mapped for this chunk. >+ * @src_bytes: Byte size of the chunk (page aligned). >+ * @src_tt: Source (old) tt providing the page pointers. >+ * @dst_tt: Destination (new) tt providing the page pointers. >+ * @start_page: Page offset of this chunk within the tt page arrays. >+ * >+ * A defragmentation move may harvest already beneficial-order chunks from the >+ * old tt, so the new tt references (borrows) some of the same physical pages. >+ * For those pages the source and destination GPU mappings alias the same >+ * memory and the data blit is a pointless self-copy. Walk the chunk and >+ * only blit runs of pages that actually differ (src page != dst page), >+ * coalescing contiguous to-copy pages into a single blit. >+ * >+ * Return: The number of blits emitted (or that would be emitted when @bb is >+ * NULL). >+ */ >+static u32 emit_copy_chunks(struct xe_gt *gt, struct xe_bb *bb, >+ u64 src_ofs, u64 dst_ofs, u32 src_bytes, >+ struct ttm_tt *src_tt, struct ttm_tt *dst_tt, >+ pgoff_t start_page) >+{ >+ u32 npages = src_bytes >> PAGE_SHIFT; >+ u32 i = 0, nblits = 0; >+ >+ while (i < npages) { >+ u32 run = 0; >+ >+ /* Skip a run of borrowed pages (src and dst alias). */ >+ if (src_tt->pages[start_page + i] == >+ dst_tt->pages[start_page + i]) { >+ i++; >+ continue; >+ } >+ >+ /* Coalesce a run of pages that actually need copying. */ >+ while (i + run < npages && >+ src_tt->pages[start_page + i + run] != >+ dst_tt->pages[start_page + i + run]) >+ run++; >+ >+ if (bb) >+ emit_copy(gt, bb, src_ofs + (u64)i * PAGE_SIZE, >+ dst_ofs + (u64)i * PAGE_SIZE, >+ run * PAGE_SIZE, XE_PAGE_SIZE); >+ nblits++; >+ i += run; >+ } >+ >+ return nblits; >+} >+ > static u64 xe_migrate_batch_base(struct xe_migrate *m, bool usm) > { > return usm ? m->usm_batch_base_ofs : m->batch_base_ofs; >@@ -1302,14 +1359,15 @@ static bool is_devmem(struct xe_bo *bo, struct ttm_resource *res) > * @XE_MIGRATE_COPY_VRAM_RESOLVE: Decompression (VRAM -> system) resolve; > * always uses the compression PAT index for the data copy. > * @XE_MIGRATE_COPY_DEFRAG_DATA: Defrag move pass that copies the data pages >- * between two distinct page sets (old @src_sg pages -> new pages) without >- * touching the CCS aux state. The data pages are mapped without the >- * compression PAT so the (possibly compressed) bytes are copied verbatim >- * rather than being decompressed and recompressed, and no CCS aux copy is >- * appended; the aux state is migrated separately by the >- * @XE_MIGRATE_COPY_DEFRAG_CCS pass. >+ * between two distinct page sets (old @src_tt pages -> new pages) without >+ * touching the CCS aux state. Pages the new tt borrowed from @src_tt >+ * (harvested already beneficial-order chunks) alias the same memory on both >+ * sides and are skipped. The data pages are mapped without the compression PAT >+ * so the (possibly compressed) bytes are copied verbatim rather than being >+ * decompressed and recompressed, and no CCS aux copy is appended; the aux >+ * state is migrated separately by the @XE_MIGRATE_COPY_DEFRAG_CCS pass. > * @XE_MIGRATE_COPY_DEFRAG_CCS: Defrag move pass that migrates only the CCS aux >- * state between two distinct page sets (old @src_sg pages -> new pages). The >+ * state between two distinct page sets (old @src_tt pages -> new pages). The > * data blit is skipped (the data was copied by the > * @XE_MIGRATE_COPY_DEFRAG_DATA pass) and both the source and destination data > * pages are mapped with the compression PAT so the aux state is copied >@@ -1329,7 +1387,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > struct xe_bo *dst_bo, > struct ttm_resource *src, > struct ttm_resource *dst, >- struct sg_table *src_sg, >+ struct ttm_tt *src_tt, > enum xe_migrate_copy_mode mode, > bool intr) > { >@@ -1359,6 +1417,14 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > !defrag_copy; > bool copy_system_ccs = copy_ccs && (!src_is_vram || !dst_is_vram) && > !defrag_ccs && !defrag_copy; >+ /* >+ * On the defrag data pass the new (destination) tt may have borrowed >+ * already beneficial-order pages from the old (source) tt, so skip the >+ * self-copy for any page they share. Compare the tt page arrays at the >+ * matching offset. >+ */ >+ struct ttm_tt *dst_tt = dst_bo->ttm.ttm; >+ bool skip_borrowed = defrag_copy; > > /* > * For decompression operation, always use the compression PAT index. >@@ -1371,10 +1437,13 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > > /* > * The defrag CCS pass migrates the aux state from the old pages >- * (@src_sg) to the new pages with both sides accessed indirectly, so >+ * (@src_tt) to the new pages with both sides accessed indirectly, so > * keep both src_is_pltt and dst_is_pltt set (no direct staging side). > */ > >+ /* Defrag passes compare the old (@src_tt) and new tt page arrays. */ >+ xe_assert(xe, !(defrag_copy || defrag_ccs) || (src_tt && dst_tt)); >+ > /* Copying CCS between two different BOs is not supported yet. */ > if (XE_WARN_ON(copy_ccs && src_bo != dst_bo)) > return ERR_PTR(-EINVAL); >@@ -1383,7 +1452,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > return ERR_PTR(-EINVAL); > > if (!src_is_vram && src->mem_type != XE_PL_STOLEN) >- xe_res_first_sg(src_sg ? src_sg : xe_bo_sg(src_bo), 0, size, &src_it); >+ xe_res_first_sg(src_tt ? xe_tt_sg(src_tt) : xe_bo_sg(src_bo), 0, size, &src_it); > else > xe_res_first(src, 0, size, &src_it); > if (!dst_is_vram && dst->mem_type != XE_PL_STOLEN) >@@ -1392,7 +1461,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > xe_res_first(dst, 0, size, &dst_it); > > if (copy_system_ccs) >- xe_res_first_sg(src_sg ? src_sg : xe_bo_sg(src_bo), >+ xe_res_first_sg(src_tt ? xe_tt_sg(src_tt) : xe_bo_sg(src_bo), > xe_bo_ccs_pages_start(src_bo), > PAGE_ALIGN(xe_device_ccs_bytes(xe, size)), > &ccs_it); >@@ -1406,6 +1475,8 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > u64 ccs_ofs, ccs_size; > u32 ccs_pt; > u32 pte_flags; >+ pgoff_t start_page = (xe_bo_size(src_bo) - size) >> PAGE_SHIFT; >+ u32 ndata_blits = 1; > > bool usm = xe->info.has_usm; > u32 avail_pts = max_mem_transfer_per_pass(xe) / LEVEL0_PAGE_TABLE_ENCODE_SIZE; >@@ -1443,9 +1514,30 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > xe_assert(xe, IS_ALIGNED(ccs_it.start, PAGE_SIZE)); > } > >- /* Add copy commands size here */ >+ /* >+ * Add copy commands size here. On the defrag data pass the blit >+ * is split into one command per run of non-borrowed pages, so >+ * size for the number of runs actually needed. >+ */ >+ if (skip_borrowed) >+ ndata_blits = emit_copy_chunks(gt, NULL, 0, 0, src_L0, >+ src_tt, dst_tt, start_page); >+ >+ /* >+ * If every page in this chunk was borrowed there is nothing to >+ * copy: don't build a batch or issue any GPU commands, just >+ * advance the cursors past the chunk. The non-vram tt cursors >+ * would otherwise be advanced by emit_pte(). >+ */ >+ if (skip_borrowed && !ndata_blits) { >+ xe_res_next(&src_it, src_L0); >+ xe_res_next(&dst_it, src_L0); >+ size -= src_L0; >+ continue; >+ } >+ > batch_size += ((copy_only_ccs || defrag_ccs) ? 0 : >- emit_copy_cmd_len(xe)) + >+ ndata_blits * emit_copy_cmd_len(xe)) + > ((needs_ccs_emit ? EMIT_COPY_CCS_DW : 0)); > > bb = __xe_bb_new(gt, batch_size, usm, !fence && intr); >@@ -1474,7 +1566,10 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > bb->cs[bb->len++] = MI_BATCH_BUFFER_END; > update_idx = bb->len; > >- if (!copy_only_ccs && !defrag_ccs) >+ if (skip_borrowed) >+ emit_copy_chunks(gt, bb, src_L0_ofs, dst_L0_ofs, src_L0, >+ src_tt, dst_tt, start_page); >+ else if (!copy_only_ccs && !defrag_ccs) > emit_copy(gt, bb, src_L0_ofs, dst_L0_ofs, src_L0, XE_PAGE_SIZE); > > if (needs_ccs_emit) >@@ -1530,6 +1625,29 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > return ERR_PTR(err); > } > >+ /* >+ * A defrag move always (re)allocates at least one chunk (TTM fails a >+ * zero-progress defrag move), but that chunk may lie entirely in the >+ * trailing CCS backup pages (extra_pages) beyond the BO data, which >+ * hold stale contents while in TT and need no copy. Every data page >+ * was then borrowed and no job was emitted, so hand back the BO's >+ * existing fences instead: the job would have depended on exactly >+ * these, and a signaled stub would let the old tt be torn down under >+ * in-flight GPU work. Any other copy always emits a job. >+ */ >+ if (!fence) { >+ if (XE_WARN_ON(!(defrag_copy || defrag_ccs) || >+ !xe_bo_needs_ccs_pages(src_bo))) >+ return ERR_PTR(-EINVAL); >+ >+ err = dma_resv_get_singleton(src_bo->ttm.base.resv, >+ DMA_RESV_USAGE_BOOKKEEP, &fence); >+ if (err) >+ return ERR_PTR(err); >+ if (!fence) >+ fence = dma_fence_get_stub(); >+ } >+ > return fence; > } > >@@ -1572,18 +1690,21 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m, > * @bo: The buffer object being defragmented. Both @src and @dst belong to @bo. > * @src: The source TTM resource (the old backing). > * @dst: The dst TTM resource (the freshly reallocated backing). >- * @src_sg: Scatter-gather table of the source (old) backing pages. >+ * @src_tt: The source (old) backing tt, providing both the scatter-gather >+ * table and page pointers of the old pages. > * @need_ccs: Whether the BO has CCS aux state that must be migrated too. > * > * Used by the defrag path where a single BO has its backing reallocated at a > * more beneficial page order. The contents are relocated from the old pages >- * (@src_sg) to the new pages (the BO's current backing) entirely on the GPU, >+ * (@src_tt) to the new pages (the BO's current backing) entirely on the GPU, > * in up to two passes: > * > * - Data pass (always): copy the data pages verbatim. The pages are mapped > * without the compression PAT, so the (possibly compressed) bytes are copied > * as-is rather than being decompressed and recompressed, and no CCS aux copy >- * is appended. >+ * is appended. Pages the new backing borrowed from @src_tt (harvested >+ * already beneficial-order chunks) alias the same memory on both sides and >+ * are skipped. > * > * - CCS pass (@need_ccs): copy the CCS aux (compression) state. Both the old > * and new data pages are mapped with the compression PAT so the copy engine >@@ -1604,17 +1725,17 @@ struct dma_fence *xe_migrate_copy_defrag(struct xe_migrate *m, > struct xe_bo *bo, > struct ttm_resource *src, > struct ttm_resource *dst, >- struct sg_table *src_sg, >+ struct ttm_tt *src_tt, > bool need_ccs) > { > struct dma_fence *fence2, *fence = >- __xe_migrate_copy(m, bo, bo, src, dst, src_sg, >+ __xe_migrate_copy(m, bo, bo, src, dst, src_tt, > XE_MIGRATE_COPY_DEFRAG_DATA, false); > > if (IS_ERR(fence) || !need_ccs) > return fence; > >- fence2 = __xe_migrate_copy(m, bo, bo, src, dst, src_sg, >+ fence2 = __xe_migrate_copy(m, bo, bo, src, dst, src_tt, > XE_MIGRATE_COPY_DEFRAG_CCS, false); > if (IS_ERR(fence2)) > dma_fence_wait(fence, false); >diff --git a/drivers/gpu/drm/xe/xe_migrate.h b/drivers/gpu/drm/xe/xe_migrate.h >index 70451392e0a7..c410652641f5 100644 >--- a/drivers/gpu/drm/xe/xe_migrate.h >+++ b/drivers/gpu/drm/xe/xe_migrate.h >@@ -13,6 +13,7 @@ struct drm_pagemap_addr; > struct iosys_map; > struct sg_table; > struct ttm_resource; >+struct ttm_tt; > > struct xe_bo; > struct xe_gt; >@@ -64,7 +65,7 @@ struct dma_fence *xe_migrate_copy_defrag(struct xe_migrate *m, > struct xe_bo *bo, > struct ttm_resource *src, > struct ttm_resource *dst, >- struct sg_table *src_sg, >+ struct ttm_tt *src_tt, > bool need_ccs); > > struct dma_fence *xe_migrate_resolve(struct xe_migrate *m, >-- >2.34.1 >