From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49A69606A322 for ; Thu, 3 Dec 2026 20:06:59 +0000 (UTC) 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=HGFukdW1 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0FFFD10EB5C; Thu, 3 Dec 2026 20:06:54 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 69B6F112B91 for ; Thu, 3 Dec 2026 20:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796328406; x=1827864406; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=XHrfAsKnpV5Y1466iFigcEBObr2lSK1F5mN1RhPlZYg=; b=HGFukdW1iwxYVyWqKPgyLAO0WBM5Z3DPSyhq1rAR+84t9W6IXMPWLqWQ VaLtVpGLLRmukPBrlSyfZYT/+B8ShDM93LxG5CigAXLYTSawDouOMXOLd JnYr3NtbkKvLH3DLakj8SLCbDOgh0MKcmxxZkbLdXCSpZUjjZyU+XiIvA UjqONnO0SCMqsiKV/gA3XdMQj+l8VLNzr2EVKEhJS4DfkfLn3FOMXA6MF By5V4tqg0fsJitvLBsi0ZWl54bxSOCa6+3It6vX5Dlq1eNt01hUHsyW8J pH84OboQ6oGZX0WFSMkFTkClxLrXyJ3ogVqYbuVMQd3G4aHkd0+ioQTFt g==; X-CSE-ConnectionGUID: UpxSt0GwRCGYCcNohXq4oQ== X-CSE-MsgGUID: EOhsKk8LTbaGr0HFYL9LCA== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5215798" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5215798" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 12:06:46 -0800 X-CSE-ConnectionGUID: VofMm288TOKylTU4MyJZdA== X-CSE-MsgGUID: m/Hqj53QRFuVVD0J9qclVA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="13963761" Received: from fmsmsx901.amr.corp.intel.com ([10.18.126.90]) by fmviesa005.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 12:06:45 -0800 Received: from FMSMSX903.amr.corp.intel.com (10.18.126.92) 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; Thu, 3 Dec 2026 12:06:45 -0800 Received: from fmsedg901.ED.cps.intel.com (10.1.192.143) 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 via Frontend Transport; Thu, 3 Dec 2026 12:06:45 -0800 Received: from BL0PR03CU003.outbound.protection.outlook.com (52.101.53.11) 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; Thu, 3 Dec 2026 12:06:45 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nXhNvjA0qOu17bY/APZSLOLY5Iiyh9NxKunm1dGJ4hzggC2JB9t7B2xK/yVLPgSSlYTnACzp3GVwr0RcqVYEUDwUpIOsKF+qvxKjL0nwlG2eSwqxaMJ/wdvcIQVCK6ptAXDhab7n9gmNh05oOPHKnrG/d8IjFUrA4WohPSdrw+qfI0nO1UzeiYmffuT3aSr10NFG+vaq5YBIM8emFCBprhhXO130uJFfshoU//1OzAn0llygRyLcr0wMq76UB7simDEY/JsjelyGRtA2QbHAgF6RpPLMKgIdij1BjbwgK6137gTVovz9+vx1KmEdVWGVb4/yJQVSKmoDGVcL2dW+BA== 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=ICekDMk+vtquOYNkuwkHOxfPPt4jRDDFSAligUL65uU=; b=vGaGEtjkuwVx+4OG4NQ7AB9pRZNm14r26KqjDVglGzrOUD8ao3956y7fA45W/a8YGtSPSvCxMqHXVGXvqNsqXnGYcshV69ZGyy4O5aHLgU4c5uYW3o+o5rvBbceNZiuNsmRz2VvRKlq7SoIQuni2a1Ct9tlvulyJVgQdRSycYs2AA984fLkn6s9AhfBiy3jHoPVcPJSMIYgCI08s3A9xCng+5YXQRQdSO4S+SPy3em48aVoQtCuyR3c2pwitZzslNmDPY2oPh2B8wsI42VDlYTTDrb0e6Lus9l8xJtHS4Y8xCCzW6gXVpV2oqpgXcLDGt2VUrRvFwGpHORuOshOX1g== 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 DS7PR11MB5990.namprd11.prod.outlook.com (2603:10b6:8:71::5) by PH8PR11MB6975.namprd11.prod.outlook.com (2603:10b6:510:224::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Thu, 3 Dec 2026 20:06:41 +0000 Received: from DS7PR11MB5990.namprd11.prod.outlook.com ([fe80::133c:5eed:3aec:b899]) by DS7PR11MB5990.namprd11.prod.outlook.com ([fe80::133c:5eed:3aec:b899%3]) with mapi id 15.21.0688.010; Thu, 3 Dec 2026 20:06:41 +0000 Date: Thu, 3 Dec 2026 15:06:38 -0500 From: Rodrigo Vivi To: =?iso-8859-1?Q?Pi=F3rkowski=2C?= Piotr CC: , Matt Atwood , Satyanarayana K V P , Tangudu Tilak Tirumalesh , Varun Gupta Subject: Re: [PATCH v2 2/5] drm/xe/ggtt: Align shareable GGTT nodes by GGTT address Message-ID: References: <20261203181408.362175-1-piotr.piorkowski@intel.com> <20261203181408.362175-3-piotr.piorkowski@intel.com> Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261203181408.362175-3-piotr.piorkowski@intel.com> X-ClientProxiedBy: BY3PR05CA0034.namprd05.prod.outlook.com (2603:10b6:a03:39b::9) To DS7PR11MB5990.namprd11.prod.outlook.com (2603:10b6:8:71::5) X-Archived-By: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR11MB5990:EE_|PH8PR11MB6975:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b19c1a5-6bd0-449e-0f7b-08df5178f24f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|23010399003|376014|10067099003|56012099006|11063799006|261102123227099003|261022075727099003|261021123027099003|261009223027099003|261021121427099003|261022105027099003|261028144727099003|261026121527099003|261026140227099003|22082099003|18002099003|4143699003; X-Microsoft-Antispam-Message-Info: gyIVWeKVL+r3U6jPWIep8iqDROWil6W1t038UlVaTOaJ5Fp7+6sIGHiipuPriU61rlWDzrGlxXKBTfWBVk0K098UHQX0LSZ4Jj8RC5vC5RyJM1soAgI8RlUIv8FGC1i3xvVtO+2WTfEp7673kWyECJ3r0+WR738f/25oN1vr2gGC0tceU570hpfXLP/rDQ4YHNChuIEpdGJBnQunyY+RZdpjhx0SKEmWjiupKwUoQPioc53hfuBR2ND8+1+unR6IUGo5vE4M0f42dACHjQQdIXnbLM7YoXI2/PVlTf1/Eu9ZLGifZkQ9+Yq1Y1BR2w5vdDaDe1cqMPLYYvN+gKXeMYF1p210d4FNEYLidFLGhUp1UUDiEE1jR9WXhOBt5iZjcPqhsOS0iOH4AsEIx5KhgsQ+7CxcepKdxdAwEqNG1u74leK+NTSFqBkhEqHfsonuoi8uMbKKYXQTQwwQU1pvScf8bJHcTlYGaPIM/BT6Bg+y1MYUR7ckUMwLA5Sw1dwMLDVSGX+Fg8H/uCUdcwq7BCSl/iA3ITJbhJALt38L2tPYISDK88hd77iSH3zUeSvPMNG/u8EhHOgvF7a6SPqUSX1+6YgkA5zG+rbHRGgbpr9DVcRoyLN+WU+gZKowKQ2GxUFqWv/l3yDZ8O2hosvZIfHut1ICTMYpszXgcOxqyi4= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS7PR11MB5990.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(23010399003)(376014)(10067099003)(56012099006)(11063799006)(261102123227099003)(261022075727099003)(261021123027099003)(261009223027099003)(261021121427099003)(261022105027099003)(261028144727099003)(261026121527099003)(261026140227099003)(22082099003)(18002099003)(4143699003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?wbhRAchJzIHAaDY7hoP7/HKBf70BynCMGv+PZuf9ybtJvHxl96zl2y+jsF?= =?iso-8859-1?Q?5rG4KU18gA70AaPy+MiMn5TiGDkzRE5ABRZ3y7QA6neXhw49+l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HDNDCBA6VUOkEHkP/oXuTRFGAUJ7S2XZQGCOCaaUqOVnrsQdq0ttvBmrZsk5pQGadQ+ZLlToptVISw395O16DRIwDhiOwT8YAwe5yEZCKZoNYq94y2SRS6esNXsrq2vNdap72QsJpAvile4/5TMfFIKpmaK6imBBPdZWjY0ZBYyIllhe/IyBlVra+pi6+d1JctSia7F2rTm7424WZ7HB7xsVNu+qACKacATP7ce7QdJzkGJAFzBNxdNMVJ9sPja0fFW4A81+6kDyw11NUefYPJAFl9kSLLU51XcPOzJLcZk3UNcZO65ljIxHzcMGnQF9z1jDoMyFQ+j97f3hww== X-MS-Exchange-CrossTenant-Network-Message-Id: 6b19c1a5-6bd0-449e-0f7b-08df5178f24f X-MS-Exchange-CrossTenant-AuthSource: DS7PR11MB5990.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2026 20:06:41.5559 (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: XSlmVtlqvC60N4wxyRudM8GoOXRqR+59U31q0GfKpjybEuQs7gDvbUJ762pO4KmIJ6RlupAKI3IVZQ+Q3Mocsg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR11MB6975 X-OriginatorOrg: intel.com X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Thu, Dec 03, 2026 at 07:14:05PM +0100, Piórkowski, Piotr wrote: > From: Piotr Piórkowski > > drm_mm offsets of the GGTT start at ggtt->start (the WOPCM size), so the > alignment passed to drm_mm is applied to the offset from ggtt->start, not > to the GGTT address. The GGTT address is only aligned when ggtt->start > is, which is not guaranteed as the WOPCM size differs between platforms. > > The GGTT range provisioned to a VF is programmed in the hardware by its > GGTT address, so any alignment requirement for it applies to the GGTT > address and not to the drm_mm offset. > > Make xe_ggtt_insert_node_shareable() align the GGTT address of the node. > If ggtt->start is not aligned to the requested alignment, look for the > highest suitable address in the holes of the shareable range and reserve > the node there. > > Also align by GGTT address in xe_ggtt_largest_hole() and > xe_ggtt_print_holes(), so the VF provisioning estimates match what can > actually be allocated. While at it, drop the max() with ggtt->start > there, a leftover from when drm_mm used GGTT addresses, which made both > skip the first ggtt->start bytes of the lowest hole. > > Cc: Matt Atwood > Cc: Rodrigo Vivi > Cc: Satyanarayana K V P > Cc: Tangudu Tilak Tirumalesh > Cc: Varun Gupta > Signed-off-by: Piotr Piórkowski Reviewed-by: Rodrigo Vivi > --- > drivers/gpu/drm/xe/xe_ggtt.c | 96 ++++++++++++++++++++++++++++++------ > 1 file changed, 82 insertions(+), 14 deletions(-) > > diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c > index c24b7814c3ab..f3836a04eefd 100644 > --- a/drivers/gpu/drm/xe/xe_ggtt.c > +++ b/drivers/gpu/drm/xe/xe_ggtt.c > @@ -939,13 +939,66 @@ struct xe_ggtt_node *xe_ggtt_insert_node(struct xe_ggtt *ggtt, u32 size, u32 ali > } > > #ifdef CONFIG_PCI_IOV > +/* > + * drm_mm aligns offsets from ggtt->start, but the GGTT address of a VF range > + * is what has to be aligned. If ggtt->start is not aligned to @align, look for > + * the highest offset with an aligned GGTT address in the holes of the > + * shareable range directly. > + */ > +static int ggtt_insert_node_shareable_locked(struct xe_ggtt_node *node, u64 size, > + u64 align) > +{ > + struct xe_ggtt *ggtt = node->ggtt; > + u64 range_start = ggtt_shareable_offset(ggtt); > + u64 range_end = ggtt->full_size; > + u64 hole_start, hole_end, best = U64_MAX; > + struct drm_mm_node *entry; > + > + lockdep_assert_held(&ggtt->lock); > + > + if (align <= 1 || IS_ALIGNED(ggtt->start, align)) > + return ggtt_insert_node_in_range_locked(node, size, align, range_start, > + ggtt->shareable_size, > + DRM_MM_INSERT_HIGH); > + > + xe_tile_assert(ggtt->tile, is_power_of_2(align)); > + > + if (!size) > + return -EINVAL; > + > + drm_mm_for_each_hole(entry, &ggtt->mm, hole_start, hole_end) { > + u64 lo = max(hole_start, range_start); > + u64 hi = min(hole_end, range_end); > + u64 addr; > + > + if (hi <= lo || hi - lo < size) > + continue; > + > + addr = ALIGN_DOWN(ggtt->start + hi - size, align); > + if (addr < ggtt->start + lo) > + continue; > + > + if (best == U64_MAX || addr - ggtt->start > best) > + best = addr - ggtt->start; > + } > + > + if (best == U64_MAX) > + return -ENOSPC; > + > + node->base.start = best; > + node->base.size = size; > + > + return drm_mm_reserve_node(&ggtt->mm, &node->base); > +} > + > /** > * xe_ggtt_insert_node_shareable() - Insert a new node in the shareable GGTT range > * @ggtt: the &xe_ggtt into which the node should be inserted. > * @size: size of the node > - * @align: alignment constrain of the node > + * @align: alignment constraint of the node > * > - * Allocations always start from the top (DRM_MM_INSERT_HIGH). > + * Allocations always start from the top (DRM_MM_INSERT_HIGH). @align applies > + * to the GGTT address of the node, not to its offset from the GGTT start. > * > * Return: &xe_ggtt_node on success or an ERR_PTR on failure. > */ > @@ -963,10 +1016,7 @@ struct xe_ggtt_node *xe_ggtt_insert_node_shareable(struct xe_ggtt *ggtt, u32 siz > > guard(mutex)(&ggtt->lock); > > - ret = ggtt_insert_node_in_range_locked(node, size, align, > - ggtt_shareable_offset(ggtt), > - ggtt->shareable_size, > - DRM_MM_INSERT_HIGH); > + ret = ggtt_insert_node_shareable_locked(node, size, align); > if (ret) { > ggtt_node_fini(node); > return ERR_PTR(ret); > @@ -1224,6 +1274,30 @@ void xe_ggtt_remove_bo(struct xe_ggtt *ggtt, struct xe_bo *bo) > bo->flags & XE_BO_FLAG_GGTT_INVALIDATE); > } > > +/* > + * Shrink a hole, given as drm_mm offsets, to aligned boundaries. Align the > + * GGTT addresses rather than the drm_mm offsets. > + */ > +static bool ggtt_align_hole(struct xe_ggtt *ggtt, u64 alignment, > + u64 *hole_start, u64 *hole_end) > +{ > + u64 start = ggtt->start + *hole_start; > + u64 end = ggtt->start + *hole_end; > + > + if (alignment > 1) { > + xe_tile_assert(ggtt->tile, is_power_of_2(alignment)); > + start = ALIGN(start, alignment); > + end = ALIGN_DOWN(end, alignment); > + } > + > + if (start >= end) > + return false; > + > + *hole_start = start - ggtt->start; > + *hole_end = end - ggtt->start; > + return true; > +} > + > /** > * xe_ggtt_largest_hole - Largest GGTT hole > * @ggtt: the &xe_ggtt that will be inspected > @@ -1241,10 +1315,7 @@ u64 xe_ggtt_largest_hole(struct xe_ggtt *ggtt, u64 alignment, u64 *spare) > > mutex_lock(&ggtt->lock); > drm_mm_for_each_hole(entry, mm, hole_start, hole_end) { > - hole_start = max(hole_start, ggtt->start); > - hole_start = ALIGN(hole_start, alignment); > - hole_end = ALIGN_DOWN(hole_end, alignment); > - if (hole_start >= hole_end) > + if (!ggtt_align_hole(ggtt, alignment, &hole_start, &hole_end)) > continue; > hole_size = hole_end - hole_start; > if (spare) > @@ -1416,10 +1487,7 @@ u64 xe_ggtt_print_holes(struct xe_ggtt *ggtt, u64 alignment, struct drm_printer > > mutex_lock(&ggtt->lock); > drm_mm_for_each_hole(entry, mm, hole_start, hole_end) { > - hole_start = max(hole_start, ggtt->start); > - hole_start = ALIGN(hole_start, alignment); > - hole_end = ALIGN_DOWN(hole_end, alignment); > - if (hole_start >= hole_end) > + if (!ggtt_align_hole(ggtt, alignment, &hole_start, &hole_end)) > continue; > hole_size = hole_end - hole_start; > total += hole_size; > -- > 2.34.1 >