From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=198.175.65.12 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1796071892; b=Ioaq2/uktqqQK3iVt7mQHYCjPUu1kMXgRU/PqdSKckggMP9eK0Sun4II4ww6w4InJFmr hXM46ImMgHbYBjlavevPLCGnOucudEFlSFETCODVBhxod4iPl/B90+3+Jyn602GlgKJRV VBbSJ54tLIkhTJrmSBRvihU4h0KIOwZrdPuIhesvv5Yhh2IT64dmL5RpSYg3GVE9deczJ x13I5KXbQgauDkiGowWxVEWo6AWb1mF50KOlVOS+Ox28uFHCvS1C/43ujVgCAz2W0t9Ea NmDAZEleZQBLf6O0TsuWdpVH9wIyvry7Eq2Sbw5DgiKCCAY6rghwP4c9R7KHAtpz/PQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796071892; 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=XjmPYFK62qDOUYnc23Xbp9f3w2ylzlPtGEPuM9n5wx8=; b=XJaE60HQTN5acRCokQaVr6otSNftd5zy0I0u6t3P0D/TVX5fjyQOwTy91DoDwdF5lm1p +nBvUJNFaGe1ybzpUpqbCxNrP5dUjCs7AxvhY6jBcXW4oXDtGKC+5dTiDLjSH1WU7LrQv fNnWXs22rlO49FuRStfJm0vYKCR4PGyGJQ9OYULa62S2Qqs9rnQxIDy+uM2/6PnEIC/uq MmCzkWIoWSkkesRJ+lv4UgOqcQck85m44EtCaRB0mzu25rT7leL1Uxg0X2f7esnX2GrLZ c0O75tFU3ygKy1NtVtgy9K3J9mz8E1ZPKDjG/d8p8PCECEfz1KsnocHh/yV3MhNChoQ== 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=MrLU5soS; arc=fail smtp.remote-ip=198.175.65.12 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 93DDA606A31A for ; Mon, 30 Nov 2026 20:51:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 93DDA606A31A 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=MrLU5soS DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796071892; x=1827607892; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=XjmPYFK62qDOUYnc23Xbp9f3w2ylzlPtGEPuM9n5wx8=; b=MrLU5soS+mmd+70XDl1KMxVaQ9m0bleU1g6i0sN0ASuRT0h3sWlDapXF BBW7QwTm4zayZAArhnqp3SGIyVIojzFLoLpvy5FkIqO8dl5jdeeHT2FtI rRkq19UWyJ9bJeu2HW99YINNSuM8VuzZj8VzIKbDBgcBDUiJgRWX/yu94 iwTp6CO4p1toWdsmk3qumUSnFkG4F51RSS3h6Y4oUmFalc85Ffp72d/y/ CicM+jVGVq77aoYc0H9jJ/+jYJ/Gc7LEmZQwxOm/SLSsFHLmZPIjKdyJ5 soOrXA1TGncVGVIso8NU3PJOWnvHqoFtCCYzf+TWj/7ye0IH2ZIJPKOf8 g==; X-CSE-ConnectionGUID: Qz54XTmBSkeC6YJ+tE6s9g== X-CSE-MsgGUID: xqtxujOZRzmMwlTQi6LQjw== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4828538" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4828538" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 12:51:31 -0800 X-CSE-ConnectionGUID: eC5BRclZSaWh+wPvG9Yq+g== X-CSE-MsgGUID: XeCUpq5KSaWa/WfxtqLGww== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="13017829" Received: from fmsmsx902.amr.corp.intel.com ([10.18.126.91]) by orviesa007.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 12:51:30 -0800 Received: from FMSMSX901.amr.corp.intel.com (10.18.126.90) 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; Mon, 30 Nov 2026 12:51:30 -0800 Received: from fmsedg903.ED.cps.intel.com (10.1.192.145) 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 via Frontend Transport; Mon, 30 Nov 2026 12:51:30 -0800 Received: from BL0PR03CU003.outbound.protection.outlook.com (52.101.53.51) 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; Mon, 30 Nov 2026 12:51:29 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WAPQb60l3f+/ZF+7WgRXmg/UY2UtiHlwVBDc5MJDjku8oeZwmJ3RRj+5gaiiVVOIsHZKIe5mJFuBpKCidSk0m/EWWwDVVN7lwCqe+6e+pzrY0YibLaevjPCi2yPyEVYbMq70Qn7/suUtSs0vbWADJ5Qbk3s8+eL9aD9kKYM2PSuIVnZxJSHug56vcovo0NMGJNcnzgPqsFpGB3fRr1cQlk/nSgXL9TUlRcXYA0pO9J2zIfywSdbYRoSiws91LpN6FfFRjJNIEvuOEDKIAw77GVAnNx5Dx3YORmC3wX29kpEZ37NyZf6aC2AUxnWAVgz2O/Ed3e5JDCZCsiSoLw+3yA== 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=jQ8pauJgBxuqnBADpPl5BgotRSnrKl1A9RTwv3OxY3I=; b=mYFKQ+nSJ1ziLLKHnYZDXO6SH1oQB5rSQc8I0SFapLtkhdtDEq62qD9NYcVaqe0mGI2/rzallpZb3LTb4peOlHxm+t/gUatyDAoTjWMqpdFhggrL0rqPam1hHhZdrWIaROOVp4PHwHgxvO02+m1IdkxIOKZq0m/rq8qZ8Fqv6anm8HfIXG/ZNPllmJbnwB3CkDwoXxfBTsE3/ZtAAiAVNUKU6ZhSed5dgS03TVldtSiPXdVkIuzXR095wGJQDOhSY4O/zSPBRwW5y1DmE/KdCMxJVD/21thpgKDLfaO9zG7hLK8aKgiasxsA57CKhU14bvFcjVDSNa31QHunixvboA== 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 IA6PR11MB430025.namprd11.prod.outlook.com (2603:10b6:208:600::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Mon, 30 Nov 2026 20:51:26 +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.0662.012; Mon, 30 Nov 2026 20:51:26 +0000 Date: Mon, 30 Nov 2026 12:51:23 -0800 From: Niranjana Vishwanathapura To: Matthew Brost CC: , , Carlos Santa , Ryan Neph , Christian Koenig , Huang Rui , Matthew Auld , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , , Thomas =?iso-8859-1?Q?Hellstr=F6m?= Subject: Re: [PATCH v3 32/33] drm/xe: Finalize defrag-IOVA moves with post-copy job Message-ID: References: <20260711025619.2540575-1-matthew.brost@intel.com> <20260711025619.2540575-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: X-ClientProxiedBy: SJ0PR03CA0294.namprd03.prod.outlook.com (2603:10b6:a03:39e::29) 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_|IA6PR11MB430025:EE_ X-MS-Office365-Filtering-Correlation-Id: 94bdc52a-ec74-4f2c-7e8d-08df4f23b327 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|366016|1800799024|23010399003|7416014|376014|10067099003|56012099006|261026121527099003|261022105027099003|261026140227099003|261028144727099003|261021121427099003|261021123027099003|261022075727099003|261102123227099003|261009223027099003|22082099003|18002099003|5023799004|11063799006|4143699003|6133799003; X-Microsoft-Antispam-Message-Info: aAOOe02XwXV4OXqWiCy+G1VbXYvOUJhCHBhbfAFvCHGrGO5GW6PENQM67Do6cThgQa4EwFbpEb1SuEkUIfVo3Kj2pB6Wuq532umaUhr6cHtqbZZgDhEclPVGpjPWxgShcKEK4nwBm0gi+mD+M8a2n8xNakQDso9IbhJ6vQ/cQJ85t1MzfoEyKUM95ZOaz2iDbh7xW2HQJ7YXxywCuFWtTRa7p9EXyCDAl31iPjBtQoaYeWSV2Jfogtp8oAXdlSDU0wn6WJ8FvkqTTpHVzRNXa1d4z/D+Ojbza39gNcC45r85BYMv9gtm8rRHT0SQiYEuAUXw3O9DWHItKvzt7S81dIYGvnClKj2pKmx8+0k8RjUgSdqwutgJOyJpM9bXq0OXzNB4/RRi3HPVT3P4F/fQlYpfBAOB0B4ijEKu624boH8SN7BsGQeeLG5aZnlAHn8/KfHpQDbHo5EVTgoV7+eJKYP7bvPCIKL8vUiFyYE9dnZvNdeOTXbjSgBq8LnnkHz+VgX+qNvEoSWgzYQbJK1x0jEw9UeN5+AOai8bezxyqDEcDO/lDm+YtVANljSZXrbHQH3ZgsnJ1tU0X2NcC7L0SqQ/9ksvdrnpnDQixFunjccjZ1G4QJaYaECwi9AMCDInLGF5UA647lFtQKw3UsKdc0NjegUeEM+hzRBF0LdTOCc= 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)(366016)(1800799024)(23010399003)(7416014)(376014)(10067099003)(56012099006)(261026121527099003)(261022105027099003)(261026140227099003)(261028144727099003)(261021121427099003)(261021123027099003)(261022075727099003)(261102123227099003)(261009223027099003)(22082099003)(18002099003)(5023799004)(11063799006)(4143699003)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?Ki/Ub70XFrd6tOMEnWGbr/b0n7/hsL6kgo6xryX3BJa6/Ye0GqikOamOmG?= =?iso-8859-1?Q?g3GbQOHFYmzg3BlwuSgoOw6Mn8Vbnl+otixjdBTATPpgBJSX6m7Kvpk5DR?= =?iso-8859-1?Q?M0caAzXaAibEks50krVqTOkoFiIOa+PZlIJqJikT5ulmy9L5TJ5xNlqYwG?= =?iso-8859-1?Q?yMH7GCPlPoscOMEwZlSspPcAZ2XcabM9cn1X7iFZeP0LIJ0dt/iR4ODHtA?= =?iso-8859-1?Q?ZVXyvjiLuhSTbQzoOrE2oswTWIxhbI4HPwV386w6m8+B2Q8UY8DVdDebyz?= =?iso-8859-1?Q?BdoqM1LNFyU+wia+OdaI5IH/UpNPjWO6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a8PshFXe3Arb3+ECzoV7zcsX30MqFUcnyUsLiTWR6pgf9m5cziO3HqwGmRGS0O6u0/zmYyzlQ== X-MS-Exchange-CrossTenant-Network-Message-Id: 94bdc52a-ec74-4f2c-7e8d-08df4f23b327 X-MS-Exchange-CrossTenant-AuthSource: MW3PR11MB4684.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 20:51:25.9732 (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: +RdmzSRLaI1KwH3Gh8FXE62E4HAbcKjfyGcb55XtwZfRlB3givaFJibBoG1tyjyAbl+RoDIXCjjRmZUPf3jAJfFOtHyb03RJ8KqUpNCPKn7E5DV/q/bvPOWrGIJtzADm X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA6PR11MB430025 X-OriginatorOrg: intel.com On Tue, Nov 24, 2026 at 01:08:37PM -0800, Matthew Brost wrote: >On Fri, Nov 13, 2026 at 06:02:28PM -0800, Niranjana Vishwanathapura wrote: >> On Fri, Jul 10, 2026 at 07:56:18PM -0700, 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; >> > GPU PTEs stay valid. >> > >> > Cc: Carlos Santa >> > Cc: Ryan Neph >> > Cc: Christian Koenig >> > Cc: Huang Rui >> > 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: GitHub_Copilot:claude-opus-4.8 >> > Signed-off-by: Matthew Brost >> > >> > --- >> > >> > v3: >> > - Check dma_iova_sync(), wait the copy fence before unlink on error, >> > and gate the fast path on old_tt->use_iova (Sashiko) >> > --- >> > drivers/gpu/drm/xe/xe_bo.c | 325 +++++++++++++++++++++++++++++++++++-- >> > 1 file changed, 311 insertions(+), 14 deletions(-) >> > >> > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c >> > index c087f17ad6db..36290f58ccc1 100644 >> > --- a/drivers/gpu/drm/xe/xe_bo.c >> > +++ b/drivers/gpu/drm/xe/xe_bo.c >> > @@ -13,6 +13,7 @@ >> > #include >> > #include >> > #include >> > +#include >> > #include >> > #include >> > #include >> > @@ -25,6 +26,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" >> > @@ -542,7 +544,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) >> > { >> > @@ -567,7 +568,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) >> > { >> > @@ -806,7 +806,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, >> > @@ -855,7 +854,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) >> > { >> > @@ -878,7 +876,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; >> > @@ -933,7 +930,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) >> > { >> > @@ -969,7 +965,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); >> > @@ -1000,7 +995,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) >> > { >> > @@ -1047,6 +1041,133 @@ 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 original IOVA reservation that >> > + * held the temporary 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. >> > + */ >> > + if (job->copy_bytes) >> > + dma_iova_destroy(dev, &job->copy_iova, job->copy_bytes, >> > + DMA_BIDIRECTIONAL, 0); >> > + else >> > + dma_iova_free(dev, &job->copy_iova); >> > + >> > + /* >> > + * 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. >> > * >> > @@ -1063,7 +1184,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) >> > @@ -1078,6 +1198,154 @@ 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; >> > + bool packed = false; >> > + int err; >> > + >> > + xe_assert(xe, new_xe_tt->use_iova && !new_xe_tt->iova_linked); >> > + 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); >> > + >> > + if (copy.nr_changed) { >> > + err = xe_tt_map_iova_copy(xe, new_tt, ©); >> > + if (err) >> > + goto err_copy; >> > + packed = true; >> > + >> > + copy_fence = xe_migrate_copy_defrag_iova(migrate, bo, old_mem, >> > + new_mem, old_tt, >> > + copy.nr_changed, >> > + handle_system_ccs); >> > + } else { >> > + copy_fence = dma_fence_get_stub(); >> > + } >> > + 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); >> >> Assisted-by: LLM >> >> We transfer the ownership here without waiting for blit to complete. >> Probbly we should wait for copy fence to complete? >> > >Most definitely not. This is an async pipeline, we don't block on >anything by design - blocking anywhere would break the entire design as >we'd miss page flips. > >Here once we can't fail, we update the bookkeeping of the TTs so we can >immediately issue another async job behind this will the current one is >in flight. > Ok >> Niranjana >> >> > + 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.) >> > + */ >> > + if (packed) >> > + dma_fence_wait(copy_fence, false); >> > + dma_fence_put(copy_fence); >> > +err_unmap: >> > + if (packed) >> > + 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); >> > +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); >> > + >> > + /* >> > + * Both tts must be IOVA mapped: the packed copy reads the old tt's IOVA >> > + * and the finalize job transfers the old tt's reservation to the new >> > + * one. use_iova 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->use_iova && old_xe_tt->use_iova; >> > +} >> > + >> > /* >> > * Account ttm pages against the device shrinker's shrinkable and >> > * purgeable counts. >> > @@ -1357,6 +1625,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); >> > @@ -1369,12 +1638,25 @@ 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. >> > + */ >> >> The commit is bit confusing compared to the code below. Eviction marking is >> not completely skipped, it is only skipped when it is not needed. May be >> update the comment? >> > >I've read this a few times and it pretty clear to me. > >Do you have different suggestion? > "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. When the async TLB-flush fast path below succeeds, the BO need not be marked evicted (the rebind paths in xe_exec_ioctl() and preempt_rebind_work_func() would otherwise needlessly rebind); the eviction mark is reinstated below (the 'else if (defrag_iova)' branch) as a fallback when that fast path isn't taken. Preempt fences still need to be triggered regardless." Main point being drm_gpuvm_bo_evict() called in 'else if (defrag_iova)' case. Niranjana >Matt > >> Niranjana >> >> > + 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) >> > + drm_gpuvm_bo_evict(vm_bo, true); >> > /* >> > * L2 cache may not be flushed, so ensure that is done in >> > * xe_vm_invalidate_vma() below >> > @@ -1394,6 +1676,8 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo, >> > if (!ctx->no_wait_gpu && >> > !xe_vm_flush_vm_bo_tlb_async(vm, bo, vm_bo)) >> > continue; >> > + else if (defrag_iova) >> > + drm_gpuvm_bo_evict(vm_bo, true); >> > } >> > >> > if (!idle) { >> > @@ -2120,6 +2404,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict, >> > bool needs_clear; >> > 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; >> > >> > /* >> > @@ -2168,7 +2453,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; >> > @@ -2278,9 +2568,16 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict, >> > >> > fence = xe_migrate_clear(migrate, bo, new_mem, flags); >> > } else if (ttm_bo->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); >> > -- >> > 2.34.1 >> >