From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=198.175.65.21 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1796148317; b=Y3jzhUpz4cEkLL40YNZ2GUOXCrUMHpgs8WaGeMtp3agaXIs2Yh6F0WdX5PmeBkR/ksAn FeZcTYckoK1s6IIv2I2zLrpmPcxvd7vy5oihE9PNuABXpLsyZG6nfnX4og7FEWX3otg6A LpBimLAmoM8l8oXCNtGSgJ3yZzhwvGGqlQ8duur2bkTQvE+4xXNf4suio2iHfwwCPcI57 v2iFuAxHfni2waPcgboUWrO2ZCHQzyp0/yL7nb59MwMvGzWwu/pB+v7833Xb7O/N1WASq F++dl3uioeHkwfMGS1vYKKSQFf5pMWK1dv3xkhTr1bdbIrOTF4VlC4TH1AFqxWdtU2Q== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796148317; 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=x2OvtvnIvzbiBl5J+dA/bp6/+Q1x4YykKNekPv8Bo1Q=; b=3JP9Ahmc0pPUABj54O4ynnNvz+6r7g/UtYKJNwxhA1oyn95oC7LVIJOF1bbA+zXX7/Vu LjOD2sQrnjg0/gRzjYBWP0VQRJ6pEdxa//uTbEwKt9TkGFBvw2YjoAqJwa34HVL4w+I2w p0ktcMVDiaji4XC98hBPEe+iPViOOQV6sIYFiqjiiKTUQt1JsbLGwRsgyl6nSbOcHh4Fa yj+uMrVxbAzWW7P0qvjLIaC4hrIwTu+4Mk+ldKtc3u2+9ryPk9scHbpjrDl5nySZKsDWg iqHj18jkMjFr6vUj71VXZvKVBw/zXT/ZrDMP04Oiw36q5dc+0BUysJDR3EaHOeIAIfA== 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=iLdfFw9p; arc=fail smtp.remote-ip=198.175.65.21 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (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 18D2B606A31A for ; Tue, 1 Dec 2026 18:05:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 18D2B606A31A 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=iLdfFw9p DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796148316; x=1827684316; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=x2OvtvnIvzbiBl5J+dA/bp6/+Q1x4YykKNekPv8Bo1Q=; b=iLdfFw9pZIsA9kuIeqXhFsE8prUHgucOII2JlrQZI7SzJx5A8TWtnCag 9NELM3GEI9Cal5ZBv/6RT2V3fs2rWMhezYmNLal6tNWv2NcwTUT+5gx8l kIBwm4dLfLNvHCHI+SVKHPz0F+ESAmnT9O6ojK1kfWCxdGCGM7C2pWlIn BE0r4GTOHqiQiDUQrsRUs7lcnQav8QfyoXhr1VevaeqA2nZYtaBZvQHgH Z4eIS0DQib5tMyIetY8TRjUuGP+lS0PvJhQpH1OLZWUPOsx/L6Uaetc1g TUGON9vHeXK7wzx8iKeDzmAyIBsa9zEdACQkULhgtD+aR4qWNV87WKcRk g==; X-CSE-ConnectionGUID: I1NZAPdoRhakRRZhYeQ7lQ== X-CSE-MsgGUID: /S8pGtCEQ2CbCEaGOboDyQ== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5142191" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="5142191" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 10:05:13 -0800 X-CSE-ConnectionGUID: a4ErA7HHQWS9g2qvnUmt1A== X-CSE-MsgGUID: jMSQRkHTRkO1m5OSzr5KXQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13689753" Received: from fmsmsx903.amr.corp.intel.com ([10.18.126.92]) by fmviesa009.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 10:05:13 -0800 Received: from FMSMSX901.amr.corp.intel.com (10.18.126.90) by fmsmsx903.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Tue, 1 Dec 2026 10:05:12 -0800 Received: from fmsedg902.ED.cps.intel.com (10.1.192.144) 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; Tue, 1 Dec 2026 10:05:12 -0800 Received: from BYAPR05CU005.outbound.protection.outlook.com (52.101.85.34) by edgegateway.intel.com (192.55.55.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Tue, 1 Dec 2026 10:05:12 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qfG0nthHhns7G1X8+1xcC50O7+O3FKdwz71tjyZt4lkUBGgN0vFz7ff/n5g/cR4k62YSjUbrfqkZ1NtVL3JojOZIggPv54aUV0UI3GRvZXCWOI78zWmVazobJWwWQVVIpGoT7nXU/0pj7TTJZxqXQH2qSnbvgSYNUY0QGiNoyLkTDGvo0a7v9O7QBgR3LJuX0Stxd+din63HaH5E0Y8JgB5EvNLWygT8JxQHwaCpCFq9bD/gLlYvq8J5zJ66y2PN1IrqcIC+i2WUj/zNf86a+lNDhUDOGe2g6plD3DEDWi1gdRaJo5Wx0nPowczZE0rsG8SoVj0HWW6rNmR+T1Fegw== 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=KgXDV6g2zAFrSfeo1zCeJH0O0vhRJ7AJc03BFVmhQfQ=; b=hgfKf6RmmNH0StkRFTwbdMsMDMGrOSJuR5EA7niiK2vpu49LWG/j2bNPI8w55tfcyjlyowHYpoeZ/Ly3lUvsp2/Vl/fYnB2J8TfU0tac7ZMtFXM/c36BtUOW2iREE7tjylrVD2rgUcnnk4qcm9W0RNOYVVWXdsJqFy8cOjPD3IOVyJi3StxKTaxQNP9tlyffyTrHj67i5brgAWVwah8VBMXkhZ1Ygx5KdLQ4vqLthZF3whXApeU9ke2ygQ1xb/R1Mo9ybXEebL14aTAaalCcQLK2j4Dt+CXjkrDCXhKw9nvrjrvfAhtRIgRVDkLWptKeLjS1ED3N824I/GJkjklhEA== 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 PH7PR11MB8009.namprd11.prod.outlook.com (2603:10b6:510:248::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Tue, 1 Dec 2026 18:05:02 +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; Tue, 1 Dec 2026 18:05:02 +0000 Date: Tue, 1 Dec 2026 10:04:59 -0800 From: Matthew Brost To: Niranjana Vishwanathapura 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 17/33] drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies Message-ID: References: <20260711025619.2540575-1-matthew.brost@intel.com> <20260711025619.2540575-18-matthew.brost@intel.com> Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: BY5PR04CA0011.namprd04.prod.outlook.com (2603:10b6:a03:1d0::21) 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_|PH7PR11MB8009:EE_ X-MS-Office365-Filtering-Correlation-Id: c2116384-6023-4f43-4ba8-08df4fd59eb8 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|261028144727099003|56012099006|261026140227099003|261102123227099003|261022105027099003|261021123027099003|261021121427099003|261009223027099003|22082099003|18002099003|11063799006|4143699003|6133799003|3023799007; X-Microsoft-Antispam-Message-Info: Yni2miMppwOMKMY8pnzeHmtM8UNo+O5Y1SUN+2NIvKInb0sfEZUOZt4VSpdsAYbB/Dz6ZePYa8wogDq/7pfzcc7tu93v6J2bKiauQJ+sXjLLOmsIdw/8S5EurNS8Yr3Qn9Plv1rFfnzoeXXuwx8oNWwuxHdRaR+NgWiJDxmqPmXA+8yX+mN69k8Lz/Y99Gv43dK/WBgvM74xmjVDjGlb1i1kqqW/hbVvHvr6/ceqpXZ3VjIRxux9uGFbn8z9Czed5kjmXDvvhONZj6xlW4hhehep+nZZLtnotv6pKrMNJ+D0x13L17IlvH3441Exkb5aVzClgUtxNOsSVpNhAvB+Ws0QJeUocUWbxwR/HGu9GdFNMnwu9ORnKfDTCNCwy41gW1Tizs6dA2u8D+Vz2S3Tbx28AlXGbdJO0paLtz+zSdAxbcn26nRWnRtcrFr+HZgx6u165xJxjqwtSqQwKtFEiXRrmxOudUJgaKMMl554ENM2/jd6xw19dk/e7dTP2JGaiFFnF/Z7vhVop/FfNoAYqS2x557wGpUuE8GsBw0K0rEjpDvj7UalgCL+h+1URjQhPeVBpQEDqjF1tbj6JPLomBKW3h9CfjIcs6cS2n987vFM2IXBxZz1D29O29X+om6tu6BvwkbxuKLy5MQwqK0fDaO1jdDP2P2zQtcgQq7m04A= 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)(366016)(1800799024)(23010399003)(7416014)(376014)(10067099003)(261028144727099003)(56012099006)(261026140227099003)(261102123227099003)(261022105027099003)(261021123027099003)(261021121427099003)(261009223027099003)(22082099003)(18002099003)(11063799006)(4143699003)(6133799003)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?RylZxSXw3Ew8cpcxv9Xnkg6/uLfbpKzhzJmOMEH2hTEL+XS16bbzgo7QPx?= =?iso-8859-1?Q?BRxbkyRdcy68Gel94iT/JNQtZzawSVPehLs/iHLm8pk3Ds4YSFc5uWzM65?= =?iso-8859-1?Q?/ySHDdcE7UKCX1iubwpQATa3dkPw5hC9uQIo3z+4nLNXhhV9xqdr7DVk57?= =?iso-8859-1?Q?/O3BJnifix4cjt8PvMj/UcYzuAxF7mEzGKJIX1944BpJQoxGC4SXoexsP2?= =?iso-8859-1?Q?VcUG/Y5yn0BMuXdjD7E2qw/q3w+LiX+EPSIlgzh1jBrqCYfUVBS6cTufH0?= =?iso-8859-1?Q?yCmiO6JBpkuH29XSS5vmDbkQmfs6+3+mgVAzdNzwKuI0Un6Qh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I+3Y/Y8ez3ZvcVYaMdPhojMv5WjaJDD5MzjQ== X-MS-Exchange-CrossTenant-Network-Message-Id: c2116384-6023-4f43-4ba8-08df4fd59eb8 X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4787.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 18:05:02.1596 (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: J7M8khUuJslPg+8Tqs1gOc5TcnzOudMnU0f5xw+VXQ5OFyaupzHD+BDXu4FRa9ZtsNS09tMKiuRx4SGqaTMx2Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB8009 X-OriginatorOrg: intel.com On Fri, Nov 06, 2026 at 09:07:36PM -0800, Niranjana Vishwanathapura wrote: > On Fri, Jul 10, 2026 at 07:56:03PM -0700, 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 folded > > into struct xe_migrate_copy_flags to keep the growing set of copy > > variants readable. > > > > 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 > > --- > > drivers/gpu/drm/xe/xe_migrate.c | 136 ++++++++++++++++++++++++++++---- > > drivers/gpu/drm/xe/xe_migrate.h | 8 ++ > > 2 files changed, 128 insertions(+), 16 deletions(-) > > > > diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c > > index 92d5e81ceac2..305c6e1942fb 100644 > > --- a/drivers/gpu/drm/xe/xe_migrate.c > > +++ b/drivers/gpu/drm/xe/xe_migrate.c > > @@ -858,13 +858,39 @@ static u32 xe_migrate_ccs_copy(struct xe_migrate *m, > > return flush_flags; > > } > > > > +/** > > + * struct xe_migrate_copy_flags - Flags for __xe_migrate_copy() > > + * @copy_only_ccs: Only copy the CCS aux state, aliasing the destination data > > + * mapping to the source (used when the data pages are shared between src/dst). > > + * @is_vram_resolve: Decompression (VRAM -> system) resolve; always uses the > > + * compression PAT index for the data 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 @defrag_copy pass) and both the source > > + * and destination data pages are mapped with the compression PAT so the aux > > + * state is copied indirect -> indirect. > > + * @defrag_copy: 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 @defrag_ccs pass. The two passes need > > + * opposite compression PAT settings, which is why they cannot be combined. > > + */ > > +struct xe_migrate_copy_flags { > > + u32 copy_only_ccs : 1; > > + u32 is_vram_resolve : 1; > > + u32 defrag_ccs : 1; > > + u32 defrag_copy : 1; > > +}; > > Assisted-by: LLM > > These flags seems to be mutually exclusive. So, probably use an enum instead? > > enum xe_migrate_copy_mode { > XE_MIGRATE_COPY_NORMAL, > XE_MIGRATE_COPY_CCS_ONLY, /* dst aliases src */ > XE_MIGRATE_COPY_VRAM_RESOLVE, > XE_MIGRATE_COPY_DEFRAG_DATA, /* distinct dst, verbatim data */ > XE_MIGRATE_COPY_DEFRAG_CCS, /* distinct dst, indirect->indirect aux */ > }; > Yes, this is better. Will change. Matt > Niranjana > > > + > > 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, > > + struct xe_migrate_copy_flags flags) > > { > > struct xe_gt *gt = m->tile->primary_gt; > > struct xe_device *xe = gt_to_xe(gt); > > @@ -881,20 +907,29 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > > bool src_is_vram = mem_type_is_vram(src->mem_type); > > bool dst_is_vram = mem_type_is_vram(dst->mem_type); > > 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) && > > + !flags.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) && > > + !flags.defrag_copy; > > + bool copy_system_ccs = copy_ccs && (!src_is_vram || !dst_is_vram) && > > + !flags.defrag_ccs && !flags.defrag_copy; > > > > /* > > * For decompression operation, always use the compression PAT index. > > * Otherwise, only use the compression PAT index for device memory > > * when copying from VRAM to system memory. > > */ > > - bool use_comp_pat = is_vram_resolve || (type_device && > > + bool use_comp_pat = flags.is_vram_resolve || (type_device && > > 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); > > @@ -903,7 +938,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > > return ERR_PTR(-EINVAL); > > > > if (!src_is_vram) > > - 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) > > @@ -912,7 +947,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); > > > > @@ -942,7 +978,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > > batch_size += pte_update_size(m, pte_flags, src, &src_it, &src_L0, > > &src_L0_ofs, &src_L0_pt, 0, 0, > > avail_pts); > > - if (copy_only_ccs) { > > + if (flags.copy_only_ccs) { > > dst_L0_ofs = src_L0_ofs; > > } else { > > pte_flags = dst_is_vram ? PTE_UPDATE_FLAG_IS_VRAM : 0; > > @@ -963,7 +999,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 += ((flags.copy_only_ccs || flags.defrag_ccs) ? 0 : > > + emit_copy_cmd_len(xe)) + > > ((needs_ccs_emit ? EMIT_COPY_CCS_DW : 0)); > > > > bb = xe_bb_new(gt, batch_size, usm); > > @@ -975,13 +1012,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 || flags.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, > > + else if (!flags.copy_only_ccs) > > + emit_pte(m, bb, dst_L0_pt, dst_is_vram, > > + copy_system_ccs || flags.defrag_ccs, > > &dst_it, src_L0, dst); > > > > if (copy_system_ccs) > > @@ -990,7 +1029,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 (!flags.copy_only_ccs && !flags.defrag_ccs) > > emit_copy(gt, bb, src_L0_ofs, dst_L0_ofs, src_L0, XE_PAGE_SIZE); > > > > if (needs_ccs_emit) > > @@ -1078,7 +1117,69 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m, > > struct ttm_resource *dst, > > bool copy_only_ccs) > > { > > - return __xe_migrate_copy(m, src_bo, dst_bo, src, dst, copy_only_ccs, false); > > + return __xe_migrate_copy(m, src_bo, dst_bo, src, dst, NULL, > > + (struct xe_migrate_copy_flags) { > > + .copy_only_ccs = copy_only_ccs, > > + }); > > +} > > + > > +/** > > + * 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, > > + (struct xe_migrate_copy_flags) { > > + .defrag_copy = true, > > + }); > > + > > + if (IS_ERR(fence) || !need_ccs) > > + return fence; > > + > > + fence2 = __xe_migrate_copy(m, bo, bo, src, dst, src_sg, > > + (struct xe_migrate_copy_flags) { > > + .defrag_ccs = true, > > + }); > > + if (IS_ERR(fence2)) > > + dma_fence_wait(fence, false); > > + dma_fence_put(fence); > > + > > + return fence2; > > } > > > > /** > > @@ -1096,7 +1197,10 @@ 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); > > + return __xe_migrate_copy(m, bo, bo, res, res, NULL, > > + (struct xe_migrate_copy_flags) { > > + .is_vram_resolve = true, > > + }); > > } > > > > /** > > diff --git a/drivers/gpu/drm/xe/xe_migrate.h b/drivers/gpu/drm/xe/xe_migrate.h > > index 965c45889c72..e4f996942a6d 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; > > @@ -132,6 +133,13 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m, > > struct ttm_resource *dst, > > bool copy_only_ccs); > > > > +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 > >