diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c index 9b58f47986f6..63e8bf193605 100644 --- a/drivers/gpu/drm/xe/xe_ggtt.c +++ b/drivers/gpu/drm/xe/xe_ggtt.c @@ -451,6 +451,7 @@ int xe_ggtt_init_early(struct xe_ggtt *ggtt) 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); static void xe_ggtt_initial_clear(struct xe_ggtt *ggtt) { @@ -482,8 +483,11 @@ static void ggtt_node_remove(struct xe_ggtt_node *node) xe_ggtt_clear(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) + if (bound && node->invalidate_on_remove) { xe_ggtt_invalidate(ggtt); + /* Drain engine TLBs so a recycled range can't hit a stale entry. */ + xe_ggtt_invalidate_engine(ggtt); + } mutex_unlock(&ggtt->lock); ggtt_node_fini(node); @@ -601,6 +605,34 @@ static void xe_ggtt_invalidate(struct xe_ggtt *ggtt) ggtt_invalidate_gt_tlb(ggtt->tile->media_gt); } +static void ggtt_invalidate_gt_engine_tlb(struct xe_gt *gt) +{ + int err; + + /* + * Multi-queue GTs miss engine GGTT TLB invalidations (GuC + * lite-restore skips the full context restore), so the engine + * flush is needed there. + */ + if (!gt || !xe_gt_has_multi_queue(gt)) + return; + + err = xe_tlb_inval_ggtt_full(>->tlb_inval); + xe_gt_WARN(gt, err, "Failed to invalidate engine GGTT TLBs (%pe)", + ERR_PTR(err)); +} + +/* + * Drain engine-side GGTT TLBs on teardown so a recycled range's next + * occupant can't hit a predecessor's cached translation. + */ +static void xe_ggtt_invalidate_engine(struct xe_ggtt *ggtt) +{ + /* Each GT in a tile has its own engine TLBs to drain */ + ggtt_invalidate_gt_engine_tlb(ggtt->tile->primary_gt); + ggtt_invalidate_gt_engine_tlb(ggtt->tile->media_gt); +} + /** * xe_ggtt_shift_nodes() - Shift GGTT nodes to adjust for a change in usable address range. * @ggtt: the &xe_ggtt struct instance