From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=198.175.65.11 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1796443790; b=dsUqwl8aMiUjmpNI7BaLcjnEZ1MlIAvwd8cnSbP5YDfZ1rD/vkxuhOjfKehY+ms5VOGT YahV2tpYs/e+umQ3/974C6c7+fRFHh2FmjgsD4qo0lF7wQJt8os0C4FDn4wNFufdHgGTP qgZwqPifKDJLg0qT9FUbMrbrkABqc6DFqKEz7xLjasOPDjbrgHZPLDemiZPouZg6r+nW1 sMed8+eMTCqOU3KhZ+9oP2WqbEOInsSb/8ZwOG8k4EwIUaw2BeWev/ebMJ1Lrcb6NYtL3 rVcAvswrPTFPBxEAx2S7vfEbZG6meItMNIzBgrF9P01qk2is7lCYrbCAGUpwJQdGV8A== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796443790; 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=uU+D682DQdx5jx77LSSfqZXUPoOghvPxcwPUchMM/qU=; b=kqyV0U7y8TR4zBTtxNudXQ3dWQe+cYxxtRsseVbObKfBxTrCPUaE0Eex4BV2q5ny13/z EJ8ZelHR8EpTGx2E+MoPGo74buHcl9cdgMqhrHwu/pWFFQkSUSrXFVAG1Wic3bqUZmdyX 0FeqrxEkfqyd6wOjdfhGHyLI2RPJfCIstQqHtamz+57haNhYZknjujvpbvPp7Fzd5ZUe7 Vpx12mUFjiuwBk2/c9elYAKiz2NQZm04hyPOJE/3C+6ctMyW3I1iENzXC+AN0Ztry22Y5 wSvEZtXJuPQO+IvF0KmenalHdmfifoNN32jX8PCRnKwQfBXnX9k1Hs0owp5qkmtWcZw== 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=Z2Bv9KMa; arc=fail smtp.remote-ip=198.175.65.11 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 6C5FA606A322 for ; Sat, 5 Dec 2026 04:09:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6C5FA606A322 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=Z2Bv9KMa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796443788; x=1827979788; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=uU+D682DQdx5jx77LSSfqZXUPoOghvPxcwPUchMM/qU=; b=Z2Bv9KMafxI/V96gZO7GEoqpW1ER3M8RLdxiTiNPk5Qa3/7yknsEtz5r JA0BjZE1rZOF6Z74khLhZBcAQTXxRnqqnbl6DMPUdK5mN6pb4KSU2CLuu s/0pFypTh1Gmi5iDUZq/dSKtu6Bnpk3MF2D4x4UunsjPMVfPb+K248TUA qzTLXTvIi99XojGlq/1H5ONBXJ8AKBjSqrbjfVrjbUYL7xNa+W01nhAp9 Wb6R293zXBfc2WHstRl2kP5XmSqmlFqG10HTejtPlwX1SIIy/6LOt6JEB jV46mQKlmovjrkHzDhVSMOXGiiUQhQNVQEayzg639FaK6gfSWe5Xx0KuN g==; X-CSE-ConnectionGUID: 84QVm7+VROGAMy7DEO8yMw== X-CSE-MsgGUID: YJBmUPiLT3yGlRerKrsQ7w== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5332285" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5332285" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 20:09:47 -0800 X-CSE-ConnectionGUID: CCLMZcjCS4K81qBN/s1mvg== X-CSE-MsgGUID: Ki9dGxGET+Cb9QpSNQHFeA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="14390638" Received: from orsmsx902.amr.corp.intel.com ([10.22.229.24]) by fmviesa009.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 20:09:41 -0800 Received: from ORSMSX901.amr.corp.intel.com (10.22.229.23) by ORSMSX902.amr.corp.intel.com (10.22.229.24) 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 20:09:40 -0800 Received: from ORSEDG903.ED.cps.intel.com (10.7.248.13) by ORSMSX901.amr.corp.intel.com (10.22.229.23) 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 20:09:40 -0800 Received: from PH8PR06CU001.outbound.protection.outlook.com (40.107.209.26) by edgegateway.intel.com (134.134.137.113) 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 20:09:39 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Enx/4s4iCmLUUvqvk6mv2fj1aIblSczN8PXBMzYbnMAPAvbPhgjXvGZDEtjYReeVfEjtg/1ORECt7y2XaLamZP69bKgxNJHGpLskzSnev/1PGmQCQgrSApU51N4w5XHTNe56BXPuaxWlBegeKNanmfzPxwCrc7vb+Ts6VqiAKXgOot2TNjGMMpEgpE277CmG4coyoJ29rKgfI8Q1/0moHxBkxVMsMAY9sVq292buWGUYKfdirIbOaE70+Qe0bDwwpVQ6DjqnE8fT0YwhQfBlHWIuIEAmPinLDIIdoOj0sP5t25kcUvpuG078MbqJ+R+Q9jt4/z5Avuy7EJSeHSfJFg== 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=bO4P2+dnawH/9UohGKpQm2TpRYucgK2AKIa1VsHzrCo=; b=AW/+leuOPtHjOz2mNXDx3Ke0F4aPh5zMRxglR4qJQjArd22WCiNvXk1afCSOohzvtmJI3DpaugQBai62y8noNms7g9xKhvkFZocuXaU+xjmEcA4LbcVe+uIOKvvA1t79dxoRpuVJPS4WeC3mAm7L6xWHDgXYKps49Vyi3hTSEu28ZN7ikM93bieF13Yp6DcKPVIFoJFmJonVkmlqCOIuJhVQsMI0LPZdUM6VsvFUiZ3wZzeaZWcazuXNidAbD57iTSu657K6ZJd4YPj/wqbin8pKTvJ4D1FdgZ323oqWX8otgolmIamlYVoNexuqGigJbE4uggd/UAzTkG6LLP6cNA== 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 IA4PR11MB8990.namprd11.prod.outlook.com (2603:10b6:208:56b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Sat, 5 Dec 2026 04:09:28 +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; Sat, 5 Dec 2026 04:09:28 +0000 Date: Fri, 4 Dec 2026 20:09:25 -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 32/35] drm/xe: Finalize defrag-IOVA moves with post-copy job Message-ID: References: <20261203202352.4153159-1-matthew.brost@intel.com> <20261203202352.4153159-33-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-33-matthew.brost@intel.com> X-ClientProxiedBy: BY3PR10CA0017.namprd10.prod.outlook.com (2603:10b6:a03:255::22) 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_|IA4PR11MB8990:EE_ X-MS-Office365-Filtering-Correlation-Id: e6642d40-a53b-40af-5c45-08df52858e16 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|56012099006|261022105027099003|261021121427099003|261102123227099003|10067099003|261021123027099003|261028144727099003|261026140227099003|261026121527099003|261022075727099003|261009223027099003|11063799006|4143699003|5023799004|6133799003; X-Microsoft-Antispam-Message-Info: DcW4mZHXWXDGSmXuPsvAoRrj/qEYPrcjh2WGGgncyudiIoieSknWPPnQHjk8yW+7ClzXtaCw0HBki3w6THo0vMq48UJjJW0Gy429kTbhTMip8x4shB96G3rtu5FxaUsHM1DmHUV6L8D/xeFqbV8ihnUYOZAyfHr7i/E0fPLZav/Sq8F9UQzzdsu6LimwVyGcrvEB39TK23w1Eb4XL7xmGuOWkazr/0Ya71mEMRrGpsCl+laq2T7cJkWxowUQxkGkpIVFepuyVFily8ZUMNRQclu52fzhFgaCFKy1qdiosiMc0u0U9/qKPwDHD8Y4PCrsjkW3SEUA4ZUNnlmtUZQhvCCcTOkYQ+yOb/4z1ZS6AHdanN6Lg64pAeePJxYAm+cNbP1+1vyqLvpWxkYLsaqKQvn4fswycGiy4+hwLYnhghIFUS/d5ZjD2NsqpGOSlkYN4GjnK9Z2MeO0qs4n0JR+6oRMGueRthbm5rbJwFcR245Y1fZACUtxeEXxc6L577D27i9277Cg25yi5HB/SizHs0z6IQagg4wbYY0WPn2O3csZ/6WC7O/9kLMacRgMAQ2Z+TfxD6CC9tEgP8kI4vpJTn7uz3jzqnkKmXZCDjW67cVV8nBpIUB5zH1zg1PiHHQV+gKrxLzWbcksYe4M1sT1tHJDOTp4EcXv0NmXwZg1ync= 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)(23010399003)(366016)(7416014)(376014)(18002099003)(22082099003)(56012099006)(261022105027099003)(261021121427099003)(261102123227099003)(10067099003)(261021123027099003)(261028144727099003)(261026140227099003)(261026121527099003)(261022075727099003)(261009223027099003)(11063799006)(4143699003)(5023799004)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?JTL23viB59hETzqFns8loZ4kRlfyG+vCPB7DSxdQuejZhIRyJDG00Let76?= =?iso-8859-1?Q?tr52B4cc4sSue1mcbPhqMrc0FymEB5bOkk2V6alV/sfEEmD3riSzi3MOwO?= =?iso-8859-1?Q?wf8+Fn38kaLAAmmWe86/IY6Sjr2U4ox5ATlvQvVirnQEQzssI5AVW0gRtQ?= =?iso-8859-1?Q?ajSsIoGG7gnlmtuzcf1EEX+US2OiRvjLMOTGyhJ6CEMfBlJeHz2QMAl1Sf?= =?iso-8859-1?Q?NKLzBWe/vI0HXhaV8ZUSk01sq4tcAyTowWiXh3pqGa0TMdboFTfBj7fVPW?= =?iso-8859-1?Q?kHTz+e+uz1cmgwXYwCXWH69byXbBXow92uvIxT3qen1jS+WqCgibXmR1LI?= =?iso-8859-1?Q?eef+aOOqDaxnl8pUAMe4y3MjN3NWmOjDE/XjiQwtOv0fbvc3YmS40+8SoJ?= =?iso-8859-1?Q?YyANky9e8CrQA1j7bkx7qVx/la/BKDqTyugmFIfyPe4uHbIdblUXlKDoYS?= =?iso-8859-1?Q?CEZiUPwX8mgV6uZ8N5pgvAUQ2VhHH++icRqgnkbVgR9cnmRgw5paiDOUS0?= =?iso-8859-1?Q?zSycJM5lKmr40qECO+u9TrmazwBHtS+NHoKki3JRBYw8ZXR7ZHgfc7WpuM?= =?iso-8859-1?Q?sLe0mLqIxZbtMWxvvJxkrA1X5c5bJhhMtW9f3rTNPy62DzD8XnVPV4y02k?= =?iso-8859-1?Q?bQHeaIoE/2IsS+kytUd/fSPE2r/RbNKimRozUtrzKShFbX5iMAoJEkzNms?= =?iso-8859-1?Q?nsAYnHgR/ZKQft546T+qP9uDzErYxKxKfVUekjq29ELR4izdk7Dkedy3rh?= =?iso-8859-1?Q?V1nNcBwvdrbvprkNBDnjUhfu20jsiTAdbIPSTR0PlM2IHSLfRGEIUvXpWr?= =?iso-8859-1?Q?jOZDkjc86ssw1ciWYanYtmD7LUUORFiKOvKznRUbgt7zdryBgHEowPpgUs?= =?iso-8859-1?Q?IXIRFGTtg6kSHUvN37aj77nDnYcaxRMXrh3g7K1vigYldbYfIgRUC0ZGJN?= =?iso-8859-1?Q?d5qJ/G9RoOVmrhxhnfafGWd67bOuQbx4uXdtc1bxVHTiX1mVGrkFs0GP5b?= =?iso-8859-1?Q?SgYl668Et96OkkLfRGB/Owt+tcD7cgD7JPI8Q7Uq9WmXdrmfNZS2jTk1Uo?= =?iso-8859-1?Q?vUGBi0uKTK3Z4aVKR5RYvt6saYhdFgriwfry6pPJTDvIXu8+t62WqFTh42?= =?iso-8859-1?Q?vHnLYLJOfQNVfI/xA6ChjC2n2TyiiFbMxlnzaByoL6Zd6TJEpMJ1n6V0PI?= =?iso-8859-1?Q?i4CyNv6AvmKyTw1v48oB6hvpk32R3XpEoqBE/Mcv+uvTvsKzCAD3YWjzAx?= =?iso-8859-1?Q?SHnInMkh9DlEF47JeUvYuAl7SzQ5jNe64mmmpJ/zICkfQxOPLw4Z4KyVkJ?= =?iso-8859-1?Q?YXDffhVlBa19lyC17IKzwaoKXHPbDSaAXl9sGec4gFHuTSB2DNpVxnEKJ+?= =?iso-8859-1?Q?DIXlueABwo762GHoz9nIkvXjOgBNr21NKC47oVIZh//4baR3reo/4zP2v9?= =?iso-8859-1?Q?kBWwPxOaZjKIpUGOTojLZEiELpMW0NVNwtPZXkhuueSbSnyrOPbr7On9Ur?= =?iso-8859-1?Q?n7N/2YYgTDRNF8Tb1f++Dhom580VPNr4K1mu9r/d13h+PdtLNpHfFRvKcp?= =?iso-8859-1?Q?ZbShqe/8fghXQAmq0w0EYEV9UpXs3HaOlVefTyzayFaTivYuEFfFouzU+Q?= =?iso-8859-1?Q?LbvFEsHUx+asByips92444DwZasbAK+H2dk1cGlcNTLzZ7pXOGPlee2Ou7?= =?iso-8859-1?Q?kXbwQI3Xj/7nwIP5srCsai9JAC59q+J0AycF4km/3RE2P4AtV5IziO+DOw?= =?iso-8859-1?Q?3jXWTTkEzwCCc3JmiXMCqelMOlHGM9PHn8zwNTvgxjCV2JPeF76cauQAaR?= =?iso-8859-1?Q?ZNCzhr/qOJ2ojt202/WUHFFy//I17vThRxjznG6+LaNUaVv07sa7?= X-Exchange-RoutingPolicyChecked: GuIbkHpK6wcpkHG5amxc9oAb4elBNsZoFgAoUBHSXNIp8k2j0ljogpGbNUScvEXrhIB9mmNaNLfF9HQ18hotV86DWv4bq0JEjnxC98AESKf6Q5omeb7zjgTk4eeYNjWv6YvOuBTbByj5pcHHIw53anez9TYVZJauarII36JjyaUKEL6faLjdQgr09JNXRjcKmpc3yAdMMaxMhwJYedvEXjyXcrfn+VPaBsLDpVdiDLj4L7H4eYNkjdF1Pb3m7BgWXPqIURGJOiB4nBWiN+PDuSh9TKAY8T6Ge2UMLuzSJTxULaMH65Q593clRFwb4AO+/ukijjlwJdHLX80AhcjMsQ== X-MS-Exchange-CrossTenant-Network-Message-Id: e6642d40-a53b-40af-5c45-08df52858e16 X-MS-Exchange-CrossTenant-AuthSource: MW3PR11MB4684.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2026 04:09:27.9610 (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: +qpCo/LhH1aRFNPOrWG4cSH9uDLlrQt56igXFceoydxwvb8n+hmjQT4rufNdfLU3cSMhMN0VG43b6LnJb+JZT8XLof4FA37bT2mFYSKAJhSb7KkM8f43hzVnHIAAkN/u X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR11MB8990 X-OriginatorOrg: intel.com On Thu, Dec 03, 2026 at 12:23:49PM -0800, Matthew Brost wrote: >Wire up end-to-end defrag for IOVA-mapped BOs. A defrag move >is eligible whenever the destination TT is IOVA mapped. The >packed-copy step moves only changed pages; the IOVA reservation >is transferred to the new backing so device-visible addresses >are preserved, avoiding GPU rebind overhead. > >Add xe_bo_defrag_use_iova() to select the IOVA defrag path. >Add xe_bo_defrag_iova_copy() to drive the move: diff new vs >stashed old TT, link changed pages packed, blit them, then >queue a post-copy finalize job. > >The finalize job tears down the temporary packed mapping, >transfers the full old TT reservation to the new one, and >relinks the copied pages at natural offsets. > >Borrowed pages skip the copy and simply adopt the old >reservation. > >Since reservation transfer preserves device-visible addresses, >xe_bo_trigger_rebind() skips drm_gpuvm_bo_evict() marking for >dma-fence mode VMs; GPU PTEs stay valid, and exec already waits >on the kernel fences of all external BOs. > >Preempt-fence mode VMs are still marked evicted. For an external >BO the move's kernel fence lands in the BO's own dma-resv, and >only the rebind chains it into the VM's dma-resv, which is what >the preempt rebind worker and xe_vm_add_compute_exec_queue() >wait on. Defrag targets 3D (dma-fence mode) workloads, so the >needless rebind of compute VMs is accepted rather than teaching >the preempt paths to wait on external BO kernel fences. > >v5: > - Assert of move always happens (Sashiko) > - All call drm_gpuvm_bo_evict a preempt VMs (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 | 340 +++++++++++++++++++++++++++++++++++-- > 1 file changed, 326 insertions(+), 14 deletions(-) > >diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c >index cc419939dddb..d5d27727c910 100644 >--- a/drivers/gpu/drm/xe/xe_bo.c >+++ b/drivers/gpu/drm/xe/xe_bo.c >@@ -16,6 +16,7 @@ > #include > #include > #include >+#include > #include > #include > #include >@@ -28,6 +29,7 @@ > #include > > #include "xe_device.h" >+#include "xe_dep_job_types.h" > #include "xe_dep_scheduler.h" > #include "xe_dma_buf.h" > #include "xe_drm_client.h" >@@ -573,7 +575,6 @@ static void xe_tt_unaccount_iova(struct xe_device *xe, > * @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) > { >@@ -598,7 +599,6 @@ static void xe_tt_unaccount_iova(struct xe_device *xe, > { > } > >-__maybe_unused > static void xe_tt_account_iova_pages(struct xe_device *xe, > struct xe_ttm_tt *xe_tt) > { >@@ -905,7 +905,6 @@ struct xe_tt_iova_copy { > * 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, >@@ -954,7 +953,6 @@ struct xe_tt_iova_run_collect { > }; > > /* 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) > { >@@ -977,7 +975,6 @@ static int xe_tt_iova_grow(void **arr, unsigned int *cap, unsigned int need, > 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; >@@ -1032,7 +1029,6 @@ static void xe_tt_iova_store_run(pgoff_t start, pgoff_t count, void *arg) > * > * 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) > { >@@ -1068,7 +1064,6 @@ static int xe_tt_iova_copy_init(struct ttm_tt *new_tt, struct ttm_tt *old_tt, > * 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); >@@ -1099,7 +1094,6 @@ static void xe_tt_iova_copy_fini(struct xe_tt_iova_copy *copy) > * 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) > { >@@ -1152,6 +1146,130 @@ static int xe_tt_map_iova_copy(struct xe_device *xe, struct ttm_tt *new_tt, > return ret; > } > >+/** >+ * struct xe_iova_defrag_job - Post-copy finalize job for an IOVA defrag move. >+ * >+ * After the GPU defrag copy into the packed copy-step mapping completes, this >+ * dependency job runs the CPU-side IOMMU fixups at the point of no failure: >+ * tear down the temporary packed mapping, then per changed run unlink the old >+ * pages and link the new pages into the (transferred) reservation at their >+ * natural offset. >+ */ >+struct xe_iova_defrag_job { >+ /** @dep: base generic dependency Xe job. */ >+ struct xe_dep_job dep; >+ /** @xe: The xe device. */ >+ struct xe_device *xe; >+ /** @new_tt: The destination tt being finalized (owns the reservation). */ >+ struct ttm_tt *new_tt; >+ /** >+ * @copy_iova: Snapshot of the new tt's temporary IOVA reservation that >+ * held the packed copy-step mapping. Destroyed by the job (the new tt >+ * itself adopts the old tt's reservation at job creation). >+ */ >+ struct dma_iova_state copy_iova; >+ /** @copy_bytes: Byte length of the packed copy-step mapping. */ >+ size_t copy_bytes; >+ /** @copy: Changed-page description; the job owns and frees @copy.runs. */ >+ struct xe_tt_iova_copy copy; >+}; >+ >+static struct dma_fence *xe_iova_defrag_job_run(struct xe_dep_job *dep_job) >+{ >+ struct xe_iova_defrag_job *job = >+ container_of(dep_job, typeof(*job), dep); >+ struct xe_device *xe = job->xe; >+ struct device *dev = xe->drm.dev; >+ struct xe_ttm_tt *xe_tt = >+ container_of(job->new_tt, struct xe_ttm_tt, ttm); >+ unsigned int r, l; >+ >+ /* >+ * Tear down the temporary packed copy-step mapping and free its >+ * reservation. The new tt has already adopted the old tt's full >+ * reservation (transferred at job creation), so this only touches the >+ * snapshot taken before the transfer. >+ * >+ * This mapping was the GPU blit's write destination, so tear it down >+ * with attrs 0 (not DMA_ATTR_SKIP_CPU_SYNC): for non-coherent or >+ * bounced (SWIOTLB) mappings the device->CPU copy-back / cache sync of >+ * the freshly copied data happens during unlink, exactly as >+ * xe_tt_unmap_iova() does. Skipping it would silently drop the >+ * defragmented data on those configs. >+ */ >+ dma_iova_destroy(dev, &job->copy_iova, job->copy_bytes, >+ DMA_BIDIRECTIONAL, 0); >+ >+ /* >+ * For each changed run, unlink the old pages (still linked from the >+ * adopted reservation). >+ */ >+ for (r = 0; r < job->copy.nr_runs; r++) { >+ size_t off = (size_t)job->copy.runs[r].start << PAGE_SHIFT; >+ size_t len = (size_t)job->copy.runs[r].count << PAGE_SHIFT; >+ >+ dma_iova_unlink(dev, &xe_tt->iova, off, len, >+ DMA_BIDIRECTIONAL, DMA_ATTR_SKIP_CPU_SYNC); >+ } >+ >+ /* >+ * Relink the freshly copied new pages from the snapshot captured at job >+ * creation. The destination tt's page array may have been mutated (or >+ * torn down) by TTM since then, so it is never dereferenced here. >+ * Borrowed pages are shared with the old tt and stay correctly linked >+ * for free, so the snapshot only covers the changed runs. >+ */ >+ for (l = 0; l < job->copy.nr_links; l++) { >+ int ret = dma_iova_link(dev, &xe_tt->iova, >+ job->copy.links[l].phys, >+ job->copy.links[l].offset, >+ job->copy.links[l].len, >+ DMA_BIDIRECTIONAL, >+ DMA_ATTR_SKIP_CPU_SYNC); >+ /* >+ * Point of no failure: the data is already copied and the >+ * reservation ownership has been transferred. A relink failure >+ * leaves a hole in the mapping; there is no safe recovery, so >+ * just warn. >+ */ >+ drm_WARN_ON(&xe->drm, ret); >+ } >+ >+ /* Sync the relinked changed runs into the device's view. */ >+ for (r = 0; r < job->copy.nr_runs; r++) { >+ size_t off = (size_t)job->copy.runs[r].start << PAGE_SHIFT; >+ size_t len = (size_t)job->copy.runs[r].count << PAGE_SHIFT; >+ >+ /* >+ * Point of no failure (as with the relink above): warn on a >+ * sync error so a stale IOMMU cache does not fail silently. >+ */ >+ drm_WARN_ON(&xe->drm, dma_iova_sync(dev, &xe_tt->iova, off, len)); >+ } >+ >+ /* >+ * All work is synchronous CPU-side IOMMU fixup, so there is no hardware >+ * fence to wait on; returning NULL makes the scheduler signal the job's >+ * finished fence immediately. >+ */ >+ return NULL; >+} >+ >+static void xe_iova_defrag_job_free(struct xe_dep_job *dep_job) >+{ >+ struct xe_iova_defrag_job *job = >+ container_of(dep_job, typeof(*job), dep); >+ >+ xe_tt_iova_copy_fini(&job->copy); >+ drm_sched_job_cleanup(&job->dep.drm); >+ kfree(job); >+} >+ >+static const struct xe_dep_job_ops xe_iova_defrag_job_ops = { >+ .run_job = xe_iova_defrag_job_run, >+ .free_job = xe_iova_defrag_job_free, >+}; >+ > /* > * xe_tt_iova_transfer - Transfer a full IOVA reservation old_tt -> new_tt. > * >@@ -1168,7 +1286,6 @@ static int xe_tt_map_iova_copy(struct xe_device *xe, struct ttm_tt *new_tt, > * 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) >@@ -1184,6 +1301,157 @@ static void xe_tt_iova_transfer(struct xe_device *xe, > old_tt->use_iova = false; > } > >+/* >+ * xe_bo_defrag_iova_copy - Run an IOVA defrag move with a packed copy mapping. >+ * >+ * Only the changed (non-borrowed) pages of @new_tt are DMA mapped, packed >+ * contiguously into the front of its reservation, the GPU copy blits them from >+ * the old tt at natural offsets, and a post-copy finalize job adopts the old >+ * tt's full reservation and relinks the changed runs. Returns the finalize >+ * job's finished fence (the fence the move waits on), or an ERR_PTR on failure >+ * with all partial state unwound. >+ */ >+static struct dma_fence * >+xe_bo_defrag_iova_copy(struct xe_device *xe, struct xe_migrate *migrate, >+ struct xe_bo *bo, struct ttm_resource *old_mem, >+ struct ttm_resource *new_mem, struct ttm_tt *old_tt, >+ bool handle_system_ccs) >+{ >+ struct ttm_tt *new_tt = bo->ttm.ttm; >+ struct xe_ttm_tt *new_xe_tt = container_of(new_tt, struct xe_ttm_tt, ttm); >+ struct xe_ttm_tt *old_xe_tt = container_of(old_tt, struct xe_ttm_tt, ttm); >+ struct drm_sched_entity *entity = >+ xe_dep_scheduler_entity(xe->mem.defrag.iova_sched); >+ struct xe_iova_defrag_job *job; >+ struct dma_fence *copy_fence; >+ struct dma_fence *fence; >+ struct xe_tt_iova_copy copy; >+ int err; >+ >+ xe_assert(xe, new_xe_tt->iova_eligible && !new_xe_tt->use_iova); >+ xe_assert(xe, old_xe_tt->use_iova && old_xe_tt->iova_linked); >+ >+ err = xe_tt_iova_copy_init(new_tt, old_tt, ©); >+ if (err) >+ return ERR_PTR(err); >+ >+ /* >+ * TTM fails a defrag move that (re)allocates no chunk, so at least one >+ * page always differs from the old tt. >+ */ >+ if (XE_WARN_ON(!copy.nr_changed)) { >+ err = -EINVAL; >+ goto err_copy; >+ } >+ >+ err = xe_tt_map_iova_copy(xe, new_tt, ©); >+ if (err) >+ goto err_copy; >+ >+ copy_fence = xe_migrate_copy_defrag_iova(migrate, bo, old_mem, new_mem, >+ old_tt, copy.nr_changed, >+ handle_system_ccs); >+ if (IS_ERR(copy_fence)) { >+ err = PTR_ERR(copy_fence); >+ goto err_unmap; >+ } >+ >+ job = kzalloc(sizeof(*job), GFP_KERNEL); >+ if (!job) { >+ err = -ENOMEM; >+ goto err_fence; >+ } >+ >+ job->dep.ops = &xe_iova_defrag_job_ops; >+ job->xe = xe; >+ job->new_tt = new_tt; >+ job->copy_iova = new_xe_tt->iova; >+ job->copy_bytes = (size_t)copy.nr_changed << PAGE_SHIFT; >+ job->copy = copy; >+ >+ err = drm_sched_job_init(&job->dep.drm, entity, 1, NULL, 0); >+ if (err) >+ goto err_job; >+ >+ err = drm_sched_job_add_dependency(&job->dep.drm, >+ dma_fence_get(copy_fence)); >+ if (err) >+ goto err_job_init; >+ >+ /* >+ * Point of no failure: transfer the old tt's full reservation to the >+ * new tt. The finalize job (already armed below) destroys the packed >+ * copy mapping snapshot and relinks the changed runs. >+ */ >+ xe_tt_iova_transfer(xe, new_xe_tt, old_xe_tt); >+ memset(©, 0, sizeof(copy)); /* ownership moved to the job */ >+ >+ drm_sched_job_arm(&job->dep.drm); >+ fence = dma_fence_get(&job->dep.drm.s_fence->finished); >+ drm_sched_entity_push_job(&job->dep.drm); >+ >+ dma_fence_put(copy_fence); >+ >+ return fence; >+ >+err_job_init: >+ drm_sched_job_cleanup(&job->dep.drm); >+err_job: >+ kfree(job); >+err_fence: >+ /* >+ * The GPU copy into the packed destination mapping was already >+ * submitted; it must finish before we tear that mapping down below, >+ * otherwise the blit would fault or scribble on unmapped IOVA. (Reached >+ * only with a valid, submitted copy_fence; the IS_ERR(copy_fence) case >+ * jumps straight to err_unmap with no GPU work in flight.) >+ */ >+ dma_fence_wait(copy_fence, false); >+ dma_fence_put(copy_fence); >+err_unmap: >+ dma_iova_unlink(xe->drm.dev, &new_xe_tt->iova, 0, >+ (size_t)copy.nr_changed << PAGE_SHIFT, >+ DMA_BIDIRECTIONAL, DMA_ATTR_SKIP_CPU_SYNC); >+ dma_iova_free(xe->drm.dev, &new_xe_tt->iova); >+ new_xe_tt->use_iova = false; >+err_copy: >+ xe_tt_iova_copy_fini(©); >+ return ERR_PTR(err); >+} >+ >+/* >+ * xe_bo_defrag_use_iova - Whether a defrag move should use the packed IOVA path. >+ * >+ * Eligible when the move is a defrag (stashed old tt) and the destination tt is >+ * IOVA mapped. The IOVA reservation is transferred to the new backing, so the >+ * device-visible addresses are preserved and no GPU rebind is needed (see >+ * xe_bo_trigger_rebind()); this makes the path worthwhile regardless of BO >+ * size. A flat-CCS aux pass, if needed, is migrated packed alongside the data >+ * (changed pages only), so it does not disqualify the path. Otherwise the >+ * full-mapping defrag path is used. >+ */ >+static bool xe_bo_defrag_use_iova(struct ttm_buffer_object *ttm_bo) >+{ >+ struct xe_ttm_tt *xe_tt, *old_xe_tt; >+ >+ if (!ttm_bo->defrag_old_tt || !ttm_bo->ttm) >+ return false; >+ >+ xe_tt = container_of(ttm_bo->ttm, struct xe_ttm_tt, ttm); >+ old_xe_tt = container_of(ttm_bo->defrag_old_tt, struct xe_ttm_tt, ttm); >+ >+ /* >+ * The old tt must hold a live IOVA mapping (the packed copy reads its >+ * IOVA and the finalize job transfers its reservation to the new tt), >+ * and the new tt must be eligible to take the temporary copy-step >+ * reservation. Eligibility is a deterministic per-device decision taken >+ * at tt creation, so for a given BO the old and new tt always agree; >+ * the explicit old-tt check guards against ever routing a sg-fallback >+ * old tt into xe_tt_iova_transfer() (which would copy an invalid iova). >+ */ >+ return xe_tt->iova_eligible && old_xe_tt->use_iova; >+} >+ > /* > * Account ttm pages against the device shrinker's shrinkable and > * purgeable counts. >@@ -1570,6 +1838,7 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo, > struct drm_gem_object *obj = &bo->ttm.base; > struct drm_gpuvm_bo *vm_bo; > bool idle = false; >+ bool defrag_iova; > int ret = 0; > > dma_resv_assert_held(bo->ttm.base.resv); >@@ -1582,18 +1851,48 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo, > dma_resv_iter_end(&cursor); > } > >+ /* >+ * A defrag move that reallocates IOVA-mapped backing preserves the >+ * device-visible addresses: the IOVA reservation is transferred from >+ * the old to the new tt, so the existing GPU PTEs stay valid and the >+ * BO must not be marked evicted (the rebind paths in xe_exec_ioctl() >+ * and preempt_rebind_work_func() would otherwise needlessly rebind). >+ * Preempt fences still need to be triggered, and fault-mode / L2 >+ * flush-optimized configs still need a TLB invalidation below, so only >+ * the eviction marking is skipped (except on L2 flush-optimized HW, >+ * where that invalidation zaps the PTEs of a dma-resv VM). >+ * >+ * Preempt-fence mode VMs are still marked evicted: for an external BO >+ * the move's kernel fence lands in the BO's own dma-resv, which only >+ * the rebind (chaining it into the VM's dma-resv) makes >+ * preempt_rebind_work_func() and xe_vm_add_compute_exec_queue() wait >+ * for. Defrag targets 3D (dma-fence mode) workloads, whose exec waits >+ * on the kernel fences of all external BOs, so the needless rebind of >+ * compute VMs is accepted rather than teaching the preempt paths to >+ * wait as well. >+ */ >+ defrag_iova = xe_bo_defrag_use_iova(&bo->ttm); >+ > drm_gem_for_each_gpuvm_bo(vm_bo, obj) { > struct xe_vm *vm = gpuvm_to_vm(vm_bo->vm); > struct drm_gpuva *gpuva; > > if (!xe_vm_in_fault_mode(vm)) { >- drm_gpuvm_bo_evict(vm_bo, true); >+ if (!defrag_iova || xe_vm_in_preempt_fence_mode(vm)) >+ drm_gpuvm_bo_evict(vm_bo, true); > /* > * L2 cache may not be flushed, so ensure that is done in > * xe_vm_invalidate_vma() below > */ > if (!xe_device_is_l2_flush_optimized(xe)) > continue; >+ >+ /* >+ * The invalidation below zaps the PTEs, so a defrag-IOVA >+ * BO must be rebound after all. >+ */ >+ if (defrag_iova && !xe_vm_in_preempt_fence_mode(vm)) >+ drm_gpuvm_bo_evict(vm_bo, true); > } > > if (!idle) { >@@ -2506,6 +2805,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict, > 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; >+ bool defrag_iova = xe_bo_defrag_use_iova(ttm_bo); > int ret = 0; > > /* >@@ -2578,7 +2878,12 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict, > needs_clear = (ttm && ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC) || > (!ttm && ttm_bo->type == ttm_bo_type_device); > >- if (new_mem->mem_type == XE_PL_TT) { >+ /* >+ * For a defrag move using the packed IOVA path the destination tt is >+ * not fully mapped here; only the changed pages are mapped (packed) for >+ * the copy, and the finalize job establishes the full mapping. >+ */ >+ if (new_mem->mem_type == XE_PL_TT && !defrag_iova) { > ret = xe_tt_map(xe, ttm); > if (ret) > goto out; >@@ -2711,9 +3016,16 @@ 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) { >- fence = xe_migrate_copy_defrag(migrate, bo, old_mem, new_mem, >- ttm_bo->defrag_old_tt, >- handle_system_ccs); >+ if (defrag_iova) >+ fence = xe_bo_defrag_iova_copy(xe, migrate, bo, old_mem, >+ new_mem, >+ ttm_bo->defrag_old_tt, >+ handle_system_ccs); >+ else >+ fence = xe_migrate_copy_defrag(migrate, bo, old_mem, >+ new_mem, >+ 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); >-- >2.34.1 >