From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=192.198.163.11 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1796243079; b=uXlWkrjsqlNpJyxD6gXXFXFl7q45KYAMF2O1YzEQAsfVgmaY0UL2SQ+0UCRbFzB5//rn r9+Szha0uYBiiJgml7zkzwFr19u2+zaJDlPuIcpjqxLBnN0M1oVkH1Y120tiRD5uYOlLO y5vEtj6WGVs2M/9sAaxBAOxwhRaEmrRfg9EAOwwY/vo+ZljivfUirB1j0QmVhQLvjI1Gt MS3qDGzjXs3/rcYyVr/ZC32bpLFR52CJ58dirZAf5FS4p5C3GZKXijPozNqPomLFTUTDH OX2Vu/ISygnUXOGiuNLXBgCitlisIlF7TCTVSi2Xf0cCOdlcYwQAi6JcnwrafM5G6iQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796243079; 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=DPFwybQnTwgGqi/i4rHHcUQESwHCw7D5+++J1q5gqJo=; b=AFvHsvj3bwf386e+d7DY08HoqeZ09TPFBM2VhzAuAmJsaOk453vG90h6K5cQXM8imY9q lhcyHWEtSuHIRrzTXBRWRIzm8dRqUIvg5r23zpB7qDrKy07UbU7O9zpEhbC+GU5bmy6Nc j1HC0ryWSxF0mqVH0F/yrB9LTOQi4oI46eDvX/PP6zSN3efA3pp9fQHfKumkIZzYxwv3e P9kErGdZTcOe1eJL0sfVw72HlH5HumWvxfJUR4A/Z6QA2OslJR5vh5B9h5JvM12xgLSE2 q/K9VBbxfG+QcVg8yFY8+QfRE7h7QhARlIuu3HIOToLjkFQS2enErm/TG0y4p52pW/g== 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="aMTuzfs/"; arc=fail smtp.remote-ip=192.198.163.11 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 890E9606A322 for ; Wed, 2 Dec 2026 20:24:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 890E9606A322 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, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=aMTuzfs/ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796243079; x=1827779079; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=DPFwybQnTwgGqi/i4rHHcUQESwHCw7D5+++J1q5gqJo=; b=aMTuzfs/WPI4eYwcI058OU/ZellwyPmT2vNjK7pdL+284LyAta5Ws/X4 LlBhGIJLzk1Kq2hM+fKGD59ql+63DRkmx9+fCYf5P8ajmVZksijPW59Ao iTVLF+uSm/Wrix+1Scs49mw8R3cGirbYM2fUobPhOwsBSuB1zvLParoY8 kkh/Qq1DgTRPCDWmiRQZ4ebtDoTHikpbdcsK0CXBA+UFzCtjdRdO0TcMO 8pqUkGcFB748iOmRO+pSetRYV84gnjnAqzif92yQT8HNMl4ivM+a/6e3B TNIw17/mB9Fq+IBMbAJh2dDc2EDyNCq5alQBiPmIPvITI80OPYnGcmA/L w==; X-CSE-ConnectionGUID: P4V//KGrTdaQ3lhHPqtckA== X-CSE-MsgGUID: sFoVlvojRgSCQ/lGAe306w== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5089406" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5089406" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 12:24:38 -0800 X-CSE-ConnectionGUID: jNCVUp3NSeCQ8rO6jd5CqQ== X-CSE-MsgGUID: i2IlfhdZRjiWKQyjSUYWqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13441630" Received: from orsmsx903.amr.corp.intel.com ([10.22.229.25]) by orviesa004.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 12:24:37 -0800 Received: from ORSMSX903.amr.corp.intel.com (10.22.229.25) by ORSMSX903.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 12:24:36 -0800 Received: from ORSEDG901.ED.cps.intel.com (10.7.248.11) by ORSMSX903.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Wed, 2 Dec 2026 12:24:36 -0800 Received: from SN4PR2101CU001.outbound.protection.outlook.com (40.93.195.50) by edgegateway.intel.com (134.134.137.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 12:24:36 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gEvFfB280wMEqlGn+BsvlU2TQaTFFV4wO0ulKXlbeFC4EL4TuOn1Q18k1lyPJzeVXwvY3P7e/ELjsxLJ7e1shEWru8zezw1kTjimpW4dpdWZ+YyIboTPCeG212pkcrWJuLve19YsP/wZnt/lc3Alnvk8WLGFNhXRv/uLvBMvc+JEBs1trvB6cd8qU9HvbzIf17PAZ4F4M7xkOs4X45x7O3rjeXUZ6NZsvNZW8J9sPdVDHb71W8ODvX2Nm4bMx6L8Irvs5ym0bl/lI4qJiSQEGmB3qLEETUBS/WU+5gdjYLkGOMaNGGon0sQNSHmsa6PUe05KJed7lILr8nASZmNEBQ== 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=YOTL7pgPVN+OVNZYND6iCaCQDKgyfybDLE5to7bQmgo=; b=ZXoUY4YW3OPZBWflnh2RdwxToyoP+4MVJ0ORntcOE0P8rV/H8OILn9IyrOEsY3tIsRuHQVdsH2E59Hh5h9yjw9Z/NaEzE2uXYU/kQ0qkNr9A8jn5iFVSLU/0J3fDs/C07wtORe69TMOfVXf81r2NO5jd9+YifYDG9SIZTG8JkGLSecSKVbcnGoeT4vgWvWSj8Zv6SvadLJLnTyZ7NB1JP5i5nLMd2wY9NV1Eq4k/5xt1+RrPmnBZC6AWoahumqNaSgGuMZwItjKx8Ls4bIaWNOXsv/u4PHHmeQFmklck08TUfEhlyF6Y8oYyCt0pQKlk6t69hHQB++MubFzI+qfDyg== 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 SA1PR11MB5828.namprd11.prod.outlook.com (2603:10b6:806:237::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 20:24:17 +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.009; Wed, 2 Dec 2026 20:24:17 +0000 Date: Wed, 2 Dec 2026 12:24:13 -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 v4 28/33] drm/xe: Add packed copy-step IOVA mapping for defrag Message-ID: References: <20261201234915.3305331-1-matthew.brost@intel.com> <20261201234915.3305331-29-matthew.brost@intel.com> Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261201234915.3305331-29-matthew.brost@intel.com> X-ClientProxiedBy: PH8PR21CA0018.namprd21.prod.outlook.com (2603:10b6:510:2ce::8) 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_|SA1PR11MB5828:EE_ X-MS-Office365-Filtering-Correlation-Id: 03e8f698-8e87-48ed-7155-08df50b23d03 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|7416014|376014|366016|1800799024|23010399003|4143699003|6133799003|261009223027099003|18002099003|22082099003|3023799007|10067099003|56012099006|5023799004|261022075727099003|261028144727099003|261102123227099003|11063799006|261022105027099003|261021121427099003|261026121527099003|261026140227099003; X-Microsoft-Antispam-Message-Info: Qrzilv8rWzFLs7UavFj2cQYjLaSkmSbeD5kOe4Bq2djywkMKGofm+I3NhMlvjACPsienD4bHJI1yQTDyHtN+fJjy7qcZn3AMrF/4JQXHtWd64QYRr4AZER+JRF/vi791h6fsF90NiRv0IIzYuYqNdIv7gll/xE74uaE7OpXbOYxfBqrfDPKv13qpcWM3I+LPfsx0bgFYTAynJzIbUkXUsldScOpv6gMSDhcAjee+X/J63Ie/j6wzg9BPpan4GEs/dp+9GC9r+qn/y93c/ofSOuF6Yaoow78VNa9aHKBpStCxGJ71HOrE1k4yVmCKz3SPYtxlcMaM13tp0p5K9V26lGFY3sx8+rhEJcBgs1ZKzEqw2OYcnt4IIC276W3Smv9Aq4S8QwpsSE27NmxgFAhqZRnKs0qeUv9P/FHdbF6t6c4Cdh/VY/BRaHaPxULk+WRg/cGda9hzQ/bkiw0Pf8uS2ShFBaIOAR2SISaeSBtZkW7zTnqIvU4feWIYkFukdbWAM60Rpq/nWM+oYQVB+nD9zz0EXRPTZO3w8UN0WNeTK4WneLC9NtIlmS6q9R1hbIMqHY1iYiF3mvJw39FurcVQHpcKFBf0LajZ4oeSStQw7Ue+fomPjHWkD79FJgoFORDiSbkaFUhchKUMLvoGjMRQNZrXr3toOdxnOpNkNcoEfnI= 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)(7416014)(376014)(366016)(1800799024)(23010399003)(4143699003)(6133799003)(261009223027099003)(18002099003)(22082099003)(3023799007)(10067099003)(56012099006)(5023799004)(261022075727099003)(261028144727099003)(261102123227099003)(11063799006)(261022105027099003)(261021121427099003)(261026121527099003)(261026140227099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?KpxciupBr2eybG/guP8qfJTD53xsviMjLV/LbA7exLLDry5H6xLOGUf2/X?= =?iso-8859-1?Q?RHTO8RbpHgrDHjr9IW8TSFLx5JJFBIM01eqM6XQ8yszo1/1If2Rc1Piz4R?= =?iso-8859-1?Q?c+SxHgBjUylU8jNKbnLY/NSiixqtU8+9oQA6CQn5Ll1AJbs8ffTlrJSHjm?= =?iso-8859-1?Q?AD/JLTH8o3D08G/P5vJHlovpq457PXUzjKisqLPlH6w2uMmS8d9JjUk4zr?= =?iso-8859-1?Q?GuFlJxOEq/t7zptCuH6YOM62L/QgNp4kKm+toChlJVad1qzuHZ/FPYZWud?= =?iso-8859-1?Q?Cd7OHeEAvpjS6uTwlSjlF4bfMh+wxY4k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JFqdI4wuwh3bGk9hDbQUALyhHkEpY+vMCQQspyIsnpgDg2VwOcM18/XDJ+dl2XQILQg== X-MS-Exchange-CrossTenant-Network-Message-Id: 03e8f698-8e87-48ed-7155-08df50b23d03 X-MS-Exchange-CrossTenant-AuthSource: MW3PR11MB4684.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 20:24:16.9705 (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: f7zTFCLOylOEOTHeHhKDyJx1xD091S5OHyp/Omw8Q+3Zz3cgOLwEfCcw8EVqZ3tarV34gJGiagytxkDqNBgEG4dym6UB5t0nfgooBA5Ypden5kjEhqFAZSdJ3w3JJp1z X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR11MB5828 X-OriginatorOrg: intel.com On Tue, Dec 01, 2026 at 03:49:10PM -0800, Matthew Brost wrote: >Add machinery to map only changed pages during defrag when the >destination TT is IOVA-mapped. Only the non-borrowed (freshly >allocated) pages need copying; borrowed pages are aliases from >the old TT. > >Add xe_tt_iova_copy_init() to diff new vs old TT folios and >record changed-page runs. Add xe_tt_map_iova_copy() to link >those changed pages packed contiguously at the front of the >new TT's IOVA reservation, synced and ready for GPU blits. > >No users yet; wired up in later patches. > >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 NIT..missing vesion histrory update (resulted from patch 26 dma_iova call shuffling). Changes LGTM. Reviewed-by: Niranjana Vishwanathapura >--- > drivers/gpu/drm/xe/xe_bo.c | 371 +++++++++++++++++++++++++++++++++++++ > 1 file changed, 371 insertions(+) > >diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c >index 993c26b6e809..1a02fe407d78 100644 >--- a/drivers/gpu/drm/xe/xe_bo.c >+++ b/drivers/gpu/drm/xe/xe_bo.c >@@ -559,6 +559,31 @@ static void xe_tt_unaccount_iova(struct xe_device *xe, > } > } > } >+ >+/* >+ * xe_tt_account_iova_pages - account a tt's pages from a full folio walk >+ * @xe: the xe device >+ * @xe_tt: the xe_ttm_tt to account (its @iova_dma_pages must start zeroed) >+ * >+ * Walk @xe_tt's pages one folio at a time (the same head-page order walk used >+ * by xe_tt_map_iova()) and account each into xe->mem.dma_mapped_pages[] and >+ * @xe_tt->iova_dma_pages[]. Used to (re)derive accounting that exactly matches >+ * the pages a tt is actually mapped with. >+ */ >+__maybe_unused >+static void xe_tt_account_iova_pages(struct xe_device *xe, >+ struct xe_ttm_tt *xe_tt) >+{ >+ struct ttm_tt *tt = &xe_tt->ttm; >+ unsigned long i = 0; >+ >+ while (i < tt->num_pages) { >+ unsigned int order = ttm_pool_page_order_nodma(tt->pages[i]); >+ >+ xe_tt_account_iova_add(xe, xe_tt, order); >+ i += 1UL << order; >+ } >+} > #else > static void xe_tt_account_iova_add(struct xe_device *xe, > struct xe_ttm_tt *xe_tt, unsigned int order) >@@ -569,6 +594,12 @@ static void xe_tt_unaccount_iova(struct xe_device *xe, > struct xe_ttm_tt *xe_tt) > { > } >+ >+__maybe_unused >+static void xe_tt_account_iova_pages(struct xe_device *xe, >+ struct xe_ttm_tt *xe_tt) >+{ >+} > #endif > > static int xe_tt_map_sg(struct xe_device *xe, struct ttm_tt *tt) >@@ -810,6 +841,346 @@ bool xe_bo_sg_is_contiguous(struct xe_bo *bo, size_t len) > return drm_prime_get_contiguous_size(xe_tt->sg) >= len; > } > >+/** >+ * struct xe_tt_iova_run - A contiguous run of changed pages in a defrag move >+ * @start: First page offset (natural ttm_tt index) of the run. >+ * @count: Number of pages in the run. >+ * >+ * Runs are folio aligned: defrag borrows whole beneficial-order chunks, so a >+ * folio is either entirely borrowed (unchanged) or entirely freshly allocated >+ * (changed), never split across the boundary. >+ */ >+struct xe_tt_iova_run { >+ pgoff_t start; >+ pgoff_t count; >+}; >+ >+/** >+ * struct xe_tt_iova_link - A snapshot folio link descriptor for defrag relink >+ * @phys: Physical address of the folio's head page. >+ * @offset: Natural byte offset into the reservation to link the folio at. >+ * @len: Byte length of the folio (PAGE_SIZE << order). >+ * >+ * Captured at copy-init time while the destination tt's page array is valid and >+ * stable under the BO lock. The post-copy finalize job runs asynchronously, >+ * after TTM may have mutated (or torn down) the destination tt page array, so >+ * it relinks purely from these snapshots and never dereferences that array. >+ */ >+struct xe_tt_iova_link { >+ phys_addr_t phys; >+ size_t offset; >+ size_t len; >+}; >+ >+/** >+ * struct xe_tt_iova_copy - Changed-page subset of an IOVA defrag move >+ * @runs: Array of changed-page runs, in ascending natural tt offset. >+ * @nr_runs: Number of entries in @runs. >+ * @links: Per-folio link snapshots covering the changed runs, in ascending >+ * natural offset. Drives the asynchronous finalize relink so it never >+ * touches the destination tt's (possibly mutated) page array. >+ * @nr_links: Number of entries in @links. >+ * @nr_changed: Total number of changed pages (sum of the run counts). This is >+ * also the size, in pages, of the packed copy-step IOVA mapping >+ * produced by xe_tt_map_iova_copy(). >+ */ >+struct xe_tt_iova_copy { >+ struct xe_tt_iova_run *runs; >+ unsigned int nr_runs; >+ struct xe_tt_iova_link *links; >+ unsigned int nr_links; >+ pgoff_t nr_changed; >+}; >+ >+/* >+ * xe_tt_iova_walk_changed - Walk a defrag move's changed-page runs. >+ * >+ * Iterate @new_tt one folio at a time (folio order read from TTM via >+ * ttm_pool_page_order_nodma()) and compare each folio's head page against >+ * @old_tt at the same natural offset. Pages the new backing borrowed from the >+ * old tt alias the same struct page and are unchanged; freshly allocated pages >+ * differ. Coalesce contiguous changed folios into runs and, for each run, >+ * invoke @fn. Returns the total number of changed pages. >+ */ >+__maybe_unused >+static pgoff_t xe_tt_iova_walk_changed(struct ttm_tt *new_tt, >+ struct ttm_tt *old_tt, >+ void (*fn)(pgoff_t start, pgoff_t count, >+ void *arg), >+ void *arg) >+{ >+ pgoff_t i = 0, n = new_tt->num_pages; >+ pgoff_t run_start = 0, nr_changed = 0; >+ bool in_run = false; >+ >+ while (i < n) { >+ unsigned int order = ttm_pool_page_order_nodma(new_tt->pages[i]); >+ pgoff_t nr = 1UL << order; >+ bool changed = new_tt->pages[i] != old_tt->pages[i]; >+ >+ if (changed) { >+ if (!in_run) { >+ run_start = i; >+ in_run = true; >+ } >+ nr_changed += nr; >+ } else if (in_run) { >+ if (fn) >+ fn(run_start, i - run_start, arg); >+ in_run = false; >+ } >+ >+ i += nr; >+ } >+ >+ if (in_run && fn) >+ fn(run_start, n - run_start, arg); >+ >+ return nr_changed; >+} >+ >+struct xe_tt_iova_run_collect { >+ struct ttm_tt *new_tt; >+ struct xe_tt_iova_run *runs; >+ unsigned int nr_runs; >+ unsigned int runs_cap; >+ struct xe_tt_iova_link *links; >+ unsigned int nr_links; >+ unsigned int links_cap; >+ int err; >+}; >+ >+/* Geometrically grow @arr (element size @elem) to hold at least @need slots. */ >+__maybe_unused >+static int xe_tt_iova_grow(void **arr, unsigned int *cap, unsigned int need, >+ size_t elem) >+{ >+ unsigned int new_cap; >+ void *p; >+ >+ if (need <= *cap) >+ return 0; >+ >+ new_cap = *cap ? *cap * 2 : 64; >+ if (new_cap < need) >+ new_cap = need; >+ >+ p = krealloc_array(*arr, new_cap, elem, GFP_KERNEL); >+ if (!p) >+ return -ENOMEM; >+ >+ *arr = p; >+ *cap = new_cap; >+ return 0; >+} >+ >+__maybe_unused >+static void xe_tt_iova_store_run(pgoff_t start, pgoff_t count, void *arg) >+{ >+ struct xe_tt_iova_run_collect *c = arg; >+ pgoff_t i = start, end = start + count; >+ >+ if (c->err) >+ return; >+ >+ if (xe_tt_iova_grow((void **)&c->runs, &c->runs_cap, c->nr_runs + 1, >+ sizeof(*c->runs))) { >+ c->err = -ENOMEM; >+ return; >+ } >+ c->runs[c->nr_runs].start = start; >+ c->runs[c->nr_runs].count = count; >+ c->nr_runs++; >+ >+ while (i < end) { >+ struct page *page = c->new_tt->pages[i]; >+ unsigned int order = ttm_pool_page_order_nodma(page); >+ >+ if (xe_tt_iova_grow((void **)&c->links, &c->links_cap, >+ c->nr_links + 1, sizeof(*c->links))) { >+ c->err = -ENOMEM; >+ return; >+ } >+ c->links[c->nr_links].phys = page_to_phys(page); >+ c->links[c->nr_links].offset = (size_t)i << PAGE_SHIFT; >+ c->links[c->nr_links].len = PAGE_SIZE << order; >+ c->nr_links++; >+ >+ i += 1UL << order; >+ } >+} >+ >+/** >+ * xe_tt_iova_copy_init() - Compute the changed-page subset of a defrag move >+ * @new_tt: The freshly (re)allocated destination tt. >+ * @old_tt: The stashed source tt (bo->defrag_old_tt). >+ * @copy: Output description of the changed pages. >+ * >+ * Diff @new_tt against @old_tt and record the runs of changed (non-borrowed) >+ * pages into @copy, along with a per-folio snapshot of their physical >+ * addresses, natural offsets and lengths. The result drives both the packed >+ * copy-step IOVA mapping (xe_tt_map_iova_copy()) and the post-copy finalize >+ * that relinks the new backing into the IOVA reservation. The finalize runs >+ * asynchronously, after TTM may have mutated @new_tt->pages, so it consumes the >+ * snapshot rather than re-reading the page array. @new_tt and @old_tt must >+ * describe the same BO (equal num_pages) and both be populated. >+ * >+ * The caller owns @copy and must release it with xe_tt_iova_copy_fini(). >+ * >+ * Return: 0 on success, -ENOMEM on allocation failure. >+ */ >+__maybe_unused >+static int xe_tt_iova_copy_init(struct ttm_tt *new_tt, struct ttm_tt *old_tt, >+ struct xe_tt_iova_copy *copy) >+{ >+ struct xe_tt_iova_run_collect c = { .new_tt = new_tt }; >+ >+ memset(copy, 0, sizeof(*copy)); >+ >+ /* >+ * Single pass: collect the changed runs and per-folio link snapshots >+ * directly, growing the arrays on demand. Changed runs are few (the >+ * borrowed majority is skipped), so the geometric reallocs are rare and >+ * this avoids a second full O(num_pages) walk just to size the arrays. >+ */ >+ copy->nr_changed = xe_tt_iova_walk_changed(new_tt, old_tt, >+ xe_tt_iova_store_run, &c); >+ if (c.err) { >+ kfree(c.runs); >+ kfree(c.links); >+ return c.err; >+ } >+ if (!c.nr_runs) >+ return 0; >+ >+ copy->runs = c.runs; >+ copy->nr_runs = c.nr_runs; >+ copy->links = c.links; >+ copy->nr_links = c.nr_links; >+ >+ return 0; >+} >+ >+/** >+ * xe_tt_iova_copy_fini() - Release a struct xe_tt_iova_copy >+ * @copy: The copy description to release. >+ */ >+__maybe_unused >+static void xe_tt_iova_copy_fini(struct xe_tt_iova_copy *copy) >+{ >+ kfree(copy->runs); >+ kfree(copy->links); >+ copy->runs = NULL; >+ copy->links = NULL; >+ copy->nr_runs = 0; >+ copy->nr_links = 0; >+ copy->nr_changed = 0; >+} >+ >+/** >+ * xe_tt_map_iova_copy() - DMA map the changed-page subset for a defrag copy >+ * @xe: The xe device. >+ * @new_tt: The destination tt (must be IOVA eligible and not yet reserved). >+ * @copy: The changed-page description from xe_tt_iova_copy_init(). >+ * >+ * Reserve an IOVA range for @new_tt and link only its changed pages into it, >+ * packed contiguously at the front of the range ([0, @copy->nr_changed) >+ * pages). This provides a compact, contiguous destination for the GPU defrag >+ * copy without mapping the (majority) borrowed pages, and lets the whole >+ * temporary mapping later be torn down with a single dma_iova_destroy(). >+ * >+ * The reservation's remaining tail is left unlinked. This does not establish >+ * the tt's final mapping (@iova_linked stays false); the post-copy finalize is >+ * responsible for that. >+ * >+ * Return: 0 on success, negative error code on failure (any partial linkage is >+ * unwound). >+ */ >+__maybe_unused >+static int xe_tt_map_iova_copy(struct xe_device *xe, struct ttm_tt *new_tt, >+ const struct xe_tt_iova_copy *copy) >+{ >+ struct xe_ttm_tt *xe_tt = container_of(new_tt, struct xe_ttm_tt, ttm); >+ struct device *dev = xe->drm.dev; >+ size_t mapped = 0; >+ unsigned int r; >+ int ret; >+ >+ xe_assert(xe, xe_tt->iova_eligible); >+ xe_assert(xe, !xe_tt->use_iova); >+ xe_assert(xe, !xe_tt->iova_linked); >+ >+ if (!xe_tt_iova_reserve(xe, new_tt)) >+ return -ENOMEM; >+ >+ for (r = 0; r < copy->nr_runs; r++) { >+ pgoff_t i = copy->runs[r].start; >+ pgoff_t end = i + copy->runs[r].count; >+ >+ while (i < end) { >+ struct page *page = new_tt->pages[i]; >+ unsigned int order = ttm_pool_page_order_nodma(page); >+ size_t len = PAGE_SIZE << order; >+ >+ ret = dma_iova_link(dev, &xe_tt->iova, >+ page_to_phys(page), mapped, len, >+ DMA_BIDIRECTIONAL, >+ DMA_ATTR_SKIP_CPU_SYNC); >+ if (ret) >+ goto err_unlink; >+ >+ mapped += len; >+ i += 1UL << order; >+ } >+ } >+ >+ ret = dma_iova_sync(dev, &xe_tt->iova, 0, mapped); >+ if (ret) >+ goto err_unlink; >+ >+ return 0; >+ >+err_unlink: >+ if (mapped) >+ dma_iova_unlink(dev, &xe_tt->iova, 0, mapped, >+ DMA_BIDIRECTIONAL, DMA_ATTR_SKIP_CPU_SYNC); >+ dma_iova_free(dev, &xe_tt->iova); >+ xe_tt->use_iova = false; >+ return ret; >+} >+ >+/* >+ * xe_tt_iova_transfer - Transfer a full IOVA reservation old_tt -> new_tt. >+ * >+ * Move the (fully linked) IOVA reservation from the old tt to the new tt, >+ * leaving the old tt without a reservation so its destroy path does not double >+ * free. The new tt keeps its existing reservation snapshotted in the finalize >+ * job for teardown. Called at the defrag finalize job's point of no failure. >+ * >+ * Also rebalance the per-order DMA-page accounting: drop the old tt's >+ * accounting and account the pages the new tt actually ends up mapped with. >+ * The finalize relink leaves the new tt's mapping equal to new_tt->pages >+ * (borrowed pages alias the old tt; changed runs use the new pages, which may >+ * have a different order distribution), so deriving the accounting from a full >+ * folio walk of the new tt keeps xe->mem.dma_mapped_pages[] exact while the new >+ * mapping lives, rather than carrying the old tt's stale distribution. >+ */ >+__maybe_unused >+static void xe_tt_iova_transfer(struct xe_device *xe, >+ struct xe_ttm_tt *new_tt, >+ struct xe_ttm_tt *old_tt) >+{ >+ new_tt->iova = old_tt->iova; >+ new_tt->use_iova = true; >+ new_tt->iova_linked = true; >+ >+ xe_tt_unaccount_iova(xe, old_tt); >+ xe_tt_account_iova_pages(xe, new_tt); >+ >+ old_tt->iova_linked = false; >+ old_tt->use_iova = false; >+} >+ > /* > * Account ttm pages against the device shrinker's shrinkable and > * purgeable counts. >-- >2.34.1 >