From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: "Piórkowski, Piotr" <piotr.piorkowski@intel.com>
Cc: <intel-xe@lists.freedesktop.org>,
Matt Atwood <matthew.s.atwood@intel.com>,
Satyanarayana K V P <satyanarayana.k.v.p@intel.com>,
Tangudu Tilak Tirumalesh <tilak.tirumalesh.tangudu@intel.com>,
Varun Gupta <varun.gupta@intel.com>
Subject: Re: [PATCH v2 2/5] drm/xe/ggtt: Align shareable GGTT nodes by GGTT address
Date: Thu, 3 Dec 2026 15:06:38 -0500 [thread overview]
Message-ID: <axHLzhGDtUCBqlIg@intel.com> (raw)
In-Reply-To: <20261203181408.362175-3-piotr.piorkowski@intel.com>
On Thu, Dec 03, 2026 at 07:14:05PM +0100, Piórkowski, Piotr wrote:
> From: Piotr Piórkowski <piotr.piorkowski@intel.com>
>
> 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 <matthew.s.atwood@intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Satyanarayana K V P <satyanarayana.k.v.p@intel.com>
> Cc: Tangudu Tilak Tirumalesh <tilak.tirumalesh.tangudu@intel.com>
> Cc: Varun Gupta <varun.gupta@intel.com>
> Signed-off-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> ---
> 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
>
next prev parent reply other threads:[~2026-12-03 20:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 18:14 [PATCH v2 0/5] Apply Wa_14028597154 to SR-IOV VF Piórkowski, Piotr
2026-12-03 18:14 ` [PATCH v2 1/5] drm/xe: Don't allow disabling multi-queue on PF Piórkowski, Piotr
2026-12-03 20:06 ` Piotr Piórkowski
2026-12-03 18:14 ` [PATCH v2 2/5] drm/xe/ggtt: Align shareable GGTT nodes by GGTT address Piórkowski, Piotr
2026-12-03 20:06 ` Rodrigo Vivi [this message]
2026-12-03 18:14 ` [PATCH v2 3/5] drm/xe/tests: Test shareable GGTT alignment " Piórkowski, Piotr
2026-12-03 18:14 ` [PATCH v2 4/5] drm/xe/xe3p_lpg: Apply Wa_14028597154 to SR-IOV PF Piórkowski, Piotr
2026-12-03 18:14 ` [PATCH v2 5/5] drm/xe/xe3p_lpg: Apply Wa_14028597154 to SR-IOV VF Piórkowski, Piotr
2026-12-03 18:28 ` ✓ CI.KUnit: success for Apply Wa_14028597154 to SR-IOV VF (rev2) Patchwork
2026-12-03 19:04 ` ✓ Xe.CI.BAT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=axHLzhGDtUCBqlIg@intel.com \
--to=rodrigo.vivi@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.s.atwood@intel.com \
--cc=piotr.piorkowski@intel.com \
--cc=satyanarayana.k.v.p@intel.com \
--cc=tilak.tirumalesh.tangudu@intel.com \
--cc=varun.gupta@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox