From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: "Piórkowski, Piotr" <piotr.piorkowski@intel.com>
Cc: <intel-xe@lists.freedesktop.org>,
Varun Gupta <varun.gupta@intel.com>,
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>
Subject: Re: [PATCH v2 4/5] drm/xe/xe3p_lpg: Apply Wa_14028597154 to SR-IOV PF
Date: Thu, 3 Dec 2026 15:30:43 -0500 [thread overview]
Message-ID: <axHRc_Bek-agTmkc@intel.com> (raw)
In-Reply-To: <20261203181408.362175-5-piotr.piorkowski@intel.com>
On Thu, Dec 03, 2026 at 07:14:07PM +0100, Piórkowski, Piotr wrote:
> From: Varun Gupta <varun.gupta@intel.com>
>
> Wa_14028597154 requires the low-4MB GGTT PTE matching each 4MB chunk of
> GGTT (addr >> 10), plus the following page, to be backed by a dummy page
> of the function owning that chunk. With SR-IOV this also applies to the
> GGTT ranges of the VFs.
>
> When the WA is active, provision VF GGTT ranges 4MB aligned and in whole
> 4MB chunks. Make them at least 8MB, as the VF keeps the top 4MB of its
> range unused, and don't estimate a fair VF GGTT size below 8MB.
>
> Hand the low-4MB PTEs matching a VF range to the VF together with the
> range, as VFID-only PTEs like the range itself. On release, restore the
> PF dummy page in them and invalidate the GGTT TLBs.
>
> Keep the 4MB chunk right below a VF range free of PF allocations. Place
> PF BOs at least 4MB below the lowest VF chunk, and place a VF range only
> where the chunk below is free or owned by another VF. Track the
> VF-owned chunks, so PF resume leaves their low-4MB PTEs alone.
>
> The VF side of the WA is added in a follow-up patch.
>
> v2:
> - Fix build without CONFIG_PCI_IOV (CI)
>
> 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>
> Signed-off-by: Varun Gupta <varun.gupta@intel.com>
> Signed-off-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
> ---
> drivers/gpu/drm/xe/xe_ggtt.c | 159 +++++++++++++++++++--
> drivers/gpu/drm/xe/xe_ggtt.h | 1 +
> drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 19 ++-
> 3 files changed, 164 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
> index f3836a04eefd..64b81c0c48a3 100644
> --- a/drivers/gpu/drm/xe/xe_ggtt.c
> +++ b/drivers/gpu/drm/xe/xe_ggtt.c
> @@ -6,6 +6,7 @@
> #include "xe_ggtt.h"
>
> #include <kunit/visibility.h>
> +#include <linux/bitmap.h>
> #include <linux/error-injection.h>
> #include <linux/io-64-nonatomic-lo-hi.h>
> #include <linux/sizes.h>
> @@ -72,6 +73,8 @@
> #define XE_GGTT_FLAGS_64K BIT(0)
> #define XE_GGTT_FLAGS_ONLINE BIT(1)
>
> +#define XE_GGTT_NUM_4M_CHUNKS (SZ_4G / SZ_4M)
> +
> /**
> * struct xe_ggtt_node - A node in GGTT.
> *
> @@ -132,6 +135,8 @@ struct xe_ggtt {
> struct xe_bo *scratch;
> /** @low_4m_pte: PTE backing GGTT [4K, 4M), 0 if unused */
> u64 low_4m_pte;
> + /** @vf_chunks: Bitmap of 4MB GGTT chunks assigned to VFs */
> + DECLARE_BITMAP(vf_chunks, XE_GGTT_NUM_4M_CHUNKS);
> /** @lock: Mutex lock to protect GGTT data */
> struct mutex lock;
> /**
> @@ -480,6 +485,14 @@ static void ggtt_init_shared(struct xe_ggtt *ggtt, u64 start, u64 size)
> ggtt_init_ranges(ggtt, start, size, size, size);
> }
>
> +static bool ggtt_needs_low_4m_wa(struct xe_ggtt *ggtt)
> +{
> + struct xe_tile *tile = ggtt->tile;
> +
> + return tile->primary_gt && XE_GT_WA(tile->primary_gt, 14028597154) &&
> + xe_gt_has_multi_queue(tile->primary_gt);
> +}
> +
> static void ggtt_init_generic(struct xe_ggtt *ggtt, u64 start, u64 size)
> {
> struct xe_device *xe = tile_to_xe(ggtt->tile);
> @@ -568,6 +581,87 @@ ALLOW_ERROR_INJECTION(xe_ggtt_init_early, ERRNO); /* See xe_pci_probe() */
> static void xe_ggtt_invalidate(struct xe_ggtt *ggtt);
> static void xe_ggtt_invalidate_engine(struct xe_ggtt *ggtt);
>
> +/*
> + * Return the low-4MB PTEs of the VF chunks in [start, start + size) to the PF
> + * dummy page. Chunks not assigned to a VF are left alone, so releasing a PF
> + * node does not touch the low 4MB.
> + */
> +static void ggtt_release_low_4m_locked(struct xe_ggtt *ggtt, u64 start, u64 size)
> +{
> + u64 va;
> +
> + lockdep_assert_held(&ggtt->lock);
> + xe_tile_assert(ggtt->tile, ggtt->low_4m_pte);
> +
> + for (va = ALIGN_DOWN(start, SZ_4M); va < start + size; va += SZ_4M)
> + if (__test_and_clear_bit(va / SZ_4M, ggtt->vf_chunks))
> + ggtt_set_low_4m_pte(ggtt, va >> 10, ggtt->low_4m_pte);
> +}
> +
> +#ifdef CONFIG_PCI_IOV
> +static u64 xe_encode_vfid_pte(u16 vfid)
> +{
> + return FIELD_PREP(GGTT_PTE_VFID, vfid) | XE_PAGE_PRESENT;
> +}
> +
> +/*
> + * Wa_14028597154: hand the low-4MB PTE matching every 4MB chunk of a VF range
> + * (va >> 10) to that VF, as a VFID-only PTE like in xe_ggtt_assign_locked().
> + */
> +static void ggtt_assign_low_4m_locked(struct xe_ggtt *ggtt, u64 start, u64 size,
> + u16 vfid)
> +{
> + u64 pte = xe_encode_vfid_pte(vfid);
> + u64 va;
> +
> + lockdep_assert_held(&ggtt->lock);
> + xe_tile_assert(ggtt->tile, ggtt->low_4m_pte);
> + xe_tile_assert(ggtt->tile, IS_ALIGNED(start, SZ_4M) && IS_ALIGNED(size, SZ_4M));
> +
> + for (va = start; va < start + size; va += SZ_4M) {
> + ggtt_set_low_4m_pte(ggtt, va >> 10, pte);
> + __set_bit(va / SZ_4M, ggtt->vf_chunks);
> + }
> +}
> +
> +/*
> + * Wa_14028597154: the 4MB chunk right below a VF range must not hold PF
> + * allocations. It has to be free, below the GGTT start, or owned by another
> + * VF.
> + */
> +static bool ggtt_low_4m_room_below(struct xe_ggtt *ggtt, u64 addr, u64 hole_start)
> +{
> + if (!ggtt->low_4m_pte || addr >= hole_start + SZ_4M)
> + return true;
> +
> + if (hole_start == ggtt->start)
> + return true;
> +
> + if (addr < SZ_4M)
> + return false;
> +
> + return test_bit(addr / SZ_4M - 1, ggtt->vf_chunks);
> +}
> +#endif
> +
> +/*
> + * Return the lowest drm_mm offset in a hole that can hold a VF range. If the
> + * hole starts right above a node not owned by a VF, skip its first 4MB, see
> + * ggtt_low_4m_room_below().
> + */
> +static u64 ggtt_low_4m_hole_start(struct xe_ggtt *ggtt, u64 hole_start)
> +{
> + u64 addr = ggtt->start + hole_start;
> +
> + if (!ggtt->low_4m_pte || !hole_start)
> + return hole_start;
> +
> + if (IS_ALIGNED(addr, SZ_4M) && test_bit(addr / SZ_4M - 1, ggtt->vf_chunks))
> + return hole_start;
> +
> + return hole_start + SZ_4M;
> +}
> +
> static void ggtt_restore_low_4m_locked(struct xe_ggtt *ggtt)
> {
> u64 low_start = max_t(u64, ALIGN_DOWN(ggtt->start, SZ_4M) >> 10,
> @@ -582,8 +676,11 @@ static void ggtt_restore_low_4m_locked(struct xe_ggtt *ggtt)
> if (!ggtt->low_4m_pte)
> return;
>
> - for (addr = low_start; addr < low_end; addr += XE_PAGE_SIZE)
> + for (addr = low_start; addr < low_end; addr += XE_PAGE_SIZE) {
> + if (test_bit(addr >> XE_PTE_SHIFT, ggtt->vf_chunks))
> + continue;
> ggtt_set_low_4m_pte(ggtt, addr, ggtt->low_4m_pte);
> + }
> }
>
> /*
> @@ -607,8 +704,7 @@ static int ggtt_map_low_4m_wa(struct xe_ggtt *ggtt)
> if (IS_SRIOV_VF(xe))
> return 0;
>
> - if (!tile->primary_gt || !XE_GT_WA(tile->primary_gt, 14028597154) ||
> - !xe_gt_has_multi_queue(tile->primary_gt))
> + if (!ggtt_needs_low_4m_wa(ggtt))
> return 0;
>
> bo = xe_managed_bo_create_pin_map(xe, tile, XE_PAGE_SIZE, XE_BO_FLAG_SYSTEM);
> @@ -640,6 +736,17 @@ void xe_ggtt_resume(struct xe_ggtt *ggtt)
> ggtt_restore_low_4m_locked(ggtt);
> }
>
> +/**
> + * xe_ggtt_has_low_4m_wa() - Check if the low-4MB GGTT mapping is applied
> + * @ggtt: the &xe_ggtt
> + *
> + * Return: true if the low-4MB GGTT mapping for Wa_14028597154 is in place.
> + */
> +bool xe_ggtt_has_low_4m_wa(struct xe_ggtt *ggtt)
> +{
> + return ggtt->low_4m_pte;
> +}
> +
> static void xe_ggtt_initial_clear(struct xe_ggtt *ggtt)
> {
> struct drm_mm_node *hole;
> @@ -666,8 +773,13 @@ static void ggtt_node_remove(struct xe_ggtt_node *node)
>
> mutex_lock(&ggtt->lock);
> bound = ggtt->flags & XE_GGTT_FLAGS_ONLINE;
> - if (bound)
> + if (bound) {
> xe_ggtt_clear(ggtt, xe_ggtt_node_addr(node), xe_ggtt_node_size(node));
> + /* Return a released VF range's low-4MB PTEs to the PF dummy page */
> + if (IS_SRIOV_PF(tile_to_xe(ggtt->tile)) && ggtt->low_4m_pte)
> + ggtt_release_low_4m_locked(ggtt, xe_ggtt_node_addr(node),
> + xe_ggtt_node_size(node));
> + }
> drm_mm_remove_node(&node->base);
> node->base.size = 0;
> if (bound && node->invalidate_on_remove) {
> @@ -941,9 +1053,9 @@ 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.
> + * is what has to be aligned. If ggtt->start is not aligned to @align, or the
> + * placement has to follow Wa_14028597154, 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)
> @@ -956,11 +1068,13 @@ static int ggtt_insert_node_shareable_locked(struct xe_ggtt_node *node, u64 size
>
> lockdep_assert_held(&ggtt->lock);
>
> - if (align <= 1 || IS_ALIGNED(ggtt->start, align))
> + if ((align <= 1 || IS_ALIGNED(ggtt->start, align)) && !ggtt->low_4m_pte)
> return ggtt_insert_node_in_range_locked(node, size, align, range_start,
> ggtt->shareable_size,
> DRM_MM_INSERT_HIGH);
>
> + /* Wa_14028597154: VF ranges are handed out in whole 4MB chunks */
> + align = max_t(u64, align, ggtt->low_4m_pte ? SZ_4M : 1);
> xe_tile_assert(ggtt->tile, is_power_of_2(align));
>
> if (!size)
> @@ -978,6 +1092,10 @@ static int ggtt_insert_node_shareable_locked(struct xe_ggtt_node *node, u64 size
> if (addr < ggtt->start + lo)
> continue;
>
> + /* Wa_14028597154: keep PF allocations out of the chunk below */
> + if (!ggtt_low_4m_room_below(ggtt, addr, ggtt->start + hole_start))
> + continue;
> +
> if (best == U64_MAX || addr - ggtt->start > best)
> best = addr - ggtt->start;
> }
> @@ -1198,6 +1316,21 @@ static int __xe_ggtt_insert_bo_at(struct xe_ggtt *ggtt, struct xe_bo *bo,
>
> end = min(end, ggtt->size);
>
> + /*
> + * Wa_14028597154: keep PF allocations at least 4MB below the lowest
> + * VF-owned chunk.
> + */
> + if (ggtt->low_4m_pte && IS_SRIOV_PF(tile_to_xe(ggtt->tile))) {
Only BOs get this limit, display fb pins don't. Fine if only contexts
matter for this WA, right? Maybe say it in the comment.
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> + unsigned long first_vf = find_first_bit(ggtt->vf_chunks,
> + XE_GGTT_NUM_4M_CHUNKS);
> +
> + if (first_vf < XE_GGTT_NUM_4M_CHUNKS) {
> + u64 limit = (u64)first_vf * SZ_4M - SZ_4M;
> +
> + end = limit > ggtt->start ? min(end, limit - ggtt->start) : 0;
> + }
> + }
> +
> if (end < start + xe_bo_size(bo))
> err = -ENOSPC;
> else
> @@ -1315,6 +1448,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 = ggtt_low_4m_hole_start(ggtt, hole_start);
> if (!ggtt_align_hole(ggtt, alignment, &hole_start, &hole_end))
> continue;
> hole_size = hole_end - hole_start;
> @@ -1329,11 +1463,6 @@ u64 xe_ggtt_largest_hole(struct xe_ggtt *ggtt, u64 alignment, u64 *spare)
> }
>
> #ifdef CONFIG_PCI_IOV
> -static u64 xe_encode_vfid_pte(u16 vfid)
> -{
> - return FIELD_PREP(GGTT_PTE_VFID, vfid) | XE_PAGE_PRESENT;
> -}
> -
> static void xe_ggtt_assign_locked(const struct xe_ggtt_node *node, u16 vfid)
> {
> struct xe_ggtt *ggtt = node->ggtt;
> @@ -1344,6 +1473,9 @@ static void xe_ggtt_assign_locked(const struct xe_ggtt_node *node, u16 vfid)
>
> lockdep_assert_held(&ggtt->lock);
>
> + if (ggtt->low_4m_pte)
> + ggtt_assign_low_4m_locked(ggtt, start, size, vfid);
> +
> while (start < end) {
> ggtt->pt_ops->ggtt_set_pte(ggtt, start, pte);
> start += XE_PAGE_SIZE;
> @@ -1487,6 +1619,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 = ggtt_low_4m_hole_start(ggtt, hole_start);
> if (!ggtt_align_hole(ggtt, alignment, &hole_start, &hole_end))
> continue;
> hole_size = hole_end - hole_start;
> diff --git a/drivers/gpu/drm/xe/xe_ggtt.h b/drivers/gpu/drm/xe/xe_ggtt.h
> index 78e68c2ca3ad..7b5221d6f733 100644
> --- a/drivers/gpu/drm/xe/xe_ggtt.h
> +++ b/drivers/gpu/drm/xe/xe_ggtt.h
> @@ -18,6 +18,7 @@ int xe_ggtt_init_early(struct xe_ggtt *ggtt);
> int xe_ggtt_init_kunit(struct xe_ggtt *ggtt, u32 reserved, u32 size);
> int xe_ggtt_init(struct xe_ggtt *ggtt);
> void xe_ggtt_resume(struct xe_ggtt *ggtt);
> +bool xe_ggtt_has_low_4m_wa(struct xe_ggtt *ggtt);
>
> void xe_ggtt_shift_nodes(struct xe_ggtt *ggtt, u64 new_base);
> u64 xe_ggtt_start(struct xe_ggtt *ggtt);
> diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> index 926f1e83bd79..0b136b4616e7 100644
> --- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> +++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> @@ -442,6 +442,10 @@ static u64 pf_get_ggtt_alignment(struct xe_gt *gt)
> {
> struct xe_device *xe = gt_to_xe(gt);
>
> + /* Wa_14028597154: VF GGTT ranges must start on and span whole 4MB chunks */
> + if (xe_ggtt_has_low_4m_wa(gt_to_tile(gt)->mem.ggtt))
> + return SZ_4M;
> +
> return IS_DGFX(xe) && xe->info.vram_flags & XE_VRAM_FLAGS_NEED64K ? SZ_64K : SZ_4K;
> }
>
> @@ -495,7 +499,9 @@ static int pf_distribute_config_ggtt(struct xe_tile *tile, unsigned int vfid, u6
>
> static void pf_release_vf_config_ggtt(struct xe_gt *gt, struct xe_gt_sriov_config *config)
> {
> - xe_ggtt_node_remove(config->ggtt_region, false);
> + /* Wa_14028597154: drop TLB entries for the VF's own low-4MB dummy page */
> + xe_ggtt_node_remove(config->ggtt_region,
> + xe_ggtt_has_low_4m_wa(gt_to_tile(gt)->mem.ggtt));
> config->ggtt_region = NULL;
> }
>
> @@ -514,6 +520,10 @@ static int pf_provision_vf_ggtt(struct xe_gt *gt, unsigned int vfid, u64 size)
>
> size = round_up(size, alignment);
>
> + /* Wa_14028597154: the VF keeps its top 4MB free, so give it at least 8MB */
> + if (size && xe_ggtt_has_low_4m_wa(ggtt))
> + size = max_t(u64, size, SZ_8M);
> +
> if (config->ggtt_region) {
> err = pf_distribute_config_ggtt(tile, vfid, 0, 0);
> if (unlikely(err))
> @@ -545,7 +555,7 @@ static int pf_provision_vf_ggtt(struct xe_gt *gt, unsigned int vfid, u64 size)
> config->ggtt_region = node;
> return 0;
> err:
> - xe_ggtt_node_remove(node, false);
> + xe_ggtt_node_remove(node, xe_ggtt_has_low_4m_wa(ggtt));
> return err;
> }
>
> @@ -751,6 +761,11 @@ static u64 pf_estimate_fair_ggtt(struct xe_gt *gt, unsigned int num_vfs)
>
> fair = div_u64(available, num_vfs);
> fair = ALIGN_DOWN(fair, alignment);
> +
> + /* Wa_14028597154: each VF needs at least 8MB, see pf_provision_vf_ggtt() */
> + if (fair < SZ_8M && xe_ggtt_has_low_4m_wa(gt_to_tile(gt)->mem.ggtt))
> + fair = 0;
> +
> xe_gt_sriov_dbg_verbose(gt, "GGTT available(%lluK) fair(%u x %lluK)\n",
> available / SZ_1K, num_vfs, fair / SZ_1K);
> return fair;
> --
> 2.34.1
>
next prev parent reply other threads:[~2026-12-03 20:31 UTC|newest]
Thread overview: 14+ 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 20:30 ` Rodrigo Vivi
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
2026-12-03 18:14 ` [PATCH v2 3/5] drm/xe/tests: Test shareable GGTT alignment " Piórkowski, Piotr
2026-12-03 20:07 ` Rodrigo Vivi
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 20:30 ` Rodrigo Vivi [this message]
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 20:31 ` Rodrigo Vivi
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=axHRc_Bek-agTmkc@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