From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=192.198.163.9 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1796244745; b=hAv8pFmtG4q3FtiC85zwVilBIeViTK9RrbiChHBnJqcRdeBAzsUHMIBpYBCGVw4foJlK 5GNGHC1OTpO8ONM9KWUMVMtZ/XOTI1TKJm/eaMC+3+wph1lp2oGN1uytyYh1XlCIG+D/e tHFqqSjq3twfwptKuNFhLbjfHz1NLNTNE7H/dH+JA1gLPJxNd0Uj/Hkrc001Of2xMeTdY DzoJFK9eidtWNV6pkoL2SOakPqxKtX0uOEywfNPrC2for9c5qgcYK0FasrSnaGIx4xgRy y1eomL+ivh+tgqZX/c2ewuXomlbMCWilNIFqCsFCPEb7TNXFC0xTtbvu4rnD/n6dzNQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796244745; 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=eM4+Qz5Fp7GO9WpstK1OFqPnIHWcxuaRhBCAX/s5C+8=; b=xsnLIoFh/GCLFivXoBLliR4jvu5MuxtRCt6HNEOr5zk7ViaeNKM1owwh4gIKb5Q65nGE yW1ox4WH7XeXYp9JuLgphZ+HExP7AuA/feLD+5zEp+7yXHH+XE6Fn7MjKbjjUwIkIw7sO rv1u4zgPUTNJzk9t4qtI0elBjcj2cripya8z/SYttBG2gPiWzMCqmBAUXOQ5slhHF+7YR QL6Tae9mstIod53jpOLYqSiaDS0MSG66DEPjSgSvD8aZDEsTwaqxH8Ky/g5mZhfesvnIo Mqo9gDihoHEmsqMR0ktidbV++4iZOLgFn5S44dRSVl27Ot62daW6UlbmX+8NPMVwCHw== 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=S0UVUhOk; arc=fail smtp.remote-ip=192.198.163.9 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 DB7CF606A322 for ; Wed, 2 Dec 2026 20:52:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DB7CF606A322 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=S0UVUhOk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796244745; x=1827780745; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=eM4+Qz5Fp7GO9WpstK1OFqPnIHWcxuaRhBCAX/s5C+8=; b=S0UVUhOkPg+mgSKM3lZOXP/bTdX7Eg7FAE4zPSgXR/bLOY4OFf58jsYp SobX5s+bT29gjBOR/qS2KGI1vPVPkMNcnxQ1R/eQdPe4neo8v3pOjzfEX zr8Ytg+Dc9eBKqA6WQ/E5gt6s3MP1X7CMHdA+7x4ddhjyCWsN/ykqL2JB C/LkGrjbUZazfFVE5D1LhDMD2avvSPTQPf7RLMqWQOhpAr6lvceSX8put OugyW03wBzIxJyXJ1qFy9Uf74AcLw7cae7WKhX9UhWHIylWYy+87I/gtY WUFj0hUFOvKtaermRJApM/85PFywRxqDfHADBG1Nz/bUytM1StfCyym2d w==; X-CSE-ConnectionGUID: cf9nISXdRdyEBp4BnBnNhQ== X-CSE-MsgGUID: hROjRR72Rd2EOMOweYTrRw== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5042360" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5042360" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 12:52:24 -0800 X-CSE-ConnectionGUID: ykd6SsjqTXKp9zvmGIsO2A== X-CSE-MsgGUID: YLr2tbeuQBmMby4Iw4GHXA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13860772" Received: from fmsmsx902.amr.corp.intel.com ([10.18.126.91]) by fmviesa007.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 12:52:24 -0800 Received: from FMSMSX902.amr.corp.intel.com (10.18.126.91) 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; Wed, 2 Dec 2026 12:52:23 -0800 Received: from fmsedg901.ED.cps.intel.com (10.1.192.143) 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; Wed, 2 Dec 2026 12:52:23 -0800 Received: from PH8PR06CU001.outbound.protection.outlook.com (40.107.209.48) by edgegateway.intel.com (192.55.55.81) 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:52:23 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WVG6uDWOTgdugf6Tsss4VEMrgzE5kqAJOrt1BHZbtRYqHDcRu4sw36s35oh1UOFaFNYfukiOo68CsxyFMtUqdMLGqiA/Z1rYw2cJ1r4dvsGSLeMXtBhwrzm5LSZy54FRaXsCc2ji8wSGFL8ZsW+3Fh4bkL3Y+Pl1GXSW7DRgb39FWM1mbPIqgICUTjVGdAs+/X+uroYZMU8K2AHp4IX/sEW1VjpaXkZtdfFLSDNyWfP15NEyMiUS8YBqFZlay3kj/DG7Hr44Oz6CyNKWgDQ4nnqTDrfxVA8Ab1iJHapJW2aRmYw1moTh77nWvJb7KIlhuNeH+SdLxkti9prLmxXMHA== 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=t4F+dPs8X5T9zwTKnEp10pglLGEHq47cI43ZmrpMHYI=; b=G3XOS+8XplMUApDjMYlyMxIMPBcT6lsGGMPAp3dfD3xG+S1YiFW4WkLzw9zcYlr/0cIRXGHrpbs4pkPP4Ev3f0QXWP0zN5lOJfG5B066RlafguPrdDEE2bNMq5e9IRPrDMKqM8klLICM+1POlyuftL73MhtiYUAq0X58HSvfxBSyj6gk0CUXW0JMX/lWoyrRseBBQviYU5jaGU3iPI19XK8+PVAQCAgIpMJ53zrNRkaMMnribrrAsvo13k0rqRCVMd7vR3gjaVZeFSjkrFAxxdpgK+0CS8ICteCbA+yyWhszbUrPEG2YQQDF6bUPuRoVq4Ii7DmCgxQCZCHvTLGlIQ== 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 CO1PR11MB4787.namprd11.prod.outlook.com (2603:10b6:303:95::23) by PH7PR11MB7720.namprd11.prod.outlook.com (2603:10b6:510:2b3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.11; Wed, 2 Dec 2026 20:52:14 +0000 Received: from CO1PR11MB4787.namprd11.prod.outlook.com ([fe80::e7eb:a872:53d1:21fd]) by CO1PR11MB4787.namprd11.prod.outlook.com ([fe80::e7eb:a872:53d1:21fd%4]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 20:52:14 +0000 Date: Wed, 2 Dec 2026 12:52:12 -0800 From: Matthew Brost To: Niranjana Vishwanathapura 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 15/33] drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies Message-ID: References: <20261201234915.3305331-1-matthew.brost@intel.com> <20261201234915.3305331-16-matthew.brost@intel.com> Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: MW4PR04CA0253.namprd04.prod.outlook.com (2603:10b6:303:88::18) To CO1PR11MB4787.namprd11.prod.outlook.com (2603:10b6:303:95::23) 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: CO1PR11MB4787:EE_|PH7PR11MB7720:EE_ X-MS-Office365-Filtering-Correlation-Id: c17e0d60-6183-472d-3c07-08df50b62493 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|23010399003|366016|7416014|376014|18002099003|22082099003|10067099003|56012099006|261028144727099003|261021121427099003|261022105027099003|261026121527099003|261026140227099003|261021123027099003|261102123227099003|261009223027099003|4143699003|11063799006|6133799003|3023799007; X-Microsoft-Antispam-Message-Info: UXuOv1rCcRlzkbJ1q4mGmQxOXqfK3cQxEiNRnN58oK5TrI3lNwMjQKFDBRfypuMmyS3fXSg1+U0AUEw5jlkYYT3V5wiDbEQcOYP/Odsdqb0EYxvDMaWvGMG4f4imoCL4Bn7ecFJSBwDkOMnZ2vZwjlaKKjLLBL4+u3rO9amnmTSNjzrF1mLqY4NjOAaTfI9fA43OWjfZWQewslII1uOv18eFqtICIaZ1YBV0DAZ0zBCLM9dfCPAQXedB56VE/arcktCr1ksLpDylRzNzCgDn3QxqM00CKeitH3M62jeNcbuIhAXO/fie0/o+legQzKJcJMXflSeOsepmoW3RDuagajnZAXEa/nAB1rAzx4JlRA9CjPucDQsnCRbPSCKVEg222+fK7YKNjhgVpfgsX+a3421szQn5Jii47bx8r5h6z/YD2wPIGhQ//9sU7V/JMRSFvlI4vZpYMeR9/YWiQByasmknOmW/88Nwf663IaqdKku2dzEgY2vd0Iv7I4/TOBwNZH8rNvKGkACm0J+wn30nAKWjuNmodz13rwNDYPx8SUF2kBmzgjSI7O0K2pvky7fg2ZmK+578dmTq1KYPMRDOiZhdYMyhM6HczPeHTVbNa3faQZkYX+dXTf4Rffh0xxBMsargYCTFD1533ePgA02Z9C92LogL8q6KDTidtA0LQh0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR11MB4787.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(23010399003)(366016)(7416014)(376014)(18002099003)(22082099003)(10067099003)(56012099006)(261028144727099003)(261021121427099003)(261022105027099003)(261026121527099003)(261026140227099003)(261021123027099003)(261102123227099003)(261009223027099003)(4143699003)(11063799006)(6133799003)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?pW3VUunQRQWk9fP/MGGhhFCPAWvEO2zBQgUUUO6WNSOfyjFk3I20O52pV1?= =?iso-8859-1?Q?FjT81ZQa7x4FTSsmHajMUfioz/tC/GHnWa5S/8505v6gGcMrYilK70a1hH?= =?iso-8859-1?Q?Hl2svK5h5gctuIfidsIjcTgjYtLGg9ywLi8gNVW9BFEb3OaYTp31O5geff?= =?iso-8859-1?Q?nL6tNFK6I2U+d6blVZzpIpypYIfuwkA1K1Q0nDiJUWDyao5Rcu0trFImW9?= =?iso-8859-1?Q?m8w3t4veXlB4TOp1bXi0AKoGloam9c6jYJrQYvEsEa2Nmx+BcgQ9/UECmu?= =?iso-8859-1?Q?5PTo/JosabVyndXkCgwAO60niouLFXqM6owEiaYufUhpyCyiVKZ8vw3JfD?= =?iso-8859-1?Q?4N16vaiz6+ihUJnPI6X+oHGAQvlMIkTcpkC+D30IZjoxfjZsRBiKAvYQQg?= =?iso-8859-1?Q?F/9IkjzQr+9UfyAlpq3NEwT1k2RSqKTQb+VSlbwODNLXV7iRWMUcT+TUEK?= =?iso-8859-1?Q?+t5PwBR47W2rpdldfajR5uJV2+zN+UWG1xVTctCMk2io/M0XpIG5JrRKFi?= =?iso-8859-1?Q?A+fH5wU9tNuroxva9LhZ1I0InV0VEBBxzM/WQWF+bHTqDf87Q5fJGY4uSm?= =?iso-8859-1?Q?jf1FfFJjXudwqJm+vsmn0geoaRN+tht3VEZ+T4SfgavPjXTuOjYjT0EemH?= =?iso-8859-1?Q?/hxeFTcvPDK4JEd1nDlE9I6Q8g5SGsqs+19HC7iKH8t2kWhP7rkg1wzOlk?= =?iso-8859-1?Q?hADDpxC+Mk8VbMp/2d9RT+XwJZ7Pmqxt2XCSs0NaCgBah2rTx39B3sfY6g?= =?iso-8859-1?Q?twIVZe+SEpIoZYvN7Lc4ZpWi/GbyHI3RmqS9sarSC69DfSGEx3JrV+YKgY?= =?iso-8859-1?Q?NgdIal/LcZOWTVgGNkGznAb+amoolsw+UEURurodXovlhO+tcZ41EMfvWQ?= =?iso-8859-1?Q?ckDIsv5APKB4RogVX6ROEFBHhSj/Xm2SVB59o0cfGe50g36OuITKcElnJr?= =?iso-8859-1?Q?Qc5AgxWaqh6MG5LH4ksr8Iq4+d2E48laF6EHAp47+w1hrIOslLkeElnpNK?= =?iso-8859-1?Q?ZUF+IbNYXQc8R8DuP37wUn/uMOjNGCH6j7jZv2Ggf4xkSq/I7Qk4r/cyyp?= =?iso-8859-1?Q?LMUWo7KzjExSI0ZndM7YN8GAGh3o1h9fq/dEpjpaZRqIlm+aVDezw9wXHK?= =?iso-8859-1?Q?ZmJcAZ/r1/p3zLbAi6/QtgZ9IXJNXn8kiuWofrM+boP3JbRf+bRp4I8nsO?= =?iso-8859-1?Q?rqWeOWdOQoA/HzRebumVsRGQwKDLxlyfMN3WIg4ybG7kYwjUIJ92FWBtjl?= =?iso-8859-1?Q?+cok9e/oqU8dHBHbPDLC5I/yJZ1xtOmL5qbODNN4RQyO9o17YtjUvPqcF1?= =?iso-8859-1?Q?scWDNqCjgzCNjUZXXhfqozQQ5IaU43t2lqszbgUB4ab7Bzkywms2FE+avh?= =?iso-8859-1?Q?ngC/7A6PJXS/P63utX1gNEp42kVXf8XCCtYyBIjt56MTXJ6jEgjL8RU0md?= =?iso-8859-1?Q?fqqf/Vs6AKNU9eJwBdQyhS2tvSPrEwLWsz4ARtA9p126xseruFgR4ymucv?= =?iso-8859-1?Q?G+1zkfuuYarCsgeaearObG0a8rM8U02TGYOsYKp4Z+NR19cAvwJqgcovTM?= =?iso-8859-1?Q?6TCjtQKEQPKYfmY70rTzUIl4G7KX161bRIOc2wOTb/lS9YczXIl52kAjqT?= =?iso-8859-1?Q?3n9keN8rVbqUxzxAAlUKVvUoQ+oQPfSdCH5qb6xbiAAbZgjdIz3ahpVIQg?= =?iso-8859-1?Q?X5TdZVzPGJCG60KO/UnKYDtqdwqRmz87JLs545GYLF0iagil5QkuHfdsHA?= =?iso-8859-1?Q?wO7wGbA9vvz2qci+AlMu2vaEBMRMoPN8r6dKMadI7GnRzEeKvu0JfglsCj?= =?iso-8859-1?Q?oNQUU96n/Q=3D=3D?= X-Exchange-RoutingPolicyChecked: UmSsPPxV7NanBb84XkSvSxofYuj2YnIp+lyobEVaqfjn9o+jy5a3LXGU6uf49wVWf5rEWlayBtx45QtYTjPCKM6ssu6MEklAnw/7H1Vecv+TVC4/NtPex2EcDM3vIFbwAj/S9GfgyvWzy7JL6XcFj+9wXzeHjtFmFmcrJCcw0tq07RK+U1eSAyQDXhuyQVPiX5riVTRVnvThRfSnhdnFtpv3EwYjmxbgL29Ll9NI7gq6DPx43fdBAfiISuWBOTRALaBiNtp7H1ULvJ7ZMSXovjHGdcS5oGcMt05qxNdq3m4mrdsO/TpyesPCcCgytzoJFLLQMJEAVPsAzjrKWf++LQ== X-MS-Exchange-CrossTenant-Network-Message-Id: c17e0d60-6183-472d-3c07-08df50b62493 X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4787.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 20:52:13.9377 (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: jXbgrIvcuVjPIk1bJfegJRs8rkzrY1Ma/L11D4a2gPNLWSR98R0FAlTvmNebgxbjeRPmesCb09Q2EqnBT5EPjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB7720 X-OriginatorOrg: intel.com On Tue, Dec 01, 2026 at 10:42:57PM -0800, Niranjana Vishwanathapura wrote: > On Tue, Dec 01, 2026 at 03:48:57PM -0800, Matthew Brost wrote: > > Add xe_migrate_copy_defrag(), a copy helper for the upcoming page > > defragmentation path where a single BO has its backing reallocated at a > > more beneficial page order and its contents must be relocated from the > > old pages to the new ones entirely on the GPU. > > > > The contents are relocated 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. > > > > - 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 accesses the aux state indirectly, issuing one > > indirect -> indirect XY_CTRL_SURF_COPY_BLT; the data blit is skipped. > > > > The two passes are issued separately because they require opposite > > compression PAT settings on the data page mappings (cleared for the > > verbatim data copy, set for the indirect CCS access), which a single > > mapping cannot satisfy. Both passes run in order on the same migrate > > queue and are captured by the returned fence. > > > > The source pages are passed explicitly via an sg_table argument (the > > old, still populated backing) since they no longer match the BO's > > current backing. The boolean arguments to __xe_migrate_copy() are replaced > > by a single enum xe_migrate_copy_mode, since the copy variants are > > mutually exclusive. > > > > v4: > > - s/struct xe_migrate_copy_flags/enum xe_migrate_copy_mode (Niranjana) > > > > 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_migrate.c | 133 ++++++++++++++++++++++++++++---- > > drivers/gpu/drm/xe/xe_migrate.h | 8 ++ > > 2 files changed, 127 insertions(+), 14 deletions(-) > > > > diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c > > index 23575f9dc651..0f469942ae6e 100644 > > --- a/drivers/gpu/drm/xe/xe_migrate.c > > +++ b/drivers/gpu/drm/xe/xe_migrate.c > > @@ -1292,16 +1292,50 @@ static bool is_devmem(struct xe_bo *bo, struct ttm_resource *res) > > > > return true; > > } > > +/** > > + * enum xe_migrate_copy_mode - Mode for __xe_migrate_copy() > > + * @XE_MIGRATE_COPY_NORMAL: Regular copy of data (and CCS aux state if needed). > > + * @XE_MIGRATE_COPY_CCS_ONLY: Only copy the CCS aux state, aliasing the > > + * destination data mapping to the source (used when the data pages are shared > > + * between src/dst). > > + * @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. > > + * @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 > > + * 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 > > + * indirect -> indirect. The two defrag passes need opposite compression PAT > > + * settings, which is why they cannot be combined. > > + */ > > +enum xe_migrate_copy_mode { > > + XE_MIGRATE_COPY_NORMAL, > > + XE_MIGRATE_COPY_CCS_ONLY, > > + XE_MIGRATE_COPY_VRAM_RESOLVE, > > + XE_MIGRATE_COPY_DEFRAG_DATA, > > + XE_MIGRATE_COPY_DEFRAG_CCS, > > +}; > > > > static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > > struct xe_bo *src_bo, > > struct xe_bo *dst_bo, > > struct ttm_resource *src, > > struct ttm_resource *dst, > > - bool copy_only_ccs, > > - bool is_vram_resolve, > > + struct sg_table *src_sg, > > + enum xe_migrate_copy_mode mode, > > bool intr) > > { > > + bool copy_only_ccs = mode == XE_MIGRATE_COPY_CCS_ONLY; > > + bool is_vram_resolve = mode == XE_MIGRATE_COPY_VRAM_RESOLVE; > > + bool defrag_copy = mode == XE_MIGRATE_COPY_DEFRAG_DATA; > > + bool defrag_ccs = mode == XE_MIGRATE_COPY_DEFRAG_CCS; > > struct xe_gt *gt = m->tile->primary_gt; > > struct xe_device *xe = gt_to_xe(gt); > > struct dma_fence *fence = NULL; > > @@ -1317,10 +1351,13 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > > bool src_is_vram = is_devmem(src_bo, src); > > bool dst_is_vram = is_devmem(dst_bo, dst); > > bool type_device = src_bo->ttm.type == ttm_bo_type_device; > > - bool needs_ccs_emit = type_device && xe_migrate_needs_ccs_emit(xe); > > + bool needs_ccs_emit = type_device && xe_migrate_needs_ccs_emit(xe) && > > + !defrag_copy; > > bool copy_ccs = xe_device_has_flat_ccs(xe) && > > - xe_bo_needs_ccs_pages(src_bo) && xe_bo_needs_ccs_pages(dst_bo); > > - bool copy_system_ccs = copy_ccs && (!src_is_vram || !dst_is_vram); > > + xe_bo_needs_ccs_pages(src_bo) && xe_bo_needs_ccs_pages(dst_bo) && > > + !defrag_copy; > > + bool copy_system_ccs = copy_ccs && (!src_is_vram || !dst_is_vram) && > > + !defrag_ccs && !defrag_copy; > > > > /* > > * For decompression operation, always use the compression PAT index. > > @@ -1331,6 +1368,12 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > > xe_device_has_flat_ccs(xe) && > > GRAPHICS_VER(xe) >= 20 && src_is_vram && !dst_is_vram); > > > > + /* > > + * The defrag CCS pass migrates the aux state from the old pages > > + * (@src_sg) to the new pages with both sides accessed indirectly, so > > + * keep both src_is_pltt and dst_is_pltt set (no direct staging side). > > + */ > > + > > /* Copying CCS between two different BOs is not supported yet. */ > > if (XE_WARN_ON(copy_ccs && src_bo != dst_bo)) > > return ERR_PTR(-EINVAL); > > @@ -1339,7 +1382,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(xe_bo_sg(src_bo), 0, size, &src_it); > > + xe_res_first_sg(src_sg ? src_sg : 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) > > @@ -1348,7 +1391,8 @@ 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(xe_bo_sg(src_bo), xe_bo_ccs_pages_start(src_bo), > > + xe_res_first_sg(src_sg ? src_sg : xe_bo_sg(src_bo), > > + xe_bo_ccs_pages_start(src_bo), > > PAGE_ALIGN(xe_device_ccs_bytes(xe, size)), > > &ccs_it); > > > > @@ -1399,7 +1443,8 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > > } > > > > /* Add copy commands size here */ > > - batch_size += ((copy_only_ccs) ? 0 : emit_copy_cmd_len(xe)) + > > + batch_size += ((copy_only_ccs || defrag_ccs) ? 0 : > > + emit_copy_cmd_len(xe)) + > > ((needs_ccs_emit ? EMIT_COPY_CCS_DW : 0)); > > > > bb = __xe_bb_new(gt, batch_size, usm, !fence && intr); > > @@ -1411,13 +1456,15 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > > if (src_is_vram && xe_migrate_allow_identity(src_L0, &src_it)) > > xe_res_next(&src_it, src_L0); > > else > > - emit_pte(m, bb, src_L0_pt, src_is_vram, copy_system_ccs || use_comp_pat, > > + emit_pte(m, bb, src_L0_pt, src_is_vram, > > + copy_system_ccs || use_comp_pat || defrag_ccs, > > &src_it, src_L0, src); > > > > if (dst_is_vram && xe_migrate_allow_identity(src_L0, &dst_it)) > > xe_res_next(&dst_it, src_L0); > > else if (!copy_only_ccs) > > - emit_pte(m, bb, dst_L0_pt, dst_is_vram, copy_system_ccs, > > + emit_pte(m, bb, dst_L0_pt, dst_is_vram, > > + copy_system_ccs || defrag_ccs, > > &dst_it, src_L0, dst); > > > > if (copy_system_ccs) > > @@ -1426,7 +1473,7 @@ 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) > > + 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) > > @@ -1513,7 +1560,64 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m, > > bool copy_only_ccs, > > bool intr) > > { > > - return __xe_migrate_copy(m, src_bo, dst_bo, src, dst, copy_only_ccs, false, intr); > > + return __xe_migrate_copy(m, src_bo, dst_bo, src, dst, NULL, > > + copy_only_ccs ? XE_MIGRATE_COPY_CCS_ONLY : > > + XE_MIGRATE_COPY_NORMAL, intr); > > +} > > + > > +/** > > + * xe_migrate_copy_defrag() - Migrate a BO's backing to a reallocated page set. > > + * @m: The migration context. > > + * @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. > > + * @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, > > + * 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. > > + * > > + * - 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 > > + * accesses the aux state indirectly, issuing one indirect -> indirect > > + * XY_CTRL_SURF_COPY_BLT; the data blit is skipped. > > + * > > + * The two passes are issued separately because they require opposite > > + * compression PAT settings on the data page mappings (cleared for the verbatim > > + * data copy, set for the indirect CCS access), which a single mapping cannot > > + * satisfy. Both passes run in order on the same migrate queue. > > + * > > + * Return: Pointer to a dma_fence representing the last copy batch, or an error > > + * pointer on failure. > > + */ > > +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, > > + bool need_ccs) > > +{ > > + struct dma_fence *fence2, *fence = > > + __xe_migrate_copy(m, bo, bo, src, dst, src_sg, > > + XE_MIGRATE_COPY_DEFRAG_DATA, false); > > NIT...Passing false to 'intr' here and below is fine, given defrag worker > context can't be interrupted. May be add a line of documentation just in > case tomorrow if someone tries to defragment from a interruptible context? I don't think we'd ever defrag from an interruptable context as entire point is not to run reclaim at higher orders in a user context (i.e., the one which are interruptable). Let me add comment around this. Matt > > In anycase, > Reviewed-by: Niranjana Vishwanathapura > > > + > > + if (IS_ERR(fence) || !need_ccs) > > + return fence; > > + > > + fence2 = __xe_migrate_copy(m, bo, bo, src, dst, src_sg, > > + XE_MIGRATE_COPY_DEFRAG_CCS, false); > > + if (IS_ERR(fence2)) > > + dma_fence_wait(fence, false); > > + dma_fence_put(fence); > > + > > + return fence2; > > } > > > > /** > > @@ -1522,7 +1626,7 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m, > > * @bo: The buffer object to resolve > > * @res: The reservation object > > * > > - * Wrapper around __xe_migrate_copy() with is_vram_resolve set to true > > + * Wrapper around __xe_migrate_copy() with XE_MIGRATE_COPY_VRAM_RESOLVE > > * to trigger decompression if needed. > > * > > * Return: A dma_fence that signals on completion, or an ERR_PTR on failure. > > @@ -1531,7 +1635,8 @@ struct dma_fence *xe_migrate_resolve(struct xe_migrate *m, > > struct xe_bo *bo, > > struct ttm_resource *res) > > { > > - return __xe_migrate_copy(m, bo, bo, res, res, false, true, true); > > + return __xe_migrate_copy(m, bo, bo, res, res, NULL, > > + XE_MIGRATE_COPY_VRAM_RESOLVE, true); > > } > > > > /** > > diff --git a/drivers/gpu/drm/xe/xe_migrate.h b/drivers/gpu/drm/xe/xe_migrate.h > > index 0bf94f5b388d..70451392e0a7 100644 > > --- a/drivers/gpu/drm/xe/xe_migrate.h > > +++ b/drivers/gpu/drm/xe/xe_migrate.h > > @@ -11,6 +11,7 @@ > > struct dma_fence; > > struct drm_pagemap_addr; > > struct iosys_map; > > +struct sg_table; > > struct ttm_resource; > > > > struct xe_bo; > > @@ -59,6 +60,13 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m, > > bool copy_only_ccs, > > bool intr); > > > > +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, > > + bool need_ccs); > > + > > struct dma_fence *xe_migrate_resolve(struct xe_migrate *m, > > struct xe_bo *bo, > > struct ttm_resource *res); > > -- > > 2.34.1 > >